From: Jasper Orschulko Date: Fri, 10 May 2024 11:38:34 +0000 (+0200) Subject: env: Invert gd->env_valid for env_mmc_save X-Git-Tag: v2026.01-rc1~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F815%2Fhead;p=thirdparty%2Fu-boot.git env: Invert gd->env_valid for env_mmc_save 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 This is the same issue as resolved in commit e589d5822cac ("env: spi: Fix gd->env_valid for the first write") Signed-off-by: Michael Glembotzki Signed-off-by: Jasper Orschulko Signed-off-by: Michael Heimpold [trini: Amend the commit message] --- Changes in v2: - Rebase to current master - Amend the commit message to reference the SPI version of this fix, which had significant follow-up discussion. --- diff --git a/env/mmc.c b/env/mmc.c index 46ffa6386d6..1eddba3b0f8 100644 --- a/env/mmc.c +++ b/env/mmc.c @@ -371,7 +371,7 @@ static int env_mmc_save(void) ret = 0; if (IS_ENABLED(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; fini: fini_mmc_for_env(mmc);