[U-Boot] [PATCH v2] common: add a grepenv command

Wolfgang Denk wd at denx.de
Sat Apr 2 00:59:55 CEST 2011


Dear Kim Phillips,

In message <20110401174658.eaa8d773.kim.phillips at freescale.com> you wrote:
> u-boot environments, esp. when boards are shared across multiple
> users, can get pretty large and time consuming to visually parse.
> The grepenv command this patch adds can be used in lieu of printenv
> to facilitate searching.  grepenv works like printenv but limits
> its output only to environment strings (variable name and value
> pairs) that match the user specified substring.

It would be nice if you gave an example of how to use this.

> +int do_grepenv (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> +{
> +	char buf[CONFIG_SYS_CBSIZE], *searchstr;
> +	int i = 0, j = 0, k = 0;
> +	int rcode = 1;
> +
> +	if (argc != 2) {
> +		cmd_usage(cmdtp);
> +		return 1;
> +	}

Why don't you allow for an arbitrary number of arguments here?

> +	/* find and print matching env vars */
> +	do {
> +		buf[j] = env_get_char(i);
...
> +	} while (!(j == 0 && env_get_char(i) == '\0'));

This does not work as you might expect.  The current environment
cannot be parsed like that, becuase it is not stored in a linear list
any more, but in a hash table instead.

You may be lucky on some systems (especially NOR flash based ones) to
read the last saved data from the persistent storage, but this is NOT
the current environment.



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 at denx.de
"Deliver yesterday, code today, think tomorrow."


More information about the U-Boot mailing list