[U-Boot] [PATCH] env: Add the ability to merge the saved env with the default.
Doug Anderson
dianders at chromium.org
Wed Feb 15 00:30:55 CET 2012
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 or could be a tool like we use in Chrome OS that
modifies the variables in a binary image before flashing (see
factory_setup/update_firmware_vars.py in
http://git.chromium.org/git/chromiumos/platform/factory-utils).
Signed-off-by: Doug Anderson <dianders at chromium.org>
---
common/env_common.c | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/common/env_common.c b/common/env_common.c
index 71811c4..5938732 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
*/
@@ -208,7 +221,18 @@ int env_import(const char *buf, int check)
}
if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0)) {
+ 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);
+ hdelete_r(MERGE_WITH_DEFAULT, &env_htab);
+ puts("Merged saved with default environment\n\n");
+ }
return 1;
}
--
1.7.7.3
More information about the U-Boot
mailing list