diff --git a/Platform/OpenCore/OpenCoreUefi.c b/Platform/OpenCore/OpenCoreUefi.c index 440b15d8..9ff5a856 100644 --- a/Platform/OpenCore/OpenCoreUefi.c +++ b/Platform/OpenCore/OpenCoreUefi.c @@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include +#include #include #include @@ -36,6 +37,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include @@ -482,7 +484,13 @@ OcLoadUefiSupport ( IN OC_CPU_INFO *CpuInfo ) { - BOOLEAN AgiExitBs; + EFI_STATUS Status; + UINTN Index; + UINTN Index2; + UINT16 *BootOrder; + UINTN BootOrderSize; + BOOLEAN BootOrderChanged; + BOOLEAN AgiExitBs; OcReinstallProtocols (Config); @@ -526,6 +534,52 @@ OcLoadUefiSupport ( &Config->Uefi.Quirks.RequestBootVarFallback ); + if (Config->Uefi.Quirks.RequestBootVarFallback) { + Status = GetVariable2 ( + EFI_BOOT_ORDER_VARIABLE_NAME, + &gEfiGlobalVariableGuid, + (VOID **) &BootOrder, + &BootOrderSize + ); + + // + // Deduplicate BootOrder variable contents. + // + if (!EFI_ERROR (Status) && BootOrderSize > 0 && BootOrderSize % sizeof (BootOrder[0]) == 0) { + BootOrderChanged = FALSE; + + for (Index = 1; Index < BootOrderSize / sizeof (BootOrder[0]); ++Index) { + for (Index2 = 0; Index2 < Index; ++Index2) { + if (BootOrder[Index] == BootOrder[Index2]) { + // + // Found duplicate. + // + BootOrderChanged = TRUE; + CopyMem ( + &BootOrder[Index], + &BootOrder[Index + 1], + BootOrderSize - sizeof (BootOrder[0]) * (Index + 1) + ); + BootOrderSize -= sizeof (BootOrder[0]); + --Index; + break; + } + } + + if (BootOrderChanged) { + DEBUG ((DEBUG_INFO, "OC: Performed BootOrder deduplication\n")); + gRT->SetVariable ( + EFI_BOOT_ORDER_VARIABLE_NAME, + &gEfiGlobalVariableGuid, + EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, + BootOrderSize, + BootOrder + ); + } + } + } + } + if (Config->Uefi.Quirks.ReleaseUsbOwnership || Config->Uefi.Quirks.ExitBootServicesDelay > 0 || AgiExitBs) {