[v2,24/35] arm: stm32mp: stm32mp2: move boot device environment helpers to SoC code

Message ID 20261107143241.2236511-25-dario.binacchi@amarulasolutions.com
State New
Headers
Series Add Engicam MicroGEA-STM32MP257D-RMM board support |

Commit Message

Dario Binacchi Nov. 7, 2026, 2:32 p.m. UTC
The environment location and the MMC environment device only depend on
the boot device reported by the ROM code, so they are not specific to
the STMicroelectronics boards.

Move env_get_location(), mmc_get_env_dev() and the mmc_get_boot() helper
to the SoC code, so that other vendor boards can use them too.

No functional change intended.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

(no changes since v1)

 arch/arm/mach-stm32mp/stm32mp2/Makefile |  1 +
 arch/arm/mach-stm32mp/stm32mp2/env.c    | 82 +++++++++++++++++++++++++
 board/st/stm32mp2/stm32mp2.c            | 71 +--------------------
 3 files changed, 84 insertions(+), 70 deletions(-)
 create mode 100644 arch/arm/mach-stm32mp/stm32mp2/env.c

-- 
2.43.0
  

Comments

Patrice CHOTARD Nov. 16, 2026, 2:34 p.m. UTC | #1
On 11/7/26 15:32, Dario Binacchi wrote:
> The environment location and the MMC environment device only depend on
> the boot device reported by the ROM code, so they are not specific to
> the STMicroelectronics boards.
> 
> Move env_get_location(), mmc_get_env_dev() and the mmc_get_boot() helper
> to the SoC code, so that other vendor boards can use them too.
> 
> No functional change intended.
> 
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> ---
> 
> (no changes since v1)
> 
>  arch/arm/mach-stm32mp/stm32mp2/Makefile |  1 +
>  arch/arm/mach-stm32mp/stm32mp2/env.c    | 82 +++++++++++++++++++++++++
>  board/st/stm32mp2/stm32mp2.c            | 71 +--------------------
>  3 files changed, 84 insertions(+), 70 deletions(-)
>  create mode 100644 arch/arm/mach-stm32mp/stm32mp2/env.c
> 
> diff --git a/arch/arm/mach-stm32mp/stm32mp2/Makefile b/arch/arm/mach-stm32mp/stm32mp2/Makefile
> index 8f2e641dcab6..f2def2d1283e 100644
> --- a/arch/arm/mach-stm32mp/stm32mp2/Makefile
> +++ b/arch/arm/mach-stm32mp/stm32mp2/Makefile
> @@ -5,6 +5,7 @@
>  
>  obj-y += cpu.o
>  obj-y += arm64-mmu.o
> +obj-y += env.o
>  obj-y += rifsc.o
>  obj-y += stm32mp2x.o
>  obj-$(CONFIG_OF_SYSTEM_SETUP) += fdt.o
> diff --git a/arch/arm/mach-stm32mp/stm32mp2/env.c b/arch/arm/mach-stm32mp/stm32mp2/env.c
> new file mode 100644
> index 000000000000..9e7b5b882908
> --- /dev/null
> +++ b/arch/arm/mach-stm32mp/stm32mp2/env.c
> @@ -0,0 +1,82 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause
> +/*
> + * Copyright (C) 2023, STMicroelectronics - All Rights Reserved
> + */
> +
> +#define LOG_CATEGORY LOGC_ARCH
> +
> +#include <config.h>
> +#include <env_internal.h>
> +#include <log.h>
> +#include <mmc.h>
> +#include <asm/arch/sys_proto.h>
> +#include <dm/device.h>
> +#include <dm/uclass.h>
> +
> +enum env_location env_get_location(enum env_operation op, int prio)
> +{
> +	u32 bootmode = get_bootmode();
> +
> +	if (prio)
> +		return ENVL_UNKNOWN;
> +
> +	switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
> +	case BOOT_FLASH_SD:
> +	case BOOT_FLASH_EMMC:
> +		if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
> +			return ENVL_MMC;
> +		else
> +			return ENVL_NOWHERE;
> +
> +	case BOOT_FLASH_NAND:
> +	case BOOT_FLASH_SPINAND:
> +		if (CONFIG_IS_ENABLED(ENV_IS_IN_UBI))
> +			return ENVL_UBI;
> +		else
> +			return ENVL_NOWHERE;
> +
> +	case BOOT_FLASH_NOR:
> +		if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
> +			return ENVL_SPI_FLASH;
> +		else
> +			return ENVL_NOWHERE;
> +	default:
> +		return ENVL_NOWHERE;
> +	}
> +}
> +
> +static 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_ENV_MMC_DEVICE_INDEX), (-1));
> +
> +	if (mmc_env_dev >= 0)
> +		return mmc_env_dev;
> +
> +	/* use boot instance to select the correct mmc device identifier */
> +	return mmc_get_boot();
> +}
> diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c
> index f2575339b990..96735fa9f8a1 100644
> --- a/board/st/stm32mp2/stm32mp2.c
> +++ b/board/st/stm32mp2/stm32mp2.c
> @@ -7,12 +7,11 @@
>  
>  #include <button.h>
>  #include <config.h>
> -#include <env_internal.h>
> +#include <env.h>
>  #include <fdt_support.h>
>  #include <led.h>
>  #include <log.h>
>  #include <misc.h>
> -#include <mmc.h>
>  #include <asm/global_data.h>
>  #include <asm/io.h>
>  #include <asm/arch/sys_proto.h>
> @@ -88,74 +87,6 @@ int board_init(void)
>  	return 0;
>  }
>  
> -enum env_location env_get_location(enum env_operation op, int prio)
> -{
> -	u32 bootmode = get_bootmode();
> -
> -	if (prio)
> -		return ENVL_UNKNOWN;
> -
> -	switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
> -	case BOOT_FLASH_SD:
> -	case BOOT_FLASH_EMMC:
> -		if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
> -			return ENVL_MMC;
> -		else
> -			return ENVL_NOWHERE;
> -
> -	case BOOT_FLASH_NAND:
> -	case BOOT_FLASH_SPINAND:
> -		if (CONFIG_IS_ENABLED(ENV_IS_IN_UBI))
> -			return ENVL_UBI;
> -		else
> -			return ENVL_NOWHERE;
> -
> -	case BOOT_FLASH_NOR:
> -		if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
> -			return ENVL_SPI_FLASH;
> -		else
> -			return ENVL_NOWHERE;
> -	default:
> -		return ENVL_NOWHERE;
> -	}
> -}
> -
> -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_ENV_MMC_DEVICE_INDEX), (-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;

Hi Dario

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice
  

Patch

diff --git a/arch/arm/mach-stm32mp/stm32mp2/Makefile b/arch/arm/mach-stm32mp/stm32mp2/Makefile
index 8f2e641dcab6..f2def2d1283e 100644
--- a/arch/arm/mach-stm32mp/stm32mp2/Makefile
+++ b/arch/arm/mach-stm32mp/stm32mp2/Makefile
@@ -5,6 +5,7 @@ 
 
 obj-y += cpu.o
 obj-y += arm64-mmu.o
+obj-y += env.o
 obj-y += rifsc.o
 obj-y += stm32mp2x.o
 obj-$(CONFIG_OF_SYSTEM_SETUP) += fdt.o
diff --git a/arch/arm/mach-stm32mp/stm32mp2/env.c b/arch/arm/mach-stm32mp/stm32mp2/env.c
new file mode 100644
index 000000000000..9e7b5b882908
--- /dev/null
+++ b/arch/arm/mach-stm32mp/stm32mp2/env.c
@@ -0,0 +1,82 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause
+/*
+ * Copyright (C) 2023, STMicroelectronics - All Rights Reserved
+ */
+
+#define LOG_CATEGORY LOGC_ARCH
+
+#include <config.h>
+#include <env_internal.h>
+#include <log.h>
+#include <mmc.h>
+#include <asm/arch/sys_proto.h>
+#include <dm/device.h>
+#include <dm/uclass.h>
+
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+	u32 bootmode = get_bootmode();
+
+	if (prio)
+		return ENVL_UNKNOWN;
+
+	switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
+	case BOOT_FLASH_SD:
+	case BOOT_FLASH_EMMC:
+		if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
+			return ENVL_MMC;
+		else
+			return ENVL_NOWHERE;
+
+	case BOOT_FLASH_NAND:
+	case BOOT_FLASH_SPINAND:
+		if (CONFIG_IS_ENABLED(ENV_IS_IN_UBI))
+			return ENVL_UBI;
+		else
+			return ENVL_NOWHERE;
+
+	case BOOT_FLASH_NOR:
+		if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
+			return ENVL_SPI_FLASH;
+		else
+			return ENVL_NOWHERE;
+	default:
+		return ENVL_NOWHERE;
+	}
+}
+
+static 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_ENV_MMC_DEVICE_INDEX), (-1));
+
+	if (mmc_env_dev >= 0)
+		return mmc_env_dev;
+
+	/* use boot instance to select the correct mmc device identifier */
+	return mmc_get_boot();
+}
diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c
index f2575339b990..96735fa9f8a1 100644
--- a/board/st/stm32mp2/stm32mp2.c
+++ b/board/st/stm32mp2/stm32mp2.c
@@ -7,12 +7,11 @@ 
 
 #include <button.h>
 #include <config.h>
-#include <env_internal.h>
+#include <env.h>
 #include <fdt_support.h>
 #include <led.h>
 #include <log.h>
 #include <misc.h>
-#include <mmc.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
 #include <asm/arch/sys_proto.h>
@@ -88,74 +87,6 @@  int board_init(void)
 	return 0;
 }
 
-enum env_location env_get_location(enum env_operation op, int prio)
-{
-	u32 bootmode = get_bootmode();
-
-	if (prio)
-		return ENVL_UNKNOWN;
-
-	switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
-	case BOOT_FLASH_SD:
-	case BOOT_FLASH_EMMC:
-		if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
-			return ENVL_MMC;
-		else
-			return ENVL_NOWHERE;
-
-	case BOOT_FLASH_NAND:
-	case BOOT_FLASH_SPINAND:
-		if (CONFIG_IS_ENABLED(ENV_IS_IN_UBI))
-			return ENVL_UBI;
-		else
-			return ENVL_NOWHERE;
-
-	case BOOT_FLASH_NOR:
-		if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
-			return ENVL_SPI_FLASH;
-		else
-			return ENVL_NOWHERE;
-	default:
-		return ENVL_NOWHERE;
-	}
-}
-
-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_ENV_MMC_DEVICE_INDEX), (-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;