]> git.sur5r.net Git - u-boot/commitdiff
env: Add an enum for environment state
authorSimon Glass <sjg@chromium.org>
Thu, 3 Aug 2017 18:21:56 +0000 (12:21 -0600)
committerTom Rini <trini@konsulko.com>
Tue, 15 Aug 2017 12:18:51 +0000 (08:18 -0400)
At present we have three states for the environment, numbered 0, 1 and 2.
Add an enum to record this to avoid open-coded values.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
28 files changed:
board/Arcturus/ucp1020/spl.c
board/freescale/b4860qds/spl.c
board/freescale/c29xpcie/spl.c
board/freescale/p1010rdb/spl.c
board/freescale/p1022ds/spl.c
board/freescale/p1_p2_rdb_pc/spl.c
board/freescale/t102xqds/spl.c
board/freescale/t102xrdb/spl.c
board/freescale/t104xrdb/spl.c
board/freescale/t208xqds/spl.c
board/freescale/t208xrdb/spl.c
board/freescale/t4qds/spl.c
board/freescale/t4rdb/spl.c
env/dataflash.c
env/eeprom.c
env/ext4.c
env/fat.c
env/flash.c
env/mmc.c
env/nand.c
env/nvram.c
env/onenand.c
env/remote.c
env/sata.c
env/sf.c
env/ubi.c
include/asm-generic/global_data.h
include/environment.h

index cd484fc44b3aeaf05a26950e1acba1920b3e496d..b5e7a5db060dc80e9926b66a2482d6608af284e7 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <ns16550.h>
 #include <malloc.h>
 #include <mmc.h>
@@ -99,7 +100,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
        nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
                            (uchar *)CONFIG_ENV_ADDR);
        gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 #else
        env_relocate();
 #endif
index 60d7f0d48a83d513ee23802d73c9d8ed02ad5b5f..b1824b07a2176e5a7dd94174ad03ff7e2b626c21 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <asm/spl.h>
 #include <malloc.h>
 #include <ns16550.h>
@@ -101,7 +102,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
        nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
                            (uchar *)CONFIG_ENV_ADDR);
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 #endif
 
        i2c_init_all();
index 94093f11a88092663cc3e894e3487591c440dbcc..28541a72cb1808685d6d2a71890092a7d0ab16dd 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <ns16550.h>
 #include <malloc.h>
 #include <mmc.h>
@@ -63,7 +64,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
        nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
                            (uchar *)CONFIG_ENV_ADDR);
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        i2c_init_all();
 
index 2cebc2c00218f41ef5e7a91d954abf3467d79d44..001308874e41fefc104220574296cce1112f6f3d 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <ns16550.h>
 #include <malloc.h>
 #include <mmc.h>
@@ -87,7 +88,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
        nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
                            (uchar *)CONFIG_ENV_ADDR);
                            gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 #else
        env_relocate();
 #endif
index a117dc3a2c6eda0c048921a65e7ee7794b15e166..94b357d446812b50673cb50333d9b8132c0514b6 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <ns16550.h>
 #include <malloc.h>
 #include <mmc.h>
@@ -100,7 +101,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
                            (uchar *)CONFIG_ENV_ADDR);
 
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 #else
        env_relocate();
 #endif
index ca7ba5754e25b309e9ae73a54d268c2642c28ee2..c1d4c36b0642c6b2de87a3390934ca8229d8932b 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <ns16550.h>
 #include <malloc.h>
 #include <mmc.h>
@@ -92,7 +93,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
        nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
                            (uchar *)CONFIG_ENV_ADDR);
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 #else
        env_relocate();
 #endif
index b987ecea1d23e0552b81f279c2fa1b84495c2c7a..3aa19e6715ba29e178e51fe33517c6b88fd9163c 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <malloc.h>
 #include <ns16550.h>
 #include <nand.h>
@@ -138,7 +139,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
 #endif
 
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        i2c_init_all();
 
