All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] stm32mp: use device sequence number in boot_instance variable
@ 2021-07-06 15:19 Patrick Delaunay
  2021-07-06 15:19 ` [PATCH 2/2] ARM: dts: stm32mp15: remove mmc alias Patrick Delaunay
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Patrick Delaunay @ 2021-07-06 15:19 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, U-Boot STM32

Use the device sequence number in boot_instance variable
and no more the SDMMC instance provided by ROM code/TF-A.

After this patch we don't need to define the mmc alias in
device tree, for example:
  mmc0 = &sdmmc1;
  mmc1 = &sdmmc2;
  mmc2 = &sdmmc3;
to have a correct mapping between the ROM code boot device =
"${boot_device}${boot_instance}" and the MMC device in U-Boot.

With this patch the 'mmc0' device (used in mmc commands) is
always used when only one instance sdmmc is activated in device
tree, even if it is only the sdmmc2 or sdmmc3.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
Dependancy with [1] to have correct 'mmc' node name (sdmmc@ => mmc@)
from kernel "ARM: dts: stm32: Rename mmc controller nodes to mmc@"

[1] "arm: dts: stm32mp15: alignment with v5.13"
    http://patchwork.ozlabs.org/project/uboot/list/?series=251100&state=*


 arch/arm/mach-stm32mp/cpu.c                | 16 +++++++++-
 arch/arm/mach-stm32mp/include/mach/stm32.h |  4 +++
 board/st/stm32mp1/stm32mp1.c               | 35 +++++++++++++++++-----
 3 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
index 592bfd413d..f6ed2ce0e4 100644
--- a/arch/arm/mach-stm32mp/cpu.c
+++ b/arch/arm/mach-stm32mp/cpu.c
@@ -483,6 +483,11 @@ static void setup_boot_mode(void)
 		STM32_UART7_BASE,
 		STM32_UART8_BASE
 	};
+	const u32 sdmmc_addr[] = {
+		STM32_SDMMC1_BASE,
+		STM32_SDMMC2_BASE,
+		STM32_SDMMC3_BASE
+	};
 	char cmd[60];
 	u32 boot_ctx = readl(TAMP_BOOT_CONTEXT);
 	u32 boot_mode =
@@ -525,7 +530,16 @@ static void setup_boot_mode(void)
 		break;
 	case BOOT_FLASH_SD:
 	case BOOT_FLASH_EMMC:
-		sprintf(cmd, "%d", instance);
+		if (instance > ARRAY_SIZE(sdmmc_addr))
+			break;
+		/* search associated sdmmc node in devicetree */
+		sprintf(cmd, "mmc@%x", sdmmc_addr[instance]);
+		if (uclass_get_device_by_name(UCLASS_MMC, cmd, &dev)) {
+			printf("mmc%d = %s not found in device tree!\n",
+			       instance, cmd);
+			break;
+		}
+		sprintf(cmd, "%d", dev_seq(dev));
 		env_set("boot_device", "mmc");
 		env_set("boot_instance", cmd);
 		break;
diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h b/arch/arm/mach-stm32mp/include/mach/stm32.h
index 5fdb893b0e..c11a9903f2 100644
--- a/arch/arm/mach-stm32mp/include/mach/stm32.h
+++ b/arch/arm/mach-stm32mp/include/mach/stm32.h
@@ -32,6 +32,10 @@
 #define STM32_UART7_BASE		0x40018000
 #define STM32_UART8_BASE		0x40019000
 
+#define STM32_SDMMC1_BASE		0x58005000
+#define STM32_SDMMC2_BASE		0x58007000
+#define STM32_SDMMC3_BASE		0x48004000
+
 #define STM32_SYSRAM_BASE		0x2FFC0000
 #define STM32_SYSRAM_SIZE		SZ_256K
 
diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
index 18b8870269..2faf5c81b4 100644
--- a/board/st/stm32mp1/stm32mp1.c
+++ b/board/st/stm32mp1/stm32mp1.c
@@ -841,6 +841,31 @@ const char *env_ext4_get_intf(void)
 	}
 }
 
+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);
+};
+
 const char *env_ext4_get_dev_part(void)
 {
 	static char *const env_dev_part =
@@ -854,22 +879,16 @@ const char *env_ext4_get_dev_part(void)
 	if (strlen(env_dev_part) > 0)
 		return env_dev_part;
 
-	u32 bootmode = get_bootmode();
-
-	return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
+	return dev_part[mmc_get_boot()];
 }
 
 int mmc_get_env_dev(void)
 {
-	u32 bootmode;
-
 	if (CONFIG_SYS_MMC_ENV_DEV >= 0)
 		return CONFIG_SYS_MMC_ENV_DEV;
 
-	bootmode = get_bootmode();
-
 	/* use boot instance to select the correct mmc device identifier */
-	return (bootmode & TAMP_BOOT_INSTANCE_MASK) - 1;
+	return mmc_get_boot();
 }
 
 #if defined(CONFIG_OF_BOARD_SETUP)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] ARM: dts: stm32mp15: remove mmc alias
  2021-07-06 15:19 [PATCH 1/2] stm32mp: use device sequence number in boot_instance variable Patrick Delaunay
@ 2021-07-06 15:19 ` Patrick Delaunay
  2021-07-07  7:35   ` Patrice CHOTARD
  2021-07-16  8:31   ` Patrick DELAUNAY
  2021-07-07  7:37 ` [PATCH 1/2] stm32mp: use device sequence number in boot_instance variable Patrice CHOTARD
  2021-07-16  8:32 ` Patrick DELAUNAY
  2 siblings, 2 replies; 6+ messages in thread
