Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Fainelli via buildroot <buildroot@buildroot.org>
To: buildroot@buildroot.org
Cc: "Eric Le Bihan" <eric.le.bihan.dev@free.fr>,
	"Gary Bisson" <bisson.gary@gmail.com>,
	"Jérôme Pouiller" <jezz@sysmic.org>,
	"Florian Fainelli" <florian.fainelli@broadcom.com>,
	"Bernd Kuhls" <bernd@kuhls.net>,
	"Thomas Perale" <thomas.perale@mind.be>,
	"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
	"Refik Tuzakli" <tuzakli.refik@gmail.com>,
	"Francois Perrad" <francois.perrad.86@gmail.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Arnout Vandecappelle" <arnout@rnout.be>,
	"Petr Vorel" <petr.vorel@gmail.com>,
	"Spenser Gilliland" <spenser@gillilanding.com>,
	"Giulio Benetti" <giulio.benetti@benettiengineering.com>,
	"Pascal de Bruijn" <p.debruijn@unilogic.nl>,
	"Luca Ceresoli" <luca.ceresoli@bootlin.com>,
	"Romain Naour" <romain.naour@gmail.com>,
	"Mahyar Koshkouei" <mahyar.koshkouei@gmail.com>
Subject: [Buildroot] [PATCH v2 20/23] linux: support custom logo and devicetree files in out-of-tree builds
Date: Wed, 28 Oct 2026 14:37:41 -0700	[thread overview]
Message-ID: <20261028213744.511429-21-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261028213744.511429-1-florian.fainelli@broadcom.com>

A custom logo and custom devicetree files are added to the kernel
sources, which must not be done in a source directory we do not own.

When either is configured for an out-of-tree build, build from a shadow
of the source directory instead: a tree of real directories containing
symlinks to the files (support/scripts/symlink-tree), where files can
be replaced or added without touching the original. Packages opt in by
setting <pkg>_OUT_OF_TREE_SRCDIR.

Custom files are copied with --remove-destination so that a symlink is
replaced rather than written through.

Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
 linux/linux.mk               | 34 ++++++++++++++++-----
 package/pkg-generic.mk       |  5 +++-
 support/scripts/symlink-tree | 58 ++++++++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+), 8 deletions(-)
 create mode 100755 support/scripts/symlink-tree

diff --git a/linux/linux.mk b/linux/linux.mk
index 5734d78aa9a2..37d143742435 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -227,7 +227,7 @@ LINUX_DTSO_NAMES += $(basename $(LINUX_DTSO_LIST))
 define LINUX_COPY_CUSTOM_DTS_FILES
 	$(foreach d, $(LINUX_KERNEL_CUSTOM_DTS_DIR), \
 		@$(call MESSAGE,"Copying devicetree overlay $(d)")$(sep) \
-		$(Q)$(call SYSTEM_RSYNC,$(d),$(LINUX_ARCH_PATH)/boot/dts/)$(sep))
+		$(Q)$(call SYSTEM_RSYNC,$(d),$(LINUX_SRC_ARCH_PATH)/boot/dts/)$(sep))
 endef
 endif
 
@@ -291,14 +291,18 @@ endif
 # for bzImage, arch/i386 and arch/x86_64 do not exist when copying the
 # defconfig file.
 ifeq ($(KERNEL_ARCH),i386)
-LINUX_ARCH_PATH = $(LINUX_DIR)/arch/x86
+LINUX_ARCH_SUBDIR = arch/x86
 else ifeq ($(KERNEL_ARCH),x86_64)
-LINUX_ARCH_PATH = $(LINUX_DIR)/arch/x86
+LINUX_ARCH_SUBDIR = arch/x86
 else ifeq ($(KERNEL_ARCH),sparc64)
-LINUX_ARCH_PATH = $(LINUX_DIR)/arch/sparc
+LINUX_ARCH_SUBDIR = arch/sparc
 else
-LINUX_ARCH_PATH = $(LINUX_DIR)/arch/$(KERNEL_ARCH)
+LINUX_ARCH_SUBDIR = arch/$(KERNEL_ARCH)
 endif
+# Build products (images, dtbs) are in the build directory, but the sources
+# of the kernel, to which custom files are added, may be elsewhere.
+LINUX_ARCH_PATH = $(LINUX_DIR)/$(LINUX_ARCH_SUBDIR)
+LINUX_SRC_ARCH_PATH = $(LINUX_SRCDIR)/$(LINUX_ARCH_SUBDIR)
 
 ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
 LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
