OcAppleBootPolicyLib: Add advanced debug logging

This commit is contained in:
vit9696 2019-05-03 00:23:26 +03:00
parent e395ca103d
commit d190a8de1d

View File

@ -26,6 +26,7 @@
#include <Library/OcMiscLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
@ -165,8 +166,18 @@ InternalGetApfsSpecialFileInfo (
);
if (*VolumeInfo == NULL) {
DEBUG ((DEBUG_INFO, "OCBP: Apfs Volume Info is missing\n"));
return EFI_NOT_FOUND;
}
DEBUG ((
DEBUG_INFO,
"OCBP: Apfs Volume Info - %p (%u, %g, %u)\n",
*VolumeInfo,
(*VolumeInfo)->Always1,
&(*VolumeInfo)->Uuid,
(*VolumeInfo)->Role
));
}
if (ContainerInfo != NULL) {
@ -178,11 +189,20 @@ InternalGetApfsSpecialFileInfo (
);
if (*ContainerInfo == NULL) {
DEBUG ((DEBUG_INFO, "OCBP: Apfs Container Info is missing\n"));
if (VolumeInfo != NULL) {
FreePool (*VolumeInfo);
}
return EFI_NOT_FOUND;
}
DEBUG ((
DEBUG_INFO,
"OCBP: Apfs Container Info - %p (%u, %g)\n",
*ContainerInfo,
(*ContainerInfo)->Always1,
&(*ContainerInfo)->Uuid
));
}
return EFI_SUCCESS;
@ -205,15 +225,19 @@ InternalGetBooterFromBlessedSystemFilePath (
);
if (*FilePath == NULL) {
DEBUG ((DEBUG_INFO, "OCBP: Blessed file is missing\n"));
return EFI_NOT_FOUND;
}
if (!IsDevicePathValid(*FilePath, FilePathSize)) {
if (!IsDevicePathValid (*FilePath, FilePathSize)) {
DEBUG ((DEBUG_INFO, "OCBP: Blessed file is invalid\n"));
FreePool (*FilePath);
*FilePath = NULL;
return EFI_NOT_FOUND;
}
DEBUG ((DEBUG_INFO, "OCBP: Blessed file is valid\n"));
return EFI_SUCCESS;
}
@ -244,10 +268,12 @@ InternalGetBooterFromBlessedSystemFolderPath (
);
if (DevicePath == NULL) {
DEBUG ((DEBUG_INFO, "OCBP: Blessed folder is missing\n"));
return Status;
}
if (!IsDevicePathValid (DevicePath, DevicePathSize)) {
DEBUG ((DEBUG_INFO, "OCBP: Blessed folder is invalid\n"));
FreePool (DevicePath);
return EFI_NOT_FOUND;
}
@ -280,10 +306,12 @@ InternalGetBooterFromBlessedSystemFolderPath (
FreePool (DevicePath);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCBP: Blessed folder append failed - %r\n", Status));
return Status;
}
if (!InternalFileExists (Root, BooterPath)) {
DEBUG ((DEBUG_INFO, "OCBP: Blessed folder %s is missing\n", BooterPath));
return EFI_NOT_FOUND;
}
@ -306,10 +334,13 @@ InternalGetBooterFromPredefinedNameList (
PathName = mBootPathNames[Index];
if (InternalFileExists (Root, PathName)) {
DEBUG ((DEBUG_INFO, "OCBP: Predefined %s was found\n", PathName));
if (DevicePath != NULL) {
*DevicePath = FileDevicePath (Device, PathName);
}
return EFI_SUCCESS;
} else {
DEBUG ((DEBUG_INFO, "OCBP: Predefined %s is missing\n", PathName));
}
}
@ -397,6 +428,7 @@ InternalGetBooterFromApfsVolumePredefinedNameList (
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCBP: Missing partition %s on preboot - %r\n", VolumeDirectoryName, Status));
return Status;
}
@ -408,12 +440,20 @@ InternalGetBooterFromApfsVolumePredefinedNameList (
);
if (VolumeDirectoryInfo == NULL) {
DEBUG ((DEBUG_INFO, "OCBP: Missing volume file info %s - %r\n", VolumeDirectoryName, Status));
VolumeDirectoryHandle->Close (VolumeDirectoryHandle);
return EFI_NOT_FOUND;
}
Status = EFI_NOT_FOUND;
DEBUG ((
DEBUG_INFO,
"OCBP: Want predefined list for APFS %u at %s\n",
VolumeDirectoryInfo->Attribute,
VolumeDirectoryName
));
if ((VolumeDirectoryInfo->Attribute & EFI_FILE_DIRECTORY) != 0) {
Status = InternalGetBooterFromPredefinedNameList (
Device,
@ -463,6 +503,7 @@ InternalGetBooterFromApfsPredefinedNameList (
APPLE_APFS_VOLUME_INFO *VolumeInfo;
CHAR16 VolumeDirectoryName[GUID_STRING_LENGTH+1];
NumberOfHandles = 0;
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiSimpleFileSystemProtocolGuid,
@ -471,6 +512,8 @@ InternalGetBooterFromApfsPredefinedNameList (
&HandleBuffer
);
DEBUG ((DEBUG_INFO, "OCBP: %u filesystems for APFS - %r\n", (UINT32) NumberOfHandles, Status));
if (EFI_ERROR (Status)) {
return Status;
}
@ -484,11 +527,25 @@ InternalGetBooterFromApfsPredefinedNameList (
(VOID **) &FileSystem
);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_INFO,
"OCBP: Borked filesystem %u of %u for APFS - %r\n",
(UINT32) Index,
(UINT32) NumberOfHandles,
Status
));
continue;
}
Status = FileSystem->OpenVolume (FileSystem, &HandleRoot);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_INFO,
"OCBP: Borked root volume %u of %u for APFS - %r\n",
(UINT32) Index,
(UINT32) NumberOfHandles,
Status
));
continue;
}
@ -497,9 +554,24 @@ InternalGetBooterFromApfsPredefinedNameList (
HandleRoot->Close (HandleRoot);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_INFO,
"OCBP: No apfs info %u of %u for APFS - %r\n",
(UINT32) Index,
(UINT32) NumberOfHandles,
Status
));
continue;
}
DEBUG ((
DEBUG_INFO,
"OCBP: Trying to match container %g vs %g for APFS\n",
&ContainerInfo->Uuid,
ContainerUuid,
Status
));
Status = EFI_NOT_FOUND;
if (!CompareGuid (&ContainerInfo->Uuid, ContainerUuid)) {
@ -529,13 +601,29 @@ InternalGetBooterFromApfsPredefinedNameList (
DevicePath
);
if (!EFI_ERROR (Status)) {
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_INFO,
"OCBP: No apfs booter %u of %u for APFS - %r\n",
(UINT32) Index,
(UINT32) NumberOfHandles,
Status
));
} else {
break;
}
}
FreePool (HandleBuffer);
DEBUG ((
DEBUG_INFO,
"OCBP: Apfs bless for %g:%g is %r\n",
ContainerUuid,
VolumeUuid,
Status
));
return Status;
}
@ -781,11 +869,13 @@ BootPolicyGetBootFileEx (
(VOID **) &FileSystem
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCBP: Missing filesystem - %r\n", Status));
return Status;
}
Status = FileSystem->OpenVolume (FileSystem, &Root);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCBP: Invalid root volume - %r\n", Status));
return Status;
}