From 0d2952d9e0e39d20e9ed105f4d91da3a3d426722 Mon Sep 17 00:00:00 2001 From: Samuel Dolt Date: Thu, 24 Aug 2023 15:40:34 +0200 Subject: [PATCH] nwl-image.bbclass: add fitimage generation support --- .../classes/nwl-image-fitimage.bbclass | 85 +++++++++++++++++++ .../recipes-core/images/nwl-fitimage.bb | 47 ---------- .../images/nwl-ramdisk-minimal.bb | 9 +- 3 files changed, 90 insertions(+), 51 deletions(-) create mode 100644 layers/meta-nwl-distro/classes/nwl-image-fitimage.bbclass delete mode 100644 layers/meta-nwl-distro/recipes-core/images/nwl-fitimage.bb diff --git a/layers/meta-nwl-distro/classes/nwl-image-fitimage.bbclass b/layers/meta-nwl-distro/classes/nwl-image-fitimage.bbclass new file mode 100644 index 0000000..c11099d --- /dev/null +++ b/layers/meta-nwl-distro/classes/nwl-image-fitimage.bbclass @@ -0,0 +1,85 @@ +# This class generate a fitimage +# This class should ihnerited after the nwl-image class + +# Configuration: +# ============================================================================== + +# Set the initramfs to the current image being build by default +# This can be overriden if another image as to be included +INITRAMFS_IMAGE ??= "${IMAGE_BASENAME}" +INITRAMFS_IMAGE_NAME ??= "${INITRAMFS_IMAGE}-${MACHINE}" + +# Glue for kernel-fitimage +# ============================================================================== + +kernel_do_deploy () { + # The kernel-fitimage class appends the deployment to this task. We just have to provide the task. + deployDir=${DEPLOY_DIR_IMAGE} +} + +inherit kernel-fitimage +inherit kernel-arch + +do_assemble_fitimage:prepend() { + install -d ${S}/arch/${ARCH}/boot/ + install -m 0644 ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${KERNEL_IMAGE_LINK_NAME}${KERNEL_IMAGE_BIN_EXT} ${S}/arch/${ARCH}/boot/vmlinuz.bin + + for DTB in ${KERNEL_DEVICETREE}; do + # We have to watch out for when the device-tree is located in its own subdirectory in the kernel sources. + # DTB_SUBDIR will contain this directory. + DTB_DEPLOY=`basename ${DTB}` + DTB_SUBDIR=`dirname ${DTB}` + install -d arch/${ARCH}/boot/${DTB_SUBDIR} + install -m 0644 ${DEPLOY_DIR_IMAGE}/${DTB_DEPLOY} ${S}/arch/${ARCH}/boot/${DTB} + done +} + +KERNEL_CLASSES = "kernel-fitimage" +KERNEL_IMAGETYPES += "fitImage" + +# We want the initramfs inside the fitimage as a separate part and not bundle +# inside the kernel part +INITRAMFS_IMAGE_BUNDLE = "0" + + +do_image_fitimage() { + kernel_do_deploy +} + + +addtask image_fitimage after do_image before do_image_complete +addtask assemble_fitimage_initramfs after do_image before do_image_fitimage +addtask assemble_fitimage after do_image before do_image_fitimage + +do_assemble_fitimage_initramfs[depends] += "virtual/kernel:do_deploy virtual/${TARGET_PREFIX}binutils:do_populate_sysroot" +do_assemble_fitimage[depends] += "virtual/kernel:do_deploy virtual/${TARGET_PREFIX}binutils:do_populate_sysroot" + + +# a fitimage image can be embedded into a WIC image +do_image_wic[recrdeptask] += "do_image_fitimage" + +python __anonymous () { + initramfs = d.getVar('INITRAMFS_IMAGE') + image = d.getVar('IMAGE_BASENAME') + + if image == initramfs: + + # If the initramfs is the same as the image being build, we should + # not depend on do_image_complete but on do_image_${FSTYPE_WITHOUT_EXT} + fstype = d.getVar('IMAGE_FSTYPES').split('.')[0] + d.appendVarFlag('do_assemble_fitimage_initramfs', 'recrdeptask', f' do_image_{fstype}') + depends = d.getVarFlag('do_assemble_fitimage_initramfs', 'depends') + depends = depends.replace(f'{initramfs}:do_image_complete', '') + d.setVarFlag('do_assemble_fitimage_initramfs', 'depends', depends) + + + # If the initramfs is the same as the image being build, it should + # come from IMGDEPLOYDIR instead of DEPLOY_DIR_IMAGE + # This is done by using an ugly monkey patching of the + # fitimage_assemble function + imgdeploydir = d.getVar('IMGDEPLOYDIR') + deploy_dir_image = d.getVar('DEPLOY_DIR_IMAGE') + task = d.getVar('fitimage_assemble') + task = task.replace(f'initramfs_path="{deploy_dir_image}', f'initramfs_path="{imgdeploydir}') + d.setVar('fitimage_assemble', task) +} diff --git a/layers/meta-nwl-distro/recipes-core/images/nwl-fitimage.bb b/layers/meta-nwl-distro/recipes-core/images/nwl-fitimage.bb deleted file mode 100644 index 27b2e85..0000000 --- a/layers/meta-nwl-distro/recipes-core/images/nwl-fitimage.bb +++ /dev/null @@ -1,47 +0,0 @@ -SUMMARY = "Create a fitimage with included kernel, dtb and ramdisk" -MAINTAINER = "Lucien Müller " -LICENSE = "CLOSED" - -inherit kernel-fitimage -inherit kernel-arch -inherit deploy - - -PACKAGE_ARCH = "${MACHINE_ARCH}" - -KERNEL_CLASSES = "kernel-fitimage" -KERNEL_IMAGETYPES += "fitImage" - -addtask assemble_fitimage_initramfs before do_install after do_compile -addtask do_deploy after assemble_fitimage_initramfs - -do_configure[depends] += "virtual/kernel:do_deploy" -do_bundle_initramfs[depends] += "${INITRAMFS_IMAGE}:do_image_complete" -do_deploy[depends] += "${PN}:do_assemble_fitimage" - -INITRAMFS_IMAGE = "nwl-ramdisk-minimal" -INITRAMFS_IMAGE_NAME = "${INITRAMFS_IMAGE}-${MACHINE}" -INITRAMFS_IMAGE_BUNDLE = "0" - -do_configure:prepend () { - install -d ${S}/arch/${ARCH}/boot/ - for DTB in ${KERNEL_DEVICETREE}; do - # We have to watch out for when the device-tree is located in its own subdirectory in the kernel sources. - # DTB_SUBDIR will contain this directory. - DTB_DEPLOY=`basename ${DTB}` - DTB_SUBDIR=`dirname ${DTB}` - install -d arch/${ARCH}/boot/${DTB_SUBDIR} - install -m 0644 ${DEPLOY_DIR_IMAGE}/${DTB_DEPLOY} arch/${ARCH}/boot/${DTB} - done - install -m 0644 ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${KERNEL_IMAGE_LINK_NAME}.bin arch/${ARCH}/boot/vmlinuz.bin -} - -kernel_do_deploy () { - # The kernel-fitimage class appends the deployment to this task. We just have to provide the task. -} - -do_deploy () { - deployDir=${DEPLOY_DIR_IMAGE} - kernel_do_deploy -} - diff --git a/layers/meta-nwl-distro/recipes-core/images/nwl-ramdisk-minimal.bb b/layers/meta-nwl-distro/recipes-core/images/nwl-ramdisk-minimal.bb index bbc20e6..c3c72f1 100644 --- a/layers/meta-nwl-distro/recipes-core/images/nwl-ramdisk-minimal.bb +++ b/layers/meta-nwl-distro/recipes-core/images/nwl-ramdisk-minimal.bb @@ -1,17 +1,18 @@ SUMMARY = "A minimal ramdisk image." MAINTAINER = "Lucien Müller " +COREOS_IMAGE_GENERATE_INSTALLER = "0" +COREOS_IMAGE_GENERATE_UKI = "0" +COREOS_IMAGE_GENERATE_SWU = "0" + inherit nwl-image +inherit nwl-image-fitimage IMAGE_FSTYPES = "cpio.xz" # Keep only the minimum packages NO_RECOMMENDATIONS = "1" -COREOS_IMAGE_GENERATE_INSTALLER = "0" -COREOS_IMAGE_GENERATE_UKI = "0" -COREOS_IMAGE_GENERATE_SWU = "0" - IMAGE_INSTALL:append = " \ coreutils \ ncurses-terminfo-base \