public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH v2] image: copy DTB_FILES to DEPLOYDIR/IMAGE_FULLNAME/KERNEL_NAME/
       [not found] <ixzytHYnTmI>
@ 2025-10-08  6:22 ` 'Badrikesh Prusty' via isar-users
  0 siblings, 0 replies; 2+ messages in thread
From: 'Badrikesh Prusty' via isar-users @ 2025-10-08  6:22 UTC (permalink / raw)
  To: isar-users; +Cc: Badrikesh Prusty

Copy DTB_FILES to DEPLOYDIR/IMAGE_FULLNAME/KERNEL_NAME instead of DEPLOYDIR/.

An issue is observed when we attempt to build a second image for a machine
utilizing DTB_FILES. During the do_copy_boot_files task of image creation, the
DTB_FILES are copied to the shared location DEPLOYDIR/<dtb files>. When the
build of a second image is triggered, it detects that the DTB_FILES are already
present and avoids overwriting them.

Reproducer:
bitbake mc:phyboard-mira-bookworm:isar-image-base
bitbake mc:phyboard-mira-bookworm:isar-image-debug

Copy the DTB_FILES to the directory: DEPLOYDIR/IMAGE_FULLNAME/KERNEL_NAME/.
* This will allow building multiple images.
* As each kernel recipe ships its own DTB_FILES, if a user tries to rebuild
the same image with a new kernel, the DTB_FILES associated with the older
kernel will not be overwritten.

Update the DTB_IMG variable to check for DTB_FILES in their new location.
Update the WIC plugin scripts to use the DTB_FILES from their updated location
within the DEPLOYDIR.
Add IMAGE_FULLNAME and KERNEL_NAME to WICVARS to allow the scripts to retrieve
these variable values during WIC image generation.

Signed-off-by: Badrikesh Prusty <badrikesh.prusty@siemens.com>
---
 RECIPE-API-CHANGELOG.md                            | 11 +++++++++++
 meta/classes/image.bbclass                         |  5 +++--
 meta/classes/imagetypes_wic.bbclass                |  6 +++---
 .../lib/wic/plugins/source/bootimg-efi-isar.py     | 10 ++++++++--
 scripts/lib/wic/plugins/source/bootimg-efi.py      |  9 +++++++--
 .../lib/wic/plugins/source/bootimg-partition.py    | 14 ++++++++++++++
 6 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index 2930ade9..0ad0ebf7 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -761,3 +761,14 @@ the following variables in your image recipe. For example, to use German, add:
 LOCALE_GEN = "de_DE.UTF-8 UTF-8\n"
 LOCALE_DEFAULT = "de_DE.UTF-8"
 ```
+
+### Copy DTB_FILES to Separate Location for Multi-Image/Multi-Kernel Support
+
+Copy DTB_FILES to DEPLOYDIR/IMAGE_FULLNAME/KERNEL_NAME instead of DEPLOYDIR/.
+
+This enables building multiple images utilizing DTB_FILES, with each kernel
+recipe providing its own DTB_FILES. Rebuilding an image with a new kernel won't
+overwrite the DTBfiles from the previous one.
+
+Update DTB_IMG to locate DTB_FILES in their new path, and modify WIC plugin
+scripts to use the updated DTB_FILES location within DEPLOYDIR.
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index bd1b8552..8606d353 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -333,7 +333,7 @@ EOF
 KERNEL_IMG = "${PP_DEPLOY}/${KERNEL_IMAGE}"
 INITRD_IMG = "${PP_DEPLOY}/${INITRD_DEPLOY_FILE}"
 # only one dtb file supported, pick the first
-DTB_IMG = "${PP_DEPLOY}/${@(d.getVar('DTB_FILES').split() or [''])[0]}"
+DTB_IMG = "${PP_DEPLOY}/${IMAGE_FULLNAME}/${KERNEL_NAME}/${@(d.getVar('DTB_FILES').split() or [''])[0]}"
 
 do_copy_boot_files[cleandirs] += "${DEPLOYDIR}"
 do_copy_boot_files[sstate-inputdirs] = "${DEPLOYDIR}"
