From patchwork Mon Feb 16 01:34:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1885 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=1771205750; bh=mKR9+mxLSCKoiqHiUyaDmFQptHHSIgaYjjWhp/zFSMA=; 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=gxXmtypGWMIWHugxTUkAmgKecPDTfqi8hsf6VnOPxmI0YCCeKTbmFiWBMDZKOzWaa HLLnXuBLQZqYrXnF7SB24UGQhovSPTsS5bfSfC68qjhlT0Xr/ZW3vdN1I2gEMJ3+YA 1CMToEpuqzwL04h6cABNOVnsgRZuWnpyfkkKXSBgOSV4EBMlK99qiW7GoEFs2Rj+rJ h/69Mvzq7hq9Jj3/4ErIdc0/yIX7/MRFc24aWBswJCrrfdDJqRayUy5LluRfBnE4Tl irLbjfJdRgwSPGosabUwsMhVtCyHICv3kZYSXfLF6WTeYjfpFy3tNEmw3PRlhOdk8i aEM1Xakt1kVgw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 97A4B69BDB for ; Sun, 15 Feb 2026 18:35:50 -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 IdEy3GMxNpen for ; Sun, 15 Feb 2026 18:35:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771205750; bh=mKR9+mxLSCKoiqHiUyaDmFQptHHSIgaYjjWhp/zFSMA=; 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=gxXmtypGWMIWHugxTUkAmgKecPDTfqi8hsf6VnOPxmI0YCCeKTbmFiWBMDZKOzWaa HLLnXuBLQZqYrXnF7SB24UGQhovSPTsS5bfSfC68qjhlT0Xr/ZW3vdN1I2gEMJ3+YA 1CMToEpuqzwL04h6cABNOVnsgRZuWnpyfkkKXSBgOSV4EBMlK99qiW7GoEFs2Rj+rJ h/69Mvzq7hq9Jj3/4ErIdc0/yIX7/MRFc24aWBswJCrrfdDJqRayUy5LluRfBnE4Tl irLbjfJdRgwSPGosabUwsMhVtCyHICv3kZYSXfLF6WTeYjfpFy3tNEmw3PRlhOdk8i aEM1Xakt1kVgw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 84C4569BCC for ; Sun, 15 Feb 2026 18:35:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771205748; bh=xoWvyh1DIBCeEMkUlfZyt7n/db7yPwLoRpipZyI59c4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L9d2HpVCd/VkYjsmV7oRAMesuD5r0DARjGl3ZadCQwsJQDD4I7f2mbDgNQgoC+bYx fvpIdgCUQCIQ9LOhPValgE/vhRUfZ+IuxWefln1RqoH/L3dZuZHFIp4tpCKG5hCGcv mkapCo/gOtpxmpJ4gbH+rMzRRwK5o1bgY/xpvS2o7q0IpUqzWwWkBuqGPmI55xknM+ GO5VcypdSPxumEx8OT2itjODO6H+CqO56UJrwChXFyS0ZUDoFt/KQ3kmwtdx9VsMzm yx2hIS3bbjMhBV218NySQUpUREwBtJMoC5u3lyMw9rykBQsHs81Bp9JlI0qb51eBSF Ozhu1CRzY7nQw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7056969B01; Sun, 15 Feb 2026 18:35:48 -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 N0YaMKIa9rxf; Sun, 15 Feb 2026 18:35:48 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771205744; bh=YPMa/JxrK5Cw2ERILwlOmh7Jfi7JaLLBAaVdbntKNP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=De0xVWfzI+5tmm2e0mAhdiuK8rR00knLZAIJsAIQVM+4n2uf+6MmvlRs1FPT1LaSN LmFDcq6QOUk4yywpyWJ50HawdzI4rw1bRpIoOs48Hef/dRBSI33enxUr3WksIBjoSk graJxZraIrepTkE3eGb7drxCkZEDI53q2shhBhi+wXTSoXGLadBcMoS/U8wLdvJq/v 72QtbsD5TfViEk0x9/+jYFop/GvINjR9InpH3MUSpShmYnIp2zjlPVaW3/R9Qxw/xW HE/82dy1SxUSzIAgjO5MwkawTXYuMqQoyuBs7SdsBkgOxjTHsLfGDJZzfqxMuu80tu gPjfWF6wut/dA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 1B2AE69AD9; Sun, 15 Feb 2026 18:35:44 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 15 Feb 2026 18:34:53 -0700 Message-ID: <20260216013511.4079770-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260216013511.4079770-1-sjg@u-boot.org> References: <20260216013511.4079770-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: OMIZPYNZYWLC3NH6ILHSYOWW3KWCISDR X-Message-ID-Hash: OMIZPYNZYWLC3NH6ILHSYOWW3KWCISDR 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 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/17] ulib: Extract common example build rules for demo 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 The example build rules (link command, object lists, objcopy, and final-target logic) are duplicated in each arch Makefile. As more architectures gain ulib support, this duplication grows. Extract the common rules into scripts/Makefile.ulib-example, so that each arch's Makefile sets EXAMPLE_ARCH (and optionally EXAMPLE_APPEND_DTB or EXAMPLE_POST_LINK), then includes the shared file. Convert x86 to use it. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- arch/x86/Makefile | 31 ++------------------- scripts/Makefile.ulib-example | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 scripts/Makefile.ulib-example diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 7df20c43de1..661e75fbdaa 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -65,34 +65,7 @@ u-boot-x86-reset16.bin: u-boot-x86-16bit.elf FORCE $(call if_changed,objcopy) endif -# x86 example targets: re-link U-Boot with example objects providing main() -# -# The example .o files are compiled via kbuild (examples/ulib/Kbuild). -# This re-links u-boot with those objects so the example's strong main() -# overrides the weak one in board_r.c, using the shared u-boot-link helper. ifdef CONFIG_EXAMPLES -INPUTS-$(CONFIG_ULIB) += examples_x86 - -PHONY += examples_x86 - -X86_EXAMPLES := demo - -quiet_cmd_u-boot-example = LD $@ - cmd_u-boot-example = $(call u-boot-link,$(example-objs),$@.map) - -# Per-example object lists (matches examples/ulib/Makefile:demo_objs) -example-demo-objs := examples/ulib/demo.o examples/ulib/demo_helper.o - -# Link each example ELF (depends on u-boot to ensure archives exist) -examples/ulib/demo: $(example-demo-objs) u-boot FORCE - $(eval example-objs := $(example-demo-objs)) - $(call if_changed,u-boot-example) - -# Binary targets (same objcopy flags as u-boot-nodtb.bin) -OBJCOPYFLAGS_demo-nodtb.bin = $(OBJCOPYFLAGS_u-boot-nodtb.bin) -examples/ulib/demo-nodtb.bin: examples/ulib/demo FORCE - $(call if_changed,objcopy) - -examples_x86: $(foreach e,$(X86_EXAMPLES),examples/ulib/$(e)-nodtb.bin) FORCE - @: +EXAMPLE_ARCH := x86 +include scripts/Makefile.ulib-example endif diff --git a/scripts/Makefile.ulib-example b/scripts/Makefile.ulib-example new file mode 100644 index 00000000000..fd7c60e4483 --- /dev/null +++ b/scripts/Makefile.ulib-example @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Common build rules for ulib example programs. +# +# Re-links U-Boot with example objects providing main(). The example .o +# files are compiled via kbuild (examples/ulib/Kbuild). This re-links +# u-boot with those objects so the example's strong main() overrides the +# weak one in board_r.c, using the shared u-boot-link helper. +# +# Required variables (set by arch Makefile before including): +# EXAMPLE_ARCH - architecture name (x86, arm, riscv, ...) +# +# Optional variables: +# EXAMPLE_APPEND_DTB - set to y to append DTB to the binary +# EXAMPLE_POST_LINK - extra recipe line run after linking the ELF + +INPUTS-$(CONFIG_ULIB) += examples_$(EXAMPLE_ARCH) +PHONY += examples_$(EXAMPLE_ARCH) + +ULIB_EXAMPLES := demo + +quiet_cmd_u-boot-example = LD $@ + cmd_u-boot-example = $(call u-boot-link,$(example-objs),$@.map) + +# Per-example object lists (matches examples/ulib/Kbuild) +example-demo-objs := examples/ulib/demo.o examples/ulib/demo_helper.o + +# Link each example ELF (depends on u-boot to ensure archives exist) +examples/ulib/demo: $(example-demo-objs) u-boot FORCE + $(eval example-objs := $(example-demo-objs)) + $(call if_changed,u-boot-example) + $(EXAMPLE_POST_LINK) + +# Binary target (without DTB) +OBJCOPYFLAGS_demo-nodtb.bin = $(OBJCOPYFLAGS_u-boot-nodtb.bin) +examples/ulib/demo-nodtb.bin: examples/ulib/demo FORCE + $(call if_changed,objcopy) + +ifeq ($(EXAMPLE_APPEND_DTB),y) +# Binary with DTB appended +examples/ulib/demo.bin: examples/ulib/demo-nodtb.bin dts/dt.dtb FORCE + $(call if_changed,cat) + +examples_$(EXAMPLE_ARCH): \ + $(foreach e,$(ULIB_EXAMPLES),examples/ulib/$(e).bin) FORCE + @: +else +examples_$(EXAMPLE_ARCH): \ + $(foreach e,$(ULIB_EXAMPLES),examples/ulib/$(e)-nodtb.bin) FORCE + @: +endif