Patchwork [U-Boot,06/17] env: Add the ability to merge the saved env with the default.

login
register
mail settings
Submitter Simon Glass
Date Nov. 3, 2012, 12:27 a.m.
Message ID <1351902453-27956-7-git-send-email-sjg@chromium.org>
Download mbox | patch
Permalink /patch/196789/
State Superseded, archived
Delegated to: Tom Rini
Headers show

Comments

Simon Glass - Nov. 3, 2012, 12:27 a.m.
From: Doug Anderson <dianders@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@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
---
 README              |    7 +++++++
 common/env_common.c |   25 +++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)
Wolfgang Denk - Nov. 3, 2012, 3:28 p.m.
Dear Simon Glass,

In message <1351902453-27956-7-git-send-email-sjg@chromium.org> you wrote:
> From: Doug Anderson <dianders@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.

I don't see the need for this.

What exactly does it that "env reset" followed by "env import" does not
do?

Best regards,

Wolfgang Denk
Simon Glass - Nov. 7, 2012, 12:53 a.m.
Hi Wolfgang,

On Sat, Nov 3, 2012 at 8:28 AM, Wolfgang Denk <wd@denx.de> wrote:
> Dear Simon Glass,
>
> In message <1351902453-27956-7-git-send-email-sjg@chromium.org> you wrote:
>> From: Doug Anderson <dianders@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.
>
> I don't see the need for this.
>
> What exactly does it that "env reset" followed by "env import" does not
> do?

It allows the environment to either overwrite or merge, under the
control of the imported environment itself. I suppose the same could
be achieved by a script anyway. Let's drop it.

Regards,
Simon

>
> Best regards,
>
> Wolfgang Denk
>
> --
> DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
> Don't put off for tomorrow what you can  do  today,  because  if  you
> enjoy it today you can do it again tomorrow.

Patch

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;
 	}