[PATCH 07/13] imx: kontron-sl-mx8mm: Export current env config to devicetree

Frieder Schrempf frieder at fris.de
Tue Oct 7 10:16:04 CEST 2025


From: Frieder Schrempf <frieder.schrempf at kontron.de>

This allows userspace tools like libubootenv to determine the
location of the currently used environment and select a
matching config.

Signed-off-by: Frieder Schrempf <frieder.schrempf at kontron.de>
---
 board/kontron/sl-mx8mm/sl-mx8mm.c | 36 +++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/board/kontron/sl-mx8mm/sl-mx8mm.c b/board/kontron/sl-mx8mm/sl-mx8mm.c
index 405ac0fb03f..cb0b3acdd62 100644
--- a/board/kontron/sl-mx8mm/sl-mx8mm.c
+++ b/board/kontron/sl-mx8mm/sl-mx8mm.c
@@ -14,6 +14,7 @@
 #include <fdt_support.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
+#include <mmc.h>
 #include <net.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -108,12 +109,43 @@ int fdt_set_usb_eth_addr(void *blob)
 
 int ft_board_setup(void *blob, struct bd_info *bd)
 {
-	int ret = fdt_set_usb_eth_addr(blob);
+	enum env_location env_loc;
+	enum boot_device boot_dev;
+	char env_str_sd[] = "sd-card";
+	char env_str_nor[] = "spi-nor";
+	char env_str_emmc[] = "emmc";
+	char *env_config_str;
+	int ret;
+
+	ret = fdt_set_usb_eth_addr(blob);
+	if (ret)
+		return ret;
 
+	ret = fdt_fixup_memory(blob, PHYS_SDRAM, gd->ram_size);
 	if (ret)
 		return ret;
 
-	return fdt_fixup_memory(blob, PHYS_SDRAM, gd->ram_size);
+	env_loc = env_get_location(0, 0);
+	if (env_loc == ENVL_MMC) {
+		boot_dev = get_boot_device();
+		if (boot_dev == SD2_BOOT)
+			env_config_str = env_str_sd;
+		else if (boot_dev == MMC1_BOOT)
+			env_config_str = env_str_emmc;
+		else
+			return 0;
+	} else if (env_loc == ENVL_SPI_FLASH) {
+		env_config_str = env_str_nor;
+	} else {
+		return 0;
+	}
+
+	/*
+	 * Export a string to the devicetree that tells userspace tools like
+	 * libubootenv where the environment is currently coming from.
+	 */
+	return fdt_find_and_setprop(blob, "/chosen", "u-boot,env-config",
+				    env_config_str, strlen(env_config_str) + 1, 1);
 }
 
 int board_late_init(void)
-- 
2.51.0



More information about the U-Boot mailing list