X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Nt32Pkg%2FLibrary%2FPlatformBootManagerLib%2FPlatformBootManager.c;h=cf8289faff174660fc84455277683f1b8902ecd9;hp=7964b2b8082cb3f1eeb3c6c60105f315585d3765;hb=11cf25f030eb9b9a4541b35791c46d85709173f2;hpb=8f227c2fd97c8160c6e3f99c532d778942efaf62 diff --git a/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c b/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c index 7964b2b808..cf8289faff 100644 --- a/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c +++ b/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c @@ -2,7 +2,8 @@ This file include all platform action which can be customized by IBV/OEM. -Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP
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 @@ -15,179 +16,50 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "PlatformBootManager.h" - -EFI_GUID mUefiShellFileGuid = { 0x7C04A583, 0x9E3E, 0x4f1c, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 }; +EFI_GUID mBootMenuFile = { + 0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D } +}; /** - Perform the memory test base on the memory test intensive level, - and update the memory resource. - - @param Level The memory test intensive level. + Perform the platform diagnostic, such like test memory. OEM/IBV also + can customize this function to support specific platform diagnostic. - @retval EFI_STATUS Success test all the system memory and update - the memory resource + @param MemoryTestLevel The memory test intensive level + @param QuietBoot Indicate if need to enable the quiet boot **/ -EFI_STATUS -PlatformBootManagerMemoryTest ( - IN EXTENDMEM_COVERAGE_LEVEL Level +VOID +PlatformBootManagerDiagnostics ( + IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel, + IN BOOLEAN QuietBoot ) { - EFI_STATUS Status; - BOOLEAN RequireSoftECCInit; - EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest; - UINT64 TestedMemorySize; - UINT64 TotalMemorySize; - UINTN TestPercent; - UINT64 PreviousValue; - BOOLEAN ErrorOut; - UINT32 TempData; - - TestedMemorySize = 0; - TotalMemorySize = 0; - PreviousValue = 0; - - RequireSoftECCInit = FALSE; - - Status = gBS->LocateProtocol ( - &gEfiGenericMemTestProtocolGuid, - NULL, - (VOID **) &GenMemoryTest - ); - if (EFI_ERROR (Status)) { - return EFI_SUCCESS; - } + 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) { + BootLogoEnableLogo (); - Status = GenMemoryTest->MemoryTestInit ( - GenMemoryTest, - Level, - &RequireSoftECCInit - ); - if (Status == 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. + // Perform system diagnostic // - return EFI_SUCCESS; - } - - do { - Status = GenMemoryTest->PerformMemoryTest ( - GenMemoryTest, - &TestedMemorySize, - &TotalMemorySize, - &ErrorOut, - FALSE - ); - if (ErrorOut && (Status == EFI_DEVICE_ERROR)) { - Print (L"System encounters memory errors!"); - CpuDeadLoop (); - } - - TempData = (UINT32) DivU64x32 (TotalMemorySize, 16); - TestPercent = (UINTN) DivU64x32 ( - DivU64x32 (MultU64x32 (TestedMemorySize, 100), 16), - TempData - ); - if (TestPercent != PreviousValue) { - Print (L"Perform memory test: %d/100", TestPercent); - PreviousValue = TestPercent; + Status = PlatformBootManagerMemoryTest (MemoryTestLevel); + if (EFI_ERROR (Status)) { + BootLogoDisableLogo (); } - } while (Status != EFI_NOT_FOUND); - Status = GenMemoryTest->Finished (GenMemoryTest); - - Print (L"\r%dM bytes of system memory tested OK\n", (UINT32) DivU64x32 (TotalMemorySize, 1024 * 1024)); - return EFI_SUCCESS; -} - - -/** - Return the index of the load option in the load option array. - - The function consider two load options are equal when the - OptionType, Attributes, Description, FilePath and OptionalData are equal. - - @param Key Pointer to the load option to be found. - @param Array Pointer to the array of load options to be found. - @param Count Number of entries in the Array. - - @retval -1 Key wasn't found in the Array. - @retval 0 ~ Count-1 The index of the Key in the Array. -**/ -INTN -PlatformFindLoadOption ( - IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key, - IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array, - IN UINTN Count - ) -{ - UINTN Index; - - for (Index = 0; Index < Count; Index++) { - if ((Key->OptionType == Array[Index].OptionType) && - (Key->Attributes == Array[Index].Attributes) && - (StrCmp (Key->Description, Array[Index].Description) == 0) && - (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize (Key->FilePath)) == 0) && - (Key->OptionalDataSize == Array[Index].OptionalDataSize) && - (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->OptionalDataSize) == 0)) { - return (INTN) Index; - } + return; } - return -1; -} - -VOID -PlatformRegisterFvBootOption ( - EFI_GUID *FileGuid, - CHAR16 *Description, - UINT32 Attributes - ) -{ - EFI_STATUS Status; - UINTN OptionIndex; - EFI_BOOT_MANAGER_LOAD_OPTION NewOption; - EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; - UINTN BootOptionCount; - MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode; - EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - - Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage); - ASSERT_EFI_ERROR (Status); - - EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid); - DevicePath = AppendDevicePathNode ( - DevicePathFromHandle (LoadedImage->DeviceHandle), - (EFI_DEVICE_PATH_PROTOCOL *) &FileNode - ); - - Status = EfiBootManagerInitializeLoadOption ( - &NewOption, - LoadOptionNumberUnassigned, - LoadOptionTypeBoot, - Attributes, - Description, - DevicePath, - NULL, - 0 - ); - if (!EFI_ERROR (Status)) { - BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); - - OptionIndex = PlatformFindLoadOption (&NewOption, BootOptions, BootOptionCount); - - if (OptionIndex == -1) { - Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1); - ASSERT_EFI_ERROR (Status); - } - EfiBootManagerFreeLoadOption (&NewOption); - EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); - } + // + // Perform system diagnostic + // + Status = PlatformBootManagerMemoryTest (MemoryTestLevel); } /** @@ -207,9 +79,6 @@ PlatformBootManagerBeforeConsole ( UINTN Index; EFI_STATUS Status; WIN_NT_SYSTEM_CONFIGURATION *Configuration; - EFI_INPUT_KEY Enter; - EFI_INPUT_KEY F2; - EFI_BOOT_MANAGER_LOAD_OPTION BootOption; GetVariable2 (L"Setup", &gEfiWinNtSystemConfigGuid, (VOID **) &Configuration, NULL); if (Configuration != NULL) { @@ -250,22 +119,195 @@ PlatformBootManagerBeforeConsole ( } // - // Register ENTER as CONTINUE key + // From PI spec vol2: + // Prior to invoking any UEFI drivers, applications, or connecting consoles, + // the platform should signal the event EFI_END_OF_DXE_EVENT_GUID // - Enter.ScanCode = SCAN_NULL; - Enter.UnicodeChar = CHAR_CARRIAGE_RETURN; - EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL); + EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid); + // - // Map F2 to Boot Manager Menu + // Dispatch deferred images after EndOfDxe event. // - F2.ScanCode = SCAN_F2; - F2.UnicodeChar = CHAR_NULL; - EfiBootManagerGetBootManagerMenu (&BootOption); - EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL); + EfiBootManagerDispatchDeferredImages (); +} + +/** + Returns the priority number. + + @param BootOption +**/ +UINTN +BootOptionPriority ( + CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption + ) +{ // - // Register UEFI Shell + // Make sure Shell is first // - PlatformRegisterFvBootOption (&mUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE); + if (StrCmp (BootOption->Description, L"UEFI Shell") == 0) { + return 0; + } + return 100; +} + +INTN +EFIAPI +CompareBootOption ( + CONST EFI_BOOT_MANAGER_LOAD_OPTION *Left, + CONST EFI_BOOT_MANAGER_LOAD_OPTION *Right + ) +{ + return BootOptionPriority (Left) - BootOptionPriority (Right); +} + +/** + Generate device path include the input file guid info. + + @param FileGuid Input file guid for the BootManagerMenuApp. + + @retval DevicePath for BootManagerMenuApp. +**/ +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; } /** @@ -284,15 +326,52 @@ PlatformBootManagerAfterConsole ( VOID ) { - PlatformBootManagerMemoryTest (QUICK); + 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; + EfiBootManagerConnectAll (); EfiBootManagerRefreshAllBootOption (); - Print ( - L"\n" - L"F2 to enter Boot Manager Menu.\n" - L"Enter to boot directly.\n" - L"\n" - ); + + // + // 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); + + // + // Make Shell as the first boot option + // + EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, (SORT_COMPARE) CompareBootOption); + + PlatformBootManagerDiagnostics (QUICK, TRUE); + + 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."); } /** @@ -306,5 +385,38 @@ PlatformBootManagerWaitCallback ( UINT16 TimeoutRemain ) { - Print (L"\r%-2d seconds remained...", 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; +} +