summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorGerlando Falauto <gerlando.falauto@keymile.com>2012-08-24 00:11:39 +0000
committerTom Rini <trini@ti.com>2012-09-18 12:01:52 -0700
commitc5983592e912835fe9ed00b9d98b05580c460eae (patch)
tree96245807698607969286b6b4d0b2f1b664fdb3e8 /common
parent348b1f1c6064990210a6797c86514fd358b73062 (diff)
downloadu-boot-imx-c5983592e912835fe9ed00b9d98b05580c460eae.zip
u-boot-imx-c5983592e912835fe9ed00b9d98b05580c460eae.tar.gz
u-boot-imx-c5983592e912835fe9ed00b9d98b05580c460eae.tar.bz2
env: add check/apply logic to himport_r()
Change hashtable so that a callback function will decide whether a variable can be overwritten, and possibly apply the changes. So add a new field to struct hsearch_data: o "apply" callback function to check whether a variable can be overwritten, and possibly immediately apply the changes; when NULL, no check is performed. And a new argument to himport_r(): o "do_apply": whether to call the apply callback function NOTE: This patch does not change the current behavior. Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com> Reviewed-by: Marek Vasut <marex@denx.de>
Diffstat (limited to 'common')
-rw-r--r--common/cmd_nvedit.c3
-rw-r--r--common/env_common.c8
2 files changed, 7 insertions, 4 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index c601b3a..ddf3b8d 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -202,6 +202,7 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
* environment variable, then (if successful) apply the changes to internals so
* to make them effective. Code for this function was taken out of
* _do_env_set(), which now calls it instead.
+ * Also called as a callback function by himport_r().
* Returns 0 in case of success, 1 in case of failure.
* When (flag & H_FORCE) is set, do not print out any error message and force
* overwriting of write-once variables.
@@ -915,7 +916,7 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
}
if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
- 0, NULL) == 0) {
+ 0, NULL, 0 /* do_apply */) == 0) {
error("Environment import failed: errno = %d\n", errno);
return 1;
}
diff --git a/common/env_common.c b/common/env_common.c
index c5cefd8..b9865bf 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -136,7 +136,9 @@ const uchar default_environment[] = {
"\0"
};
-struct hsearch_data env_htab;
+struct hsearch_data env_htab = {
+ .apply = env_check_apply,
+};
static uchar __env_get_char_spec(int index)
{
@@ -197,7 +199,7 @@ void set_default_env(const char *s)
if (himport_r(&env_htab, (char *)default_environment,
sizeof(default_environment), '\0', 0,
- 0, NULL) == 0)
+ 0, NULL, 0 /* do_apply */) == 0)
error("Environment import failed: errno = %d\n", errno);
gd->flags |= GD_FLG_ENV_READY;
@@ -223,7 +225,7 @@ int env_import(const char *buf, int check)
}
if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0,
- 0, NULL)) {
+ 0, NULL, 0 /* do_apply */)) {
gd->flags |= GD_FLG_ENV_READY;
return 1;
}