Skip to contentSkip to conversation

Add support for bootconfig on initramfs and FIT images

RFC PATCH Superseded Francesco Valla 2 participants 7 messages Mar 18 – Mar 20

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for bootconfig on initramfs and FIT images

Hello,

this patchset introduces support for attaching a bootconfig block both to plain initramfs images and inside FIT images. The bootconfig source can be configured globally or per-image.

== Introduction to bootconfig ==

A bootconfig is a small footer that can be added to an initramfs image and is read by the kernel at startup if the CONFIG_BOOT_CONFIG option is set. Its content can be used to expand the kernel command line even beyond its canonical size limit.

An interesting point about the bootconfig mechanism is that the initramfs image does *not* need to be there for the bootconfig to be read, as its presence is always checked starting from the bottom of the declared initramfs area.

More details on the bootconfig concept can be found at [0].

== Patchset walkthrough ==

Patch 1 adds a new recipe to compile the tool used for bootconfig management; being this part of the Linux kernel source code, it is compiled from the kernel shared workdir.

Patch 2 adds a new image conversion type to add the bootconfig to an image. While today only a cpio (plain or compressed) or an ext2 image would make sense here as a base for such operation, this is not strictly enforced as new usecases may arise in the future. A new bbclass containing the relevant configuration variables for this operation is also introduced in this patch.

Patche 3 adds a test recipe containing a bootconfig that can be used for tests; this recipe will then be used by patch 4.

Patch 4 adds support for adding a bootconfig inside a FIT image. Since the bootconfig is always read from the end of an initramfs memory area (even if the initramfs isn´t really there!), two forms of support are added here, both enabled by the FIT_INCLUDE_BOOTCONFIG variable:

- if INITRAMFS_IMAGE is set, the .bootconfig image is searched to be included as ramdisk section;
- if INITRAMFS_IMAGE is not set, a dummy/empty initramfs artifact is created and the bootconfig block is added there; the resulting binary is then added as ramdisk section.

It should be noted that if INITRAMFS_IMAGE_BUNDLE the bootconfig will NOT be included inside the FIT image and a warning will be displayed.

== Usecases ==

The main usecases I can think of are:

- (the one driving the work) initramfs-less dm-verity setup starting from a bootconfig included inside the FIT image and verified as part of the FIT verification; I have a working PoC for this based on a modified version of image_types_verity from meta-openembedded;
- complex tracing setups where the classic kernel command line is not sufficient (bootconfig is e.g. indicated as boot-time tracing mechanism [1]);
- debug flexibility: no need to modify the kernel nor the bootloader setup to pass debug arguments to the kernel.

Bonus track: the first usecase was featured in Francesco Castagnotto's podcast "I use Yocto btw", with me explaining it (in italian) [2].

== Open points ==

Following points are still open, with probable room for improvements:

- the BOOTCONFIG_TASK mechanism feels legacy, but I couldn't think of a better one;
- I'm not sure if and how the INITRAMFS_IMAGE_BUNDLE case should be managed (maybe bundling also the bootconfig itself?);
- should an example bootconfig recipe be added?

Thank you in advance for any feedback on this!

Best regards,
Francesco

[0] https://docs.kernel.org/admin-guide/bootconfig.html
[1] https://docs.kernel.org/trace/boottime-trace.html
[2] https://open.spotify.com/episode/0qR6lzm0nz4uylt0lCBfYQ

---
Francesco Valla (4):
bootconfig: add recipe
image_types: add bootconfig conversion type
recipes-test: add bootconfig-test recipe
kernel-fit-image: add bootconfig support

 .../recipes-test/bootconfig/bootconfig-test.bb     | 20 +++++++
 .../bootconfig/bootconfig-test/bootconfig-test.txt |  6 +++
 meta/classes-recipe/bootconfig-config.bbclass      | 12 +++++
 meta/classes-recipe/image_types.bbclass            | 15 +++++-
 meta/classes-recipe/kernel-fit-image.bbclass       | 44 +++++++++++++--
 meta/conf/image-fitimage.conf                      |  3 ++
 meta/lib/oeqa/selftest/cases/fitimage.py           | 63 +++++++++++++++++++---
 meta/recipes-kernel/bootconfig/bootconfig.bb       | 44 +++++++++++++++
 8 files changed, 193 insertions(+), 14 deletions(-)

