From: Marek Vasut Date: Wed, 6 Oct 2021 16:29:53 +0000 (+0200) Subject: env: mmc: Add missing eMMC bootpart restoration to env erase X-Git-Url: http://git.dujemihanovic.xyz/login.html?a=commitdiff_plain;h=f47f87f257b790bbc9b071de433324dab2305d7d;p=u-boot.git env: mmc: Add missing eMMC bootpart restoration to env erase If the environment is stored in eMMC hardware boot partition, the environment driver first stores the currently selected eMMC boot partition, then does the requested operation, and then restores the original boot partition settings. In case the environment operation fails, the boot partition settings are also restored. The 'env erase' implementation in the MMC environment driver lacks the path which restores the boot partition. This could lead to various failure modes, like the system boots the wrong copy of bootloader etc. Fix this by filling in the missing restoration path. Signed-off-by: Marek Vasut Cc: Fabio Estevam Cc: Jaehoon Chung Cc: Peng Fan Cc: Stefano Babic --- diff --git a/env/mmc.c b/env/mmc.c index c4cb163991..e111d8e588 100644 --- a/env/mmc.c +++ b/env/mmc.c @@ -263,20 +263,26 @@ static int env_mmc_erase(void) return 1; } - if (mmc_get_env_addr(mmc, copy, &offset)) - return CMD_RET_FAILURE; + if (mmc_get_env_addr(mmc, copy, &offset)) { + ret = CMD_RET_FAILURE; + goto fini; + } ret = erase_env(mmc, CONFIG_ENV_SIZE, offset); #ifdef CONFIG_ENV_OFFSET_REDUND copy = 1; - if (mmc_get_env_addr(mmc, copy, &offset)) - return CMD_RET_FAILURE; + if (mmc_get_env_addr(mmc, copy, &offset)) { + ret = CMD_RET_FAILURE; + goto fini; + } ret |= erase_env(mmc, CONFIG_ENV_SIZE, offset); #endif +fini: + fini_mmc_for_env(mmc); return ret; } #endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */