From: Patrice Chotard Date: Tue, 22 Apr 2025 15:33:42 +0000 (+0200) Subject: board: st: stm32mp2: add mmc_get_env_dev() X-Git-Tag: v2025.07-rc1~11^2~17 X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3be0ccc4746b64a6ed2f955b1238e9c53de8b16;p=pandora-u-boot.git board: st: stm32mp2: add mmc_get_env_dev() Use the boot instance to select the correct mmc device identifier, this patch only to save the environment on eMMC = MMC(1) on STMicroelectronics boards. Set the CONFIG_SYS_MMC_ENV_DEV to -1 to select the mmc boot instance by default. Signed-off-by: Patrick Delaunay Signed-off-by: Patrice Chotard --- diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c index c70ffaf5dbd..8446b8fd3d6 100644 --- a/board/st/stm32mp2/stm32mp2.c +++ b/board/st/stm32mp2/stm32mp2.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,42 @@ enum env_location env_get_location(enum env_operation op, int prio) } } +int mmc_get_boot(void) +{ + struct udevice *dev; + u32 boot_mode = get_bootmode(); + unsigned int instance = (boot_mode & TAMP_BOOT_INSTANCE_MASK) - 1; + char cmd[20]; + const u32 sdmmc_addr[] = { + STM32_SDMMC1_BASE, + STM32_SDMMC2_BASE, + STM32_SDMMC3_BASE + }; + + if (instance > ARRAY_SIZE(sdmmc_addr)) + return 0; + + /* search associated sdmmc node in devicetree */ + snprintf(cmd, sizeof(cmd), "mmc@%x", sdmmc_addr[instance]); + if (uclass_get_device_by_name(UCLASS_MMC, cmd, &dev)) { + log_err("mmc%d = %s not found in device tree!\n", instance, cmd); + return 0; + } + + return dev_seq(dev); +}; + +int mmc_get_env_dev(void) +{ + const int mmc_env_dev = CONFIG_IS_ENABLED(ENV_IS_IN_MMC, (CONFIG_SYS_MMC_ENV_DEV), (-1)); + + if (mmc_env_dev >= 0) + return mmc_env_dev; + + /* use boot instance to select the correct mmc device identifier */ + return mmc_get_boot(); +} + int board_late_init(void) { const void *fdt_compat; diff --git a/configs/stm32mp25_defconfig b/configs/stm32mp25_defconfig index d11910f139f..fd5c36ec3e2 100644 --- a/configs/stm32mp25_defconfig +++ b/configs/stm32mp25_defconfig @@ -36,7 +36,7 @@ CONFIG_CMD_LOG=y CONFIG_OF_LIVE=y CONFIG_ENV_IS_NOWHERE=y CONFIG_ENV_IS_IN_MMC=y -CONFIG_SYS_MMC_ENV_DEV=1 +CONFIG_SYS_MMC_ENV_DEV=-1 CONFIG_NO_NET=y CONFIG_SYS_64BIT_LBA=y CONFIG_GPIO_HOG=y