---
base-commit: 531f87111d83430615f2e20dd41a3dd5fc25c7ab
change-id: 20260318-bootconfig-47ebc0231153

Best regards,

Signature · 1 line
Francesco Valla <[email protected]>
#1 lore raw

RFC PATCH 1/4 bootconfig: add recipe

Add a new recipe for the bootconfig tool, with source coming directly from the kernel shared workdir.

---
 meta/recipes-kernel/bootconfig/bootconfig.bb | 44 ++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
meta/recipes-kernel/bootconfig/bootconfig.bb new file +44 -0
new file mode 100644
index 0000000000000000000000000000000000000000..77ee70dd1839ef90a292cf829f4f3a4353f85c28
@@ -0,0 +1,44 @@
+SUMMARY = "Apply, delete or show boot config"
+DESCRIPTION = "bootconfig is a tool that can be used to add a boot config block \
+at the end of a kernel initramfs, as well as remove it or show its content."
+LICENSE = "GPL-2.0-only"
+
+inherit kernelsrc kernel-arch
+
+do_populate_lic[depends] += "virtual/kernel:do_shared_workdir"
+do_configure[depends] += "virtual/kernel:do_shared_workdir"
+
+EXTRA_OEMAKE = "\
+    -C ${S}/tools/bootconfig \
+    O=${B} \
+    CROSS=${TARGET_PREFIX} \
+    CC="${CC} ${DEBUG_PREFIX_MAP} -ffile-prefix-map=${STAGING_KERNEL_DIR}=${KERNEL_SRC_PATH} ${CFLAGS}" \
+    HOSTCC="${BUILD_CC} ${BUILD_CFLAGS}" \
+    LD="${LD}" \
+    AR=${AR} \
+    ARCH=${ARCH} \
+    V=1 \
+    'DESTDIR=${D}' \
+    'prefix=${prefix}' \
+    'bindir=${bindir}' \
+"
+
+do_compile() {
+	oe_runmake ${B}/bootconfig
+}
+
+do_install() {
+	install -d ${D}${bindir}
+	oe_runmake install
+}
+
+
+PACKAGE_ARCH = "${MACHINE_ARCH}"
+
+python do_package:prepend() {
+    d.setVar('PKGV', d.getVar("KERNEL_VERSION").split("-")[0])
+}
+
+B = "${WORKDIR}/${BPN}-${PV}"
+
+BBCLASSEXTEND = "native nativesdk"
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH RFC 1/4] bootconfig: add recipe

Hi Franceso

Thank you for the patches.

Quoted 47 lines · Francesco Valla

Add a new recipe for the bootconfig tool, with source coming directly from the kernel shared workdir.

---
 meta/recipes-kernel/bootconfig/bootconfig.bb | 44
++++++++++++++++++++++++++++

 1 file changed, 44 insertions(+)
meta/recipes-kernel/bootconfig/bootconfig.bb new file +0 -0
new file mode 100644

index 0000000000000000000000000000000000000000..77ee70dd1839ef90a292cf829f4 f3a4353f85c28

meta/recipes-kernel/bootconfig/bootconfig.bb new file +2 -0
@@ -0,0 +1,44 @@
+SUMMARY = "Apply, delete or show boot config"
+DESCRIPTION = "bootconfig is a tool that can be used to add a boot

config block \
+at the end of a kernel initramfs, as well as remove it or show its content."

meta/recipes-kernel/bootconfig/bootconfig.bb new file +12 -0
+LICENSE = "GPL-2.0-only"
+
+inherit kernelsrc kernel-arch
+
+do_populate_lic[depends] += "virtual/kernel:do_shared_workdir"
+do_configure[depends] += "virtual/kernel:do_shared_workdir"
+
+EXTRA_OEMAKE = "\
+    -C ${S}/tools/bootconfig \
+    O=${B} \
+    CROSS=${TARGET_PREFIX} \
+    CC="${CC} ${DEBUG_PREFIX_MAP} -ffile-prefix-

