public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Alexander Smirnov <asmirnov@ilbers.de>
To: Jan Kiszka <jan.kiszka@siemens.com>,
	isar-users <isar-users@googlegroups.com>
Subject: Re: [PATCH v4 5/8] Provide class for easy custom kernel builds
Date: Mon, 12 Feb 2018 21:56:16 +0300	[thread overview]
Message-ID: <c397effe-33fb-7697-ea53-816be1123350@ilbers.de> (raw)
In-Reply-To: <10f71292d5c06de6909594c891f2478334106135.1518362719.git.jan.kiszka@siemens.com>

On 02/11/2018 06:25 PM, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> With this class, it becomes almost trivial to replace the distro kernel
> with a custom build. You just need to inherit linux-kernel, specify the
> source URI, define via S where the source is unpacked to and provide a
> defconfig. To switch to a custom kernel recipe,
> PREFERRED_PROVIDER_virtual/kernel has to be adjusted in local.conf or
> the distro conf.
> 
> 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 replacement of their distro packages. 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>
> ---
>   meta/classes/linux-kernel.bbclass | 98 +++++++++++++++++++++++++++++++++++++++
>   1 file changed, 98 insertions(+)
>   create mode 100644 meta/classes/linux-kernel.bbclass
> 
> diff --git a/meta/classes/linux-kernel.bbclass b/meta/classes/linux-kernel.bbclass
> new file mode 100644
> index 0000000..5f4df3f
> --- /dev/null
> +++ b/meta/classes/linux-kernel.bbclass
> @@ -0,0 +1,98 @@
> +# Custom kernel build
> +#
> +# This software is a part of ISAR.
> +# Copyright (c) Siemens AG, 2018
> +#
> +# SPDX-License-Identifier: MIT
> +
> +DESCRIPTION ?= "Custom kernel"
> +PROVIDES = "virtual/kernel"
> +
> +inherit dpkg-base
> +
> +KERNEL_DEBIAN_DEPENDS ?= "initramfs-tools | linux-initramfs-tool, kmod, linux-base (>= 4.3~)"
> +KERNEL_HEADERS_DEBIAN_DEPENDS ?= "libc6, libssl1.1, gcc"
> +KBUILD_DEPENDS ?= "libssl-dev libelf-dev bc"
> +
> +REPACK_DIR = "${PP}/repack"
> +REPACK_LINUX_IMAGE_DIR = "${REPACK_DIR}/linux-image"
> +REPACK_LINUX_HEADERS_DIR = "${REPACK_DIR}/linux-headers"
> +
> +dpkg_runbuild() {
> +	E="${@ bb.utils.export_proxies(d)}"
> +	sudo -E chroot ${BUILDCHROOT_DIR} sh -c '
> +		set -e
> +
> +		apt-get install -y -o Debug::pkgProblemResolver=yes \
> +			--no-install-recommends ${KBUILD_DEPENDS}
> +
> +		cd ${PP}/${S}
> +		cp ../defconfig .config
> +		make olddefconfig
> +
> +		make -j ${@bb.utils.cpu_count() * 2} deb-pkg
> +
> +		rm -rf ${REPACK_DIR}
> +		mkdir -p ${REPACK_DIR}
> +		mkdir -p ${REPACK_LINUX_IMAGE_DIR}
> +		mkdir -p ${REPACK_LINUX_HEADERS_DIR}
> +
> +		cd ${PP}
> +		tar xzf linux-${PV}_${PV}-1.debian.tar.gz -C ${REPACK_DIR}
> +		dpkg-deb -R linux-image-${PV}_${PV}-1_${KERNEL_ARCH}.deb \
> +			${REPACK_LINUX_IMAGE_DIR}
> +		dpkg-deb -R linux-headers-${PV}_${PV}-1_${KERNEL_ARCH}.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_ARCH}" \
> +			-DSection=kernel \
> +			-DPriority=required \
> +			-DProvides="${PN}" \
> +			-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_ARCH}" \
> +			-DPackage="linux-headers-${KERNEL_ARCH}" \
> +			-DSection=kernel \
> +			-DDepends="${KERNEL_HEADERS_DEBIAN_DEPENDS}"
> +
> +		dpkg-deb -b ${REPACK_LINUX_IMAGE_DIR} \
> +			linux-image-${KERNEL_ARCH}_${PV}-1_${KERNEL_ARCH}.deb
> +		rm -f linux-image-${PV}_${PV}-1_${KERNEL_ARCH}.deb
> +		dpkg-deb -b ${REPACK_LINUX_HEADERS_DIR} \
> +			linux-headers-${KERNEL_ARCH}_${PV}-1_${KERNEL_ARCH}.deb
> +		rm -f linux-headers-${PV}_${PV}-1_${KERNEL_ARCH}.deb
> +	'
> +}
> 

What is the benefit of having this script in the class? I see that we 
have separate files for:

  - buildchroot
  - kernel modules

Why this chroot script should be a part of bitbake class? This makes 
debugging much more complicated, because I have no possibility to run 
this script manually from buildchroot (like I could do with build.sh)

Also formatting style looks nasty here.

Alex

  reply	other threads:[~2018-02-12 18:56 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-11 15:25 [PATCH v4 0/8] Provide infrastructure and examples for custom kernels and modules Jan Kiszka
2018-02-11 15:25 ` [PATCH v4 1/8] Forward proxy settings to dpkg build Jan Kiszka
2018-02-11 15:25 ` [PATCH v4 2/8] Prioritize isar-apt repo over all others Jan Kiszka
2018-02-12  9:33   ` Alexander Smirnov
2018-02-12  9:41     ` Jan Kiszka
2018-02-12 10:08       ` Alexander Smirnov
2018-02-12 10:11         ` Jan Kiszka
2018-02-12 10:27           ` Jan Kiszka
2018-02-12 13:09             ` Alexander Smirnov
2018-02-12 13:45               ` Jan Kiszka
2018-02-12 16:31                 ` Alexander Smirnov
2018-02-12 17:00                   ` Jan Kiszka
2018-02-12 17:27                     ` Jan Kiszka
2018-02-12 18:51                     ` Alexander Smirnov
2018-02-13  7:22                       ` Jan Kiszka
2018-02-13  8:09                         ` Alexander Smirnov
2018-02-13  8:22                           ` Jan Kiszka
2018-02-13  8:45                             ` Alexander Smirnov
2018-02-13  8:51                               ` Jan Kiszka
2018-02-11 15:25 ` [PATCH v4 3/8] Replace SRC_DIR with S Jan Kiszka
2018-02-11 15:25 ` [PATCH v4 4/8] Install kernel via replaceable recipe Jan Kiszka
2018-02-11 15:25 ` [PATCH v4 5/8] Provide class for easy custom kernel builds Jan Kiszka
2018-02-12 18:56   ` Alexander Smirnov [this message]
2018-02-13  7:03     ` Jan Kiszka
2018-02-13  8:19       ` Alexander Smirnov
2018-02-13  8:24         ` Jan Kiszka
2018-02-13  9:53       ` Henning Schild
2018-02-13 10:21         ` Jan Kiszka
2018-02-11 15:25 ` [PATCH v4 6/8] Add custom kernel examples Jan Kiszka
2018-02-12 19:02   ` Alexander Smirnov
2018-02-13  7:03     ` Jan Kiszka
2018-02-13  8:16       ` Alexander Smirnov
2018-02-13  8:24         ` Jan Kiszka
2018-02-11 15:25 ` [PATCH v4 7/8] Provide include file for easy custom module builds Jan Kiszka
2018-02-11 15:25 ` [PATCH v4 8/8] Add exemplary kernel module Jan Kiszka
2018-02-13  9:41 ` [PATCH v4 0/8] Provide infrastructure and examples for custom kernels and modules 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=c397effe-33fb-7697-ea53-816be1123350@ilbers.de \
    --to=asmirnov@ilbers.de \
    --cc=isar-users@googlegroups.com \
    --cc=jan.kiszka@siemens.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