diff options
author | Mike Crowe <mac@mcrowe.com> | 2021-10-07 14:17:57 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-12-09 13:49:51 +0000 |
commit | 37b0f34817928a6a0ac31f8dc12cb9debe2ff920 (patch) | |
tree | 0f34c05b449626e9f32aff6589d491453b409eab /meta/classes/kernel.bbclass | |
parent | f8474be059bb02dcb46a425c0a1842ff2d4d2c8d (diff) | |
download | poky-37b0f34817928a6a0ac31f8dc12cb9debe2ff920.tar.gz |
kernel: improve transformation from KERNEL_IMAGETYPE_FOR_MAKE
In 526bdd88ccd758204452579333ba188e29270bde the imageType loop in
kernel_do_deploy was changed to use KERNEL_IMAGETYPE_FOR_MAKE rather
than KERNEL_IMAGETYPES. This broke the special handling for fitImage
immediately below because KERNEL_IMAGETYPE_FOR_MAKE never contains
fitImage.
It has always been my understanding that KERNEL_IMAGETYPE_FOR_MAKE
controlled what was passed to make, but KERNEL_IMAGETYPE controlled what
was installed/deployed. When the two are different then it's the
responsibility of whoever set KERNEL_IMAGETYPE_FOR_MAKE to ensure that
whatever comes out of the kernel build system has been transformed in to
the requested form by the time of installation. This is what happens for
kernel.bbclass's own support for vmlinux.gz.
I think this means that for KERNEL_IMAGETYPE vmlinux.gz, kernel.bbclass
is responsible for generating vmlinux.gz.initramfs[1] so that
kernel_do_deploy can deploy it. This means that the change in
526bdd88ccd758204452579333ba188e29270bde can be reverted, fixing
KERNEL_IMAGETYPE = "fitImage".
In addition, it ought to be possible for recipes and other classes that
use kernel.bbclass to hook into this mechanism by setting
KERNEL_IMAGETYPE_FOR_MAKE and performing their own transformations.
do_bundle_initramfs calls kernel_do_compile and we don't want it to
transform vmlinux to vmlinux.gz at that point, since it will fight
against the careful renaming and preserving that do_bundle_initramfs
does. Let's separate the transformation out of kernel_do_compile to a
new do_transform_kernel task that can be run at the right time. This
means that it's also logical to perform the equivalent translation for
the kernel with the initramfs in a separate
do_transform_bundled_initramfs task too.
This leaves two clear customisation points for recipes and other classes
to hook into the process and perform their transformations:
do_transform_kernel and do_transform_bundled_initramfs.
(I care about this because our recipes that use kernel.bbclass also set
KERNEL_IMAGETYPE_FOR_MAKE and transform vmlinux into a form suitable for
our bootloader after do_compile and do_bundle_initramfs into the format
matching KERNEL_IMAGETYPE. I'm unable to successfully bundle an
initramfs after 526bdd88ccd758204452579333ba188e29270bde, but I didn't
want to just revert that change to reintroduce the bug that it was
fixing.)
I can't say that I'm entirely happy with this change, but I'm unsure
what to do to improve it. I find the way that both the bare kernel and
the one with the initramfs both get deployed to be confusing, and a
waste of build time. I would like to not actually generate a publishable
kernel image at all during do_compile when an initramfs is in use, but I
suspect that this would affect valid use cases that I'm not aware of.
(From OE-Core rev: 10a4a132e87e835726bf5da81a60f6f509b90765)
Signed-off-by: Mike Crowe <mac@mcrowe.com>
[1] It could be argued that this should be vmlinux.initramfs.gz, but
that would require another special case in kernel_do_deploy and the
filename is only visible within this class and the recipes that use it
anyway.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/kernel.bbclass')
-rw-r--r-- | meta/classes/kernel.bbclass | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass index 2d219cb5e5..0df24ac910 100644 --- a/meta/classes/kernel.bbclass +++ b/meta/classes/kernel.bbclass | |||
@@ -77,7 +77,7 @@ python __anonymous () { | |||
77 | # KERNEL_IMAGETYPES may contain a mixture of image types supported directly | 77 | # KERNEL_IMAGETYPES may contain a mixture of image types supported directly |
78 | # by the kernel build system and types which are created by post-processing | 78 | # by the kernel build system and types which are created by post-processing |
79 | # the output of the kernel build system (e.g. compressing vmlinux -> | 79 | # the output of the kernel build system (e.g. compressing vmlinux -> |
80 | # vmlinux.gz in kernel_do_compile()). | 80 | # vmlinux.gz in kernel_do_transform_kernel()). |
81 | # KERNEL_IMAGETYPE_FOR_MAKE should contain only image types supported | 81 | # KERNEL_IMAGETYPE_FOR_MAKE should contain only image types supported |
82 | # directly by the kernel build system. | 82 | # directly by the kernel build system. |
83 | if not d.getVar('KERNEL_IMAGETYPE_FOR_MAKE'): | 83 | if not d.getVar('KERNEL_IMAGETYPE_FOR_MAKE'): |
@@ -134,6 +134,8 @@ set -e | |||
134 | # standalone for use by wic and other tools. | 134 | # standalone for use by wic and other tools. |
135 | if image: | 135 | if image: |
136 | d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') | 136 | d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') |
137 | if image and bb.utils.to_boolean(d.getVar('INITRAMFS_IMAGE_BUNDLE')): | ||
138 | bb.build.addtask('do_transform_bundled_initramfs', 'do_deploy', 'do_bundle_initramfs', d) | ||
137 | 139 | ||
138 | # NOTE: setting INITRAMFS_TASK is for backward compatibility | 140 | # NOTE: setting INITRAMFS_TASK is for backward compatibility |
139 | # The preferred method is to set INITRAMFS_IMAGE, because | 141 | # The preferred method is to set INITRAMFS_IMAGE, because |
@@ -316,6 +318,14 @@ do_bundle_initramfs () { | |||
316 | } | 318 | } |
317 | do_bundle_initramfs[dirs] = "${B}" | 319 | do_bundle_initramfs[dirs] = "${B}" |
318 | 320 | ||
321 | kernel_do_transform_bundled_initramfs() { | ||
322 | # vmlinux.gz is not built by kernel | ||
323 | if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then | ||
324 | gzip -9cn < ${KERNEL_OUTPUT_DIR}/vmlinux.initramfs > ${KERNEL_OUTPUT_DIR}/vmlinux.gz.initramfs | ||
325 | fi | ||
326 | } | ||
327 | do_transform_bundled_initramfs[dirs] = "${B}" | ||
328 | |||
319 | python do_devshell:prepend () { | 329 | python do_devshell:prepend () { |
320 | os.environ["LDFLAGS"] = '' | 330 | os.environ["LDFLAGS"] = '' |
321 | } | 331 | } |
@@ -364,12 +374,17 @@ kernel_do_compile() { | |||
364 | for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do | 374 | for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do |
365 | oe_runmake ${typeformake} CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd | 375 | oe_runmake ${typeformake} CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd |
366 | done | 376 | done |
377 | } | ||
378 | |||
379 | kernel_do_transform_kernel() { | ||
367 | # vmlinux.gz is not built by kernel | 380 | # vmlinux.gz is not built by kernel |
368 | if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then | 381 | if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then |
369 | mkdir -p "${KERNEL_OUTPUT_DIR}" | 382 | mkdir -p "${KERNEL_OUTPUT_DIR}" |
370 | gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz" | 383 | gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz" |
371 | fi | 384 | fi |
372 | } | 385 | } |
386 | do_transform_kernel[dirs] = "${B}" | ||
387 | addtask transform_kernel after do_compile before do_install | ||
373 | 388 | ||
374 | do_compile_kernelmodules() { | 389 | do_compile_kernelmodules() { |
375 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE | 390 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
@@ -621,7 +636,7 @@ inherit cml1 | |||
621 | 636 | ||
622 | KCONFIG_CONFIG_COMMAND:append = " LD='${KERNEL_LD}' HOSTLDFLAGS='${BUILD_LDFLAGS}'" | 637 | KCONFIG_CONFIG_COMMAND:append = " LD='${KERNEL_LD}' HOSTLDFLAGS='${BUILD_LDFLAGS}'" |
623 | 638 | ||
624 | EXPORT_FUNCTIONS do_compile do_install do_configure | 639 | EXPORT_FUNCTIONS do_compile do_transform_kernel do_transform_bundled_initramfs do_install do_configure |
625 | 640 | ||
626 | # kernel-base becomes kernel-${KERNEL_VERSION} | 641 | # kernel-base becomes kernel-${KERNEL_VERSION} |
627 | # kernel-image becomes kernel-image-${KERNEL_VERSION} | 642 | # kernel-image becomes kernel-image-${KERNEL_VERSION} |
@@ -772,7 +787,7 @@ kernel_do_deploy() { | |||
772 | fi | 787 | fi |
773 | 788 | ||
774 | if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then | 789 | if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then |
775 | for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do | 790 | for imageType in ${KERNEL_IMAGETYPES} ; do |
776 | if [ "$imageType" = "fitImage" ] ; then | 791 | if [ "$imageType" = "fitImage" ] ; then |
777 | continue | 792 | continue |
778 | fi | 793 | fi |