index dc6d9eeef626a785f23c14ab23fafdb5acbfcd4c..ca1e49ffa7b4ce9a73326c4a8036c73a0e979b91 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <malloc.h>
 #include <ns16550.h>
 #include <nand.h>
@@ -125,7 +126,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
 #endif
 
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        i2c_init_all();
 
index 2e43307b2d471c09c30310e31f5b3dcdc26397b7..4fb9323873982979a713bd5a1d2293a50aa23874 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <malloc.h>
 #include <ns16550.h>
 #include <nand.h>
@@ -119,7 +120,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
                               (uchar *)CONFIG_ENV_ADDR);
 #endif
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        i2c_init_all();
 
index d7d716b690a23c833ab07522f2d6480015a038b3..36961dc9b05302bdac0a3153af2a688090b02f99 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <malloc.h>
 #include <ns16550.h>
 #include <nand.h>
@@ -124,7 +125,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
 #endif
 
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        i2c_init_all();
 
index b43140148b18c554cdef10e39fe05095acbd79d2..f0cc34d788e196a33a6092099d19335323b8db0a 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <malloc.h>
 #include <ns16550.h>
 #include <nand.h>
@@ -94,7 +95,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
 #endif
 
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        i2c_init_all();
 
index 9ecdaedda333844a9fa01483260cf4ac025bc8cd..750f1554939be95c8604745e7d4f2c0c750bdbee 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <asm/spl.h>
 #include <malloc.h>
 #include <ns16550.h>
@@ -129,7 +130,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
 #endif
 
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        i2c_init_all();
 
index 5feab1cfcd60951780962337ca0edb5cd641ec91..932954e93df3ee6c1e65e11c5ca9442fe5ab0a64 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <environment.h>
 #include <asm/spl.h>
 #include <malloc.h>
 #include <ns16550.h>
@@ -87,7 +88,7 @@ void board_init_r(gd_t *gd, ulong dest_addr)
                           (uchar *)CONFIG_ENV_ADDR);
 
        gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        i2c_init_all();
 
index 034e3231693e3b751dc41f6e181a9672f03d6540..c140b74c98d94dc53b6346dd7de228adf9811326 100644 (file)
@@ -78,7 +78,7 @@ int env_init(void)
 {
        /* use default */
        gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        return 0;
 }
index 5f63a6cd4a98d71f9b10a924da02000e87667ed1..ac6b30fa8fc3fc6ae1f7b3a2b664e1eb231bc511 100644 (file)
@@ -71,7 +71,7 @@ uchar env_get_char_spec(int index)
        unsigned int off = CONFIG_ENV_OFFSET;
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
-       if (gd->env_valid == 2)
+       if (gd->env_valid == ENV_REDUND)
                off = CONFIG_ENV_OFFSET_REDUND;
 #endif
        eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
@@ -128,21 +128,21 @@ void env_relocate_spec(void)
                gd->env_addr    = 0;
                gd->env_valid   = 0;
        } else if (crc_ok[0] && !crc_ok[1]) {
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
        } else if (!crc_ok[0] && crc_ok[1]) {
-               gd->env_valid = 2;
+               gd->env_valid = ENV_REDUND;
        } else {
                /* both ok - check serial */
                if (flags[0] == ACTIVE_FLAG && flags[1] == OBSOLETE_FLAG)
-                       gd->env_valid = 1;
+                       gd->env_valid = ENV_VALID;
                else if (flags[0] == OBSOLETE_FLAG && flags[1] == ACTIVE_FLAG)
-                       gd->env_valid = 2;
+                       gd->env_valid = ENV_REDUND;
                else if (flags[0] == 0xFF && flags[1] == 0)
-                       gd->env_valid = 2;
+                       gd->env_valid = ENV_REDUND;
                else if (flags[1] == 0xFF && flags[0] == 0)
-                       gd->env_valid = 1;
+                       gd->env_valid = ENV_VALID;
                else /* flags are equal - almost impossible */
-                       gd->env_valid = 1;
+                       gd->env_valid = ENV_VALID;
        }
 
 #else /* CONFIG_ENV_OFFSET_REDUND */
