env: mcc: Drop unnecessary #ifdefs

This file has a lot of conditional code and much of it is unnecessary.
Clean this up to reduce the number of build combinations.

This patch replaces the test on CONFIG_ENV_OFFSET_REDUND for the
more coherent CONFIG_SYS_REDUNDAND_ENVIRONMENT.

This patch also corrects a compilation issue in init_mmc_for_env()
when CONFIG_SYS_MMC_ENV_PART is not activated, env_mmc_orig_hwpart is
not defined.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
This commit is contained in:
Patrick Delaunay 2022-11-10 11:48:59 +01:00 committed by Tom Rini
parent f7e07a7ef4
commit 46c9016b7f

120
env/mmc.c vendored
View File

@ -46,7 +46,7 @@ DECLARE_GLOBAL_DATA_PTR;
#if (defined(CONFIG_SYS_REDUNDAND_ENVIRONMENT) && \ #if (defined(CONFIG_SYS_REDUNDAND_ENVIRONMENT) && \
(CONFIG_SYS_MMC_ENV_PART == 1) && \ (CONFIG_SYS_MMC_ENV_PART == 1) && \
(CONFIG_ENV_OFFSET == CONFIG_ENV_OFFSET_REDUND)) (CONFIG_ENV_OFFSET == CONFIG_ENV_OFFSET_REDUND))
#define ENV_MMC_HWPART_REDUND #define ENV_MMC_HWPART_REDUND 1
#endif #endif
#if CONFIG_IS_ENABLED(OF_CONTROL) #if CONFIG_IS_ENABLED(OF_CONTROL)
@ -108,12 +108,11 @@ static inline s64 mmc_offset(int copy)
defvalue = ENV_MMC_OFFSET; defvalue = ENV_MMC_OFFSET;
propname = dt_prop.offset; propname = dt_prop.offset;
#if defined(CONFIG_ENV_OFFSET_REDUND) if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT) && copy) {
if (copy) {
defvalue = ENV_MMC_OFFSET_REDUND; defvalue = ENV_MMC_OFFSET_REDUND;
propname = dt_prop.offset_redund; propname = dt_prop.offset_redund;
} }
#endif
return ofnode_conf_read_int(propname, defvalue); return ofnode_conf_read_int(propname, defvalue);
} }
#else #else
@ -121,10 +120,9 @@ static inline s64 mmc_offset(int copy)
{ {
s64 offset = ENV_MMC_OFFSET; s64 offset = ENV_MMC_OFFSET;
#if defined(CONFIG_ENV_OFFSET_REDUND) if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT) && copy)
if (copy)
offset = ENV_MMC_OFFSET_REDUND; offset = ENV_MMC_OFFSET_REDUND;
#endif
return offset; return offset;
} }
#endif #endif
@ -165,8 +163,24 @@ static int mmc_set_env_part(struct mmc *mmc, uint part)
return ret; return ret;
} }
static bool mmc_set_env_part_init(struct mmc *mmc)
{
env_mmc_orig_hwpart = mmc_get_blk_desc(mmc)->hwpart;
if (mmc_set_env_part(mmc, mmc_get_env_part(mmc)))
return false;
return true;
}
static int mmc_set_env_part_restore(struct mmc *mmc)
{
return mmc_set_env_part(mmc, env_mmc_orig_hwpart);
}
#else #else
static inline int mmc_set_env_part(struct mmc *mmc, uint part) {return 0; }; static inline int mmc_set_env_part(struct mmc *mmc, uint part) {return 0; };
static bool mmc_set_env_part_init(struct mmc *mmc) {return true; }
static inline int mmc_set_env_part_restore(struct mmc *mmc) {return 0; };
#endif #endif
static const char *init_mmc_for_env(struct mmc *mmc) static const char *init_mmc_for_env(struct mmc *mmc)
@ -183,8 +197,7 @@ static const char *init_mmc_for_env(struct mmc *mmc)
if (mmc_init(mmc)) if (mmc_init(mmc))
return "MMC init failed"; return "MMC init failed";
#endif #endif
env_mmc_orig_hwpart = mmc_get_blk_desc(mmc)->hwpart; if (!mmc_set_env_part_init(mmc))
if (mmc_set_env_part(mmc, mmc_get_env_part(mmc)))
return "MMC partition switch failed"; return "MMC partition switch failed";
return NULL; return NULL;
@ -192,11 +205,7 @@ static const char *init_mmc_for_env(struct mmc *mmc)
static void fini_mmc_for_env(struct mmc *mmc) static void fini_mmc_for_env(struct mmc *mmc)
{ {
#ifdef CONFIG_SYS_MMC_ENV_PART mmc_set_env_part_restore(mmc);
int dev = mmc_get_env_dev();
blk_select_hwpart_devnum(UCLASS_MMC, dev, env_mmc_orig_hwpart);
#endif
} }
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_SPL_BUILD) #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_SPL_BUILD)
@ -233,21 +242,20 @@ static int env_mmc_save(void)
if (ret) if (ret)
goto fini; goto fini;
#ifdef CONFIG_ENV_OFFSET_REDUND if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
if (gd->env_valid == ENV_VALID) if (gd->env_valid == ENV_VALID)
copy = 1; copy = 1;
#ifdef ENV_MMC_HWPART_REDUND if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
ret = mmc_set_env_part(mmc, copy + 1); ret = mmc_set_env_part(mmc, copy + 1);
if (ret) if (ret)
goto fini; goto fini;
#endif }
#endif if (mmc_get_env_addr(mmc, copy, &offset)) {
ret = 1;
if (mmc_get_env_addr(mmc, copy, &offset)) { goto fini;
ret = 1; }
goto fini;
} }
printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "", dev); printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "", dev);
@ -259,12 +267,12 @@ static int env_mmc_save(void)
ret = 0; ret = 0;
#ifdef CONFIG_ENV_OFFSET_REDUND if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND; gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
#endif
fini: fini:
fini_mmc_for_env(mmc); fini_mmc_for_env(mmc);
return ret; return ret;
} }
@ -308,23 +316,23 @@ static int env_mmc_erase(void)
printf("\n"); printf("\n");
ret = erase_env(mmc, CONFIG_ENV_SIZE, offset); ret = erase_env(mmc, CONFIG_ENV_SIZE, offset);
#ifdef CONFIG_ENV_OFFSET_REDUND if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
copy = 1; copy = 1;
#ifdef ENV_MMC_HWPART_REDUND if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
ret = mmc_set_env_part(mmc, copy + 1); ret = mmc_set_env_part(mmc, copy + 1);
if (ret) if (ret)
goto fini; goto fini;
#endif }
if (mmc_get_env_addr(mmc, copy, &offset)) { if (mmc_get_env_addr(mmc, copy, &offset)) {
ret = CMD_RET_FAILURE; ret = CMD_RET_FAILURE;
goto fini; goto fini;
}
ret |= erase_env(mmc, CONFIG_ENV_SIZE, offset);
} }
ret |= erase_env(mmc, CONFIG_ENV_SIZE, offset);
#endif
fini: fini:
fini_mmc_for_env(mmc); fini_mmc_for_env(mmc);
return ret; return ret;
@ -345,7 +353,7 @@ static inline int read_env(struct mmc *mmc, unsigned long size,
return (n == blk_cnt) ? 0 : -1; return (n == blk_cnt) ? 0 : -1;
} }
#ifdef CONFIG_ENV_OFFSET_REDUND #if defined(CONFIG_SYS_REDUNDAND_ENVIRONMENT)
static int env_mmc_load(void) static int env_mmc_load(void)
{ {
#if !defined(ENV_IS_EMBEDDED) #if !defined(ENV_IS_EMBEDDED)
@ -375,19 +383,19 @@ static int env_mmc_load(void)
goto fini; goto fini;
} }
#ifdef ENV_MMC_HWPART_REDUND if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
ret = mmc_set_env_part(mmc, 1); ret = mmc_set_env_part(mmc, 1);
if (ret) if (ret)
goto fini; goto fini;
#endif }
read1_fail = read_env(mmc, CONFIG_ENV_SIZE, offset1, tmp_env1); read1_fail = read_env(mmc, CONFIG_ENV_SIZE, offset1, tmp_env1);
#ifdef ENV_MMC_HWPART_REDUND if (IS_ENABLED(ENV_MMC_HWPART_REDUND)) {
ret = mmc_set_env_part(mmc, 2); ret = mmc_set_env_part(mmc, 2);
if (ret) if (ret)
goto fini; goto fini;
#endif }
read2_fail = read_env(mmc, CONFIG_ENV_SIZE, offset2, tmp_env2); read2_fail = read_env(mmc, CONFIG_ENV_SIZE, offset2, tmp_env2);
@ -403,7 +411,7 @@ err:
#endif #endif
return ret; return ret;
} }
#else /* ! CONFIG_ENV_OFFSET_REDUND */ #else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */
static int env_mmc_load(void) static int env_mmc_load(void)
{ {
#if !defined(ENV_IS_EMBEDDED) #if !defined(ENV_IS_EMBEDDED)
@ -448,7 +456,7 @@ err:
#endif #endif
return ret; return ret;
} }
#endif /* CONFIG_ENV_OFFSET_REDUND */ #endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
U_BOOT_ENV_LOCATION(mmc) = { U_BOOT_ENV_LOCATION(mmc) = {
.location = ENVL_MMC, .location = ENVL_MMC,