[U-Boot] [PATCH v2] Add support for eMMC environment in boot partition
Sergey Kubushyn
ksi at koi8.net
Sun Oct 9 06:49:19 CEST 2016
This allows to place U-Boot environment into eMMC boot partition thus
saving space on user partition for the OS (or whatever.) When booting
off of eMMC many (all?) MCUs can use dedicated boot0/boot1 partitions
to boot so U-Boot (or SPL) is written to one (or both) such partitions.
When such boot configuration is used it makes sense to place environment
in the same partition where the U-Boot itself is so the entire user
partition is available for the OS.
It might be not well polished yet but it is a simple patch that can be
reworked later.
It uses 4 Kconfig variables right now which probably belong to the board
Kconfig. Those are:
CONFIG_ENV_IN_EMMC_BOOT -- tells that environment is in eMMC boot
partition if defined
CONFIG_EMMC_ENV_PART -- tells which boot partition environment should be
stored in (either 1 or 2)
CONFIG_EMMC_BOOT_PART -- which boot partition will be used by eMMC to
read U-Boot/SPL binary for boot protocol (either 1 or 2.) That can be
different from the environment partition
CONFIG_EMMC_BOOT_ACK -- tells that eMMC should provide boot ACKs if
defined
Here is an excerpt from actual board Kconfig:
=== Cut ===
config ENV_IN_EMMC_BOOT
bool "Environment is in eMMC boot partition"
default y
config EMMC_ENV_PART
hex "eMMC boot partition used for environment (1 or 2)"
default 1
config EMMC_BOOT_PART
hex "eMMC boot partition the board boots off of (1 or 2)"
default 1
config EMMC_BOOT_ACK
bool "Enable ACKs from eMMC when booting off of boot partition"
default n
=== Cut ===
Signed-off-by: Sergey Kubushyn <ksi at koi8.net>
Cc: Tom Rini <trini at konsulko.com>
Cc: Pantelis Antoniou <panto at antoniou-consulting.com>
---
common/env_mmc.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/common/env_mmc.c b/common/env_mmc.c
index 16f6a17..3b2477c 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -68,6 +68,45 @@ int env_init(void)
return 0;
}
+#ifdef CONFIG_ENV_IN_EMMC_BOOT
+__weak u8 mmc_get_env_part(struct mmc *mmc)
+{
+ return CONFIG_EMMC_ENV_PART;
+}
+
+__weak u8 mmc_get_boot_part(struct mmc *mmc)
+{
+ return CONFIG_EMMC_BOOT_PART;
+}
+
+__weak u8 mmc_get_boot_ack(struct mmc *mmc)
+{
+#ifdef CONFIG_EMMC_BOOT_ACK
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+static int mmc_set_env_part(struct mmc *mmc)
+{
+ int ret = 0;
+ u8 boot_part = 0;
+ u8 boot_ack = 0;
+ u8 env_part = 0;
+
+ boot_part = mmc_get_boot_part(mmc);
+ boot_ack = mmc_get_boot_ack(mmc);
+ env_part = mmc_get_env_part(mmc);
+
+ ret = mmc_set_part_conf(mmc, boot_ack, boot_part, env_part);
+
+ if (ret)
+ puts("MMC switch to boot partition failed\n");
+
+ return ret;
+}
+#else
#ifdef CONFIG_SYS_MMC_ENV_PART
__weak uint mmc_get_env_part(struct mmc *mmc)
{
@@ -96,6 +135,7 @@ static int mmc_set_env_part(struct mmc *mmc)
#else
static inline int mmc_set_env_part(struct mmc *mmc) {return 0; };
#endif
+#endif
static const char *init_mmc_for_env(struct mmc *mmc)
{
@@ -113,6 +153,15 @@ static const char *init_mmc_for_env(struct mmc *mmc)
static void fini_mmc_for_env(struct mmc *mmc)
{
+#ifdef CONFIG_ENV_IN_EMMC_BOOT
+ u8 boot_part = 0;
+ u8 boot_ack = 0;
+
+ boot_part = mmc_get_boot_part(mmc);
+ boot_ack = mmc_get_boot_ack(mmc);
+
+ mmc_set_part_conf(mmc, boot_ack, boot_part, 0);
+#else
#ifdef CONFIG_SYS_MMC_ENV_PART
int dev = mmc_get_env_dev();
@@ -121,6 +170,7 @@ static void fini_mmc_for_env(struct mmc *mmc)
#endif
blk_select_hwpart_devnum(IF_TYPE_MMC, dev, env_mmc_orig_hwpart);
#endif
+#endif
}
#ifdef CONFIG_CMD_SAVEENV
--
2.5.5
More information about the U-Boot
mailing list