From patchwork Wed Feb 11 14:32:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1818 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=1770820470; bh=JYj4zxo/GLMDL+cBRcFlTID+pavTFRMLsdw/W6Htu48=; 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=e/YHKEBeDE0WKSiwBNJgha70zE7erIxu8pVXrQ+dWG6RiKuAIu5E7e21LIw/+olJs y42kuU4gzaTvSu9C1da8Uoo+Zw8fZWLNCldR2DLBgc3LLOYUTAes1/nzVdCLJE56x7 mWgrapz6fyO3sr9HF7yGMOLZOMyQCDCfFBkiCTZsqe3ajsVs5AG9LG6s4g3lgZWBxa 8OCdznDlnqVTPvYVXL5NuAI3R9QmZtvD8om5VvCTr6VBcBCfSHSRxwh0z2xLOJa8Dh bq/j+iRIkIg78Vhr88mhD2dqyynqjYIG+JlzrshJxNRdTXgUg+8UyHy5GSh8S7ncZH POb2V1uTiHgXg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5400C69A8F for ; Wed, 11 Feb 2026 07:34:30 -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 l8mp4Yz1SrJr for ; Wed, 11 Feb 2026 07:34:30 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820470; bh=JYj4zxo/GLMDL+cBRcFlTID+pavTFRMLsdw/W6Htu48=; 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=e/YHKEBeDE0WKSiwBNJgha70zE7erIxu8pVXrQ+dWG6RiKuAIu5E7e21LIw/+olJs y42kuU4gzaTvSu9C1da8Uoo+Zw8fZWLNCldR2DLBgc3LLOYUTAes1/nzVdCLJE56x7 mWgrapz6fyO3sr9HF7yGMOLZOMyQCDCfFBkiCTZsqe3ajsVs5AG9LG6s4g3lgZWBxa 8OCdznDlnqVTPvYVXL5NuAI3R9QmZtvD8om5VvCTr6VBcBCfSHSRxwh0z2xLOJa8Dh bq/j+iRIkIg78Vhr88mhD2dqyynqjYIG+JlzrshJxNRdTXgUg+8UyHy5GSh8S7ncZH POb2V1uTiHgXg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4244569A89 for ; Wed, 11 Feb 2026 07:34:30 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820468; bh=V9GQTIO7lOGRAIZwMXxU4nY4QC7NlK129sYUjGT9UVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O80rD5X0nG05NCJqQbSaEw+R5uS0ImZeC6JEB9/gNgk4TIjwSX+6/3YlDyHH7WFat t+ofIZGrPk+yT0Ebenwzx5ZLEUoEO/x1RnmYlCIi5YFJZtnv8uFUX3kj3DIeEe+GSf 0O7UiLSWjfv4gpth+aNUuKvnQ36mrJZFnuVv539lDOzRkiQYKbcAQlLrwh9YCJJZVu d6COEn7IE34JcUnhBMjCC0iMpiQfn4b9sclm7wGSna/b1Y4eyPi7Iq7UF2oRoR7vVS VpMl2JS+sJoXTlLEa1W0c3ImJsWBCm1rBt6P4kuJDHWoylk8UOWgHolmIccgSJY6h/ UtyvNt0kjJJNg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8FC4C699BF; Wed, 11 Feb 2026 07:34:28 -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 QcmsndAeaOeB; Wed, 11 Feb 2026 07:34:28 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820464; bh=MtQkqF9Oa4mhiIsEWMPu4Q8Map0aE7lsL/ekN+yOCgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r81B3ZEK1l1rUuN3UUMCnoV0AwHwiqHmuDDzuamDVj7oqSEofePQpfCP9ixG0FHdI Nl9SRAtjgX05Vt3sVFjJ4oK/qFXWAv5nm5+p8iA1/Mr1FrXcYXcNFEHgUvAtGRN7qC 0lnqmblocT7cTjiqJNlGKqEjNY36F7rz6+HZfFpYtj9N4f5K+ZuSXZ4+lT2aFBMbgG zD7wK5/udIxmeHkLfDMoln4pzUouNEtkWVwrXkNcuvc7ZcOqXJfLWcBQeaG64+PUH2 L9YAKqv+yFnoh6z300CEOzfLi/3COXoxHkhzjkbosf/RNgE+BbTPJUY0OK5FZxJ9Dp A9MExDf9xNrFA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 1E113699D6; Wed, 11 Feb 2026 07:34:24 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 11 Feb 2026 07:32:55 -0700 Message-ID: <20260211143309.1183113-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260211143309.1183113-1-sjg@u-boot.org> References: <20260211143309.1183113-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: NWPZV63EX77XOQCOKTSQW7QHW7PBAY2K X-Message-ID-Hash: NWPZV63EX77XOQCOKTSQW7QHW7PBAY2K 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: Simon Glass , "Claude Opus 4 . 6" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/12] x86: Link 16-bit startup into separate 32-bit ELF 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 On x86_64 with 16-bit init, start16.o and resetvec.o are built as 32-bit objects and cannot be linked into the 64-bit PIE binary. Add a linker script (u-boot-16bit.lds) and Makefile rules to link them into a small 32-bit ELF (u-boot-x86-16bit.elf) with the correct section addresses. The existing objcopy rules then extract the .start16 and .resetvec sections from this ELF instead of from the main u-boot binary. Co-developed-by: Claude Opus 4.6 Signed-off-by: Simon Glass --- arch/x86/Makefile | 27 ++++++++++++++++++++++++++- arch/x86/cpu/u-boot-16bit.lds | 30 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 arch/x86/cpu/u-boot-16bit.lds diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 8abedd6e5e9..955a728e361 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -29,9 +29,34 @@ libs-y += arch/x86/cpu/ libs-y += arch/x86/lib/ OBJCOPYFLAGS_u-boot-x86-start16.bin := -O binary -j .start16 +OBJCOPYFLAGS_u-boot-x86-reset16.bin := -O binary -j .resetvec + +ifneq ($(CONFIG_X86_64)$(CONFIG_X86_16BIT_INIT),yy) +# Normal case: extract 16-bit sections from the u-boot ELF u-boot-x86-start16.bin: u-boot FORCE $(call if_changed,objcopy) -OBJCOPYFLAGS_u-boot-x86-reset16.bin := -O binary -j .resetvec u-boot-x86-reset16.bin: u-boot FORCE $(call if_changed,objcopy) +else +# 64-bit with 16-bit init: the 16-bit objects are built as 32-bit and +# not linked into the 64-bit u-boot. Link them into a small 32-bit +# ELF with the correct addresses so that cross-references (e.g., +# resetvec -> start16 -> _start) are resolved. +u-boot-x86-16bit.lds: $(srctree)/arch/x86/cpu/u-boot-16bit.lds prepare FORCE + $(call if_changed_dep,cpp_lds) + +LDFLAGS_u-boot-x86-16bit.elf := -m elf_i386 -static -nostdlib \ + --defsym=_start=$(CONFIG_TEXT_BASE) + +u-boot-x86-16bit.elf: arch/x86/cpu/start16.o arch/x86/cpu/resetvec.o \ + u-boot-x86-16bit.lds FORCE + $(LD) $(LDFLAGS_u-boot-x86-16bit.elf) -T u-boot-x86-16bit.lds \ + arch/x86/cpu/start16.o arch/x86/cpu/resetvec.o -o $@ + +u-boot-x86-start16.bin: u-boot-x86-16bit.elf FORCE + $(call if_changed,objcopy) + +u-boot-x86-reset16.bin: u-boot-x86-16bit.elf FORCE + $(call if_changed,objcopy) +endif diff --git a/arch/x86/cpu/u-boot-16bit.lds b/arch/x86/cpu/u-boot-16bit.lds new file mode 100644 index 00000000000..048d0f17b4f --- /dev/null +++ b/arch/x86/cpu/u-boot-16bit.lds @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Linker script for 16-bit x86 startup code (start16 + resetvec). + * + * Written by Simon Glass + * + * Used when building a 64-bit U-Boot with integrated 16-bit init. + * The 16-bit objects are built as 32-bit and linked separately so that + * the 64-bit PIE binary does not see 16-bit relocations. + */ + +#include + +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH(i386) + +SECTIONS +{ + . = START_16 - RESET_SEG_START; + .start16 : AT (START_16) { + KEEP(*(.start16)); + } + + . = RESET_VEC_LOC - RESET_SEG_START; + .resetvec : AT (RESET_VEC_LOC) { + KEEP(*(.resetvec)); + } + + /DISCARD/ : { *(.note.gnu.property) } +}