Hello GRUB Developers,

I hope this message finds you well. During my work with the GRUB
chainloader command in conjunction with grub-to-bootmgr, I encountered
the error message: "failed to load image." This message lacked
sufficient detail to diagnose the underlying issue.

Upon investigation, I discovered that the UEFI Boot Services function
`LoadImage()` was returning various error statuses. However, GRUB's
current implementation handles only a generic error code, omitting
more specific and informative statuses defined in the UEFI
specification.

According to the UEFI Specification (version 2.11), `LoadImage()` can
return multiple error status codes that offer precise information
about the nature of the failure.

Patch:

* loader/efi/chainloader.c (grub_cmd_chainloader): Enhance error
handling by adding specific messages for invalid parameters, image not
found, and unsupported image types based on UEFI LoadImage() error
codes.

```diff
diff --git a/grub-core/loader/efi/chainloader.c
b/grub-core/loader/efi/chainloader.c
index 869307bf3..4fd46dfda 100644
--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -346,6 +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_INVALID_PARAMETER)
+       grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid image parameters");
+      else if (status == GRUB_EFI_NOT_FOUND)
+       grub_error (GRUB_ERR_FILE_NOT_FOUND, "Image not found");
+      else if (status == GRUB_EFI_UNSUPPORTED)
+       grub_error (GRUB_ERR_BAD_OS, "Unsupported image type");
     else
      grub_error (GRUB_ERR_BAD_OS, "Cannot load image");
   }
```diff

While this patch addresses some of the most common error statuses, the
UEFI `LoadImage()` function defines 11 return status codes (excluding
EFI_SUCCESS). Future enhancements could aim to cover additional
statuses for more informative messages.

Best regards,
Khaalid

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

Reply via email to