diff options
| author | Gerlando Falauto <gerlando.falauto@keymile.com> | 2012-08-24 00:11:41 +0000 | 
|---|---|---|
| committer | Tom Rini <trini@ti.com> | 2012-09-18 12:01:52 -0700 | 
| commit | b64b7c3df7906342ca8abe8ae31c0c12ced3f401 (patch) | |
| tree | d94787922964d2cc6dfd8b27cff971913dc2c3cb /common/cmd_nvedit.c | |
| parent | 152874b65b8060e7b026933ce332a9687256e28c (diff) | |
| download | olio-uboot-2014.01-b64b7c3df7906342ca8abe8ae31c0c12ced3f401.tar.xz olio-uboot-2014.01-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/cmd_nvedit.c')
| -rw-r--r-- | common/cmd_nvedit.c | 40 | 
1 files changed, 34 insertions, 6 deletions
| diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 310ca16ae..3474bc609 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -656,14 +656,41 @@ int envmatch(uchar *s1, int i2)  	return -1;  } -static int do_env_default(cmd_tbl_t *cmdtp, int flag, +static int do_env_default(cmd_tbl_t *cmdtp, int __flag,  			  int argc, char * const argv[])  { -	if (argc != 2 || strcmp(argv[1], "-f") != 0) -		return CMD_RET_USAGE; +	int all = 0, flag = 0; -	set_default_env("## Resetting to default environment\n"); -	return 0; +	debug("Initial value for argc=%d\n", argc); +	while (--argc > 0 && **++argv == '-') { +		char *arg = *argv; + +		while (*++arg) { +			switch (*arg) { +			case 'a':		/* default all */ +				all = 1; +				break; +			case 'f':		/* force */ +				flag |= H_FORCE; +				break; +			default: +				return cmd_usage(cmdtp); +			} +		} +	} +	debug("Final value for argc=%d\n", argc); +	if (all && (argc == 0)) { +		/* Reset the whole environment */ +		set_default_env("## Resetting to default environment\n"); +		return 0; +	} +	if (!all && (argc > 0)) { +		/* Reset individual variables */ +		set_default_vars(argc, argv); +		return 0; +	} + +	return cmd_usage(cmdtp);  }  static int do_env_delete(cmd_tbl_t *cmdtp, int flag, @@ -994,7 +1021,8 @@ U_BOOT_CMD(  #if defined(CONFIG_CMD_ASKENV)  	"ask name [message] [size] - ask for environment variable\nenv "  #endif -	"default -f - reset default environment\n" +	"default [-f] -a - [forcibly] reset default environment\n" +	"env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"  #if defined(CONFIG_CMD_EDITENV)  	"env edit name - edit environment variable\n"  #endif |