Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rustam Abdullaev <rustamabd@gmail.com>
To: buildroot@buildroot.org
Cc: Andreas Ziegler <br025@umbiko.net>,
	Giulio Benetti <giulio.benetti@benettiengineering.com>,
	Romain Naour <romain.naour@gmail.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Rustam Abdullaev <rustamabd@gmail.com>
Subject: [Buildroot] [PATCH v2 1/1] toolchain/toolchain-external: introduce BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS
Date: Sat, 27 Dec 2025 21:14:15 +0000	[thread overview]
Message-ID: <20251227211415.2269024-1-rustamabd@gmail.com> (raw)

This change makes it possible to update kernel headers in the external
toolchain with the headers from the current kernel.

It is important to have matching kernel headers when building packages
that make use of kernel features such as seccomp, as they depend on
system call definitions in linux/unistd.h. A typical example of this is
openssh - building it with the official ARM GNU toolchain and kernel 6.x
results in a non-working sshd.

Currently restricted to glibc-based toolchains as glibc is backward- and
forward-compatible with different kernel versions while uClibc and musl
are not.

Signed-off-by: Rustam Abdullaev <rustamabd@gmail.com>
---
Changes v1 -> v2:
	- Restrict the option to glibc-based toolchains.
	- Improve commit message.
	- Restore the check-kernel-headers call in linux-headers.mk.
	- Install the headers into the toolchain explicitly instead of copying
	  over all staging headers.
	- Remove the loose version check option as it doesn't seem necessary.
---
 package/linux-headers/Config.in               |  2 ++
 package/linux-headers/linux-headers.mk        |  3 ++-
 toolchain/Config.in                           |  4 ++++
 toolchain/helpers.mk                          |  4 +---
 toolchain/toolchain-buildroot/Config.in       |  2 --
 toolchain/toolchain-external/Config.in        | 12 ++++++++++++
 .../pkg-toolchain-external.mk                 | 19 ++++++++++++++++++-
 7 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/package/linux-headers/Config.in b/package/linux-headers/Config.in
index 0ea95164d6..ff04529325 100644
--- a/package/linux-headers/Config.in
+++ b/package/linux-headers/Config.in
@@ -1,2 +1,4 @@
 config BR2_PACKAGE_LINUX_HEADERS
 	bool
+	# Can be selected by internal toolchains or external toolchains needing updated headers
+	default y if BR2_TOOLCHAIN_BUILDROOT
diff --git a/package/linux-headers/linux-headers.mk b/package/linux-headers/linux-headers.mk
index b4b5a5b47d..10ad7c4630 100644
--- a/package/linux-headers/linux-headers.mk
+++ b/package/linux-headers/linux-headers.mk
@@ -5,7 +5,8 @@
 ################################################################################
 
 # This package is used to provide Linux kernel headers for the
-# internal toolchain backend.
+# internal toolchain backend and for external toolchains that need
+# updated kernel headers.
 
 # Set variables depending on whether we are using headers from a kernel
 # build or a standalone header package.
diff --git a/toolchain/Config.in b/toolchain/Config.in
index 99337a1873..35d1245061 100644
--- a/toolchain/Config.in
+++ b/toolchain/Config.in
@@ -68,6 +68,10 @@ source "toolchain/toolchain-external/Config.in"
 # so put it here instead
 source "package/gdb/Config.in.host"
 
+# Linux headers can be used by both internal and external toolchains
+source "package/linux-headers/Config.in.host"
+source "package/linux-headers/Config.in"
+
 comment "Toolchain Generic Options"
 
 # https://sourceware.org/bugzilla/show_bug.cgi?id=30730
diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
index 21c710d0fb..1802d57421 100644
--- a/toolchain/helpers.mk
+++ b/toolchain/helpers.mk
@@ -169,11 +169,9 @@ copy_toolchain_sysroot = \
 # $2: sysroot directory
 # $3: kernel version string, in the form: X.Y
 # $4: test to do for the latest kernel version, 'strict' or 'loose'
-#     always 'strict' if this is not the latest version.
 #
 check_kernel_headers_version = \
-	if ! support/scripts/check-kernel-headers.sh $(1) $(2) $(3) \
-		$(if $(BR2_TOOLCHAIN_HEADERS_LATEST),$(4),strict); \
+	if ! support/scripts/check-kernel-headers.sh $(1) $(2) $(3) $(4) ; \
 	then \
 		exit 1; \
 	fi
