From patchwork Thu Feb 12 00:14:00 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1832 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855295; bh=VhCQegqNA1sEeR28D7JWfqkRxCr3qXaNuKTPIL7S13s=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=fvW19x0blLrCLra16fXVmhHv/9xuYTsdmJozztpDMtdRelwC4Ml2znL6NTF4gGZI3 U9ce4aHYQ+yDjM5sOMbRYIfTC/Xn4E3jSQ1+4TsEJE+A88V19PefzKc7LCeEcBFrU4 TFtf6Te/2Rp4DU82mw7rThGqPptdsVY2VDBoQ39KFRu/5maA4ADl/UlR5BgQGuz8rB oWieyjLT2QmrHH0jJDRORUzxnJz0orMlqkjivbJXvGNcmMxhoURHivU12ZPsHaH62j rh/P4nz2b3K28j7voRjm2zZ2Pbf0U0fhJNlRt+s41SvCpCNoOu+LjqPQzKTm9haJic jCRcB6r2peGbg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4C4D1699C6 for ; Wed, 11 Feb 2026 17:14:55 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 9_fXNCejW3xz for ; Wed, 11 Feb 2026 17:14:55 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855295; bh=VhCQegqNA1sEeR28D7JWfqkRxCr3qXaNuKTPIL7S13s=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=fvW19x0blLrCLra16fXVmhHv/9xuYTsdmJozztpDMtdRelwC4Ml2znL6NTF4gGZI3 U9ce4aHYQ+yDjM5sOMbRYIfTC/Xn4E3jSQ1+4TsEJE+A88V19PefzKc7LCeEcBFrU4 TFtf6Te/2Rp4DU82mw7rThGqPptdsVY2VDBoQ39KFRu/5maA4ADl/UlR5BgQGuz8rB oWieyjLT2QmrHH0jJDRORUzxnJz0orMlqkjivbJXvGNcmMxhoURHivU12ZPsHaH62j rh/P4nz2b3K28j7voRjm2zZ2Pbf0U0fhJNlRt+s41SvCpCNoOu+LjqPQzKTm9haJic jCRcB6r2peGbg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3B03769A99 for ; Wed, 11 Feb 2026 17:14:55 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855293; bh=AubdEcWNZYfCzyWmQl/sFZdpXUHmUukP93MsW9DfyKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qYfOwv6s3GDQt9r4k04E5qvY8vNfbv3S3P/4yhcbfwgoQdECYR7w5VR2J2YkLZlfN 2FTNo5KlOE+RZOv4vW0+15eo+G9OFNpAHUzQWAXHoVph9j/LyNrRIJyuEjiHnhqVzD n5ZsGWs7zxHnin9inXAsWbZkAu7Tfs6ZLbvriRZvGSQrJbncuO9uOBmPB+68Re3qdJ 4HX05Do/2hvEJHtRKbd5ZpxFKLD/D/7Jmp0mxxtOtHn713+IlUe71xZTy9tE0tl1RW M0Zwe1qnn4mCSWGQEv07sKLbRc0OM+7/YESX7I98t2bcg7qM4tyZgwxHx9rK1Xjkk3 H2fS+o9CCD3LA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 87B6F69A99; Wed, 11 Feb 2026 17:14:53 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id 8X6CAma5KiDo; Wed, 11 Feb 2026 17:14:53 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855288; bh=GdBJ/EHBZUe36fDn7oWo0wOMkCGXf24pFSkZteykTMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JjHVFjmnRs/fwU5SR7VB0q7am5oc8A5wrW2om3uKpGbbxVd3a+LXvLrMCGzK6y49s 8jZfwPEVCsbS28+d6YyLUbH20tYIMmwASa0hZs6eUJYWeBTu4P8ONECbVF9lXO3LKh ss/kSZdgIejD82bPOzFj0k10+wCd/7TmSIPbhPCBH3FvHFV/eDfufWgUuGDkCLkYAI CGcP6C+dW4WmrZzYBl0FgEVaAMqhpjD+m4r8uQMiJFxm6EWKz2Tm9Pq3y+atbfa81A 4rbvLtFhopHZTBdSIw8aCmG5qh2wiwLcVOgg8hYIExi7qTcX9hxYyWY0CFwqtls7kU dSW1UYc1CQVyw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id CC3CB699C6; Wed, 11 Feb 2026 17:14:47 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 11 Feb 2026 17:14:00 -0700 Message-ID: <20260212001410.1919749-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260212001410.1919749-1-sjg@u-boot.org> References: <20260212001410.1919749-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: M3JWJNLHKOOKDA6MH6QWKGH7GTK2UN27 X-Message-ID-Hash: M3JWJNLHKOOKDA6MH6QWKGH7GTK2UN27 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 6" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 09/15] riscv: Add EFI app linker script and build CRT objects List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a linker script for building U-Boot as a RISC-V EFI application. This defines the PE/COFF .text and .data sections, the .reloc section for PE base relocations and the .embedded_dtb section (16-byte aligned) for the devicetree blob. Also add the EFI CRT0 and relocation objects to the build for EFI_APP so they are linked into the final binary. Co-developed-by: Claude Opus 4.6 Signed-off-by: Simon Glass --- arch/riscv/lib/Makefile | 2 + arch/riscv/lib/elf_riscv64_efi_app.lds | 136 +++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 arch/riscv/lib/elf_riscv64_efi_app.lds diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile index 36712cbb5c9..b0b1cabf903 100644 --- a/arch/riscv/lib/Makefile +++ b/arch/riscv/lib/Makefile @@ -38,6 +38,8 @@ CFLAGS_REMOVE_$(EFI_CRT0) := $(CFLAGS_NON_EFI) CFLAGS_$(EFI_RELOC) := $(CFLAGS_EFI) CFLAGS_REMOVE_$(EFI_RELOC) := $(CFLAGS_NON_EFI) +obj-$(CONFIG_EFI_APP) += $(EFI_CRT0) $(EFI_RELOC) + obj-$(CONFIG_$(PHASE_)USE_ARCH_MEMSET) += memset.o obj-$(CONFIG_$(PHASE_)USE_ARCH_MEMMOVE) += memmove.o obj-$(CONFIG_$(PHASE_)USE_ARCH_MEMCPY) += memcpy.o diff --git a/arch/riscv/lib/elf_riscv64_efi_app.lds b/arch/riscv/lib/elf_riscv64_efi_app.lds new file mode 100644 index 00000000000..6374433cdb3 --- /dev/null +++ b/arch/riscv/lib/elf_riscv64_efi_app.lds @@ -0,0 +1,136 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * U-Boot riscv64 EFI application linker script + * + * Modified from lib/efi_loader/elf_efi.ldsi and + * arch/arm/lib/elf_aarch64_efi.lds + */ + +OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv", "elf64-littleriscv") +OUTPUT_ARCH(riscv) +ENTRY(_start) +SECTIONS +{ + /* + * The .text section must come first at VMA 0 so that the PE/COFF + * header in .text.head is at the start of the binary. The CRT0 + * defines image_base at the very beginning of .text.head. + */ + .text 0x0 : { + _text = .; + *(.text.head) + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + *(.srodata) + *(.rodata*) + . = ALIGN(16); + *(.dynamic); + . = ALIGN(512); + } + . = ALIGN(4096); + _etext = .; + _text_size = . - _text; + + /* + * .hash and .gnu.hash are needed in the ELF for dynamic linking + * during the link step, but are not extracted into the PE binary. + */ + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .eh_frame : { *(.eh_frame) } + + . = ALIGN(65536); + .reloc : { + KEEP (*(.reloc)) + } + + /* + * Everything from _data to _edata makes up the PE .data section. + * The CRT0 PE header uses _edata for both VirtualSize and + * SizeOfRawData, so BSS must be included (as zero-filled file + * data) rather than in a separate section. + */ + . = ALIGN(4096); + _data = .; + + /* + * Dynamic relocations in .rela.dyn so the linker sets DT_RELA + * to point here. All relocation input sections are gathered + * into this single output section. + */ + .rela.dyn : { + *(.rela.dyn) + *(.rela.text*) + *(.rela.data*) + *(.rela.got) + *(.rela.stab) + *(.rela.init_array*) + *(.rela.fini_array*) + *(.rela.ctors*) + *(.rela.dtors*) + *(.rela__u_boot_list*) + } + + /* Dynamic symbol table and strings */ + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + + /* Embedded device tree (must be separate for embeddtb command) */ + . = ALIGN(16); + .embedded_dtb : { + *(.embedded_dtb) + } + + /* + * Regular data and BSS live together in one output section. + * Mixing PROGBITS (.data) and NOBITS (.bss) input sections in + * the same output section forces the linker to emit file content + * for the entire section, so BSS gets zero-filled in the file. + * This avoids a VMA gap that would bloat the PE binary. + */ + .data : { + *(.sdata) + *(.data) + *(.data1) + *(.data.*) + *(.got.plt) + *(.got) + + /* U-Boot lists */ + . = ALIGN(8); + KEEP(*(SORT(__u_boot_list*))); + . = ALIGN(8); + + /* BSS merged into data to get file content */ + . = ALIGN(16); + _bss = .; + *(.sbss) + *(.scommon) + *(.dynbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN(512); + _bss_end = .; + _edata = .; + _end = .; + } + _data_size = _edata - _data; + + /* + * PLT relocations are placed after _edata so they do not fall + * within the DT_RELA range. _relocate() only handles + * R_RISCV_RELATIVE and would panic on R_RISCV_JUMP_SLOT entries. + */ + .rela.plt : { *(.rela.plt) } + + . = ALIGN(4096); + .note.gnu.build-id : { *(.note.gnu.build-id) } + /DISCARD/ : { + *(.rel.reloc) + *(.eh_frame) + *(.note.GNU-stack) + } + .comment 0 : { *(.comment) } +}