[U-Boot] [PATCH] env: Add the ability to merge the saved env with the default.

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

On Tuesday 14 February 2012 18:30:55 Doug Anderson wrote:
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).
this is kind of a crappy interface. also, doesn't the existing `env import` do this ? * env import [-d] [-t | -b | -c] addr [size] * -d: delete existing environment before importing; * otherwise overwrite / append to existion definitions
so if we "imported" the default, we'd get this ?
i think someone recently was doing work on default env handling. but wasn't following it too closely. -mike

Mike,
On Mon, Mar 5, 2012 at 8:27 PM, Mike Frysinger vapier@gentoo.org wrote:
this is kind of a crappy interface.
Agreed.
also, doesn't the existing `env import` do this ?
- env import [-d] [-t | -b | -c] addr [size]
- -d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
so if we "imported" the default, we'd get this ?
It's not quite possible to just import the default from the saved for two reasons: 1. I don't know of any way to import the default. It's not stored at any well-known address or with any well-known size. 2. The order of precedence would be a little different (default would override saved).
...but I think you're right that using "env import" is the better way to go. I can always have the default boot command load the "overrides" into memory and the import them. That works just fine for us.
Thank you for your review and suggestion!
Please consider this patch abandoned.
-Doug

Dear Doug Anderson,
In message CAD=FV=Ws+FuCqUXRd3-PJS-2y5PTspgegMftvTOQqhK=96y9MQ@mail.gmail.com you wrote:
It's not quite possible to just import the default from the saved for two reasons:
- I don't know of any way to import the default. It's not stored at any
well-known address or with any well-known size.
Then save it to a well-known address. env reset followed by env export should be a reasonably straughtforward way to get there.
- The order of precedence would be a little different (default would
override saved).
I'm not sure I understand what you mean. You can chose if you import the saved defaults before or after your private settings.
...but I think you're right that using "env import" is the better way to go. I can always have the default boot command load the "overrides" into memory and the import them. That works just fine for us.
Thank you for your review and suggestion!
Please consider this patch abandoned.
Done. Thanks.
Best regards,
Wolfgang Denk

On Tuesday 06 March 2012 12:07:10 you wrote:
On Mon, Mar 5, 2012 at 8:27 PM, Mike Frysinger wrote:
also, doesn't the existing `env import` do this ?
- env import [-d] [-t | -b | -c] addr [size]
- -d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
so if we "imported" the default, we'd get this ?
It's not quite possible to just import the default from the saved for two reasons:
- I don't know of any way to import the default. It's not stored at any
well-known address or with any well-known size. 2. The order of precedence would be a little different (default would override saved).
...but I think you're right that using "env import" is the better way to go. I can always have the default boot command load the "overrides" into memory and the import them. That works just fine for us.
i think this thread is what i was remembering: http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/109115
with that in place, it should be easy to implement the functionality you desire on top of that right ? -mike
participants (3)
-
Doug Anderson
-
Mike Frysinger
-
Wolfgang Denk