From 9947a9fbc20f5c0ec0acd002209693081fe8d5ff Mon Sep 17 00:00:00 2001 From: Mattiwatti Date: Sat, 25 Apr 2020 06:33:56 +0200 Subject: Loader: support legacy BIOS boot entries in the fallback path Fixes #9 --- Application/Loader/Loader.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'Application/Loader/Loader.c') diff --git a/Application/Loader/Loader.c b/Application/Loader/Loader.c index ae4ded5..eba4f56 100644 --- a/Application/Loader/Loader.c +++ b/Application/Loader/Loader.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -412,6 +413,14 @@ TryBootOptionsInOrder( if ((BootOptions[Index].Attributes & LOAD_OPTION_CATEGORY) != LOAD_OPTION_CATEGORY_BOOT) continue; + // + // Ignore legacy (BBS) entries, unless non-Windows entries are allowed (second boot attempt) + // + const BOOLEAN IsLegacy = DevicePathType(BootOptions[Index].FilePath) == BBS_DEVICE_PATH && + DevicePathSubType(BootOptions[Index].FilePath) == BBS_BBS_DP; + if (OnlyBootWindows && IsLegacy) + continue; + // // Filter out non-Windows boot entries. // Apply some heuristics based on the device path, which must end in "bootmgfw.efi" or "bootx64.efi". @@ -442,18 +451,24 @@ TryBootOptionsInOrder( MaybeWindows = TRUE; } - if (ConvertedPath != NULL) - FreePool(ConvertedPath); - if (OnlyBootWindows && !MaybeWindows) { if (FullPath != BootOptions[Index].FilePath) FreePool(FullPath); - + if (ConvertedPath != NULL) + FreePool(ConvertedPath); + // Not Windows; skip this entry continue; } + // Print what we're booting + if (ConvertedPath != NULL) + { + Print(L"Booting %Sdevice path %S...\r\n", IsLegacy ? L"legacy " : L"", ConvertedPath); + FreePool(ConvertedPath); + } + // // Boot this image. // @@ -474,6 +489,26 @@ TryBootOptionsInOrder( // Signal the EVT_SIGNAL_READY_TO_BOOT event EfiSignalEventReadyToBoot(); + // Handle BBS entries + if (IsLegacy) + { + Print(L"\r\nNOTE: EfiGuard does not support legacy (non-UEFI) Windows installations.\r\n" + L"The legacy OS will be booted, but EfiGuard will not work.\r\nPress any key to acknowledge...\r\n"); + WaitForKey(); + + EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; + Status = gBS->LocateProtocol(&gEfiLegacyBiosProtocolGuid, + NULL, + (VOID**)&LegacyBios); + ASSERT_EFI_ERROR(Status); + + BootOptions[Index].Status = LegacyBios->LegacyBoot(LegacyBios, + (BBS_BBS_DEVICE_PATH*)BootOptions[Index].FilePath, + BootOptions[Index].OptionalDataSize, + BootOptions[Index].OptionalData); + return !EFI_ERROR(BootOptions[Index].Status); + } + // So again, DO NOT call this abortion: //BmSetMemoryTypeInformationVariable((BOOLEAN)((BootOptions[Index].Attributes & LOAD_OPTION_CATEGORY) == LOAD_OPTION_CATEGORY_BOOT)); -- cgit v1.2.3