grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 0/2] EFI chainloader improvement


From: Glenn Washburn
Subject: [PATCH v2 0/2] EFI chainloader improvement
Date: Wed, 31 May 2023 23:16:24 -0500

Changes since v1:
 * Rebase onto latest master
 * Change logic: The device path argument to image load changed back to the way
   it was originally where the argument is set to the device path that $root
   resolves to. If $root does not resolve or is not a device, the argument
   will be NULL as allowed for in the spec. By setting $root to the device of
   the chainloaded file, v1 behavior can be had. So this is more versatile
   behavior.
 * Minor rewording of metadata.

This series improves the EFI chainloader. I've noticed for a while now that
chainloading would fail when root=memdisk. It didn't really make sense because
I was specifying the image to chainload as device+path, so why would it care
about what my root was. But I noticed that if I changed the root to the device
the image file was located on, then chainloading worked. The second patch
fixes this by removing some previous assumptions that I don't believe are
valid (eg. that LoadImage needs a valid device path).

Glenn

Glenn Washburn (2):
  docs: Document extra arguments to chainloader on EFI
  efi/chainloader: Do not require a $root visible to EFI firmware when
    chainloading

 docs/grub.texi                     |  7 +++++--
 grub-core/loader/efi/chainloader.c | 28 +++++++++++++---------------
 2 files changed, 18 insertions(+), 17 deletions(-)

Range-diff against v1:
2:  04edeb1d7fd0 ! 1:  d1fc25518bfc docs: Document that extra arguments to 
chainloader on EFI
    @@ Metadata
     Author: Glenn Washburn <development@efficientek.com>
     
      ## Commit message ##
    -    docs: Document that extra arguments to chainloader on EFI
    +    docs: Document extra arguments to chainloader on EFI
     
         Extra arguments given to chainloader on EFI platforms will be sent to
         the chainloaded application. Also, minor edit in the chainloading 
section
    @@ Commit message
         necessarily in real mode (which does not exist on some achitectures).
     
      ## docs/grub.texi ##
    -@@ docs/grub.texi: information.
    +@@ docs/grub.texi: invoke shutdown machinery.
      Operating systems that do not support Multiboot and do not have specific
      support in GRUB (specific support is available for Linux, FreeBSD, NetBSD
      and OpenBSD) must be chain-loaded, which involves loading another boot
1:  eed74ee4b128 ! 2:  c17d3a8a0fe0 efi/chainloader: Do not require a valid 
$root when chainloading
    @@ Metadata
     Author: Glenn Washburn <development@efficientek.com>
     
      ## Commit message ##
    -    efi/chainloader: Do not require a valid $root when chainloading
    +    efi/chainloader: Do not require a $root visible to EFI firmware when 
chainloading
     
         The EFI chainloader checks that a device path can be created for the 
$root
         device before allowing chainloading to a given file. This is probably 
to
    @@ Commit message
         that is accessible by the firmware, eg. (hd0,1)/efi/boot.efi, would
         fail when root is a location inaccessible by the firmware, eg. memdisk.
     
    -    Use GRUB_EFI_BYTES_TO_PAGES() instead of donig the calculation 
explicitly.
    +    Use GRUB_EFI_BYTES_TO_PAGES() instead of doing the calculation 
explicitly.
     
         Add comment noting the section where the load options for the 
chainloaded
         EFI application is constructed.
    @@ grub-core/loader/efi/chainloader.c
      #include <grub/i18n.h>
      #include <grub/net.h>
     @@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader 
(grub_command_t cmd __attribute__ ((unused)),
    -   if (! file)
    -     goto fail;
      
    --  /* Get the root device's device path.  */
    --  dev = grub_device_open (0);
    +   /* Get the root device's device path.  */
    +   dev = grub_device_open (0);
     -  if (! dev)
     -    goto fail;
     -
    -+  dev = file->device;
    -   if (dev->disk)
    +-  if (dev->disk)
    ++  if (dev == NULL)
    ++    ;
    ++  else if (dev->disk)
          dev_handle = grub_efidisk_get_device_handle (dev->disk);
        else if (dev->net && dev->net->server)
    +     {
     @@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader 
(grub_command_t cmd __attribute__ ((unused)),
        if (dev_handle)
          dp = grub_efi_get_device_path (dev_handle);
    @@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader (grub_command_t 
cmd __a
     -  pages = (((grub_efi_uintn_t) size + ((1 << 12) - 1)) >> 12);
     +  pages = (grub_efi_uintn_t) GRUB_EFI_BYTES_TO_PAGES (size);
      
    -   status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES,
    +   status = b->allocate_pages (GRUB_EFI_ALLOCATE_ANY_PAGES,
                              GRUB_EFI_LOADER_CODE,
     @@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader 
(grub_command_t cmd __attribute__ ((unused)),
          }
    @@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader (grub_command_t 
cmd __a
        if (argc > 1)
          {
            int i, len;
    -@@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader 
(grub_command_t cmd __attribute__ ((unused)),
    -     }
    - 
    -   grub_file_close (file);
    --  grub_device_close (dev);
    - 
    -   /* We're finished with the source image buffer and file path now. */
    -   efi_call_2 (b->free_pages, address, pages);
    -@@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader 
(grub_command_t cmd __attribute__ ((unused)),
    - 
    -  fail:
    - 
    --  if (dev)
    --    grub_device_close (dev);
    --
    -   if (file)
    -     grub_file_close (file);
    - 
-- 
2.34.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]