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.

Signed-off-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
Tom Rini 2025-10-21 14:37:01 -06:00
parent 38f40e6de6
commit cf262e1608
2 changed files with 2 additions and 2 deletions

2
env/fat.c vendored
View File

@ -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;

2
env/ubi.c vendored
View File

@ -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;
}