tools/env: Use a board-specific default env

Originally added in aa701b9433

Before this patch, there was a hard-coded env that was used as default
if the env in flash is detected as invalid.  Now this tool (compiled
for a given board) will share the default env with the u-boot for the
board.

Fix include of config.h

Need to define "TEXT_BASE" when building the fw_env tool so that the
default env will be correct for environments which use it.

Define __ASSEMBLY__ when calling #include <config.h> so that we only
get #defines (all we're interested in).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
master
Joe Hershberger 12 years ago committed by Tom Rini
parent 47708457f8
commit 497f2053f8
  1. 5
      tools/env/Makefile
  2. 28
      tools/env/fw_env.c
  3. 19
      tools/env/fw_env.h

@ -24,13 +24,14 @@
include $(TOPDIR)/config.mk include $(TOPDIR)/config.mk
HOSTSRCS := $(SRCTREE)/lib/crc32.c fw_env.c fw_env_main.c HOSTSRCS := $(SRCTREE)/lib/crc32.c fw_env.c fw_env_main.c
HEADERS := fw_env.h HEADERS := fw_env.h $(OBJTREE)/include/config.h
# Compile for a hosted environment on the target # Compile for a hosted environment on the target
HOSTCPPFLAGS = -idirafter $(SRCTREE)/include \ HOSTCPPFLAGS = -idirafter $(SRCTREE)/include \
-idirafter $(OBJTREE)/include2 \ -idirafter $(OBJTREE)/include2 \
-idirafter $(OBJTREE)/include \ -idirafter $(OBJTREE)/include \
-DUSE_HOSTCC -DUSE_HOSTCC \
-DTEXT_BASE=$(TEXT_BASE)
ifeq ($(MTD_VERSION),old) ifeq ($(MTD_VERSION),old)
HOSTCPPFLAGS += -DMTD_OLD HOSTCPPFLAGS += -DMTD_OLD

28
tools/env/fw_env.c vendored

@ -45,8 +45,6 @@
#include "fw_env.h" #include "fw_env.h"
#include <config.h>
#define WHITESPACE(c) ((c == '\t') || (c == ' ')) #define WHITESPACE(c) ((c == '\t') || (c == ' '))
#define min(x, y) ({ \ #define min(x, y) ({ \
@ -81,7 +79,7 @@ static int dev_current;
#define ENVSECTORS(i) envdevices[(i)].env_sectors #define ENVSECTORS(i) envdevices[(i)].env_sectors
#define DEVTYPE(i) envdevices[(i)].mtd_type #define DEVTYPE(i) envdevices[(i)].mtd_type
#define CONFIG_ENV_SIZE ENVSIZE(dev_current) #define CUR_ENVSIZE ENVSIZE(dev_current)
#define ENV_SIZE getenvsize() #define ENV_SIZE getenvsize()
@ -226,7 +224,7 @@ static int get_config (char *);
#endif #endif
static inline ulong getenvsize (void) static inline ulong getenvsize (void)
{ {
ulong rc = CONFIG_ENV_SIZE - sizeof (long); ulong rc = CUR_ENVSIZE - sizeof(long);
if (HaveRedundEnv) if (HaveRedundEnv)
rc -= sizeof (char); rc -= sizeof (char);
@ -442,7 +440,7 @@ int fw_env_write(char *name, char *value)
++env; ++env;
/* /*
* Overflow when: * Overflow when:
* "name" + "=" + "val" +"\0\0" > CONFIG_ENV_SIZE - (env-environment) * "name" + "=" + "val" +"\0\0" > CUR_ENVSIZE - (env-environment)
*/ */
len = strlen (name) + 2; len = strlen (name) + 2;
/* add '=' for first arg, ' ' for all others */ /* add '=' for first arg, ' ' for all others */
@ -957,8 +955,8 @@ static int flash_write (int fd_current, int fd_target, int dev_target)
printf ("Writing new environment at 0x%lx on %s\n", printf ("Writing new environment at 0x%lx on %s\n",
DEVOFFSET (dev_target), DEVNAME (dev_target)); DEVOFFSET (dev_target), DEVNAME (dev_target));
#endif #endif
rc = flash_write_buf (dev_target, fd_target, environment.image, rc = flash_write_buf(dev_target, fd_target, environment.image,
CONFIG_ENV_SIZE, DEVOFFSET (dev_target), CUR_ENVSIZE, DEVOFFSET(dev_target),
DEVTYPE(dev_target)); DEVTYPE(dev_target));
if (rc < 0) if (rc < 0)
return rc; return rc;
@ -997,10 +995,10 @@ static int flash_read (int fd)
DEVTYPE(dev_current) = mtdinfo.type; 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, CUR_ENVSIZE,
DEVOFFSET (dev_current), mtdinfo.type); DEVOFFSET (dev_current), mtdinfo.type);
return (rc != CONFIG_ENV_SIZE) ? -1 : 0; return (rc != CUR_ENVSIZE) ? -1 : 0;
} }
static int flash_io (int mode) static int flash_io (int mode)
@ -1097,11 +1095,11 @@ int fw_env_open(void)
if (parse_config ()) /* should fill envdevices */ if (parse_config ()) /* should fill envdevices */
return -1; return -1;
addr0 = calloc (1, CONFIG_ENV_SIZE); addr0 = calloc(1, CUR_ENVSIZE);
if (addr0 == NULL) { if (addr0 == NULL) {
fprintf (stderr, fprintf(stderr,
"Not enough memory for environment (%ld bytes)\n", "Not enough memory for environment (%ld bytes)\n",
CONFIG_ENV_SIZE); CUR_ENVSIZE);
return -1; return -1;
} }
@ -1136,11 +1134,11 @@ int fw_env_open(void)
flag0 = *environment.flags; flag0 = *environment.flags;
dev_current = 1; dev_current = 1;
addr1 = calloc (1, CONFIG_ENV_SIZE); addr1 = calloc(1, CUR_ENVSIZE);
if (addr1 == NULL) { if (addr1 == NULL) {
fprintf (stderr, fprintf(stderr,
"Not enough memory for environment (%ld bytes)\n", "Not enough memory for environment (%ld bytes)\n",
CONFIG_ENV_SIZE); CUR_ENVSIZE);
return -1; return -1;
} }
redundant = addr1; redundant = addr1;