From: Patrick Delaunay @ 2021-07-06 15:19 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, Tom Rini, uboot-stm32

Remove the mmc alias no more required as the sequence number
of mmc device is used for boot_instance.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

 arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi | 1 -
 arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi | 2 --
 2 files changed, 3 deletions(-)

diff --git a/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi b/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi
index 6787619290..7dcc96c19c 100644
--- a/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi
+++ b/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi
@@ -10,7 +10,6 @@
 / {
 	aliases {
 		i2c3 = &i2c4;
-		mmc0 = &sdmmc1;
 		usb0 = &usbotg_hs;
 	};
 	config {
diff --git a/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi b/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi
index f3002e995b..46a43371bd 100644
--- a/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi
+++ b/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi
@@ -10,8 +10,6 @@
 / {
 	aliases {
 		i2c3 = &i2c4;
-		mmc0 = &sdmmc1;
-		mmc1 = &sdmmc2;
 	};
 
 	config {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] ARM: dts: stm32mp15: remove mmc alias
  2021-07-06 15:19 ` [PATCH 2/2] ARM: dts: stm32mp15: remove mmc alias Patrick Delaunay
@ 2021-07-07  7:35   ` Patrice CHOTARD
  2021-07-16  8:31   ` Patrick DELAUNAY
  1 sibling, 0 replies; 6+ messages in thread
From: Patrice CHOTARD @ 2021-07-07  7:35 UTC (permalink / raw)
  To: Patrick Delaunay, u-boot

Hi Patrick

On 7/6/21 5:19 PM, Patrick Delaunay wrote:
> Remove the mmc alias no more required as the sequence number
> of mmc device is used for boot_instance.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> 
>  arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi | 1 -
>  arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi | 2 --
>  2 files changed, 3 deletions(-)
> 
> diff --git a/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi b/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi
> index 6787619290..7dcc96c19c 100644
> --- a/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi
> +++ b/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi
> @@ -10,7 +10,6 @@
>  / {
>  	aliases {
>  		i2c3 = &i2c4;
> -		mmc0 = &sdmmc1;
>  		usb0 = &usbotg_hs;
>  	};
>  	config {
> diff --git a/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi b/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi
> index f3002e995b..46a43371bd 100644
> --- a/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi
> +++ b/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi
> @@ -10,8 +10,6 @@
>  / {
>  	aliases {
>  		i2c3 = &i2c4;
> -		mmc0 = &sdmmc1;
> -		mmc1 = &sdmmc2;
>  	};
>  
>  	config {
> 
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] stm32mp: use device sequence number in boot_instance variable
  2021-07-06 15:19 [PATCH 1/2] stm32mp: use device sequence number in boot_instance variable Patrick Delaunay
  2021-07-06 15:19 ` [PATCH 2/2] ARM: dts: stm32mp15: remove mmc alias Patrick Delaunay
@ 2021-07-07  7:37 ` Patrice CHOTARD
  2021-07-16  8:32 ` Patrick DELAUNAY
  2 siblings, 0 replies; 6+ messages in thread
From: Patrice CHOTARD @ 2021-07-07  7:37 UTC (permalink / raw)
  To: Patrick Delaunay, u-boot; +Cc: U-Boot STM32

Hi Patrick

On 7/6/21 5:19 PM, Patrick Delaunay wrote:
> Use the device sequence number in boot_instance variable
> and no more the SDMMC instance provided by ROM code/TF-A.
> 
> After this patch we don't need to define the mmc alias in
> device tree, for example:
>   mmc0 = &sdmmc1;
>   mmc1 = &sdmmc2;
>   mmc2 = &sdmmc3;
> to have a correct mapping between the ROM code boot device =
> "${boot_device}${boot_instance}" and the MMC device in U-Boot.
> 
> With this patch the 'mmc0' device (used in mmc commands) is
> always used when only one instance sdmmc is activated in device
> tree, even if it is only the sdmmc2 or sdmmc3.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> Dependancy with [1] to have correct 'mmc' node name (sdmmc@ => mmc@)
> from kernel "ARM: dts: stm32: Rename mmc controller nodes to mmc@"
> 
> [1] "arm: dts: stm32mp15: alignment with v5.13"
>     http://patchwork.ozlabs.org/project/uboot/list/?series=251100&state=*
> 
> 
>  arch/arm/mach-stm32mp/cpu.c                | 16 +++++++++-
>  arch/arm/mach-stm32mp/include/mach/stm32.h |  4 +++
>  board/st/stm32mp1/stm32mp1.c               | 35 +++++++++++++++++-----
>  3 files changed, 46 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
> index 592bfd413d..f6ed2ce0e4 100644
> --- a/arch/arm/mach-stm32mp/cpu.c
> +++ b/arch/arm/mach-stm32mp/cpu.c
> @@ -483,6 +483,11 @@ static void setup_boot_mode(void)
>  		STM32_UART7_BASE,
>  		STM32_UART8_BASE
>  	};
> +	const u32 sdmmc_addr[] = {
> +		STM32_SDMMC1_BASE,
> +		STM32_SDMMC2_BASE,
> +		STM32_SDMMC3_BASE
> +	};
>  	char cmd[60];
>  	u32 boot_ctx = readl(TAMP_BOOT_CONTEXT);
>  	u32 boot_mode =
> @@ -525,7 +530,16 @@ static void setup_boot_mode(void)
>  		break;
>  	case BOOT_FLASH_SD:
>  	case BOOT_FLASH_EMMC:
> -		sprintf(cmd, "%d", instance);
> +		if (instance > ARRAY_SIZE(sdmmc_addr))
> +			break;
> +		/* search associated sdmmc node in devicetree */
> +		sprintf(cmd, "mmc@%x", sdmmc_addr[instance]);
> +		if (uclass_get_device_by_name(UCLASS_MMC, cmd, &dev)) {
> +			printf("mmc%d = %s not found in device tree!\n",
> +			       instance, cmd);
> +			break;
> +		}
> +		sprintf(cmd, "%d", dev_seq(dev));
>  		env_set("boot_device", "mmc");
>  		env_set("boot_instance", cmd);
>  		break;
> diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h b/arch/arm/mach-stm32mp/include/mach/stm32.h
> index 5fdb893b0e..c11a9903f2 100644
> --- a/arch/arm/mach-stm32mp/include/mach/stm32.h
> +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h
> @@ -32,6 +32,10 @@
>  #define STM32_UART7_BASE		0x40018000
>  #define STM32_UART8_BASE		0x40019000
>  
> +#define STM32_SDMMC1_BASE		0x58005000
> +#define STM32_SDMMC2_BASE		0x58007000
> +#define STM32_SDMMC3_BASE		0x48004000
> +
>  #define STM32_SYSRAM_BASE		0x2FFC0000
>  #define STM32_SYSRAM_SIZE		SZ_256K
>  
> diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
> index 18b8870269..2faf5c81b4 100644
> --- a/board/st/stm32mp1/stm32mp1.c
> +++ b/board/st/stm32mp1/stm32mp1.c
> @@ -841,6 +841,31 @@ const char *env_ext4_get_intf(void)
>  	}
>  }
>  
> +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);
> +};
> +
>  const char *env_ext4_get_dev_part(void)
>  {
>  	static char *const env_dev_part =
> @@ -854,22 +879,16 @@ const char *env_ext4_get_dev_part(void)
>  	if (strlen(env_dev_part) > 0)
>  		return env_dev_part;
>  
> -	u32 bootmode = get_bootmode();
> -
> -	return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
> +	return dev_part[mmc_get_boot()];
>  }
>  
>  int mmc_get_env_dev(void)
>  {
> -	u32 bootmode;
> -
>  	if (CONFIG_SYS_MMC_ENV_DEV >= 0)
>  		return CONFIG_SYS_MMC_ENV_DEV;
>  
> -	bootmode = get_bootmode();
> -
>  	/* use boot instance to select the correct mmc device identifier */
> -	return (bootmode & TAMP_BOOT_INSTANCE_MASK) - 1;
> +	return mmc_get_boot();
>  }
>  
>  #if defined(CONFIG_OF_BOARD_SETUP)
> 

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

