diff mbox series

[1/4,RFC] ARM: stm32: Implement board coding on AV96

Message ID 20200331234807.432637-1-marex@denx.de
State RFC
Delegated to: Patrick Delaunay
Headers show
Series [1/4,RFC] ARM: stm32: Implement board coding on AV96 | expand

Commit Message

Marek Vasut March 31, 2020, 11:48 p.m. UTC
The AV96 board does exist in multiple variants. To cater for all of
them, implement board code handling. There are two GPIOs which code
the type of the board, read them out and use the value to pick the
correct device tree from an fitImage.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: Patrice Chotard <patrice.chotard@st.com>
---
 arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi |  9 +++
 arch/arm/mach-stm32mp/spl.c                |  2 +-
 board/dhelectronics/dh_stm32mp1/board.c    | 84 ++++++++++++++++++++++
 board/dhelectronics/dh_stm32mp1/u-boot.its | 39 ++++++++++
 configs/stm32mp15_dhcor_basic_defconfig    |  3 +
 5 files changed, 136 insertions(+), 1 deletion(-)
 create mode 100644 board/dhelectronics/dh_stm32mp1/u-boot.its

Comments

Patrick DELAUNAY April 7, 2020, 7:51 a.m. UTC | #1
Dear Marek,

> From: Marek Vasut <marex@denx.de>
> Sent: mercredi 1 avril 2020 01:48
> 
> The AV96 board does exist in multiple variants. To cater for all of them, implement
> board code handling. There are two GPIOs which code the type of the board, read
> them out and use the value to pick the correct device tree from an fitImage.

Nice.
 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> Cc: Patrick Delaunay <patrick.delaunay@st.com>
> Cc: Patrice Chotard <patrice.chotard@st.com>
> ---
>  arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi |  9 +++
>  arch/arm/mach-stm32mp/spl.c                |  2 +-
>  board/dhelectronics/dh_stm32mp1/board.c    | 84 ++++++++++++++++++++++
>  board/dhelectronics/dh_stm32mp1/u-boot.its | 39 ++++++++++
>  configs/stm32mp15_dhcor_basic_defconfig    |  3 +
>  5 files changed, 136 insertions(+), 1 deletion(-)  create mode 100644
> board/dhelectronics/dh_stm32mp1/u-boot.its
> 

[...]

> diff --git a/arch/arm/mach-stm32mp/spl.c b/arch/arm/mach-stm32mp/spl.c index
> ca4231cd0d..5461572090 100644
> --- a/arch/arm/mach-stm32mp/spl.c
> +++ b/arch/arm/mach-stm32mp/spl.c
> @@ -76,7 +76,7 @@ void spl_display_print(void)  }  #endif
> 
> -void board_init_f(ulong dummy)
> +__weak void board_init_f(ulong dummy)
>  {
>  	struct udevice *dev;
>  	int ret;
> diff --git a/board/dhelectronics/dh_stm32mp1/board.c
> b/board/dhelectronics/dh_stm32mp1/board.c
> index a3458a2623..36b8652521 100644
> --- a/board/dhelectronics/dh_stm32mp1/board.c
> +++ b/board/dhelectronics/dh_stm32mp1/board.c
> @@ -133,6 +133,90 @@ int checkboard(void)
>  	return 0;
>  }

It is really need to add weak and duplicate all this function ?

Is it possible to define a weak function called just before DDR init ?

As board_early_init_f for example....done in mach-rockchip/spl.c
Or at91_spl_board_init() in mach-at91/spl_at91.c

In ./arch/arm/mach-stm32mp/spl.c

+__weak int board_early_init_f(void)
+{
+	return 0;
+}

void board_init_f(ulong dummy)
{
	struct udevice *dev;
	int ret;

	arch_cpu_init();

[....]
	/* enable console uart printing */
	preloader_console_init();

+	board_early_init_f();

	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
	if (ret) {
		printf("DRAM init failed: %d\n", ret);
		hang();
	}
}

[....]

> +
> +void board_init_f(ulong dummy)
> +{
> +	struct udevice *dev;
> +	int ret;
> +
> +	arch_cpu_init();

[....]

> +
> +	/* enable console uart printing */
> +	preloader_console_init();
> +
> +	board_get_coding_straps();
> +
> +	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
> +	if (ret) {
> +		printf("DRAM init failed: %d\n", ret);
> +		hang();
> +	}
> +}

With my proposal:


__weak int board_early_init_f(void)
{
	board_get_coding_straps();

	return 0;
}

