All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Davis Jr <vince@underview.tech>
To: openembedded-core@lists.openembedded.org
Cc: Vincent Davis Jr <vince@underview.tech>
Subject: [OE-core][PATCH v3 3/8] bootimg_efi: copy grub modules
Date: Fri,  5 Sep 2025 12:41:31 -0400	[thread overview]
Message-ID: <20250905164136.2896809-3-vince@underview.tech> (raw)
In-Reply-To: <20250905164136.2896809-1-vince@underview.tech>

Assumming all grub modules weren't embedded
into boot*.efi (core.img) copy them now.

This commit populates the common partition
used to store the grub config and grub modules
for both PCBIOS and EFI.

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
---
 scripts/lib/wic/plugins/source/bootimg_efi.py | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/scripts/lib/wic/plugins/source/bootimg_efi.py b/scripts/lib/wic/plugins/source/bootimg_efi.py
index 98be12160c..c3254033d6 100644
--- a/scripts/lib/wic/plugins/source/bootimg_efi.py
+++ b/scripts/lib/wic/plugins/source/bootimg_efi.py
@@ -350,7 +350,39 @@ class BootimgEFIPlugin(SourcePlugin):
                             (kernel_dir, mod, hdddir, mod[9:])
                         exec_cmd(cp_cmd, True)
                 else:
+                    # Assumming all grub modules weren't embedded
+                    # into grub.efi or core.img copy them now.
+                    copy_types = [ '*.mod', '*.o', '*.lst' ]
+
+                    # It appears the EFI directory resides after
+                    # initial population of the EFI System partition
+                    # in the if statement above. Remove so that the
+                    # partition doesn't contain any unrequired files.
                     shutil.rmtree("%s/EFI" % hdddir)
+
+                    hdddir = "%s/hdd" % cr_workdir
+
+                    staging_libdir = cls._get_staging_libdir()
+
+                    grub_format = get_bitbake_var('GRUB_MKIMAGE_FORMAT_EFI')
+                    if not grub_format:
+                        grub_format = 'x86_64-efi'
+
+                    grub_prefix_path = get_bitbake_var('GRUB_PREFIX_PATH')
+                    if not grub_prefix_path:
+                        grub_prefix_path = '/boot/grub'
+
+                    # Copy grub modules
+                    install_dir = '%s/%s/%s' % (hdddir, grub_prefix_path, grub_format)
+                    os.makedirs(install_dir, exist_ok=True)
+
+                    for ctype in copy_types:
+                        files = glob('%s/grub/%s/%s' % \
+                            (staging_libdir, grub_format, ctype))
+                        for file in files:
+                            shutil.copy2(file, install_dir, follow_symlinks=True)
+
+                    # bootimg_pcbios calles prepare_rootfs no need to here.
                     return 0
             elif source_params['loader'] == 'grub-efi':
                 shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir,
@@ -457,3 +489,24 @@ class BootimgEFIPlugin(SourcePlugin):
 
         part.size = int(bootimg_size)
         part.source_file = bootimg
+
+    @classmethod
+    def _get_staging_libdir(cls):
+        """
+        For unknown reasons when running test with poky
+        STAGING_LIBDIR gets unset when wic create is executed.
+        Bellow is a hack to determine what STAGING_LIBDIR should
+        be if not specified.
+        """
+
+        staging_libdir = get_bitbake_var('STAGING_LIBDIR')
+        staging_dir_target = get_bitbake_var('STAGING_DIR_TARGET')
+
+        if not staging_libdir:
+            staging_libdir = '%s/usr/lib64' % staging_dir_target
+            if not os.path.isdir(staging_libdir):
+                staging_libdir = '%s/usr/lib32' % staging_dir_target
+                if not os.path.isdir(staging_libdir):
+                    staging_libdir = '%s/usr/lib' % staging_dir_target
+
+        return staging_libdir
-- 
2.43.0



  parent reply	other threads:[~2025-09-05 16:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 16:41 [OE-core][PATCH v3 1/8] bootimg_pcbios: support grub hybrid boot Vincent Davis Jr
2025-09-05 16:41 ` [OE-core][PATCH v3 2/8] bootimg_efi: " Vincent Davis Jr
2025-09-05 16:41 ` Vincent Davis Jr [this message]
2025-09-05 16:41 ` [OE-core][PATCH v3 4/8] bootimg_pcbios: update default boot timeout to zero Vincent Davis Jr
2025-09-05 16:41 ` [OE-core][PATCH v3 5/8] bootimg_biosplusefi: add grub only examples Vincent Davis Jr
2025-09-05 16:41 ` [OE-core][PATCH v3 6/8] grub-efi: support custom embedded grub configs Vincent Davis Jr
2025-09-05 16:41 ` [OE-core][PATCH v3 7/8] oe-selftest[wic]: add test_grub_install_biosplusefi Vincent Davis Jr
2025-09-05 16:41 ` [OE-core][PATCH v3 8/8] oe-selftest[wic]: add test_grub_install_biosplusefi_qemu Vincent Davis Jr
2025-09-07 14:02 ` [OE-core][PATCH v3 1/8] bootimg_pcbios: support grub hybrid boot Mathieu Dubois-Briand
2025-09-07 15:47   ` Vincent Davis
2025-09-08 12:25     ` Mathieu Dubois-Briand
2025-09-13  4:29       ` [PATCH " Vincent Davis Jr
2025-09-15 12:17         ` [OE-core] " Mathieu Dubois-Briand

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=20250905164136.2896809-3-vince@underview.tech \
    --to=vince@underview.tech \
    --cc=openembedded-core@lists.openembedded.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.