Skip to content

Commit

Permalink
OcBootManagementLib: Fix default boot option selection regression
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Dec 7, 2020
1 parent a05230c commit 7c5f19a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 13 deletions.
16 changes: 16 additions & 0 deletions Include/Acidanthera/Guid/OcVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
#define OC_RTC_BLACKLIST_VARIABLE_NAME L"rtc-blacklist"

//
// Boot prefix used instead of normal Boot in OC_VENDOR_VARIABLE_GUID
//
#define OC_VENDOR_BOOT_VARIABLE_PREFIX L"OCBt"

//
// BootOrder variable name for OC_VENDOR_VARIABLE_GUID
//
#define OC_VENDOR_BOOT_ORDER_VARIABLE_NAME OC_VENDOR_BOOT_VARIABLE_PREFIX L"Order"


//
// BootNext variable name for OC_VENDOR_VARIABLE_GUID
//
#define OC_VENDOR_BOOT_NEXT_VARIABLE_NAME OC_VENDOR_BOOT_VARIABLE_PREFIX L"Next"

//
// 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102
// This GUID is specifically used for normal variable access by Lilu kernel extension and its plugins.
Expand Down
55 changes: 47 additions & 8 deletions Library/OcBootManagementLib/DefaultEntryChoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ InternalGetBootOptionData (
UINTN LoadOptionSize;
EFI_LOAD_OPTION *LoadOption;

UnicodeSPrint (BootVarName, sizeof (BootVarName), L"Boot%04x", BootOption);
if (CompareGuid (BootGuid, &gOcVendorVariableGuid)) {
UnicodeSPrint (
BootVarName,
sizeof (BootVarName),
OC_VENDOR_BOOT_VARIABLE_PREFIX L"%04x",
BootOption
);
} else {
UnicodeSPrint (BootVarName, sizeof (BootVarName), L"Boot%04x", BootOption);
}

Status = GetVariable2 (
BootVarName,
Expand Down Expand Up @@ -306,14 +315,21 @@ InternalClearNextVariables (
)
{
CHAR16 VariableName[32];
CHAR16 *BootNextName;
UINTN Index;

if (CompareGuid (BootVariableGuid, &gOcVendorVariableGuid)) {
BootNextName = OC_VENDOR_BOOT_NEXT_VARIABLE_NAME;
} else {
BootNextName = EFI_BOOT_NEXT_VARIABLE_NAME;
}

//
// Next variable data specified by UEFI spec.
// For now we do not bother dropping the variable it points to.
//
gRT->SetVariable (
EFI_BOOT_NEXT_VARIABLE_NAME,
BootNextName,
BootVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
0,
Expand Down Expand Up @@ -388,15 +404,22 @@ InternalHasFirmwareUpdateAsNext (
EFI_STATUS Status;
UINT32 VariableAttributes;
UINT16 BootNext;
CHAR16 *BootNextName;
UINTN VariableSize;
OC_BOOT_ENTRY_TYPE EntryType;
EFI_DEVICE_PATH_PROTOCOL *UefiDevicePath;
EFI_LOAD_OPTION *LoadOption;
UINTN LoadOptionSize;

if (CompareGuid (BootVariableGuid, &gOcVendorVariableGuid)) {
BootNextName = OC_VENDOR_BOOT_NEXT_VARIABLE_NAME;
} else {
BootNextName = EFI_BOOT_NEXT_VARIABLE_NAME;
}

VariableSize = sizeof (BootNext);
Status = gRT->GetVariable (
EFI_BOOT_NEXT_VARIABLE_NAME,
BootNextName,
BootVariableGuid,
&VariableAttributes,
&VariableSize,
Expand Down Expand Up @@ -464,6 +487,8 @@ OcGetBootOrder (
EFI_STATUS Status;
UINT32 VariableAttributes;
UINT16 BootNext;
CHAR16 *BootOrderName;
CHAR16 *BootNextName;
UINT16 *BootOrder;
UINTN VariableSize;
UINTN Index;
Expand All @@ -480,13 +505,21 @@ OcGetBootOrder (
*HasBootNext = FALSE;
}

if (CompareGuid (BootVariableGuid, &gOcVendorVariableGuid)) {
BootOrderName = OC_VENDOR_BOOT_ORDER_VARIABLE_NAME;
BootNextName = OC_VENDOR_BOOT_NEXT_VARIABLE_NAME;
} else {
BootOrderName = EFI_BOOT_ORDER_VARIABLE_NAME;
BootNextName = EFI_BOOT_NEXT_VARIABLE_NAME;
}

//
// Precede variable with boot next.
//
if (WithBootNext) {
VariableSize = sizeof (BootNext);
Status = gRT->GetVariable (
EFI_BOOT_NEXT_VARIABLE_NAME,
BootNextName,
BootVariableGuid,
&VariableAttributes,
&VariableSize,
Expand All @@ -503,7 +536,7 @@ OcGetBootOrder (

VariableSize = 0;
Status = gRT->GetVariable (
EFI_BOOT_ORDER_VARIABLE_NAME,
BootOrderName,
BootVariableGuid,
&VariableAttributes,
&VariableSize,
Expand All @@ -517,7 +550,7 @@ OcGetBootOrder (
}

Status = gRT->GetVariable (
EFI_BOOT_ORDER_VARIABLE_NAME,
BootOrderName,
BootVariableGuid,
&VariableAttributes,
&VariableSize,
Expand Down Expand Up @@ -640,6 +673,8 @@ OcSetDefaultBootEntry (
EFI_HANDLE DeviceHandle;
OC_BOOT_ENTRY *MatchedEntry;
EFI_GUID *BootVariableGuid;
CHAR16 *BootOrderName;
CHAR16 *BootVariableName;
UINT16 *BootOrder;
UINT16 *NewBootOrder;
UINT16 BootTmp;
Expand Down Expand Up @@ -667,8 +702,12 @@ OcSetDefaultBootEntry (

if (Context->CustomBootGuid) {
BootVariableGuid = &gOcVendorVariableGuid;
BootOrderName = OC_VENDOR_BOOT_ORDER_VARIABLE_NAME;
BootVariableName = OC_VENDOR_BOOT_VARIABLE_PREFIX L"0080";
} else {
BootVariableGuid = &gEfiGlobalVariableGuid;
BootOrderName = EFI_BOOT_ORDER_VARIABLE_NAME;
BootVariableName = L"Boot0080";
}

BootOrder = OcGetBootOrder (
Expand Down Expand Up @@ -755,7 +794,7 @@ OcSetDefaultBootEntry (
CopyMem ((UINT8 *) (LoadOption + 1) + LoadOptionNameSize, Entry->DevicePath, DevicePathSize);

Status = gRT->SetVariable (
L"Boot0080",
BootVariableName,
BootVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
Expand Down Expand Up @@ -822,7 +861,7 @@ OcSetDefaultBootEntry (
}

Status = gRT->SetVariable (
EFI_BOOT_ORDER_VARIABLE_NAME,
BootOrderName,
BootVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
Expand Down
10 changes: 5 additions & 5 deletions Platform/OpenRuntime/UefiRuntimeServices.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ IsEfiBootVar (
return FALSE;
}

CopyMem (&NewVariableName[0], L"OCBt", L_STR_SIZE_NT (L"OCBt"));
CopyMem (&NewVariableName[0], OC_VENDOR_BOOT_VARIABLE_PREFIX, L_STR_SIZE_NT (OC_VENDOR_BOOT_VARIABLE_PREFIX));
CopyMem (
&NewVariableName[L_STR_LEN (L"OCBt")],
&VariableName[L_STR_LEN (L"OCBt")],
Size - L_STR_SIZE_NT (L"OCBt")
&NewVariableName[L_STR_LEN (OC_VENDOR_BOOT_VARIABLE_PREFIX)],
&VariableName[L_STR_LEN (OC_VENDOR_BOOT_VARIABLE_PREFIX)],
Size - L_STR_SIZE_NT (OC_VENDOR_BOOT_VARIABLE_PREFIX)
);
}

Expand All @@ -183,7 +183,7 @@ IsOcBootVar (
return FALSE;
}

if (StrnCmp (L"OCBt", VariableName, L_STR_LEN (L"OCBt")) != 0) {
if (StrnCmp (OC_VENDOR_BOOT_VARIABLE_PREFIX, VariableName, L_STR_LEN (OC_VENDOR_BOOT_VARIABLE_PREFIX)) != 0) {
return FALSE;
}

Expand Down

0 comments on commit 7c5f19a

Please sign in to comment.