@@ -170,7 +170,7 @@ void env_relocate_spec(void)
        }
 
        if (crc == new) {
-               gd->env_valid   = 1;
+               gd->env_valid   = ENV_VALID;
        } else {
                gd->env_valid   = 0;
        }
@@ -178,7 +178,7 @@ void env_relocate_spec(void)
 
        off = CONFIG_ENV_OFFSET;
 #ifdef CONFIG_ENV_OFFSET_REDUND
-       if (gd->env_valid == 2)
+       if (gd->env_valid == ENV_REDUND)
                off = CONFIG_ENV_OFFSET_REDUND;
 #endif
 
@@ -205,7 +205,7 @@ int saveenv(void)
                return rc;
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
-       if (gd->env_valid == 1) {
+       if (gd->env_valid == ENV_VALID) {
                off     = CONFIG_ENV_OFFSET_REDUND;
                off_red = CONFIG_ENV_OFFSET;
        }
@@ -222,10 +222,10 @@ int saveenv(void)
                                 off_red + offsetof(env_t, flags),
                                 (uchar *)&flag_obsolete, 1);
 
-               if (gd->env_valid == 1)
-                       gd->env_valid = 2;
+               if (gd->env_valid == ENV_VALID)
+                       gd->env_valid = ENV_REDUND;
                else
-                       gd->env_valid = 1;
+                       gd->env_valid = ENV_VALID;
        }
 #endif
        return rc;
@@ -240,6 +240,6 @@ int saveenv(void)
 int env_init(void)
 {
        gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
        return 0;
 }
index adefa7dc991ee5f7cd4f415cd79223803bf38a16..7bb4ce7cffa1e88af380a71da3038c4c91780bee 100644 (file)
@@ -41,7 +41,7 @@ int env_init(void)
 {
        /* use default */
        gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        return 0;
 }
index b51c920cd45fdc01cda9d5ad353c184b73f8e395..129b945a2f7eb2f5f796dd362a41665156609153 100644 (file)
--- a/env/fat.c
+++ b/env/fat.c
@@ -29,7 +29,7 @@ int env_init(void)
 {
        /* use default */
        gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        return 0;
 }
index 004e8849a7dd23508dd790a41e3298f92b167c43..dcf3cd2c62cfd7bd399c6c379c84b98a4908b925 100644 (file)
@@ -75,28 +75,28 @@ int env_init(void)
 
        if (crc1_ok && !crc2_ok) {
                gd->env_addr    = addr1;
-               gd->env_valid   = 1;
+               gd->env_valid   = ENV_VALID;
        } else if (!crc1_ok && crc2_ok) {
                gd->env_addr    = addr2;
-               gd->env_valid   = 1;
+               gd->env_valid   = ENV_VALID;
        } else if (!crc1_ok && !crc2_ok) {
                gd->env_addr    = addr_default;
                gd->env_valid   = 0;
        } else if (flag1 == ACTIVE_FLAG && flag2 == OBSOLETE_FLAG) {
                gd->env_addr    = addr1;
-               gd->env_valid   = 1;
+               gd->env_valid   = ENV_VALID;
        } else if (flag1 == OBSOLETE_FLAG && flag2 == ACTIVE_FLAG) {
                gd->env_addr    = addr2;
-               gd->env_valid   = 1;
+               gd->env_valid   = ENV_VALID;
        } else if (flag1 == flag2) {
                gd->env_addr    = addr1;
-               gd->env_valid   = 2;
+               gd->env_valid   = ENV_REDUND;
        } else if (flag1 == 0xFF) {
                gd->env_addr    = addr1;
-               gd->env_valid   = 2;
+               gd->env_valid   = ENV_REDUND;
        } else if (flag2 == 0xFF) {
                gd->env_addr    = addr2;
-               gd->env_valid   = 2;
+               gd->env_valid   = ENV_REDUND;
        }
 
        return 0;
@@ -211,7 +211,7 @@ int env_init(void)
 {
        if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
                gd->env_addr    = (ulong)&(env_ptr->data);
-               gd->env_valid   = 1;
+               gd->env_valid   = ENV_VALID;
                return 0;
        }
 