> +#ifdef CONFIG_SPL_LOAD_FIT
> +int board_fit_config_name_match(const char *name) {
> +	if (somcode == 0 && !strcmp(name, "586-100"))
> +		return 0;
> +
> +	return -EINVAL;
> +}
> +#endif
> +#endif
> +
>  static void board_key_check(void)
>  {
>  #if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG) diff --
> git a/board/dhelectronics/dh_stm32mp1/u-boot.its
> b/board/dhelectronics/dh_stm32mp1/u-boot.its
> new file mode 100644
> index 0000000000..3ca3036f7e
> --- /dev/null
> +++ b/board/dhelectronics/dh_stm32mp1/u-boot.its

[...]

> diff --git a/configs/stm32mp15_dhcor_basic_defconfig
> b/configs/stm32mp15_dhcor_basic_defconfig
> index 97e95bde7d..6c5ca31f40 100644
> --- a/configs/stm32mp15_dhcor_basic_defconfig
> +++ b/configs/stm32mp15_dhcor_basic_defconfig
> @@ -11,7 +11,10 @@ CONFIG_SPL_SPI_SUPPORT=y
>  CONFIG_SPL_TEXT_BASE=0x2FFC2500
>  CONFIG_DISTRO_DEFAULTS=y
>  CONFIG_FIT=y
> +CONFIG_SPL_LOAD_FIT=y
> +CONFIG_SPL_FIT_SOURCE="board/dhelectronics/dh_stm32mp1/u-boot.its"
>  CONFIG_BOOTCOMMAND="run bootcmd_stm32mp"
> +CONFIG_SPL_LEGACY_IMAGE_SUPPORT=y
>  CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION=y
>  CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=3
>  CONFIG_SPL_I2C_SUPPORT=y

To include the needed target in "make all" you can also add

+ CONFIG_BUILD_TARGET="u-boot.itb"

Or change default in Kconfig (add ARCH_STM32MP for SPL_LOAD_FIT case)

> --
> 2.25.1

Regards

Patrick
Marek Vasut April 7, 2020, 9:04 a.m. UTC | #2
On 4/7/20 9:51 AM, Patrick DELAUNAY wrote:
> Dear Marek,

Hi,

[...]

>> b/board/dhelectronics/dh_stm32mp1/board.c
>> index a3458a2623..36b8652521 100644
>> --- a/board/dhelectronics/dh_stm32mp1/board.c
>> +++ b/board/dhelectronics/dh_stm32mp1/board.c
>> @@ -133,6 +133,90 @@ int checkboard(void)
>>  	return 0;
>>  }
> 
> It is really need to add weak and duplicate all this function ?
> 
> Is it possible to define a weak function called just before DDR init ?
> 
> As board_early_init_f for example....done in mach-rockchip/spl.c
> Or at91_spl_board_init() in mach-at91/spl_at91.c
> 
> In ./arch/arm/mach-stm32mp/spl.c
> 
> +__weak int board_early_init_f(void)
> +{
> +	return 0;
> +}
> 
> void board_init_f(ulong dummy)
> {
> 	struct udevice *dev;
> 	int ret;
> 
> 	arch_cpu_init();
> 
> [....]
> 	/* enable console uart printing */
> 	preloader_console_init();
> 
> +	board_early_init_f();

[...]

>> diff --git a/configs/stm32mp15_dhcor_basic_defconfig
>> b/configs/stm32mp15_dhcor_basic_defconfig
>> index 97e95bde7d..6c5ca31f40 100644
>> --- a/configs/stm32mp15_dhcor_basic_defconfig
>> +++ b/configs/stm32mp15_dhcor_basic_defconfig
>> @@ -11,7 +11,10 @@ CONFIG_SPL_SPI_SUPPORT=y
>>  CONFIG_SPL_TEXT_BASE=0x2FFC2500
>>  CONFIG_DISTRO_DEFAULTS=y
>>  CONFIG_FIT=y
>> +CONFIG_SPL_LOAD_FIT=y
>> +CONFIG_SPL_FIT_SOURCE="board/dhelectronics/dh_stm32mp1/u-boot.its"
>>  CONFIG_BOOTCOMMAND="run bootcmd_stm32mp"
>> +CONFIG_SPL_LEGACY_IMAGE_SUPPORT=y
>>  CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION=y
>>  CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=3
>>  CONFIG_SPL_I2C_SUPPORT=y
> 
> To include the needed target in "make all" you can also add
> 
> + CONFIG_BUILD_TARGET="u-boot.itb"
> 
> Or change default in Kconfig (add ARCH_STM32MP for SPL_LOAD_FIT case)

I very much have both in my tree already, so I'll send a non-RFC.
diff mbox series

Patch

diff --git a/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi b/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi
index 02dad81b0b..17a23ae21c 100644
--- a/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi
+++ b/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi
@@ -11,6 +11,15 @@ 
 #include "stm32mp157-u-boot.dtsi"
 #include "stm32mp15-ddr3-2x4Gb-1066-binG.dtsi"
 
+/ {
+	u-boot,dm-pre-reloc;
+	config {
+		u-boot,dm-pre-reloc;
+		#gpio-cells = <2>;
+		dh,som-coding-gpios = <&gpioz 7 0>, <&gpiof 3 0>;
+	};
+};
+
 &i2c4 {
 	u-boot,dm-pre-reloc;
 };
diff --git a/arch/arm/mach-stm32mp/spl.c b/arch/arm/mach-stm32mp/spl.c
index ca4231cd0d..5461572090 100644
--- a/arch/arm/mach-stm32mp/spl.c
+++ b/arch/arm/mach-stm32mp/spl.c
@@ -76,7 +76,7 @@  void spl_display_print(void)
 }
 #endif
 
-void board_init_f(ulong dummy)
+__weak void board_init_f(ulong dummy)
 {
 	struct udevice *dev;
 	int ret;
diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c
index a3458a2623..36b8652521 100644
--- a/board/dhelectronics/dh_stm32mp1/board.c
+++ b/board/dhelectronics/dh_stm32mp1/board.c
@@ -133,6 +133,90 @@  int checkboard(void)
 	return 0;
 }
 
+#ifdef CONFIG_SPL_BUILD
+static u8 somcode __section("data");
+
+static void board_get_coding_straps(void)
+{
+	struct gpio_desc gpio;
+	ofnode node;
+	int i, ret;
+
+	node = ofnode_path("/config");
+	if (!ofnode_valid(node)) {
+		printf("%s: no /config node?\n", __func__);
+		return;
+	}
+
+	for (i = 0; i < 2; i++) {
+		ret = gpio_request_by_name_nodev(node, "dh,som-coding-gpios",
+						 i, &gpio, GPIOD_IS_IN);
+		if (ret) {
+			printf("%s: could not find a /config/dh,som-coding-gpios[%i]\n",
+			      __func__, i);
+			return;
+		}
+
+		somcode |= !!dm_gpio_get_value(&gpio) << i;
+	}
+
+	printf("Code:  SoM:%x\n", somcode);
+}
+
+void board_init_f(ulong dummy)
+{
+	struct udevice *dev;
+	int ret;
+
+	arch_cpu_init();
+
+	ret = spl_early_init();
+	if (ret) {
+		debug("spl_early_init() failed: %d\n", ret);
+		hang();
+	}
+
+	ret = uclass_get_device(UCLASS_CLK, 0, &dev);
+	if (ret) {
+		debug("Clock init failed: %d\n", ret);
+		return;
+	}
+
+	ret = uclass_get_device(UCLASS_RESET, 0, &dev);
+	if (ret) {
+		debug("Reset init failed: %d\n", ret);
+		return;
+	}
+
+	ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev);
+	if (ret) {
+		debug("%s: Cannot find pinctrl device\n", __func__);
+		return;
+	}
+
+	/* enable console uart printing */
+	preloader_console_init();
+
+	board_get_coding_straps();
+
+	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
+	if (ret) {
+		printf("DRAM init failed: %d\n", ret);
+		hang();
+	}
+}
+
+#ifdef CONFIG_SPL_LOAD_FIT
+int board_fit_config_name_match(const char *name)
+{
+	if (somcode == 0 && !strcmp(name, "586-100"))
+		return 0;
+
+	return -EINVAL;
+}
+#endif
+#endif
+
 static void board_key_check(void)
 {
 #if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
diff --git a/board/dhelectronics/dh_stm32mp1/u-boot.its b/board/dhelectronics/dh_stm32mp1/u-boot.its
new file mode 100644
index 0000000000..3ca3036f7e
--- /dev/null
+++ b/board/dhelectronics/dh_stm32mp1/u-boot.its
@@ -0,0 +1,39 @@ 
+/dts-v1/;
+
+/ {
+	description = "U-Boot mainline";
+	#address-cells = <1>;
+
+	images {
+		uboot {
+			description = "U-Boot (32-bit)";
+			data = /incbin/("../../../u-boot-nodtb.bin");
+			type = "standalone";
+			os = "U-Boot";
+			arch = "arm";
+			compression = "none";
+			load = <0xc0100000>;
+			entry = <0xc0100000>;
+		};
+
+		fdt-1 {
+			description = ".dtb";
+			data = /incbin/("../../../arch/arm/dts/stm32mp15xx-dhcor-avenger96.dtb");
+			type = "flat_dt";
+			arch = "arm";
+			compression = "none";
+		};
+	};
+
+	configurations {
+		default = "config-1";
+
+		config-1 {
+			description = "586-100";	/* SoM model */
+			loadables = "uboot";
+			fdt = "fdt-1";
+		};
+
+		/* Add 586-200..586-400 with fdt-2..fdt-4 here */
+	};
+};
diff --git a/configs/stm32mp15_dhcor_basic_defconfig b/configs/stm32mp15_dhcor_basic_defconfig
index 97e95bde7d..6c5ca31f40 100644
--- a/configs/stm32mp15_dhcor_basic_defconfig
+++ b/configs/stm32mp15_dhcor_basic_defconfig
@@ -11,7 +11,10 @@  CONFIG_SPL_SPI_SUPPORT=y
 CONFIG_SPL_TEXT_BASE=0x2FFC2500
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_FIT=y
+CONFIG_SPL_LOAD_FIT=y
+CONFIG_SPL_FIT_SOURCE="board/dhelectronics/dh_stm32mp1/u-boot.its"
 CONFIG_BOOTCOMMAND="run bootcmd_stm32mp"
+CONFIG_SPL_LEGACY_IMAGE_SUPPORT=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=3
 CONFIG_SPL_I2C_SUPPORT=y