From: Ben Warren Date: Mon, 19 Feb 2007 15:37:46 -0500 Subject: [U-Boot-Users] [PATCH] fw_printenv - changed MTD include and fixed compiler warnings Message-ID: <1171917466.22834.48.camel@saruman.qstreams.net> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de This user-space program was including a kernel header, which prevented compilation. Compiler warnings were 'fixed' by some casts. If anyone stores binary data in environment variables this may not work. The DULG mentions a 'fw_setenv' command, which doesn't technically exist. The Makefile was modified to create a link that becomes this command. Signed-off-by: Ben Warren --- tools/env/Makefile | 3 ++- tools/env/README | 3 ++- tools/env/fw_env.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tools/env/Makefile b/tools/env/Makefile index 1f16768..90dac5e 100644 --- a/tools/env/Makefile +++ b/tools/env/Makefile @@ -32,9 +32,10 @@ all: $(obj)fw_printenv $(obj)fw_printenv: $(SRCS) $(HEADERS) $(CROSS_COMPILE)gcc $(CPPFLAGS) $(SRCS) -o $(obj)fw_printenv + ln -s $(obj)fw_printenv $(obj)fw_setenv clean: - rm -f $(obj)fw_printenv $(obj)crc32.c + rm -f $(obj)fw_printenv $(obj)crc32.c $(obj)fw_setenv $(obj)crc32.c: ln -s $(src)../../lib_generic/crc32.c $(obj)crc32.c diff --git a/tools/env/README b/tools/env/README index d8386f7..2f3adc1 100644 --- a/tools/env/README +++ b/tools/env/README @@ -34,7 +34,8 @@ The DEVICEx_NAME constants define which be used to access the environment. The DEVICEx_OFFSET constants define the environment offset within the -MTD character device. +MTD character device. Note that if your Linux kernel is compiled with MTD +PARTITION support, this value will probably be 0. ENVx_SIZE defines the size in bytes taken by the environment, which may be less then flash sector size, if the environment takes less diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index f723b5b..ad89f54 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -31,7 +31,7 @@ #include #include #include #include -#include +#include #include "fw_env.h" typedef unsigned char uchar; @@ -40,7 +40,7 @@ #define CMD_GETENV "fw_printenv" #define CMD_SETENV "fw_setenv" typedef struct envdev_s { - uchar devname[16]; /* Device name */ + char devname[16]; /* Device name */ ulong devoff; /* Device offset */ ulong env_size; /* environment size */ ulong erase_size; /* device erase size */ @@ -241,8 +241,8 @@ void fw_printenv (int argc, char *argv[] } for (i = 1; i < argc; ++i) { /* print single env variables */ - uchar *name = argv[i]; - uchar *val = NULL; + char *name = argv[i]; + char *val = NULL; for (env = environment.data; *env; env = nxt + 1) { @@ -253,7 +253,7 @@ void fw_printenv (int argc, char *argv[] return; } } - val = envmatch (name, env); + val = (char *)envmatch ((uchar *)name, env); if (val) { if (!n_flag) { fputs (name, stdout); @@ -281,7 +281,7 @@ int fw_setenv (int argc, char *argv[]) int i, len; uchar *env, *nxt; uchar *oldval = NULL; - uchar *name; + char *name; if (argc < 2) { return (EINVAL); @@ -303,7 +303,7 @@ int fw_setenv (int argc, char *argv[]) return (EINVAL); } } - if ((oldval = envmatch (name, env)) != NULL) + if ((oldval = envmatch ((uchar *)name, env)) != NULL) break; } @@ -361,7 +361,7 @@ int fw_setenv (int argc, char *argv[]) while ((*env = *name++) != '\0') env++; for (i = 2; i < argc; ++i) { - uchar *val = argv[i]; + char *val = argv[i]; *env = (i == 2) ? '=' : ' '; while ((*++env = *val++) != '\0'); -- 1.4.1