@@ -356,7 +356,8 @@ do_copy_boot_files() {
             die "${file} not found"
         fi
 
-        cp -f "$dtb" "${DEPLOYDIR}/"
+        mkdir -p "${DEPLOYDIR}/${IMAGE_FULLNAME}/${KERNEL_NAME}"
+        cp -f "$dtb" "${DEPLOYDIR}/${IMAGE_FULLNAME}/${KERNEL_NAME}/"
     done
 }
 addtask copy_boot_files before do_rootfs_postprocess after do_rootfs_install
diff --git a/meta/classes/imagetypes_wic.bbclass b/meta/classes/imagetypes_wic.bbclass
index fb0b81a9..a9fec616 100644
--- a/meta/classes/imagetypes_wic.bbclass
+++ b/meta/classes/imagetypes_wic.bbclass
@@ -102,9 +102,9 @@ WIC_DEPLOY_PARTITIONS ?= "0"
 
 # taken from OE, do not touch directly
 WICVARS += "\
-           BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD IMAGE_BASENAME IMAGE_BOOT_FILES IMAGE_EFI_BOOT_FILES \
-           IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD INITRD_LIVE ISODIR RECIPE_SYSROOT_NATIVE \
-           ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS TRANSLATED_TARGET_ARCH"
+           BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD IMAGE_BASENAME IMAGE_FULLNAME IMAGE_BOOT_FILES \
+           IMAGE_EFI_BOOT_FILES IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD INITRD_LIVE ISODIR KERNEL_NAME \
+           RECIPE_SYSROOT_NATIVE ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS TRANSLATED_TARGET_ARCH"
 
 # Isar specific vars used in our plugins
 WICVARS += "DISTRO DISTRO_ARCH KERNEL_FILE"
diff --git a/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py b/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py
index 446398d0..465e549a 100644
--- a/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py
+++ b/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py
@@ -57,7 +57,10 @@ class BootimgEFIPlugin(SourcePlugin):
         if dtb:
             if ';' in dtb:
                 raise WicError("Only one DTB supported, exiting")
-            cp_cmd = "cp %s/%s %s" % (bootimg_dir, dtb, hdddir)
+            image_fullname = get_bitbake_var("IMAGE_FULLNAME")
+            kernel_name = get_bitbake_var("KERNEL_NAME")
+            dtbs_dir = os.path.join(bootimg_dir, image_fullname, kernel_name)
+            cp_cmd = "cp %s/%s %s" % (dtbs_dir, dtb, hdddir)
             exec_cmd(cp_cmd, True)
 
     @classmethod
@@ -359,8 +362,11 @@ class BootimgEFIPlugin(SourcePlugin):
                 if dtb:
                     if ';' in dtb:
                         raise WicError("Only one DTB supported, exiting")
+                    image_fullname = get_bitbake_var("IMAGE_FULLNAME")
+                    kernel_name = get_bitbake_var("KERNEL_NAME")
+                    dtbs_dir = os.path.join(deploy_dir, image_fullname, kernel_name)
                     dtb_params = '--add-section .dtb=%s/%s --change-section-vma .dtb=0x40000' % \
-                        (deploy_dir, dtb)
+                        (dtbs_dir, dtb)
                 else:
                     dtb_params = ''
 
diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py
index 13a9cddf..0e17543d 100644
--- a/scripts/lib/wic/plugins/source/bootimg-efi.py
+++ b/scripts/lib/wic/plugins/source/bootimg-efi.py
@@ -51,7 +51,10 @@ class BootimgEFIPlugin(SourcePlugin):
         if dtb:
             if ';' in dtb:
                 raise WicError("Only one DTB supported, exiting")
-            cp_cmd = "cp %s/%s %s" % (bootimg_dir, dtb, hdddir)
+            image_fullname = get_bitbake_var("IMAGE_FULLNAME")
+            kernel_name = get_bitbake_var("KERNEL_NAME")
+            dtbs_dir = os.path.join(bootimg_dir, image_fullname, kernel_name)
+            cp_cmd = "cp %s/%s %s" % (dtbs_dir, dtb, hdddir)
             exec_cmd(cp_cmd, True)
 
     @classmethod
@@ -368,7 +371,9 @@ class BootimgEFIPlugin(SourcePlugin):
                 if dtb:
                     if ';' in dtb:
                         raise WicError("Only one DTB supported, exiting")
