From 620bcad3241fee38488a0773b9beaf77ee025ba6 Mon Sep 17 00:00:00 2001 From: longpanda Date: Tue, 26 Jan 2021 11:07:31 +0800 Subject: [PATCH] update for vdiskchain --- .../Application/VDiskChain/VDiskChain.c | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/EDK2/edk2_mod/edk2-edk2-stable201911/MdeModulePkg/Application/VDiskChain/VDiskChain.c b/EDK2/edk2_mod/edk2-edk2-stable201911/MdeModulePkg/Application/VDiskChain/VDiskChain.c index 6c8a2ce5..f3d8d458 100644 --- a/EDK2/edk2_mod/edk2-edk2-stable201911/MdeModulePkg/Application/VDiskChain/VDiskChain.c +++ b/EDK2/edk2_mod/edk2-edk2-stable201911/MdeModulePkg/Application/VDiskChain/VDiskChain.c @@ -71,7 +71,10 @@ CONST CHAR16 *gEfiBootFileName[] = UINT8 *g_disk_buf_addr = NULL; UINT64 g_disk_buf_size = 0; - + +STATIC EFI_GET_VARIABLE g_org_get_variable = NULL; +STATIC EFI_EXIT_BOOT_SERVICES g_org_exit_boot_service = NULL; + VOID EFIAPI VDiskDebug(IN CONST CHAR8 *Format, ...) { VA_LIST Marker; @@ -217,6 +220,54 @@ STATIC EFI_STATUS vdisk_patch_vdisk_path(CHAR16 *pos) return 0; } +EFI_STATUS EFIAPI vdisk_get_variable_wrapper +( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes, OPTIONAL + IN OUT UINTN *DataSize, + OUT VOID *Data OPTIONAL +) +{ + EFI_STATUS Status = EFI_SUCCESS; + + Status = g_org_get_variable(VariableName, VendorGuid, Attributes, DataSize, Data); + if (StrCmp(VariableName, L"SecureBoot") == 0) + { + if ((*DataSize == 1) && Data) + { + *(UINT8 *)Data = 0; + } + } + + return Status; +} + +EFI_STATUS EFIAPI vdisk_exit_boot_service_wrapper +( + IN EFI_HANDLE ImageHandle, + IN UINTN MapKey +) +{ + return g_org_exit_boot_service(ImageHandle, MapKey); +} + +STATIC EFI_STATUS EFIAPI vdisk_disable_secure_boot(IN EFI_HANDLE ImageHandle) +{ + /* step1: wrapper security protocol. */ + /* Do we still need it since we have been loaded ? */ + + + /* step2: fake SecureBoot variable */ + g_org_exit_boot_service = gBS->ExitBootServices; + gBS->ExitBootServices = vdisk_exit_boot_service_wrapper; + + g_org_get_variable = gRT->GetVariable; + gRT->GetVariable = vdisk_get_variable_wrapper; + + return EFI_SUCCESS; +} + STATIC EFI_STATUS EFIAPI vdisk_parse_cmdline(IN EFI_HANDLE ImageHandle) { CHAR16 *Pos = NULL; @@ -254,6 +305,11 @@ STATIC EFI_STATUS EFIAPI vdisk_parse_cmdline(IN EFI_HANDLE ImageHandle) vdisk_patch_vdisk_path(Pos + 6); + if (StrStr(pCmdLine, L"secureboot=off")) + { + vdisk_disable_secure_boot(ImageHandle); + } + FreePool(pCmdLine); return EFI_SUCCESS; }