map=${STAGING_KERNEL_DIR}=${KERNEL_SRC_PATH} ${CFLAGS}" \
+    HOSTCC="${BUILD_CC} ${BUILD_CFLAGS}" \
+    LD="${LD}" \
+    AR=${AR} \
+    ARCH=${ARCH} \
+    V=1 \
+    'DESTDIR=${D}' \
+    'prefix=${prefix}' \
+    'bindir=${bindir}' \
+"

meta/recipes-kernel/bootconfig/bootconfig.bb new file +2 -0
+
+do_compile() {

meta/recipes-kernel/bootconfig/bootconfig.bb line 36

Quoted 10 lines
meta/recipes-kernel/bootconfig/bootconfig.bb new file +10 -0
+	oe_runmake ${B}/bootconfig
+}
+
+do_install() {
+	install -d ${D}${bindir}
+	oe_runmake install
+}
+
+
+PACKAGE_ARCH = "${MACHINE_ARCH}"

This is not understandable to me. From the description I would assume this tool runs on the host machine.

meta/recipes-kernel/bootconfig/bootconfig.bb line 44

Quoted 8 lines
meta/recipes-kernel/bootconfig/bootconfig.bb new file +8 -0
+
+python do_package:prepend() {
+    d.setVar('PKGV', d.getVar("KERNEL_VERSION").split("-")[0])
+}
+
+B = "${WORKDIR}/${BPN}-${PV}"
+
+BBCLASSEXTEND = "native nativesdk"

If the tool runs on the host machine, should this not be a pure -native recipe without this line e.g. named bootconfig-native.bb

Is bootconfig a good name for a recipe? Or should it be e.g. linux- bootconfig-native.bb?

Side note: We need to be careful not to create a dependency of the initramfs on the kernel build directory. Such a dependency would essentially invalidate the sstate-cache for the kernel, which we want to avoid.

Regards,
Adrian

#3 lore raw

Re: [PATCH RFC 1/4] bootconfig: add recipe

Hi Adrian,

Quoted 57 lines · Adrian

Hi Franceso

Thank you for the patches.

Quoted 52 lines · Francesco Valla

Add a new recipe for the bootconfig tool, with source coming directly from the kernel shared workdir.

---
�meta/recipes-kernel/bootconfig/bootconfig.bb | 44
++++++++++++++++++++++++++++
�1 file changed, 44 insertions(+)

meta/recipes-kernel/bootconfig/bootconfig.bb new file +0 -0
new file mode 100644

index 0000000000000000000000000000000000000000..77ee70dd1839ef90a292cf829f4 f3a4353f85c28

meta/recipes-kernel/bootconfig/bootconfig.bb new file +2 -0
@@ -0,0 +1,44 @@
+SUMMARY = "Apply, delete or show boot config"
+DESCRIPTION = "bootconfig is a tool that can be used to add a boot

config block \
+at the end of a kernel initramfs, as well as remove it or show its content."

meta/recipes-kernel/bootconfig/bootconfig.bb new file +12 -0
+LICENSE = "GPL-2.0-only"
+
+inherit kernelsrc kernel-arch
+
+do_populate_lic[depends] += "virtual/kernel:do_shared_workdir"
+do_configure[depends] += "virtual/kernel:do_shared_workdir"
+
+EXTRA_OEMAKE = "\
+��� -C ${S}/tools/bootconfig \
+��� O=${B} \
+��� CROSS=${TARGET_PREFIX} \
+��� CC="${CC} ${DEBUG_PREFIX_MAP} -ffile-prefix-

map=${STAGING_KERNEL_DIR}=${KERNEL_SRC_PATH} ${CFLAGS}" \
+��� HOSTCC="${BUILD_CC} ${BUILD_CFLAGS}" \
+��� LD="${LD}" \
+��� AR=${AR} \
+��� ARCH=${ARCH} \
+��� V=1 \
+��� 'DESTDIR=${D}' \
+��� 'prefix=${prefix}' \
+��� 'bindir=${bindir}' \
+"

meta/recipes-kernel/bootconfig/bootconfig.bb new file +7 -0
+
+do_compile() {
+	oe_runmake ${B}/bootconfig
+}
+
+do_install() {
+	install -d ${D}${bindir}
Quoted 9 lines

meta/recipes-kernel/bootconfig/bootconfig.bb line 36

Quoted 5 lines
meta/recipes-kernel/bootconfig/bootconfig.bb new file +5 -0
+	oe_runmake install
+}
+
+
+PACKAGE_ARCH = "${MACHINE_ARCH}"

