Hi Shoudi Li,

On 6/24/26 4:35 AM, Shoudi Li via lists.openembedded.org wrote:
[You don't often get email from 
[email protected]. Learn why this is important at 
https://aka.ms/LearnAboutSenderIdentification ]

For machine with multiple dtbs specified, we need to merge dtb overlays
to base and pass the merged dtb to ukify to create UKI.
Walks UKI_DEVICETREE, splits entries into base_dtbs (.dtb) and overlays,
and validates all paths exist. For each base DTB, finds matching overlays
by checking whether the overlay filename starts with the base DTB name.

If matches exist, runs fdtoverlay -i <base> <overlays…> -o <B>/<base>-merged.dtb
and passes the merged file to ukify.
If no overlays match, passes the base DTB directly — no change in behaviour for
DTB-only boards.

Signed-off-by: Shoudi Li <[email protected]>
---
  meta/classes-recipe/uki.bbclass | 28 ++++++++++++++++++++++++++--
  1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/meta/classes-recipe/uki.bbclass b/meta/classes-recipe/uki.bbclass
index fa1c95603b..03eb9eafbd 100644
--- a/meta/classes-recipe/uki.bbclass
+++ b/meta/classes-recipe/uki.bbclass
@@ -61,6 +61,7 @@
  #

  DEPENDS += "\
+    dtc-native \
      os-release \
      systemd-boot \
      systemd-boot-native \
@@ -150,16 +151,39 @@ python do_uki() {
      if cmdline:
          ukify_cmd += " --cmdline='%s'" % (cmdline)

-    # dtb
+    # dtb: separate base DTBs from overlays, merge each base with its matching 
overlays
      uki_devicetree = d.getVar('UKI_DEVICETREE')
      if uki_devicetree:
+        base_dtbs = []
+        overlays = []
          for dtb in uki_devicetree.split():
              # DTBs are without sub-directories in deploy_dir
              dtb_name = os.path.basename(dtb)
              dtb_path = "%s/%s" % (deploy_dir_image, dtb_name)
              if not os.path.exists(dtb_path):
                  bb.fatal(f"ERROR: cannot find {dtb_path}.")
-            ukify_cmd += " --devicetree %s" % (dtb_path)
+            if dtb_name.endswith('.dtbo'):
+                overlays.append(dtb_path)
+            else:
+                base_dtbs.append(dtb_path)
+
+        fdtoverlay_bin = os.path.join(d.getVar('STAGING_BINDIR_NATIVE'), 
'fdtoverlay')
+        build_dir = d.getVar('B')
+        for base_dtb in base_dtbs:
+            base_name = os.path.splitext(os.path.basename(base_dtb))[0]
+            # Overlays whose filename starts with the base DTB name
+            matching_overlays = [o for o in overlays
+                                  if 
os.path.basename(o).startswith(base_name)]> +            if matching_overlays:
+                merged_dtb = os.path.join(build_dir, "%s-merged.dtb" % 
base_name)
+                fdtoverlay_cmd = "%s -i %s %s -o %s" % (
+                    fdtoverlay_bin, base_dtb, " ".join(matching_overlays), 
merged_dtb)
+                bb.debug(2, "uki: merging DTBs: %s" % fdtoverlay_cmd)
+                out, err = bb.process.run(fdtoverlay_cmd, shell=True)

Please do not use shell=True except absolutely required (and even then, we should really be thinking hard about not doing that). See recent patches on the ML where we started to migrate away from this.

Cheers,
Quentin
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#239493): 
https://lists.openembedded.org/g/openembedded-core/message/239493
Mute This Topic: https://lists.openembedded.org/mt/119953784/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to