diff --git a/toolchain/toolchain-buildroot/Config.in b/toolchain/toolchain-buildroot/Config.in
index 0bccdc817c..592d88c68e 100644
--- a/toolchain/toolchain-buildroot/Config.in
+++ b/toolchain/toolchain-buildroot/Config.in
@@ -108,8 +108,6 @@ config BR2_TOOLCHAIN_BUILDROOT_LIBC
 	default "glibc"  if BR2_TOOLCHAIN_BUILDROOT_GLIBC
 	default "musl"	 if BR2_TOOLCHAIN_BUILDROOT_MUSL
 
-source "package/linux-headers/Config.in.host"
-source "package/linux-headers/Config.in"
 source "package/musl/Config.in"
 source "package/uclibc/Config.in"
 source "package/glibc/Config.in"
diff --git a/toolchain/toolchain-external/Config.in b/toolchain/toolchain-external/Config.in
index 831387bc4e..7ea71b5625 100644
--- a/toolchain/toolchain-external/Config.in
+++ b/toolchain/toolchain-external/Config.in
@@ -125,4 +125,16 @@ config BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY
 	  Copy the gdbserver provided by the external toolchain to the
 	  target.
 
+config BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS
+	bool "Update kernel headers"
+	# Restrict this option to glibc, as uClibc and musl should probably
+	# be rebuilt when updating kernel headers.
+	depends on BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_PACKAGE_LINUX_HEADERS
+	help
+	  Select this option to update the kernel headers in the
+	  external toolchain with headers from the kernel being built.
+	  This is useful when the external toolchain has older kernel
+	  headers than the kernel being built.
+
 endif # BR2_TOOLCHAIN_EXTERNAL
diff --git a/toolchain/toolchain-external/pkg-toolchain-external.mk b/toolchain/toolchain-external/pkg-toolchain-external.mk
index 270cf814ed..80d8b0f017 100644
--- a/toolchain/toolchain-external/pkg-toolchain-external.mk
+++ b/toolchain/toolchain-external/pkg-toolchain-external.mk
@@ -542,6 +542,18 @@ define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LDD
 	fi
 endef
 
+define TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS
+	echo "Updating kernel headers in the external toolchain..." ; \
+	SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
+	(cd $(LINUX_HEADERS_DIR); $(TARGET_MAKE_ENV) $(BR2_MAKE) \
+		ARCH=$(KERNEL_ARCH) \
+		HOSTCC="$(HOSTCC)" \
+		HOSTCFLAGS="$(HOSTCFLAGS)" \
+		HOSTCXX="$(HOSTCXX)" \
+		INSTALL_HDR_PATH=$${SYSROOT_DIR}/usr \
+		headers_install)
+endef
+
 ################################################################################
 # inner-toolchain-external-package -- defines the generic installation rules
 # for external toolchain packages
@@ -573,6 +585,11 @@ $(2)_POST_EXTRACT_HOOKS += \
 	TOOLCHAIN_EXTERNAL_MOVE
 endif
 
+ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS),y)
+$(2)_DEPENDENCIES += linux-headers
+$(2)_PRE_CONFIGURE_HOOKS += TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS
+endif
+
 # Checks for an already installed toolchain: check the toolchain
 # location, check that it is usable, and then verify that it
 # matches the configuration provided in Buildroot: ABI, C++ support,
@@ -585,7 +602,7 @@ define $(2)_CONFIGURE_CMDS
 		$$(BUILD_DIR),\
 		$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC)),\
 		$$(call qstrip,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST)),\
-		$$(if $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),loose,strict)); \
+		$$(if $$(or $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),$$(BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS)),loose,strict)); \
 	$$(call check_gcc_version,$$(TOOLCHAIN_EXTERNAL_CC),\
 		$$(call qstrip,$$(BR2_TOOLCHAIN_GCC_AT_LEAST))); \
 	if test "$$(BR2_arm)" = "y" ; then \
-- 
2.39.5

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

             reply	other threads:[~2025-12-27 21:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-27 21:14 Rustam Abdullaev [this message]
2025-12-27 22:24 ` [Buildroot] [PATCH v2 1/1] toolchain/toolchain-external: introduce BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS Thomas Petazzoni via buildroot
2025-12-28 16:10   ` Rustam
2026-03-14  7:27     ` Andreas Ziegler
2026-02-02 13:41   ` John Ernberg via buildroot
2026-03-13 23:03     ` Romain Naour 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=20251227211415.2269024-1-rustamabd@gmail.com \
    --to=rustamabd@gmail.com \
    --cc=br025@umbiko.net \
    --cc=buildroot@buildroot.org \
    --cc=giulio.benetti@benettiengineering.com \
    --cc=romain.naour@gmail.com \
    --cc=thomas.petazzoni@bootlin.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