From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7764021106F34 for ; Wed, 29 Aug 2018 19:01:35 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Aug 2018 19:01:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,305,1531810800"; d="scan'208";a="84534476" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.8]) by fmsmga004.fm.intel.com with ESMTP; 29 Aug 2018 19:01:34 -0700 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Hao Wu , Andrew Fish Date: Thu, 30 Aug 2018 10:02:12 +0800 Message-Id: <20180830020213.148968-9-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.16.1.windows.1 In-Reply-To: <20180830020213.148968-1-ruiyu.ni@intel.com> References: <20180830020213.148968-1-ruiyu.ni@intel.com> Subject: [PATCH v2 8/9] EmulatorPkg: Use MdeModulePkg/Bds module X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Aug 2018 02:01:35 -0000 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 Cc: Hao Wu Cc: Andrew Fish --- EmulatorPkg/EmulatorPkg.dsc | 31 +- EmulatorPkg/EmulatorPkg.fdf | 21 +- EmulatorPkg/Library/EmuBdsLib/BdsPlatform.c | 559 --------------------- EmulatorPkg/Library/PlatformBmLib/PlatformBm.c | 435 ++++++++++++++++ .../BdsPlatform.h => PlatformBmLib/PlatformBm.h} | 63 ++- .../PlatformBmData.c} | 13 +- .../PlatformBmLib.inf} | 28 +- .../Library/PlatformBmLib/PlatformBmMemoryTest.c | 133 +++++ 8 files changed, 649 insertions(+), 634 deletions(-) delete mode 100644 EmulatorPkg/Library/EmuBdsLib/BdsPlatform.c create mode 100644 EmulatorPkg/Library/PlatformBmLib/PlatformBm.c rename EmulatorPkg/Library/{EmuBdsLib/BdsPlatform.h => PlatformBmLib/PlatformBm.h} (60%) rename EmulatorPkg/Library/{EmuBdsLib/PlatformData.c => PlatformBmLib/PlatformBmData.c} (77%) rename EmulatorPkg/Library/{EmuBdsLib/EmuBdsLib.inf => PlatformBmLib/PlatformBmLib.inf} (71%) create mode 100644 EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c 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 @@ [LibraryClasses] 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 @@ [LibraryClasses] # # Platform # - PlatformBdsLib|EmulatorPkg/Library/EmuBdsLib/EmuBdsLib.inf + PlatformBootManagerLib|EmulatorPkg/Library/PlatformBmLib/PlatformBmLib.inf KeyMapLib|EmulatorPkg/Library/KeyMapLibNull/KeyMapLibNull.inf # @@ -107,7 +109,6 @@ [LibraryClasses] 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 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.UEFI_DRIVER, Li 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 @@ [PcdsFixedAtBuild] 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 @@ [PcdsDynamicDefault.common.DEFAULT] [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 @@ [Components] } 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 { + + 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 #{ # 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.
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
# Portions copyright (c) 2009 - 2011, Apple Inc. All rights reserved.
# # This program and the accompanying materials @@ -183,9 +183,12 @@ [FV.FvRecovery] 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 @@ [FV.FvRecovery] 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 @@ [Rule.Common.UEFI_APPLICATION] } } +[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.
-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.
+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 similarity index 60% rename from EmulatorPkg/Library/EmuBdsLib/BdsPlatform.h rename to 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 @@ -22,6 +22,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include +#include +#include #include #include @@ -30,15 +33,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include -#include -#include +#include #include #include +#include +#include +#include +#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 similarity index 77% rename from EmulatorPkg/Library/EmuBdsLib/PlatformData.c rename to 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.
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
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 similarity index 71% rename from EmulatorPkg/Library/EmuBdsLib/EmuBdsLib.inf rename to 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.
@@ -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 @@ [LibraryClasses] 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.
+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; +} -- 2.16.1.windows.1