]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
wic/bootimg-efi: Add support for loading devicetree files
authorJan Kiszka <jan.kiszka@siemens.com>
Sat, 30 Jul 2022 08:24:43 +0000 (10:24 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 2 Aug 2022 10:29:57 +0000 (11:29 +0100)
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 the 'dtb' parameter contains more than one
entry.

Out of scope for now are overlays (only supported by systemd-boot).

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
[Luca: rebased on commit 98e9d435b278 ("wic/bootimg-efi: use cross objcopy when building unified kernel image")]

scripts/lib/wic/plugins/source/bootimg-efi.py

index 57e79f4516f1f9b06526b31a2b3d60b05005b815..634a808d782b1e3724d842f5582e1031dff456ff 100644 (file)
@@ -35,12 +35,12 @@ class BootimgEFIPlugin(SourcePlugin):
     name = 'bootimg-efi'
 
     @classmethod
-    def _copy_additional_files(cls, hdddir, initrd):
-        if initrd:
-            bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
-            if not bootimg_dir:
-                raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
+    def _copy_additional_files(cls, hdddir, initrd, dtb):
+        bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
+        if not bootimg_dir:
+            raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
 
+        if initrd:
             initrds = initrd.split(';')
             for rd in initrds:
                 cp_cmd = "cp %s/%s %s" % (bootimg_dir, rd, hdddir)
@@ -48,6 +48,12 @@ class BootimgEFIPlugin(SourcePlugin):
         else:
             logger.debug("Ignoring missing initrd")
 
+        if dtb:
+            if ';' in dtb:
+                raise WicError("Only one DTB supported, exiting")
+            cp_cmd = "cp %s/%s %s" % (bootimg_dir, dtb, hdddir)
+            exec_cmd(cp_cmd, True)
+
     @classmethod
     def do_configure_grubefi(cls, hdddir, creator, cr_workdir, source_params):
         """
@@ -67,8 +73,9 @@ class BootimgEFIPlugin(SourcePlugin):
                                "get it from %s." % configfile)
 
         initrd = source_params.get('initrd')
+        dtb = source_params.get('dtb')
 
-        cls._copy_additional_files(hdddir, initrd)
+        cls._copy_additional_files(hdddir, initrd, dtb)
 
         if not custom_cfg:
             # Create grub configuration using parameters from wks file
@@ -102,6 +109,9 @@ class BootimgEFIPlugin(SourcePlugin):
                     grubefi_conf += " /%s" % rd
                 grubefi_conf += "\n"
 
+            if dtb:
+                grubefi_conf += "devicetree /%s\n" % dtb
+
             grubefi_conf += "}\n"
 
         logger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg",
@@ -131,9 +141,10 @@ class BootimgEFIPlugin(SourcePlugin):
         loader_conf += "timeout %d\n" % bootloader.timeout
 
         initrd = source_params.get('initrd')
+        dtb = source_params.get('dtb')
 
         if not unified_image:
-            cls._copy_additional_files(hdddir, initrd)
+            cls._copy_additional_files(hdddir, initrd, dtb)
 
         logger.debug("Writing systemd-boot config "
                      "%s/hdd/boot/loader/loader.conf", cr_workdir)
@@ -181,6 +192,9 @@ class BootimgEFIPlugin(SourcePlugin):
                 for rd in initrds:
                     boot_conf += "initrd /%s\n" % rd
 
+            if dtb:
+                boot_conf += "devicetree /%s\n" % dtb
+
         if not unified_image:
             logger.debug("Writing systemd-boot config "
                          "%s/hdd/boot/loader/entries/boot.conf", cr_workdir)
@@ -316,6 +330,15 @@ class BootimgEFIPlugin(SourcePlugin):
                         shutil.copyfileobj(in_file, initrd)
                 initrd.close()
 
+                dtb = source_params.get('dtb')
+                if dtb:
+                    if ';' in dtb:
+                        raise WicError("Only one DTB supported, exiting")
+                    dtb_params = '--add-section .dtb=%s/%s --change-section-vma .dtb=0x40000' % \
+                        (deploy_dir, dtb)
+                else:
+                    dtb_params = ''
+
                 # Searched by systemd-boot:
                 # https://systemd.io/BOOT_LOADER_SPECIFICATION/#type-2-efi-unified-kernel-images
                 install_cmd = "install -d %s/EFI/Linux" % hdddir
@@ -330,6 +353,7 @@ class BootimgEFIPlugin(SourcePlugin):
                 objcopy_cmd += " --change-section-vma .osrel=0x20000"
                 objcopy_cmd += " --add-section .cmdline=%s" % cmdline.name
                 objcopy_cmd += " --change-section-vma .cmdline=0x30000"
+                objcopy_cmd += dtb_params
                 objcopy_cmd += " --add-section .linux=%s/%s" % (staging_kernel_dir, kernel)
                 objcopy_cmd += " --change-section-vma .linux=0x2000000"
                 objcopy_cmd += " --add-section .initrd=%s" % initrd.name