On 5/7/25 9:21 AM, khaliid caliy wrote:
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");
These seem like common errors. The same things is mostly repeated in the
other patch too. One idea is to make a GRUB error message printer. Maybe
use a va_list if there is extra information to take on. An empty list
would just print out a simple standard message like most of yours do.
Anyway just a thought, maybe not worth it.
Thanks
Ross
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://urldefense.com/v3/__https://lists.gnu.org/mailman/listinfo/grub-devel__;!!ACWV5N9M2RV99hQ!JkkQTX5bp5kODtzztV6SRRWpI-ydYF8UzAo_rJ55QKqKS4vLQRbiLnnOHZkgLHDpltY8T_wC1GDYYAeAywUP_9ILQA$
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel