env: mmc: Make redundant env in both eMMC boot partitions consider DT properties
PATCH 1/1 env: mmc: Make redundant env in both eMMC boot partitions consider DT properties
Introduce a new function mmc_env_hwpart_redund() which replaces IS_ENABLED(ENV_MMC_HWPART_REDUND) and internally does almost the same check as the macro which assigned ENV_MMC_HWPART_REDUND did, and call it in place of IS_ENABLED(ENV_MMC_HWPART_REDUND).
The difference compared to IS_ENABLED(ENV_MMC_HWPART_REDUND) is in the last conditional, which does not do plain macro compare (CONFIG_ENV_OFFSET == CONFIG_ENV_OFFSET_REDUND), but instead does mmc_offset(mmc, 0) == mmc_offset(mmc, 1). If OF_CONTROL is not in use, this gets optimized back to original macro compare, but if OF_CONTROL is in use, this also takes into account the DT properties u-boot,mmc-env-offset and u-boot,mmc-env-offset-redundant.
---
Cc: Dragan Simic <[email protected]>
Cc: Joe Hershberger <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
--- env/mmc.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)
env/mmc.c +21 -16
@@ -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 int mmc_env_hwpart_redund (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 0 ; + +if (CONFIG_SYS_MMC_ENV_PART !=1 ) +return 0 ; + +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_hwpart_redund (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_hwpart_redund (mmc)) { ret =mmc_set_env_part (mmc, copy +1 );if (ret) goto fini;
@@ -477,7 +482,7 @@ static int env_mmc_load(void) goto fini; } -if (IS_ENABLED (ENV_MMC_HWPART_REDUND )) { +if (mmc_env_hwpart_redund (mmc)) { ret =mmc_set_env_part (mmc,1 );if (ret) goto fini;
@@ -485,7 +490,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_hwpart_redund (mmc)) { ret =mmc_set_env_part (mmc,2 );if (ret) goto fini;
Signature · 1 line
2.47.2
Hi Marek,
Quoted 51 lines · Marek Vasut
Introduce a new function
mmc_env_hwpart_redund()which replacesIS_ENABLED(ENV_MMC_HWPART_REDUND)and internally does almost the same check as the macro which assignedENV_MMC_HWPART_REDUNDdid, and call it in place ofIS_ENABLED(ENV_MMC_HWPART_REDUND).The difference compared to
IS_ENABLED(ENV_MMC_HWPART_REDUND)is in the last conditional, which does not do plain macro compare (CONFIG_ENV_OFFSET==CONFIG_ENV_OFFSET_REDUND), but instead doesmmc_offset(mmc, 0)==mmc_offset(mmc, 1). IfOF_CONTROLis not in use, this gets optimized back to original macro compare, but ifOF_CONTROLis in use, this also takes into account the DT properties u-boot,mmc-env-offset and u-boot,mmc-env-offset-redundant.Signed-off-by Marek Vasut <[email protected]>---
Cc: Dragan Simic <[email protected]>
Cc: Joe Hershberger <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]--- env/mmc.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)env/mmc.c +0
-12@@ -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,
env/mmc.c static inline s64 mmc_offset(struct mmc *mmc, int copy) · line 208
Quoted 4 lines
env/mmc.c +1
-0@@ -217,6 +205,23 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy) }#endif +static int mmc_env_hwpart_redund (struct mmc *mmc)
Maybe a bool would be more appropriate here?
Please also document what this function does, the name isn't the most explicit I've seen.
Looks ok otherwise!
Cheers,
Quentin