All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 5/5] New implementation for internal handling of environment variables.
Date: Mon, 26 Jul 2010 16:52:39 +0200	[thread overview]
Message-ID: <201007261652.39368.matthias.fuchs@esd-electronics.com> (raw)
In-Reply-To: <1279395948-25864-6-git-send-email-wd@denx.de>

Hi Wolfgang,

I could think of some situations where the new env command
is helpful. But more during development than for production systems.

Switching between environment profiles would be cool. And a "env default -f"
behavior that keeps MAC addresses and serial# is also on my wishlist.

I did some testing on our PMC440 with environment in EEPROM.
Please see some comments below.

On Saturday 17 July 2010 21:45, Wolfgang Denk wrote:
> diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
> index 8c86f15..976a30b 100644
> --- a/common/cmd_nvedit.c
> +++ b/common/cmd_nvedit.c
...
> +/*
> + * env export [-t | -b | -c] addr [size]
> + *	-t:	export as text format; if size is given, data will be
> + *		padded with '\0' bytes; if not, one terminating '\0'
> + *		will be added (which is included in the "filesize"
> + *		setting so you can for exmple copy this to flash and
> + *		keep the termination).
> + *	-b:	export as binary format (name=value pairs separated by
> + *		'\0', list end marked by double "\0\0")
> + *	-c:	export as checksum protected environment format as
> + *		used for example by "saveenv" command
> + *	addr:	memory address where environment gets stored
> + *	size:	size of output buffer
> + *
...
> +static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> +{
> +	char	buf[32];
> +	char	*addr, *cmd, *res;
> +	size_t	size;
> +	ssize_t	len;
> +	env_t	*envp = (env_t *)addr;
addr is uninitialized. declaration is enough here.
> +	char	sep = '\n';
> +	int	chk = 0;
> +	int	fmt = 0;
> +
> +	cmd = *argv;
> +
> +	while (--argc > 0 && **++argv == '-') {
I'd like some more braces for readability.

> +		char *arg = *argv;
> +		while (*++arg) {
> +			switch (*arg) {
> +			case 'b':		/* raw binary format */
> +				if (fmt++)
> +					goto sep_err;
> +				sep = '\0';
> +				break;
> +			case 'c':		/* external checksum format */
> +				if (fmt++)
> +					goto sep_err;
> +				sep = '\0';
> +				chk = 1;
> +				break;
> +			case 't':		/* text format */
> +				if (fmt++)
> +					goto sep_err;
> +				sep = '\n';
> +				break;
> +			default:
> +				cmd_usage(cmdtp);
> +				return 1;
> +			}
> +		}
> +	}
>  
> -/**************************************************/
> +	if (argc < 1) {
> +		cmd_usage(cmdtp);
> +		return 1;
> +	}
> +
> +	addr = (char *)simple_strtoul(argv[0], NULL, 16);
> +
> +	if (argc == 2) {
> +		size = simple_strtoul(argv[1], NULL, 16);
> +		memset(addr, '\0', size);
> +	} else {
> +		size = 0;
> +	}
> +
> +	if (sep) {		/* export as text file */
> +		len = hexport(sep, &addr, size);
> +		if (len < 0) {
> +			error("Cannot export environment: errno = %d\n",
> +				errno);
> +			return 1;
> +		}
> +		sprintf(buf, "%zX", len);
> +		setenv("filesize", buf);
> +
> +		return 0;
> +	}
> +
> +	if (chk) {		/* export as checksum protected block */
Add:
		envp = (env_t *)addr;
> +		res = (char *)&envp->data;
> +	} else {		/* export as raw binary data */
> +		res = (char *)&addr;
Should'n this be 
		res = addr;

> +	}
> +
> +	len = hexport('\0', &res, ENV_SIZE);
> +	if (len < 0) {
> +		error("Cannot export environment: errno = %d\n",
> +			errno);
> +		return 1;
> +	}
> +
> +	if (chk) {
> +		envp->crc   = crc32(0, envp->data, ENV_SIZE);
> +#ifdef CONFIG_ENV_ADDR_REDUND
> +		envp->flags = ACTIVE_FLAG;
> +#endif
> +	}
> +	sprintf(buf, "%zX", len + offsetof(env_t,data));
> +	setenv("filesize", buf);
> +
> +	return 0;
> +
> +sep_err:
> +	printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
> +		cmd);
> +	return 1;
> +}
> +
...


