summaryrefslogtreecommitdiff
path: root/env/sf.c
diff options
context:
space:
mode:
authorMichal Simek <[email protected]>2025-09-22 18:03:39 +0200
committerTom Rini <[email protected]>2025-10-02 11:32:34 -0600
commite589d5822cac10915ec04e8d9044d2460aec8924 (patch)
treed2028bb559e544edf5e1d4034fb75b29d1ae1141 /env/sf.c
parenta14253b15c8371b78da2984c0386241c552cc4df (diff)
env: spi: Fix gd->env_valid for the first write
When both SPI environment locations are invalid (gd->env_valid == ENV_INVALID), the first call to saveenv writes to the primary location and sets the active flag. However, the logic for updating gd->env_valid incorrectly sets it to ENV_REDUND, which does not match the actual location written. This causes the first two writes to target the same location, and alternation only begins after the second write. Update the logic to alternate gd->env_valid based on whether the last write was to the primary or redundant location, ensuring the first write sets ENV_VALID and subsequent writes alternate as expected. This aligns env_valid with the actual storage location and fixes the alternation sequence from the first write. With this change, the "Valid environment" printout correctly reflects the active location after each save, and the alternation between primary and redundant locations works as intended from the start. Signed-off-by: Michal Simek <[email protected]> Reviewed-by: Marek Vasut <[email protected]> Acked-by: E Shattow <[email protected]>
Diffstat (limited to 'env/sf.c')
-rw-r--r--env/sf.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/env/sf.c b/env/sf.c
index 0b70e18b9af..0e27a020643 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -148,7 +148,7 @@ static int env_sf_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;
printf("Valid environment: %d\n", (int)gd->env_valid);