[PATCH] env: Invert gd->env_valid for env_mmc_save

jasper at fancydomain.eu jasper at fancydomain.eu
Fri May 10 13:38:34 CEST 2024


From: Jasper Orschulko <jasper at fancydomain.eu>

The A/B update strategy of the env's has a gap in the first 2 calls of saveenv.
The env's are stored twice on the first memory area if:
gd->env_valid == ENV_INVALID.

u-boot=> saveenv
Saving Environment to MMC... Writing to MMC(1)... OK
u-boot=> saveenv
Saving Environment to MMC... Writing to MMC(1)... OK  <-- !!!
u-boot=> saveenv
Saving Environment to MMC... Writing to redundant MMC(1)... OK
u-boot=> saveenv
Saving Environment to MMC... Writing to MMC(1)... OK

Signed-off-by: Michael Glembotzki <Michael.Glembotzki at iris-sensing.com>
Signed-off-by: Jasper Orschulko <jasper at fancydomain.eu>
---
 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/env/mmc.c b/env/mmc.c
index 7afb733e890..2bef30c973c 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -299,7 +299,7 @@ static int env_mmc_save(void)
 	ret = 0;
 
 	if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
-		gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
+		gd->env_valid = gd->env_valid == ENV_VALID ? ENV_REDUND : ENV_VALID;
 
 fini:
 	fini_mmc_for_env(mmc);
-- 
2.45.0



More information about the U-Boot mailing list