mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
OpenCoreUefi: Support deduplicating BootOrder at boot
This commit is contained in:
parent
e835d2be70
commit
eb7a5c41f5
@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#include <OpenCore.h>
|
||||
|
||||
#include <Guid/OcVariables.h>
|
||||
#include <Guid/GlobalVariable.h>
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
@ -36,6 +37,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#include <Library/OcUnicodeCollationEngLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
|
||||
#include <Protocol/DevicePath.h>
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user