Skip to contentSkip to conversation

ARM: bootm: Add support for starting Linux through OpTee-OS on ARMv7a

PATCH Superseded Marek Vasut 2 participants 3 messages May 12, 2025 – Jun 5, 2025 Arm (32-bit)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ARM: bootm: Add support for starting Linux through OpTee-OS on ARMv7a

Add support for jumping to Linux kernel through OpTee-OS on ARMv7a. This is only supported if U-Boot runs in PL1 secure. This change adds two components, one is fitImage OpTee-OS loadable handler, which makes a note of OpTee-OS being loaded and stores the load address for later jump to it. The second part is the actual jump to Linux through OpTee-OS. The jump through OpTee-OS requires set up of multiple CPU registers, r1 and r2 are passed through, r0 and r3 have to be set to 0, lr is set to Linux kernel entry point. This setup is done by new assembler function boot_jump_linux_via_optee().

The boot_jump_linux_via_optee() also includes STM32MP13xx late TZC configuration write, this cannot be moved easily, hence the ifdef.

---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Janne Grunau <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Patrick Rudolph <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]

---
 arch/arm/include/asm/armv7.h |  2 ++
 arch/arm/lib/Makefile        |  3 +++
 arch/arm/lib/bootm-optee.S   | 30 +++++++++++++++++++++++
 arch/arm/lib/bootm.c         | 47 +++++++++++++++++++++++++++---------
 4 files changed, 71 insertions(+), 11 deletions(-)
 create mode 100644 arch/arm/lib/bootm-optee.S
arch/arm/include/asm/armv7.h +2 -0
index c002998ac0b..bfffbbd5d9a 100644
@@ -142,6 +142,8 @@ bool armv7_boot_nonsec(void);
 unsigned int _nonsec_init(void);
 void _do_nonsec_entry(void *target_pc, unsigned long r0,
 		      unsigned long r1, unsigned long r2);
+void boot_jump_linux_via_optee(void *target_pc, unsigned long r1,
+			       unsigned long r2, unsigned long tee_entry);
 void _smp_pen(void);
 
 extern char __secure_start[];
arch/arm/lib/Makefile +3 -0
index ade42d0ca43..92149d7058c 100644
@@ -41,6 +41,9 @@ obj-$(CONFIG_CMD_BOOTZ) += zimage.o
 endif
 obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
 endif
+ifndef CONFIG_ARM64
+obj-$(CONFIG_BOOTM_OPTEE) += bootm-optee.o
+endif
 ifdef CONFIG_ARM64
 obj-$(CONFIG_$(PHASE_)USE_ARCH_MEMSET) += memset-arm64.o
 obj-$(CONFIG_$(PHASE_)USE_ARCH_MEMCPY) += memcpy-arm64.o
arch/arm/lib/bootm-optee.S new file +30 -0
new file mode 100644
index 00000000000..9d1a77b563d
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ *  Copyright (C) 2025 Marek Vasut
+ */
+#include <config.h>
+#include <linux/linkage.h>
+
+ENTRY(boot_jump_linux_via_optee)
+	mov	r4, r3
+	mov	lr, r0
+	mov	r3, #0
+	mov	r0, #0
+
+	/*
+	 * Special TZC handling on this platform, the last
+	 * 'str' has to be immediately before 'bx' and can
+	 * not be interleaved with any return from function
+	 * call, if it is then the system hangs.
+	 */
+#if defined(CONFIG_STM32MP13X) && !defined(CONFIG_TFABOOT)
+	ldr	r6, =STM32_TZC_BASE + 0x114 + (0x20 * 2)
+	mov	r7, #0x0
+	str	r7, [r6]
+	ldr	r6, =STM32_TZC_BASE + 0x110 + (0x20 * 1)
+	mov	r7, #0x1
+	str	r7, [r6]
+#endif
+
+	bx	r4
+ENDPROC(boot_jump_linux_via_optee)
arch/arm/lib/bootm.c +36 -11

77 lines not on this page · raw message

Signature · 1 line
2.47.2
#1 lore raw

PATCH 2/2 spl: fit: Add ability to jump to Linux via OpTee-OS on ARMv7a

Add support for jumping to Linux kernel through OpTee-OS on ARMv7a to SPL. This is already supported on ARMv8a, this patch adds the ARMv7a support. Extend the SPL fitImage loader to record OpTee-OS load address and in case the load address is non-zero, use the same bootm-optee.S code used by the U-Boot fitImage jump code to start OpTee-OS first and jump to Linux next.

