[U-Boot] [PATCH v3 1/2] env_mmc: make board configurable the partition for the environment

This complements commit 9404a5fc7cb58 "env_mmc: allow environment to be in an eMMC partition" by allowing boards to accommodate the partition to use for the environment in different scenarios (similarly to what is done with the mmc dev number). Depending on the detected boot media, boards may decide to store the environment in a different partition.
The __weak function also allows to remove some ifdefs from the code. If CONFIG_SYS_MMC_ENV_PART is not defined, partition 0 is assumed (default value for U-Boot when a partition is not provided).
Signed-off-by: Hector Palacios hector.palacios@digi.com Reviewed-by: Stephen Warren swarren@nvidia.com ---
Notes: Changes since v2: - Move CONFIG_SYS_MMC_ENV_PART to config_fallbacks Changes since v1: - Use default define if not set
common/env_mmc.c | 25 +++++++++++++------------ include/config_fallbacks.h | 6 ++++++ 2 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/common/env_mmc.c b/common/env_mmc.c index 78c2bc7a1f08..8dbeb057a3c4 100644 --- a/common/env_mmc.c +++ b/common/env_mmc.c @@ -66,6 +66,11 @@ __weak int mmc_get_env_devno(void) return CONFIG_SYS_MMC_ENV_DEV; }
+__weak int mmc_get_env_partno(void) +{ + return CONFIG_SYS_MMC_ENV_PART; +} + int env_init(void) { /* use default */ @@ -77,6 +82,9 @@ int env_init(void)
static int init_mmc_for_env(struct mmc *mmc) { + int mmc_env_devno = mmc_get_env_devno(); + int mmc_env_partno = mmc_get_env_partno(); + if (!mmc) { puts("No MMC card found\n"); return -1; @@ -87,30 +95,23 @@ static int init_mmc_for_env(struct mmc *mmc) return -1; }
-#ifdef CONFIG_SYS_MMC_ENV_PART - if (CONFIG_SYS_MMC_ENV_PART != mmc->part_num) { - int mmc_env_devno = mmc_get_env_devno(); - - if (mmc_switch_part(mmc_env_devno, - CONFIG_SYS_MMC_ENV_PART)) { + if (mmc_env_partno != mmc->part_num) { + if (mmc_switch_part(mmc_env_devno, mmc_env_partno)) { puts("MMC partition switch failed\n"); return -1; } } -#endif
return 0; }
static void fini_mmc_for_env(struct mmc *mmc) { -#ifdef CONFIG_SYS_MMC_ENV_PART int mmc_env_devno = mmc_get_env_devno(); + int mmc_env_partno = mmc_get_env_partno();
- if (CONFIG_SYS_MMC_ENV_PART != mmc->part_num) - mmc_switch_part(mmc_env_devno, - mmc->part_num); -#endif + if (mmc_env_partno != mmc->part_num) + mmc_switch_part(mmc_env_devno, mmc->part_num); }
#ifdef CONFIG_CMD_SAVEENV diff --git a/include/config_fallbacks.h b/include/config_fallbacks.h index e59ee963f71f..7a6f55feb12e 100644 --- a/include/config_fallbacks.h +++ b/include/config_fallbacks.h @@ -53,4 +53,10 @@ #define HAVE_BLOCK_DEVICE #endif
+#if defined(CONFIG_MMC) +#if !defined(CONFIG_SYS_MMC_ENV_PART) +#define CONFIG_SYS_MMC_ENV_PART 0 +#endif +#endif + #endif /* __CONFIG_FALLBACKS_H */

Since function mmc_get_env_devno is __weak and can be overridden by board code, boards do not need to mandatory define CONFIG_SYS_MMC_ENV_DEV. If the constant is not defined, define it to 0 by default.
Signed-off-by: Hector Palacios hector.palacios@digi.com Reviewed-by: Stephen Warren swarren@nvidia.com ---
Notes: Changes since v2: - Move CONFIG_SYS_MMC_ENV_DEV to config_fallbacks Changes since v1: - Use default define if not set
include/config_fallbacks.h | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/include/config_fallbacks.h b/include/config_fallbacks.h index 7a6f55feb12e..b17fb28d90b9 100644 --- a/include/config_fallbacks.h +++ b/include/config_fallbacks.h @@ -54,6 +54,9 @@ #endif
#if defined(CONFIG_MMC) +#if !defined(CONFIG_SYS_MMC_ENV_DEV) +#define CONFIG_SYS_MMC_ENV_DEV 0 +#endif #if !defined(CONFIG_SYS_MMC_ENV_PART) #define CONFIG_SYS_MMC_ENV_PART 0 #endif

On Thu, Jan 23, 2014 at 10:39 AM, Hector Palacios hector.palacios@digi.com wrote:
Since function mmc_get_env_devno is __weak and can be overridden by board code, boards do not need to mandatory define CONFIG_SYS_MMC_ENV_DEV. If the constant is not defined, define it to 0 by default.
Signed-off-by: Hector Palacios hector.palacios@digi.com Reviewed-by: Stephen Warren swarren@nvidia.com
Acked-by: Otavio Salvador otavio@ossystems.com.br

On Thu, Jan 23, 2014 at 10:39 AM, Hector Palacios hector.palacios@digi.com wrote:
This complements commit 9404a5fc7cb58 "env_mmc: allow environment to be in an eMMC partition" by allowing boards to accommodate the partition to use for the environment in different scenarios (similarly to what is done with the mmc dev number). Depending on the detected boot media, boards may decide to store the environment in a different partition.
The __weak function also allows to remove some ifdefs from the code. If CONFIG_SYS_MMC_ENV_PART is not defined, partition 0 is assumed (default value for U-Boot when a partition is not provided).
Signed-off-by: Hector Palacios hector.palacios@digi.com Reviewed-by: Stephen Warren swarren@nvidia.com
Acked-by: Otavio Salvador otavio@ossystems.com.br

Hi Hector,
On Jan 23, 2014, at 2:39 PM, Hector Palacios wrote:
This complements commit 9404a5fc7cb58 "env_mmc: allow environment to be in an eMMC partition" by allowing boards to accommodate the partition to use for the environment in different scenarios (similarly to what is done with the mmc dev number). Depending on the detected boot media, boards may decide to store the environment in a different partition.
The __weak function also allows to remove some ifdefs from the code. If CONFIG_SYS_MMC_ENV_PART is not defined, partition 0 is assumed (default value for U-Boot when a partition is not provided).
Signed-off-by: Hector Palacios hector.palacios@digi.com Reviewed-by: Stephen Warren swarren@nvidia.com
The patch does not apply cleanly after Tom's mmc patches went in.
Can you please rework and report? Thanks.
Regards
-- Pantelis

Hi Antoniou,
On 02/07/2014 05:26 PM, Pantelis Antoniou wrote:
Hi Hector,
On Jan 23, 2014, at 2:39 PM, Hector Palacios wrote:
This complements commit 9404a5fc7cb58 "env_mmc: allow environment to be in an eMMC partition" by allowing boards to accommodate the partition to use for the environment in different scenarios (similarly to what is done with the mmc dev number). Depending on the detected boot media, boards may decide to store the environment in a different partition.
The __weak function also allows to remove some ifdefs from the code. If CONFIG_SYS_MMC_ENV_PART is not defined, partition 0 is assumed (default value for U-Boot when a partition is not provided).
Signed-off-by: Hector Palacios hector.palacios@digi.com Reviewed-by: Stephen Warren swarren@nvidia.com
The patch does not apply cleanly after Tom's mmc patches went in.
Can you please rework and report? Thanks.
Ooops. I'm afraid I applied this after an unofficial non-upstream Freescale patch. Without it, this series just doesn't fit. I would need to resend a version that includes Freescale missing patch, and have this reviewed.
Sorry about that.
participants (4)
-
Hector Palacios
-
Otavio Salvador
-
Palacios, Hector
-
Pantelis Antoniou