From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6522335612514598912 X-Received: by 10.28.145.139 with SMTP id t133mr457020wmd.21.1518599598838; Wed, 14 Feb 2018 01:13:18 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 10.28.165.130 with SMTP id o124ls2045916wme.9.canary-gmail; Wed, 14 Feb 2018 01:13:18 -0800 (PST) X-Google-Smtp-Source: AH8x224X8hNdMmXOfYVCNK94nomSdLosvr4yMs1gUmcGhn0o9wWmVscieusZ4+edjcH1gWXJS+Zj X-Received: by 10.28.241.2 with SMTP id p2mr453101wmh.26.1518599598361; Wed, 14 Feb 2018 01:13:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518599598; cv=none; d=google.com; s=arc-20160816; b=Gl0vhd0iCJw9ZjSQIZa4SKZAuFblzY0rpppwyl+aYvrYCNXLzgpR0gaj3nLmhzKDUt AcphzxP/DiaYH+zf1+qdGen0QhZ9zNbaFW9LVhhfzQShQr0KTIaS5GDot7zcRMV6QfTs nXCUxLHn0CoEWsnQC4IfKQwQY/7EAP+Sz0Z1s7t2KMcGY0BWDWxcGK759GUO8Zye4qx6 9F4AGM6UlOHmtj38i+eWZRVpEL5dxCdZFwn1VM0ed/JUO8cb7hQOu5pgMaPQKI4tzg0C UFqIuf1sMIycX0I06G/PILpFzEgl7X0US8+5mXQnQLseU7q8CESyCsg2lCtHnCamqBSa NV1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:to:from:arc-authentication-results; bh=iDfJpgUlAjaCnYTmi6sta3VD53qzClOphv6nADhCX+w=; b=K3XnU9iYxejC6vAOHbucSAcOMMSo5MoEX7TM/P8y+Zsmpd4YzosagsUa/yBreulfSD 9nae5ZMGNMUYl8voLPHAAX8fCrQN4qv3jz4IHfEq9MC6l+JqvzmmX2PZBBVAibEGyM7T yh4XZjsCliNvIQRwo/N27FBcIqHoocJFD9trYLFE5k64t5AKE31ebx1nKiPimH1pxslz twfAxn5zJ98Ik6v+8/Jyc4oAaKC7VdBI1i6sFDl8vXfTCZOCP6jkkX5LwU1hmQTk+3CA v2HR3Yvka5vIqLY9OVjZ5KjuEQTJEV025SvGOoDnQnkfqECxxzR7HnXX9XUVOzQ8V4+U o5og== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com Return-Path: Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id t15si98650wmh.1.2018.02.14.01.13.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Feb 2018 01:13:18 -0800 (PST) Received-SPF: pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id w1E9DHpw024672 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 14 Feb 2018 10:13:18 +0100 Received: from md1f2u6c.ww002.siemens.net ([167.87.36.169]) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id w1E9DHSa028726 for ; Wed, 14 Feb 2018 10:13:17 +0100 From: Jan Kiszka To: isar-users Subject: [PATCH v5 2/5] Provide include for easy custom kernel builds Date: Wed, 14 Feb 2018 10:13:12 +0100 Message-Id: X-Mailer: git-send-email 2.13.6 In-Reply-To: References: In-Reply-To: References: X-TUID: q8C8ub7ucQPU From: Jan Kiszka 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-[_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 --- meta/recipes-kernel/linux/files/build-kernel.sh | 75 +++++++++++++++++++++++++ meta/recipes-kernel/linux/linux-custom.inc | 47 ++++++++++++++++ 2 files changed, 122 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..e64ab7b --- /dev/null +++ b/meta/recipes-kernel/linux/files/build-kernel.sh @@ -0,0 +1,75 @@ +#!/bin/sh +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