From 6035d010f6280e2e1450b54423a081e69fbfac58 Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Wed, 30 Dec 2020 10:15:16 +0100 Subject: [PATCH] multiboot2: support AMD SKINIT Signed-off-by: Krystian Hebel Signed-off-by: Sergii Dmytruk --- grub-core/loader/multiboot.c | 12 ++++++-- grub-core/loader/multiboot_elfxx.c | 8 +++--- grub-core/loader/multiboot_mbi2.c | 46 ++++++++++++++++++++---------- include/grub/multiboot2.h | 4 +-- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c index 17a922be2..e8a0fe207 100644 --- a/grub-core/loader/multiboot.c +++ b/grub-core/loader/multiboot.c @@ -51,6 +51,7 @@ #include #include #if defined (__i386__) || defined (__x86_64__) +#include #include #include #endif @@ -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); } @@ -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; } diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c index a92082533..520f5bd0e 100644 --- a/grub-core/loader/multiboot_elfxx.c +++ b/grub-core/loader/multiboot_elfxx.c @@ -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"); @@ -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"); @@ -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"); } @@ -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; diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c index fd93bc0e4..4e27f4766 100644 --- a/grub-core/loader/multiboot_mbi2.c +++ b/grub-core/loader/multiboot_mbi2.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -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, @@ -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; } diff --git a/include/grub/multiboot2.h b/include/grub/multiboot2.h index 0ca577e73..61a7fc904 100644 --- a/include/grub/multiboot2.h +++ b/include/grub/multiboot2.h @@ -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);