File chain-addon-command.patch of Package grub2
--- grub-2.12/include/grub/efi/api.h 2024-06-27 11:18:54.416856176 +0200
+++ grub-2.12-new/include/grub/efi/api.h 2024-06-27 11:19:27.384787381 +0200
@@ -394,6 +394,11 @@
{ 0x93, 0x87, 0x6d, 0x87, 0x60, 0x50, 0xdc, 0x67 } \
}
+#define SYSTEMD_ADDON_MEDIA_GUID \
+ { 0x97ac68bf, 0xc741, 0x4bbb, \
+ { 0xb7, 0xbf, 0x7f, 0x6c, 0xcc, 0x00, 0x8a, 0x7e } \
+ }
+
struct grub_efi_sal_system_table
{
grub_uint32_t signature;
--- grub-2.12/grub-core/loader/efi/chainloader.c 2024-06-27 11:18:53.684861720 +0200
+++ grub-2.12-new/grub-core/loader/efi/chainloader.c 2024-06-27 11:26:02.544459462 +0200
@@ -53,6 +53,10 @@
GRUB_MOD_LICENSE ("GPLv3+");
static grub_dl_t my_mod;
+static char **addons;
+static int n_addons;
+static grub_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
+static grub_guid_t systemd_addon_guid = SYSTEMD_ADDON_MEDIA_GUID;
#ifdef SUPPORT_SECURE_BOOT
static grub_efi_boolean_t debug_secureboot = 0;
@@ -733,7 +737,6 @@ grub_cmd_chainloader (grub_command_t cmd
file_path = make_file_path (dp, filename);
if (file_path == NULL)
goto fail;
-
grub_printf ("file path: ");
grub_efi_print_device_path (file_path);
}
@@ -875,6 +878,47 @@ grub_cmd_chainloader (grub_command_t cmd
}
loaded_image->device_handle = dev_handle;
+ /* Load addons by uefi protocole */
+ grub_efi_device_path_t *orig_dp = NULL;
+ grub_efi_device_path_t **addons_dp = NULL, **iterator_dp = NULL;
+
+ status = b->handle_protocol (dev_handle,
+ (void *) &device_path_guid, (void **) &orig_dp);
+ if (status != GRUB_EFI_SUCCESS)
+ {
+ grub_dprintf ("chain", "Failed to handle device path protocole\n");
+ goto fail;
+ }
+
+ addons_dp = grub_calloc(n_addons, sizeof(grub_efi_device_path_t *));
+ iterator_dp = addons_dp;
+
+ for (int idx = 0; idx < n_addons; idx++)
+ {
+ *iterator_dp = make_file_path(orig_dp, addons[idx]);
+ if (*iterator_dp == NULL)
+ {
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+ goto fail;
+ }
+ iterator_dp++;
+ }
+ *iterator_dp = NULL;
+
+ status = b->install_multiple_protocol_interfaces (&dev_handle,
+ &systemd_addon_guid,
+ addons_dp, NULL);
+ if (status == GRUB_EFI_OUT_OF_RESOURCES)
+ {
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+ goto fail;
+ }
+ else if (status != GRUB_EFI_SUCCESS)
+ {
+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("failed to install protocols"));
+ goto fail;
+ }
+
/* Build load options with arguments from chainloader command line. */
if (cmdline)
{
@@ -914,16 +958,39 @@ grub_cmd_chainloader (grub_command_t cmd
return grub_errno;
}
-static grub_command_t cmd;
+static grub_err_t
+grub_cmd_addon (grub_command_t cmd __attribute__ ((unused)),
+ int argc, char *argv[])
+{
+ addons = grub_realloc(addons, argc * sizeof(addons));
+ if (! addons)
+ {
+ grub_free(addons);
+ return grub_errno;
+ }
+ for (int i = 0; i < argc; i++)
+ {
+ grub_size_t file_size = grub_strlen(argv[i]);
+ addons[n_addons] = grub_calloc(file_size +1, sizeof(char *));
+ grub_memcpy(addons[n_addons++], argv[i], file_size);
+ }
+
+ return GRUB_ERR_NONE;
+}
+
+static grub_command_t cmd_chainloader, cmd_addon;
GRUB_MOD_INIT(chainloader)
{
- cmd = grub_register_command ("chainloader", grub_cmd_chainloader,
+ cmd_chainloader = grub_register_command ("chainloader", grub_cmd_chainloader,
0, N_("Load another boot loader."));
+ cmd_addon = grub_register_command ("add-on", grub_cmd_addon,
+ 0, N_("Load addon for the chainloaded boot loader."));
my_mod = mod;
}
GRUB_MOD_FINI(chainloader)
{
- grub_unregister_command (cmd);
+ grub_unregister_command (cmd_chainloader);
+ grub_unregister_command (cmd_addon);
}