This is not understandable to me. From the description I would assume this tool runs on the host machine.

I probably overthought the usecases here, with bootconfig being used on the target for on-the-fly bootconfig modification. But this wouldn't work with a FIT image obviously.

Quoted 12 lines

meta/recipes-kernel/bootconfig/bootconfig.bb line 44

Quoted 8 lines
meta/recipes-kernel/bootconfig/bootconfig.bb new file +8 -0
+
+python do_package:prepend() {
+��� d.setVar('PKGV', d.getVar("KERNEL_VERSION").split("-")[0])
+}
+
+B = "${WORKDIR}/${BPN}-${PV}"
+
+BBCLASSEXTEND = "native nativesdk"

If the tool runs on the host machine, should this not be a pure -native recipe without this line e.g. named bootconfig-native.bb

Quoted 3 lines

Is bootconfig a good name for a recipe? Or should it be e.g. linux- bootconfig-native.bb?

linux-bootconfig is a good name, I'll go with it in the next revision.

Quoted 5 lines

Side note: We need to be careful not to create a dependency of the initramfs on the kernel build directory. Such a dependency would essentially invalidate the sstate-cache for the kernel, which we want to avoid.

Agreed, one of the unpoken reasons for the RFC label is that the reasoning about dependencies has not been completed yes. I'm still facing challenges e.g. for FIT vs WIC cross-dependencies when a dm-veriry rootfs is used and its parameters are inserted into the FIT image that lives in the boot partition.
But I wanted to gather a first round of impressions with a (working) first version while working on it.

Quoted 3 lines

Regards,
Adrian

Thank you!

Reagrds,
Francesco

#4 lore raw

RFC PATCH 2/4 image_types: add bootconfig conversion type

In reply to Francesco Valla

Add the addition of a bootconfig block at the end of an image as a conversion type; while a bootconfig is mostly used in conjuntion with an initramfs (i.e.: a cpio image or one of its compressed forms), having it as a generic conversion type simplifies the implemntation and is ready for future modifications at kernel side.

The following configurations variables are introduced (in a separate bbclass, for further usage by other components):

- BOOTCONFIG_SRC: source file to be used as bootconfig, to be found

    inside DEPLOY_DIR_IMAGE;

- BOOTCONFIG_TASK: task deploying the bootconfig source file specified in BOOTCONFIG_SRC to DEPLOY_DIR_IMAGE; an image using the bootconfig modifier will depend on it.

---
 meta/classes-recipe/bootconfig-config.bbclass | 12 ++++++++++++
 meta/classes-recipe/image_types.bbclass       | 15 +++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)
meta/classes-recipe/bootconfig-config.bbclass new file +12 -0
new file mode 100644
index 0000000000000000000000000000000000000000..3d34fc47a3a684aef1ecdbd5ed52c904611bf95d
@@ -0,0 +1,12 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+# Name of the file to be used as bootconfig source, to be found inside DEPLOY_DIR_IMAGE
+BOOTCONFIG_SRC ?= ""
+
+# Task deploying the bootconfig source to DEPLOY_DIR_IMAGE
+#  e.g.: BOOTCONFIG_TASK = "bootconfig-debug:do_deploy"
+BOOTCONFIG_TASK ?= ""
meta/classes-recipe/image_types.bbclass +13 -2
index e6ef0ce11e40c0f8388fb5547ab03943004bde2f..98c6d9e836f5c80f78e6f6f32aa923de66feb836 100644
@@ -264,9 +264,18 @@ IMAGE_CMD:f2fs () {
 	sload.f2fs -f ${IMAGE_ROOTFS} ${IMGDEPLOYDIR}/${IMAGE_NAME}.f2fs
 }
 
+oe_bootconfig() {
+	local src_image=$1
+	if [ -z "${BOOTCONFIG_SRC}" ]; then
+		bbfatal "bootconfig image type requested but BOOTCONFIG_SRC is not set"
+	fi
+	cp ${src_image} ${src_image}.bootconfig
+	bootconfig -a ${DEPLOY_DIR_IMAGE}/${BOOTCONFIG_SRC} ${src_image}.bootconfig
+}
+
 EXTRA_IMAGECMD = ""
 
-inherit siteinfo kernel-arch image-artifact-names
+inherit siteinfo kernel-arch image-artifact-names bootconfig-config
 
 JFFS2_ENDIANNESS ?= "${@oe.utils.conditional('SITEINFO_ENDIANNESS', 'le', '-l', '-b', d)}"
 JFFS2_ERASEBLOCK ?= "0x40000"
@@ -333,7 +342,7 @@ IMAGE_TYPES:append:x86-64 = " hddimg iso"
 # CONVERSION_CMD/DEPENDS.
 COMPRESSIONTYPES ?= ""
 
-CONVERSIONTYPES = "gz bz2 lzma xz lz4 lzo zip 7zip zst sum md5sum sha1sum sha224sum sha256sum sha384sum sha512sum bmap u-boot vmdk vhd vhdx vdi qcow2 base64 gzsync zsync ${COMPRESSIONTYPES}"
+CONVERSIONTYPES = "gz bz2 lzma xz lz4 lzo zip 7zip zst sum md5sum sha1sum sha224sum sha256sum sha384sum sha512sum bmap u-boot vmdk vhd vhdx vdi qcow2 base64 gzsync zsync bootconfig ${COMPRESSIONTYPES}"
 CONVERSION_CMD:lzma = "lzma -k -f -7 ${IMAGE_NAME}.${type}"
 CONVERSION_CMD:gz = "gzip -f -9 -n -c --rsyncable ${IMAGE_NAME}.${type} > ${IMAGE_NAME}.${type}.gz"
 CONVERSION_CMD:bz2 = "pbzip2 -f -k ${IMAGE_NAME}.${type}"
@@ -360,6 +369,7 @@ CONVERSION_CMD:qcow2 = "qemu-img convert -O qcow2 ${IMAGE_NAME}.${type} ${IMAGE_
 CONVERSION_CMD:base64 = "base64 ${IMAGE_NAME}.${type} > ${IMAGE_NAME}.${type}.base64"
 CONVERSION_CMD:zsync = "zsyncmake_curl ${IMAGE_NAME}.${type}"
 CONVERSION_CMD:gzsync = "zsyncmake_curl -z ${IMAGE_NAME}.${type}"
+CONVERSION_CMD:bootconfig = "oe_bootconfig ${IMAGE_NAME}.${type}"
 CONVERSION_DEPENDS_lzma = "xz-native"
 CONVERSION_DEPENDS_gz = "pigz-native"
 CONVERSION_DEPENDS_bz2 = "pbzip2-native"
@@ -380,6 +390,7 @@ CONVERSION_DEPENDS_vhdx = "qemu-system-native"
 CONVERSION_DEPENDS_vhd = "qemu-system-native"
 CONVERSION_DEPENDS_zsync = "zsync-curl-native"
 CONVERSION_DEPENDS_gzsync = "zsync-curl-native"
+CONVERSION_DEPENDS_bootconfig = "bootconfig-native ${BOOTCONFIG_TASK}"
 
 RUNNABLE_IMAGE_TYPES ?= "ext2 ext3 ext4"
 RUNNABLE_MACHINE_PATTERNS ?= "qemu"
Signature · 1 line
2.53.0
#5 lore raw

RFC PATCH 3/4 recipes-test: add bootconfig-test recipe

In reply to Francesco Valla

Add a test recipe deploying a fixed bootconfig source file to DEPLOY_DIR_IMAGE, to be used in tests that expect a bootconfig to be available.

---
 .../recipes-test/bootconfig/bootconfig-test.bb       | 20 ++++++++++++++++++++
 .../bootconfig/bootconfig-test/bootconfig-test.txt   |  6 ++++++
 2 files changed, 26 insertions(+)
