Some SoCs support 'boot_device' and 'boot_instance' environment variables to select the right boot media during boot command execution.
The i.MX8M SoC doesn't set these variables but provides internally all the needed information to create them. Add setup_boot_mode() to arch_misc_init() to populate boot_device and boot_instance from the boot device reported by the ROM. Signed-off-by: William MARTIN <[email protected]> --- v2: rebase v3: fix boot_instance for mmc add second usb v4: fix flexspi/qspi for IMX8MQ --- --- arch/arm/mach-imx/imx8m/soc.c | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c index 1fe083ae94f..87b2d579d01 100644 --- a/arch/arm/mach-imx/imx8m/soc.c +++ b/arch/arm/mach-imx/imx8m/soc.c @@ -1472,6 +1472,80 @@ void reset_cpu(void) #endif #if IS_ENABLED(CONFIG_ARCH_MISC_INIT) +static void setup_boot_mode(void) +{ + enum boot_device dev = get_boot_device(); + + log_debug("setup_boot_mode = %u\n", dev); + + switch (dev) { + case USB_BOOT: + env_set("boot_device", "usb"); + env_set("boot_instance", "0"); + break; + + case USB2_BOOT: + env_set("boot_device", "usb"); + env_set("boot_instance", "1"); + break; + + case QSPI_BOOT: + if (IS_ENABLED(CONFIG_IMX8MQ)) { + env_set("boot_device", "qspi"); + } else { + env_set("boot_device", "flexspi"); + } + env_set("boot_instance", "0"); + break; + + case SPI_NOR_BOOT: + env_set("boot_device", "spi"); + env_set("boot_instance", "0"); + break; + + case NAND_BOOT: + env_set("boot_device", "nand"); + env_set("boot_instance", "0"); + break; + + case SD1_BOOT: + env_set("boot_device", "sdcard"); + env_set("boot_instance", "0"); + break; + + case SD2_BOOT: + env_set("boot_device", "sdcard"); + env_set("boot_instance", "1"); + break; + + case SD3_BOOT: + env_set("boot_device", "sdcard"); + env_set("boot_instance", "2"); + break; + + case MMC1_BOOT: + env_set("boot_device", "mmc"); + env_set("boot_instance", "0"); + break; + + case MMC2_BOOT: + env_set("boot_device", "mmc"); + env_set("boot_instance", "1"); + break; + + case MMC3_BOOT: + env_set("boot_device", "mmc"); + env_set("boot_instance", "2"); + break; + + default: + env_set("boot_device", "invalid"); + env_set("boot_instance", ""); + log_err("unexpected boot mode = %x\n", dev); + break; + } +} + int arch_misc_init(void) { if (IS_ENABLED(CONFIG_FSL_CAAM)) { @@ -1483,6 +1557,8 @@ int arch_misc_init(void) printf("Failed to initialize caam_jr: %d\n", ret); } + setup_boot_mode(); + return 0; } #endif -- 2.47.3