@@ -309,7 +309,7 @@ void env_relocate_spec(void)
            crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc) {
                char flag = OBSOLETE_FLAG;
 
-               gd->env_valid = 2;
+               gd->env_valid = ENV_REDUND;
                flash_sect_protect(0, (ulong)flash_addr_new, end_addr_new);
                flash_write(&flag,
                            (ulong)&(flash_addr_new->flags),
@@ -321,7 +321,7 @@ void env_relocate_spec(void)
            (flash_addr->flags & ACTIVE_FLAG) == ACTIVE_FLAG) {
                char flag = ACTIVE_FLAG;
 
-               gd->env_valid = 2;
+               gd->env_valid = ENV_REDUND;
                flash_sect_protect(0, (ulong)flash_addr, end_addr);
                flash_write(&flag,
                            (ulong)&(flash_addr->flags),
@@ -329,7 +329,7 @@ void env_relocate_spec(void)
                flash_sect_protect(1, (ulong)flash_addr, end_addr);
        }
 
-       if (gd->env_valid == 2)
+       if (gd->env_valid == ENV_REDUND)
                puts("*** Warning - some problems detected "
                     "reading environment; recovered successfully\n\n");
 #endif /* CONFIG_ENV_ADDR_REDUND */
index bb760a00ed82db5b563fc861437f3ae1f9aa2049..e387202e714731697800b340b3e19674311d3e31 100644 (file)
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -86,7 +86,7 @@ int env_init(void)
 {
        /* use default */
        gd->env_addr    = (ulong)&default_environment[0];
-       gd->env_valid   = 1;
+       gd->env_valid   = ENV_VALID;
 
        return 0;
 }
@@ -180,7 +180,7 @@ int saveenv(void)
                goto fini;
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
-       if (gd->env_valid == 1)
+       if (gd->env_valid == ENV_VALID)
                copy = 1;
 #endif
 
@@ -200,7 +200,7 @@ int saveenv(void)
        ret = 0;
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
-       gd->env_valid = gd->env_valid == 2 ? 1 : 2;
+       gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
 #endif
 
 fini:
@@ -265,10 +265,10 @@ void env_relocate_spec(void)
                ret = 1;
                goto fini;
        } else if (!read1_fail && read2_fail) {
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
                env_import((char *)tmp_env1, 1);
        } else if (read1_fail && !read2_fail) {
-               gd->env_valid = 2;
+               gd->env_valid = ENV_REDUND;
                env_import((char *)tmp_env2, 1);
        } else {
                env_import_redund((char *)tmp_env1, (char *)tmp_env2);
index 760f6859e354daeaa5299cf159f53938ae64f975..90f274bf8aab9d13dc753d047d7bd9ef9a84ac52 100644 (file)
@@ -84,37 +84,37 @@ int env_init(void)
 
                return 0;
        } else if (crc1_ok && !crc2_ok) {
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
        }
 #ifdef CONFIG_ENV_OFFSET_REDUND
        else if (!crc1_ok && crc2_ok) {
-               gd->env_valid = 2;
+               gd->env_valid = ENV_REDUND;
        } else {
                /* both ok - check serial */
                if (tmp_env1->flags == 255 && tmp_env2->flags == 0)
-                       gd->env_valid = 2;
+                       gd->env_valid = ENV_REDUND;
                else if (tmp_env2->flags == 255 && tmp_env1->flags == 0)
-                       gd->env_valid = 1;
+                       gd->env_valid = ENV_VALID;
                else if (tmp_env1->flags > tmp_env2->flags)
-                       gd->env_valid = 1;
+                       gd->env_valid = ENV_VALID;
                else if (tmp_env2->flags > tmp_env1->flags)
-                       gd->env_valid = 2;
+                       gd->env_valid = ENV_REDUND;
                else /* flags are equal - almost impossible */
-                       gd->env_valid = 1;
+                       gd->env_valid = ENV_VALID;
        }
 
-       if (gd->env_valid == 2)
+       if (gd->env_valid == ENV_REDUND)
                env_ptr = tmp_env2;
        else
 #endif
-       if (gd->env_valid == 1)
+       if (gd->env_valid == ENV_VALID)
                env_ptr = tmp_env1;
 
        gd->env_addr = (ulong)env_ptr->data;
 
 #else /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */
        gd->env_addr    = (ulong)&default_environment[0];
-       gd->env_valid   = 1;
+       gd->env_valid   = ENV_VALID;
 #endif /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */
 
        return 0;
@@ -217,14 +217,15 @@ int saveenv(void)
                return ret;
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
-       env_idx = (gd->env_valid == 1);
+       env_idx = (gd->env_valid == ENV_VALID);
 #endif
 
        ret = erase_and_write_env(&location[env_idx], (u_char *)env_new);
 #ifdef CONFIG_ENV_OFFSET_REDUND
        if (!ret) {
                /* preset other copy for next write */
-               gd->env_valid = gd->env_valid == 2 ? 1 : 2;
+               gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID :
+                               ENV_REDUND;
                return ret;
        }
 
@@ -342,10 +343,10 @@ void env_relocate_spec(void)
                set_default_env("!bad env area");
                goto done;
        } else if (!read1_fail && read2_fail) {
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
                env_import((char *)tmp_env1, 1);
        } else if (read1_fail && !read2_fail) {
-               gd->env_valid = 2;
+               gd->env_valid = ENV_REDUND;
                env_import((char *)tmp_env2, 1);
        } else {
                env_import_redund((char *)tmp_env1, (char *)tmp_env2);
index 524f07d5f8967460ac37dd7eb453f385f54cafc8..d046c9393cff7bbdbd24de996884f36e8538e9f5 100644 (file)
@@ -104,7 +104,7 @@ int env_init(void)
        if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
                gd->env_addr    = (ulong)&env_ptr->data;
 #endif
-               gd->env_valid   = 1;
+               gd->env_valid = ENV_VALID;
        } else {
                gd->env_addr    = (ulong)&default_environment[0];
                gd->env_valid   = 0;
index cc3d670de83d4314834695c86ef8ab654f56a8fd..d7ad45a0e549ae639fc129aec453c720d86eb4dd 100644 (file)
@@ -60,7 +60,7 @@ void env_relocate_spec(void)
 
        rc = env_import(buf, 1);
        if (rc)
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
 }
 
 int saveenv(void)
