]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
kernel-fit-image: skip kernel section if linux.bin is missing mathieu/master-next mathieu/master-next-success
authorKavinaya S <kavinaya@qti.qualcomm.com>
Tue, 12 Aug 2025 09:14:53 +0000 (14:44 +0530)
committerMathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Fri, 15 Aug 2025 09:26:00 +0000 (11:26 +0200)
Avoids errors during image generation by checking for the
presence of linux.bin before attempting to copy and emit the
kernel section. This ensures that the build process continues
gracefully when the kernel binary is not available.

A clean separation between firmware (including DTBs) and the
HLOS (Linux Kernel) is highly recommended and often necessary
to enable independent firmware updates, enforce trust boundaries,
and support running the same kernel across different hardware
platforms by simply swapping DTBs. One effective way to achieve
this separation is by using a Unified Kernel Image (UKI) that
contains only the Linux kernel and initramfs, while keeping the
DTBs in a separate FIT image, such as dtb.bin.

To support this setup, it's important to ensure that a FIT image
can be generated without requiring the Linux kernel binary,
allowing the build process to continue gracefully even when the
kernel is unavailable.

Additionally, this approach is very useful when the kernel-fit-
extra-artifacts class is not set, as it enables the creation of
an .its file without depending on the kernel.

Signed-off-by: Kavinaya S <kavinaya@qti.qualcomm.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
meta/classes-recipe/kernel-fit-image.bbclass

index fd4c6a30feb96243d09c92c36d81f01e7c69fe0e..c0f925d90eb0ecbac8538e2466ecb7e7ef3a9179 100644 (file)
@@ -59,12 +59,26 @@ python do_compile() {
     )
 
     # Prepare a kernel image section.
-    shutil.copyfile(os.path.join(kernel_deploydir, "linux.bin"), "linux.bin")
-    with open(os.path.join(kernel_deploydir, "linux_comp")) as linux_comp_f:
-        linux_comp = linux_comp_f.read()
-    root_node.fitimage_emit_section_kernel("kernel-1", "linux.bin", linux_comp,
+    # Construct the full path to linux.bin
+    linux_bin_path = os.path.join(kernel_deploydir, "linux.bin")
+
+    # Check if linux.bin exists
+    if os.path.exists(linux_bin_path):
+        # Copy linux.bin to current directory
+        shutil.copyfile(linux_bin_path, "linux.bin")
+
+        # Read linux_comp file
+        linux_comp_path = os.path.join(kernel_deploydir, "linux_comp")
+        with open(linux_comp_path, 'r') as linux_comp_f:
+            linux_comp = linux_comp_f.read()
+
+        # Emit kernel image section
+        root_node.fitimage_emit_section_kernel("kernel-1", "linux.bin", linux_comp,
         d.getVar('UBOOT_LOADADDRESS'), d.getVar('UBOOT_ENTRYPOINT'),
         d.getVar('UBOOT_MKIMAGE_KERNEL_TYPE'), d.getVar("UBOOT_ENTRYSYMBOL"))
+    else:
+        bb.note("linux.bin not found. Skipping kernel image preparation. ")
+
 
     # Prepare a DTB image section
     kernel_devicetree = d.getVar('KERNEL_DEVICETREE')