From 4a6fd34b267dbf4a72080ab9a085bb45c63660fb Mon Sep 17 00:00:00 2001 From: wdenk Date: Sat, 12 Apr 2003 23:38:12 +0000 Subject: * Patch by Lutz Dennig, 10 Apr 2003: Update for R360MPI board * Add new meaning to "autostart" environment variable: If set to "no", a standalone image passed to the "bootm" command will be copied to the load address (and eventually uncompressed), but NOT be started. This can be used to load and uncompress arbitrary data. * Set max brightness for MN11236 displays on TRAB board --- tools/env/fw_env.c | 484 ++++++++++++++++++++++++++--------------------------- 1 file changed, 240 insertions(+), 244 deletions(-) (limited to 'tools/env') diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index b60395e..f70c023 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1,5 +1,5 @@ /* - * (C) Copyright 2000 + * (C) Copyright 2000-2003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this @@ -12,7 +12,7 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License @@ -34,16 +34,16 @@ #include #include "fw_env.h" -typedef unsigned char uchar; +typedef unsigned char uchar; #define CMD_GETENV "fw_printenv" #define CMD_SETENV "fw_setenv" typedef struct envdev_s { - uchar devname[16]; /* Device name */ - ulong devoff; /* Device offset */ - ulong env_size; /* environment size */ - ulong erase_size; /* device erase size */ + uchar devname[16]; /* Device name */ + ulong devoff; /* Device offset */ + ulong env_size; /* environment size */ + ulong erase_size; /* device erase size */ } envdev_t; static envdev_t envdevices[2]; @@ -59,8 +59,8 @@ static int curdev; #define ENV_SIZE getenvsize() typedef struct environment_s { - ulong crc; /* CRC32 over data bytes */ - uchar flags; /* active or obsolete */ + ulong crc; /* CRC32 over data bytes */ + uchar flags; /* active or obsolete */ uchar *data; } env_t; @@ -77,92 +77,94 @@ static uchar obsolete_flag = 0; static uchar default_environment[] = { #if defined(CONFIG_BOOTARGS) - "bootargs=" CONFIG_BOOTARGS "\0" + "bootargs=" CONFIG_BOOTARGS "\0" #endif #if defined(CONFIG_BOOTCOMMAND) - "bootcmd=" CONFIG_BOOTCOMMAND "\0" + "bootcmd=" CONFIG_BOOTCOMMAND "\0" #endif #if defined(CONFIG_RAMBOOTCOMMAND) - "ramboot=" CONFIG_RAMBOOTCOMMAND "\0" + "ramboot=" CONFIG_RAMBOOTCOMMAND "\0" #endif #if defined(CONFIG_NFSBOOTCOMMAND) - "nfsboot=" CONFIG_NFSBOOTCOMMAND "\0" + "nfsboot=" CONFIG_NFSBOOTCOMMAND "\0" #endif #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) - "bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0" + "bootdelay=" MK_STR (CONFIG_BOOTDELAY) "\0" #endif #if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0) - "baudrate=" MK_STR(CONFIG_BAUDRATE) "\0" + "baudrate=" MK_STR (CONFIG_BAUDRATE) "\0" #endif #ifdef CONFIG_LOADS_ECHO - "loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0" + "loads_echo=" MK_STR (CONFIG_LOADS_ECHO) "\0" #endif #ifdef CONFIG_ETHADDR - "ethaddr=" MK_STR(CONFIG_ETHADDR) "\0" + "ethaddr=" MK_STR (CONFIG_ETHADDR) "\0" #endif #ifdef CONFIG_ETH1ADDR - "eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0" + "eth1addr=" MK_STR (CONFIG_ETH1ADDR) "\0" #endif #ifdef CONFIG_ETH2ADDR - "eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0" + "eth2addr=" MK_STR (CONFIG_ETH2ADDR) "\0" #endif #ifdef CONFIG_ETHPRIME - "ethprime=" CONFIG_ETHPRIME "\0" + "ethprime=" CONFIG_ETHPRIME "\0" #endif #ifdef CONFIG_IPADDR - "ipaddr=" MK_STR(CONFIG_IPADDR) "\0" + "ipaddr=" MK_STR (CONFIG_IPADDR) "\0" #endif #ifdef CONFIG_SERVERIP - "serverip=" MK_STR(CONFIG_SERVERIP) "\0" + "serverip=" MK_STR (CONFIG_SERVERIP) "\0" #endif #ifdef CFG_AUTOLOAD - "autoload=" CFG_AUTOLOAD "\0" + "autoload=" CFG_AUTOLOAD "\0" #endif #ifdef CONFIG_ROOTPATH - "rootpath=" MK_STR(CONFIG_ROOTPATH) "\0" + "rootpath=" MK_STR (CONFIG_ROOTPATH) "\0" #endif #ifdef CONFIG_GATEWAYIP - "gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0" + "gatewayip=" MK_STR (CONFIG_GATEWAYIP) "\0" #endif #ifdef CONFIG_NETMASK - "netmask=" MK_STR(CONFIG_NETMASK) "\0" + "netmask=" MK_STR (CONFIG_NETMASK) "\0" #endif #ifdef CONFIG_HOSTNAME - "hostname=" MK_STR(CONFIG_HOSTNAME) "\0" + "hostname=" MK_STR (CONFIG_HOSTNAME) "\0" #endif #ifdef CONFIG_BOOTFILE - "bootfile=" MK_STR(CONFIG_BOOTFILE) "\0" + "bootfile=" MK_STR (CONFIG_BOOTFILE) "\0" #endif #ifdef CONFIG_LOADADDR - "loadaddr=" MK_STR(CONFIG_LOADADDR) "\0" + "loadaddr=" MK_STR (CONFIG_LOADADDR) "\0" #endif #ifdef CONFIG_PREBOOT - "preboot=" CONFIG_PREBOOT "\0" + "preboot=" CONFIG_PREBOOT "\0" #endif #ifdef CONFIG_CLOCKS_IN_MHZ - "clocks_in_mhz=" "1" "\0" + "clocks_in_mhz=" "1" "\0" #endif #if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0) - "pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0" + "pcidelay=" MK_STR (CONFIG_PCI_BOOTDELAY) "\0" #endif #ifdef CONFIG_EXTRA_ENV_SETTINGS CONFIG_EXTRA_ENV_SETTINGS #endif - "\0" /* Termimate env_t data with 2 NULs */ + "\0" /* Termimate env_t data with 2 NULs */ }; -static int flash_io (int mode); -static uchar *envmatch(uchar *s1, uchar *s2); -static int env_init(void); -static int parse_config(void); +static int flash_io (int mode); +static uchar *envmatch (uchar * s1, uchar * s2); +static int env_init (void); +static int parse_config (void); + #if defined(CONFIG_FILE) -static int get_config(char *); +static int get_config (char *); #endif -static inline ulong getenvsize(void) +static inline ulong getenvsize (void) { - ulong rc = CFG_ENV_SIZE - sizeof(long); + ulong rc = CFG_ENV_SIZE - sizeof (long); + if (HaveRedundEnv) - rc -= sizeof(char); + rc -= sizeof (char); return rc; } @@ -174,20 +176,20 @@ unsigned char *fw_getenv (unsigned char *name) { uchar *env, *nxt; - if (env_init()) + if (env_init ()) return (NULL); - for (env=environment.data; *env; env=nxt+1) { + for (env = environment.data; *env; env = nxt + 1) { uchar *val; - for (nxt=env; *nxt; ++nxt) { + for (nxt = env; *nxt; ++nxt) { if (nxt >= &environment.data[ENV_SIZE]) { fprintf (stderr, "## Error: " "environment not terminated\n"); return (NULL); } } - val=envmatch(name, env); + val = envmatch (name, env); if (!val) continue; return (val); @@ -199,17 +201,17 @@ unsigned char *fw_getenv (unsigned char *name) * Print the current definition of one, or more, or all * environment variables */ -void fw_printenv(int argc, char *argv[]) +void fw_printenv (int argc, char *argv[]) { uchar *env, *nxt; int i, n_flag; - if (env_init()) + if (env_init ()) return; - if (argc == 1) { /* Print all env variables */ - for (env=environment.data; *env; env=nxt+1) { - for (nxt=env; *nxt; ++nxt) { + if (argc == 1) { /* Print all env variables */ + for (env = environment.data; *env; env = nxt + 1) { + for (nxt = env; *nxt; ++nxt) { if (nxt >= &environment.data[ENV_SIZE]) { fprintf (stderr, "## Error: " "environment not terminated\n"); @@ -217,12 +219,12 @@ void fw_printenv(int argc, char *argv[]) } } - printf("%s\n", env); + printf ("%s\n", env); } return; } - if (strcmp(argv[1], "-n") == 0) { + if (strcmp (argv[1], "-n") == 0) { n_flag = 1; ++argv; --argc; @@ -235,32 +237,31 @@ void fw_printenv(int argc, char *argv[]) n_flag = 0; } - for (i=1; i= &environment.data[ENV_SIZE]) { fprintf (stderr, "## Error: " "environment not terminated\n"); return; } } - val=envmatch(name, env); + val = envmatch (name, env); if (val) { if (!n_flag) { fputs (name, stdout); - putc ('=', stdout); + putc ('=', stdout); } - puts (val); + puts (val); break; } } if (!val) - fprintf (stderr, "## Error: \"%s\" not defined\n", - name); + fprintf (stderr, "## Error: \"%s\" not defined\n", name); } } @@ -274,7 +275,7 @@ void fw_printenv(int argc, char *argv[]) */ int fw_setenv (int argc, char *argv[]) { - int i, len; + int i, len; uchar *env, *nxt; uchar *oldval = NULL; uchar *name; @@ -283,7 +284,7 @@ int fw_setenv (int argc, char *argv[]) return (EINVAL); } - if (env_init()) + if (env_init ()) return (errno); name = argv[1]; @@ -291,15 +292,15 @@ int fw_setenv (int argc, char *argv[]) /* * search if variable with this name already exists */ - for (env=environment.data; *env; env=nxt+1) { - for (nxt=env; *nxt; ++nxt) { + for (nxt = env = environment.data; *env; env = nxt + 1) { + for (nxt = env; *nxt; ++nxt) { if (nxt >= &environment.data[ENV_SIZE]) { fprintf (stderr, "## Error: " "environment not terminated\n"); return (EINVAL); } } - if ((oldval=envmatch(name, env)) != NULL) + if ((oldval = envmatch (name, env)) != NULL) break; } @@ -311,7 +312,7 @@ int fw_setenv (int argc, char *argv[]) * Ethernet Address and serial# can be set only once */ if ((strcmp (name, "ethaddr") == 0) || - (strcmp (name, "serial#") == 0) ) { + (strcmp (name, "serial#") == 0)) { fprintf (stderr, "Can't overwrite \"%s\"\n", name); return (EROFS); } @@ -336,20 +337,19 @@ int fw_setenv (int argc, char *argv[]) /* * Append new definition at the end */ - for (env=environment.data; *env || *(env+1); ++env) - ; + for (env = environment.data; *env || *(env + 1); ++env); if (env > environment.data) ++env; /* * Overflow when: * "name" + "=" + "val" +"\0\0" > CFG_ENV_SIZE - (env-environment) */ - len = strlen(name) + 2; + len = strlen (name) + 2; /* add '=' for first arg, ' ' for all others */ - for (i=2; i (&environment.data[ENV_SIZE]-env)) { + if (len > (&environment.data[ENV_SIZE] - env)) { fprintf (stderr, "Error: environment overflow, \"%s\" deleted\n", name); @@ -357,26 +357,24 @@ int fw_setenv (int argc, char *argv[]) } while ((*env = *name++) != '\0') env++; - for (i=2; i