public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] wic: bootimg-efi-isar: Add support for loading device tree files
@ 2022-07-10 20:51 Jan Kiszka
  2022-07-11 13:12 ` Henning Schild
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kiszka @ 2022-07-10 20:51 UTC (permalink / raw)
  To: isar-users

From: Jan Kiszka <jan.kiszka@siemens.com>

For device tree using systems, add support to set a custom devices tree
during UEFI boot. This requires to copy the DTB file to the boot
partition and to add the respective loader entries to the configuration
files.

Both grub and systemd-boot support only loading a specific device tree.
Therefore refuse to work if DTB_FILES contains more than one entry.

This has been tested with grub from bullseye and systemd from
bullseye-backport. The latter is needed as only systemd 250 gained the
required feature.

Out of scope are overlays (only supported by systemd-boot) as well as
unified kernel images (practically broken on non-x86 with current
toolchains).

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 meta/classes/imagetypes_wic.bbclass           |  2 +-
 .../wic/plugins/source/bootimg-efi-isar.py    | 39 +++++++++++++------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/meta/classes/imagetypes_wic.bbclass b/meta/classes/imagetypes_wic.bbclass
index 61a74d4a..3a577f71 100644
--- a/meta/classes/imagetypes_wic.bbclass
+++ b/meta/classes/imagetypes_wic.bbclass
@@ -106,7 +106,7 @@ WICVARS += "\
            ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS TRANSLATED_TARGET_ARCH"
 
 # Isar specific vars used in our plugins
-WICVARS += "DISTRO DISTRO_ARCH"
+WICVARS += "DISTRO DISTRO_ARCH DTB_FILES"
 
 python do_rootfs_wicenv () {
     wicvars = d.getVar('WICVARS', True)
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 a24e04f3..aff51e81 100644
--- a/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py
+++ b/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py
@@ -58,13 +58,12 @@ class BootimgEFIPlugin(SourcePlugin):
                 raise WicError("configfile is specified but failed to "
                                "get it from %s." % configfile)
 
-        initrd = source_params.get('initrd')
+        bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
+        if not bootimg_dir:
+            raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
 
+        initrd = source_params.get('initrd')
         if initrd:
-            bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
-            if not bootimg_dir:
-                raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
-
             initrds = initrd.split(';')
             for rd in initrds:
                 cp_cmd = "cp %s/%s %s" % (bootimg_dir, rd, hdddir)
@@ -72,6 +71,13 @@ class BootimgEFIPlugin(SourcePlugin):
         else:
             logger.debug("Ignoring missing initrd")
 
+        dtb_files = (get_bitbake_var("DTB_FILES") or '').split()
+        if dtb_files:
+            if len(dtb_files) > 1:
+                raise WicError("Only one DTB support in grub configuration, exiting")
+            cp_cmd = "cp %s/%s %s" % (bootimg_dir, dtb_files[0], hdddir)
+            exec_cmd(cp_cmd, True)
+
         if not custom_cfg:
             # Create grub configuration using parameters from wks file
             bootloader = creator.ks.bootloader
@@ -108,6 +114,9 @@ class BootimgEFIPlugin(SourcePlugin):
                     grubefi_conf += " /%s" % rd
                 grubefi_conf += "\n"
 
+            if dtb_files:
+                grubefi_conf += "devicetree /%s\n" % dtb_files[0]
+
             grubefi_conf += "}\n"
 
         logger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg",
@@ -134,14 +143,12 @@ class BootimgEFIPlugin(SourcePlugin):
             loader_conf += "default boot\n"
         loader_conf += "timeout %d\n" % bootloader.timeout
 
-        initrd = source_params.get('initrd')
+        bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
+        if not bootimg_dir:
+            raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
 
+        initrd = source_params.get('initrd')
         if initrd and source_params.get('create-unified-kernel-image') != "true":
-            # obviously we need to have a common common deploy var
-            bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
-            if not bootimg_dir:
-                raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
-
             initrds = initrd.split(';')
             for rd in initrds:
                 cp_cmd = "cp %s/%s %s" % (bootimg_dir, rd, hdddir)
@@ -149,6 +156,13 @@ class BootimgEFIPlugin(SourcePlugin):
         else:
             logger.debug("Ignoring missing initrd")
 
+        dtb_files = (get_bitbake_var("DTB_FILES") or '').split()
+        if dtb_files:
+            if len(dtb_files) > 1:
+                raise WicError("Only one DTB support in grub configuration, exiting")
+            cp_cmd = "cp %s/%s %s" % (bootimg_dir, dtb_files[0], hdddir)
+            exec_cmd(cp_cmd, True)
+
         logger.debug("Writing systemd-boot config "
                      "%s/hdd/boot/loader/loader.conf", cr_workdir)
         cfg = open("%s/hdd/boot/loader/loader.conf" % cr_workdir, "w")
@@ -197,6 +211,9 @@ class BootimgEFIPlugin(SourcePlugin):
                 for rd in initrds:
                     boot_conf += "initrd /%s\n" % rd
 
+            if dtb_files:
+                boot_conf += "devicetree /%s\n" % dtb_files[0]
+
         if source_params.get('create-unified-kernel-image') != "true":
             logger.debug("Writing systemd-boot config "
                          "%s/hdd/boot/loader/entries/boot.conf", cr_workdir)
-- 
2.35.3

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

end of thread, other threads:[~2022-07-11 16:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-10 20:51 [PATCH] wic: bootimg-efi-isar: Add support for loading device tree files Jan Kiszka
2022-07-11 13:12 ` Henning Schild
2022-07-11 15:14   ` Jan Kiszka
2022-07-11 16:12     ` Henning Schild
2022-07-11 16:31       ` Jan Kiszka

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