Skip to content

Commit

Permalink
OvmfPkg: improve PlatformBootManagerLib API
Browse files Browse the repository at this point in the history
OvmfPkg implementation of PlatformBootManagerLib was different than
UefiPayloadPkg implementation, becuase of that there were problems in
porting one to one code that register and unregister iPXE file as boot
option. PlatformBootManagerLib PlatformRegisterFvBootOption gined
BootNow parameter and PlatformUnregisterFvBootOption function.

Signed-off-by: Piotr Król <[email protected]>
  • Loading branch information
pietrushnic committed Oct 23, 2023
1 parent 62b6d31 commit f203b1c
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ VOID
PlatformRegisterFvBootOption (
EFI_GUID *FileGuid,
CHAR16 *Description,
UINT32 Attributes
UINT32 Attributes,
BOOLEAN BootNow
)
{
EFI_STATUS Status;
Expand Down Expand Up @@ -270,6 +271,9 @@ PlatformRegisterFvBootOption (
ASSERT_EFI_ERROR (Status);
FreePool (DevicePath);

if (BootNow)
EfiBootManagerBoot (&NewOption);

BootOptions = EfiBootManagerGetLoadOptions (
&BootOptionCount, LoadOptionTypeBoot
);
Expand All @@ -286,6 +290,68 @@ PlatformRegisterFvBootOption (
EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
}

VOID
PlatformUnregisterFvBootOption (
EFI_GUID *FileGuid,
CHAR16 *Description,
UINT32 Attributes
)
{
EFI_STATUS Status;
INTN OptionIndex;
EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
UINTN BootOptionCount;
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;

Status = gBS->HandleProtocol (
gImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID **) &LoadedImage
);
ASSERT_EFI_ERROR (Status);

EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);
ASSERT (DevicePath != NULL);
DevicePath = AppendDevicePathNode (
DevicePath,
(EFI_DEVICE_PATH_PROTOCOL *) &FileNode
);
ASSERT (DevicePath != NULL);

Status = EfiBootManagerInitializeLoadOption (
&NewOption,
LoadOptionNumberUnassigned,
LoadOptionTypeBoot,
Attributes,
Description,
DevicePath,
NULL,
0
);
ASSERT_EFI_ERROR (Status);
FreePool (DevicePath);

BootOptions = EfiBootManagerGetLoadOptions (
&BootOptionCount, LoadOptionTypeBoot
);

OptionIndex = EfiBootManagerFindLoadOption (
&NewOption, BootOptions, BootOptionCount
);

if (OptionIndex >= 0 && OptionIndex < BootOptionCount) {
Status = EfiBootManagerDeleteLoadOptionVariable (BootOptions[OptionIndex].OptionNumber,
BootOptions[OptionIndex].OptionType);
ASSERT_EFI_ERROR (Status);
}
EfiBootManagerFreeLoadOption (&NewOption);
EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
}

/**
Remove all MemoryMapped(...)/FvFile(...) and Fv(...)/FvFile(...) boot options
whose device paths do not resolve exactly to an FvFile in the system.
Expand Down

0 comments on commit f203b1c

Please sign in to comment.