From 3536e3904152210d70ae5ef6cf24c6d572cbf04f Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 Feb 2022 13:47:16 +0100 Subject: ARM: stm32mp: change stm32image extension to .stm32 The .img extension for stm32mp1 images is unfortunate. The format is deprecated and its header makes it not directly executable and thus not suitable as-is for use in a FIP image where the BL33 is run from offset 0. To make existence of the STM32 header evident, rename the extension from .img to .stm32. As it's still supported by TF-A, have symlinks, so user build script can use the old names for now. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20220220124736.3052502-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- Documentation/boards/stm32mp.rst | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'Documentation') diff --git a/Documentation/boards/stm32mp.rst b/Documentation/boards/stm32mp.rst index 24b7a19ceb..2b9dc01b55 100644 --- a/Documentation/boards/stm32mp.rst +++ b/Documentation/boards/stm32mp.rst @@ -10,7 +10,7 @@ The first stage boot loader (FSBL) is loaded by the ROM code into the built-in SYSRAM and executed. The FSBL sets up the SDRAM, install a secure monitor and then the second stage boot loader (SSBL) is loaded into DRAM. -When building barebox, the resulting ``barebox-${board}.img`` file has the STM32 +When building barebox, the resulting ``barebox-${board}.stm32`` file has the STM32 header preprended, so it can be loaded directly as SSBL by the ARM TF-A (https://github.com/ARM-software/arm-trusted-firmware). Each entry point has a header-less image ending in ``*.pblb`` as well. @@ -25,18 +25,23 @@ as sole defconfig for all STM32MP boards:: make ARCH=arm stm32mp_defconfig -The resulting images will be placed under ``images/``: +The resulting images will be placed under ``images/``:: -:: + barebox-stm32mp15xx-dkx.stm32 + barebox-stm32mp15x-ev1.stm32 + barebox-stm32mp157c-lxa-mc1.stm32 + barebox-prtt1a.stm32 + barebox-prtt1s.stm32 + barebox-prtt1c.stm32 + barebox-stm32mp157c-seeed-odyssey.stm32 + barebox-dt-2nd.img - barebox-stm32mp15xx-dkx.img # both DK1 and DK2 - barebox-stm32mp157c-lxa-mc1.img - barebox-stm32mp157c-seeed-odyssey.img - barebox-stm32mp15x-ev1.img # stm32mp157c-ev1 and friends +In the above output, images with a ``.stm32`` extension feature the (legacy) +stm32image header. ``barebox-dt-2nd.img`` is a generic barebox image that +received an external device tree. - -Flashing barebox ----------------- +Flashing barebox (legacy stm32image) +------------------------------------ An appropriate image for a SD-Card can be generated with following ``genimage(1)`` config:: @@ -55,7 +60,7 @@ An appropriate image for a SD-Card can be generated with following size = 256K } partition ssbl { - image = "barebox-@STM32MP_BOARD@.img" + image = "barebox-@STM32MP_BOARD@.stm32" size = 1M } partition barebox-environment { @@ -69,7 +74,7 @@ partitions may look like this:: image @STM32MP_BOARD@.img { partition ssbl { - image = "barebox-@STM32MP_BOARD@.img" + image = "barebox-@STM32MP_BOARD@.stm32" size = 1M } partition barebox-environment { -- cgit v1.2.3 From b07c1c88edd3753b8c10ef13b3c6daf78ab88b3f Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 Feb 2022 13:47:19 +0100 Subject: ARM: stm32mp: build extra barebox-stm32mp-generic-bl33.img barebox-dt-2nd.img expects being loaded at an offset, so the stack can grow down from entry point. The STM32MP TF-A default is to not have an offset. Avoid this issue by having a stm32mp specific entry point that sets up a 64 byte stack after end of barebox. As it's stm32mp-specific anyway, we can skip the early FDT parsing and ask the SDRAM controller about RAM size. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20220220124736.3052502-8-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- Documentation/boards/stm32mp.rst | 51 +++++++++++++++++++++++++++++++----- arch/arm/mach-stm32mp/Makefile | 1 + arch/arm/mach-stm32mp/bl33-generic.c | 24 +++++++++++++++++ images/Makefile.stm32mp | 5 ++++ 4 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 arch/arm/mach-stm32mp/bl33-generic.c (limited to 'Documentation') diff --git a/Documentation/boards/stm32mp.rst b/Documentation/boards/stm32mp.rst index 2b9dc01b55..55bdafe785 100644 --- a/Documentation/boards/stm32mp.rst +++ b/Documentation/boards/stm32mp.rst @@ -13,20 +13,26 @@ then the second stage boot loader (SSBL) is loaded into DRAM. When building barebox, the resulting ``barebox-${board}.stm32`` file has the STM32 header preprended, so it can be loaded directly as SSBL by the ARM TF-A (https://github.com/ARM-software/arm-trusted-firmware). Each entry point has a -header-less image ending in ``*.pblb`` as well. +header-less image ending in ``*.pblb`` as well. Additionally, there is +a ``barebox-stm32mp-generic.img``, which is a header-less image for +use as part of a Firmware Image Package (FIP). -Use of barebox as FSBL is not supported. +barebox images are meant to be loaded by the ARM TF-A +(https://github.com/ARM-software/arm-trusted-firmware). FIP images are +mandatory for STM32MP1 since TF-A v2.7. + +Use of barebox as FSBL is not implemented. Building barebox ---------------- -With multi-image and device trees, it's expected to have ``stm32mp_defconfig`` -as sole defconfig for all STM32MP boards:: +There's a single ``stm32mp_defconfig`` for all STM32MP boards:: make ARCH=arm stm32mp_defconfig The resulting images will be placed under ``images/``:: + barebox-stm32mp-generic-bl33.img barebox-stm32mp15xx-dkx.stm32 barebox-stm32mp15x-ev1.stm32 barebox-stm32mp157c-lxa-mc1.stm32 @@ -37,13 +43,44 @@ The resulting images will be placed under ``images/``:: barebox-dt-2nd.img In the above output, images with a ``.stm32`` extension feature the (legacy) -stm32image header. ``barebox-dt-2nd.img`` is a generic barebox image that -received an external device tree. +stm32image header. ``barebox-dt-2nd.img`` and ``barebox-stm32mp-generic-bl33.img`` +are board-generic barebox images that receive an external device tree. + +Flashing barebox (FIP) +---------------------- + +After building barebox in ``$BAREBOX_BUILDDIR``, change directory to ARM +Trusted Firmware to build a FIP image. Example building STM32MP157C-DK2 +with SP_min (no OP-TEE): + +.. code:: bash + + make CROSS_COMPILE=arm-none-eabi- PLAT=stm32mp1 ARCH=aarch32 ARM_ARCH_MAJOR=7 \ + STM32MP_EMMC=1 STM32MP_EMMC_BOOT=1 STM32MP_SDMMC=1 STM32MP_SPI_NOR=1 \ + AARCH32_SP=sp_min \ + DTB_FILE_NAME=stm32mp157c-dk2.dtb \ + BL33=$BAREBOX_BUILDDIR/images/barebox-stm32mp-generic-bl33.img \ + BL33_CFG=$BAREBOX_BUILDDIR/arch/arm/dts/stm32mp157c-dk2.dtb \ + fip + +For different boards, adjust ``DTB_FILENAME`` and ``BL33_CFG`` as appropriate. + +If OP-TEE is used, ensure ``CONFIG_OPTEE_SIZE`` is set appropriately, so +early barebox code does not attempt accessing secure memory. + +barebox can also be patched into an existing FIP image with ``fiptool``: + +.. code:: bash + + fiptool update mmcblk0p3 \ + --nt-fw $BAREBOX_BUILDDIR/images/barebox-stm32mp-generic-bl33.img \ + --hw-config $BAREBOX_BUILDDIR/arch/arm/dts/stm32mp135f-dk.dtb Flashing barebox (legacy stm32image) ------------------------------------ -An appropriate image for a SD-Card can be generated with following +After building ARM Trusted Firmware with ``STM32MP_USE_STM32IMAGE=1``, +an appropriate image for a SD-Card can be generated with following ``genimage(1)`` config:: image @STM32MP_BOARD@.img { diff --git a/arch/arm/mach-stm32mp/Makefile b/arch/arm/mach-stm32mp/Makefile index 4163bd176b..86c13b8fca 100644 --- a/arch/arm/mach-stm32mp/Makefile +++ b/arch/arm/mach-stm32mp/Makefile @@ -2,4 +2,5 @@ obj-y := init.o obj-pbl-y := ddrctrl.o +pbl-y := bl33-generic.o obj-$(CONFIG_BOOTM) += stm32image.o diff --git a/arch/arm/mach-stm32mp/bl33-generic.c b/arch/arm/mach-stm32mp/bl33-generic.c new file mode 100644 index 0000000000..6f779b19cf --- /dev/null +++ b/arch/arm/mach-stm32mp/bl33-generic.c @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +/* + * barebox-dt-2nd.img expects being loaded at an offset, so the + * stack can grow down from entry point. The STM32MP TF-A default + * is to not have an offset. This stm32mp specific entry points + * avoids this issue by setting up a 64 byte stack after end of + * barebox and by asking the memory controller about RAM size + * instead of parsing it out of the DT. + * + * When using OP-TEE, ensure CONFIG_OPTEE_SIZE is appopriately set. + */ + +ENTRY_FUNCTION(start_stm32mp_bl33, r0, r1, r2) +{ + stm32mp_cpu_lowlevel_init(); + + putc_ll('>'); + + stm32mp1_barebox_entry((void *)r2); +} diff --git a/images/Makefile.stm32mp b/images/Makefile.stm32mp index eeb5d9ecf6..fa79e09f95 100644 --- a/images/Makefile.stm32mp +++ b/images/Makefile.stm32mp @@ -25,6 +25,11 @@ endef # -------------------------------------- +# For use as --nt-fw (BL33) in FIP images +pblb-$(CONFIG_ARCH_STM32MP) += start_stm32mp_bl33 +FILE_barebox-stm32mp-generic-bl33.img = start_stm32mp_bl33.pblb +image-$(CONFIG_ARCH_STM32MP) += barebox-stm32mp-generic-bl33.img + $(call build_stm32mp_image, CONFIG_MACH_STM32MP15XX_DKX, start_stm32mp15xx_dkx, stm32mp15xx-dkx) $(call build_stm32mp_image, CONFIG_MACH_STM32MP15X_EV1, start_stm32mp15x_ev1, stm32mp15x-ev1) -- cgit v1.2.3 From c7bb31362687174027660c2d393e7686523be856 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 21 Feb 2022 11:36:25 +0100 Subject: ARM: stm32mp: add board support for STM32MP135F-DK We already have the needed drivers in place to support the upcoming STM32MP131. Linux already has a basic DT for the DK board. Add a barebox board that leverages it. To try it out modify the existing FIP with: fiptool update --nt-fw build/images/barebox-stm32mp-generic-bl33.img \ --hw-config build/arch/arm/dts/stm32mp135f-dk.dtb \ mmcblk0p3 Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20220221103625.3728055-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- Documentation/boards/stm32mp.rst | 1 + arch/arm/boards/Makefile | 1 + arch/arm/boards/stm32mp13xx-dk/Makefile | 2 ++ arch/arm/boards/stm32mp13xx-dk/lowlevel.c | 19 +++++++++++++++++++ arch/arm/dts/Makefile | 1 + arch/arm/dts/stm32mp131.dtsi | 14 ++++++++++++++ arch/arm/dts/stm32mp135f-dk.dts | 12 ++++++++++++ arch/arm/mach-stm32mp/Kconfig | 8 ++++++++ images/Makefile.stm32mp | 1 + 9 files changed, 59 insertions(+) create mode 100644 arch/arm/boards/stm32mp13xx-dk/Makefile create mode 100644 arch/arm/boards/stm32mp13xx-dk/lowlevel.c create mode 100644 arch/arm/dts/stm32mp131.dtsi create mode 100644 arch/arm/dts/stm32mp135f-dk.dts (limited to 'Documentation') diff --git a/Documentation/boards/stm32mp.rst b/Documentation/boards/stm32mp.rst index 55bdafe785..6f4b14049a 100644 --- a/Documentation/boards/stm32mp.rst +++ b/Documentation/boards/stm32mp.rst @@ -33,6 +33,7 @@ There's a single ``stm32mp_defconfig`` for all STM32MP boards:: The resulting images will be placed under ``images/``:: barebox-stm32mp-generic-bl33.img + barebox-stm32mp13xx-dk.stm32 barebox-stm32mp15xx-dkx.stm32 barebox-stm32mp15x-ev1.stm32 barebox-stm32mp157c-lxa-mc1.stm32 diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile index a15963c775..8557e1dca8 100644 --- a/arch/arm/boards/Makefile +++ b/arch/arm/boards/Makefile @@ -139,6 +139,7 @@ obj-$(CONFIG_MACH_SOCFPGA_TERASIC_SOCKIT) += terasic-sockit/ obj-$(CONFIG_MACH_SOLIDRUN_CUBOX) += solidrun-cubox/ obj-$(CONFIG_MACH_SOLIDRUN_MICROSOM) += solidrun-microsom/ obj-$(CONFIG_MACH_STM32MP15XX_DKX) += stm32mp15xx-dkx/ +obj-$(CONFIG_MACH_STM32MP13XX_DK) += stm32mp13xx-dk/ obj-$(CONFIG_MACH_LXA_MC1) += lxa-mc1/ obj-$(CONFIG_MACH_STM32MP15X_EV1) += stm32mp15x-ev1/ obj-$(CONFIG_MACH_TECHNEXION_PICO_HOBBIT) += technexion-pico-hobbit/ diff --git a/arch/arm/boards/stm32mp13xx-dk/Makefile b/arch/arm/boards/stm32mp13xx-dk/Makefile new file mode 100644 index 0000000000..9961af02a3 --- /dev/null +++ b/arch/arm/boards/stm32mp13xx-dk/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +lwl-y += lowlevel.o diff --git a/arch/arm/boards/stm32mp13xx-dk/lowlevel.c b/arch/arm/boards/stm32mp13xx-dk/lowlevel.c new file mode 100644 index 0000000000..ac4fa40e19 --- /dev/null +++ b/arch/arm/boards/stm32mp13xx-dk/lowlevel.c @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include + +extern char __dtb_z_stm32mp135f_dk_start[]; + +ENTRY_FUNCTION(start_stm32mp13xx_dk, r0, r1, r2) +{ + void *fdt; + + stm32mp_cpu_lowlevel_init(); + + putc_ll('>'); + + fdt = __dtb_z_stm32mp135f_dk_start + get_runtime_offset(); + + stm32mp1_barebox_entry(fdt); +} diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index d419e8394d..e0bb66580f 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -127,6 +127,7 @@ lwl-$(CONFIG_MACH_SKOV_IMX6) += imx6s-skov-imx6.dtb.o imx6dl-skov-imx6.dtb.o imx lwl-$(CONFIG_MACH_SKOV_ARM9CPU) += at91-skov-arm9cpu.dtb.o lwl-$(CONFIG_MACH_SEEED_ODYSSEY) += stm32mp157c-odyssey.dtb.o lwl-$(CONFIG_MACH_STM32MP15XX_DKX) += stm32mp157c-dk2.dtb.o stm32mp157a-dk1.dtb.o +lwl-$(CONFIG_MACH_STM32MP13XX_DK) += stm32mp135f-dk.dtb.o lwl-$(CONFIG_MACH_LXA_MC1) += stm32mp157c-lxa-mc1.dtb.o lwl-$(CONFIG_MACH_STM32MP15X_EV1) += stm32mp157c-ev1.dtb.o lwl-$(CONFIG_MACH_SCB9328) += imx1-scb9328.dtb.o diff --git a/arch/arm/dts/stm32mp131.dtsi b/arch/arm/dts/stm32mp131.dtsi new file mode 100644 index 0000000000..2ecad85f08 --- /dev/null +++ b/arch/arm/dts/stm32mp131.dtsi @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/ { + aliases { + mmc0 = &sdmmc1; + }; +}; + +&{/soc} { + memory-controller@5a003000 { + compatible = "st,stm32mp13-ddr"; + reg = <0x5a003000 0x1000>; + }; +}; diff --git a/arch/arm/dts/stm32mp135f-dk.dts b/arch/arm/dts/stm32mp135f-dk.dts new file mode 100644 index 0000000000..104886e8af --- /dev/null +++ b/arch/arm/dts/stm32mp135f-dk.dts @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) + +#include +#include "stm32mp131.dtsi" + +/ { + model = "STM32MP153F-DK"; + + chosen { + stdout-path = "serial0:115200n8"; + }; +}; diff --git a/arch/arm/mach-stm32mp/Kconfig b/arch/arm/mach-stm32mp/Kconfig index 38c1a44770..57c1691591 100644 --- a/arch/arm/mach-stm32mp/Kconfig +++ b/arch/arm/mach-stm32mp/Kconfig @@ -6,10 +6,18 @@ config ARCH_NR_GPIO int default 416 +config ARCH_STM32MP13 + select ARM_PSCI_CLIENT + bool + config ARCH_STM32MP157 select ARM_PSCI_CLIENT bool +config MACH_STM32MP13XX_DK + select ARCH_STM32MP13 + bool "STM32MP137F DK board" + config MACH_STM32MP15XX_DKX select ARCH_STM32MP157 bool "STM32MP157 DK1 and DK2 boards" diff --git a/images/Makefile.stm32mp b/images/Makefile.stm32mp index fa79e09f95..abe70a6a50 100644 --- a/images/Makefile.stm32mp +++ b/images/Makefile.stm32mp @@ -30,6 +30,7 @@ pblb-$(CONFIG_ARCH_STM32MP) += start_stm32mp_bl33 FILE_barebox-stm32mp-generic-bl33.img = start_stm32mp_bl33.pblb image-$(CONFIG_ARCH_STM32MP) += barebox-stm32mp-generic-bl33.img +$(call build_stm32mp_image, CONFIG_MACH_STM32MP13XX_DK, start_stm32mp13xx_dk, stm32mp13xx-dk) $(call build_stm32mp_image, CONFIG_MACH_STM32MP15XX_DKX, start_stm32mp15xx_dkx, stm32mp15xx-dkx) $(call build_stm32mp_image, CONFIG_MACH_STM32MP15X_EV1, start_stm32mp15x_ev1, stm32mp15x-ev1) -- cgit v1.2.3