meta-selftest/recipes-test/bootconfig/bootconfig-test.bb new file +20 -0
new file mode 100644
index 0000000000000000000000000000000000000000..0cf74fa93652009466220f21001923a81d628a2e
@@ -0,0 +1,20 @@
+SUMMARY = "Test bootconfig"
+DESCRIPTION = "This generates a dummy bootconfig to be used to for testing."
+LICENSE = "MIT"
+
+SRC_URI = "file://bootconfig-test.txt"
+
+EXCLUDE_FROM_WORLD = "1"
+ 
+inherit deploy nopackages
+
+do_configure[noexec] = "1"
+do_compile[noexec] = "1"
+deltask do_stash_locale
+deltask do_install
+deltask do_populate_sysroot
+
+do_deploy() {
+    install -m0664 ${UNPACKDIR}/bootconfig-test.txt ${DEPLOYDIR}/bootconfig-test.txt
+}
+addtask deploy after do_unpack before do_build
meta-selftest/recipes-test/bootconfig/bootconfig-test/bootconfig-test.txt new file +6 -0
new file mode 100644
index 0000000000000000000000000000000000000000..c194018b0bd0e225aaf01a49dff78fcaebe8a7d4
@@ -0,0 +1,6 @@
+kernel {
+  root = 01234567-89ab-cdef-0123-456789abcd
+}
+init {
+  splash
+}
Signature · 1 line
2.53.0
#6 lore raw

RFC PATCH 4/4 kernel-fit-image: add bootconfig support

In reply to Francesco Valla

Support for bootconfig is added to generated FITs in two forms, both depending on the FIT_INCLUDE_BOOTCONFIG being set to 1 to be enabled:

- if INITRAMFS_IMAGE is set, a .bootconfig image will be searched

    instead of the plain or compressed cpio archives;

- if INITRAMFS_IMAGE is not set, a dummy initramfs will be generated and the bootconfig specified in BOOTCONFIG_SRC will be attached to it.

The case where both FIT_INCLUDE_BOOTCONFIG and INITRAMFS_IMAGE_BUNDLE are set to '1' is not supported, as it wouldn't work as expected on the target device.

---
 meta/classes-recipe/kernel-fit-image.bbclass | 44 +++++++++++++++++--
 meta/conf/image-fitimage.conf                |  3 ++
 meta/lib/oeqa/selftest/cases/fitimage.py     | 63 ++++++++++++++++++++++++----
 3 files changed, 98 insertions(+), 12 deletions(-)
meta/classes-recipe/kernel-fit-image.bbclass +40 -4
index 367bc9bcfd3a4cd237e466269fa143941a02031a..9188723252912f2db6c9952798f66798cfe32b78 100644
@@ -1,5 +1,5 @@
 
-inherit kernel-arch kernel-artifact-names uboot-config deploy
+inherit kernel-arch kernel-artifact-names uboot-config bootconfig-config deploy
 require conf/image-fitimage.conf
 
 S = "${UNPACKDIR}"
