]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
imx: kontron-sl-mx8mm: Export current env config to devicetree
authorFrieder Schrempf <frieder.schrempf@kontron.de>
Tue, 7 Oct 2025 08:16:04 +0000 (10:16 +0200)
committerFabio Estevam <festevam@gmail.com>
Tue, 7 Oct 2025 11:58:28 +0000 (08:58 -0300)
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@kontron.de>
board/kontron/sl-mx8mm/sl-mx8mm.c

index 405ac0fb03f7a445ed0e68679667bd7c7c27c4fa..cb0b3acdd624517667f5b7025bb0c0c2bd76ae54 100644 (file)
@@ -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)