[PATCH 05/21] board: st: stm32mp2: add mmc_get_env_dev()
Patrice Chotard
patrice.chotard at foss.st.com
Thu Apr 24 08:07:07 CEST 2025
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 <patrick.delaunay at foss.st.com>
Signed-off-by: Patrice Chotard <patrice.chotard at foss.st.com>
---
board/st/stm32mp2/stm32mp2.c | 37 ++++++++++++++++++++++++++++++++++++
configs/stm32mp25_defconfig | 2 +-
2 files changed, 38 insertions(+), 1 deletion(-)
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 <fdt_support.h>
#include <log.h>
#include <misc.h>
+#include <mmc.h>
#include <asm/global_data.h>
#include <asm/arch/sys_proto.h>
#include <dm/device.h>
@@ -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
--
2.25.1
More information about the U-Boot
mailing list