public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: isar-users <isar-users@googlegroups.com>
Cc: Henning Schild <henning.schild@siemens.com>
Subject: [PATCH 9/9] wic: bootimg-efi-isar: Sync with latest upstream changes
Date: Fri,  5 Aug 2022 20:51:44 +0200	[thread overview]
Message-ID: <8341c6f1875328531a6c50cf9724a856d71d3e90.1659725504.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1659725504.git.jan.kiszka@siemens.com>

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

Specifically brings in DTB support for grub and systemd-boot.

It also changes the generation of unified kernel images in a way that
is definitely not compatible with Isar. Not sure if this feature was
used before (isar-cip-core uses EFI Boot Guard for that purpose), but
it's still patched here to not call non-existing objcopy binaries, just
in case.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 .../wic/plugins/source/bootimg-efi-isar.py    | 97 +++++++++++--------
 1 file changed, 59 insertions(+), 38 deletions(-)

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..6e6cd6ec 100644
--- a/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py
+++ b/meta/scripts/lib/wic/plugins/source/bootimg-efi-isar.py
@@ -40,6 +40,26 @@ class BootimgEFIPlugin(SourcePlugin):
 
     name = 'bootimg-efi-isar'
 
+    @classmethod
+    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)
+                exec_cmd(cp_cmd, True)
+        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):
         """
@@ -59,18 +79,9 @@ class BootimgEFIPlugin(SourcePlugin):
                                "get it from %s." % configfile)
 
         initrd = source_params.get('initrd')
+        dtb = source_params.get('dtb')
 
-        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)
-                exec_cmd(cp_cmd, True)
-        else:
-            logger.debug("Ignoring missing initrd")
+        cls._copy_additional_files(hdddir, initrd, dtb)
 
         if not custom_cfg:
             # Create grub configuration using parameters from wks file
@@ -108,6 +119,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",
@@ -129,25 +143,18 @@ class BootimgEFIPlugin(SourcePlugin):
 
         bootloader = creator.ks.bootloader
 
+        unified_image = source_params.get('create-unified-kernel-image') == "true"
+
         loader_conf = ""
-        if source_params.get('create-unified-kernel-image') != "true":
+        if not unified_image:
             loader_conf += "default boot\n"
         loader_conf += "timeout %d\n" % bootloader.timeout
 
         initrd = source_params.get('initrd')
+        dtb = source_params.get('dtb')
 
-        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)
-                exec_cmd(cp_cmd, True)
-        else:
-            logger.debug("Ignoring missing initrd")
+        if not unified_image:
+            cls._copy_additional_files(hdddir, initrd, dtb)
 
         logger.debug("Writing systemd-boot config "
                      "%s/hdd/boot/loader/loader.conf", cr_workdir)
@@ -197,7 +204,10 @@ class BootimgEFIPlugin(SourcePlugin):
                 for rd in initrds:
                     boot_conf += "initrd /%s\n" % rd
 
-        if source_params.get('create-unified-kernel-image') != "true":
+            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)
             cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w")
@@ -332,27 +342,38 @@ 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
                 exec_cmd(install_cmd)
 
                 staging_dir_host = get_bitbake_var("STAGING_DIR_HOST")
+                target_sys = get_bitbake_var("TARGET_SYS")
 
                 # https://www.freedesktop.org/software/systemd/man/systemd-stub.html
-                objcopy_cmd = "objcopy \
-                    --add-section .osrel=%s --change-section-vma .osrel=0x20000 \
-                    --add-section .cmdline=%s --change-section-vma .cmdline=0x30000 \
-                    --add-section .linux=%s --change-section-vma .linux=0x2000000 \
-                    --add-section .initrd=%s --change-section-vma .initrd=0x3000000 \
-                    %s %s" % \
-                    ("%s/usr/lib/os-release" % staging_dir_host,
-                    cmdline.name,
-                    "%s/%s" % (staging_kernel_dir, kernel),
-                    initrd.name,
-                    efi_stub,
-                    "%s/EFI/Linux/linux.efi" % hdddir)
-                exec_cmd(objcopy_cmd)
+                objcopy_cmd = "%s-objcopy" % target_sys
+                # Isar runs this natively
+                objcopy_cmd = "objcopy"
+                objcopy_cmd += " --add-section .osrel=%s/usr/lib/os-release" % staging_dir_host
+                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
+                objcopy_cmd += " --change-section-vma .initrd=0x3000000"
+                objcopy_cmd += " %s %s/EFI/Linux/linux.efi" % (efi_stub, hdddir)
+                exec_native_cmd(objcopy_cmd, native_sysroot)
         else:
             install_cmd = "install -m 0644 %s/%s %s/%s" % \
                 (staging_kernel_dir, kernel, hdddir, kernel)
-- 
2.35.3


  parent reply	other threads:[~2022-08-05 18:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05 18:51 [PATCH 0/9] Update wic Jan Kiszka
2022-08-05 18:51 ` [PATCH 1/9] wic: added fspassno parameter to partition Jan Kiszka
2022-08-05 18:51 ` [PATCH 2/9] wic/plugins/images/direct: Allow changes in fstab on rootfs Jan Kiszka
2022-08-05 18:51 ` [PATCH 3/9] wic: fix WicError message Jan Kiszka
2022-08-05 18:51 ` [PATCH 4/9] wic/plugins/rootfs: Fix NameError for 'orig_path' Jan Kiszka
2022-08-05 18:51 ` [PATCH 5/9] wic: add target tools to PATH when executing native commands Jan Kiszka
2022-08-05 18:51 ` [PATCH 6/9] wic/bootimg-efi: use cross objcopy when building unified kernel image Jan Kiszka
2022-08-05 18:51 ` [PATCH 7/9] wic/bootimg-efi: Factor out some common bits Jan Kiszka
2022-08-05 18:51 ` [PATCH 8/9] wic/bootimg-efi: Add support for loading devicetree files Jan Kiszka
2022-08-05 18:51 ` Jan Kiszka [this message]
2022-08-15  8:23 ` [PATCH 0/9] Update wic Anton Mikanovich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8341c6f1875328531a6c50cf9724a856d71d3e90.1659725504.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=henning.schild@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox