From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6522335612514598912 X-Received: by 10.25.19.24 with SMTP id j24mr8753lfi.12.1518636914318; Wed, 14 Feb 2018 11:35:14 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 10.46.50.16 with SMTP id y16ls1856667ljy.6.gmail; Wed, 14 Feb 2018 11:35:13 -0800 (PST) X-Google-Smtp-Source: AH8x224OBMB25GVl4Y3c5KM9EhQZfaIg/2md8fRItwxiElC+DLoLOiSARe+5m9B/kgsilztmovO/ X-Received: by 10.46.89.156 with SMTP id g28mr6038ljf.32.1518636913525; Wed, 14 Feb 2018 11:35:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518636913; cv=none; d=google.com; s=arc-20160816; b=vDMDK/y27rPu62ymR2YweH4ij4U6cwwSlLHxcalaeD6bnG+oPMMc2nhNEOhX5C9AKk T5HeNUtyHDBWS68s5jl7BtrtwFheA/+ifeeOozrAryGtmrebn9Xtc/zRmyHOyCPf7p4r MdaDFR6sKv48I36On3k5Wf6sU8HMW8MMSIpXACn1DSMUZzJlVLLJrU6POt8HmBeoQ5EQ OJKKkP6mTDWl6k2KTQ49wOn4MhPIkh9x1AsOiZrU23SuxmJcH09t8gP1Zay3SNPY5sIu Ld60JzMQ5Scik9F9tk5I9CJDNUFuPdETXK1LEPRcMiyzCbbP8Kl43FFU4jUVXoY50E1+ lKjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :arc-authentication-results; bh=eBn4B8PDY/mun5RrsOAg4zaVEC+x0pWZ81imHXWRSTE=; b=XnNy/a1k2p7b3EIbl8+bGXw3HM6Tu1sYywAWzBhZcPAzx/gCr5IGTiTnbU6iGEKvgo qPvTgYHrdAymwVNwpk9EROhQGY0hYK180mZYngS14Uk8NghcCVwpikIlhWC7kYwjYuay K/OgGMFwQUm1YE1YywN2qPDpAc1gBevuQwnTIYZlv2xOGcldhmbawvqtfuuQfmSXUTbl +4MAuajbf/CubfhyetzBkTblVjVi21zjvrwzrku91xeLr8cagt1RJHmUhu4FQN25kA9u yOnihPQGN/AqU/CNdQB66pLh84jZ2Z7WwsANFzIiVK333Xn/g36hCHZHOgPTU9JJZPGR HkHg== 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 w20si707727ljd.2.2018.02.14.11.35.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Feb 2018 11:35:13 -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 mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id w1EJZCIT022321 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 14 Feb 2018 20:35:12 +0100 Received: from [139.25.68.37] (md1q0hnc.ad001.siemens.net [139.25.68.37] (may be forged)) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id w1EJZC33029437 for ; Wed, 14 Feb 2018 20:35:12 +0100 Subject: [PATCH v6 2/5] Provide include for easy custom kernel builds From: Jan Kiszka To: isar-users References: Message-ID: Date: Wed, 14 Feb 2018 20:35:11 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TUID: HaqOPzTNcVGF 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 --- 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