[U-Boot] [RFC 1/4] env: Rework mmc environment ifdef

Maxime Ripard maxime.ripard at free-electrons.com
Wed Oct 25 12:25:58 UTC 2017


We want the MMC environment code to be compilable so that it can be used by
other environment methods, even if it's not the primary one.

Rework slightly the ifdef to do that.

Signed-off-by: Maxime Ripard <maxime.ripard at free-electrons.com>
---
 env/mmc.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/env/mmc.c b/env/mmc.c
index 3f3092d97560..ffbd1f7c0e59 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -143,7 +143,10 @@ static inline int write_env(struct mmc *mmc, unsigned long size,
 	return (n == blk_cnt) ? 0 : -1;
 }
 
-static int env_mmc_save(void)
+#ifdef CONFIG_ENV_IS_IN_MMC
+static
+#endif
+int env_mmc_save(void)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
 	int dev = mmc_get_env_dev();
@@ -206,10 +209,13 @@ static inline int read_env(struct mmc *mmc, unsigned long size,
 	return (n == blk_cnt) ? 0 : -1;
 }
 
-#ifdef CONFIG_ENV_OFFSET_REDUND
-static int env_mmc_load(void)
+#ifdef CONFIG_ENV_IS_IN_MMC
+static
+#endif
+int env_mmc_load(void)
 {
 #if !defined(ENV_IS_EMBEDDED)
+#ifdef CONFIG_ENV_OFFSET_REDUND
 	struct mmc *mmc;
 	u32 offset1, offset2;
 	int read1_fail = 0, read2_fail = 0;
@@ -265,13 +271,7 @@ err:
 	if (ret)
 		set_default_env(errmsg);
 
-#endif
-	return ret;
-}
 #else /* ! CONFIG_ENV_OFFSET_REDUND */
-static int env_mmc_load(void)
-{
-#if !defined(ENV_IS_EMBEDDED)
 	ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
 	struct mmc *mmc;
 	u32 offset;
@@ -306,11 +306,12 @@ fini:
 err:
 	if (ret)
 		set_default_env(errmsg);
-#endif
+#endif /* CONFIG_ENV_OFFSET_REDUND */
+#endif /* ENV_IS_EMBEDDED */
 	return ret;
 }
-#endif /* CONFIG_ENV_OFFSET_REDUND */
 
+#ifdef CONFIG_ENV_IS_IN_MMC
 U_BOOT_ENV_LOCATION(mmc) = {
 	.location	= ENVL_MMC,
 	ENV_NAME("MMC")
@@ -319,3 +320,4 @@ U_BOOT_ENV_LOCATION(mmc) = {
 	.save		= env_save_ptr(env_mmc_save),
 #endif
 };
+#endif /* CONFIG_ENV_IS_IN_MMC */
-- 
2.14.2



More information about the U-Boot mailing list