-                    dtb_path = "%s/%s" % (deploy_dir, dtb)
+                    image_fullname = get_bitbake_var("IMAGE_FULLNAME")
+                    kernel_name = get_bitbake_var("KERNEL_NAME")
+                    dtb_path = os.path.join(deploy_dir, image_fullname, kernel_name, dtb)
                     dtb_params = '--add-section .dtb=%s --change-section-vma .dtb=0x%x' % \
                             (dtb_path, dtb_off)
                     linux_off = dtb_off + os.stat(dtb_path).st_size
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py
index 94183174..5c1e4497 100644
--- a/scripts/lib/wic/plugins/source/bootimg-partition.py
+++ b/scripts/lib/wic/plugins/source/bootimg-partition.py
@@ -183,9 +183,23 @@ class BootimgPartitionPlugin(SourcePlugin):
 
         logger.debug('Kernel dir: %s', bootimg_dir)
 
+        image_fullname = get_bitbake_var("IMAGE_FULLNAME")
+        kernel_name = get_bitbake_var("KERNEL_NAME")
+        dtbs_dir = os.path.join(image_fullname, kernel_name)
 
         for task in cls.install_task:
             src_path, dst_path = task
+
+            src_fullpath = os.path.join(kernel_dir, src_path)
+
+            # If default path doesn't exist, try DTB deploy path
+            if not os.path.exists(src_fullpath):
+                src_path = os.path.join(dtbs_dir, src_path)
+                src_fullpath = os.path.join(kernel_dir, src_path)
+
+                if not os.path.exists(src_fullpath):
+                    raise WicError("Couldn't find %s, exiting" % src_fullpath)
+
             logger.debug('Install %s as %s', src_path, dst_path)
             install_cmd = "install -m 0644 -D %s %s" \
                           % (os.path.join(kernel_dir, src_path),
-- 
2.47.3

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20251008062241.52067-1-badrikesh.prusty%40siemens.com.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2] image: copy DTB_FILES to DEPLOYDIR/IMAGE_FULLNAME/KERNEL_NAME/
@ 2025-10-08  6:28 'Badrikesh Prusty' via isar-users
  0 siblings, 0 replies; 2+ messages in thread
From: 'Badrikesh Prusty' via isar-users @ 2025-10-08  6:28 UTC (permalink / raw)
  To: isar-users; +Cc: Badrikesh Prusty

Copy DTB_FILES to DEPLOYDIR/IMAGE_FULLNAME/KERNEL_NAME instead of DEPLOYDIR/.

An issue is observed when we attempt to build a second image for a machine
utilizing DTB_FILES. During the do_copy_boot_files task of image creation, the
DTB_FILES are copied to the shared location DEPLOYDIR/<dtb files>. When the
build of a second image is triggered, it detects that the DTB_FILES are already
present and avoids overwriting them.

Reproducer:
bitbake mc:phyboard-mira-bookworm:isar-image-base
bitbake mc:phyboard-mira-bookworm:isar-image-debug

Copy the DTB_FILES to the directory: DEPLOYDIR/IMAGE_FULLNAME/KERNEL_NAME/.
* This will allow building multiple images.
* As each kernel recipe ships its own DTB_FILES, if a user tries to rebuild
the same image with a new kernel, the DTB_FILES associated with the older
kernel will not be overwritten.

Update the DTB_IMG variable to check for DTB_FILES in their new location.
Update the WIC plugin scripts to use the DTB_FILES from their updated location
within the DEPLOYDIR.
Add IMAGE_FULLNAME and KERNEL_NAME to WICVARS to allow the scripts to retrieve
these variable values during WIC image generation.

