Skip to content

Commit

Permalink
multiboot2: support AMD SKINIT
Browse files Browse the repository at this point in the history
Signed-off-by: Krystian Hebel <[email protected]>
Signed-off-by: Sergii Dmytruk <[email protected]>
  • Loading branch information
krystian-hebel authored and SergiiDmytruk committed Feb 26, 2024
1 parent c90cc21 commit 6035d01
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
12 changes: 9 additions & 3 deletions grub-core/loader/multiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <grub/memory.h>
#include <grub/i18n.h>
#if defined (__i386__) || defined (__x86_64__)
#include <grub/i386/skinit.h>
#include <grub/i386/slaunch.h>
#include <grub/i386/txt.h>
#endif
Expand Down Expand Up @@ -176,6 +177,11 @@ normal_boot (struct grub_relocator *rel, struct grub_relocator32_state state)
state.ecx = slparams->dce_size;
state.edx = 0;
}
else if (state.edi == SLP_AMD_SKINIT)
{
state.eax = slparams->dce_base;
state.edi = SLP_AMD_SKINIT;
}

grub_relocator32_boot (rel, state, 0);
}
Expand Down Expand Up @@ -206,10 +212,10 @@ grub_multiboot_boot (void)
return err;

#ifdef GRUB_USE_MULTIBOOT2
if (grub_slaunch_platform_type () == SLP_INTEL_TXT)
if (grub_slaunch_platform_type () != SLP_NONE)
{
err = grub_multiboot2_prepare_slaunch_txt (state.MULTIBOOT_MBI_REGISTER,
mbi_size);
err = grub_multiboot2_prepare_slaunch (state.MULTIBOOT_MBI_REGISTER,
mbi_size);
if (err)
return err;
}
Expand Down
8 changes: 4 additions & 4 deletions grub-core/loader/multiboot_elfxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
(long) mld->align, mld->preference, load_size,
mld->avoid_efi_boot_services);

if (grub_slaunch_platform_type () == SLP_INTEL_TXT)
if (grub_slaunch_platform_type () != SLP_NONE)
{
#ifndef GRUB_USE_MULTIBOOT2
return grub_error (GRUB_ERR_BAD_OS, "Only multiboot2 supported for slaunch");
Expand Down Expand Up @@ -158,7 +158,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
grub_dprintf ("multiboot_loader", "load_base_addr=0x%lx, source=0x%lx\n",
(long) mld->load_base_addr, (long) source);

if (grub_slaunch_platform_type () == SLP_INTEL_TXT)
if (grub_slaunch_platform_type () != SLP_NONE)
{
#ifndef GRUB_USE_MULTIBOOT2
return grub_error (GRUB_ERR_BAD_OS, "Only multiboot2 supported for slaunch");
Expand Down Expand Up @@ -189,7 +189,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
{
mld->load_base_addr = mld->link_base_addr;
/* TODO: support non-relocatable */
if (grub_slaunch_platform_type () == SLP_INTEL_TXT)
if (grub_slaunch_platform_type () != SLP_NONE)
return grub_error (GRUB_ERR_BAD_OS, "Non-relocatable ELF not supported with slaunch");
}

Expand Down Expand Up @@ -247,7 +247,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
}
}

if (grub_slaunch_platform_type () == SLP_INTEL_TXT)
if (grub_slaunch_platform_type () != SLP_NONE)
{
slparams->mle_header_offset = 0xffffffff;

Expand Down
46 changes: 31 additions & 15 deletions grub-core/loader/multiboot_mbi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <grub/net.h>
#include <grub/lib/cmdline.h>
#include <grub/i386/memory.h>
#include <grub/i386/skinit.h>
#include <grub/i386/slaunch.h>
#include <grub/i386/txt.h>
#include <grub/slr_table.h>
Expand Down Expand Up @@ -1187,25 +1188,37 @@ add_multiboot2_slrt_policy_entries (void)
}

grub_err_t
grub_multiboot2_prepare_slaunch_txt (grub_uint32_t mbi_target,
grub_uint32_t mbi_size)
grub_multiboot2_prepare_slaunch (grub_uint32_t mbi_target,
grub_uint32_t mbi_size)
{
grub_err_t err;
struct grub_slaunch_params *slparams = grub_slaunch_params ();
grub_uint32_t slp = grub_slaunch_platform_type ();

slparams->slr_table_base = GRUB_SLAUNCH_STORE_IN_OS2MLE;
slparams->slr_table_size = GRUB_PAGE_SIZE;
slparams->boot_params_addr = mbi_target;

slparams->slr_table_mem = grub_zalloc (slparams->slr_table_size);
if (slparams->slr_table_mem == NULL)
return GRUB_ERR_OUT_OF_MEMORY;
if (slp == SLP_INTEL_TXT)
{
slparams->slr_table_base = GRUB_SLAUNCH_STORE_IN_OS2MLE;
slparams->slr_table_size = GRUB_PAGE_SIZE;

slparams->slr_table_mem = grub_zalloc (slparams->slr_table_size);
if (slparams->slr_table_mem == NULL)
return GRUB_ERR_OUT_OF_MEMORY;

err = grub_txt_boot_prepare (slparams);
if (err != GRUB_ERR_NONE)
err = grub_txt_boot_prepare (slparams);
if (err != GRUB_ERR_NONE)
return grub_error (err, "TXT boot preparation failed");
}
else if (slp == SLP_AMD_SKINIT)
{
grub_printf ("TXT boot preparation failed");
return err;
err = grub_skinit_boot_prepare (grub_multiboot2_relocator, slparams);
if (err != GRUB_ERR_NONE)
return grub_error (err, "SKINIT preparations have failed");
}
else
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("Unknown secure launcher platform type: %d\n"), slp);

grub_slaunch_add_slrt_policy_entry (18,
GRUB_SLR_ET_MULTIBOOT2_INFO,
Expand All @@ -1214,16 +1227,19 @@ grub_multiboot2_prepare_slaunch_txt (grub_uint32_t mbi_target,
mbi_size,
"Measured MB2 information");
grub_slaunch_add_slrt_policy_entries ();
grub_txt_add_slrt_policy_entries ();
if (slp == SLP_INTEL_TXT)
grub_txt_add_slrt_policy_entries ();
add_multiboot2_slrt_policy_entries ();
grub_slaunch_finish_slr_table ();

grub_dprintf ("multiboot_loader", "slr_table_base = %lx, slr_table_size = %x\n",
(unsigned long) slparams->slr_table_base,
(unsigned) slparams->slr_table_size);
grub_memcpy ((void *)(grub_addr_t) slparams->slr_table_base,
slparams->slr_table_mem,
slparams->slr_table_size);

if (slp == SLP_INTEL_TXT)
grub_memcpy ((void *)(grub_addr_t) slparams->slr_table_base,
slparams->slr_table_mem,
slparams->slr_table_size);

return GRUB_ERR_NONE;
}
4 changes: 2 additions & 2 deletions include/grub/multiboot2.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void grub_multiboot2_set_bootdev (void);
void
grub_multiboot2_add_elfsyms (grub_size_t num, grub_size_t entsize,
unsigned shndx, void *data);
grub_err_t grub_multiboot2_prepare_slaunch_txt (grub_uint32_t mbi_target,
grub_uint32_t mbi_size);
grub_err_t grub_multiboot2_prepare_slaunch (grub_uint32_t mbi_target,
grub_uint32_t mbi_size);

grub_uint32_t grub_multiboot2_get_mmap_count (void);
grub_err_t grub_multiboot2_set_video_mode (void);
Expand Down

0 comments on commit 6035d01

Please sign in to comment.