Thanks
Patrice

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] ARM: dts: stm32mp15: remove mmc alias
  2021-07-06 15:19 ` [PATCH 2/2] ARM: dts: stm32mp15: remove mmc alias Patrick Delaunay
  2021-07-07  7:35   ` Patrice CHOTARD
@ 2021-07-16  8:31   ` Patrick DELAUNAY
  1 sibling, 0 replies; 6+ messages in thread
From: Patrick DELAUNAY @ 2021-07-16  8:31 UTC (permalink / raw)
  To: u-boot; +Cc: Patrice Chotard, Tom Rini, uboot-stm32

Hi,

On 7/6/21 5:19 PM, Patrick Delaunay wrote:
> Remove the mmc alias no more required as the sequence number
> of mmc device is used for boot_instance.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
>
>   arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi | 1 -
>   arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi | 2 --
>   2 files changed, 3 deletions(-)
>

Applied to u-boot-stm/master, thanks!

Regards
Patrick


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] stm32mp: use device sequence number in boot_instance variable
  2021-07-06 15:19 [PATCH 1/2] stm32mp: use device sequence number in boot_instance variable Patrick Delaunay
  2021-07-06 15:19 ` [PATCH 2/2] ARM: dts: stm32mp15: remove mmc alias Patrick Delaunay
  2021-07-07  7:37 ` [PATCH 1/2] stm32mp: use device sequence number in boot_instance variable Patrice CHOTARD
@ 2021-07-16  8:32 ` Patrick DELAUNAY
  2 siblings, 0 replies; 6+ messages in thread