@@ -110,7 +110,7 @@ int env_init(void)
 {
        /* use default */
        gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        return 0;
 }
index eb977ee1fe81a2b3398b5c27f94f7f95eef2a299..e003e02fb9ec6c8ec8035a220eeec049bcc941de 100644 (file)
@@ -29,7 +29,7 @@ int env_init(void)
 {
        if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
                gd->env_addr = (ulong)&(env_ptr->data);
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
                return 0;
        }
 
index b0cee35a60fd60f80fea0c4b9bbd445993e0c664..64589117f25a357758b12483a1bc9c62b4450ce0 100644 (file)
@@ -37,7 +37,7 @@ int env_init(void)
 {
        /* use default */
        gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        return 0;
 }
index 45f441a042b5ec0caedf226c81754ba63106c041..1da354913861eb90c5e0e138efb29cc3fac7faad 100644 (file)
--- a/env/sf.c
+++ b/env/sf.c
@@ -93,7 +93,7 @@ int saveenv(void)
                return ret;
        env_new.flags   = ACTIVE_FLAG;
 
-       if (gd->env_valid == 1) {
+       if (gd->env_valid == ENV_VALID) {
                env_new_offset = CONFIG_ENV_OFFSET_REDUND;
                env_offset = CONFIG_ENV_OFFSET;
        } else {
@@ -145,7 +145,7 @@ int saveenv(void)
 
        puts("done\n");
 
-       gd->env_valid = gd->env_valid == 2 ? 1 : 2;
+       gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
 
        printf("Valid environment: %d\n", (int)gd->env_valid);
 
@@ -198,30 +198,30 @@ void env_relocate_spec(void)
                set_default_env("!bad CRC");
                goto err_read;
        } else if (crc1_ok && !crc2_ok) {
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
        } else if (!crc1_ok && crc2_ok) {
-               gd->env_valid = 2;
+               gd->env_valid = ENV_REDUND;
        } else if (tmp_env1->flags == ACTIVE_FLAG &&
                   tmp_env2->flags == OBSOLETE_FLAG) {
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
        } else if (tmp_env1->flags == OBSOLETE_FLAG &&
                   tmp_env2->flags == ACTIVE_FLAG) {
-               gd->env_valid = 2;
+               gd->env_valid = ENV_REDUND;
        } else if (tmp_env1->flags == tmp_env2->flags) {
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
        } else if (tmp_env1->flags == 0xFF) {
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
        } else if (tmp_env2->flags == 0xFF) {
-               gd->env_valid = 2;
+               gd->env_valid = ENV_REDUND;
        } else {
                /*
                 * this differs from code in env_flash.c, but I think a sane
                 * default path is desirable.
                 */
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
        }
 
-       if (gd->env_valid == 1)
+       if (gd->env_valid == ENV_VALID)
                ep = tmp_env1;
        else
                ep = tmp_env2;
@@ -324,7 +324,7 @@ void env_relocate_spec(void)
 
        ret = env_import(buf, 1);
        if (ret)
-               gd->env_valid = 1;
+               gd->env_valid = ENV_VALID;
 
 err_read:
        spi_flash_free(env_flash);
@@ -338,7 +338,7 @@ int env_init(void)
 {
        /* SPI flash isn't usable before relocation */
        gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        return 0;
 }
index 95b527ddca47c60c7dbe6a55cde935b523a1f8e0..542371df8fec29623403ecf25fe3a24d09310082 100644 (file)
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -26,7 +26,7 @@ int env_init(void)
 {
        /* use default */
        gd->env_addr = (ulong)&default_environment[0];
-       gd->env_valid = 1;
+       gd->env_valid = ENV_VALID;
 
        return 0;
 }
@@ -48,7 +48,7 @@ int saveenv(void)
                return 1;
        }
 
