[U-Boot] [PATCH v2 19/34] env: Add an enum for environment state

Simon Glass sjg at chromium.org
Mon Jul 24 03:19:54 UTC 2017


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 at chromium.org>
---

Changes in v2: None

 board/Arcturus/ucp1020/spl.c       |  3 ++-
 board/freescale/b4860qds/spl.c     |  3 ++-
 board/freescale/c29xpcie/spl.c     |  3 ++-
 board/freescale/p1010rdb/spl.c     |  3 ++-
 board/freescale/p1022ds/spl.c      |  3 ++-
 board/freescale/p1_p2_rdb_pc/spl.c |  3 ++-
 board/freescale/t102xqds/spl.c     |  3 ++-
 board/freescale/t102xrdb/spl.c     |  3 ++-
 board/freescale/t104xrdb/spl.c     |  3 ++-
 board/freescale/t208xqds/spl.c     |  3 ++-
 board/freescale/t208xrdb/spl.c     |  3 ++-
 board/freescale/t4qds/spl.c        |  3 ++-
 board/freescale/t4rdb/spl.c        |  3 ++-
 env/dataflash.c                    |  2 +-
 env/eeprom.c                       | 30 ++++++++++++++--------------
 env/ext4.c                         |  2 +-
 env/fat.c                          |  2 +-
 env/flash.c                        | 22 ++++++++++----------
 env/mmc.c                          | 22 ++++++++++----------
 env/nand.c                         | 41 +++++++++++++++++++-------------------
 env/nvram.c                        |  2 +-
 env/onenand.c                      |  4 ++--
 env/remote.c                       |  2 +-
 env/sata.c                         |  2 +-
 env/sf.c                           | 26 ++++++++++++------------
 env/ubi.c                          | 22 ++++++++++----------
 include/asm-generic/global_data.h  |  2 +-
 include/environment.h              |  7 +++++++
 28 files changed, 124 insertions(+), 103 deletions(-)

diff --git a/board/Arcturus/ucp1020/spl.c b/board/Arcturus/ucp1020/spl.c
index cd484fc44b..b5e7a5db06 100644
--- a/board/Arcturus/ucp1020/spl.c
+++ b/board/Arcturus/ucp1020/spl.c
@@ -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
diff --git a/board/freescale/b4860qds/spl.c b/board/freescale/b4860qds/spl.c
index 60d7f0d48a..b1824b07a2 100644
--- a/board/freescale/b4860qds/spl.c
+++ b/board/freescale/b4860qds/spl.c
@@ -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();
diff --git a/board/freescale/c29xpcie/spl.c b/board/freescale/c29xpcie/spl.c
index 94093f11a8..28541a72cb 100644
--- a/board/freescale/c29xpcie/spl.c
+++ b/board/freescale/c29xpcie/spl.c
@@ -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();
 
diff --git a/board/freescale/p1010rdb/spl.c b/board/freescale/p1010rdb/spl.c
index 2cebc2c002..001308874e 100644
--- a/board/freescale/p1010rdb/spl.c
+++ b/board/freescale/p1010rdb/spl.c
@@ -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
diff --git a/board/freescale/p1022ds/spl.c b/board/freescale/p1022ds/spl.c
index a117dc3a2c..94b357d446 100644
--- a/board/freescale/p1022ds/spl.c
+++ b/board/freescale/p1022ds/spl.c
@@ -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
diff --git a/board/freescale/p1_p2_rdb_pc/spl.c b/board/freescale/p1_p2_rdb_pc/spl.c
index ca7ba5754e..c1d4c36b06 100644
--- a/board/freescale/p1_p2_rdb_pc/spl.c
+++ b/board/freescale/p1_p2_rdb_pc/spl.c
@@ -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
diff --git a/board/freescale/t102xqds/spl.c b/board/freescale/t102xqds/spl.c
index b987ecea1d..3aa19e6715 100644
--- a/board/freescale/t102xqds/spl.c
+++ b/board/freescale/t102xqds/spl.c
@@ -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();
 
diff --git a/board/freescale/t102xrdb/spl.c b/board/freescale/t102xrdb/spl.c
index dc6d9eeef6..ca1e49ffa7 100644
--- a/board/freescale/t102xrdb/spl.c
+++ b/board/freescale/t102xrdb/spl.c
@@ -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();
 
diff --git a/board/freescale/t104xrdb/spl.c b/board/freescale/t104xrdb/spl.c
index 2e43307b2d..4fb9323873 100644
--- a/board/freescale/t104xrdb/spl.c
+++ b/board/freescale/t104xrdb/spl.c
@@ -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();
 
diff --git a/board/freescale/t208xqds/spl.c b/board/freescale/t208xqds/spl.c
index d7d716b690..36961dc9b0 100644
--- a/board/freescale/t208xqds/spl.c
+++ b/board/freescale/t208xqds/spl.c
@@ -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();
 
diff --git a/board/freescale/t208xrdb/spl.c b/board/freescale/t208xrdb/spl.c
index b43140148b..f0cc34d788 100644
--- a/board/freescale/t208xrdb/spl.c
+++ b/board/freescale/t208xrdb/spl.c
@@ -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();
 
