This patch addresses some undescriptive error messages that grub
chainloader command returns when issue encountered, specifically
during the loading of the uefi image or starting the image.

As per uefi UEFI specification (2.11) boot service functions
`StartImage()` and `LoadImage` return error codes that describe the
issue happened, which the command didn't check and suppressed it. The
current implementation of the command prints some generic error
messages like "unknown error", "cannot load image". Which doesn't tell
much of the nature of the issue and what happened.

So my patch addresses the command error message and prints the error
based on the return value of the functions or else prints the status
code returned by the functions.

diff --git a/grub-core/loader/efi/chainloader.c
b/grub-core/loader/efi/chainloader.c
index 869307bf3..c0ef37489 100644
--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -91,7 +91,7 @@ grub_chainloader_boot (void *context)
           }
       }
      else
-       grub_error (GRUB_ERR_BAD_OS, "unknown error");
+       grub_error (GRUB_ERR_BAD_OS, "cannot start image 0x%"
PRIxGRUB_EFI_UINTN_T, status);
    }

  if (exit_data)
@@ -346,8 +346,12 @@ grub_cmd_chainloader (grub_command_t cmd
__attribute__ ((unused)),
    {
      if (status == GRUB_EFI_OUT_OF_RESOURCES)
       grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of resources");
+      else if (status == GRUB_EFI_UNSUPPORTED)
+       grub_error(GRUB_ERR_BAD_OS, "image is not supported");
+      else if (status == GRUB_EFI_INVALID_PARAMETER)
+       grub_error(GRUB_ERR_BAD_ARGUMENT, "invalid argument");
      else
-       grub_error (GRUB_ERR_BAD_OS, "cannot load image");
+       grub_error (GRUB_ERR_BAD_OS, "cannot load image 0x%"
PRIxGRUB_EFI_UINTN_T, status);

      goto fail;
    }

Checking error messages is important and may save time for users or
professionals. So please let me know for any improvement, adjustment
or any other feedback.

Thanks best regards khaalid

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to