OcBootManagementLib: Fallback to boot.efi when dmg loading is disabled

This commit is contained in:
vit9696 2020-08-20 20:32:09 +03:00
parent e78301f744
commit 47a341f80d

View File

@ -351,9 +351,22 @@ AddBootEntryOnFileSystem (
CHAR16 *TextDevicePath;
BOOLEAN IsFolder;
BOOLEAN IsGeneric;
BOOLEAN IsReallocated;
EntryType = OcGetBootDevicePathType (DevicePath, &IsFolder, &IsGeneric);
if (IsFolder && BootContext->PickerContext->DmgLoading == OcDmgLoadingDisabled) {
DevicePath = AppendFileNameDevicePath (DevicePath, L"boot.efi");
IsFolder = FALSE;
IsReallocated = TRUE;
DEBUG ((DEBUG_INFO, "OCB: Switching DMG boot path to boot.efi due to policy\n"));
if (DevicePath == NULL) {
return EFI_OUT_OF_RESOURCES;
}
} else {
IsReallocated = FALSE;
}
DEBUG_CODE_BEGIN ();
TextDevicePath = ConvertDevicePathToText (DevicePath, TRUE, FALSE);
@ -385,6 +398,9 @@ AddBootEntryOnFileSystem (
//
if (BootContext->PickerContext->HideAuxiliary && EntryType == OC_BOOT_APPLE_RECOVERY) {
DEBUG ((DEBUG_INFO, "OCB: Discarding recovery entry due to auxiliary\n"));
if (IsReallocated) {
FreePool (DevicePath);
}
return EFI_UNSUPPORTED;
}
@ -393,6 +409,9 @@ AddBootEntryOnFileSystem (
//
if (BootContext->PickerContext->HideAuxiliary && EntryType == OC_BOOT_APPLE_TIME_MACHINE) {
DEBUG ((DEBUG_INFO, "OCB: Discarding time machine entry due to auxiliary\n"));
if (IsReallocated) {
FreePool (DevicePath);
}
return EFI_UNSUPPORTED;
}
@ -403,6 +422,9 @@ AddBootEntryOnFileSystem (
if (RecoveryPart ? FileSystem->RecoveryFs->LoaderFs : FileSystem->LoaderFs
&& IsOpenCoreBootloader (DevicePath)) {
DEBUG ((DEBUG_INFO, "OCB: Discarding discovered OpenCore bootloader\n"));
if (IsReallocated) {
FreePool (DevicePath);
}
return EFI_UNSUPPORTED;
}
@ -440,6 +462,9 @@ AddBootEntryOnFileSystem (
//
RemoveEntryList (Link);
InsertTailList (&FileSystem->BootEntries, Link);
if (IsReallocated) {
FreePool (DevicePath);
}
return EFI_ALREADY_STARTED;
}
}
@ -450,6 +475,9 @@ AddBootEntryOnFileSystem (
//
BootEntry = AllocateZeroPool (sizeof (*BootEntry));
if (BootEntry == NULL) {
if (IsReallocated) {
FreePool (DevicePath);
}
return EFI_OUT_OF_RESOURCES;
}
@ -462,6 +490,9 @@ AddBootEntryOnFileSystem (
Status = InternalDescribeBootEntry (BootEntry);
if (EFI_ERROR (Status)) {
FreePool (BootEntry);
if (IsReallocated) {
FreePool (DevicePath);
}
return Status;
}