diff --git a/board/freescale/t4qds/spl.c b/board/freescale/t4qds/spl.c
index 9ecdaedda3..750f155493 100644
--- a/board/freescale/t4qds/spl.c
+++ b/board/freescale/t4qds/spl.c
@@ -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();
 
diff --git a/board/freescale/t4rdb/spl.c b/board/freescale/t4rdb/spl.c
index 5feab1cfcd..932954e93d 100644
--- a/board/freescale/t4rdb/spl.c
+++ b/board/freescale/t4rdb/spl.c
@@ -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();
 
diff --git a/env/dataflash.c b/env/dataflash.c
index 034e323169..c140b74c98 100644
--- a/env/dataflash.c
+++ b/env/dataflash.c
@@ -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;
 }
diff --git a/env/eeprom.c b/env/eeprom.c
index 5f63a6cd4a..ac6b30fa8f 100644
--- a/env/eeprom.c
+++ b/env/eeprom.c
@@ -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;
 }
diff --git a/env/ext4.c b/env/ext4.c
index adefa7dc99..7bb4ce7cff 100644
--- a/env/ext4.c
+++ b/env/ext4.c
@@ -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;
 }
diff --git a/env/fat.c b/env/fat.c
index 75616d4c5b..5a2131a5a9 100644
--- 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;
 }
diff --git a/env/flash.c b/env/flash.c
index 004e8849a7..dcf3cd2c62 100644
--- a/env/flash.c
+++ b/env/flash.c
@@ -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 */
diff --git a/env/mmc.c b/env/mmc.c
index 88b043ec35..32764a15c9 100644
--- 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;
 }
@@ -186,7 +186,7 @@ int saveenv(void)
 #ifdef CONFIG_ENV_OFFSET_REDUND
 	env_new->flags	= ++env_flags; /* increase the serial */
 
-	if (gd->env_valid == 1)
+	if (gd->env_valid == ENV_VALID)
 		copy = 1;
 #endif
 
@@ -206,7 +206,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:
@@ -278,26 +278,26 @@ void env_relocate_spec(void)
 		ret = 1;
 		goto fini;
 	} 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 {
 		/* 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;
 	}
 
 	free(env_ptr);
 
-	if (gd->env_valid == 1)
+	if (gd->env_valid == ENV_VALID)
 		ep = tmp_env1;
 	else
 		ep = tmp_env2;
diff --git a/env/nand.c b/env/nand.c
index 133ecfbb8e..357f1baf7a 100644
--- a/env/nand.c
+++ b/env/nand.c
@@ -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;
@@ -222,14 +222,15 @@ int saveenv(void)
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
 	env_new->flags = ++env_flags; /* increase the serial */
-	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;
 	}
 
@@ -353,26 +354,26 @@ void env_relocate_spec(void)
 		set_default_env("!bad CRC");
 		goto done;
 	} 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 {
 		/* 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;
 	}
 
 	free(env_ptr);
 
-	if (gd->env_valid == 1)
+	if (gd->env_valid == ENV_VALID)
 		ep = tmp_env1;
 	else
 		ep = tmp_env2;
diff --git a/env/nvram.c b/env/nvram.c
index 524f07d5f8..d046c9393c 100644
--- a/env/nvram.c
+++ b/env/nvram.c
@@ -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;
diff --git a/env/onenand.c b/env/onenand.c
index cc3d670de8..d7ad45a0e5 100644
--- a/env/onenand.c
+++ b/env/onenand.c
@@ -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;
 }
diff --git a/env/remote.c b/env/remote.c
index eb977ee1fe..e003e02fb9 100644
--- a/env/remote.c
+++ b/env/remote.c
@@ -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;
 	}
 
diff --git a/env/sata.c b/env/sata.c
index b0cee35a60..64589117f2 100644
--- a/env/sata.c
+++ b/env/sata.c
@@ -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;
 }
diff --git a/env/sf.c b/env/sf.c
index 45f441a042..1da3549138 100644
--- 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;
 }
diff --git a/env/ubi.c b/env/ubi.c
index 0ac2f65f0b..d37095db0c 100644
--- 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;
 }
@@ -52,7 +52,7 @@ int saveenv(void)
 
 	env_new->flags = ++env_flags; /* increase the serial */
 
-	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)) {
@@ -74,7 +74,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;
 }
@@ -155,24 +155,24 @@ void env_relocate_spec(void)
 		set_default_env("!bad CRC");
 		return;
 	} 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 {
 		/* 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 == 1)
+	if (gd->env_valid == ENV_VALID)
 		ep = tmp_env1;
 	else
 		ep = tmp_env2;
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index fb90be9d3e..d8d1b444f2 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -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 */
diff --git a/include/environment.h b/include/environment.h
index d6aa1f0fff..b4c8c48717 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -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 */
-- 
2.14.0.rc0.284.gd933b75aa4-goog



More information about the U-Boot mailing list