summaryrefslogtreecommitdiff
path: root/tools/env
diff options
context:
space:
mode:
authorJon Povey <jon.povey@racelogic.co.uk>2011-03-11 14:10:56 +0900
committerWolfgang Denk <wd@denx.de>2011-04-21 00:25:08 +0200
commit735eb0f0e66b544b1dfaf6c43ce6e4bd9ae64b5e (patch)
tree5e79be38ff31b24fe389d45b082f651682dd9657 /tools/env
parentaef293bc85dad4f8d645e46d723606a747236a60 (diff)
downloadu-boot-imx-735eb0f0e66b544b1dfaf6c43ce6e4bd9ae64b5e.zip
u-boot-imx-735eb0f0e66b544b1dfaf6c43ce6e4bd9ae64b5e.tar.gz
u-boot-imx-735eb0f0e66b544b1dfaf6c43ce6e4bd9ae64b5e.tar.bz2
tools/env: fix redundant env flag comparison
This fixes two bugs with comparison of redundant environment flags on read. flag0 and flag1 in fw_env_open() were declared signed instead of unsigned char breaking BOOLEAN mode "== 0xFF" tests and in INCREMENTAL mode the wrong environment would be chosen where the flag values are 127 and 128 (either way round). With both flags over 128, both signs flipped and the logic worked by happy accident. Also there was a logic bug in the INCREMENTAL test (after signedness was fixed) in the case flag0=0, flag1=255, env 1 would be incorrectly chosen. Fix both of these. Signed-off-by: Jon Povey <jon.povey@racelogic.co.uk>
Diffstat (limited to 'tools/env')
-rw-r--r--tools/env/fw_env.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index e0f46bc..ed6b53f 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1067,11 +1067,11 @@ static char *envmatch (char * s1, char * s2)
int fw_env_open(void)
{
int crc0, crc0_ok;
- char flag0;
+ unsigned char flag0;
void *addr0;
int crc1, crc1_ok;
- char flag1;
+ unsigned char flag1;
void *addr1;
struct env_image_single *single;
@@ -1185,14 +1185,13 @@ int fw_env_open(void)
}
break;
case FLAG_INCREMENTAL:
- if ((flag0 == 255 && flag1 == 0) ||
- flag1 > flag0)
+ if (flag0 == 255 && flag1 == 0)
dev_current = 1;
else if ((flag1 == 255 && flag0 == 0) ||
- flag0 > flag1)
- dev_current = 0;
- else /* flags are equal - almost impossible */
+ flag0 >= flag1)
dev_current = 0;
+ else /* flag1 > flag0 */
+ dev_current = 1;
break;
default:
fprintf (stderr, "Unknown flag scheme %u \n",