OvmfPkg/PlatformBootManagerLib: Introduce FileIsInFv function.
Move out file presence check from RemoveStaleFvFileOptions to a new helper function for reusability. No functional changes intended. Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
This commit is contained in:
parent
103aed83a7
commit
abbd05992d
|
@ -84,6 +84,88 @@ InstallDevicePathCallback (
|
|||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
This function checks whether a File exists within the firmware volume.
|
||||
|
||||
@param[in] FilePath Path of the file.
|
||||
|
||||
@return TRUE if the file exists within the volume, false
|
||||
otherwise.
|
||||
**/
|
||||
BOOLEAN
|
||||
FileIsInFv (
|
||||
EFI_DEVICE_PATH_PROTOCOL *FilePath
|
||||
)
|
||||
{
|
||||
UINT32 AuthenticationStatus;
|
||||
EFI_FV_FILE_ATTRIBUTES FileAttributes;
|
||||
EFI_DEVICE_PATH_PROTOCOL *SearchNode;
|
||||
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFileNode;
|
||||
EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;
|
||||
UINTN BufferSize;
|
||||
EFI_FV_FILETYPE FoundType;
|
||||
EFI_HANDLE FvHandle;
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// Locate the Firmware Volume2 protocol instance that is denoted by the
|
||||
// boot option. If this lookup fails (i.e., the boot option references a
|
||||
// firmware volume that doesn't exist), then we'll proceed to delete the
|
||||
// boot option.
|
||||
//
|
||||
SearchNode = FilePath;
|
||||
Status = gBS->LocateDevicePath (
|
||||
&gEfiFirmwareVolume2ProtocolGuid,
|
||||
&SearchNode,
|
||||
&FvHandle
|
||||
);
|
||||
|
||||
//
|
||||
// File not Found
|
||||
//
|
||||
if (EFI_ERROR (Status)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// The firmware volume was found; now let's see if it contains the FvFile
|
||||
// identified by GUID.
|
||||
//
|
||||
Status = gBS->HandleProtocol (
|
||||
FvHandle,
|
||||
&gEfiFirmwareVolume2ProtocolGuid,
|
||||
(VOID **)&FvProtocol
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
FvFileNode = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)NextDevicePathNode (FilePath);
|
||||
//
|
||||
// Buffer==NULL means we request metadata only: BufferSize, FoundType,
|
||||
// FileAttributes.
|
||||
//
|
||||
Status = FvProtocol->ReadFile (
|
||||
FvProtocol,
|
||||
&FvFileNode->FvFileName, // NameGuid
|
||||
NULL, // Buffer
|
||||
&BufferSize,
|
||||
&FoundType,
|
||||
&FileAttributes,
|
||||
&AuthenticationStatus
|
||||
);
|
||||
|
||||
//
|
||||
// File not Found
|
||||
//
|
||||
if (EFI_ERROR (Status)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// The FvFile was found.
|
||||
//
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VOID
|
||||
PlatformRegisterFvBootOption (
|
||||
EFI_GUID *FileGuid,
|
||||
|
@ -185,14 +267,14 @@ RemoveStaleFvFileOptions (
|
|||
);
|
||||
|
||||
for (Index = 0; Index < BootOptionCount; ++Index) {
|
||||
EFI_DEVICE_PATH_PROTOCOL *Node1, *Node2, *SearchNode;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Node1, *Node2;
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE FvHandle;
|
||||
|
||||
//
|
||||
// If the device path starts with neither MemoryMapped(...) nor Fv(...),
|
||||
// then keep the boot option.
|
||||
//
|
||||
|
||||
Node1 = BootOptions[Index].FilePath;
|
||||
if (!((DevicePathType (Node1) == HARDWARE_DEVICE_PATH) &&
|
||||
(DevicePathSubType (Node1) == HW_MEMMAP_DP)) &&
|
||||
|
@ -213,59 +295,10 @@ RemoveStaleFvFileOptions (
|
|||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Locate the Firmware Volume2 protocol instance that is denoted by the
|
||||
// boot option. If this lookup fails (i.e., the boot option references a
|
||||
// firmware volume that doesn't exist), then we'll proceed to delete the
|
||||
// boot option.
|
||||
//
|
||||
SearchNode = Node1;
|
||||
Status = gBS->LocateDevicePath (
|
||||
&gEfiFirmwareVolume2ProtocolGuid,
|
||||
&SearchNode,
|
||||
&FvHandle
|
||||
);
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
//
|
||||
// The firmware volume was found; now let's see if it contains the FvFile
|
||||
// identified by GUID.
|
||||
//
|
||||
EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;
|
||||
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFileNode;
|
||||
UINTN BufferSize;
|
||||
EFI_FV_FILETYPE FoundType;
|
||||
EFI_FV_FILE_ATTRIBUTES FileAttributes;
|
||||
UINT32 AuthenticationStatus;
|
||||
|
||||
Status = gBS->HandleProtocol (
|
||||
FvHandle,
|
||||
&gEfiFirmwareVolume2ProtocolGuid,
|
||||
(VOID **)&FvProtocol
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
FvFileNode = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)Node2;
|
||||
//
|
||||
// Buffer==NULL means we request metadata only: BufferSize, FoundType,
|
||||
// FileAttributes.
|
||||
//
|
||||
Status = FvProtocol->ReadFile (
|
||||
FvProtocol,
|
||||
&FvFileNode->FvFileName, // NameGuid
|
||||
NULL, // Buffer
|
||||
&BufferSize,
|
||||
&FoundType,
|
||||
&FileAttributes,
|
||||
&AuthenticationStatus
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
//
|
||||
// The FvFile was found. Keep the boot option.
|
||||
//
|
||||
// If file is in firmware then keep the entry
|
||||
if (FileIsInFv (BootOptions[Index].FilePath)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the boot option.
|
||||
|
|
Loading…
Reference in New Issue