From b9c3052fbb25bff26702e6c16abfd0a5ec92040c Mon Sep 17 00:00:00 2001 From: Brandon Maier Date: Thu, 17 Dec 2020 17:19:18 -0600 Subject: env: increment redund flag on read fail If one of the reads fails when importing redundant environments (a single read failure), the env_flags wouldn't get initialized in env_import_redund(). If a user then calls saveenv, the new environment will have the wrong flags value. So on the next load the new environment will be ignored. While debugging this, I also noticed that env/sf.c was not correctly handling a single read failure, as it would not check the crc before assigning it to gd->env_addr. Having a special error path for when there is a single read failure seems unnecessary and may lead to future bugs. Instead collapse the 'single read failure' error to be the same as a 'single crc failure'. That way env_check_redund() either passes or fails, and if it passes we are guaranteed to have checked the CRC. Signed-off-by: Brandon Maier CC: Joe Hershberger CC: Wolfgang Denk CC: Heiko Schocher Reviewed-by: Tom Rini --- include/env.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/env.h b/include/env.h index c15339a93f1..b5731e4b9a7 100644 --- a/include/env.h +++ b/include/env.h @@ -328,8 +328,6 @@ int env_export(struct environment_s *env_out); * @buf2_read_fail: 0 if buf2 is valid, non-zero if invalid * @return 0 if OK, * -EIO if no environment is valid, - * -EINVAL if read of second entry is good - * -ENOENT if read of first entry is good * -ENOMSG if the CRC was bad */ -- cgit v1.2.3 From 1af031ac3e3e75ea1ae58da093db956a8c9bc144 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Tue, 9 Feb 2021 11:48:50 +0100 Subject: env: add ENV_ERASE_PTR macro Add ENV_ERASE_PTR macro to handle erase opts and remove the associated ifdef. This patch is a extension of previous commit 82b2f4135719 ("env_internal.h: add alternative ENV_SAVE_PTR macro"). Signed-off-by: Patrick Delaunay --- include/env_internal.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/env_internal.h b/include/env_internal.h index 708c833a550..b7bddcb00d8 100644 --- a/include/env_internal.h +++ b/include/env_internal.h @@ -211,6 +211,7 @@ struct env_driver { #endif #define ENV_SAVE_PTR(x) (CONFIG_IS_ENABLED(SAVEENV) ? (x) : NULL) +#define ENV_ERASE_PTR(x) (CONFIG_IS_ENABLED(CMD_ERASEENV) ? (x) : NULL) extern struct hsearch_data env_htab; -- cgit v1.2.3