@@ -12,6 +12,7 @@ EXCLUDE_FROM_WORLD = "1"
 DEPENDS += "\
     u-boot-tools-native dtc-native \
     ${@'kernel-signing-keys-native' if d.getVar('FIT_GENERATE_KEYS') == '1' else ''} \
+    ${@'bootconfig-native' if (d.getVar('FIT_INCLUDE_BOOTCONFIG') == '1' and not d.getVar("INITRAMFS_IMAGE")) else ''} \
 "
 
 python () {
@@ -23,6 +24,9 @@ python () {
         else:
             d.appendVarFlag('do_compile', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
 
+    if not image and d.getVar('BOOTCONFIG_TASK') and d.getVar('FIT_INCLUDE_BOOTCONFIG') == '1':
+        d.appendVarFlag('do_compile', 'depends', ' ${BOOTCONFIG_TASK}')
+
     #check if there are any dtb providers
     providerdtb = d.getVar("PREFERRED_PROVIDER_virtual/dtb")
     if providerdtb:
@@ -54,8 +58,24 @@ FIT_KERNEL_SIGN_ENABLE ?= "${UBOOT_SIGN_ENABLE}"
 FIT_KERNEL_SIGN_KEYNAME ?= "${UBOOT_SIGN_KEYNAME}"
 FIT_KERNEL_SIGN_KEYDIR ?= "${UBOOT_SIGN_KEYDIR}"
 
+create_bootconfig_bin() {
+    if [ ! -e ${DEPLOY_DIR_IMAGE}/${BOOTCONFIG_SRC} ]; then
+        bbfatal "Did not find bootconfig source file: ${DEPLOY_DIR_IMAGE}/${BOOTCONFIG_SRC}"
+    fi
+
+    # Create empty file
+    dd if=/dev/zero of=bootconfig.bin count=0
+
+    # Add bootconfig to file
+    bootconfig -a ${DEPLOY_DIR_IMAGE}/${BOOTCONFIG_SRC} bootconfig.bin
+
+    # Re-read bootconfig
+    bootconfig -l bootconfig.bin
+}
+
 python do_compile() {
     import shutil
+    import subprocess
     import oe.fitimage
 
     itsfile = "fit-image.its"
@@ -135,10 +155,18 @@ python do_compile() {
 
     # Prepare a ramdisk section.
     initramfs_image = d.getVar('INITRAMFS_IMAGE')
-    if initramfs_image and d.getVar("INITRAMFS_IMAGE_BUNDLE") != '1':
+    if initramfs_image and d.getVar("INITRAMFS_IMAGE_BUNDLE") == '1':
+        bb.note("Initramfs is bundled with kernel image, not including it as ramdisk")
+        if d.getVar("FIT_INCLUDE_BOOTCONFIG") == '1':
+            bb.warn("FIT_INCLUDE_BOOTCONFIG not supported if INITRAMFS_IMAGE_BUNDLE is set. Bootconfig won't be included in the FIT image.")
+    elif initramfs_image:
         # Find and use the first initramfs image archive type we find
+        fstypes = d.getVar("FIT_SUPPORTED_INITRAMFS_FSTYPES").split()
+        if d.getVar("FIT_INCLUDE_BOOTCONFIG") == '1':
+            bb.note("Including initramfs with bootconfig")
+            fstypes = [ "%s.bootconfig" % f for f in fstypes ]
         found = False
-        for img in d.getVar("FIT_SUPPORTED_INITRAMFS_FSTYPES").split():
+        for img in fstypes:
             initramfs_path = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), "%s.%s" % (d.getVar('INITRAMFS_IMAGE_NAME'), img))
             if os.path.exists(initramfs_path):
                 bb.note("Found initramfs image: " + initramfs_path)
@@ -152,7 +180,15 @@ python do_compile() {
                 bb.note("Did not find initramfs image: " + initramfs_path)
 
         if not found:
-            bb.fatal("Could not find a valid initramfs type for %s, the supported types are: %s" % (d.getVar('INITRAMFS_IMAGE_NAME'), d.getVar('FIT_SUPPORTED_INITRAMFS_FSTYPES')))
+            bb.fatal("Could not find a valid initramfs type for %s, the supported types are: %s" % (d.getVar('INITRAMFS_IMAGE_NAME'), " ".join(fstypes)))
+    elif d.getVar("FIT_INCLUDE_BOOTCONFIG") == '1':
+        # Include bootconfig also without an initramfs, emitting a dedicated ramdisk section
+        bb.build.exec_func('create_bootconfig_bin', d)
+
+        root_node.fitimage_emit_section_ramdisk("ramdisk-1", "bootconfig.bin",
+            "bootconfig",
+            d.getVar("UBOOT_RD_LOADADDRESS"),
+            d.getVar("UBOOT_RD_ENTRYPOINT"))
 
     #
     # Prepare loadables sections
meta/conf/image-fitimage.conf +3 -0
index 2fdb816d556c786dcc2c14cb149446eaddc2ff4b..b2178853f388e320710b3c0117799145795bf8f4 100644
@@ -37,6 +37,9 @@ FIT_CONF_PREFIX[doc] = "Prefix to use for FIT configuration node name"
 
 FIT_SUPPORTED_INITRAMFS_FSTYPES ?= "cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.zst cpio.gz ext2.gz cpio"
 
+# Include bootconfig (either with or without initramfs)
+FIT_INCLUDE_BOOTCONFIG ?= "0"
+
 # Allow user to support special use cases where the kernel binary is
 # not included in the FIT image itself.
 # This is particularly useful for UKI-based setups, where the kernel
meta/lib/oeqa/selftest/cases/fitimage.py +55 -8

156 lines not on this page · raw message

Signature · 1 line
2.53.0