Skip to contentSkip to conversation

env: fat, ubi: Fix gd->env_valid for the first write

PATCH In review Tom Rini 1 participant 2 messages Oct 21, 2025 – Oct 24, 2025

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 env: fat, ubi: Fix gd->env_valid for the first write

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.

---
 env/fat.c | 2 +-
 env/ubi.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
env/fat.c +1 -1
index 58c279ff7690..7e1648223838 100644
@@ -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;
env/ubi.c +1 -1
index f424b1a16e85..59bd96feb488 100644
@@ -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;
 }
Signature · 1 line
2.43.0
author
#1 lore raw
Quoted 10 lines · Tom Rini

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.

[...]

Applied to u-boot/master, thanks!

[1/1] env: fat, ubi: Fix gd->env_valid for the first write

      commit: cf262e16080abcd587f47d0bbc8fa84558abcf89
Signature · 1 line
Tom