Skip to content

Commit

Permalink
Make efi machines load an env block from a variable
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Jones <pjones@redhat.com>
  • Loading branch information
vathpela authored and martinezjavier committed Jun 11, 2021
1 parent e57a521 commit 636612c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions grub-core/Makefile.core.def
Expand Up @@ -207,6 +207,7 @@ kernel = {
efi = kern/efi/acpi.c;
efi = kern/efi/sb.c;
efi = kern/lockdown.c;
efi = lib/envblk.c;
i386_coreboot = kern/i386/pc/acpi.c;
i386_multiboot = kern/i386/pc/acpi.c;
i386_coreboot = kern/acpi.c;
Expand Down
36 changes: 35 additions & 1 deletion grub-core/kern/efi/init.c
Expand Up @@ -27,8 +27,11 @@
#include <grub/env.h>
#include <grub/mm.h>
#include <grub/kernel.h>

#include <grub/stack_protector.h>

#include <grub/lib/envblk.h>

#ifdef GRUB_STACK_PROTECTOR

static grub_efi_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID;
Expand Down Expand Up @@ -82,6 +85,36 @@ stack_protector_init (void)

grub_addr_t grub_modbase;

#define GRUB_EFI_GRUB_VARIABLE_GUID \
{ 0x91376aff, 0xcba6, 0x42be, \
{ 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
}

/* Helper for grub_efi_env_init */
static int
set_var (const char *name, const char *value,
void *whitelist __attribute__((__unused__)))
{
grub_env_set (name, value);
return 0;
}

static void
grub_efi_env_init (void)
{
grub_efi_guid_t efi_grub_guid = GRUB_EFI_GRUB_VARIABLE_GUID;
struct grub_envblk envblk_s = { NULL, 0 };
grub_envblk_t envblk = &envblk_s;

grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid, &envblk_s.size,
(void **) &envblk_s.buf);
if (!envblk_s.buf || envblk_s.size < 1)
return;

grub_envblk_iterate (envblk, NULL, set_var);
grub_free (envblk_s.buf);
}

void
grub_efi_init (void)
{
Expand All @@ -108,10 +141,11 @@ grub_efi_init (void)
efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
0, 0, 0, NULL);

grub_efi_env_init ();
grub_efidisk_init ();
}

void (*grub_efi_net_config) (grub_efi_handle_t hnd,
void (*grub_efi_net_config) (grub_efi_handle_t hnd,
char **device,
char **path);

Expand Down

0 comments on commit 636612c

Please sign in to comment.