From: Stefan Koch <stefan-koch@siemens.com>
To: isar-users@googlegroups.com
Cc: stefan-koch@siemens.com, jan.kiszka@siemens.com,
christian.storm@siemens.com, michael.adler@siemens.com,
simon.sudler@siemens.com, cedric.hombourger@siemens.com,
adriaan.schmidt@siemens.com, felix.moessbauer@siemens.com,
ubely@ilbers.de
Subject: [PATCH v6 3/5] linux-custom: Provide target and host specific kernel kbuild packages
Date: Wed, 14 Feb 2024 11:10:23 +0100 [thread overview]
Message-ID: <20240214101025.2123540-4-stefan-koch@siemens.com> (raw)
In-Reply-To: <20240214101025.2123540-1-stefan-koch@siemens.com>
When using a cross build this patch does introduce
target and host specific kernel kbuild packages that
ship the "scripts" and "tools" binaries.
The "-kbuildtarget" and "-native" multiarch bitbake targets are useable to run
additional target or host specific builds for kbuild scripts and tools.
Using the "-kbuildtarget" bitbake target enables the build of
a target specific kbuild package at cross builds.
So using "linux-kbuild" provides the package for the target platform.
Using the "-native" bitbake target enables the build of
a host specific kbuild package at cross builds.
When cross building using "linux-kbuild-native"
provides the package for the host platform.
Only the "host" specific package is built automatically at cross builds.
This solves this from doc/custom_kernel.inc:
- The kernel headers package has not supported both native
and cross compilation of kernel modules when itself was cross built
- Future roadmap: Generate kernel headers package for both host
and target when using a cross build
Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
---
.../linux/classes/kbuildtarget.bbclass | 8 ++++
.../linux/files/debian/control.tmpl | 6 ++-
.../linux/files/debian/isar/build.tmpl | 13 ++++-
.../linux/files/debian/isar/common.tmpl | 9 ++++
.../linux/files/debian/isar/install.tmpl | 34 +++++++++-----
meta/recipes-kernel/linux/linux-custom.inc | 47 ++++++++++++++++++-
6 files changed, 99 insertions(+), 18 deletions(-)
create mode 100644 meta/recipes-kernel/linux/classes/kbuildtarget.bbclass
diff --git a/meta/recipes-kernel/linux/classes/kbuildtarget.bbclass b/meta/recipes-kernel/linux/classes/kbuildtarget.bbclass
new file mode 100644
index 00000000..26369861
--- /dev/null
+++ b/meta/recipes-kernel/linux/classes/kbuildtarget.bbclass
@@ -0,0 +1,8 @@
+python kbuildtarget_virtclass_handler() {
+ pn = e.data.getVar('PN')
+ if pn.endswith('-kbuildtarget'):
+ e.data.setVar('BPN', pn[:-len('-kbuildtarget')])
+ e.data.appendVar('OVERRIDES', ':class-kbuildtarget')
+}
+addhandler kbuildtarget_virtclass_handler
+kbuildtarget_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"
diff --git a/meta/recipes-kernel/linux/files/debian/control.tmpl b/meta/recipes-kernel/linux/files/debian/control.tmpl
index 7f271367..6f8f8afe 100644
--- a/meta/recipes-kernel/linux/files/debian/control.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/control.tmpl
@@ -6,6 +6,7 @@ Build-Depends: bc, kmod, cpio, ${KBUILD_DEPENDS}
Homepage: http://www.kernel.org/
Package: linux-image-${KERNEL_NAME_PROVIDED}
+Build-Profiles: <kernel>
Architecture: any
Depends: ${KERNEL_DEBIAN_DEPENDS}
Description: ${KERNEL_NAME_PROVIDED} Linux kernel, version @KR@
@@ -13,6 +14,7 @@ Description: ${KERNEL_NAME_PROVIDED} Linux kernel, version @KR@
files, version: @KR@.
Package: linux-headers-${KERNEL_NAME_PROVIDED}
+Build-Profiles: <kernel>
Architecture: any
Depends: ${KERNEL_HEADERS_DEBIAN_DEPENDS}, ${perl:Depends}, ${shlib:Depends}
Description: ${KERNEL_NAME_PROVIDED} Linux kernel headers for @KR@
@@ -21,7 +23,7 @@ Description: ${KERNEL_NAME_PROVIDED} Linux kernel headers for @KR@
This is useful for people who need to build external modules
Package: linux-libc-dev
-Build-Profiles: <!nolibcdev>
+Build-Profiles: <!nolibcdev kernel>
Section: devel
Provides: linux-kernel-headers
Architecture: any
@@ -41,6 +43,7 @@ Description: Linux Kernel Headers for development (for cross-compiling)
your kernel. Use linux-headers-* packages for that.
Package: linux-image-${KERNEL_NAME_PROVIDED}-dbg
+Build-Profiles: <kernel>
Section: debug
Architecture: any
Description: Linux kernel debugging symbols for @KR@
@@ -48,6 +51,7 @@ Description: Linux kernel debugging symbols for @KR@
all the necessary debug symbols for the kernel and its modules.
Package: linux-kbuild-${KERNEL_NAME_PROVIDED}
+Build-Profiles: <kbuild>
Architecture: any
Depends: ${perl:Depends}, ${shlib:Depends}
Description: ${KERNEL_NAME_PROVIDED} Linux kbuild scripts and tools for @KR@
diff --git a/meta/recipes-kernel/linux/files/debian/isar/build.tmpl b/meta/recipes-kernel/linux/files/debian/isar/build.tmpl
index 906dc580..81a6ba8a 100644
--- a/meta/recipes-kernel/linux/files/debian/isar/build.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/isar/build.tmpl
@@ -21,8 +21,17 @@ do_build() {
KR=$(${MAKE} O=${KERNEL_BUILD_DIR} -s --no-print-directory kernelrelease)
sed -i "s/@KR@/${KR}/g" ${S}/debian/control ${S}/debian/linux-image-${KERNEL_NAME_PROVIDED}.*
- # Build the Linux kernel
- ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}"
+ if echo "${DEB_BUILD_PROFILES}" | grep -q "kernel"; then # Build kernel scripts and tools
+ ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}"
+ elif echo "${DEB_BUILD_PROFILES}" | grep -q "kbuild"; then # Build kernel scripts and tools
+ ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" scripts
+ if grep -q -E "CONFIG_STACK_VALIDATION=y|CONFIG_HAVE_OBJTOOL=y" ${KERNEL_BUILD_DIR}/.config && [ -d "tools/objtool" ]; then
+ ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" tools/objtool || true
+ fi
+ if grep -q "CONFIG_MODULES=y" ${KERNEL_BUILD_DIR}/.config; then
+ ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" modules_prepare
+ fi
+ fi
# Stop tracing
set +x
diff --git a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl
index 0944e943..e3a1d8a0 100644
--- a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl
@@ -12,6 +12,15 @@ KERNEL_PKG_LIBC_HEADERS=linux-libc-dev
KERNEL_PKG_LIBC_HEADERS_CROSS=linux-libc-dev-${DISTRO_ARCH}-cross
KERNEL_PKG_KERN_KBUILD=linux-kbuild-${KERNEL_NAME_PROVIDED}
+# Force creating debian package with valid host arch for -native build
+# Use a cross build to comply with arch specific kernel defconfigs
+# The scripts and tools are always created for host arch
+if echo "${DEB_BUILD_PROFILES}" | grep -q -e "cross" -e "kbuild"
+then
+ eval $(dpkg-architecture -f -A ${DISTRO_ARCH})
+ CROSS_COMPILE=${DEB_TARGET_GNU_TYPE}-
+fi
+
# Constants
KCONF=.config
diff --git a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl
index 97780dcc..77856aee 100644
--- a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl
@@ -33,20 +33,28 @@ do_install() {
# Trace what we do here
set -x
- # Run the install steps
- install_image
- if [ "${ARCH}" != "um" ]; then
- install_config
- install_map
+ if echo "${DEB_BUILD_PROFILES}" | grep -q "kbuild"; then
+ # Install kernel scripts and tools
+ install_kbuild ${deb_kern_kbuild_dir}
+ fi
+
+ if echo "${DEB_BUILD_PROFILES}" | grep -q "kernel"; then
+ if echo "${DEB_BUILD_PROFILES}" | grep -q "cross"; then
+ # Install cross kernel scripts and tools
+ install_kbuild ${deb_kern_kbuild_dir}-${HOST_ARCH}-cross
+ fi
+
+ # Run the install steps
+ install_image
+ if [ "${ARCH}" != "um" ]; then
+ install_config
+ install_map
+ fi
+ install_hooks
+ install_dtbs
+ install_kmods
+ install_headers
fi
- install_hooks
- install_dtbs
- install_kmods
- install_headers
-
- # Cleanup and install kernel scripts and tools
- rm -rf ${deb_kern_kbuild_dir}
- install_kbuild ${deb_kern_kbuild_dir}
# Stop tracing
set +x
diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
index cbd23dc2..9c52751c 100644
--- a/meta/recipes-kernel/linux/linux-custom.inc
+++ b/meta/recipes-kernel/linux/linux-custom.inc
@@ -86,28 +86,71 @@ TEMPLATE_VARS += " \
inherit dpkg
inherit template
+inherit kbuildtarget
# Add custom cflags to the kernel build
KCFLAGS ?= "-fdebug-prefix-map=${CURDIR}=."
KAFLAGS ?= "-fdebug-prefix-map=${CURDIR}=."
# Derive name of the kernel packages from the name of this recipe
-KERNEL_NAME_PROVIDED ?= "${@ d.getVar('PN').partition('linux-')[2]}"
+KERNEL_NAME_PROVIDED ?= "${@ d.getVar('BPN').partition('linux-')[2]}"
+
+# Determine cross-profile override
+python() {
+ if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and d.getVar("ISAR_CROSS_COMPILE", True) == "1" and "class-native" not in d.getVar("OVERRIDES", True).split(":"):
+ d.appendVar("OVERRIDES", ":cross-profile")
+}
+
+# Default profiles and provides
+BUILD_PROFILES = "kernel kbuild"
+
+# We only offer the -kbuildtarget variant when actually cross compiling
+BBCLASSEXTEND:append:cross-profile = " kbuildtarget"
+
+# When cross-profile is active:
+# build only kernel with the default variant of the recipe
+BUILD_PROFILES:cross-profile = "kernel"
+
+# Select correct kbuild package for isar cross-build
+HEADERS_DEPENDS:cross-profile = ", linux-kbuild-${KERNEL_NAME_PROVIDED}:${HOST_ARCH} | linux-kbuild-${KERNEL_NAME_PROVIDED}"
+
+# -native: kbuild package for host
+BUILD_PROFILES:class-native = "kbuild"
+RECIPE_PROVIDES:class-native = "linux-kbuild-${KERNEL_NAME_PROVIDED}-native"
+
+# -kbuildtarget: kbuild package for target, enforcing non-cross-build
+BUILD_PROFILES:class-kbuildtarget = "kbuild"
+RECIPE_PROVIDES:class-kbuildtarget = "linux-kbuild-${KERNEL_NAME_PROVIDED}"
+ISAR_CROSS_COMPILE:class-kbuildtarget = "0"
# Make bitbake know we will be producing linux-image and linux-headers packages
# Also make it know about other packages from control
-PROVIDES += " \
+RECIPE_PROVIDES = " \
linux-image-${KERNEL_NAME_PROVIDED} \
linux-headers-${KERNEL_NAME_PROVIDED} \
linux-libc-dev \
linux-libc-dev-${DISTRO_ARCH}-cross \
linux-image-${KERNEL_NAME_PROVIDED}-dbg \
+ linux-kbuild-${KERNEL_NAME_PROVIDED} \
"
+# When cross-profile is active:
+# kbuild package is provided by -native or -kbuildtarget variant
+# Otherwise it's provided by the default variant
+RECIPE_PROVIDES:remove:cross-profile = "linux-kbuild-${KERNEL_NAME_PROVIDED}"
# Append headers depends
HEADERS_DEPENDS = ", linux-kbuild-${KERNEL_NAME_PROVIDED}"
KERNEL_HEADERS_DEBIAN_DEPENDS:append = "${HEADERS_DEPENDS}"
+# Append provides
+PROVIDES += "${RECIPE_PROVIDES}"
+
+# Append build profiles
+DEB_BUILD_PROFILES += "${BUILD_PROFILES}"
+
+# Add dependency to build -kbuildtarget and -native automatically
+RDEPENDS:append:cross-profile = " ${BPN}-native"
+
def get_kernel_arch(d):
distro_arch = d.getVar("DISTRO_ARCH")
if distro_arch in ["amd64", "i386"]:
--
2.39.2
next prev parent reply other threads:[~2024-02-14 10:10 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-14 10:10 [PATCH v6 0/5] linux-custom: Split up binaries from kernel headers to kbuild package Stefan Koch
2024-02-14 10:10 ` [PATCH v6 1/5] linux-custom: Set PROVIDES variable using bitbake overrides Stefan Koch
2024-02-14 10:10 ` [PATCH v6 2/5] linux-custom: Split up binaries from kernel headers to kbuild package Stefan Koch
2024-02-14 10:10 ` Stefan Koch [this message]
2024-05-05 17:16 ` [PATCH v6 3/5] linux-custom: Provide target and host specific kernel kbuild packages Jan Kiszka
2024-05-06 10:07 ` Koch, Stefan
2024-05-06 10:46 ` Jan Kiszka
2024-05-06 6:22 ` Jan Kiszka
2024-07-04 6:12 ` Anton Mikanovich
2024-07-04 12:44 ` 'Koch, Stefan' via isar-users
2024-07-04 13:02 ` 'cedric.hombourger@siemens.com' via isar-users
2024-07-04 13:19 ` 'Koch, Stefan' via isar-users
2024-02-14 10:10 ` [PATCH v6 4/5] linux-module: Support emulated module build with cross-compiled kernel Stefan Koch
2024-02-14 10:10 ` [PATCH v6 5/5] docs: Update custom_kernel docs for split up of kernel scripts and tools Stefan Koch
2024-02-16 7:42 ` [PATCH v6 0/5] linux-custom: Split up binaries from kernel headers to kbuild package MOESSBAUER, Felix
2024-04-15 12:47 ` Uladzimir Bely
2024-04-17 9:29 ` Koch, Stefan
2024-04-23 19:22 ` Uladzimir Bely
2024-04-30 13:10 ` Koch, Stefan
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=20240214101025.2123540-4-stefan-koch@siemens.com \
--to=stefan-koch@siemens.com \
--cc=adriaan.schmidt@siemens.com \
--cc=cedric.hombourger@siemens.com \
--cc=christian.storm@siemens.com \
--cc=felix.moessbauer@siemens.com \
--cc=isar-users@googlegroups.com \
--cc=jan.kiszka@siemens.com \
--cc=michael.adler@siemens.com \
--cc=simon.sudler@siemens.com \
--cc=ubely@ilbers.de \
/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