mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Xogium <contact@xogium.me>, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 07/24] ARM: stm32mp: build extra barebox-stm32mp-generic-bl33.img
Date: Sun, 20 Feb 2022 13:47:19 +0100	[thread overview]
Message-ID: <20220220124736.3052502-8-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220220124736.3052502-1-a.fatoum@pengutronix.de>

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 <a.fatoum@pengutronix.de>
---
 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

diff --git a/Documentation/boards/stm32mp.rst b/Documentation/boards/stm32mp.rst
index 2b9dc01b551a..55bdafe78579 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 4163bd176b1f..86c13b8fca8a 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 000000000000..6f779b19cf4d
--- /dev/null
+++ b/arch/arm/mach-stm32mp/bl33-generic.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <mach/entry.h>
+#include <debug_ll.h>
+
+/*
+ * 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 eeb5d9ecf6d3..862e955dbc59 100644
--- a/images/Makefile.stm32mp
+++ b/images/Makefile.stm32mp
@@ -25,6 +25,11 @@ endef
 
 # --------------------------------------
 
+# For use as --nt-fw (BL33) in FIP images
+pblb-y += start_stm32mp_bl33
+FILE_barebox-stm32mp-generic-bl33.img  = start_stm32mp_bl33.pblb
+image-y += 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)
 
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2022-02-20 12:52 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-20 12:47 [PATCH 00/24] ARM: stm32mp: add trusted bootchain (SCMI&FIP) support Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 01/24] PBL: fdt: factor reg property parsing into helper Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 02/24] pinctrl: stm32: use gpio-ranges instead of alias Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 03/24] ARM: stm32mp: simplify with build_stm32mp_image macro Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 04/24] ARM: stm32mp: change stm32image extension to .stm32 Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 05/24] filetype: detect TF-A Firmware Image Packages (FIP) Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 06/24] scripts: add tool to adjust bl33 load address in existing FIP Ahmad Fatoum
2022-02-20 12:47 ` Ahmad Fatoum [this message]
2022-02-21 10:35   ` [PATCH] fixup! ARM: stm32mp: build extra barebox-stm32mp-generic-bl33.img Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 08/24] ARM: stm32mp: ddrctrl: fix wrong register field widths Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 09/24] reset: stm32: drop stm32mp1_reset_ops indirection Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 10/24] reset: move stm32 reset code to drivers/power/reset Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 11/24] ARM: smccc: sync header with upstream Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 12/24] firmware: import Linux v5.13 SCMI support Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 13/24] reset: add " Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 14/24] clk: add SCMI clock driver Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 15/24] regulator: add SCMI regulator driver Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 16/24] clk: accept const arguments in clk_to_clk_hw/clk_hw_to_clk Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 17/24] serial: stm32: bail if clock_get_rate returns zero Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 18/24] clk: implement of_clk_hw_{onecell,simple}_get Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 19/24] clk: implement clk_hw_reparent Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 20/24] reset: add support for reset_control_status Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 21/24] clk: stm32mp1: sync with Linux v5.17-rc1 Ahmad Fatoum
2022-02-21 10:35   ` [PATCH] fixup! " Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 22/24] regulator: core: fall back to node name if no regulator-name property Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 23/24] ARM: dts: stm32mp: remove regulator-name override in stm32mp151.dtsi Ahmad Fatoum
2022-02-20 12:47 ` [PATCH 24/24] ARM: stm32mp: enable more config options Ahmad Fatoum
2022-02-23 10:57 ` [PATCH 00/24] ARM: stm32mp: add trusted bootchain (SCMI&FIP) support Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220220124736.3052502-8-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=contact@xogium.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox