]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
env: fat, ubi: Fix gd->env_valid for the first write
authorTom Rini <trini@konsulko.com>
Tue, 21 Oct 2025 20:37:01 +0000 (14:37 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 24 Oct 2025 19:47:50 +0000 (13:47 -0600)
As resolved and explained in detail in commit e589d5822cac ("env: spi:
Fix gd->env_valid for the first write") and archived discussion there is
a corner case where we don't do the right thing with redundant
environments. This same exact check was present in the mmc code and
resolved with commit 813a0df27a8a ("env: Invert gd->env_valid for
env_mmc_save") and in the discussion of that patch, I noted that both
fat and ubi (and at the time, sf) were doing the same thing. Take the
time now to correct fat and ubi environment.

Signed-off-by: Tom Rini <trini@konsulko.com>
env/fat.c
env/ubi.c

index 58c279ff7690855fcfd0e4f6f44977949eeb4573..7e164822383847505bf517a83dbb52802447f2b5 100644 (file)
--- a/env/fat.c
+++ b/env/fat.c
@@ -104,7 +104,7 @@ static int env_fat_save(void)
        }
 
 #ifdef CONFIG_ENV_REDUNDANT
-       gd->env_valid = (gd->env_valid == ENV_REDUND) ? ENV_VALID : ENV_REDUND;
+       gd->env_valid = gd->env_valid == ENV_VALID ? ENV_REDUND : ENV_VALID;
 #endif
 
        return 0;
index f424b1a16e853de300177aa6dfa4ed27afe21971..59bd96feb488065e558daac3819a07683f4e2a64 100644 (file)
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -72,7 +72,7 @@ static int env_ubi_save(void)
 
        puts("done\n");
 
-       gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
+       gd->env_valid = gd->env_valid == ENV_VALID ? ENV_REDUND : ENV_VALID;
 
        return 0;
 }