public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: isar-users <isar-users@googlegroups.com>
Subject: [PATCH v6 2/5] Provide include for easy custom kernel builds
Date: Wed, 14 Feb 2018 20:35:11 +0100	[thread overview]
Message-ID: <a071505d-c9d8-5283-e963-8785648d8ebe@siemens.com> (raw)
In-Reply-To: <e8b6e753a8b8b265926146f0919cfa1a54b46d5f.1518599595.git.jan.kiszka@siemens.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

With this include, it becomes almost trivial to replace the distro
kernel with a custom build. You just need to include linux-custom.inc,
specify the source URI, define via S where the source is unpacked to and
provide a defconfig.

To switch to a custom kernel recipe, KERNEL_NAME has to be adjusted in
local.conf or the machine configuration.

Unless explicitly stated via KERNEL_FLAVOR, this tag is derived from
the including recipe name which then needs to follow the scheme
"linux-<flavor>[_version].bb".

The different kernel defconfig file name can be specified via the
KERNEL_DEFCONFIG variable so that also machine-specific defconfigs can
be set in the same recipe (KERNEL_DEFCONFIG_my-machine = "...").

The approach works internally by first running "make deb-pkg" on the
kernel and the repackages the output to make the binary linux-image and
linux-header debs act as proper replacement of a distro kernel. This
results in a suboptimal technical implementation which may eventually be
replaced by an isar-implemented deb-pkg build process. However, this is
not expected to affect the user-visible interface of this class.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

Changes in v6:
 - added copyright header to kernel-build.sh

 meta/recipes-kernel/linux/files/build-kernel.sh | 83 +++++++++++++++++++++++++
 meta/recipes-kernel/linux/linux-custom.inc      | 47 ++++++++++++++
 2 files changed, 130 insertions(+)
 create mode 100644 meta/recipes-kernel/linux/files/build-kernel.sh
 create mode 100644 meta/recipes-kernel/linux/linux-custom.inc

