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] fw_env: use vars from the board config
Date: Mon, 2 Jan 2012 16:11:49 +0100	[thread overview]
Message-ID: <201201021611.49276.marek.vasut@gmail.com> (raw)
In-Reply-To: <1325512756-15706-1-git-send-email-fransmeulenbroeks@gmail.com>

> it is quite odd that fw_printenv/fw_setenv does not
> use the settings from include/configs but instead
> redefines things.
> 
> This patch uses the variables from the config file
> The edit in fw_env.c is only needed to resolve a name clash
> 
> Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
> 
> ---
> 
> Note: this is more intended to get some feedback.
> (also to see if I am on the right track)
> I did test the changes locally.
> 
> (and yes, I know there are some more things that could be cleaned up).
> ---
>  tools/env/fw_env.c |   20 ++++++++++----------
>  tools/env/fw_env.h |   36 ++++++++++++++++--------------------
>  2 files changed, 26 insertions(+), 30 deletions(-)
> 
> diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
> index 996682e..6597fbf 100644
> --- a/tools/env/fw_env.c
> +++ b/tools/env/fw_env.c
> @@ -79,7 +79,7 @@ static int dev_current;
>  #define ENVSECTORS(i) envdevices[(i)].env_sectors
>  #define DEVTYPE(i)    envdevices[(i)].mtd_type
> 
> -#define CONFIG_ENV_SIZE ENVSIZE(dev_current)
> +#define CFG_ENV_SIZE ENVSIZE(dev_current)

NAK, don't change it to CFG_... for no reason! Why did you change it ? Just use 
ENVSIZE(dev_current) instead.

M

