]> git.karo-electronics.de Git - karo-tx-uboot.git/commitdiff
env: Use getenv_yesno() more generally
authorJoe Hershberger <joe.hershberger@ni.com>
Wed, 12 Dec 2012 04:16:22 +0000 (22:16 -0600)
committerTom Rini <trini@ti.com>
Thu, 13 Dec 2012 18:46:55 +0000 (11:46 -0700)
Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
16 files changed:
arch/arm/lib/board.c
arch/m68k/lib/board.c
arch/microblaze/lib/board.c
arch/powerpc/cpu/mpc85xx/mp.c
arch/powerpc/lib/board.c
arch/sparc/lib/board.c
board/Marvell/db64360/db64360.c
board/Marvell/db64460/db64460.c
board/esd/cpci750/cpci750.c
board/gw8260/gw8260.c
board/prodrive/p3mx/p3mx.c
common/env_common.c
common/image.c
include/common.h
include/image.h
net/net.c

index 22a4d9cc0e59d4c877fb8892e2f960b0cad32843..e0cb6353a3feb95fc35734875d53e16b633c3cd7 100644 (file)
@@ -540,15 +540,13 @@ void board_init_r(gd_t *id, ulong dest_addr)
        flash_size = flash_init();
        if (flash_size > 0) {
 # ifdef CONFIG_SYS_FLASH_CHECKSUM
-               char *s = getenv("flashchecksum");
-
                print_size(flash_size, "");
                /*
                 * Compute and print flash CRC if flashchecksum is set to 'y'
                 *
                 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
                 */
-               if (s && (*s == 'y')) {
+               if (getenv_yesno("flashchecksum") == 1) {
                        printf("  CRC: %08X", crc32(0,
                                (const unsigned char *) CONFIG_SYS_FLASH_BASE,
                                flash_size));
index 02d73fda6111045052d5be20e1efe19e833bbc14..794b8679fefe2696bef4a8857f5b6d036b0c8882 100644 (file)
@@ -462,8 +462,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
                 *
                 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
                 */
-               s = getenv ("flashchecksum");
-               if (s && (*s == 'y')) {
+               if (getenv_yesno("flashchecksum") == 1) {
                        printf ("  CRC: %08X",
                                        crc32 (0,
                                                   (const unsigned char *) CONFIG_SYS_FLASH_BASE,
index efd63cd341213de1c81865cb6994b64367af5916..a7c2f7623392fc1fce53dd2eb992a6f74d8620d7 100644 (file)
@@ -74,7 +74,6 @@ void board_init_f(ulong not_used)
        gd = (gd_t *) (CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_GBL_DATA_OFFSET);
        bd = (bd_t *) (CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_GBL_DATA_OFFSET \
                                                - GENERATED_BD_INFO_SIZE);
-       __maybe_unused char *s;
 #if defined(CONFIG_CMD_FLASH)
        ulong flash_size = 0;
 #endif
@@ -143,8 +142,7 @@ void board_init_f(ulong not_used)
                 *
                 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
                 */
-               s = getenv ("flashchecksum");
-               if (s && (*s == 'y')) {
+               if (getenv_yesno("flashchecksum") == 1) {
                        printf ("  CRC: %08X",
                                crc32(0, (const u8 *)bd->bi_flashstart,
                                                        flash_size)
index e1197ac9e5e70ac9e843298d9bf5e367a7fdb6be..43d4836303d4f02149ce6f9f117dbf5e395be17b 100644 (file)
@@ -46,10 +46,8 @@ u32 get_my_id()
  */
 int hold_cores_in_reset(int verbose)
 {
-       const char *s = getenv("mp_holdoff");
-
        /* Default to no, overriden by 'y', 'yes', 'Y', 'Yes', or '1' */
-       if (s && (*s == 'y' || *s == 'Y' || *s == '1')) {
+       if (getenv_yesno("mp_holdoff") == 1) {
                if (verbose) {
                        puts("Secondary cores are being held in reset.\n");
                        puts("See 'mp_holdoff' environment variable\n");
index 1b051e11c4928b84ef5ee57b7d65d9fe7244749b..6a7bf4b6c21588a02b3d3bb57ed751948e5ceb73 100644 (file)
@@ -739,16 +739,13 @@ void board_init_r(gd_t *id, ulong dest_addr)
                flash_size = 0;
        } else if ((flash_size = flash_init()) > 0) {
 #ifdef CONFIG_SYS_FLASH_CHECKSUM
-               char *s;
-
                print_size(flash_size, "");
                /*
                 * Compute and print flash CRC if flashchecksum is set to 'y'
                 *
                 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
                 */
-               s = getenv("flashchecksum");
-               if (s && (*s == 'y')) {
+               if (getenv_yesno("flashchecksum") == 1) {
                        printf("  CRC: %08X",
                               crc32(0,
                                     (const unsigned char *)
@@ -841,9 +838,7 @@ void board_init_r(gd_t *id, ulong dest_addr)
         * "i2cfast" into account
         */
        {
-               char *s = getenv("i2cfast");
-
-               if (s && ((*s == 'y') || (*s == 'Y'))) {
+               if (getenv_yesno("i2cfast") == 1) {
                        bd->bi_iic_fast[0] = 1;
                        bd->bi_iic_fast[1] = 1;
                }
index 32d025a34237c89c443314035f58c3f6264105f3..1b5e995b15aaae971624fa0b584084c182f646f0 100644 (file)
@@ -284,8 +284,7 @@ void board_init_f(ulong bootflag)
                 *
                 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
                 */
-               s = getenv("flashchecksum");
-               if (s && (*s == 'y')) {
+               if (getenv_yesno("flashchecksum") == 1) {
                        printf("  CRC: %08lX",
                               crc32(0, (const unsigned char *)CONFIG_SYS_FLASH_BASE,
                                     flash_size)
index 6cae68601d34bffdad9760746b0c97600066fbfa..38769e03c536b27ff3b4d6b89a9b11e2bf909141 100644 (file)
@@ -834,15 +834,11 @@ int mem_test_walk (void)
 /*********************************************************************/
 int testdram (void)
 {
-       char *s;
        int rundata, runaddress, runwalk;
 
-       s = getenv ("testdramdata");
-       rundata = (s && (*s == 'y')) ? 1 : 0;
-       s = getenv ("testdramaddress");
-       runaddress = (s && (*s == 'y')) ? 1 : 0;
-       s = getenv ("testdramwalk");
-       runwalk = (s && (*s == 'y')) ? 1 : 0;
+       rundata = getenv_yesno("testdramdata") == 1;
+       runaddress = getenv_yesno("testdramaddress") == 1;
+       runwalk = getenv_yesno("testdramwalk") == 1;
 
 /*    rundata = 1; */
 /*    runaddress = 0; */
index d4f58b3216adf0bdc1e622a71a769c1b64d01ab8..ddb7ed5551d83ebd8ea39e0afcede78730efea3a 100644 (file)
@@ -834,15 +834,11 @@ int mem_test_walk (void)
 /*********************************************************************/
 int testdram (void)
 {
-       char *s;
        int rundata, runaddress, runwalk;
 
-       s = getenv ("testdramdata");
-       rundata = (s && (*s == 'y')) ? 1 : 0;
-       s = getenv ("testdramaddress");
-       runaddress = (s && (*s == 'y')) ? 1 : 0;
-       s = getenv ("testdramwalk");
-       runwalk = (s && (*s == 'y')) ? 1 : 0;
+       rundata = getenv_yesno("testdramdata") == 1;
+       runaddress = getenv_yesno("testdramaddress") == 1;
+       runwalk = getenv_yesno("testdramwalk") == 1;
 
 /*    rundata = 1; */
 /*    runaddress = 0; */
index 98051fb3fbe426985b2a0c2e8ab1a318135d84c5..d7deae4a541c81790a065c6174a9bd12998fea4b 100644 (file)
@@ -953,22 +953,18 @@ int mem_test_walk (void)
 /*********************************************************************/
 int testdram (void)
 {
-       char *s;
        int rundata    = 0;
        int runaddress = 0;
        int runwalk    = 0;
 
 #ifdef CONFIG_SYS_DRAM_TEST_DATA
-       s = getenv ("testdramdata");
-       rundata = (s && (*s == 'y')) ? 1 : 0;
+       rundata = getenv_yesno("testdramdata") == 1;
 #endif
 #ifdef CONFIG_SYS_DRAM_TEST_ADDRESS
-       s = getenv ("testdramaddress");
-       runaddress = (s && (*s == 'y')) ? 1 : 0;
+       runaddress = getenv_yesno("testdramaddress") == 1;
 #endif
 #ifdef CONFIG_SYS_DRAM_TEST_WALK
-       s = getenv ("testdramwalk");
-       runwalk = (s && (*s == 'y')) ? 1 : 0;
+       runwalk = getenv_yesno("testdramwalk") == 1;
 #endif
 
        if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
index 77a1e1d3ac1624779e169ce77984eed5f8d8f1a9..64c54d5e8453554729447567b177f5836d37a0b5 100644 (file)
@@ -544,15 +544,11 @@ int mem_test_walk (void)
 /*********************************************************************/
 int testdram (void)
 {
-       char *s;
        int rundata, runaddress, runwalk;
 
-       s = getenv ("testdramdata");
-       rundata = (s && (*s == 'y')) ? 1 : 0;
-       s = getenv ("testdramaddress");
-       runaddress = (s && (*s == 'y')) ? 1 : 0;
-       s = getenv ("testdramwalk");
-       runwalk = (s && (*s == 'y')) ? 1 : 0;
+       rundata = getenv_yesno("testdramdata") == 1;
+       runaddress = getenv_yesno("testdramaddress") == 1;
+       runwalk = getenv_yesno("testdramwalk") == 1;
 
        if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
                printf ("Testing RAM ... ");
index 389affcde0fda0718c954bb638a1eddad1d5f63d..c3fd19169c95beaa8d22a2ac148c4bcbdfa5b4a8 100644 (file)
@@ -768,22 +768,18 @@ int mem_test_walk (void)
 /*********************************************************************/
 int testdram (void)
 {
-       char *s;
        int rundata    = 0;
        int runaddress = 0;
        int runwalk    = 0;
 
 #ifdef CONFIG_SYS_DRAM_TEST_DATA
-       s = getenv ("testdramdata");
-       rundata = (s && (*s == 'y')) ? 1 : 0;
+       rundata = getenv_yesno("testdramdata") == 1;
 #endif
 #ifdef CONFIG_SYS_DRAM_TEST_ADDRESS
-       s = getenv ("testdramaddress");
-       runaddress = (s && (*s == 'y')) ? 1 : 0;
+       runaddress = getenv_yesno("testdramaddress") == 1;
 #endif
 #ifdef CONFIG_SYS_DRAM_TEST_WALK
-       s = getenv ("testdramwalk");
-       runwalk = (s && (*s == 'y')) ? 1 : 0;
+       runwalk = getenv_yesno("testdramwalk") == 1;
 #endif
 
        if ((rundata == 1) || (runaddress == 1) || (runwalk == 1))
index a960aa8033c3b5a41e717d8712b8550014244a05..067fe3f4c1a846fe12541e4d7282f25704e756d6 100644 (file)
@@ -81,6 +81,20 @@ const uchar *env_get_addr(int index)
                return &default_environment[index];
 }
 
+/*
+ * Read an environment variable as a boolean
+ * Return -1 if variable does not exist (default to true)
+ */
+int getenv_yesno(const char *var)
+{
+       char *s = getenv(var);
+
+       if (s == NULL)
+               return -1;
+       return (*s == '1' || *s == 'y' || *s == 'Y' || *s == 't' || *s == 'T') ?
+               1 : 0;
+}
+
 void set_default_env(const char *s)
 {
        int flags = 0;
index e93b6e89cf9da48a130c265a83b575eba4a0c737..69e888c5d507940b1318cb20c040dd65f8861ad7 100644 (file)
@@ -416,12 +416,6 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
 /* Shared dual-format routines */
 /*****************************************************************************/
 #ifndef USE_HOSTCC
-int getenv_yesno(char *var)
-{
-       char *s = getenv(var);
-       return (s && (*s == 'n')) ? 0 : 1;
-}
-
 ulong getenv_bootm_low(void)
 {
        char *s = getenv("bootm_low");
index 5e3c5eeee14313f02f0ff90a410497b4f25ec595..d0bf1e8ab234b8c66e017a6eef944c1dc3637ec2 100644 (file)
@@ -340,6 +340,11 @@ int        envmatch     (uchar *, int);
 char   *getenv      (const char *);
 int    getenv_f     (const char *name, char *buf, unsigned len);
 ulong getenv_ulong(const char *name, int base, ulong default_val);
+/*
+ * Read an environment variable as a boolean
+ * Return -1 if variable does not exist (default to true)
+ */
+int getenv_yesno(const char *var);
 int    saveenv      (void);
 int    setenv       (const char *, const char *);
 int setenv_ulong(const char *varname, ulong value);
index f54d98330634acb99c56c791d674c3cdb6816c70..b958b18a4de2fd8fc6e8638c90149f74ced088ad 100644 (file)
@@ -460,7 +460,6 @@ static inline void image_set_name(image_header_t *hdr, const char *name)
 int image_check_hcrc(const image_header_t *hdr);
 int image_check_dcrc(const image_header_t *hdr);
 #ifndef USE_HOSTCC
-int getenv_yesno(char *var);
 ulong getenv_bootm_low(void);
 phys_size_t getenv_bootm_size(void);
 phys_size_t getenv_bootm_mapsize(void);
index 82c4cc91179a547f14887c8d1f5e1cf13f84a5af..da68a61d63887f32b11e52274b4ab96aecc9a0ae 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -214,26 +214,24 @@ static int NetTryCount;
  */
 void net_auto_load(void)
 {
+#if defined(CONFIG_CMD_NFS)
        const char *s = getenv("autoload");
 
-       if (s != NULL) {
-               if (*s == 'n') {
-                       /*
-                        * Just use BOOTP/RARP to configure system;
-                        * Do not use TFTP to load the bootfile.
-                        */
-                       net_set_state(NETLOOP_SUCCESS);
-                       return;
-               }
-#if defined(CONFIG_CMD_NFS)
-               if (strcmp(s, "NFS") == 0) {
-                       /*
-                        * Use NFS to load the bootfile.
-                        */
-                       NfsStart();
-                       return;
-               }
+       if (s != NULL && strcmp(s, "NFS") == 0) {
+               /*
+                * Use NFS to load the bootfile.
+                */
+               NfsStart();
+               return;
+       }
 #endif
+       if (getenv_yesno("autoload") == 0) {
+               /*
+                * Just use BOOTP/RARP to configure system;
+                * Do not use TFTP to load the bootfile.
+                */
+               net_set_state(NETLOOP_SUCCESS);
+               return;
        }
        TftpStart(TFTPGET);
 }