diff options
author | Luigi Leonardi <leonardi@redhat.com> | 2024-12-11 17:14:06 +0100 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-12-23 10:36:19 +0000 |
commit | abbd05992d39eb48a76d08f2f3b750c557e0ce28 (patch) | |
tree | dac733d158a07f4792fafa67d4cbf5c45d70cdfe | |
parent | 103aed83a7e4a71bf93ee6f8caa937f5e9a21411 (diff) | |
download | edk2-abbd05992d39eb48a76d08f2f3b750c557e0ce28.tar.gz |
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>
-rw-r--r-- | OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c | 141 |
1 files changed, 87 insertions, 54 deletions
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c index fdd4db5ca8..430da6429d 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c @@ -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,58 +295,9 @@ 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.
- //
- continue;
- }
+ // If file is in firmware then keep the entry
+ if (FileIsInFv (BootOptions[Index].FilePath)) {
+ continue;
}
//
|