Fixes for non-building board (AR405, CANBT, PMC440) will come up shortly.

Matthias

  parent reply	other threads:[~2010-07-26 14:52 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-17 19:45 [U-Boot] [PATCH 0/5] New environment code Wolfgang Denk
2010-07-17 19:45 ` [U-Boot] [PATCH 1/5] Add basic errno support Wolfgang Denk
2010-07-17 21:17   ` Mike Frysinger
2010-07-17 21:34     ` Wolfgang Denk
2010-07-18 12:51     ` Jerry Van Baren
2010-07-18 13:03       ` Wolfgang Denk
2010-09-12 19:16   ` Wolfgang Denk
2010-07-17 19:45 ` [U-Boot] [PATCH 2/5] Add qsort - add support for sorting data arrays Wolfgang Denk
2010-09-12 19:16   ` Wolfgang Denk
2010-07-17 19:45 ` [U-Boot] [PATCH 3/5] Add hash table support as base for new environment code Wolfgang Denk
2010-09-12 19:16   ` Wolfgang Denk
2010-12-08  9:44   ` Mike Frysinger
2010-12-08 10:02     ` Wolfgang Denk
2010-12-08 10:52       ` Mike Frysinger
2010-07-17 19:45 ` [U-Boot] [PATCH 4/5] Remove support for CONFIG_HAS_UID and "forceenv" command Wolfgang Denk
2010-07-17 22:12   ` Sergey Kubushyn
2010-09-12 19:18   ` Wolfgang Denk
2010-07-17 19:45 ` [U-Boot] [PATCH 5/5] New implementation for internal handling of environment variables Wolfgang Denk
2010-07-17 22:48   ` [U-Boot] [PATCH] new env: fix off-by-one error in setenv command Wolfgang Denk
2010-07-20  0:38   ` [U-Boot] [PATCH 5/5] New implementation for internal handling of environment variables Kim Phillips
2010-07-20  9:40     ` Wolfgang Denk
2010-07-20 18:36       ` Kim Phillips
2010-07-20 19:01         ` Wolfgang Denk
2010-07-20 20:09           ` Wolfgang Denk
     [not found]             ` <1279658019.5685.125.camel@thunk>
2010-07-20 20:35               ` Wolfgang Denk
2010-07-20 21:08             ` Kim Phillips
2010-07-20 21:43               ` Wolfgang Denk
2010-07-20 22:00                 ` Kim Phillips
2010-07-25 21:45                   ` Wolfgang Denk
2010-07-26 23:18                     ` Kim Phillips
2010-07-20 19:11         ` Wolfgang Denk
2010-07-26 14:52   ` Matthias Fuchs [this message]
2010-07-28 21:17     ` Wolfgang Denk
2010-07-29  9:16       ` Matthias Fuchs
2010-08-03 22:48         ` Wolfgang Denk
2010-09-12 19:19   ` Wolfgang Denk
2010-12-30  1:53   ` [U-Boot] env_flash.c:saveenv() broken when env is smaller than a sector Mike Frysinger
2010-12-30  2:39     ` Mike Frysinger
2011-01-17 20:23       ` Wolfgang Denk
2010-07-17 19:49 ` [U-Boot] [PATCH 0/5] New environment code Wolfgang Denk
2010-07-17 20:56 ` Reinhard Meyer
2010-07-17 21:28   ` Mike Frysinger
2010-07-17 21:41     ` Wolfgang Denk
2010-07-18  2:18       ` Mike Frysinger
2010-07-17 21:31   ` Wolfgang Denk
2010-07-17 21:55 ` Wolfgang Denk
2010-07-18  5:32   ` Reinhard Meyer
2010-07-18 10:26     ` Wolfgang Denk
2010-10-20  8:08 ` Mike Frysinger
2010-10-20  8:19   ` Wolfgang Denk
2010-12-08  9:56 ` Mike Frysinger
2010-12-08 10:04   ` Wolfgang Denk
2010-12-08 10:19     ` Mike Frysinger

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=201007261652.39368.matthias.fuchs@esd-electronics.com \
    --to=matthias.fuchs@esd-electronics.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.