-       if (gd->env_valid == 1) {
+       if (gd->env_valid == ENV_VALID) {
                puts("Writing to redundant UBI... ");
                if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME_REDUND,
                                     (void *)env_new, CONFIG_ENV_SIZE)) {
@@ -70,7 +70,7 @@ int saveenv(void)
 
        puts("done\n");
 
-       gd->env_valid = gd->env_valid == 2 ? 1 : 2;
+       gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
 
        return 0;
 }
index 86bf6565f689ede5d33747769f3b45b8b4eb687a..8b32d514c344e680b0aeefd78951aa67ac70439a 100644 (file)
@@ -49,7 +49,7 @@ typedef struct global_data {
        unsigned long precon_buf_idx;   /* Pre-Console buffer index */
 #endif
        unsigned long env_addr;         /* Address  of Environment struct */
-       unsigned long env_valid;        /* Checksum of Environment valid? */
+       unsigned long env_valid;        /* Environment valid? enum env_valid */
 
        unsigned long ram_top;          /* Top address of RAM used by U-Boot */
        unsigned long relocaddr;        /* Start address of U-Boot in RAM */
index 5f2064bf23303020649078b79d3fb21d9681b1b5..ad2331c90b4d8f2e1f162b37ad1b6174b7c9a368 100644 (file)
@@ -197,6 +197,13 @@ extern uint mmc_get_env_part(struct mmc *mmc);
 #include <env_flags.h>
 #include <search.h>
 
+/* Value for environment validity */
+enum env_valid {
+       ENV_INVALID,    /* No valid environment */
+       ENV_VALID,      /* First or only environment is valid */
+       ENV_REDUND,     /* Redundant environment is valid */
+};
+
 extern struct hsearch_data env_htab;
 
 /* Function that returns a character from the environment */