Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OvmfPkg: Introduce UEFI config support for fw_cfg #6551

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions MdeModulePkg/Include/Library/UefiBootManagerLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ EfiBootManagerGetBootManagerMenu (
EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
);

BOOLEAN
BmIsBootManagerMenuFilePath (
EFI_DEVICE_PATH_PROTOCOL *DevicePath
);

/**
Get the next possible full path pointing to the load option.
The routine doesn't guarantee the returned full path points to an existing
Expand Down
6 changes: 6 additions & 0 deletions MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,8 @@ BmRegisterBootManagerMenu (
OUT EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
)
{
DEBUG ((DEBUG_INFO, "BmRegisterBootManagerMenu\n"));

EFI_STATUS Status;
CHAR16 *Description;
UINTN DescriptionLength;
Expand Down Expand Up @@ -2609,6 +2611,8 @@ EfiBootManagerGetBootManagerMenu (
EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
)
{
DEBUG ((DEBUG_INFO, "EfiBootManagerGetBootManagerMenu\n"));

EFI_STATUS Status;
UINTN BootOptionCount;
EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
Expand Down Expand Up @@ -2639,8 +2643,10 @@ EfiBootManagerGetBootManagerMenu (
// Automatically create the Boot#### for Boot Manager Menu when not found.
//
if (Index == BootOptionCount) {
DEBUG ((DEBUG_INFO, "Menu non trovato, aggiungo\n"));
return BmRegisterBootManagerMenu (BootOption);
} else {
DEBUG ((DEBUG_INFO, "Menu trovato!\n"));
return EFI_SUCCESS;
}
}
Expand Down
6 changes: 6 additions & 0 deletions MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ BmRegisterHotkeyNotify (
UINTN Index;
VOID *NotifyHandle;

DEBUG ((DEBUG_INFO, "BmRegisterHotkeyNotify\n"));

for (Index = 0; Index < Hotkey->CodeCount; Index++) {
Status = TxtInEx->RegisterKeyNotify (
TxtInEx,
Expand Down Expand Up @@ -661,6 +663,8 @@ BmProcessKeyOption (
IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOption
)
{
DEBUG ((DEBUG_INFO, "BmProcessKeyOption\n"));

EFI_STATUS Status;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;
EFI_HANDLE *Handles;
Expand Down Expand Up @@ -976,6 +980,8 @@ EfiBootManagerAddKeyOptionVariable (
...
)
{
DEBUG ((DEBUG_INFO, "Vorrei registrare tasto\n"));

EFI_STATUS Status;
VA_LIST Args;
VOID *BootOption;
Expand Down
1 change: 1 addition & 0 deletions MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleOnDiskSupport ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport ## CONSUMES
gEfiMdePkgTokenSpaceGuid.PcdBootMenuEnabled

[Depex]
TRUE
Expand Down
8 changes: 6 additions & 2 deletions MdeModulePkg/Universal/BdsDxe/BdsEntry.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,13 @@ BdsEntry (
DEBUG_CODE_END ();

//
// BootManagerMenu doesn't contain the correct information when return status is EFI_NOT_FOUND.
// Disable BootManagerMenu boot if PcdBootMenuEnabled is set to FALSE.
//
BootManagerMenuStatus = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);
if (!PcdGetBool (PcdBootMenuEnabled)) {
BootManagerMenuStatus = EFI_NOT_FOUND;
} else {
BootManagerMenuStatus = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);
}

BootFwUi = (BOOLEAN)((OsIndication & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0);
PlatformRecovery = (BOOLEAN)((OsIndication & EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY) != 0);
Expand Down
3 changes: 3 additions & 0 deletions MdePkg/MdePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -2602,5 +2602,8 @@
# @Prompt Memory encryption attribute
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0|UINT64|0x0000002e

[PcdsDynamic, PcdsDynamicEx]
gEfiMdePkgTokenSpaceGuid.PcdBootMenuEnabled|TRUE|BOOLEAN|0x0000002f

[UserExtensions.TianoCore."ExtraFiles"]
MdePkgExtra.uni
96 changes: 87 additions & 9 deletions OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,35 @@ RestrictBootOptionsToFirmware (
EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
}

VOID
RemoveBootManager (
VOID
)
{
EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
UINTN BootOptionCount;
UINTN Index;

BootOptions = EfiBootManagerGetLoadOptions (
&BootOptionCount,
LoadOptionTypeBoot
);

for (Index = 0; Index < BootOptionCount; ++Index) {
if (BmIsBootManagerMenuFilePath (BootOptions[Index].FilePath)) {
//
// Delete the boot option.
//
EfiBootManagerDeleteLoadOptionVariable (
BootOptions[Index].OptionNumber,
LoadOptionTypeBoot
);
}
}

EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
}

VOID
PlatformRegisterOptionsAndKeys (
VOID
Expand All @@ -393,22 +422,51 @@ PlatformRegisterOptionsAndKeys (
EFI_INPUT_KEY Esc;
EFI_BOOT_MANAGER_LOAD_OPTION BootOption;

Enter.ScanCode = SCAN_NULL;
Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
F2.ScanCode = SCAN_F2;
F2.UnicodeChar = CHAR_NULL;
Esc.ScanCode = SCAN_ESC;
Esc.UnicodeChar = CHAR_NULL;

//
// Delete Previously Registered hotkeys
//
if (!PcdGetBool (PcdBootMenuEnabled)) {
Status = EfiBootManagerDeleteKeyOptionVariable (
NULL,
0,
&Enter,
NULL
);

Status = EfiBootManagerDeleteKeyOptionVariable (
NULL,
0,
&F2,
NULL
);

Status = EfiBootManagerDeleteKeyOptionVariable (
NULL,
0,
&Esc,
NULL
);

return;
}

//
// Register ENTER as CONTINUE key
//
Enter.ScanCode = SCAN_NULL;
Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
ASSERT_EFI_ERROR (Status);

//
// Map F2 to Boot Manager Menu
//
F2.ScanCode = SCAN_F2;
F2.UnicodeChar = CHAR_NULL;
Esc.ScanCode = SCAN_ESC;
Esc.UnicodeChar = CHAR_NULL;
Status = EfiBootManagerGetBootManagerMenu (&BootOption);
Status = EfiBootManagerGetBootManagerMenu (&BootOption);
ASSERT_EFI_ERROR (Status);
Status = EfiBootManagerAddKeyOptionVariable (
NULL,
Expand Down Expand Up @@ -478,6 +536,7 @@ PlatformBootManagerBeforeConsole (
EFI_STATUS Status;
UINT16 FrontPageTimeout;
RETURN_STATUS PcdStatus;
BOOLEAN BootMenuEnabled;

DEBUG ((DEBUG_INFO, "PlatformBootManagerBeforeConsole\n"));
InstallDevicePathCallback ();
Expand Down Expand Up @@ -577,6 +636,18 @@ PlatformBootManagerBeforeConsole (
Status
));

Status = QemuFwCfgParseBool (
"opt/org.tianocore/FirmwareSetupSupport",
&BootMenuEnabled
);

if (RETURN_ERROR (Status)) {
BootMenuEnabled = TRUE;
}

Status = PcdSetBoolS (PcdBootMenuEnabled, BootMenuEnabled);
ASSERT_RETURN_ERROR (Status);

if (!FeaturePcdGet (PcdBootRestrictToFirmware)) {
PlatformRegisterOptionsAndKeys ();
}
Expand Down Expand Up @@ -1887,6 +1958,13 @@ PlatformBootManagerAfterConsole (
EfiBootManagerRefreshAllBootOption ();
}

//
// Remove BootManager if previously added
//
if (!PcdGetBool (PcdBootMenuEnabled)) {
RemoveBootManager ();
}

BOOLEAN ShellEnabled;
RETURN_STATUS RetStatus;

Expand Down Expand Up @@ -2087,7 +2165,7 @@ PlatformBootManagerUnableToBoot (
EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;
UINTN Index;

if (FeaturePcdGet (PcdBootRestrictToFirmware)) {
if (FeaturePcdGet (PcdBootRestrictToFirmware) || !PcdGetBool (PcdBootMenuEnabled)) {
AsciiPrint (
"%a: No bootable option was found.\n",
gEfiCallerBaseName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits ## CONSUMES
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity ## CONSUMES
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits ## CONSUMES
gEfiMdePkgTokenSpaceGuid.PcdBootMenuEnabled

[Pcd.IA32, Pcd.X64]
gEfiMdePkgTokenSpaceGuid.PcdFSBClock
Expand Down
10 changes: 10 additions & 0 deletions OvmfPkg/RUNTIME_CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ qemu-system-x86_64 \
```


## Firmware Config: opt/org.tianocore/FirmwareSetupSupport

As the name suggests, this enables/disables Firmware setup support. Default:
enabled. Usage:

```
qemu-system-x86_64 -fw_cfg name=opt/org.tianocore/FirmwareSetupSupport,string=no
```


## TLS: etc/edk2/https/ciphers

Configres the allowed TLS chiper suites. Using the host's system
Expand Down
Loading