> 
>  #define ENV_SIZE      getenvsize()
> 
> @@ -216,7 +216,7 @@ static int get_config (char *);
>  #endif
>  static inline ulong getenvsize (void)
>  {
> -	ulong rc = CONFIG_ENV_SIZE - sizeof (long);
> +	ulong rc = CFG_ENV_SIZE - sizeof (long);
> 
>  	if (HaveRedundEnv)
>  		rc -= sizeof (char);
> @@ -425,7 +425,7 @@ int fw_env_write(char *name, char *value)
>  		++env;
>  	/*
>  	 * Overflow when:
> -	 * "name" + "=" + "val" +"\0\0"  > CONFIG_ENV_SIZE - (env-environment)
> +	 * "name" + "=" + "val" +"\0\0"  > CFG_ENV_SIZE - (env-environment)
>  	 */
>  	len = strlen (name) + 2;
>  	/* add '=' for first arg, ' ' for all others */
> @@ -941,7 +941,7 @@ static int flash_write (int fd_current, int fd_target,
> int dev_target) DEVOFFSET (dev_target), DEVNAME (dev_target));
>  #endif
>  	rc = flash_write_buf (dev_target, fd_target, environment.image,
> -			      CONFIG_ENV_SIZE, DEVOFFSET (dev_target),
> +			      CFG_ENV_SIZE, DEVOFFSET (dev_target),
>  			      DEVTYPE(dev_target));
>  	if (rc < 0)
>  		return rc;
> @@ -980,10 +980,10 @@ static int flash_read (int fd)
> 
>  	DEVTYPE(dev_current) = mtdinfo.type;
> 
> -	rc = flash_read_buf (dev_current, fd, environment.image, 
CONFIG_ENV_SIZE,
> +	rc = flash_read_buf (dev_current, fd, environment.image, CFG_ENV_SIZE,
>  			     DEVOFFSET (dev_current), mtdinfo.type);
> 
> -	return (rc != CONFIG_ENV_SIZE) ? -1 : 0;
> +	return (rc != CFG_ENV_SIZE) ? -1 : 0;
>  }
> 
>  static int flash_io (int mode)
> @@ -1080,11 +1080,11 @@ int fw_env_open(void)
>  	if (parse_config ())		/* should fill envdevices */
>  		return -1;
> 
> -	addr0 = calloc (1, CONFIG_ENV_SIZE);
> +	addr0 = calloc (1, CFG_ENV_SIZE);
>  	if (addr0 == NULL) {
>  		fprintf (stderr,
>  			"Not enough memory for environment (%ld bytes)\n",
> -			CONFIG_ENV_SIZE);
> +			CFG_ENV_SIZE);
>  		return -1;
>  	}
> 
> @@ -1119,11 +1119,11 @@ int fw_env_open(void)
>  		flag0 = *environment.flags;
> 
>  		dev_current = 1;
> -		addr1 = calloc (1, CONFIG_ENV_SIZE);
> +		addr1 = calloc (1, CFG_ENV_SIZE);
>  		if (addr1 == NULL) {
>  			fprintf (stderr,
>  				"Not enough memory for environment (%ld 
bytes)\n",
> -				CONFIG_ENV_SIZE);
> +				CFG_ENV_SIZE);
>  			return -1;
>  		}
>  		redundant = addr1;
> diff --git a/tools/env/fw_env.h b/tools/env/fw_env.h
> index 2dcb373..8fcc5bd 100644
> --- a/tools/env/fw_env.h
> +++ b/tools/env/fw_env.h
> @@ -24,30 +24,26 @@
>  /*
>   * To build the utility with the run-time configuration
>   * uncomment the next line.
> - * See included "fw_env.config" sample file
> + * See included "fw_env.config" sample file (TRAB board)
>   * for notes on configuration.
>   */
> -#define CONFIG_FILE     "/etc/fw_env.config"
> +//#define CONFIG_FILE     "/etc/fw_env.config"
> 
> -#define HAVE_REDUND /* For systems with 2 env sectors */
> -#define DEVICE1_NAME      "/dev/mtd1"
> -#define DEVICE2_NAME      "/dev/mtd2"
> -#define DEVICE1_OFFSET    0x0000
> -#define ENV1_SIZE         0x4000
> -#define DEVICE1_ESIZE     0x4000
> -#define DEVICE1_ENVSECTORS     2
> -#define DEVICE2_OFFSET    0x0000
> -#define ENV2_SIZE         0x4000
> -#define DEVICE2_ESIZE     0x4000
> -#define DEVICE2_ENVSECTORS     2
> +#include "config.h"
> 
> -#define CONFIG_BAUDRATE		115200
> -#define CONFIG_BOOTDELAY	5	/* autoboot after 5 seconds	*/
> -#define CONFIG_BOOTCOMMAND							
\
> -	"bootp; "								
\
> -	"setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} "	
\
> -	"ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; "	
\
> -	"bootm"
> +#define DEVICE1_NAME      "/dev/mtd0"
> +#define DEVICE2_NAME      "/dev/mtd0"
> +#define DEVICE1_OFFSET    CONFIG_ENV_ADDR_REDUND
> +#define ENV1_SIZE         CONFIG_ENV_SIZE
> +#define DEVICE1_ESIZE     CONFIG_ENV_SECT_SIZE
> +#define DEVICE1_ENVSECTORS     1
> +#ifdef CONFIG_ENV_ADDR_REDUND
> +#define HAVE_REDUND /* For systems with 2 env sectors */
> +#define DEVICE2_OFFSET    CONFIG_ENV_ADDR_REDUND
> +#define ENV2_SIZE         CONFIG_ENV_SIZE_REDUND
> +#define DEVICE2_ESIZE     CONFIG_ENV_SECT_SIZE
> +#define DEVICE2_ENVSECTORS     1
> +#endif
> 
>  extern int   fw_printenv(int argc, char *argv[]);
>  extern char *fw_getenv  (char *name);

  reply	other threads:[~2012-01-02 15:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-02 13:59 [U-Boot] [PATCH] fw_env: use vars from the board config Frans Meulenbroeks
2012-01-02 15:11 ` Marek Vasut [this message]
     [not found]   ` <CACW_hTZRTGpvpLccqTxG+hZ2v=n4UD4vkbdqEVatf4uxNXg8zw@mail.gmail.com>
2012-01-02 16:38     ` Marek Vasut

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=201201021611.49276.marek.vasut@gmail.com \
    --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.