From: Patrick DELAUNAY @ 2021-07-16  8:32 UTC (permalink / raw)
  To: u-boot; +Cc: Patrice Chotard, U-Boot STM32

Hi,

On 7/6/21 5:19 PM, Patrick Delaunay wrote:
> Use the device sequence number in boot_instance variable
> and no more the SDMMC instance provided by ROM code/TF-A.
>
> After this patch we don't need to define the mmc alias in
> device tree, for example:
>    mmc0 = &sdmmc1;
>    mmc1 = &sdmmc2;
>    mmc2 = &sdmmc3;
> to have a correct mapping between the ROM code boot device =
> "${boot_device}${boot_instance}" and the MMC device in U-Boot.
>
> With this patch the 'mmc0' device (used in mmc commands) is
> always used when only one instance sdmmc is activated in device
> tree, even if it is only the sdmmc2 or sdmmc3.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> Dependancy with [1] to have correct 'mmc' node name (sdmmc@ => mmc@)
> from kernel "ARM: dts: stm32: Rename mmc controller nodes to mmc@"
>
> [1] "arm: dts: stm32mp15: alignment with v5.13"
>      http://patchwork.ozlabs.org/project/uboot/list/?series=251100&state=*
>
>
>   arch/arm/mach-stm32mp/cpu.c                | 16 +++++++++-
>   arch/arm/mach-stm32mp/include/mach/stm32.h |  4 +++
>   board/st/stm32mp1/stm32mp1.c               | 35 +++++++++++++++++-----
>   3 files changed, 46 insertions(+), 9 deletions(-)
>

Applied to u-boot-stm/master, thanks!

Regards
Patrick


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-16  8:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 15:19 [PATCH 1/2] stm32mp: use device sequence number in boot_instance variable Patrick Delaunay
2021-07-06 15:19 ` [PATCH 2/2] ARM: dts: stm32mp15: remove mmc alias Patrick Delaunay
2021-07-07  7:35   ` Patrice CHOTARD
2021-07-16  8:31   ` Patrick DELAUNAY
2021-07-07  7:37 ` [PATCH 1/2] stm32mp: use device sequence number in boot_instance variable Patrice CHOTARD
2021-07-16  8:32 ` Patrick DELAUNAY

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.