summaryrefslogtreecommitdiffstats
path: root/EmulatorPkg
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2018-08-30 09:53:49 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2018-08-31 10:40:18 +0800
commite01238946cbd16f2dfccd7ec86aebe20d7408586 (patch)
tree56669cfa6c3860e9a031cd60372ba91595e9cc7d /EmulatorPkg
parent0195dd509f80b1ff49739bbf1df39434a6a7540e (diff)
downloadedk2-e01238946cbd16f2dfccd7ec86aebe20d7408586.tar.gz
edk2-e01238946cbd16f2dfccd7ec86aebe20d7408586.tar.bz2
edk2-e01238946cbd16f2dfccd7ec86aebe20d7408586.zip
EmulatorPkg: Use MdeModulePkg/Bds module
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1120 Logo is enabled by adding a separate core driver LogoDxe. UiApp and BootManagerMenuApp are added to provide two UIs. LoadFileOnFv2 is added to auto-install LoadFile protocol for applications in FV so the boot options for applications can be auto-created from LoadFile. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Cc: Andrew Fish <afish@apple.com>
Diffstat (limited to 'EmulatorPkg')
-rw-r--r--EmulatorPkg/EmulatorPkg.dsc31
-rw-r--r--EmulatorPkg/EmulatorPkg.fdf21
-rw-r--r--EmulatorPkg/Library/EmuBdsLib/BdsPlatform.c559
-rw-r--r--EmulatorPkg/Library/PlatformBmLib/PlatformBm.c435
-rw-r--r--EmulatorPkg/Library/PlatformBmLib/PlatformBm.h (renamed from EmulatorPkg/Library/EmuBdsLib/BdsPlatform.h)63
-rw-r--r--EmulatorPkg/Library/PlatformBmLib/PlatformBmData.c (renamed from EmulatorPkg/Library/EmuBdsLib/PlatformData.c)13
-rw-r--r--EmulatorPkg/Library/PlatformBmLib/PlatformBmLib.inf (renamed from EmulatorPkg/Library/EmuBdsLib/EmuBdsLib.inf)28
-rw-r--r--EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c133
8 files changed, 649 insertions, 634 deletions
diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc
index 72e8aa1788..78e9a3f1cc 100644
--- a/EmulatorPkg/EmulatorPkg.dsc
+++ b/EmulatorPkg/EmulatorPkg.dsc
@@ -79,7 +79,9 @@
UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf
OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf
- GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
+ BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf
+ FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf
+ UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf
SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
@@ -90,7 +92,7 @@
#
# Platform
#
- PlatformBdsLib|EmulatorPkg/Library/EmuBdsLib/EmuBdsLib.inf
+ PlatformBootManagerLib|EmulatorPkg/Library/PlatformBmLib/PlatformBmLib.inf
KeyMapLib|EmulatorPkg/Library/KeyMapLibNull/KeyMapLibNull.inf
#
@@ -107,7 +109,6 @@
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
- UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
@@ -171,13 +172,6 @@
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
TimerLib|EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.inf
-[LibraryClasses.common.UEFI_DRIVER]
- PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-
-[LibraryClasses.common.UEFI_APPLICATION]
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-
-
[PcdsFeatureFlag]
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|FALSE
gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|TRUE
@@ -198,6 +192,9 @@
gEmulatorPkgTokenSpaceGuid.PcdEmuMemorySize|L"64!64"
+ # Change PcdBootManagerMenuFile to UiApp
+ gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
+
!ifndef $(USE_OLD_SHELL)
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 }
!endif
@@ -238,7 +235,7 @@
[PcdsDynamicHii.common.DEFAULT]
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn|L"Setup"|gEmuSystemConfigGuid|0x0|80
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow|L"Setup"|gEmuSystemConfigGuid|0x4|25
-
+ gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|10
[Components]
!ifdef $(UNIX_SEC_BUILD)
@@ -337,7 +334,17 @@
}
MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
- IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
+ MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
+ MdeModulePkg/Logo/LogoDxe.inf
+ MdeModulePkg/Universal/LoadFileOnFv2/LoadFileOnFv2.inf
+ MdeModulePkg/Application/UiApp/UiApp.inf {
+ <LibraryClasses>
+ NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf
+ NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf
+ NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf
+ }
+ MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf
+
MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
#{
# <LibraryClasses>
diff --git a/EmulatorPkg/EmulatorPkg.fdf b/EmulatorPkg/EmulatorPkg.fdf
index 314eb7b895..5b5f81443d 100644
--- a/EmulatorPkg/EmulatorPkg.fdf
+++ b/EmulatorPkg/EmulatorPkg.fdf
@@ -1,7 +1,7 @@
## @file
# This is Emulator FDF file with UEFI HII features enabled
#
-# Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2009 - 2011, Apple Inc. All rights reserved.<BR>
#
# This program and the accompanying materials
@@ -183,9 +183,12 @@ INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
INF MdeModulePkg/Universal/PrintDxe/PrintDxe.inf
-INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
+INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
+INF MdeModulePkg/Logo/LogoDxe.inf
+INF MdeModulePkg/Universal/LoadFileOnFv2/LoadFileOnFv2.inf
+INF RuleOverride = UI MdeModulePkg/Application/UiApp/UiApp.inf
+INF MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf
INF MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf
-INF MdeModulePkg/Application/HelloWorld/HelloWorld.inf
#
# Network stack drivers
@@ -212,11 +215,6 @@ INF ShellPkg/Application/Shell/Shell.inf
INF RuleOverride = BINARY EdkShellBinPkg/FullShell/FullShell.inf
!endif
-FILE FREEFORM = PCD(gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile) {
- SECTION RAW = MdeModulePkg/Logo/Logo.bmp
-}
-
-
[Rule.Common.SEC]
FILE SEC = $(NAMED_GUID) {
PE32 PE32 Align=Auto $(INF_OUTPUT)/$(MODULE_NAME).efi
@@ -296,6 +294,13 @@ FILE FREEFORM = PCD(gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile) {
}
}
+[Rule.Common.UEFI_APPLICATION.UI]
+ FILE APPLICATION = $(NAMED_GUID) {
+ PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
+ UI STRING="Enter Setup"
+ VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+ }
+
[Rule.Common.UEFI_DRIVER.BINARY]
FILE DRIVER = $(NAMED_GUID) {
DXE_DEPEX DXE_DEPEX Optional |.depex
diff --git a/EmulatorPkg/Library/EmuBdsLib/BdsPlatform.c b/EmulatorPkg/Library/EmuBdsLib/BdsPlatform.c
deleted file mode 100644
index 75fba847f4..0000000000
--- a/EmulatorPkg/Library/EmuBdsLib/BdsPlatform.c
+++ /dev/null
@@ -1,559 +0,0 @@
-/*++ @file
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-Portions copyright (c) 2011, Apple Inc. All rights reserved.
-This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "BdsPlatform.h"
-
-EMU_SYSTEM_CONFIGURATION mSystemConfigData;
-
-VOID
-SetupVariableInit (
- VOID
- )
-{
- EFI_STATUS Status;
- UINTN Size;
-
- Size = sizeof (mSystemConfigData);
- Status = gRT->GetVariable (
- L"Setup",
- &gEmuSystemConfigGuid,
- NULL,
- &Size,
- (VOID *) &mSystemConfigData
- );
-
- if (EFI_ERROR (Status)) {
- //
- // SetupVariable is corrupt
- //
- mSystemConfigData.ConOutRow = PcdGet32 (PcdConOutColumn);
- mSystemConfigData.ConOutColumn = PcdGet32 (PcdConOutRow);
-
- Status = gRT->SetVariable (
- L"Setup",
- &gEmuSystemConfigGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- sizeof (mSystemConfigData),
- (VOID *) &mSystemConfigData
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));
- }
- }
-}
-
-//
-// BDS Platform Functions
-//
-VOID
-EFIAPI
-PlatformBdsInit (
- VOID
- )
-/*++
-
-Routine Description:
-
- Platform Bds init. Include the platform firmware vendor, revision
- and so crc check.
-
-Arguments:
-
-Returns:
-
- None.
-
-**/
-{
- SetupVariableInit ();
-
- EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);
-}
-
-EFI_STATUS
-PlatformBdsConnectConsole (
- IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
- )
-/*++
-
-Routine Description:
-
- Connect the predefined platform default console device. Always try to find
- and enable the vga device if have.
-
-Arguments:
-
- PlatformConsole - Predefined platform default console device array.
-
-Returns:
-
- EFI_SUCCESS - Success connect at least one ConIn and ConOut
- device, there must have one ConOut device is
- active vga device.
-
- EFI_STATUS - Return the status of
- BdsLibConnectAllDefaultConsoles ()
-
-**/
-{
- EFI_STATUS Status;
- UINTN Index;
-
- Index = 0;
- Status = EFI_SUCCESS;
-
- //
- // Have chance to connect the platform default console,
- // the platform default console is the minimum device group
- // the platform should support
- //
- while (PlatformConsole[Index].DevicePath != NULL) {
- //
- // Update the console variable with the connect type
- //
- if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
- BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);
- }
-
- if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
- BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);
- }
-
- if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
- BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);
- }
-
- Index++;
- }
- //
- // Connect the all the default console with current cosole variable
- //
- Status = BdsLibConnectAllDefaultConsoles ();
- return Status;
-}
-
-VOID
-PlatformBdsConnectSequence (
- VOID
- )
-/*++
-
-Routine Description:
-
- Connect with predefined platform connect sequence,
- the OEM/IBV can customize with their own connect sequence.
-
-Arguments:
-
- None.
-
-Returns:
-
- None.
-
-**/
-{
- UINTN Index;
-
- Index = 0;
-
- //
- // Here we can get the customized platform connect sequence
- // Notes: we can connect with new variable which record the
- // last time boots connect device path sequence
- //
- while (gPlatformConnectSequence[Index] != NULL) {
- //
- // Build the platform boot option
- //
- BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);
- Index++;
- }
-
- //
- // Just use the simple policy to connect all devices
- //
- BdsLibConnectAll ();
-}
-
-VOID
-PlatformBdsGetDriverOption (
- IN OUT LIST_ENTRY *BdsDriverLists
- )
-/*++
-
-Routine Description:
-
- Load the predefined driver option, OEM/IBV can customize this
- to load their own drivers
-
-Arguments:
-
- BdsDriverLists - The header of the driver option link list.
-
-Returns:
-
- None.
-
-**/
-{
- UINTN Index;
-
- Index = 0;
-
- //
- // Here we can get the customized platform driver option
- //
- while (gPlatformDriverOption[Index] != NULL) {
- //
- // Build the platform boot option
- //
- BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");
- Index++;
- }
-
-}
-
-VOID
-PlatformBdsDiagnostics (
- IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
- IN BOOLEAN QuietBoot,
- IN BASEM_MEMORY_TEST BaseMemoryTest
- )
-/*++
-
-Routine Description:
-
- Perform the platform diagnostic, such like test memory. OEM/IBV also
- can customize this fuction to support specific platform diagnostic.
-
-Arguments:
-
- MemoryTestLevel - The memory test intensive level
-
- QuietBoot - Indicate if need to enable the quiet boot
-
- BaseMemoryTest - A pointer to BdsMemoryTest()
-
-Returns:
-
- None.
-
-**/
-{
- EFI_STATUS Status;
-
- //
- // Here we can decide if we need to show
- // the diagnostics screen
- // Notes: this quiet boot code should be remove
- // from the graphic lib
- //
- if (QuietBoot) {
- EnableQuietBoot (PcdGetPtr(PcdLogoFile));
- //
- // Perform system diagnostic
- //
- Status = BaseMemoryTest (MemoryTestLevel);
- if (EFI_ERROR (Status)) {
- DisableQuietBoot ();
- }
-
- return ;
- }
- //
- // Perform system diagnostic
- //
- Status = BaseMemoryTest (MemoryTestLevel);
-}
-
-VOID
-EFIAPI
-PlatformBdsPolicyBehavior (
- IN OUT LIST_ENTRY *DriverOptionList,
- IN OUT LIST_ENTRY *BootOptionList,
- IN PROCESS_CAPSULES ProcessCapsules,
- IN BASEM_MEMORY_TEST BaseMemoryTest
- )
-/*++
-
-Routine Description:
-
- The function will execute with as the platform policy, current policy
- is driven by boot mode. IBV/OEM can customize this code for their specific
- policy action.
-
-Arguments:
-
- DriverOptionList - The header of the driver option link list
-
- BootOptionList - The header of the boot option link list
-
- ProcessCapsules - A pointer to ProcessCapsules()
-
- BaseMemoryTest - A pointer to BaseMemoryTest()
-
-Returns:
-
- None.
-
-**/
-{
- EFI_STATUS Status;
- UINT16 Timeout;
- EFI_BOOT_MODE BootMode;
-
- //
- // Init the time out value
- //
- Timeout = PcdGet16 (PcdPlatformBootTimeOut);
-
- //
- // Load the driver option as the driver option list
- //
- PlatformBdsGetDriverOption (DriverOptionList);
-
- //
- // Get current Boot Mode
- //
- Status = BdsLibGetBootMode (&BootMode);
-
- //
- // Go the different platform policy with different boot mode
- // Notes: this part code can be change with the table policy
- //
- switch (BootMode) {
-
- case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
- case BOOT_WITH_MINIMAL_CONFIGURATION:
- //
- // In no-configuration boot mode, we can connect the
- // console directly.
- //
- BdsLibConnectAllDefaultConsoles ();
- PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);
-
- //
- // Perform some platform specific connect sequence
- //
- PlatformBdsConnectSequence ();
-
- //
- // Notes: current time out = 0 can not enter the
- // front page
- //
- PlatformBdsEnterFrontPage (Timeout, FALSE);
-
- //
- // Check the boot option with the boot option list
- //
- BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
- break;
-
- case BOOT_ON_FLASH_UPDATE:
- //
- // Boot with the specific configuration
- //
- PlatformBdsConnectConsole (gPlatformConsole);
- PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);
- BdsLibConnectAll ();
- ProcessCapsules (BOOT_ON_FLASH_UPDATE);
- break;
-
- case BOOT_IN_RECOVERY_MODE:
- //
- // In recovery mode, just connect platform console
- // and show up the front page
- //
- PlatformBdsConnectConsole (gPlatformConsole);
- PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);
-
- //
- // In recovery boot mode, we still enter to the
- // frong page now
- //
- PlatformBdsEnterFrontPage (Timeout, FALSE);
- break;
-
- case BOOT_WITH_FULL_CONFIGURATION:
- case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
- case BOOT_WITH_DEFAULT_SETTINGS:
- default:
- //
- // Connect platform console
- //
- Status = PlatformBdsConnectConsole (gPlatformConsole);
- if (EFI_ERROR (Status)) {
- //
- // Here OEM/IBV can customize with defined action
- //
- PlatformBdsNoConsoleAction ();
- }
-
- PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);
-
- //
- // Perform some platform specific connect sequence
- //
- PlatformBdsConnectSequence ();
-
- //
- // Give one chance to enter the setup if we
- // have the time out
- //
- PlatformBdsEnterFrontPage (Timeout, FALSE);
-
- //
- // Here we have enough time to do the enumeration of boot device
- //
- BdsLibEnumerateAllBootOption (BootOptionList);
- break;
- }
-
- return ;
-
-}
-
-VOID
-EFIAPI
-PlatformBdsBootSuccess (
- IN BDS_COMMON_OPTION *Option
- )
-/*++
-
-Routine Description:
-
- Hook point after a boot attempt succeeds. We don't expect a boot option to
- return, so the EFI 1.0 specification defines that you will default to an
- interactive mode and stop processing the BootOrder list in this case. This
- is alos a platform implementation and can be customized by IBV/OEM.
-
-Arguments:
-
- Option - Pointer to Boot Option that succeeded to boot.
-
-Returns:
-
- None.
-
-**/
-{
- CHAR16 *TmpStr;
-
- //
- // If Boot returned with EFI_SUCCESS and there is not in the boot device
- // select loop then we need to pop up a UI and wait for user input.
- //
- TmpStr = Option->StatusString;
- if (TmpStr != NULL) {
- BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
- FreePool (TmpStr);
- }
-}
-
-VOID
-EFIAPI
-PlatformBdsBootFail (
- IN BDS_COMMON_OPTION *Option,
- IN EFI_STATUS Status,
- IN CHAR16 *ExitData,
- IN UINTN ExitDataSize
- )
-/*++
-
-Routine Description:
-
- Hook point after a boot attempt fails.
-
-Arguments:
-
- Option - Pointer to Boot Option that failed to boot.
-
- Status - Status returned from failed boot.
-
- ExitData - Exit data returned from failed boot.
-
- ExitDataSize - Exit data size returned from failed boot.
-
-Returns:
-
- None.
-
-**/
-{
- CHAR16 *TmpStr;
-
- //
- // If Boot returned with failed status then we need to pop up a UI and wait
- // for user input.
- //
- TmpStr = Option->StatusString;
- if (TmpStr != NULL) {
- BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
- FreePool (TmpStr);
- }
-}
-
-EFI_STATUS
-PlatformBdsNoConsoleAction (
- VOID
- )
-/*++
-
-Routine Description:
-
- This function is remained for IBV/OEM to do some platform action,
- if there no console device can be connected.
-
-Arguments:
-
- None.
-
-Returns:
-
- EFI_SUCCESS - Direct return success now.
-
-**/
-{
- return EFI_SUCCESS;
-}
-
-VOID
-EFIAPI
-PlatformBdsLockNonUpdatableFlash (
- VOID
- )
-{
- return;
-}
-
-/**
- Lock the ConsoleIn device in system table. All key
- presses will be ignored until the Password is typed in. The only way to
- disable the password is to type it in to a ConIn device.
-
- @param Password Password used to lock ConIn device.
-
- @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
- @retval EFI_UNSUPPORTED Password not found
-
-**/
-EFI_STATUS
-EFIAPI
-LockKeyboards (
- IN CHAR16 *Password
- )
-{
- return EFI_UNSUPPORTED;
-}
diff --git a/EmulatorPkg/Library/PlatformBmLib/PlatformBm.c b/EmulatorPkg/Library/PlatformBmLib/PlatformBm.c
new file mode 100644
index 0000000000..4e3297c984
--- /dev/null
+++ b/EmulatorPkg/Library/PlatformBmLib/PlatformBm.c
@@ -0,0 +1,435 @@
+/*++ @file
+
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2011, Apple Inc. All rights reserved.
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "PlatformBm.h"
+
+EFI_GUID mBootMenuFile = {
+ 0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D }
+};
+
+/**
+ Initialize the "Setup" variable.
+**/
+VOID
+SetupVariableInit (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ UINTN Size;
+ EMU_SYSTEM_CONFIGURATION SystemConfigData;
+
+ Size = sizeof (SystemConfigData);
+ Status = gRT->GetVariable (
+ L"Setup",
+ &gEmuSystemConfigGuid,
+ NULL,
+ &Size,
+ (VOID *) &SystemConfigData
+ );
+
+ if (EFI_ERROR (Status)) {
+ //
+ // SetupVariable is corrupt
+ //
+ SystemConfigData.ConOutRow = PcdGet32 (PcdConOutColumn);
+ SystemConfigData.ConOutColumn = PcdGet32 (PcdConOutRow);
+
+ Status = gRT->SetVariable (
+ L"Setup",
+ &gEmuSystemConfigGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ sizeof (SystemConfigData),
+ (VOID *) &SystemConfigData
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));
+ }
+ }
+}
+
+EFI_DEVICE_PATH *
+FvFilePath (
+ EFI_GUID *FileGuid
+ )
+{
+
+ EFI_STATUS Status;
+ EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;
+
+ EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
+
+ Status = gBS->HandleProtocol (
+ gImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ (VOID **) &LoadedImage
+ );
+ ASSERT_EFI_ERROR (Status);
+ return AppendDevicePathNode (
+ DevicePathFromHandle (LoadedImage->DeviceHandle),
+ (EFI_DEVICE_PATH_PROTOCOL *) &FileNode
+ );
+}
+
+/**
+ Create one boot option for BootManagerMenuApp.
+
+ @param FileGuid Input file guid for the BootManagerMenuApp.
+ @param Description Description of the BootManagerMenuApp boot option.
+ @param Position Position of the new load option to put in the ****Order variable.
+ @param IsBootCategory Whether this is a boot category.
+
+
+ @retval OptionNumber Return the option number info.
+
+**/
+UINTN
+RegisterBootManagerMenuAppBootOption (
+ EFI_GUID *FileGuid,
+ CHAR16 *Description,
+ UINTN Position,
+ BOOLEAN IsBootCategory
+ )
+{
+ EFI_STATUS Status;
+ EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ UINTN OptionNumber;
+
+ DevicePath = FvFilePath (FileGuid);
+ Status = EfiBootManagerInitializeLoadOption (
+ &NewOption,
+ LoadOptionNumberUnassigned,
+ LoadOptionTypeBoot,
+ IsBootCategory ? LOAD_OPTION_ACTIVE : LOAD_OPTION_CATEGORY_APP,
+ Description,
+ DevicePath,
+ NULL,
+ 0
+ );
+ ASSERT_EFI_ERROR (Status);
+ FreePool (DevicePath);
+
+ Status = EfiBootManagerAddLoadOptionVariable (&NewOption, Position);
+ ASSERT_EFI_ERROR (Status);
+
+ OptionNumber = NewOption.OptionNumber;
+
+ EfiBootManagerFreeLoadOption (&NewOption);
+
+ return OptionNumber;
+}
+
+/**
+ Check if it's a Device Path pointing to BootManagerMenuApp.
+
+ @param DevicePath Input device path.
+
+ @retval TRUE The device path is BootManagerMenuApp File Device Path.
+ @retval FALSE The device path is NOT BootManagerMenuApp File Device Path.
+**/
+BOOLEAN
+IsBootManagerMenuAppFilePath (
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath
+)
+{
+ EFI_HANDLE FvHandle;
+ VOID *NameGuid;
+ EFI_STATUS Status;
+
+ Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &DevicePath, &FvHandle);
+ if (!EFI_ERROR (Status)) {
+ NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) DevicePath);
+ if (NameGuid != NULL) {
+ return CompareGuid (NameGuid, &mBootMenuFile);
+ }
+ }
+
+ return FALSE;
+}
+
+/**
+ Return the boot option number to the BootManagerMenuApp.
+
+ If not found it in the current boot option, create a new one.
+
+ @retval OptionNumber Return the boot option number to the BootManagerMenuApp.
+
+**/
+UINTN
+GetBootManagerMenuAppOption (
+ VOID
+ )
+{
+ UINTN BootOptionCount;
+ EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
+ UINTN Index;
+ UINTN OptionNumber;
+
+ OptionNumber = 0;
+
+ BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
+
+ for (Index = 0; Index < BootOptionCount; Index++) {
+ if (IsBootManagerMenuAppFilePath (BootOptions[Index].FilePath)) {
+ OptionNumber = BootOptions[Index].OptionNumber;
+ break;
+ }
+ }
+
+ EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
+
+ if (Index >= BootOptionCount) {
+ //
+ // If not found the BootManagerMenuApp, create it.
+ //
+ OptionNumber = (UINT16) RegisterBootManagerMenuAppBootOption (&mBootMenuFile, L"UEFI BootManagerMenuApp", (UINTN) -1, FALSE);
+ }
+
+ return OptionNumber;
+}
+
+/**
+ Platform Bds init. Include the platform firmware vendor, revision
+ and so crc check.
+**/
+VOID
+EFIAPI
+PlatformBootManagerBeforeConsole (
+ VOID
+ )
+{
+ UINTN Index;
+
+ SetupVariableInit ();
+
+ EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);
+
+ Index = 0;
+ while (gPlatformConsole[Index].DevicePath != NULL) {
+ //
+ // Update the console variable with the connect type
+ //
+ if ((gPlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
+ EfiBootManagerUpdateConsoleVariable (ConIn, gPlatformConsole[Index].DevicePath, NULL);
+ }
+
+ if ((gPlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
+ EfiBootManagerUpdateConsoleVariable (ConOut, gPlatformConsole[Index].DevicePath, NULL);
+ }
+
+ if ((gPlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
+ EfiBootManagerUpdateConsoleVariable (ErrOut, gPlatformConsole[Index].DevicePath, NULL);
+ }
+
+ Index++;
+ }
+}
+
+/**
+ Connect with predefined platform connect sequence,
+ the OEM/IBV can customize with their own connect sequence.
+**/
+VOID
+PlatformBdsConnectSequence (
+ VOID
+ )
+{
+ //
+ // Just use the simple policy to connect all devices
+ //
+ EfiBootManagerConnectAll ();
+}
+
+/**
+ Perform the platform diagnostic, such like test memory. OEM/IBV also
+ can customize this fuction to support specific platform diagnostic.
+
+ @param MemoryTestLevel The memory test intensive level
+ @param QuietBoot Indicate if need to enable the quiet boot
+**/
+VOID
+PlatformBdsDiagnostics (
+ IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
+ IN BOOLEAN QuietBoot
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Here we can decide if we need to show
+ // the diagnostics screen
+ //
+ if (QuietBoot) {
+ BootLogoEnableLogo ();
+
+ //
+ // Perform system diagnostic
+ //
+ Status = PlatformBootManagerMemoryTest (MemoryTestLevel);
+ if (EFI_ERROR (Status)) {
+ BootLogoDisableLogo ();
+ }
+
+ return;
+ }
+
+ //
+ // Perform system diagnostic
+ //
+ PlatformBootManagerMemoryTest (MemoryTestLevel);
+}
+
+/**
+ Register the static boot options.
+**/
+VOID
+PlatformBdsRegisterStaticBootOptions (
+ VOID
+ )
+{
+ EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;
+ EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;
+ EFI_INPUT_KEY Enter;
+ EFI_INPUT_KEY F2;
+ EFI_INPUT_KEY F7;
+ EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
+ UINTN OptionNumber;
+
+ Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;
+ White.Blue = White.Green = White.Red = White.Reserved = 0xFF;
+
+ //
+ // Register ENTER as CONTINUE key
+ //
+ Enter.ScanCode = SCAN_NULL;
+ Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
+ EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
+ //
+ // Map F2 to Boot Manager Menu
+ //
+ F2.ScanCode = SCAN_F2;
+ F2.UnicodeChar = CHAR_NULL;
+ EfiBootManagerGetBootManagerMenu (&BootOption);
+ EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);
+
+ //
+ // 3. Boot Device List menu
+ //
+ F7.ScanCode = SCAN_F7;
+ F7.UnicodeChar = CHAR_NULL;
+ OptionNumber = GetBootManagerMenuAppOption ();
+ EfiBootManagerAddKeyOptionVariable (NULL, (UINT16)OptionNumber, 0, &F7, NULL);
+
+ PrintXY (10, 10, &White, &Black, L"F2 to enter Setup. ");
+ PrintXY (10, 30, &White, &Black, L"F7 to enter Boot Manager Menu.");
+ PrintXY (10, 50, &White, &Black, L"Enter to boot directly.");
+}
+
+/**
+ Do the platform specific action after the console is connected.
+
+ Such as:
+ Dynamically switch output mode;
+ Signal console ready platform customized event;
+ Run diagnostics like memory testing;
+ Connect certain devices;
+ Dispatch aditional option roms.
+**/
+VOID
+EFIAPI
+PlatformBootManagerAfterConsole (
+ VOID
+ )
+{
+
+ //
+ // Go the different platform policy with different boot mode
+ // Notes: this part code can be change with the table policy
+ //
+ switch (GetBootModeHob ()) {
+
+ case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
+ case BOOT_WITH_MINIMAL_CONFIGURATION:
+ PlatformBdsDiagnostics (IGNORE, TRUE);
+
+ //
+ // Perform some platform specific connect sequence
+ //
+ PlatformBdsConnectSequence ();
+ break;
+
+ case BOOT_IN_RECOVERY_MODE:
+ PlatformBdsDiagnostics (EXTENSIVE, FALSE);
+ break;
+
+ case BOOT_WITH_FULL_CONFIGURATION:
+ case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
+ case BOOT_WITH_DEFAULT_SETTINGS:
+ default:
+ PlatformBdsDiagnostics (IGNORE, TRUE);
+ PlatformBdsRegisterStaticBootOptions ();
+ PlatformBdsConnectSequence ();
+ EfiBootManagerRefreshAllBootOption ();
+ break;
+ }
+}
+
+/**
+ This function is called each second during the boot manager waits the timeout.
+
+ @param TimeoutRemain The remaining timeout.
+**/
+VOID
+EFIAPI
+PlatformBootManagerWaitCallback (
+ UINT16 TimeoutRemain
+ )
+{
+ EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black;
+ EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White;
+ UINT16 Timeout;
+
+ Timeout = PcdGet16 (PcdPlatformBootTimeOut);
+
+ Black.Raw = 0x00000000;
+ White.Raw = 0x00FFFFFF;
+
+ BootLogoUpdateProgress (
+ White.Pixel,
+ Black.Pixel,
+ L"Start boot option",
+ White.Pixel,
+ (Timeout - TimeoutRemain) * 100 / Timeout,
+ 0
+ );
+}
+
+/**
+ 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
+PlatformBootManagerUnableToBoot (
+ VOID
+ )
+{
+ return;
+}
+
diff --git a/EmulatorPkg/Library/EmuBdsLib/BdsPlatform.h b/EmulatorPkg/Library/PlatformBmLib/PlatformBm.h
index 5ececd4bed..323a8bd19a 100644
--- a/EmulatorPkg/Library/EmuBdsLib/BdsPlatform.h
+++ b/EmulatorPkg/Library/PlatformBmLib/PlatformBm.h
@@ -12,8 +12,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
-#ifndef _BDS_PLATFORM_H
-#define _BDS_PLATFORM_H
+#ifndef _PLATFORM_BM_H
+#define _PLATFORM_BM_H
#include <PiDxe.h>
@@ -22,6 +22,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/EmuThunk.h>
#include <Protocol/EmuIoThunk.h>
#include <Protocol/EmuGraphicsWindow.h>
+#include <Protocol/GenericMemoryTest.h>
+#include <Protocol/LoadedImage.h>
+#include <Protocol/FirmwareVolume2.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
@@ -30,15 +33,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseLib.h>
#include <Library/PcdLib.h>
-#include <Library/GenericBdsLib.h>
-#include <Library/PlatformBdsLib.h>
+#include <Library/UefiBootManagerLib.h>
#include <Library/DevicePathLib.h>
#include <Library/UefiLib.h>
+#include <Library/BootLogoLib.h>
+#include <Library/HobLib.h>
+#include <Library/HiiLib.h>
+#define CONSOLE_OUT 0x00000001
+#define STD_ERROR 0x00000002
+#define CONSOLE_IN 0x00000004
+#define CONSOLE_ALL (CONSOLE_OUT | CONSOLE_IN | STD_ERROR)
+
+typedef struct {
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ UINTN ConnectType;
+} BDS_CONSOLE_CONNECT_ENTRY;
extern BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole[];
-extern EFI_DEVICE_PATH_PROTOCOL *gPlatformConnectSequence[];
-extern EFI_DEVICE_PATH_PROTOCOL *gPlatformDriverOption[];
#define gEndEntire \
{ \
@@ -61,41 +73,26 @@ typedef struct {
//
// Platform BDS Functions
//
-VOID
-PlatformBdsGetDriverOption (
- IN LIST_ENTRY *BdsDriverLists
- );
-EFI_STATUS
-BdsMemoryTest (
- EXTENDMEM_COVERAGE_LEVEL Level
- );
+/**
+ Perform the memory test base on the memory test intensive level,
+ and update the memory resource.
+ @param Level The memory test intensive level.
-VOID
-PlatformBdsConnectSequence (
- VOID
- );
+ @retval EFI_STATUS Success test all the system memory and update
+ the memory resource
+**/
EFI_STATUS
-ProcessCapsules (
- EFI_BOOT_MODE BootMode
+PlatformBootManagerMemoryTest (
+ IN EXTENDMEM_COVERAGE_LEVEL Level
);
-EFI_STATUS
-PlatformBdsConnectConsole (
- IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
- );
-
-EFI_STATUS
-PlatformBdsNoConsoleAction (
- VOID
- );
VOID
-PlatformBdsEnterFrontPage (
- IN UINT16 TimeoutDefault,
- IN BOOLEAN ConnectAllHappened
+PlatformBdsConnectSequence (
+ VOID
);
-#endif // _BDS_PLATFORM_H
+#endif // _PLATFORM_BM_H
diff --git a/EmulatorPkg/Library/EmuBdsLib/PlatformData.c b/EmulatorPkg/Library/PlatformBmLib/PlatformBmData.c
index 3eb959b894..bb9d7fff2b 100644
--- a/EmulatorPkg/Library/EmuBdsLib/PlatformData.c
+++ b/EmulatorPkg/Library/PlatformBmLib/PlatformBmData.c
@@ -1,6 +1,6 @@
/*++ @file
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
-#include "BdsPlatform.h"
+#include "PlatformBm.h"
@@ -62,12 +62,3 @@ BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole[] = {
}
};
-//
-// Predefined platform specific driver option
-//
-EFI_DEVICE_PATH_PROTOCOL *gPlatformDriverOption[] = { NULL };
-
-//
-// Predefined platform connect sequence
-//
-EFI_DEVICE_PATH_PROTOCOL *gPlatformConnectSequence[] = { NULL };
diff --git a/EmulatorPkg/Library/EmuBdsLib/EmuBdsLib.inf b/EmulatorPkg/Library/PlatformBmLib/PlatformBmLib.inf
index 755c50c789..af074c3c4b 100644
--- a/EmulatorPkg/Library/EmuBdsLib/EmuBdsLib.inf
+++ b/EmulatorPkg/Library/PlatformBmLib/PlatformBmLib.inf
@@ -1,5 +1,5 @@
## @file
-# Platfrom BDS driver
+# Platfrom Boot Manager library
#
# Do platform action customized by IBV/OEM.
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
@@ -17,29 +17,29 @@
[Defines]
INF_VERSION = 0x00010005
- BASE_NAME = EmuBdsLib
- FILE_GUID = 59569181-CBF8-2E44-9C3E-C2AB2F5608E1
+ BASE_NAME = PlatformBmLib
+ FILE_GUID = 59569181-CBF8-2E44-9C3E-C2AB2F5608E1
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
- LIBRARY_CLASS = PlatformBdsLib|DXE_DRIVER
+ LIBRARY_CLASS = PlatformBootManagerLib|DXE_DRIVER
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+# VALID_ARCHITECTURES = IA32 X64
#
[Sources]
- BdsPlatform.c
- PlatformData.c
- BdsPlatform.h
+ PlatformBm.c
+ PlatformBm.h
+ PlatformBmData.c
+ PlatformBmMemoryTest.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
EmulatorPkg/EmulatorPkg.dec
- IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
[LibraryClasses]
BaseLib
@@ -49,19 +49,25 @@
BaseMemoryLib
DebugLib
PcdLib
- GenericBdsLib
+ UefiBootManagerLib
DevicePathLib
UefiLib
+ BootLogoLib
+ HobLib
+ HiiLib
[Guids]
gEmuSystemConfigGuid
gEfiEndOfDxeEventGroupGuid
+[Protocols]
+ gEfiGenericMemTestProtocolGuid
+
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut
- gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile
+ gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand
[Depex]
gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid
diff --git a/EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c b/EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c
new file mode 100644
index 0000000000..5b39776453
--- /dev/null
+++ b/EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c
@@ -0,0 +1,133 @@
+/** @file
+ Perform the platform memory test
+
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "PlatformBm.h"
+
+//
+// BDS Platform Functions
+//
+
+/**
+ Perform the memory test base on the memory test intensive level,
+ and update the memory resource.
+
+ @param Level The memory test intensive level.
+
+ @retval EFI_STATUS Success test all the system memory and update
+ the memory resource
+
+**/
+EFI_STATUS
+PlatformBootManagerMemoryTest (
+ IN EXTENDMEM_COVERAGE_LEVEL Level
+ )
+{
+ EFI_STATUS Status;
+ EFI_STATUS KeyStatus;
+ EFI_STATUS InitStatus;
+ EFI_STATUS ReturnStatus;
+ BOOLEAN RequireSoftECCInit;
+ EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest;
+ UINT64 TestedMemorySize;
+ UINT64 TotalMemorySize;
+ UINT64 PreviousValue;
+ BOOLEAN ErrorOut;
+ BOOLEAN TestAbort;
+ EFI_INPUT_KEY Key;
+ CHAR16 *StrTotalMemory;
+ CHAR16 *Pos;
+ UINTN StrTotalMemorySize;
+
+ ReturnStatus = EFI_SUCCESS;
+ ZeroMem (&Key, sizeof (EFI_INPUT_KEY));
+
+ StrTotalMemorySize = 128;
+ Pos = AllocateZeroPool (StrTotalMemorySize);
+ ASSERT (Pos != NULL);
+
+ StrTotalMemory = Pos;
+
+ TestedMemorySize = 0;
+ TotalMemorySize = 0;
+ PreviousValue = 0;
+ ErrorOut = FALSE;
+ TestAbort = FALSE;
+
+ RequireSoftECCInit = FALSE;
+
+ Status = gBS->LocateProtocol (
+ &gEfiGenericMemTestProtocolGuid,
+ NULL,
+ (VOID **) &GenMemoryTest
+ );
+ if (EFI_ERROR (Status)) {
+ FreePool (Pos);
+ return EFI_SUCCESS;
+ }
+
+ InitStatus = GenMemoryTest->MemoryTestInit (
+ GenMemoryTest,
+ Level,
+ &RequireSoftECCInit
+ );
+ if (InitStatus == EFI_NO_MEDIA) {
+ //
+ // The PEI codes also have the relevant memory test code to check the memory,
+ // it can select to test some range of the memory or all of them. If PEI code
+ // checks all the memory, this BDS memory test will has no not-test memory to
+ // do the test, and then the status of EFI_NO_MEDIA will be returned by
+ // "MemoryTestInit". So it does not need to test memory again, just return.
+ //
+ FreePool (Pos);
+ return EFI_SUCCESS;
+ }
+
+ DEBUG ((DEBUG_INFO, "Enter memory test.\n"));
+ do {
+ Status = GenMemoryTest->PerformMemoryTest (
+ GenMemoryTest,
+ &TestedMemorySize,
+ &TotalMemorySize,
+ &ErrorOut,
+ TestAbort
+ );
+ if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {
+ PrintXY (10, 10, NULL, NULL, L"Memory Testing failed!");
+ ASSERT (0);
+ }
+
+
+ DEBUG ((DEBUG_INFO, "Perform memory test (ESC to skip).\n"));
+
+ if (!PcdGetBool (PcdConInConnectOnDemand)) {
+ KeyStatus = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
+ if (!EFI_ERROR (KeyStatus) && (Key.ScanCode == SCAN_ESC)) {
+ if (!RequireSoftECCInit) {
+ Status = GenMemoryTest->Finished (GenMemoryTest);
+ goto Done;
+ }
+
+ TestAbort = TRUE;
+ }
+ }
+ } while (Status != EFI_NOT_FOUND);
+
+ Status = GenMemoryTest->Finished (GenMemoryTest);
+
+Done:
+ DEBUG ((DEBUG_INFO, "%d bytes of system memory tested OK\r\n", TotalMemorySize));
+
+ FreePool (Pos);
+ return ReturnStatus;
+}