---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Janne Grunau <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Patrick Rudolph <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]

---
 arch/arm/lib/spl.c   |  8 ++++++++
 common/spl/spl_fit.c | 20 ++++++++++++++++++++
 include/spl.h        |  3 +++
 3 files changed, 31 insertions(+)
arch/arm/lib/spl.c +8 -0
index c43a63f1819..f41a53f0ed2 100644
@@ -16,6 +16,7 @@
 #include <asm/global_data.h>
 #include <linux/compiler.h>
 #include <asm/mach-types.h>
+#include <asm/armv7.h>
 
 #ifndef CONFIG_SPL_DM
 /* Pointer to as well as the global data structure for SPL */
@@ -72,6 +73,13 @@ void __noreturn jump_to_image_linux(struct spl_image_info *spl_image)
 	image_entry_arg_t image_entry =
 		(image_entry_arg_t)(uintptr_t) spl_image->entry_point;
 	cleanup_before_linux();
+#if defined(CONFIG_BOOTM_OPTEE) && defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
+	if (spl_image->optee_addr)
+		boot_jump_linux_via_optee((void *)(spl_image->entry_point),
+					  machid,
+					  (u32)(spl_image->arg),
+					  spl_image->optee_addr);
+#endif
 	image_entry(0, machid, spl_image->arg);
 }
 #endif	/* CONFIG_ARM64 */
common/spl/spl_fit.c +20 -0
index 86506d6905c..294fb49b9e6 100644
@@ -544,6 +544,23 @@ static int spl_fit_image_is_fpga(const void *fit, int node)
 	return !strcmp(type, "fpga");
 }
 
+static void spl_fit_image_record_arm32_optee(const void *fit, int node,
+					     struct spl_image_info *spl_image,
+					     struct spl_image_info *image_info)
+{
+#if defined(CONFIG_BOOTM_OPTEE) && defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
+	const char *type = fdt_getprop(fit, node, FIT_TYPE_PROP, NULL);
+
+	if (!type)
+		return;
+
+	if (strcmp(type, "tee"))
+		return;
+
+	spl_image->optee_addr = image_info->load_addr;
+#endif
+}
+
 static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os)
 {
 	if (!CONFIG_IS_ENABLED(FIT_IMAGE_TINY) || CONFIG_IS_ENABLED(OS_BOOT))
@@ -859,6 +876,9 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 		    image_info.entry_point != FDT_ERROR)
 			spl_image->entry_point = image_info.entry_point;
 
+		spl_fit_image_record_arm32_optee(ctx.fit, node, spl_image,
+						 &image_info);
+
 		/* Record our loadables into the FDT */
 		if (!CONFIG_IS_ENABLED(FIT_IMAGE_TINY) &&
 		    xpl_get_fdt_update(info) && spl_image->fdt_addr)
include/spl.h +3 -0
index 850c64d4b19..a51dfa4f494 100644
@@ -288,6 +288,9 @@ struct spl_image_info {
 	ulong entry_point;
 #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
 	void *fdt_addr;
+#endif
+#if defined(CONFIG_BOOTM_OPTEE) && defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
+	ulong optee_addr;
 #endif
 	u32 boot_device;
 	u32 offset;
Signature · 1 line
2.47.2
#2 lore raw
In reply to Marek Vasut
Quoted 10 lines · Marek Vasut

Add support for jumping to Linux kernel through OpTee-OS on ARMv7a. This is only supported if U-Boot runs in PL1 secure. This change adds two components, one is fitImage OpTee-OS loadable handler, which makes a note of OpTee-OS being loaded and stores the load address for later jump to it. The second part is the actual jump to Linux through OpTee-OS. The jump through OpTee-OS requires set up of multiple CPU registers, r1 and r2 are passed through, r0 and r3 have to be set to 0, lr is set to Linux kernel entry point. This setup is done by new assembler function boot_jump_linux_via_optee().

Quoted 4 lines

The boot_jump_linux_via_optee() also includes STM32MP13xx late TZC configuration write, this cannot be moved easily, hence the ifdef.

The lack of a cover letter isn't the final problem, because I could summarize this easily enough. However, this causes a large number of targets to now have warnings, such as imx8mp-icore-mx8mp-edimm2.2 and gxp.

Signature · 1 line
Tom