From: Frieder Schrempf <frieder.schre...@kontron.de>

In case we boot from SD card or eMMC, we also want to load
the environment from the according boot device.

Signed-off-by: Frieder Schrempf <frieder.schre...@kontron.de>
---
 board/kontron/sl-mx8mm/sl-mx8mm.c  | 31 ++++++++++++++++++++++++++++++
 configs/kontron-sl-mx8mm_defconfig |  1 +
 2 files changed, 32 insertions(+)

diff --git a/board/kontron/sl-mx8mm/sl-mx8mm.c 
b/board/kontron/sl-mx8mm/sl-mx8mm.c
index fea93278374..416c4cbb407 100644
--- a/board/kontron/sl-mx8mm/sl-mx8mm.c
+++ b/board/kontron/sl-mx8mm/sl-mx8mm.c
@@ -4,10 +4,13 @@
  */
 
 #include <asm/arch/imx-regs.h>
+#include <asm/arch/sys_proto.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
+#include <asm/mach-imx/boot_mode.h>
 #include <efi.h>
 #include <efi_loader.h>
+#include <env_internal.h>
 #include <fdt_support.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
@@ -117,3 +120,31 @@ int board_init(void)
 {
        return 0;
 }
+
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+       enum boot_device boot_dev = get_boot_device();
+
+       if (prio)
+               return ENVL_UNKNOWN;
+
+       /*
+        * Make sure that the environment is loaded from
+        * the MMC if we are running from SD card or eMMC.
+        */
+       if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC) &&
+           (boot_dev == SD1_BOOT || boot_dev == SD2_BOOT))
+               return ENVL_MMC;
+
+       if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
+               return ENVL_SPI_FLASH;
+
+       return ENVL_NOWHERE;
+}
+
+#if defined(CONFIG_ENV_IS_IN_MMC)
+int board_mmc_get_env_dev(int devno)
+{
+       return devno;
+}
+#endif
diff --git a/configs/kontron-sl-mx8mm_defconfig 
b/configs/kontron-sl-mx8mm_defconfig
index 064f7d0caf6..e6b5c8f800a 100644
--- a/configs/kontron-sl-mx8mm_defconfig
+++ b/configs/kontron-sl-mx8mm_defconfig
@@ -69,6 +69,7 @@ CONFIG_CMD_EXT4_WRITE=y
 
CONFIG_MTDPARTS_DEFAULT="mtdparts=spi0.0:320k(spl),1024k(u-boot),64k(env),64k(env_redundant)"
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
+CONFIG_ENV_IS_IN_MMC=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
-- 
2.37.0

Reply via email to