19
tools/env/fw_env.h vendored

@ -21,6 +21,15 @@
* MA 02111-1307 USA * MA 02111-1307 USA
*/ */
/* Pull in the current config to define the default environment */
#ifndef __ASSEMBLY__
#define __ASSEMBLY__ /* get only #defines from config.h */
#include <config.h>
#undef __ASSEMBLY__
#else
#include <config.h>
#endif
/* /*
* To build the utility with the static configuration * To build the utility with the static configuration
* comment out the next line. * comment out the next line.
@ -29,6 +38,7 @@
*/ */
#define CONFIG_FILE "/etc/fw_env.config" #define CONFIG_FILE "/etc/fw_env.config"
#ifndef CONFIG_FILE
#define HAVE_REDUND /* For systems with 2 env sectors */ #define HAVE_REDUND /* For systems with 2 env sectors */
#define DEVICE1_NAME "/dev/mtd1" #define DEVICE1_NAME "/dev/mtd1"
#define DEVICE2_NAME "/dev/mtd2" #define DEVICE2_NAME "/dev/mtd2"
@ -40,14 +50,23 @@
#define ENV2_SIZE 0x4000 #define ENV2_SIZE 0x4000
#define DEVICE2_ESIZE 0x4000 #define DEVICE2_ESIZE 0x4000
#define DEVICE2_ENVSECTORS 2 #define DEVICE2_ENVSECTORS 2
#endif
#ifndef CONFIG_BAUDRATE
#define CONFIG_BAUDRATE 115200 #define CONFIG_BAUDRATE 115200
#endif
#ifndef CONFIG_BOOTDELAY
#define CONFIG_BOOTDELAY 5 /* autoboot after 5 seconds */ #define CONFIG_BOOTDELAY 5 /* autoboot after 5 seconds */
#endif
#ifndef CONFIG_BOOTCOMMAND
#define CONFIG_BOOTCOMMAND \ #define CONFIG_BOOTCOMMAND \
"bootp; " \ "bootp; " \
"setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} " \ "setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} " \
"ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; " \ "ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; " \
"bootm" "bootm"
#endif
extern int fw_printenv(int argc, char *argv[]); extern int fw_printenv(int argc, char *argv[]);
extern char *fw_getenv (char *name); extern char *fw_getenv (char *name);

Loading…
Cancel
Save