summaryrefslogtreecommitdiff
path: root/tools/env/fw_env.c
diff options
context:
space:
mode:
authorJoe Hershberger <joe.hershberger@ni.com>2018-06-26 12:37:59 +0300
committerTom Rini <trini@konsulko.com>2018-06-27 13:09:16 -0400
commit3925b2ac97b50b1facab096ac98243615683c295 (patch)
tree247018acf941a9e3ec462ef205af22b911e30441 /tools/env/fw_env.c
parent94905e1db8d8d42c4f39f14dbee2f9788390db5e (diff)
fw_printenv: Don't bail out directly after one env read error
When using a redundant environment a read error should simply mean to not use that copy instead of giving up completely. The other copy may be just fine. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Ioan-Adrian Ratiu <adrian.ratiu@ni.com>
Diffstat (limited to 'tools/env/fw_env.c')
-rw-r--r--tools/env/fw_env.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index a5d75958e1..3a5ad026f0 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1427,14 +1427,21 @@ int fw_env_open(struct env_opts *opts)
}
dev_current = 0;
- if (flash_io(O_RDONLY)) {
+
+ if (!flash_io(O_RDONLY)) {
+ crc0 = crc32(0, (uint8_t *)environment.data, ENV_SIZE);
+ crc0_ok = (crc0 == *environment.crc);
+ } else if (have_redund_env) {
+ /*
+ * to give the redundant env a chance, maybe it's good:
+ * mark env crc0 invalid then test below if crc1 is ok
+ */
+ crc0_ok = 0;
+ } else {
ret = -EIO;
goto open_cleanup;
}
- crc0 = crc32(0, (uint8_t *)environment.data, ENV_SIZE);
-
- crc0_ok = (crc0 == *environment.crc);
if (!have_redund_env) {
if (!crc0_ok) {
fprintf(stderr,
@@ -1462,8 +1469,10 @@ int fw_env_open(struct env_opts *opts)
*/
environment.image = addr1;
if (flash_io(O_RDONLY)) {
- ret = -EIO;
- goto open_cleanup;
+ crc1_ok = 0;
+ } else {
+ crc1 = crc32(0, (uint8_t *)redundant->data, ENV_SIZE);
+ crc1_ok = (crc1 == redundant->crc);
}
/* Check flag scheme compatibility */
@@ -1489,9 +1498,6 @@ int fw_env_open(struct env_opts *opts)
goto open_cleanup;
}
- crc1 = crc32(0, (uint8_t *)redundant->data, ENV_SIZE);
-
- crc1_ok = (crc1 == redundant->crc);
flag1 = redundant->flags;
if (crc0_ok && !crc1_ok) {