All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 3/3] env: make "env default" selective, check and apply
Date: Fri, 30 Mar 2012 15:09:42 +0200	[thread overview]
Message-ID: <201203301509.42937.marex@denx.de> (raw)
In-Reply-To: <4F75AE79.7020500@keymile.com>

Dear Gerlando Falauto,

> On 03/29/2012 10:25 PM, Marek Vasut wrote:
> > Dear Gerlando Falauto,
> > 
> >> Changes in the syntax (user API) for "env default":
> >>    -f: override write-once variables
> >>    -a: all (resetting the whole env is NOT the default behavior)
> >> 
> >> Signed-off-by: Gerlando Falauto<gerlando.falauto@keymile.com>
> > 
> > I have to admit I'm not much of a fan of how you use this apply()
> > callback, is it really necessary?
> 
> See my previous email.
> 
> > Also, do we need special command for default env?
> 
> I am sorry, I don't get the question. What do you mean?
> It's always the same "env import" with an augmented command line.
> If you're referring to CONFIG_CMD_DEFAULTENV_VARS, I don't think it's
> neeed either, but it was requested at some previous time.

Hmm.

> I also think it's misleading to have some syntax for the same command
> conditionally enabled. Has it ever been done before?

Yes it was, but this is creepy -- is this command displaying the compiled-in set 
of env vars?

