[PATCH master 36/39] efi: payload: skip ELF MMU handling when booted via stub

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Feb 16 00:44:36 PST 2026


We should not touch the MMU when running as EFI app and must trust
that the EFI firmware has taken care of it.

This was so far realized by skipping MMU setup if MMU is already
enabled, but with the switch to ELF for barebox proper, the same check
can't be repeated in pbl_mmu_setup_from_elf(), so add an explicit check
that barebox wasn't invoked via the PE entry point.

Fixes: 6cb7fc2edbb6 ("ARM: PBL: setup MMU with proper permissions from ELF segments")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 efi/payload/entry-multi.c | 13 +++++++++++++
 include/efi/mode.h        |  6 +++++-
 pbl/mmu.c                 |  4 ++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/efi/payload/entry-multi.c b/efi/payload/entry-multi.c
index ef90ee077622..de977efc50b8 100644
--- a/efi/payload/entry-multi.c
+++ b/efi/payload/entry-multi.c
@@ -7,11 +7,23 @@
 #include <asm/common.h>
 #include <efi/protocol/text.h>
 #include <efi/payload.h>
+#include <efi/mode.h>
 #include <pbl.h>
 #include <pbl/handoff-data.h>
 
 asmlinkage void __efistub_efi_pe_entry(void *image, struct efi_system_table *sys_table);
 
+/*
+ * Put these in the data section so that they survive the clearing of the
+ * BSS segment.
+ */
+static __attribute__ ((section(".data"))) bool is_efi_payload;
+
+bool efi_is_payload(void)
+{
+	return is_efi_payload;
+}
+
 static void efi_putc(void *ctx, int ch)
 {
 	struct efi_system_table *sys_table = ctx;
@@ -30,6 +42,7 @@ void __efistub_efi_pe_entry(void *image, struct efi_system_table *sys_table)
 #endif
 	pbl_set_putc(efi_putc, sys_table);
 
+	is_efi_payload = true;
 	efidata.image = image;
 	efidata.sys_table = sys_table;
 
diff --git a/include/efi/mode.h b/include/efi/mode.h
index d63c47e88dbb..5093e9b2971f 100644
--- a/include/efi/mode.h
+++ b/include/efi/mode.h
@@ -18,10 +18,14 @@ enum efi_loader_state {
 	EFI_LOADER_RUNTIME,
 };
 
+#if IN_PBL && defined(CONFIG_EFI_STUB)
+bool efi_is_payload(void);
+#else
 static inline bool efi_is_payload(void)
 {
-	return IS_ENABLED(CONFIG_EFI_PAYLOAD) && BS;
+	return IS_ENABLED(CONFIG_EFI_PAYLOAD) && IN_PROPER && BS;
 }
+#endif
 
 #ifdef CONFIG_EFI_LOADER
 enum efi_loader_state efi_is_loader(void);
diff --git a/pbl/mmu.c b/pbl/mmu.c
index e7c9b8b1e8e4..897221c53f9b 100644
--- a/pbl/mmu.c
+++ b/pbl/mmu.c
@@ -10,6 +10,7 @@
 #include <asm/mmu.h>
 #include <linux/bits.h>
 #include <linux/sizes.h>
+#include <efi/mode.h>
 
 /*
  * Map ELF segment permissions (p_flags) to architecture MMU flags
@@ -45,6 +46,9 @@ int pbl_mmu_setup_from_elf(struct elf_image *elf, unsigned long membase,
 	void *phdr;
 	int i = -1;
 
+	if (efi_is_payload())
+		return 0;
+
 	pr_debug("Setting up MMU from ELF segments\n");
 
 	/*
-- 
2.47.3




More information about the barebox mailing list