forked from OERV-BSP/u-boot
Merge patch series "env: mmc: Make redundant env in both eMMC boot partitions consider DT properties"
This series from Marek Vasut <marex@denx.de> clarifies and makes a bit more configurable the case of redundant environment storage using the eMMC boot partitions. Link: https://lore.kernel.org/r/20250221184732.202336-1-marex@denx.de
This commit is contained in:
60
env/mmc.c
vendored
60
env/mmc.c
vendored
@@ -40,18 +40,6 @@
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
/*
|
||||
* In case the environment is redundant, stored in eMMC hardware boot
|
||||
* partition and the environment and redundant environment offsets are
|
||||
* identical, store the environment and redundant environment in both
|
||||
* eMMC boot partitions, one copy in each.
|
||||
* */
|
||||
#if (defined(CONFIG_SYS_REDUNDAND_ENVIRONMENT) && \
|
||||
(CONFIG_SYS_MMC_ENV_PART == 1) && \
|
||||
(CONFIG_ENV_OFFSET == CONFIG_ENV_OFFSET_REDUND))
|
||||
#define ENV_MMC_HWPART_REDUND 1
|
||||
#endif
|
||||
|
||||
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
||||
|
||||
static int mmc_env_partition_by_name(struct blk_desc *desc, const char *str,
|
||||
@@ -217,6 +205,23 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy)
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool mmc_env_is_redundant_in_both_boot_hwparts(struct mmc *mmc)
|
||||
{
|
||||
/*
|
||||
* In case the environment is redundant, stored in eMMC hardware boot
|
||||
* partition and the environment and redundant environment offsets are
|
||||
* identical, store the environment and redundant environment in both
|
||||
* eMMC boot partitions, one copy in each.
|
||||
*/
|
||||
if (!IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
|
||||
return false;
|
||||
|
||||
if (CONFIG_SYS_MMC_ENV_PART != 1)
|
||||
return false;
|
||||
|
||||
return mmc_offset(mmc, 0) == mmc_offset(mmc, 1);
|
||||
}
|
||||
|
||||
__weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
|
||||
{
|
||||
s64 offset = mmc_offset(mmc, copy);
|
||||
@@ -336,7 +341,7 @@ static int env_mmc_save(void)
|
||||
if (gd->env_valid == ENV_VALID)
|
||||
copy = 1;
|
||||
|
||||
if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
|
||||
if (mmc_env_is_redundant_in_both_boot_hwparts(mmc)) {
|
||||
ret = mmc_set_env_part(mmc, copy + 1);
|
||||
if (ret)
|
||||
goto fini;
|
||||
@@ -409,7 +414,7 @@ static int env_mmc_erase(void)
|
||||
if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
|
||||
copy = 1;
|
||||
|
||||
if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
|
||||
if (mmc_env_is_redundant_in_both_boot_hwparts(mmc)) {
|
||||
ret = mmc_set_env_part(mmc, copy + 1);
|
||||
if (ret)
|
||||
goto fini;
|
||||
@@ -443,13 +448,7 @@ static inline int read_env(struct mmc *mmc, unsigned long size,
|
||||
return (n == blk_cnt) ? 0 : -1;
|
||||
}
|
||||
|
||||
#if defined(ENV_IS_EMBEDDED)
|
||||
static int env_mmc_load(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#elif defined(CONFIG_SYS_REDUNDAND_ENVIRONMENT)
|
||||
static int env_mmc_load(void)
|
||||
static int env_mmc_load_redundant(void)
|
||||
{
|
||||
struct mmc *mmc;
|
||||
u32 offset1, offset2;
|
||||
@@ -477,7 +476,7 @@ static int env_mmc_load(void)
|
||||
goto fini;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
|
||||
if (mmc_env_is_redundant_in_both_boot_hwparts(mmc)) {
|
||||
ret = mmc_set_env_part(mmc, 1);
|
||||
if (ret)
|
||||
goto fini;
|
||||
@@ -485,7 +484,7 @@ static int env_mmc_load(void)
|
||||
|
||||
read1_fail = read_env(mmc, CONFIG_ENV_SIZE, offset1, tmp_env1);
|
||||
|
||||
if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
|
||||
if (mmc_env_is_redundant_in_both_boot_hwparts(mmc)) {
|
||||
ret = mmc_set_env_part(mmc, 2);
|
||||
if (ret)
|
||||
goto fini;
|
||||
@@ -505,8 +504,8 @@ err:
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */
|
||||
static int env_mmc_load(void)
|
||||
|
||||
static int env_mmc_load_singular(void)
|
||||
{
|
||||
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
|
||||
struct mmc *mmc;
|
||||
@@ -551,7 +550,16 @@ err:
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
|
||||
|
||||
static int env_mmc_load(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_ENV_IS_EMBEDDED))
|
||||
return 0;
|
||||
else if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
|
||||
return env_mmc_load_redundant();
|
||||
else
|
||||
return env_mmc_load_singular();
|
||||
}
|
||||
|
||||
U_BOOT_ENV_LOCATION(mmc) = {
|
||||
.location = ENVL_MMC,
|
||||
|
||||
Reference in New Issue
Block a user