Skip to contentSkip to conversation

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

PATCH In review Marek Vasut 2 participants 3 messages Oct 30, 2025 – Nov 6, 2025 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v4 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]
---
V2: - Add ifdeffery around armv7_init_nonsec(), boot_jump_linux_via_optee(),
secure_ram_addr() due to external dependencies which may not be reachable
- Add ifdeffery around arch_tee_image_process() to avoid breaking OMAP2 IH_TYPE_TEE loading
V3: Add documentation
V4: s@OpTee-OS@OPTEE-OS@

---
 arch/arm/include/asm/armv7.h       |  2 +
 arch/arm/lib/Makefile              |  3 ++
 arch/arm/lib/bootm-optee.S         | 30 ++++++++++++
 arch/arm/lib/bootm.c               | 56 ++++++++++++++++++----
 doc/usage/fit/index.rst            |  1 +
 doc/usage/fit/kernel_fdt_optee.rst | 76 ++++++++++++++++++++++++++++++
 6 files changed, 159 insertions(+), 9 deletions(-)
 create mode 100644 arch/arm/lib/bootm-optee.S
 create mode 100644 doc/usage/fit/kernel_fdt_optee.rst
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 +47 -9

94 lines not on this page · raw message

doc/usage/fit/index.rst +1 -0
index a822bf20cb2..6c78d8584ed 100644
@@ -14,6 +14,7 @@ images that it reads and boots. Documentation about FIT is available in
     howto
     kernel_fdt
     kernel_fdts_compressed
+    kernel_fdt_optee
     kernel
     multi
     multi_spl
doc/usage/fit/kernel_fdt_optee.rst new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
2.51.0
#1 lore raw

PATCH v4 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]
---
V2: Include armv7.h only on non-ARM64
V3: No change
V4: s@OpTee-OS@OPTEE-OS@

---
 arch/arm/lib/spl.c   | 10 ++++++++++
 common/spl/spl_fit.c | 20 ++++++++++++++++++++
 include/spl.h        |  3 +++
 3 files changed, 33 insertions(+)
arch/arm/lib/spl.c +10 -0
index 6c7d1fb5629..bce51b9cc7d 100644
@@ -16,6 +16,9 @@
 #include <asm/global_data.h>
 #include <linux/compiler.h>
 #include <asm/mach-types.h>
+#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
+#include <asm/armv7.h>
+#endif
 
 #ifndef CONFIG_SPL_DM
 /* Pointer to as well as the global data structure for SPL */
@@ -71,6 +74,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 746c3d2fa28..616df46e1c8 100644
@@ -550,6 +550,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))
@@ -903,6 +920,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 cf45d411ecb..06dc28362d3 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.51.0
#2 lore raw
In reply to Marek Vasut
Quoted 11 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().

[...]

Applied to u-boot/master, thanks!

[1/2] ARM: bootm: Add support for starting Linux through OPTEE-OS on ARMv7a

      commit: 20861863eb3010581b12e9a77eb7958460edaa82
[2/2] spl: fit: Add ability to jump to Linux via OPTEE-OS on ARMv7a
      commit: be0e9ac7c8a141fbc52f658fbfdd96cf2c27d0de
Signature · 1 line
Tom