@@ -356,13 +360,29 @@ LINUX_KERNEL_CUSTOM_LOGO_PATH = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_LOGO_PAT
 ifneq ($(LINUX_KERNEL_CUSTOM_LOGO_PATH),)
 LINUX_DEPENDENCIES += host-imagemagick
 define LINUX_KERNEL_CUSTOM_LOGO_CONVERT
+	rm -f $(LINUX_SRCDIR)/drivers/video/logo/logo_linux_clut224.ppm
 	$(HOST_DIR)/bin/convert $(LINUX_KERNEL_CUSTOM_LOGO_PATH) \
 		-dither None -colors 224 -compress none \
-		$(LINUX_DIR)/drivers/video/logo/logo_linux_clut224.ppm
+		$(LINUX_SRCDIR)/drivers/video/logo/logo_linux_clut224.ppm
 endef
 LINUX_PRE_BUILD_HOOKS += LINUX_KERNEL_CUSTOM_LOGO_CONVERT
 endif
 
+# A custom logo or custom devicetree files are added to the kernel sources,
+# which we must not do in a source directory we do not own. In an out-of-tree
+# build, use a shadow of that directory instead: a tree of real directories
+# containing symlinks to the files, so that those can be replaced or added.
+ifneq ($(LINUX_OVERRIDE_SRCDIR),)
+ifneq ($(LINUX_KERNEL_CUSTOM_LOGO_PATH)$(LINUX_KERNEL_CUSTOM_DTS_DIR)$(LINUX_CUSTOM_DTS_PATH),)
+LINUX_OUT_OF_TREE_SRCDIR = $(BUILD_DIR)/linux-custom-src
+define LINUX_SHADOW_SRCDIR
+	@$(call MESSAGE,"Shadowing $(LINUX_OVERRIDE_SRCDIR) for custom files")
+	support/scripts/symlink-tree -F -l .git $(call qstrip,$(LINUX_OVERRIDE_SRCDIR)) $(LINUX_OUT_OF_TREE_SRCDIR)
+endef
+LINUX_PRE_RSYNC_HOOKS += LINUX_SHADOW_SRCDIR
+endif
+endif
+
 ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y)
 LINUX_KCONFIG_DEFCONFIG = $(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG))_defconfig
 else ifeq ($(BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG),y)
@@ -561,7 +581,7 @@ endif
 define LINUX_BUILD_CMDS
 	$(call KCONFIG_DISABLE_OPT,CONFIG_GCC_PLUGINS)
 	$(foreach dts,$(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)), \
-		cp -f $(dts) $(LINUX_ARCH_PATH)/boot/dts/
+		cp -f --remove-destination $(dts) $(LINUX_SRC_ARCH_PATH)/boot/dts/
 	)
 	$(LINUX_COPY_CUSTOM_DTS_FILES)
 	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) all
diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index b9808bb624f7..14378deacd35 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -581,7 +581,10 @@ ifeq ($$($(3)_SUPPORTS_OUT_OF_TREE),YES)
 $(2)_OUT_OF_TREE = YES
 $(2)_SRCDIR = $$(SRC_DIR)/$$($(2)_BASENAME)
 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
-$(2)_SRCDIR = $$(abspath $$(call qstrip,$$($(2)_OVERRIDE_SRCDIR)))
+# A package may need to add files to its sources, which must not be done in
+# the overridden directory: it can then set <pkg>_OUT_OF_TREE_SRCDIR to
+# a shadow of the sources (see support/scripts/symlink-tree).
+$(2)_SRCDIR = $$(or $$($(3)_OUT_OF_TREE_SRCDIR),$$(abspath $$(call qstrip,$$($(2)_OVERRIDE_SRCDIR))))
 $(2)_STAMP_SRCDIR = $$($(2)_BUILDDIR)
 endif
 endif
