From d31ca9e2598f0bafb7b8e83e7de1e19d51768bf3 Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Tue, 7 Oct 2025 10:16:04 +0200 Subject: [PATCH] imx: kontron-sl-mx8mm: Export current env config to devicetree 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 --- 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 #include #include +#include #include 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.47.3