public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
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 2/5] linux-custom: Split up binaries from kernel headers to kbuild package
Date: Wed, 14 Feb 2024 11:10:22 +0100	[thread overview]
Message-ID: <20240214101025.2123540-3-stefan-koch@siemens.com> (raw)
In-Reply-To: <20240214101025.2123540-1-stefan-koch@siemens.com>

This patch does introduce specific kernel kbuild packages that
ship the "scripts" and "tools" binaries.
The kernel headers fulfill this using symlinks to point
to the "scripts" and "tools" of the kernel kbuild package.

This is already known from debian kernel packages structure:
- Generate a kernel headers package without binaries
- Create kernel kbuild packages that
  ship the "scripts" and "tools" binaries
- Using symlinks to point to the "scripts"
  and "tools" binaries

Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
---
 .../linux/files/debian/control.tmpl           |  9 +++-
 .../linux/files/debian/isar/common.tmpl       |  2 +
 .../linux/files/debian/isar/install.tmpl      | 51 +++++++++++++++----
 meta/recipes-kernel/linux/linux-custom.inc    |  4 ++
 4 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/meta/recipes-kernel/linux/files/debian/control.tmpl b/meta/recipes-kernel/linux/files/debian/control.tmpl
index 956db3e3..7f271367 100644
--- a/meta/recipes-kernel/linux/files/debian/control.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/control.tmpl
@@ -26,7 +26,7 @@ Section: devel
 Provides: linux-kernel-headers
 Architecture: any
 Description: Linux support headers for userspace development
- This package provides userspaces headers from the Linux kernel.  These headers
+ This package provides userspaces headers from the Linux kernel. These headers
  are used by the installed headers for GNU glibc and other system libraries.
 
 Package: linux-libc-dev-${DISTRO_ARCH}-cross
@@ -46,3 +46,10 @@ Architecture: any
 Description: Linux kernel debugging symbols for @KR@
  This package will come in handy if you need to debug the kernel. It provides
  all the necessary debug symbols for the kernel and its modules.
+
+Package: linux-kbuild-${KERNEL_NAME_PROVIDED}
+Architecture: any
+Depends: ${perl:Depends}, ${shlib:Depends}
+Description: ${KERNEL_NAME_PROVIDED} Linux kbuild scripts and tools for @KR@
+ This package provides kernel kbuild scripts and tools for @KR@
+ This is useful for people who need to build external modules
diff --git a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl
index 9babf9a4..0944e943 100644
--- a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl
@@ -10,6 +10,7 @@ KERNEL_PKG_IMAGE=linux-image-${KERNEL_NAME_PROVIDED}
 KERNEL_PKG_KERN_HEADERS=linux-headers-${KERNEL_NAME_PROVIDED}
 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}
 
 # Constants
 KCONF=.config
@@ -21,6 +22,7 @@ deb_dbg_dir=${deb_img_dir}-dbg
 deb_kern_hdr_dir=${deb_top_dir}/${KERNEL_PKG_KERN_HEADERS}
 deb_libc_hdr_dir=${deb_top_dir}/${KERNEL_PKG_LIBC_HEADERS}
 deb_libc_hdr_cross_dir=${deb_top_dir}/${KERNEL_PKG_LIBC_HEADERS_CROSS}
+deb_kern_kbuild_dir=${deb_top_dir}/${KERNEL_PKG_KERN_KBUILD}
 
 # Array of packages to be generated
 declare -A kern_pkgs