Signed-off-by: Badrikesh Prusty <badrikesh.prusty@siemens.com>
---
 RECIPE-API-CHANGELOG.md                            | 11 +++++++++++
 meta/classes/image.bbclass                         |  5 +++--
 meta/classes/imagetypes_wic.bbclass                |  6 +++---
 .../lib/wic/plugins/source/bootimg-efi-isar.py     | 10 ++++++++--
 scripts/lib/wic/plugins/source/bootimg-efi.py      |  9 +++++++--
 .../lib/wic/plugins/source/bootimg-partition.py    | 14 ++++++++++++++
 6 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index 2930ade9..0ad0ebf7 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -761,3 +761,14 @@ the following variables in your image recipe. For example, to use German, add:
 LOCALE_GEN = "de_DE.UTF-8 UTF-8\n"
 LOCALE_DEFAULT = "de_DE.UTF-8"
 ```
+
+### Copy DTB_FILES to Separate Location for Multi-Image/Multi-Kernel Support
+
+Copy DTB_FILES to DEPLOYDIR/IMAGE_FULLNAME/KERNEL_NAME instead of DEPLOYDIR/.
+
+This enables building multiple images utilizing DTB_FILES, with each kernel
+recipe providing its own DTB_FILES. Rebuilding an image with a new kernel won't
+overwrite the DTBfiles from the previous one.
+
+Update DTB_IMG to locate DTB_FILES in their new path, and modify WIC plugin
+scripts to use the updated DTB_FILES location within DEPLOYDIR.
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index bd1b8552..8606d353 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -333,7 +333,7 @@ EOF
 KERNEL_IMG = "${PP_DEPLOY}/${KERNEL_IMAGE}"
 INITRD_IMG = "${PP_DEPLOY}/${INITRD_DEPLOY_FILE}"
 # only one dtb file supported, pick the first
-DTB_IMG = "${PP_DEPLOY}/${@(d.getVar('DTB_FILES').split() or [''])[0]}"
+DTB_IMG = "${PP_DEPLOY}/${IMAGE_FULLNAME}/${KERNEL_NAME}/${@(d.getVar('DTB_FILES').split() or [''])[0]}"
 
 do_copy_boot_files[cleandirs] += "${DEPLOYDIR}"
 do_copy_boot_files[sstate-inputdirs] = "${DEPLOYDIR}"
@@ -356,7 +356,8 @@ do_copy_boot_files() {
             die "${file} not found"
         fi
 
-        cp -f "$dtb" "${DEPLOYDIR}/"
+        mkdir -p "${DEPLOYDIR}/${IMAGE_FULLNAME}/${KERNEL_NAME}"
+        cp -f "$dtb" "${DEPLOYDIR}/${IMAGE_FULLNAME}/${KERNEL_NAME}/"
     done
 }
 addtask copy_boot_files before do_rootfs_postprocess after do_rootfs_install
diff --git a/meta/classes/imagetypes_wic.bbclass b/meta/classes/imagetypes_wic.bbclass
index fb0b81a9..a9fec616 100644
--- a/meta/classes/imagetypes_wic.bbclass
+++ b/meta/classes/imagetypes_wic.bbclass
@@ -102,9 +102,9 @@ WIC_DEPLOY_PARTITIONS ?= "0"
 
 # taken from OE, do not touch directly
 WICVARS += "\
-           BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD IMAGE_BASENAME IMAGE_BOOT_FILES IMAGE_EFI_BOOT_FILES \
-           IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD INITRD_LIVE ISODIR RECIPE_SYSROOT_NATIVE \
-           ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS TRANSLATED_TARGET_ARCH"
+           BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD IMAGE_BASENAME IMAGE_FULLNAME IMAGE_BOOT_FILES \
+           IMAGE_EFI_BOOT_FILES IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD INITRD_LIVE ISODIR KERNEL_NAME \
+           RECIPE_SYSROOT_NATIVE ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS TRANSLATED_TARGET_ARCH"
 
 # Isar specific vars used in our plugins
 WICVARS += "DISTRO DISTRO_ARCH KERNEL_FILE"
diff --git a/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py b/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py
index 446398d0..465e549a 100644
--- a/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py
+++ b/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py
@@ -57,7 +57,10 @@ class BootimgEFIPlugin(SourcePlugin):
         if dtb:
             if ';' in dtb:
                 raise WicError("Only one DTB supported, exiting")
-            cp_cmd = "cp %s/%s %s" % (bootimg_dir, dtb, hdddir)
+            image_fullname = get_bitbake_var("IMAGE_FULLNAME")
+            kernel_name = get_bitbake_var("KERNEL_NAME")
+            dtbs_dir = os.path.join(bootimg_dir, image_fullname, kernel_name)
+            cp_cmd = "cp %s/%s %s" % (dtbs_dir, dtb, hdddir)
             exec_cmd(cp_cmd, True)
 
     @classmethod
@@ -359,8 +362,11 @@ class BootimgEFIPlugin(SourcePlugin):
                 if dtb:
                     if ';' in dtb:
                         raise WicError("Only one DTB supported, exiting")
+                    image_fullname = get_bitbake_var("IMAGE_FULLNAME")
+                    kernel_name = get_bitbake_var("KERNEL_NAME")
+                    dtbs_dir = os.path.join(deploy_dir, image_fullname, kernel_name)
                     dtb_params = '--add-section .dtb=%s/%s --change-section-vma .dtb=0x40000' % \
-                        (deploy_dir, dtb)
+                        (dtbs_dir, dtb)
                 else:
                     dtb_params = ''
 
diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py
index 13a9cddf..0e17543d 100644
--- a/scripts/lib/wic/plugins/source/bootimg-efi.py
+++ b/scripts/lib/wic/plugins/source/bootimg-efi.py
@@ -51,7 +51,10 @@ class BootimgEFIPlugin(SourcePlugin):
         if dtb:
             if ';' in dtb:
                 raise WicError("Only one DTB supported, exiting")
-            cp_cmd = "cp %s/%s %s" % (bootimg_dir, dtb, hdddir)
+            image_fullname = get_bitbake_var("IMAGE_FULLNAME")
+            kernel_name = get_bitbake_var("KERNEL_NAME")
+            dtbs_dir = os.path.join(bootimg_dir, image_fullname, kernel_name)
+            cp_cmd = "cp %s/%s %s" % (dtbs_dir, dtb, hdddir)
             exec_cmd(cp_cmd, True)
 
     @classmethod
@@ -368,7 +371,9 @@ class BootimgEFIPlugin(SourcePlugin):
                 if dtb:
                     if ';' in dtb:
                         raise WicError("Only one DTB supported, exiting")
-                    dtb_path = "%s/%s" % (deploy_dir, dtb)
+                    image_fullname = get_bitbake_var("IMAGE_FULLNAME")
+                    kernel_name = get_bitbake_var("KERNEL_NAME")
+                    dtb_path = os.path.join(deploy_dir, image_fullname, kernel_name, dtb)
                     dtb_params = '--add-section .dtb=%s --change-section-vma .dtb=0x%x' % \
                             (dtb_path, dtb_off)
                     linux_off = dtb_off + os.stat(dtb_path).st_size
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py
index 94183174..5c1e4497 100644
--- a/scripts/lib/wic/plugins/source/bootimg-partition.py
+++ b/scripts/lib/wic/plugins/source/bootimg-partition.py
@@ -183,9 +183,23 @@ class BootimgPartitionPlugin(SourcePlugin):
 
         logger.debug('Kernel dir: %s', bootimg_dir)
 
+        image_fullname = get_bitbake_var("IMAGE_FULLNAME")
+        kernel_name = get_bitbake_var("KERNEL_NAME")
+        dtbs_dir = os.path.join(image_fullname, kernel_name)
 
         for task in cls.install_task:
             src_path, dst_path = task
+
+            src_fullpath = os.path.join(kernel_dir, src_path)
+
+            # If default path doesn't exist, try DTB deploy path
+            if not os.path.exists(src_fullpath):
+                src_path = os.path.join(dtbs_dir, src_path)
+                src_fullpath = os.path.join(kernel_dir, src_path)
+
+                if not os.path.exists(src_fullpath):
+                    raise WicError("Couldn't find %s, exiting" % src_fullpath)
+
             logger.debug('Install %s as %s', src_path, dst_path)
             install_cmd = "install -m 0644 -D %s %s" \
                           % (os.path.join(kernel_dir, src_path),
-- 
2.47.3

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20251008062849.52090-1-badrikesh.prusty%40siemens.com.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-08  7:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <ixzytHYnTmI>
2025-10-08  6:22 ` [PATCH v2] image: copy DTB_FILES to DEPLOYDIR/IMAGE_FULLNAME/KERNEL_NAME/ 'Badrikesh Prusty' via isar-users
2025-10-08  6:28 'Badrikesh Prusty' via isar-users

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox