From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6755821036247187456 X-Received: by 2002:a05:6000:343:: with SMTP id e3mr12879682wre.20.1573289501026; Sat, 09 Nov 2019 00:51:41 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a7b:c941:: with SMTP id i1ls165984wml.0.canary-gmail; Sat, 09 Nov 2019 00:51:40 -0800 (PST) X-Google-Smtp-Source: APXvYqxNAOkTIdgivptM1z/43OwvpCeElo7HZVtUljso2GejqpLB6cRQjejOnFRx9DeL42qJivaW X-Received: by 2002:a1c:3c42:: with SMTP id j63mr12906353wma.90.1573289500047; Sat, 09 Nov 2019 00:51:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573289500; cv=none; d=google.com; s=arc-20160816; b=ORciwj8T02KR0wA/hKogTF9TZbSyN++irgFkawCH7YmLlWmm19ZW9KJwCzBXnXHhaD Zif8HDYr+t6vuTTOsBmOsE1smQ7m7tnUPJjVXypVZHhDodxMk/8YScJNZI6qyrpHwy23 ++qBzbjJr/LOWquZ+S4mGf6G/6x4W8Ds5lSuvpoVNxMO+4zs5v+0gQmNpXxiTgc79lyt BQdcUhB+JxT++HOywEVMuNxAPjX7hGVNM6EUBTtRLPxGkaMKlOloZV/uuwlnm36JuLxi wP3UNB0bVAPz/kAwWcEyKraLLiRzbmNhJV2SEGfjx9skew2zQyseVVdKaNyznyER+lvz /woQ== 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:from:references:to:subject; bh=XPxzH7WinmGBIeFmzxWO4Y3n+dMp8RMGk9cgHABNfcY=; b=BktHB8HuiiYVWtBXfgN/MGoR2la2J5kS9G+jroUhtiZLUnV/lMYYGzZX7PcgqoloyS eOqa07+7ksFFKIPo9pEzEEzOUBVf4iy+NxqZuln/AWA90x3ALil4W76S+f4CMroUbrCL P5iapvINR0xEZTv9Vvhav6LJT8/DZejAmb3CGPP94L1Vy0e3O+Z/KaY7vDMjxVnhXE2g bHt+M+ra/L7ETDrRvPZXypOTo/bEzVBWsQtOSKlLyUd8Q5WKec86LjAXkyhXlpkq909L QeP2w/IBJZcZL3zgqSM/AwnQOYKMVqGi+0spxbG/oZrYimIqmDiOzVvcTVonyd2RQ7Pu xp2Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Return-Path: Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id x2si511098wrv.1.2019.11.09.00.51.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Nov 2019 00:51:40 -0800 (PST) Received-SPF: pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id xA98pdZv030377 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 9 Nov 2019 09:51:39 +0100 Received: from [167.87.0.176] ([167.87.0.176]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id xA98pcVE027140; Sat, 9 Nov 2019 09:51:39 +0100 Subject: Re: [PATCH L-C v2 7/7] linux-custom: rewrite to no longer depend on the kernel's builddeb To: Cedric Hombourger , isar-users@googlegroups.com References: <1572962145-318-1-git-send-email-Cedric_Hombourger@mentor.com> <1573118604-909-1-git-send-email-Cedric_Hombourger@mentor.com> <1573118604-909-8-git-send-email-Cedric_Hombourger@mentor.com> From: Jan Kiszka Message-ID: Date: Sat, 9 Nov 2019 09:51:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <1573118604-909-8-git-send-email-Cedric_Hombourger@mentor.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-TUID: JOAZobPCMG2v On 07.11.19 10:23, Cedric Hombourger wrote: > Regain control over the packaging of the Linux kernel by providing our > own debian recipes (debian,{control,rules} files and friends) instead > of using the kernel's builddeb script. This will allow generation of > packages for "perf" (not included in this changeset) with per distro > scheme (Debian and Ubuntu have differences) and maintain compatibility > with upstream packages generated from different source packages but > dependent on a certain deployment scheme (e.g. linux-base for Debian) > > Signed-off-by: Cedric Hombourger > --- > doc/custom_kernel.md | 181 ++++++++++++++++ > .../linux/files/build-kernel.sh | 128 ----------- > meta/recipes-kernel/linux/files/debian/compat | 1 + > .../linux/files/debian/control.tmpl | 37 ++++ > .../linux/files/debian/isar/build.tmpl | 36 ++++ > .../linux/files/debian/isar/clean.tmpl | 20 ++ > .../linux/files/debian/isar/common.tmpl | 48 +++++ > .../linux/files/debian/isar/install.tmpl | 204 ++++++++++++++++++ > .../files/debian/linux-image.postinst.tmpl | 29 +++ > .../files/debian/linux-image.postrm.tmpl | 35 +++ > .../files/debian/linux-image.preinst.tmpl | 25 +++ > .../linux/files/debian/linux-image.prerm.tmpl | 21 ++ > .../linux/files/debian/rules.tmpl | 41 ++++ > meta/recipes-kernel/linux/linux-custom.inc | 179 ++++++++++----- > 14 files changed, 800 insertions(+), 185 deletions(-) > create mode 100644 doc/custom_kernel.md > delete mode 100644 meta/recipes-kernel/linux/files/build-kernel.sh > create mode 100644 meta/recipes-kernel/linux/files/debian/compat > create mode 100644 meta/recipes-kernel/linux/files/debian/control.tmpl > create mode 100644 meta/recipes-kernel/linux/files/debian/isar/build.tmpl > create mode 100644 meta/recipes-kernel/linux/files/debian/isar/clean.tmpl > create mode 100644 meta/recipes-kernel/linux/files/debian/isar/common.tmpl > create mode 100644 meta/recipes-kernel/linux/files/debian/isar/install.tmpl > create mode 100644 meta/recipes-kernel/linux/files/debian/linux-image.postinst.tmpl > create mode 100644 meta/recipes-kernel/linux/files/debian/linux-image.postrm.tmpl > create mode 100644 meta/recipes-kernel/linux/files/debian/linux-image.preinst.tmpl > create mode 100644 meta/recipes-kernel/linux/files/debian/linux-image.prerm.tmpl > create mode 100755 meta/recipes-kernel/linux/files/debian/rules.tmpl > > diff --git a/doc/custom_kernel.md b/doc/custom_kernel.md > new file mode 100644 > index 0000000..934325a > --- /dev/null > +++ b/doc/custom_kernel.md > @@ -0,0 +1,181 @@ > +# Custom kernel recipe for Isar > + > +## Contents > + > + - [Summary](#summary) > + - [Proposal owners](#proposal-owners) > + - [Current status](#current-status) > + - [Detailed description](#detailed-description) > + - [Benefit to Isar](#benefit-to-isar) > + - [How can I help?](#how-can-i-help) > + - [Scope](#scope) > + - [How to test](#how-to-test) > + - [Dependencies](#dependencies) > + - [Documentation](#documentation) > + - [Questions and answers](#questions-and-answers) > + > +## Summary > + > +Isar currently uses the Linux kernel's builddeb script to generate linux-image, > +linux-headers and linux-libc-dev packages for your custom kernel sources. The > +main benefit of this approach was that the low level details of how to package > +the Linux kernel image, modules and headers were left in the kernel. There are > +however some drawbacks: Isar had to repack generated packages to introduce some > +of the changes it needs such as suffixing the kernel packages with the name of > +the custom kernel (e.g. with "mainline" for the "linux-mainline" recipe), lack > +of automatic dependencies (the builddeb script from the kernel does not use > +debhelper), it was difficult to add packages especially distribution specific > +packages (maintain version specific patch in Isar vs being able to upstream > +distribution specific changes upstream), etc. This change is about being less > +dependent on the kernel packaging scripts (which aren't used by major distros > +anyway) and regain control on how we want or need the Linux kernel packaged. > + > +## Proposal owners > + > + * name: [Cedric Hombourger](https://github.com/chombourger) > + > +## Current status > + > +### Tests > + > +The following were recently checked: > + > + * Custom kernels in meta-isar build without (known) failures > + * initrd image gets generated when the kernel is added to the rootfs > + * `ISAR_CROSS_COMPILE` is supported > + * `KERNEL_FILE` is honored > + * `KERNEL_DEFCONFIG` may either be a file (specified via `SRC_URI`) or a > + kernel-provided defconfig > + * Config fragments get merged with the user-specified kernel configuration > + * Path to installed DTBs may be configured (new) > + * Configuration and build from a `devshell` > + * Support for the `KERNEL_LIBC_DEV_DEPLOY` directive > + > +while the following needs work: > + > + * Check if custom-kernel builds are reproducible > + > +### Remaining work items > + > + * Check if there is a better way to cross compile kernel "scripts" such as > + `fixdep` or `modpost` than manually compiling them (they are compiled for > + the build machine (amd64) and not for the target (e.g. armhf) even though > + we are cross-compiling - yet the linux-headers package should be shipping > + "scripts" for the target machine) > + > +## Detailed description > + > +### Requirements > + > +#### Current > + > +Isar has had a `linux-custom` recipe for a long time and counts many users. It is therefore > +paramount to maintain features that it has today with no or little changes to the APIs. The > +following requirements were identified and will be maintained: > + > + 1. Sources to the custom Linux kernel may be specified via `SRC_URI` > + > + 2. Configure the kernel via an in-tree or an external `defconfig` via `KERNEL_DEFCONFIG` > + > + 3. Support kernel configuration tweaks via configuration fragments (`.cfg` files) > + > + 4. Patches to the linux kernel may be specified via `SRC_URI` > + > + 5. Ensure that the Isar recipe `PV` matches the kernel release identifier (`KERNEL_RELEASE`) > + > + 6. Produce a `linux-image` package that ships the kernel image and modules > + > + 7. Allow the name of the kernel image to be changed via `KERNEL_FILE` (defaults to `vmlinuz`) > + > + 8. Produce a `linux-headers` package which includes kernel headers and kbuild scripts/tools > + > + 9. The `linux-headers` package shall support native and cross compiles of out-of-tree kernel modules > + > + 10. Produce a `linux-libc-dev` package to support user-land builds > + > + 11. Only ship the `linux-libc-dev` package if instructed to (`KERNEL_LIBC_DEV_DEPLOY` equals to `"1"`) > + > + 12. Support both native and cross compiles (`ISAR_CROSS_COMPILE`) > + > + 13. Support for the following kernel architectures: > + > + * arm > + * arm64 > + * mips > + * x86 > + > + 14. Support `devshell` (kernel configuration shall be applied) > + > +#### New requirements (proposed) > + > +This proposal includes the following new requirements: > + > + 1. Support creation of additional packages > + > + 2. Allow per-distro packaging tweaks > + > +### Approach > + > +The new implementation will have the `builddeb` code ported from the Linux kernel included to the > +Isar environment. It will be refactor to support pre and post hooks. Hooks may be used by external > +layers to extend the kernel packaging instructions provided by "stock" Isar or by Isar itself to > +implement distro-specific packages or tweaks. > + > +Hooks need the ability to add `build` and `install` steps which can be achieved by having the main > +`build` and `install` steps call pre and post scripts. This will however solve only one side of the > +problem: new packages should be declared in the `debian/control` file. The packaging process > +(initiated by `debian/rules`) will use a baseline `control` file when started and a mechanism will > +be provided for hooks to append `control` blocks as they are processed. > + > +### Future work > + > +In the event where this proposal is accepted, here are a few future projects that are being > +considered: > + > + 1. Package `perf` as Debian does > + > + 2. Add `ubuntu` as an Isar supported target distro and validate `linux-custom` recipe > + > +## Benefit to Isar > + > + * Control the kernel build and packaging process > + > + * No longer need to repack packages > + > + * Provide hooks for custom kernel recipes to add build/install directives > + > +## How can I help? > + > + * Check if you are able to build your own linux-custom recipes with this change > + * Check if packages generated by this recipe are compatible with your Debian-based distro > + * Review and provide comments on this changeset > + * Create templates for distro-specific packages (e.g. perf) > + > +## Scope > + > + * Proposal owners: proposal owners are to communicate the idea to isar-users and make sure > + that all of their requirements are met (to the extent they are already supported with the > + current solution) or may be met in the future. > + > + * Other developers: port your out-of-tree linux-custom recipes to this new solution and > + report issues. > + > +## How to test? > + > +The linux-mainline recipe may be used for some basic testing. This recipe is being used by the > +following machines: > + > + * de0-nano-soc > + * qemumipsel > + > +## Dependencies > + > + * None > + > +## Documentation > + > + * Document user-visible variables added by this proposal > + > +## Questions and answers > + > + * None > diff --git a/meta/recipes-kernel/linux/files/build-kernel.sh b/meta/recipes-kernel/linux/files/build-kernel.sh > deleted file mode 100644 > index f56e96c..0000000 > --- a/meta/recipes-kernel/linux/files/build-kernel.sh > +++ /dev/null > @@ -1,128 +0,0 @@ > -#!/bin/bash > -# > -# Custom kernel build > -# > -# This software is a part of ISAR. > -# Copyright (c) Siemens AG, 2018 > -# > -# SPDX-License-Identifier: MIT > - > -source /isar/common.sh > - > -host_arch=$(dpkg --print-architecture) > - > -if [ "$host_arch" != "$target_arch" ]; then > - case $target_arch in > - armhf) > - export ARCH=arm > - export CROSS_COMPILE="arm-linux-gnueabihf-" > - ;; > - arm64) > - export ARCH=arm64 > - export CROSS_COMPILE="aarch64-linux-gnu-" > - ;; > - mipsel) > - export ARCH=mips > - export CROSS_COMPILE="mipsel-linux-gnu-" > - ;; > - *) > - echo "error: unsupported architecture ($target_arch)" > - exit 1 > - ;; > - esac > -fi > - > -REPACK_DIR="$1/../repack" > -REPACK_LINUX_IMAGE_DIR="${REPACK_DIR}/linux-image" > -REPACK_LINUX_HEADERS_DIR="${REPACK_DIR}/linux-headers" > - > -make ${KERNEL_CONFIG_TARGET} || exit ${?} > -if [ -n "${KERNEL_FRAGMENTS}" ]; then > - scripts/kconfig/merge_config.sh -m .config ${KERNEL_FRAGMENTS} > -fi > - > -KV=$( make -s kernelrelease ) > -if [ "${KV}" != "${PV}" ]; then > - echo "ERROR: Recipe PV is \"${PV}\" but should be \"${KV}\"" 1>&2 > - echo "ERROR: Probably due to CONFIG_LOCALVERSION" 1>&2 > - exit 1 > -fi > - > -rm -f .version > -KBUILD_DEBARCH=$target_arch 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}" > - > -cp -a debian "${REPACK_DIR}" > - > -# dpkg-gencontrol performs cross-incompatible checks on the > -# Architecture field; trick it to accept the control file > -sed -i "s/Architecture: .*/Architecture: any/" "${REPACK_DIR}/debian/control" > - > -cd .. > - > -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}" \ > - -DArchitecture=$target_arch > - > -# Add Debian-like link installation to postinst > -mkdir -p ${REPACK_LINUX_IMAGE_DIR}/lib/modules/${PV} > -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/${KERNEL_FILE}-${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/${KERNEL_FILE}-${PV}\\ > -fi" > - > -# Make sure arm64 kernels are decompressed > -if [ "$target_arch" = "arm64" ]; then > - kernel_file="${REPACK_LINUX_IMAGE_DIR}/boot/${KERNEL_FILE}-${PV}" > - mv "${kernel_file}" "${kernel_file}.gz" > - gunzip "${kernel_file}.gz" > -fi Next regression: This got lost. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux