From: Frieder Schrempf <[email protected]>

Enable storing the environment on SD card and choose the env location
according to the boot device.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Frieder Schrempf <[email protected]>
---
 board/sielaff/imx6dl-sielaff/imx6dl-sielaff.c | 30 +++++++++++++++++++
 configs/imx6dl_sielaff_defconfig              |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/board/sielaff/imx6dl-sielaff/imx6dl-sielaff.c 
b/board/sielaff/imx6dl-sielaff/imx6dl-sielaff.c
index 4da084ed91c..f2c206cfeb0 100644
--- a/board/sielaff/imx6dl-sielaff/imx6dl-sielaff.c
+++ b/board/sielaff/imx6dl-sielaff/imx6dl-sielaff.c
@@ -9,6 +9,7 @@
 #include <asm/arch/crm_regs.h>
 #include <asm/arch/mx6-pins.h>
 #include <asm/io.h>
+#include <env_internal.h>
 #include <init.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -109,3 +110,32 @@ int board_init(void)
 
        return 0;
 }
+
+/*
+ * Keep the environment on the device we were booted from. The boot fuses
+ * use the SD card as primary boot device and the SPI NOR as the ECSPI
+ * recovery device, so both are valid places for the environment to live.
+ */
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+       u32 bmode;
+
+       if (prio > 0)
+               return ENVL_UNKNOWN;
+
+       if (imx6_is_ecspi_recovery_boot())
+               return ENVL_SPI_FLASH;
+
+       bmode = (imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
+               IMX6_BMODE_SHIFT;
+
+       switch (bmode) {
+       case IMX6_BMODE_SD:
+       case IMX6_BMODE_ESD:
+       case IMX6_BMODE_MMC:
+       case IMX6_BMODE_EMMC:
+               return ENVL_MMC;
+       default:
+               return ENVL_SPI_FLASH;
+       }
+}
diff --git a/configs/imx6dl_sielaff_defconfig b/configs/imx6dl_sielaff_defconfig
index bfa4c4aa1d8..615c2935844 100644
--- a/configs/imx6dl_sielaff_defconfig
+++ b/configs/imx6dl_sielaff_defconfig
@@ -61,8 +61,10 @@ CONFIG_EFI_PARTITION=y
 # CONFIG_SPL_EFI_PARTITION is not set
 CONFIG_OF_CONTROL=y
 CONFIG_OF_UPSTREAM=y
+CONFIG_ENV_IS_IN_MMC=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_ENV_RELOC_GD_ENV_ADDR=y
+CONFIG_ENV_MMC_DEVICE_INDEX=2
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
 CONFIG_BOUNCE_BUFFER=y
 CONFIG_USB_FUNCTION_FASTBOOT=y
-- 
2.55.0

Reply via email to