This patch adds MinPlatform stage 3 (UEFI boot) functionality Stage 3 adds DxeMain, drivers and modules necessary to reach UEFI shell.
Cc: Leif Lindholm <quic_llind...@quicinc.com> Cc: Michael D Kinney <michael.d.kin...@intel.com> Cc: Isaac Oram <isaac.w.o...@intel.com> Cc: Pedro Falcato <pedro.falc...@gmail.com> Cc: Gerd Hoffmann <kra...@redhat.com> Cc: Stefan Hajnoczi <stefa...@gmail.com> Signed-off-by: Theo Jehl <theojeh...@gmail.com> --- .../Include/Dsc/Stage3.dsc.inc | 101 +++++++++++++++++ .../QemuOpenBoardPkg/QemuOpenBoardPkg.dsc | 3 +- .../QemuOpenBoardPkg/QemuOpenBoardPkg.fdf | 54 +++++++++ .../BoardBootManagerLib.inf | 39 +++++++ .../BoardBootManagerLib/BoardBootManager.c | 105 ++++++++++++++++++ 5 files changed, 301 insertions(+), 1 deletion(-) create mode 100644 Platform/Qemu/QemuOpenBoardPkg/Include/Dsc/Stage3.dsc.inc create mode 100644 Platform/Qemu/QemuOpenBoardPkg/Library/BoardBootManagerLib/BoardBootManagerLib.inf create mode 100644 Platform/Qemu/QemuOpenBoardPkg/Library/BoardBootManagerLib/BoardBootManager.c diff --git a/Platform/Qemu/QemuOpenBoardPkg/Include/Dsc/Stage3.dsc.inc b/Platform/Qemu/QemuOpenBoardPkg/Include/Dsc/Stage3.dsc.inc new file mode 100644 index 000000000000..d7ae198633b2 --- /dev/null +++ b/Platform/Qemu/QemuOpenBoardPkg/Include/Dsc/Stage3.dsc.inc @@ -0,0 +1,101 @@ +## @file +# Common DSC content to begin Stage 3 enabling +# +# @copyright +# Copyright (C) 2022 Theo Jehl +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[LibraryClasses.Common] + PlatformBootManagerLib | OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf + BootLogoLib | MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf + NvVarsFileLib | OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.inf + QemuFwCfgS3Lib | OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf + QemuLoadImageLib | OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf + QemuBootOrderLib | OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf + PlatformBmPrintScLib | OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf + XenPlatformLib | OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf + LoadLinuxLib | OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf + SerializeVariablesLib | OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf + BoardBootManagerLib | QemuOpenBoardPkg/Library/BoardBootManagerLib/BoardBootManagerLib.inf + LocalApicLib | UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf + IoLib | MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf + PciExpressLib | MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf + PcdLib | MdePkg/Library/DxePcdLib/DxePcdLib.inf + PciLib | MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + DebugLib | MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf + SerialPortLib | PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf + +[Components.$(DXE_ARCH)] + MdeModulePkg/Core/Dxe/DxeMain.inf { + <LibraryClasses> + NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf + } + MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { + <LibraryClasses> + PcdLib | MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + } + MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf + MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf + MdeModulePkg/Universal/Metronome/Metronome.inf + MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf + PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf + MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf + MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf + MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf + MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf + MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf + UefiCpuPkg/CpuDxe/CpuDxe.inf + PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf + MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf + MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf + MdeModulePkg/Universal/Console/GraphicsOutputDxe/GraphicsOutputDxe.inf + MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf + MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf + MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf + MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf + UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf + OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf + MdeModulePkg/Universal/SerialDxe/SerialDxe.inf + MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf + MdeModulePkg/Bus/Isa/IsaBusDxe/IsaBusDxe.inf + MdeModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KeyboardDxe.inf + MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf + PcAtChipsetPkg/Bus/Pci/IdeControllerDxe/IdeControllerDxe.inf + MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf + FatPkg/EnhancedFatDxe/Fat.inf + OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf + + ShellPkg/Application/Shell/Shell.inf { + <LibraryClasses> + ShellCommandLib | ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf + NULL | ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf + NULL | ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf + NULL | ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf + NULL | ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf + NULL | ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf + NULL | ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf + NULL | ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf + HandleParsingLib | ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf + PrintLib | MdePkg/Library/BasePrintLib/BasePrintLib.inf + BcfgCommandLib | ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf + <PcdsFixedAtBuild> + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask | 0xFF + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize | FALSE + gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize | 8000 + } + + MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf + OvmfPkg/PlatformDxe/Platform.inf + MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf + MdeModulePkg/Application/UiApp/UiApp.inf + OvmfPkg/IoMmuDxe/IoMmuDxe.inf + MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf + OvmfPkg/SioBusDxe/SioBusDxe.inf + MdeModulePkg/Bus/Pci/PciSioSerialDxe/PciSioSerialDxe.inf diff --git a/Platform/Qemu/QemuOpenBoardPkg/QemuOpenBoardPkg.dsc b/Platform/Qemu/QemuOpenBoardPkg/QemuOpenBoardPkg.dsc index 2a4bda306cb6..55a7b7e6cdb6 100644 --- a/Platform/Qemu/QemuOpenBoardPkg/QemuOpenBoardPkg.dsc +++ b/Platform/Qemu/QemuOpenBoardPkg/QemuOpenBoardPkg.dsc @@ -50,7 +50,7 @@ # Stage 5 - boot to OS with security boot enabled # Stage 6 - boot with advanced features enabled # - gMinPlatformPkgTokenSpaceGuid.PcdBootStage | 2 + gMinPlatformPkgTokenSpaceGuid.PcdBootStage | 3 # # MinPlatform common include for required feature PCD @@ -132,6 +132,7 @@ !include MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc !include QemuOpenBoardPkg/Include/Dsc/Stage1.dsc.inc !include QemuOpenBoardPkg/Include/Dsc/Stage2.dsc.inc +!include QemuOpenBoardPkg/Include/Dsc/Stage3.dsc.inc [LibraryClasses.Common] QemuOpenFwCfgLib | QemuOpenBoardPkg/Library/QemuOpenFwCfgLib/QemuOpenFwCfgLib.inf diff --git a/Platform/Qemu/QemuOpenBoardPkg/QemuOpenBoardPkg.fdf b/Platform/Qemu/QemuOpenBoardPkg/QemuOpenBoardPkg.fdf index de275b4c8841..d07f9b4e7b80 100644 --- a/Platform/Qemu/QemuOpenBoardPkg/QemuOpenBoardPkg.fdf +++ b/Platform/Qemu/QemuOpenBoardPkg/QemuOpenBoardPkg.fdf @@ -174,10 +174,64 @@ SET gMinPlatformPkgTokenSpaceGuid.PcdFlashAreaSize = 0x800000 # Stage 3 Firmware Volumes # ########################### + +[FV.FvUefiBootUnCompressed] + !include MinPlatformPkg/Include/Fdf/CommonSpiFvHeaderInfo.fdf + FvNameGuid = D2F110DB-2388-4963-BEFD-5889EEE01569 + + INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf + + INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf + INF MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf + + INF MdeModulePkg/Universal/Metronome/Metronome.inf + INF PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf + INF UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf + INF UefiCpuPkg/CpuDxe/CpuDxe.inf + INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf + INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf + INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf + INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf + INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf + INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf + INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf + INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf + INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf + INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf + INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf + + INF OvmfPkg/IoMmuDxe/IoMmuDxe.inf + INF OvmfPkg/PlatformDxe/Platform.inf + + INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf + INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf + INF MdeModulePkg/Universal/Console/GraphicsOutputDxe/GraphicsOutputDxe.inf + INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf + INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf + INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf + INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf + INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + + INF MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf + INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf + INF ShellPkg/Application/Shell/Shell.inf + + INF OvmfPkg/SioBusDxe/SioBusDxe.inf + INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf + INF MdeModulePkg/Bus/Pci/PciSioSerialDxe/PciSioSerialDxe.inf + [FV.FvUefiBoot] !include MinPlatformPkg/Include/Fdf/CommonSpiFvHeaderInfo.fdf FvNameGuid = D0C15ADB-FE38-4331-841C-0E96C1B0FBFA + INF MdeModulePkg/Core/Dxe/DxeMain.inf + + FILE FV_IMAGE = D2F110DB-2388-4963-BEFD-5889EEE01569 { + SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE { + SECTION FV_IMAGE = FvUefiBootUncompressed + } + } + ########################### # # Stage 4 Firmware Volumes diff --git a/Platform/Qemu/QemuOpenBoardPkg/Library/BoardBootManagerLib/BoardBootManagerLib.inf b/Platform/Qemu/QemuOpenBoardPkg/Library/BoardBootManagerLib/BoardBootManagerLib.inf new file mode 100644 index 000000000000..37425d711010 --- /dev/null +++ b/Platform/Qemu/QemuOpenBoardPkg/Library/BoardBootManagerLib/BoardBootManagerLib.inf @@ -0,0 +1,39 @@ +## @file +# The module definition file for BoardBootManagerLib. +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BoardBootManagerLib + FILE_GUID = 3fe4b589-8bd9-46df-9322-d06fa2c278d6 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = BoardBootManagerLib|DXE_DRIVER + + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 EBC +# + +[Sources] + BoardBootManager.c + +[LibraryClasses] + BaseLib + UefiBootServicesTableLib + DebugLib + UefiLib + HobLib + UefiBootManagerLib + TimerLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + MinPlatformPkg/MinPlatformPkg.dec diff --git a/Platform/Qemu/QemuOpenBoardPkg/Library/BoardBootManagerLib/BoardBootManager.c b/Platform/Qemu/QemuOpenBoardPkg/Library/BoardBootManagerLib/BoardBootManager.c new file mode 100644 index 000000000000..9fad6bc56dfd --- /dev/null +++ b/Platform/Qemu/QemuOpenBoardPkg/Library/BoardBootManagerLib/BoardBootManager.c @@ -0,0 +1,105 @@ +/** @file + This file include board specific boot manager callbacks + + Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Library/DebugLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/PlatformBootManagerLib.h> +#include <Library/UefiLib.h> +#include <Library/HobLib.h> +#include <Library/PrintLib.h> +#include <Library/PerformanceLib.h> +#include <Library/BoardBootManagerLib.h> + +BOOLEAN mHotKeypressed = FALSE; +EFI_EVENT HotKeyEvent = NULL; +UINTN mBootMenuOptionNumber; + +/** + This function is called each second during the boot manager waits timeout. + + @param TimeoutRemain The remaining timeout. +**/ +VOID +EFIAPI +BoardBootManagerWaitCallback ( + UINT16 TimeoutRemain + ) +{ + EFI_STATUS Status; + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx; + EFI_KEY_DATA KeyData; + BOOLEAN PausePressed; + + // + // Pause on PAUSE key + // + Status = gBS->HandleProtocol (gST->ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (VOID **)&TxtInEx); + ASSERT_EFI_ERROR (Status); + + PausePressed = FALSE; + + while (TRUE) { + Status = TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData); + if (EFI_ERROR (Status)) { + break; + } + + if (KeyData.Key.ScanCode == SCAN_PAUSE) { + PausePressed = TRUE; + break; + } + } + + // + // Loop until non-PAUSE key pressed + // + while (PausePressed) { + Status = TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData); + if (!EFI_ERROR (Status)) { + DEBUG ( + ( + DEBUG_INFO, "[PauseCallback] %x/%x %x/%x\n", + KeyData.Key.ScanCode, KeyData.Key.UnicodeChar, + KeyData.KeyState.KeyShiftState, KeyData.KeyState.KeyToggleState + ) + ); + PausePressed = (BOOLEAN)(KeyData.Key.ScanCode == SCAN_PAUSE); + } + } +} + +/** + The function is called when no boot option could be launched, + including platform recovery options and options pointing to applications + built into firmware volumes. + + If this function returns, BDS attempts to enter an infinite loop. +**/ +VOID +EFIAPI +BoardBootManagerUnableToBoot ( + VOID + ) +{ + EFI_STATUS Status; + EFI_BOOT_MANAGER_LOAD_OPTION BootDeviceList; + CHAR16 OptionName[sizeof ("Boot####")]; + + if (mBootMenuOptionNumber == LoadOptionNumberUnassigned) { + return; + } + + UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", mBootMenuOptionNumber); + Status = EfiBootManagerVariableToLoadOption (OptionName, &BootDeviceList); + if (EFI_ERROR (Status)) { + return; + } + + for ( ;;) { + EfiBootManagerBoot (&BootDeviceList); + } +} -- 2.37.0 (Apple Git-136) -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#93725): https://edk2.groups.io/g/devel/message/93725 Mute This Topic: https://groups.io/mt/93665759/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-