On linux command also it requires to improve the way `StartImage and `LoadImage` is checked.
But first there is things i need to point, while currently the command is did well by printing the hex value of the status of `StartImage` however some UEFI status code documentation is bad and not well documented and some people may experience difficulties for finding out the meaning of the error codes so for most common expectable error codes we need to print descriptive error messages to save them for time and some uncommon print errors on hex. diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c index 78ea07ca8..1ae2328b0 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c @@ -190,6 +190,8 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) grub_efi_boot_services_t *b; grub_efi_status_t status; grub_efi_loaded_image_t *loaded_image; + grub_efi_uintn_t exit_data_size; + grub_efi_char16_t *exit_data = NULL; int len; mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t)); @@ -211,9 +213,15 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) status = b->load_image (0, grub_efi_image_handle, (grub_efi_device_path_t *) mempath, (void *) addr, size, &image_handle); - if (status != GRUB_EFI_SUCCESS) - return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); - + + if (status != GRUB_EFI_SUCCESS) { + if (status == GRUB_EFI_INVALID_PARAMETER) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument"); + else if (status == GRUB_EFI_OUT_OF_RESOURCES) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of resources"); + else + return grub_error (GRUB_ERR_BAD_OS, "cannot load image 0x%" PRIxGRUB_EFI_UINTN_T, status); + } grub_dprintf ("linux", "linux command line: '%s'\n", args); /* Convert command line to UTF-16. */ @@ -235,12 +243,30 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) (grub_uint8_t *) args, len, NULL); grub_dprintf ("linux", "starting image %p\n", image_handle); - status = b->start_image (image_handle, 0, NULL); + status = b->start_image (image_handle, &exit_data_size, &exit_data); /* When successful, not reached */ - grub_error (GRUB_ERR_BAD_OS, "start_image() returned 0x%" PRIxGRUB_EFI_UINTN_T, status); + if (exit_data) + { + char *buf; + + buf = grub_malloc (exit_data_size * 4 + 1); + if (buf) + { + *grub_utf16_to_utf8 ((grub_uint8_t *) buf, + exit_data, exit_data_size) = 0; + + grub_error (GRUB_ERR_BAD_OS, "%s", buf); + grub_free (buf); + } + } + else + grub_error (GRUB_ERR_BAD_OS, "cannot start image 0x%" PRIxGRUB_EFI_UINTN_T, status); + grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, GRUB_EFI_BYTES_TO_PAGES (len)); + if (exit_data) + b->free_pool(exit_data); loaded_image->load_options = NULL; unload: b->unload_image (image_handle); If any improvement, adjustment or any feedback let me know Best regards, khaalid _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel