]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
env: Rename the redundancy flags
authorSimon Glass <sjg@chromium.org>
Thu, 1 Aug 2019 15:47:08 +0000 (09:47 -0600)
committerTom Rini <trini@konsulko.com>
Sun, 11 Aug 2019 20:43:41 +0000 (16:43 -0400)
Add an ENV prefix to these two flags so that it is clear what they relate
to. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass <sjg@chromium.org>
cmd/nvedit.c
env/eeprom.c
env/flash.c
env/sf.c
include/env.h
include/environment.h
tools/env/fw_env.c

index 39140c07339c66e6f7f92c05e7f42261777f3753..995b6b37af680c17a107001c17895cd830ae3f1d 100644 (file)
@@ -1002,7 +1002,7 @@ NXTARG:           ;
                envp->crc = crc32(0, envp->data,
                                size ? size - offsetof(env_t, data) : ENV_SIZE);
 #ifdef CONFIG_ENV_ADDR_REDUND
-               envp->flags = ACTIVE_FLAG;
+               envp->flags = ENV_REDUND_ACTIVE;
 #endif
        }
        env_set_hex("filesize", len + offsetof(env_t, data));
index 8d82cf892ce5d83b7c67d00dfdb685b7fce7e920..91ee3f35ebf3573b73f69abd83fe2406e3d54a39 100644 (file)
@@ -132,9 +132,11 @@ static int env_eeprom_load(void)
                gd->env_valid = ENV_REDUND;
        } else {
                /* both ok - check serial */
-               if (flags[0] == ACTIVE_FLAG && flags[1] == OBSOLETE_FLAG)
+               if (flags[0] == ENV_REDUND_ACTIVE &&
+                   flags[1] == ENV_REDUND_OBSOLETE)
                        gd->env_valid = ENV_VALID;
-               else if (flags[0] == OBSOLETE_FLAG && flags[1] == ACTIVE_FLAG)
+               else if (flags[0] == ENV_REDUND_OBSOLETE &&
+                        flags[1] == ENV_REDUND_ACTIVE)
                        gd->env_valid = ENV_REDUND;
                else if (flags[0] == 0xFF && flags[1] == 0)
                        gd->env_valid = ENV_REDUND;
@@ -194,7 +196,7 @@ static int env_eeprom_save(void)
        unsigned int off        = CONFIG_ENV_OFFSET;
 #ifdef CONFIG_ENV_OFFSET_REDUND
        unsigned int off_red    = CONFIG_ENV_OFFSET_REDUND;
-       char flag_obsolete      = OBSOLETE_FLAG;
+       char flag_obsolete      = ENV_REDUND_OBSOLETE;
 #endif
 
        rc = env_export(&env_new);
@@ -207,7 +209,7 @@ static int env_eeprom_save(void)
                off_red = CONFIG_ENV_OFFSET;
        }
 
