env: mmc: Make redundant env in both eMMC boot partitions consider DT properties
PATCH v3 1/2 env: mmc: Make redundant env in both eMMC boot partitions consider DT properties
Introduce a new function mmc_env_is_redundant_in_both_boot_hwparts() 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]
---
V2: - Rename mmc_env_hwpart_redund() to mmc_env_is_redundant_in_both_boot_hwparts()
- Return bool
V3: - Hide the mmc_env_is_redundant_in_both_boot_hwparts symbol behind __maybe_unused
as this symbol is called from code gated behind ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT in env_mmc_load()
--- 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 bool __maybe_unused 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;
@@ -477,7 +482,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 +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_is_redundant_in_both_boot_hwparts (mmc)) { ret =mmc_set_env_part (mmc,2 );if (ret) goto fini;
Signature · 1 line
2.47.2
PATCH v3 2/2 env: mmc: Clean up env_mmc_load() ifdeffery
Rename the variants of env_mmc_load() for redundant and non-redundant environment to env_mmc_load_redundant() and env_mmc_load_singular() respectively and convert the env_mmc_load() implementation to use of if (IS_ENABLED(...)). As a result, drop __maybe_unused from mmc_env_is_redundant_in_both_boot_hwparts().
---
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]
---
V3: New patch
--- env/mmc.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
env/mmc.c +14 -11
@@ -205,7 +205,7 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy) }#endif -static bool __maybe_unused mmc_env_is_redundant_in_both_boot_hwparts (struct mmc *mmc) +static bool mmc_env_is_redundant_in_both_boot_hwparts (struct mmc *mmc) {/* * In case the environment is redundant, stored in eMMC hardware boot
@@ -448,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;
@@ -510,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;
@@ -556,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 ,
Signature · 1 line
2.47.2
Re: [PATCH v3 2/2] env: mmc: Clean up env_mmc_load() ifdeffery
Hi Marek,
Quoted 65 lines · Marek Vasut
Rename the variants of
env_mmc_load()for redundant and non-redundant environment toenv_mmc_load_redundant()andenv_mmc_load_singular()respectively and convert theenv_mmc_load()implementation to use of if (IS_ENABLED(...)). As a result, drop__maybe_unusedfrommmc_env_is_redundant_in_both_boot_hwparts().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]
---
V3: New patch--- env/mmc.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)env/mmc.c +4
-10@@ -205,7 +205,7 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy) }#endif -static bool __maybe_unused mmc_env_is_redundant_in_both_boot_hwparts (struct mmc *mmc) +static bool mmc_env_is_redundant_in_both_boot_hwparts (struct mmc *mmc) {/* * In case the environment is redundant, stored in eMMC hardware boot @@ -448,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;@@ -510,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;@@ -556,7 +550,16 @@ err:return ret; }
env/mmc.c err: · line 561
Quoted 10 lines
env/mmc.c +9
-1-#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 ();
The else (not its content!) could be removed since all conditions above return.
Isn't this going to be increasing the size of the binary with code that won't be run or is the compiler smart enough to remove that based on the IS_ENABLED() that are constant false at build time?
The change itself looks fine, therefore:
Thanks!
Quentin
Re: [PATCH v3 2/2] env: mmc: Clean up env_mmc_load() ifdeffery
Quoted 1 line · Quentin Schulz
Hi Marek,
Hi,
Quoted 78 lines · Marek Vasut
Quoted 64 lines
Rename the variants of
env_mmc_load()for redundant and non-redundant environment toenv_mmc_load_redundant()andenv_mmc_load_singular()respectively and convert theenv_mmc_load()implementation to use of if (IS_ENABLED(...)). As a result, drop__maybe_unusedfrommmc_env_is_redundant_in_both_boot_hwparts().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]
---
V3: New patch
---
env/mmc.c| 25 ++++++++++++++-----------1 file changed, 14 insertions(+), 11 deletions(-)env/mmc.c +1
-1@@ -205,7 +205,7 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy) } #endif -static bool __maybe_unused mmc_env_is_redundant_in_both_boot_hwparts(struct mmc *mmc) +static bool mmc_env_is_redundant_in_both_boot_hwparts(struct mmc *mmc) { /** In case the environment is redundant, stored in eMMC hardware boot
env/mmc.c +3
-9@@ -448,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;@@ -510,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;@@ -556,7 +550,16 @@ err: return ret; }env/mmc.c err: · line 560
Quoted 10 lines
env/mmc.c +9
-1-#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();The else (not its content!) could be removed since all conditions above return.
Quoted 1 line
Isn't this going to be increasing the size of the binary with code that won't be run or is the compiler smart enough to remove that based on the
IS_ENABLED()that are constant false at build time?
If that was to be the case, then IS_ENABLED() would be entirely pointless in the first place, right ?
Re: [PATCH v3 2/2] env: mmc: Clean up env_mmc_load() ifdeffery
In reply to Marek VasutHi Marek,
Thank you for the patch.
Quoted 7 lines · Marek Vasut
Rename the variants of
env_mmc_load()for redundant and non-redundant environment toenv_mmc_load_redundant()andenv_mmc_load_singular()respectively and convert theenv_mmc_load()implementation to use of if (IS_ENABLED(...)). As a result, drop__maybe_unusedfrommmc_env_is_redundant_in_both_boot_hwparts().Signed-off-by Marek Vasut <[email protected]>
Nice cleanup!
Quoted 1 line
---
Hi Marek,
Quoted 65 lines · Marek Vasut
Introduce a new function
mmc_env_is_redundant_in_both_boot_hwparts()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]
---
V2: - Renamemmc_env_hwpart_redund()tommc_env_is_redundant_in_both_boot_hwparts()
- Return bool
V3: - Hide themmc_env_is_redundant_in_both_boot_hwpartssymbol behind__maybe_unused
as this symbol is called from code gated behind ifdefCONFIG_SYS_REDUNDAND_ENVIRONMENTinenv_mmc_load()--- env/mmc.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)env/mmc.c +5
-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,@@ -217,6 +205,23 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy) }#endif +static bool __maybe_unused 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
env/mmc.c static inline s64 mmc_offset(struct mmc *mmc, int copy) · line 222
Quoted 10 lines
env/mmc.c +10
-0+* 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 );
This is not always equivalent to the current test of
CONFIG_ENV_OFFSET == CONFIG_ENV_OFFSET_REDUND
Indeed, it only is for when OF_CONTROL isn't set.
I would recommend to keep this check in patch 1, then add another patch that swaps CONFIG_ENV_OFFSET == CONFIG_ENV_OFFSET_REDUND for mmc_offset(mmc, 0) == mmc_offset(mmc, 1)
This will allow to use DT properties like u-boot,mmc-env-offset-redundant and u-boot,mmc-env-offset, which isn't supported today.
What do you think?
The rest of the diff looks good to me.
Cheers,
Quentin
Quoted 1 line · Quentin Schulz
Hi Marek,
Hi,
Quoted 80 lines · Marek Vasut
Quoted 71 lines
Introduce a new function
mmc_env_is_redundant_in_both_boot_hwparts()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]
---
V2: - Renamemmc_env_hwpart_redund()tommc_env_is_redundant_in_both_boot_hwparts()
- Return bool
V3: - Hide themmc_env_is_redundant_in_both_boot_hwpartssymbol behind__maybe_unusedas this symbol is called from code gated behind ifdefCONFIG_SYS_REDUNDAND_ENVIRONMENTinenv_mmc_load()
---
env/mmc.c| 37 +++++++++++++++++++++----------------1 file changed, 21 insertions(+), 16 deletions(-)env/mmc.c +4
-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,@@ -217,6 +205,23 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy) } #endif +static bool __maybe_unused 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;env/mmc.c static inline s64 mmc_offset(struct mmc *mmc, int copy) · line 222
Quoted 5 lines
env/mmc.c +5
-0+ + if (CONFIG_SYS_MMC_ENV_PART != 1) + return false; + + return mmc_offset(mmc, 0) == mmc_offset(mmc, 1);This is not always equivalent to the current test of
Quoted 3 lines
CONFIG_ENV_OFFSET==CONFIG_ENV_OFFSET_REDUNDIndeed, it only is for when
OF_CONTROLisn't set.
This is what the patch fixes and this is what the commit message states.
Quoted 1 line
I would recommend to keep this check in patch 1, then add another patch that swaps
CONFIG_ENV_OFFSET==CONFIG_ENV_OFFSET_REDUNDformmc_offset(mmc, 0)==mmc_offset(mmc, 1)
What benefit would that bring ?
Quoted 1 line
This will allow to use DT properties like u-boot,mmc-env-offset- redundant and u-boot,mmc-env-offset, which isn't supported today.
This is what the patch fixes and this is what the commit message states.
[...]
Quentin Schulz
Reviewed-byHi Marek,
Quoted 85 lines · Marek Vasut
Quoted 1 line · Quentin Schulz
Hi Marek,
Hi,
Quoted 80 lines · Marek Vasut
Quoted 71 lines
Introduce a new function
mmc_env_is_redundant_in_both_boot_hwparts()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]
---
V2: - Renamemmc_env_hwpart_redund()tommc_env_is_redundant_in_both_boot_hwparts()
- Return bool
V3: - Hide themmc_env_is_redundant_in_both_boot_hwpartssymbol behind__maybe_unusedas this symbol is called from code gated behind ifdefCONFIG_SYS_REDUNDAND_ENVIRONMENTinenv_mmc_load()
---
env/mmc.c| 37 +++++++++++++++++++++----------------1 file changed, 21 insertions(+), 16 deletions(-)env/mmc.c +4
-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,@@ -217,6 +205,23 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy) } #endif +static bool __maybe_unused 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;env/mmc.c static inline s64 mmc_offset(struct mmc *mmc, int copy) · line 222
Quoted 5 lines
env/mmc.c +5
-0+ + if (CONFIG_SYS_MMC_ENV_PART != 1) + return false; + + return mmc_offset(mmc, 0) == mmc_offset(mmc, 1);This is not always equivalent to the current test of
Quoted 6 lines
Quoted 3 lines
CONFIG_ENV_OFFSET==CONFIG_ENV_OFFSET_REDUNDIndeed, it only is for when
OF_CONTROLisn't set.This is what the patch fixes and this is what the commit message states.
Sigh... Should have been as careful as I was reviewing the code and read the commit log once again. Sorry for the noise.
Quoted 4 lines
Quoted 1 line
I would recommend to keep this check in patch 1, then add another patch that swaps
CONFIG_ENV_OFFSET==CONFIG_ENV_OFFSET_REDUNDformmc_offset(mmc, 0)==mmc_offset(mmc, 1)What benefit would that bring ?
1) rework to not use ifdefery,
2) add support for OF properties,
If 2) becomes an issue, easy to revert and keep the move out of ifdefery in.
Considering the change is documented in the commit log,
Thanks!
Quentin
Hi Marek,
Thank you for the patch.
Quoted 13 lines · Marek Vasut
Introduce a new function
mmc_env_is_redundant_in_both_boot_hwparts()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.
Quoted 1 line
Signed-off-by Marek Vasut <[email protected]>
Quoted 1 line
---
Quoted 13 lines · Marek Vasut
Introduce a new function
mmc_env_is_redundant_in_both_boot_hwparts()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.
Quoted 1 line
[...]
Applied to u-boot/next, thanks!
Signature · 1 line
Tom