[U-Boot] [PATCH 06/17] env: Add the ability to merge the saved env with the default.
Simon Glass
sjg at chromium.org
Sat Nov 3 01:27:22 CET 2012
From: Doug Anderson <dianders at chromium.org>
This is a useful mechanism any time you have a way to update the
saved environment outside of u-boot. This can be a tool like
fw_setenv.
Signed-off-by: Doug Anderson <dianders at chromium.org>
Signed-off-by: Simon Glass <sjg at chromium.org>
---
README | 7 +++++++
common/env_common.c | 25 +++++++++++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/README b/README
index 05c5688..785953f 100644
--- a/README
+++ b/README
@@ -4098,6 +4098,13 @@ Please note that changes to some configuration parameters may take
only effect after the next boot (yes, that's just like Windoze :-).
+If merge_with_default is in the loaded environment, and is not "0", then
+the loaded environment will be merged on top of the default environment
+instead of just replacing it. This means that your saved environment can
+contain only the variables you need to change from the default. This is
+useful with fw_setenv.
+
+
Command Line Parsing:
=====================
diff --git a/common/env_common.c b/common/env_common.c
index 3d3cb70..f7fe7a2 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -34,6 +34,19 @@
DECLARE_GLOBAL_DATA_PTR;
+/*
+ * Create a saved enviroment with this env variable set to "1" to merge the
+ * saved environment on top of the default environment. The idea is that your
+ * saved environment would just contain variables that you'd like to override
+ * from the default so that as you update u-boot (w/ potential changes to the
+ * default) you get all the updates.
+ *
+ * This is really most useful when you have a tool like fw_setenv to manage
+ * your saved environment. Using 'saveenv' to save your environment will saved
+ * the _merged_ environment (AKA it won't unmerge things).
+ */
+#define MERGE_WITH_DEFAULT "merge_with_default"
+
/************************************************************************
* Default settings to be used when no valid environment is found
*/
@@ -156,7 +169,19 @@ int env_import(const char *buf, int check)
if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0,
0, NULL, 0 /* do_apply */)) {
+ char *merge_val;
+
gd->flags |= GD_FLG_ENV_READY;
+ merge_val = getenv(MERGE_WITH_DEFAULT);
+
+ if (merge_val != NULL && merge_val[0] != '0') {
+ set_default_env("");
+ himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0',
+ H_NOCLEAR, 0, NULL, 0 /* do_apply */);
+ hdelete_r(MERGE_WITH_DEFAULT, &env_htab,
+ 0 /* do_apply */);
+ puts("Merged saved with default environment\n\n");
+ }
return 1;
}
--
1.7.7.3
More information about the U-Boot
mailing list