[Concept,02/15] board_r: Skip set_gd() for RISC-V EFI applications

Message ID 20260212001410.1919749-3-sjg@u-boot.org
State New
Headers
Series riscv: Add EFI-application support |

Commit Message

Simon Glass Feb. 12, 2026, 12:13 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

board_init_r() unconditionally calls set_gd(new_gd) for RISC-V, but
the EFI application entry point passes NULL as the new_gd parameter.
This zeroes the gp register (which holds the global data pointer),
causing an immediate page fault when gd is next accessed.

For EFI apps the global data pointer is already set correctly by
efi_app.c before calling board_init_r(), so skip the set_gd() call.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 common/board_r.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/common/board_r.c b/common/board_r.c
index c0f1ea9f003..18258b4fa0a 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -793,7 +793,8 @@  void board_init_r(gd_t *new_gd, ulong dest_addr)
 		arch_setup_gd(new_gd);
 
 #if defined(CONFIG_RISCV)
-	set_gd(new_gd);
+	if (!IS_ENABLED(CONFIG_EFI_APP))
+		set_gd(new_gd);
 #elif !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
 	gd = new_gd;
 #endif