-       env_new.flags = ACTIVE_FLAG;
+       env_new.flags = ENV_REDUND_ACTIVE;
 #endif
 
        rc = eeprom_bus_write(CONFIG_SYS_DEF_EEPROM_ADDR,
index 7a73466cf2517a5a4c89e0ba752af1a58d6b9f45..bdba09e306291c4f52f01c4cdd2b54884a956614 100644 (file)
@@ -95,10 +95,12 @@ static int env_flash_init(void)
        } else if (!crc1_ok && !crc2_ok) {
                gd->env_addr    = addr_default;
                gd->env_valid   = ENV_INVALID;
-       } else if (flag1 == ACTIVE_FLAG && flag2 == OBSOLETE_FLAG) {
+       } else if (flag1 == ENV_REDUND_ACTIVE &&
+                  flag2 == ENV_REDUND_OBSOLETE) {
                gd->env_addr    = addr1;
                gd->env_valid   = ENV_VALID;
-       } else if (flag1 == OBSOLETE_FLAG && flag2 == ACTIVE_FLAG) {
+       } else if (flag1 == ENV_REDUND_OBSOLETE &&
+                  flag2 == ENV_REDUND_ACTIVE) {
                gd->env_addr    = addr2;
                gd->env_valid   = ENV_VALID;
        } else if (flag1 == flag2) {
@@ -121,7 +123,7 @@ static int env_flash_save(void)
 {
        env_t   env_new;
        char    *saved_data = NULL;
-       char    flag = OBSOLETE_FLAG, new_flag = ACTIVE_FLAG;
+       char    flag = ENV_REDUND_OBSOLETE, new_flag = ENV_REDUND_ACTIVE;
        int     rc = 1;
 #if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
        ulong   up_data = 0;
@@ -322,9 +324,9 @@ static int env_flash_load(void)
                end_addr_new = ltmp;
        }
 
-       if (flash_addr_new->flags != OBSOLETE_FLAG &&
+       if (flash_addr_new->flags != ENV_REDUND_OBSOLETE &&
            crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc) {
-               char flag = OBSOLETE_FLAG;
+               char flag = ENV_REDUND_OBSOLETE;
 
                gd->env_valid = ENV_REDUND;
                flash_sect_protect(0, (ulong)flash_addr_new, end_addr_new);
@@ -334,9 +336,9 @@ static int env_flash_load(void)
                flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new);
        }
 
-       if (flash_addr->flags != ACTIVE_FLAG &&
-           (flash_addr->flags & ACTIVE_FLAG) == ACTIVE_FLAG) {
-               char flag = ACTIVE_FLAG;
+       if (flash_addr->flags != ENV_REDUND_ACTIVE &&
+           (flash_addr->flags & ENV_REDUND_ACTIVE) == ENV_REDUND_ACTIVE) {
+               char flag = ENV_REDUND_ACTIVE;
 
                gd->env_valid = ENV_REDUND;
                flash_sect_protect(0, (ulong)flash_addr, end_addr);
index 5531293e05697c8a6d29e45826641a10830f1bc9..09646e1eed1ffa191740dee7d13a7a269aad991b 100644 (file)
--- a/env/sf.c
+++ b/env/sf.c
@@ -30,8 +30,6 @@ static ulong env_offset               = CONFIG_ENV_OFFSET;
 static ulong env_new_offset    = CONFIG_ENV_OFFSET_REDUND;
 #endif
 
-#define ACTIVE_FLAG    1
-#define OBSOLETE_FLAG  0
 #endif /* CONFIG_ENV_OFFSET_REDUND */
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -74,7 +72,7 @@ static int setup_flash_device(void)
 static int env_sf_save(void)
 {
        env_t   env_new;
-       char    *saved_buffer = NULL, flag = OBSOLETE_FLAG;
+       char    *saved_buffer = NULL, flag = ENV_REDUND_OBSOLETE;
        u32     saved_size, saved_offset, sector;
        int     ret;
 
@@ -85,7 +83,7 @@ static int env_sf_save(void)
        ret = env_export(&env_new);
        if (ret)
                return -EIO;
-       env_new.flags   = ACTIVE_FLAG;
+       env_new.flags   = ENV_REDUND_ACTIVE;
 
        if (gd->env_valid == ENV_VALID) {
                env_new_offset = CONFIG_ENV_OFFSET_REDUND;
index 271cb3e88838cdafcbbde03c2ec73d776f766014..a74a261337e640024f1a6ebac5eb4d9014a37d2b 100644 (file)
@@ -55,6 +55,12 @@ struct env_clbk_tbl {
        {#name, callback}
 #endif
 
+/** enum env_redund_flags - Flags for the redundand_environment */
+enum env_redund_flags {
+       ENV_REDUND_OBSOLETE = 0,
+       ENV_REDUND_ACTIVE = 1,
+};
+
 /**
  * env_get_id() - Gets a sequence number for the environment
  *
index c3e8d7840a88dd402d5e29183448bfe242d783ee..70ee0fdb192c6d80bad3ad741d167ff21a5ea148 100644 (file)
@@ -135,9 +135,6 @@ extern unsigned long nand_env_oob_offset;
 
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
 # define ENV_HEADER_SIZE       (sizeof(uint32_t) + 1)
-
-# define ACTIVE_FLAG   1
-# define OBSOLETE_FLAG 0
 #else
 # define ENV_HEADER_SIZE       (sizeof(uint32_t))
 #endif
@@ -147,7 +144,7 @@ extern unsigned long nand_env_oob_offset;
 typedef struct environment_s {
        uint32_t        crc;            /* CRC32 over data bytes        */
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
-       unsigned char   flags;          /* active/obsolete flags        */
+       unsigned char   flags;          /* active/obsolete flags ENVF_REDUND_ */
 #endif
        unsigned char   data[ENV_SIZE]; /* Environment data             */
 } env_t;
index f06252d9168af09a6e31e48f59570e3380c36f22..95c99847a3af2647aef191deea2361293625a6fd 100644 (file)
@@ -119,9 +119,12 @@ static struct environment environment = {
 
 static int have_redund_env;
 
-static unsigned char active_flag = 1;
-/* obsolete_flag must be 0 to efficiently set it on NOR flash without erasing */
-static unsigned char obsolete_flag = 0;
+static unsigned char ENV_REDUND_ACTIVE = 1;
+/*
+ * ENV_REDUND_OBSOLETE must be 0 to efficiently set it on NOR flash without
+ * erasing
+ */
+static unsigned char ENV_REDUND_OBSOLETE;
 
 #define DEFAULT_ENV_INSTANCE_STATIC
 #include <env_default.h>
@@ -1142,7 +1145,7 @@ static int flash_flag_obsolete(int dev, int fd, off_t offset)
 
        erase.start = DEVOFFSET(dev);
        erase.length = DEVESIZE(dev);
-       /* This relies on the fact, that obsolete_flag == 0 */
+       /* This relies on the fact, that ENV_REDUND_OBSOLETE == 0 */
        rc = lseek(fd, offset, SEEK_SET);
        if (rc < 0) {
                fprintf(stderr, "Cannot seek to set the flag on %s\n",
@@ -1150,7 +1153,7 @@ static int flash_flag_obsolete(int dev, int fd, off_t offset)
                return rc;
        }
        ioctl(fd, MEMUNLOCK, &erase);
-       rc = write(fd, &obsolete_flag, sizeof(obsolete_flag));
+       rc = write(fd, &ENV_REDUND_OBSOLETE, sizeof(ENV_REDUND_OBSOLETE));
        ioctl(fd, MEMLOCK, &erase);
        if (rc < 0)
                perror("Could not set obsolete flag");
@@ -1169,7 +1172,7 @@ static int flash_write(int fd_current, int fd_target, int dev_target)
                (*environment.flags)++;
                break;
        case FLAG_BOOLEAN:
-               *environment.flags = active_flag;
+               *environment.flags = ENV_REDUND_ACTIVE;
                break;
        default:
                fprintf(stderr, "Unimplemented flash scheme %u\n",
@@ -1508,11 +1511,11 @@ int fw_env_open(struct env_opts *opts)
                } else {
                        switch (environment.flag_scheme) {
                        case FLAG_BOOLEAN:
-                               if (flag0 == active_flag &&
-                                   flag1 == obsolete_flag) {
+                               if (flag0 == ENV_REDUND_ACTIVE &&
+                                   flag1 == ENV_REDUND_OBSOLETE) {
                                        dev_current = 0;
-                               } else if (flag0 == obsolete_flag &&
-                                          flag1 == active_flag) {
+                               } else if (flag0 == ENV_REDUND_OBSOLETE &&
+                                          flag1 == ENV_REDUND_ACTIVE) {
                                        dev_current = 1;
                                } else if (flag0 == flag1) {
                                        dev_current = 0;