diff --git a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl
index e91d33bb..97780dcc 100644
--- a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl
@@ -33,6 +33,7 @@ do_install() {
     # Trace what we do here
     set -x
 
+    # Run the install steps
     install_image
     if [ "${ARCH}" != "um" ]; then
         install_config
@@ -43,6 +44,10 @@ do_install() {
     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
 }
@@ -171,21 +176,15 @@ kernel_headers() {
     mkdir -p ${destdir}
     mkdir -p ${deb_kern_hdr_dir}/lib/modules/${krel}
 
-    (cd ${S}; find . -name 'Makefile*' -o -name 'Kconfig*' -o -name '*.pl') >>${src_hdr_files}
-    (cd ${S}; find arch/*/include include scripts -type f -o -type l) >>${src_hdr_files}
+    (cd ${S}; find . -not -path './scripts/*' -a -not -path './tools/*' -a \( -name 'Makefile*' -o -name 'Kconfig*' -o -name '*.pl' \)) >>${src_hdr_files}
+    (cd ${S}; find arch/*/include include -type f -o -type l) >>${src_hdr_files}
     (cd ${S}; find arch/${ARCH} -name module.lds -o -name Kbuild.platforms -o -name Platform) >>${src_hdr_files}
     (cd ${S}; find $(find arch/${ARCH} -name include -o -name scripts -type d) -type f) >>${src_hdr_files}
 
     if [ -n "${CONFIG_MODULES}" ]; then
         echo Module.symvers >> ${obj_hdr_files}
     fi
-    (cd ${O}; find arch/${ARCH}/include include scripts -type f) >>${obj_hdr_files}
-    if [ -n "${CONFIG_STACK_VALIDATION}" -o -n "${CONFIG_HAVE_OBJTOOL}" ]; then
-        (cd ${O}; find tools/objtool -type f -executable) >>${obj_hdr_files}
-    fi
-    if [ -n "${CONFIG_GCC_PLUGINS}" ]; then
-        (cd ${O}; find scripts/gcc-plugins -name *.so -o -name gcc-common.h) >>${obj_hdr_files}
-    fi
+    (cd ${O}; find arch/${ARCH}/include include -type f) >>${obj_hdr_files}
 
     # deploy files that were matched above
     tar -C ${S} -cf - -T - <${src_hdr_files} | tar -C ${destdir} -xf -
@@ -194,8 +193,11 @@ kernel_headers() {
     # add the kernel config
     cp ${O}/${KCONF} ${destdir}/.config
 
-    # handle kernel development tools
-    kernel_tools
+    # add symlink to scripts and tools directories
+    ln -sf ../../lib/linux-kbuild-${krel}/scripts ${destdir}/scripts
+    if [ -n "${CONFIG_STACK_VALIDATION}" -o -n "${CONFIG_HAVE_OBJTOOL}" ]; then
+        ln -sf ../../lib/linux-kbuild-${krel}/tools ${destdir}/tools
+    fi
 
     # create symlinks
     ln -sf /${kernel_headers_dir} ${deb_kern_hdr_dir}/lib/modules/${krel}/build
@@ -209,4 +211,31 @@ install_headers() {
     kernel_headers
 }
 
+install_kbuild() {
+    kernel_kbuild_dir=usr/lib/linux-kbuild-${krel}
+    destdir=${1}/${kernel_kbuild_dir}
+    src_kbuild_files=$(mktemp)
+    obj_kbuild_files=$(mktemp)
+
+    mkdir -p ${destdir}
+
+    (cd ${S}; find . -path './scripts/*' -a -path './tools/*' -a \( -name 'Makefile*' -o -name 'Kconfig*' -o -name '*.pl' \)) >>${src_kbuild_files}
+    (cd ${S}; find scripts -type f -o -type l) >>${src_kbuild_files}
+
+    (cd ${O}; find scripts -type f) >>${obj_kbuild_files}
+    if [ -n "${CONFIG_STACK_VALIDATION}" -o -n "${CONFIG_HAVE_OBJTOOL}" ]; then
+        (cd ${O}; find tools/objtool -type f -executable) >>${obj_kbuild_files}
+    fi
+    if [ -n "${CONFIG_GCC_PLUGINS}" ]; then
+        (cd ${O}; find scripts/gcc-plugins -name *.so -o -name gcc-common.h) >>${obj_kbuild_files}
+    fi
+
+    # deploy files that were matched above
+    tar -C ${S} -cf - -T - <${src_kbuild_files} | tar -C ${destdir} -xf -
+    tar -C ${O} -cf - -T - <${obj_kbuild_files} | tar -C ${destdir} -xf -
+
+    # handle kernel development tools
+    kernel_tools
+}
+
 main install ${*}
diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
index 14c7409b..cbd23dc2 100644
--- a/meta/recipes-kernel/linux/linux-custom.inc
+++ b/meta/recipes-kernel/linux/linux-custom.inc
@@ -104,6 +104,10 @@ PROVIDES += " \
     linux-image-${KERNEL_NAME_PROVIDED}-dbg \
 "
 
+# Append headers depends
+HEADERS_DEPENDS = ", linux-kbuild-${KERNEL_NAME_PROVIDED}"
+KERNEL_HEADERS_DEBIAN_DEPENDS:append = "${HEADERS_DEPENDS}"
+
 def get_kernel_arch(d):
     distro_arch = d.getVar("DISTRO_ARCH")
     if distro_arch in ["amd64", "i386"]:
-- 
2.39.2


  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] " 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 ` Stefan Koch [this message]
2024-02-14 10:10 ` [PATCH v6 3/5] linux-custom: Provide target and host specific kernel kbuild packages Stefan Koch
2024-05-05 17:16   ` 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-3-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