> 
> Thank you,
> Gerlando
> 
> > M
> > 
> >> ---
> >> 
> >>   README                   |    2 ++
> >>   common/cmd_nvedit.c      |   43
> >> 
> >> ++++++++++++++++++++++++++++++++++++------- common/env_common.c      |
> >> 31 ++++++++++++++++++++++++++++++-
> >> 
> >>   include/config_cmd_all.h |    1 +
> >>   include/environment.h    |    5 +++++
> >>   5 files changed, 74 insertions(+), 8 deletions(-)
> >> 
> >> diff --git a/README b/README
> >> index fda0190..e924575 100644
> >> --- a/README
> >> +++ b/README
> >> 
> >> @@ -724,6 +724,8 @@ The following options need to be configured:
> >>   		CONFIG_CMD_CONSOLE	  coninfo
> >>   		CONFIG_CMD_CRC32	* crc32
> >>   		CONFIG_CMD_DATE		* support for RTC, date/time...
> >> 
> >> +		CONFIG_CMD_DEFAULTENV_VARS
> >> +					* Reset individual variables to default
> >> 
> >>   		CONFIG_CMD_DHCP		* DHCP support
> >>   		CONFIG_CMD_DIAG		* Diagnostics
> >>   		CONFIG_CMD_DS4510	* ds4510 I2C gpio commands
> >> 
> >> diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
> >> index 871b3b1..317bd1c 100644
> >> --- a/common/cmd_nvedit.c
> >> +++ b/common/cmd_nvedit.c
> >> @@ -674,14 +674,40 @@ 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_usage(cmdtp);
> >> -
> >> -	set_default_env("## Resetting to default environment\n");
> >> -	return 0;
> >> +	int all = 0, flag = 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;
> >> +	}
> >> +#ifdef CONFIG_CMD_DEFAULTENV_VARS
> >> +	if (!all&&  (argc>  0)) {
> >> +		/* Reset individual variables */
> >> +		env_default_vars(argc, argv);
> >> +		return 0;
> >> +	}
> >> +#endif
> >> +	return cmd_usage(cmdtp);
> >> 
> >>   }
> >>   
> >>   static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
> >> 
> >> @@ -1012,7 +1038,10 @@ 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"
> >> +#if defined(CONFIG_CMD_DEFAULTENV_VARS)
> >> +	"env default [-f] var [...] - [forcibly] reset variable(s) to their
> >> default values\n" +#endif
> >> 
> >>   #if defined(CONFIG_CMD_EDITENV)
> >>   
> >>   	"env edit name - edit environment variable\n"
> >>   
> >>   #endif
> >> 
> >> diff --git a/common/env_common.c b/common/env_common.c
> >> index 7e2bb2f..56719a6 100644
> >> --- a/common/env_common.c
> >> +++ b/common/env_common.c
> >> @@ -157,6 +157,11 @@ const uchar *env_get_addr(int index)
> >> 
> >>   void set_default_env(const char *s)
> >>   {
> >> 
> >> +	/*
> >> +	 * By default, do not apply changes as they will eventually
> >> +	 * be applied by someone else
> >> +	 */
> >> +	apply_cb apply_function = NULL;
> >> 
> >>   	if (sizeof(default_environment)>  ENV_SIZE) {
> >>   	
> >>   		puts("*** Error - default environment is too large\n\n");
> >>   		return;
> >> 
> >> @@ -168,6 +173,14 @@ void set_default_env(const char *s)
> >> 
> >>   				"using default environment\n\n",
> >>   				s + 1);
> >>   		
> >>   		} else {
> >> 
> >> +			/*
> >> +			 * This set_to_default was explicitly asked for
> >> +			 * by the user, as opposed to being a recovery
> >> +			 * mechanism. Therefore we chack every single
> >> +			 * variable and apply changes to the system
> >> +			 * right away (e.g. baudrate, console).
> >> +			 */
> >> +			apply_function = env_check_apply;
> >> 
> >>   			puts(s);
> >>   		
> >>   		}
> >>   	
> >>   	} else {
> >> 
> >> @@ -176,12 +189,28 @@ void set_default_env(const char *s)
> >> 
> >>   	if (himport_r(&env_htab, (char *)default_environment,
> >>   	
> >>   			sizeof(default_environment), '\0', 0,
> >> 
> >> -			0, NULL, NULL) == 0)
> >> +			0, NULL, apply_function) == 0)
> >> 
> >>   		error("Environment import failed: errno = %d\n", errno);
> >>   	
> >>   	gd->flags |= GD_FLG_ENV_READY;
> >>   
> >>   }
> >> 
> >> +#ifdef CONFIG_CMD_DEFAULTENV_VARS
> >> +
> >> +/* [re]set individual variables to their value in the default
> >> environment */ +int env_default_vars(int nvars, char * const vars[])
> >> +{
> >> +	/*
> >> +	 * Special use-case: import from default environment
> >> +	 * (and use \0 as a separator)
> >> +	 */
> >> +	return himport_r(&env_htab, (const char *)default_environment,
> >> +				sizeof(default_environment), '\0', H_NOCLEAR,
> >> +				nvars, vars, env_check_apply);
> >> +}
> >> +
> >> +#endif /* CONFIG_CMD_DEFAULTENV_VARS */
> >> +
> >> 
> >>   /*
> >>   
> >>    * Check if CRC is valid and (if yes) import the environment.
> >>    * Note that "buf" may or may not be aligned.
> >> 
> >> diff --git a/include/config_cmd_all.h b/include/config_cmd_all.h
> >> index 9716f9c..e728eae 100644
> >> --- a/include/config_cmd_all.h
> >> +++ b/include/config_cmd_all.h
> >> @@ -25,6 +25,7 @@
> >> 
> >>   #define CONFIG_CMD_CDP		/* Cisco Discovery Protocol	*/
> >>   #define CONFIG_CMD_CONSOLE	/* coninfo			*/
> >>   #define CONFIG_CMD_DATE		/* support for RTC, date/time...*/
> >> 
> >> +#define CONFIG_CMD_DEFAULTENV_VARS /* default individ variables */
> >> 
> >>   #define CONFIG_CMD_DHCP		/* DHCP Support			*/
> >>   #define CONFIG_CMD_DIAG		/* Diagnostics			*/
> >>   #define CONFIG_CMD_DISPLAY	/* Display support		*/
> >> 
> >> diff --git a/include/environment.h b/include/environment.h
> >> index 3a3e6b8..8f0d4db 100644
> >> --- a/include/environment.h
> >> +++ b/include/environment.h
> >> @@ -190,6 +190,11 @@ void env_crc_update(void);
> >> 
> >>   /* [re]set to the default environment */
> >>   void set_default_env(const char *s);
> >> 
> >> +#ifdef CONFIG_CMD_DEFAULTENV_VARS
> >> +/* [re]set individual variables to their value in the default
> >> environment */ +int env_default_vars(int nvars, char * const vars[]);
> >> +#endif
> >> +
> >> 
> >>   /* Import from binary representation into hash table */
> >>   int env_import(const char *buf, int check);

  reply	other threads:[~2012-03-30 13:09 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-18 16:49 [U-Boot] [PATCH v1 0/5] env: handle special variables and selective env default Gerlando Falauto
2011-11-18 16:49 ` [U-Boot] [PATCH v1 1/5] serial: cosmetic checkpatch compliance Gerlando Falauto
2011-11-18 20:04   ` Mike Frysinger
2011-12-05 21:47   ` Wolfgang Denk
2011-11-18 16:49 ` [U-Boot] [PATCH v1 2/5] serial: constify serial_assign() Gerlando Falauto
2011-11-18 20:03   ` Mike Frysinger
2011-12-05 21:48   ` Wolfgang Denk
2011-11-18 16:49 ` [U-Boot] [PATCH v1 3/5] env: unify logic to check and apply changes Gerlando Falauto
2011-12-07  1:50   ` Simon Glass
2011-11-18 16:49 ` [U-Boot] [PATCH v1 4/5] env: check and apply changes on delete/destroy Gerlando Falauto
2011-11-18 16:49 ` [U-Boot] [PATCH v1 5/5] env: make "env default" selective, check and apply Gerlando Falauto
2011-12-07 13:30 ` [U-Boot] [PATCH v2 0/3] env: handle special variables and selective env default Gerlando Falauto
2011-12-07 13:30 ` [U-Boot] [PATCH v2 1/3] env: unify logic to check and apply changes Gerlando Falauto
2011-12-07 22:02   ` Simon Glass
2011-12-08  5:45     ` Mike Frysinger
2011-12-12  9:32     ` Gerlando Falauto
2011-12-12 12:18       ` Wolfgang Denk
2011-12-12 13:38         ` Gerlando Falauto
2011-12-12 13:50           ` Wolfgang Denk
2011-12-12 16:24       ` Simon Glass
2012-03-29 20:19   ` Marek Vasut
2012-03-30 13:00     ` Gerlando Falauto
2012-03-30 13:08       ` Marek Vasut
2012-03-30 13:22         ` Gerlando Falauto
2012-03-30 13:55           ` Marek Vasut
2012-03-30 14:03             ` Gerlando Falauto
2012-03-30 14:28               ` Marek Vasut
2012-03-30 17:00       ` Gerlando Falauto
2011-12-07 13:30 ` [U-Boot] [PATCH v2 2/3] env: check and apply changes on delete/destroy Gerlando Falauto
2011-12-07 22:02   ` Simon Glass
2011-12-12  9:32     ` Gerlando Falauto
2011-12-12 13:08       ` Wolfgang Denk
2011-12-12 13:52         ` Gerlando Falauto
2011-12-12 19:19           ` Wolfgang Denk
2011-12-07 13:30 ` [U-Boot] [PATCH v2 3/3] env: make "env default" selective, check and apply Gerlando Falauto
2011-12-07 22:02   ` Simon Glass
2011-12-12  9:33     ` Gerlando Falauto
2011-12-12 13:10       ` Wolfgang Denk
2012-03-29 20:25   ` Marek Vasut
2012-03-30 13:00     ` Gerlando Falauto
2012-03-30 13:09       ` Marek Vasut [this message]
2012-03-30 13:25         ` Gerlando Falauto
2012-04-02 18:26 ` [U-Boot] [PATCH v3 0/6] env: handle special variables and selective env default Gerlando Falauto
2012-08-09 20:17   ` Wolfgang Denk
2012-08-09 22:19     ` Gerlando Falauto
2012-08-09 22:26       ` Wolfgang Denk
2012-08-10  8:53         ` Holger Brunck
2012-08-10 18:08           ` Wolfgang Denk
2012-08-13  7:23             ` Holger Brunck
2012-08-13 10:11               ` Wolfgang Denk
2012-08-24 10:18                 ` Gerlando Falauto
2012-08-24 15:11                   ` Marek Vasut
2012-04-02 18:26 ` [U-Boot] [PATCH v3 1/6] env: unify logic to check and apply changes Gerlando Falauto
2012-04-02 18:56   ` Marek Vasut
2012-04-02 20:39     ` Gerlando Falauto
2012-04-02 20:50       ` Marek Vasut
2012-04-02 18:26 ` [U-Boot] [PATCH v3 2/6] env: make himport_r() selective on variables Gerlando Falauto
2012-04-02 18:57   ` Marek Vasut
2012-04-02 20:43     ` Gerlando Falauto
2012-04-04  7:41       ` Simon Glass
2012-04-02 18:26 ` [U-Boot] [PATCH v3 3/6] env: add check/apply logic to himport_r() Gerlando Falauto
2012-04-02 19:00   ` Marek Vasut
2012-04-02 19:01     ` Marek Vasut
2012-04-02 20:44       ` Gerlando Falauto
2012-04-02 20:51         ` Marek Vasut
2012-04-02 18:26 ` [U-Boot] [PATCH v3 4/6] env: check and apply changes on delete/destroy Gerlando Falauto
2012-04-02 19:01   ` Marek Vasut
2012-04-02 18:26 ` [U-Boot] [PATCH v3 5/6] env: make "env default" selective, check and apply Gerlando Falauto
2012-04-02 19:04   ` Marek Vasut
2012-04-02 18:26 ` [U-Boot] [PATCH v3 6/6] env: delete selected vars not present in imported env Gerlando Falauto
2012-04-02 19:06   ` Marek Vasut
2012-04-02 20:45     ` Gerlando Falauto
2012-04-02 21:00       ` Marek Vasut
2012-08-24 10:11 ` [U-Boot] [PATCH v4 0/7] env: handle special variables and selective env default Gerlando Falauto
2012-08-24 10:11   ` [U-Boot] [PATCH v4 1/7] env: cosmetic: drop assignment i = iomux_doenv() Gerlando Falauto
2012-08-24 14:44     ` Marek Vasut
2012-09-18 19:05     ` [U-Boot] [U-Boot, v4, " Tom Rini
2012-08-24 10:11   ` [U-Boot] [PATCH v4 2/7] env: unify logic to check and apply changes Gerlando Falauto
2012-08-24 14:48     ` Marek Vasut
2012-08-24 10:11   ` [U-Boot] [PATCH v4 3/7] env: make himport_r() selective on variables Gerlando Falauto
2012-08-24 14:50     ` Marek Vasut
2012-08-24 10:11   ` [U-Boot] [PATCH v4 4/7] env: add check/apply logic to himport_r() Gerlando Falauto
2012-08-24 14:52     ` Marek Vasut
2012-08-24 10:11   ` [U-Boot] [PATCH v4 5/7] env: check and apply changes on delete/destroy Gerlando Falauto
2012-08-24 14:53     ` Marek Vasut
2012-08-24 10:11   ` [U-Boot] [PATCH v4 6/7] env: make "env default" selective, check and apply Gerlando Falauto
2012-08-24 14:56     ` Marek Vasut
2012-08-24 15:10       ` Gerlando Falauto
2012-08-24 21:10         ` Marek Vasut
2012-08-27  7:36           ` Gerlando Falauto
2012-08-27  9:57             ` Marek Vasut
2012-09-02 11:58           ` Wolfgang Denk
2012-08-24 10:11   ` [U-Boot] [PATCH v4 7/7] env: delete selected vars not present in imported env Gerlando Falauto
2012-08-24 14:58     ` Marek Vasut
2012-08-24 15:16       ` Gerlando Falauto
2012-08-24 21:12         ` Marek Vasut
2012-08-27  7:45           ` Gerlando Falauto
2012-09-02 12:01         ` Wolfgang Denk
2012-09-03  7:34           ` Gerlando Falauto
2012-08-27  7:53     ` [U-Boot] [PATCH v5 " Gerlando Falauto
2012-08-27 10:02       ` Marek Vasut
2012-09-02 11:59   ` [U-Boot] [PATCH v4 0/7] env: handle special variables and selective env default Wolfgang Denk
2012-09-02 16:13     ` Marek Vasut
2012-09-03  7:33       ` Gerlando Falauto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201203301509.42937.marex@denx.de \
    --to=marek.vasut@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.