[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] efi: Copy load_options into environment
From: |
Jordan Webb |
Subject: |
[PATCH] efi: Copy load_options into environment |
Date: |
Tue, 8 Dec 2020 20:39:50 -0600 |
When GRUB is loaded as an EFI application, it will copy the EFI
LoadOptions into an environment variable called "efi_load_options" and
export it.
My use case for this is to pass along arguments generated by the
Raspberry Pi's internal bootloader from U-Boot to GRUB to a Linux
kernel, but I think it's something that could be generally useful to
other people doing interesting things in EFI environments.
---
grub-core/kern/efi/init.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c
index 2c31847bf..29281c3c5 100644
--- a/grub-core/kern/efi/init.c
+++ b/grub-core/kern/efi/init.c
@@ -17,6 +17,7 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <grub/charset.h>
#include <grub/efi/efi.h>
#include <grub/efi/console.h>
#include <grub/efi/disk.h>
@@ -31,6 +32,10 @@ grub_addr_t grub_modbase;
void
grub_efi_init (void)
{
+ grub_efi_loaded_image_t *image = NULL;
+ int len;
+ char *load_options;
+
grub_modbase = grub_efi_modules_addr ();
/* First of all, initialize the console so that GRUB can display
messages. */
@@ -43,6 +48,14 @@ grub_efi_init (void)
0, 0, 0, NULL);
grub_efidisk_init ();
+
+ /* Copy EFI load options into environment */
+ image = grub_efi_get_loaded_image (grub_efi_image_handle);
+ len = image->load_options_size / sizeof (grub_efi_char16_t);
+ load_options = grub_malloc (len * sizeof (char));
+ *grub_utf16_to_utf8 ((grub_uint8_t *) load_options, image->load_options,
len) = '\0';
+ grub_env_set("efi_load_options", load_options);
+ grub_env_export("efi_load_options");
}
void (*grub_efi_net_config) (grub_efi_handle_t hnd,
--
2.24.3 (Apple Git-128)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] efi: Copy load_options into environment,
Jordan Webb <=