summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJoe Hershberger <joe.hershberger@ni.com>2012-12-11 22:16:21 -0600
committerTom Rini <trini@ti.com>2012-12-13 11:46:55 -0700
commit7afcf3a55b5f484b3d3442053fae8186a3fb92d7 (patch)
tree1aa2c5143a1bbef6570b03652107a09832a2f2ad /common
parent3d3b52f2586a8bf1c53496547062594fd4386454 (diff)
downloadu-boot-imx-7afcf3a55b5f484b3d3442053fae8186a3fb92d7.zip
u-boot-imx-7afcf3a55b5f484b3d3442053fae8186a3fb92d7.tar.gz
u-boot-imx-7afcf3a55b5f484b3d3442053fae8186a3fb92d7.tar.bz2
env: Refactor apply into change_ok
Move the read of the old value to inside the check function. In some cases it can be avoided all together and at the least the code is only called from one place. Also name the function and the callback to more clearly describe what it does. Pass the ENTRY instead of just the name for direct access to the whole data structure. Pass an enum to the callback that specifies the operation being approved. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Diffstat (limited to 'common')
-rw-r--r--common/cmd_nvedit.c34
-rw-r--r--common/env_common.c3
2 files changed, 17 insertions, 20 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index a8dc9a6..da5689c 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -208,10 +208,20 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
* overwriting of write-once variables.
*/
-int env_check_apply(const char *name, const char *oldval,
- const char *newval, int flag)
+int env_change_ok(const ENTRY *item, const char *newval, enum env_op op,
+ int flag)
{
int console = -1;
+ const char *name;
+#if !defined(CONFIG_ENV_OVERWRITE) && defined(CONFIG_OVERWRITE_ETHADDR_ONCE) \
+&& defined(CONFIG_ETHADDR)
+ const char *oldval = NULL;
+
+ if (op != env_op_create)
+ oldval = item->data;
+#endif
+
+ name = item->key;
/* Default value for NULL to protect string-manipulating functions */
newval = newval ? : "";
@@ -242,12 +252,12 @@ int env_check_apply(const char *name, const char *oldval,
#endif /* CONFIG_CONSOLE_MUX */
}
+#ifndef CONFIG_ENV_OVERWRITE
/*
* Some variables like "ethaddr" and "serial#" can be set only once and
* cannot be deleted, unless CONFIG_ENV_OVERWRITE is defined.
*/
-#ifndef CONFIG_ENV_OVERWRITE
- if (oldval != NULL && /* variable exists */
+ if (op != env_op_create && /* variable exists */
(flag & H_FORCE) == 0) { /* and we are not forced */
if (strcmp(name, "serial#") == 0 ||
(strcmp(name, "ethaddr") == 0
@@ -265,7 +275,7 @@ int env_check_apply(const char *name, const char *oldval,
* (which will erase all variables prior to calling this),
* we want the baudrate to actually change - for real.
*/
- if (oldval != NULL || /* variable exists */
+ if (op != env_op_create || /* variable exists */
(flag & H_NOCLEAR) == 0) { /* or env is clear */
/*
* Switch to new baudrate if new baudrate is supported
@@ -339,20 +349,6 @@ static int _do_env_set(int flag, int argc, char * const argv[])
}
env_id++;
- /*
- * search if variable with this name already exists
- */
- e.key = name;
- e.data = NULL;
- hsearch_r(e, FIND, &ep, &env_htab, 0);
-
- /*
- * Perform requested checks.
- */
- if (env_check_apply(name, ep ? ep->data : NULL, value, 0)) {
- debug("check function did not approve, refusing\n");
- return 1;
- }
/* Delete only ? */
if (argc < 3 || argv[2] == NULL) {
diff --git a/common/env_common.c b/common/env_common.c
index f22f5b9..a960aa8 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -40,7 +40,7 @@ DECLARE_GLOBAL_DATA_PTR;
#include <env_default.h>
struct hsearch_data env_htab = {
- .apply = env_check_apply,
+ .change_ok = env_change_ok,
};
static uchar __env_get_char_spec(int index)
@@ -162,6 +162,7 @@ void env_relocate(void)
{
#if defined(CONFIG_NEEDS_MANUAL_RELOC)
env_reloc();
+ env_htab.change_ok += gd->reloc_off;
#endif
if (gd->env_valid == 0) {
#if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD)