From d3716dd64bb8bb4c4ba2d19bac164d24ada72a68 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 1 Aug 2019 09:47:08 -0600 Subject: env: Rename the redundancy flags 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 --- tools/env/fw_env.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'tools/env/fw_env.c') diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index f06252d916..95c99847a3 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -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 @@ -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; -- cgit v1.2.3