diff --git a/support/scripts/symlink-tree b/support/scripts/symlink-tree
new file mode 100755
index 000000000000..6c51022dddad
--- /dev/null
+++ b/support/scripts/symlink-tree
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+
+# Create a "shadow" of a source tree: a tree of real directories whose
+# files are symlinks to the files of the original tree. Files can then be
+# added to, or replaced in, the shadow, and objects can be built inside it,
+# without ever modifying the original tree.
+#
+# Usage: symlink-tree [-F] [-f NAME]... [-l NAME]... SRC DST
+#
+#   -F       shadow every top-level entry of SRC (default: a single symlink
+#            for each top-level entry)
+#   -f NAME  shadow the top-level directory NAME
+#   -l NAME  only symlink the top-level entry NAME, even with -F
+#
+# DST is wiped and re-created.
+
+set -e
+
+all=false
+farm=" "
+link=" "
+while getopts "Ff:l:" opt; do
+    case "${opt}" in
+    F) all=true ;;
+    f) farm="${farm}${OPTARG} " ;;
+    l) link="${link}${OPTARG} " ;;
+    *) exit 1 ;;
+    esac
+done
+shift $((OPTIND - 1))
+[ $# -eq 2 ] || { echo "usage: ${0##*/} [-F] [-f NAME]... [-l NAME]... SRC DST" >&2; exit 1; }
+
+src="$(readlink -f "${1}")"
+dst="${2}"
+
+# Refuse to wipe anything that does not look like a previous shadow, or
+# that could be (part of) the source tree.
+dst_abs="$(readlink -m "${dst}")"
+case "${src}/" in
+"${dst_abs}"/*) echo "${0##*/}: ${dst} contains the source tree" >&2; exit 1 ;;
+esac
+case "${dst_abs}/" in
+"${src}"/*) echo "${0##*/}: ${dst} is inside the source tree" >&2; exit 1 ;;
+esac
+
+rm -rf "${dst}"
+mkdir -p "${dst}"
+
+for path in "${src}"/* "${src}"/.[!.]* "${src}"/..?*; do
+    [ -e "${path}" ] || [ -L "${path}" ] || continue
+    name="${path##*/}"
+    if [ -d "${path}" ] && [ ! -L "${path}" ] && [[ "${link}" != *" ${name} "* ]] &&
+       { ${all} || [[ "${farm}" == *" ${name} "* ]]; }; then
+        cp -rs "${path}" "${dst}/"
+    else
+        ln -s "${path}" "${dst}/${name}"
+    fi
+done
-- 
2.34.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  parent reply	other threads:[~2026-10-28 21:41 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 21:37 [Buildroot] [PATCH v2 00/23] Support building the Linux kernel out of tree Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 01/23] package: prepare removal of <pkg>_DIR Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 02/23] infra: introduce a global SRC_DIR variable Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 03/23] package: fix <pkg>_SRCDIR and <pkg>_BUILDDIR values Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 04/23] boot/boot-wrapper-aarch64: needs LINUX_BUILDDIR Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 05/23] boot/mxs-bootlets: needs (BAREBOX, LINUX, UBOOT)_BUILDDIR Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 06/23] linux/extensions: point to proper _SRCDIR and @D Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 07/23] linux/linux: LINUX_VERSION_PROBED should run from build directory Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 08/23] package: use <pkg>_SRCSUBDIR where <pkg>_SRCDIR used to include _SUBDIR Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 09/23] linux: build out of tree Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 10/23] packages: sync host and target patch hooks Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 11/23] omniorb: avoid target-only patch hook Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 12/23] lua: rework post-patch hook usage Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 13/23] infra: host packages inherit the target extra downloads Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 14/23] package/libtool: use post-patch hooks Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 15/23] package/libtool: also apply libtool-patch to host libtool Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 16/23] package/{ffmpeg, libvpx}: use $(@D) instead of $(pkg_SRCDIR) when possible Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 17/23] package/perl: apply the perl-cross even for the host variant Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 18/23] infra/autotools: warn for package that autoreconf without libtool patch Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 19/23] packages: replace $(PKG)_DIR with @D where possible Florian Fainelli via buildroot
2026-10-28 21:37 ` Florian Fainelli via buildroot [this message]
2026-10-28 21:37 ` [Buildroot] [PATCH v2 21/23] package/linux-tools: support an out-of-tree kernel build Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 22/23] package: read kernel headers from LINUX_SRCDIR Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 23/23] docs/manual: document out-of-tree package builds and the new srcdir variables Florian Fainelli via buildroot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261028213744.511429-21-florian.fainelli@broadcom.com \
    --to=buildroot@buildroot.org \
    --cc=arnout@rnout.be \
    --cc=bernd@kuhls.net \
    --cc=bisson.gary@gmail.com \
    --cc=eric.le.bihan.dev@free.fr \
    --cc=florian.fainelli@broadcom.com \
    --cc=francois.perrad.86@gmail.com \
    --cc=giulio.benetti@benettiengineering.com \
    --cc=jezz@sysmic.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=mahyar.koshkouei@gmail.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=p.debruijn@unilogic.nl \
    --cc=petr.vorel@gmail.com \
    --cc=romain.naour@gmail.com \
    --cc=spenser@gillilanding.com \
    --cc=thomas.perale@mind.be \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=tuzakli.refik@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox