summaryrefslogtreecommitdiffstats
path: root/common/env_common.c
diff options
context:
space:
mode:
authorGerlando Falauto <gerlando.falauto@keymile.com>2012-08-24 00:11:41 +0000
committerTom Rini <trini@ti.com>2012-09-18 12:01:52 -0700
commitb64b7c3df7906342ca8abe8ae31c0c12ced3f401 (patch)
treed94787922964d2cc6dfd8b27cff971913dc2c3cb /common/env_common.c
parent152874b65b8060e7b026933ce332a9687256e28c (diff)
downloadtalos-obmc-uboot-b64b7c3df7906342ca8abe8ae31c0c12ced3f401.tar.gz
talos-obmc-uboot-b64b7c3df7906342ca8abe8ae31c0c12ced3f401.zip
env: make "env default" selective, check and apply
Change the syntax (user API) for "env default": -f: override write-once variables var... : accept individual variable(s) -a: all (resetting the whole env is NOT the default behavior) Enable variable checking and make changes effective by enabling do_apply argument to himport_r(). Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com>
Diffstat (limited to 'common/env_common.c')
-rw-r--r--common/env_common.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/common/env_common.c b/common/env_common.c
index b9865bf630..3e46c260df 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -180,6 +180,11 @@ const uchar *env_get_addr(int index)
void set_default_env(const char *s)
{
+ /*
+ * By default, do not apply changes as they will eventually
+ * be applied by someone else
+ */
+ int do_apply = 0;
if (sizeof(default_environment) > ENV_SIZE) {
puts("*** Error - default environment is too large\n\n");
return;
@@ -191,6 +196,14 @@ void set_default_env(const char *s)
"using default environment\n\n",
s + 1);
} else {
+ /*
+ * This set_to_default was explicitly asked for
+ * by the user, as opposed to being a recovery
+ * mechanism. Therefore we check every single
+ * variable and apply changes to the system
+ * right away (e.g. baudrate, console).
+ */
+ do_apply = 1;
puts(s);
}
} else {
@@ -199,12 +212,25 @@ void set_default_env(const char *s)
if (himport_r(&env_htab, (char *)default_environment,
sizeof(default_environment), '\0', 0,
- 0, NULL, 0 /* do_apply */) == 0)
+ 0, NULL, do_apply) == 0)
error("Environment import failed: errno = %d\n", errno);
gd->flags |= GD_FLG_ENV_READY;
}
+
+/* [re]set individual variables to their value in the default environment */
+int set_default_vars(int nvars, char * const vars[])
+{
+ /*
+ * Special use-case: import from default environment
+ * (and use \0 as a separator)
+ */
+ return himport_r(&env_htab, (const char *)default_environment,
+ sizeof(default_environment), '\0', H_NOCLEAR,
+ nvars, vars, 1 /* do_apply */);
+}
+
/*
* Check if CRC is valid and (if yes) import the environment.
* Note that "buf" may or may not be aligned.
OpenPOWER on IntegriCloud