diff --git a/meta/recipes-kernel/linux/files/build-kernel.sh b/meta/recipes-kernel/linux/files/build-kernel.sh
new file mode 100644
index 0000000..5a454ae
--- /dev/null
+++ b/meta/recipes-kernel/linux/files/build-kernel.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+# Custom kernel build
+#
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2018
+#
+# SPDX-License-Identifier: MIT
+
+set -e
+
+REPACK_DIR="$1/../repack"
+REPACK_LINUX_IMAGE_DIR="${REPACK_DIR}/linux-image"
+REPACK_LINUX_HEADERS_DIR="${REPACK_DIR}/linux-headers"
+
+apt-get install -y -o Debug::pkgProblemResolver=yes --no-install-recommends \
+	${KBUILD_DEPENDS}
+
+cd $1
+make olddefconfig
+
+rm -f .version
+make -j $(($(nproc) * 2)) deb-pkg
+
+rm -rf ${REPACK_DIR}
+mkdir -p ${REPACK_DIR}
+mkdir -p ${REPACK_LINUX_IMAGE_DIR}
+mkdir -p ${REPACK_LINUX_HEADERS_DIR}
+
+cd ..
+tar xzf linux-${PV}_${PV}-1.debian.tar.gz -C ${REPACK_DIR}
+dpkg-deb -R linux-image-${PV}_${PV}-1_*.deb ${REPACK_LINUX_IMAGE_DIR}
+dpkg-deb -R linux-headers-${PV}_${PV}-1_*.deb ${REPACK_LINUX_HEADERS_DIR}
+
+dpkg-gencontrol -crepack/debian/control \
+	-lrepack/debian/changelog \
+	-frepack/debian/files \
+	-plinux-image-${PV} \
+	-P${REPACK_LINUX_IMAGE_DIR} \
+	-DPackage="linux-image-${KERNEL_NAME}" \
+	-DSection=kernel \
+	-DPriority=required \
+	-DDepends="${KERNEL_DEBIAN_DEPENDS}"
+
+# Add Debian-like link installation to postinst
+touch ${REPACK_LINUX_IMAGE_DIR}/lib/modules/${PV}/.fresh-install
+sed -i ${REPACK_LINUX_IMAGE_DIR}/DEBIAN/postinst \
+    -e "/^set -e$/a\\
+\\
+if [ -f /lib/modules/${PV}/.fresh-install ]; then\\
+	change=install\\
+else\\
+	change=upgrade\\
+fi\\
+linux-update-symlinks \$change ${PV} /boot/vmlinuz-${PV}\\
+rm -f /lib/modules/${PV}/.fresh-install"
+
+# Add Debian-like link removal to postrm
+sed -i ${REPACK_LINUX_IMAGE_DIR}/DEBIAN/postrm \
+    -e "/^set -e$/a\\
+\\
+rm -f /lib/modules/${PV}/.fresh-install\\
+\\
+if [ \"\$1\" != upgrade ] && command -v linux-update-symlinks >/dev/null; then\\
+	linux-update-symlinks remove ${PV}  /boot/vmlinuz-${PV}\\
+fi"
+
+dpkg-gencontrol -crepack/debian/control \
+	-lrepack/debian/changelog \
+	-frepack/debian/files \
+	-plinux-headers-${PV} \
+	-P${REPACK_LINUX_HEADERS_DIR} \
+	-Vkernel:debarch="${KERNEL_NAME}" \
+	-DPackage="linux-headers-${KERNEL_NAME}" \
+	-DSection=kernel \
+	-DDepends="${KERNEL_HEADERS_DEBIAN_DEPENDS}"
+
+dpkg-deb -b ${REPACK_LINUX_IMAGE_DIR} \
+	linux-image-${KERNEL_NAME}_${PV}-1_${KERNEL_NAME}.deb
+rm -f linux-image-${PV}_${PV}-1_*.deb
+dpkg-deb -b ${REPACK_LINUX_HEADERS_DIR} \
+	linux-headers-${KERNEL_NAME}_${PV}-1_${KERNEL_NAME}.deb
+rm -f linux-headers-${PV}_${PV}-1_*.deb
diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
new file mode 100644
index 0000000..0498dfa
--- /dev/null
+++ b/meta/recipes-kernel/linux/linux-custom.inc
@@ -0,0 +1,47 @@
+# Custom kernel build
+#
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2018
+#
+# SPDX-License-Identifier: MIT
+
+FILESPATH =. "${LAYERDIR_core}/recipes-kernel/linux/files:"
+
+DESCRIPTION ?= "Custom kernel"
+
+KERNEL_FLAVOR ?= "${@ d.getVar('PN', True).partition('linux-')[2]}"
+KERNEL_DEFCONFIG ?= "defconfig"
+
+python() {
+    kernel = d.getVar("KERNEL_NAME", True)
+    flavor = d.getVar("KERNEL_FLAVOR", True)
+    if kernel and flavor and kernel.startswith(flavor + "-"):
+        d.setVar('PROVIDES', 'linux-image-' + kernel + ' ' + \
+                             'linux-headers-' + kernel)
+}
+
+inherit dpkg-base
+
+SRC_URI += "file://build-kernel.sh"
+
+KBUILD_DEPENDS ?= "libssl-dev libelf-dev bc"
+KERNEL_DEBIAN_DEPENDS ?= "initramfs-tools | linux-initramfs-tool, kmod, linux-base (>= 4.3~)"
+KERNEL_HEADERS_DEBIAN_DEPENDS ?= "libc6, libssl1.1, gcc"
+
+dpkg_runbuild() {
+	# Install package builder script
+	sudo install -m 755 ${WORKDIR}/build-kernel.sh ${BUILDCHROOT_DIR}
+
+	sudo cp ${WORKDIR}/${KERNEL_DEFCONFIG} ${WORKDIR}/${S}/.config
+
+	E="${@ bb.utils.export_proxies(d)}"
+
+	export PV=${PV}
+	export KERNEL_NAME=${KERNEL_NAME}
+
+	export KBUILD_DEPENDS="${KBUILD_DEPENDS}"
+	export KERNEL_DEBIAN_DEPENDS="${KERNEL_DEBIAN_DEPENDS}"
+	export KERNEL_HEADERS_DEBIAN_DEPENDS="${KERNEL_HEADERS_DEBIAN_DEPENDS}"
+
+	sudo -E chroot ${BUILDCHROOT_DIR} /build-kernel.sh ${PP}/${S}
+}
-- 
2.13.6

  reply	other threads:[~2018-02-14 19:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-14  9:13 [PATCH v5 0/5] Provide infrastructure and examples for custom kernels and modules Jan Kiszka
2018-02-14  9:13 ` [PATCH v5 1/5] Make distro kernel replaceable Jan Kiszka
2018-02-14  9:13 ` [PATCH v5 2/5] Provide include for easy custom kernel builds Jan Kiszka
2018-02-14 19:35   ` Jan Kiszka [this message]
2018-02-14  9:13 ` [PATCH v5 3/5] Add custom kernel examples Jan Kiszka
2018-02-14  9:13 ` [PATCH v5 4/5] Provide include file for easy custom module builds Jan Kiszka
2018-02-14  9:13 ` [PATCH v5 5/5] Add exemplary kernel module Jan Kiszka
2018-02-14 15:21   ` [PATCH v6 " Jan Kiszka
2018-02-15  7:15     ` Alexander Smirnov
2018-02-15  7:35       ` [PATCH v6 4/5] Provide include file for easy custom module builds Jan Kiszka
2018-02-15  7:54         ` Alexander Smirnov
2018-02-15  7:54           ` Jan Kiszka
2018-02-15  8:01             ` Alexander Smirnov
2018-02-15 11:24 ` [PATCH v5 0/5] Provide infrastructure and examples for custom kernels and modules Alexander Smirnov
2018-02-15 15:14   ` Jan Kiszka
2018-02-15 14:43 ` Alexander Smirnov
2018-02-15 15:00   ` Jan Kiszka
2018-02-15 15:04     ` Alexander Smirnov
2018-02-15 15:13       ` Jan Kiszka
2018-02-15 15:27         ` Alexander Smirnov

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=a071505d-c9d8-5283-e963-8785648d8ebe@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=isar-users@googlegroups.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