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 <k...@koi8.net>
---
--- 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


---
******************************************************************
*  KSI@home    KOI8 Net  < >  The impossible we do immediately.  *
*  Las Vegas   NV, USA   < >  Miracles require 24-hour notice.   *
******************************************************************
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to