Message ID | 1516287703-35516-3-git-send-email-huangming23@huawei.com |
---|---|
State | New |
Headers | show |
Series | Improve D0x platforms and bug fix | expand |
On 18 January 2018 at 15:01, Ming Huang <heyi.guo@linaro.org> wrote: > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ming Huang <huangming23@huawei.com> > Signed-off-by: Heyi Guo <heyi.guo@linaro.org> > Signed-off-by: Jason Zhang <zhangjinsong2@huawei.com> > --- > Platform/Hisilicon/D03/D03.dsc | 24 + > Platform/Hisilicon/D03/D03.fdf | 7 + > Platform/Hisilicon/D05/D05.dsc | 27 +- > Platform/Hisilicon/D05/D05.fdf | 7 + > Silicon/Hisilicon/Hisilicon.dsc.inc | 1 + > Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c | 588 +++++++++++++++++ > Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h | 59 ++ > Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 89 +++ > Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c | 681 ++++++++++++++++++++ > 9 files changed, 1481 insertions(+), 2 deletions(-) > Very nice! I am glad you are switching to generic BDS > diff --git a/Platform/Hisilicon/D03/D03.dsc b/Platform/Hisilicon/D03/D03.dsc > index b434f68..f7efff5 100644 > --- a/Platform/Hisilicon/D03/D03.dsc > +++ b/Platform/Hisilicon/D03/D03.dsc > @@ -28,6 +28,7 @@ > BUILD_TARGETS = DEBUG|RELEASE > SKUID_IDENTIFIER = DEFAULT > FLASH_DEFINITION = Platform/Hisilicon/$(PLATFORM_NAME)/$(PLATFORM_NAME).fdf > + DEFINE GENERIC_BDS = TRUE > What is the reason you are keeping the old BDS? > !include Silicon/Hisilicon/Hisilicon.dsc.inc > > @@ -68,6 +69,14 @@ > CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf > GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf > PlatformBdsLib|Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf > +!if $(GENERIC_BDS) == TRUE > + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf > + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf > + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf > + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf > + PlatformBootManagerLib|Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf > +!endif > CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf > > # USB Requirements > @@ -188,6 +197,9 @@ > > gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE > gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } > +!if $(GENERIC_BDS) == TRUE > + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }|VOID*|0x0001006b > +!endif > > gHisiTokenSpaceGuid.PcdSysControlBaseAddress|0x40010000 > gHisiTokenSpaceGuid.PcdMailBoxAddress|0x0000FFF8 > @@ -405,6 +417,14 @@ > MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf > MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf > > +!if $(GENERIC_BDS) == TRUE > + MdeModulePkg/Application/UiApp/UiApp.inf { > + <LibraryClasses> > + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf > + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf > + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf > + } > +!endif > MdeModulePkg/Application/HelloWorld/HelloWorld.inf > # > # Bds > @@ -457,7 +477,11 @@ > > MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf > MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf > +!if $(GENERIC_BDS) == TRUE > + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf > +!else > IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf > +!endif > > # > # UEFI application (Shell Embedded Boot Loader) > diff --git a/Platform/Hisilicon/D03/D03.fdf b/Platform/Hisilicon/D03/D03.fdf > index 0b38eb4..0d704b5 100644 > --- a/Platform/Hisilicon/D03/D03.fdf > +++ b/Platform/Hisilicon/D03/D03.fdf > @@ -283,6 +283,9 @@ READ_LOCK_STATUS = TRUE > INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf > !endif #$(INCLUDE_TFTP_COMMAND) > > +!if $(GENERIC_BDS) == TRUE > + INF MdeModulePkg/Application/UiApp/UiApp.inf > +!endif > # > # Bds > # > @@ -291,7 +294,11 @@ READ_LOCK_STATUS = TRUE > INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf > INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf > INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf > +!if $(GENERIC_BDS) == TRUE > + INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf > +!else > INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf > +!endif > > [FV.FVMAIN_COMPACT] > FvAlignment = 16 > diff --git a/Platform/Hisilicon/D05/D05.dsc b/Platform/Hisilicon/D05/D05.dsc > index 710339c..57370dc 100644 > --- a/Platform/Hisilicon/D05/D05.dsc > +++ b/Platform/Hisilicon/D05/D05.dsc > @@ -31,7 +31,7 @@ > DEFINE EDK2_SKIP_PEICORE=0 > DEFINE NETWORK_IP6_ENABLE = FALSE > DEFINE HTTP_BOOT_ENABLE = FALSE > - > + DEFINE GENERIC_BDS = TRUE > !include Silicon/Hisilicon/Hisilicon.dsc.inc > > [LibraryClasses.common] > @@ -84,6 +84,14 @@ > CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf > GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf > PlatformBdsLib|Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf > +!if $(GENERIC_BDS) == TRUE > + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf > + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf > + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf > + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf > + PlatformBootManagerLib|Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf > +!endif > CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf > > # USB Requirements > @@ -119,6 +127,7 @@ > # It could be set FALSE to save size. > gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE > gHisiTokenSpaceGuid.PcdIsItsSupported|TRUE > + gEfiMdeModulePkgTokenSpaceGuid.PcdHiiOsRuntimeSupport|FALSE > > [PcdsFixedAtBuild.common] > gArmPlatformTokenSpaceGuid.PcdCoreCount|8 > @@ -203,7 +212,9 @@ > > gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE > gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } > - > +!if $(GENERIC_BDS) == TRUE > + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }|VOID*|0x0001006b > +!endif > gHisiTokenSpaceGuid.PcdSysControlBaseAddress|0x40010000 > gHisiTokenSpaceGuid.PcdMailBoxAddress|0x0000FFF8 > > @@ -560,6 +571,14 @@ > MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf > MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf > > +!if $(GENERIC_BDS) == TRUE > + MdeModulePkg/Application/UiApp/UiApp.inf { > + <LibraryClasses> > + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf > + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf > + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf > + } > +!endif > # > # Bds > # > @@ -610,7 +629,11 @@ > MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf > MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf > MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf > +!if $(GENERIC_BDS) == TRUE > + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf > +!else > IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf > +!endif > # > # UEFI application (Shell Embedded Boot Loader) > # > diff --git a/Platform/Hisilicon/D05/D05.fdf b/Platform/Hisilicon/D05/D05.fdf > index 97de4d2..d209210 100644 > --- a/Platform/Hisilicon/D05/D05.fdf > +++ b/Platform/Hisilicon/D05/D05.fdf > @@ -305,6 +305,9 @@ READ_LOCK_STATUS = TRUE > INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf > !endif #$(INCLUDE_TFTP_COMMAND) > > +!if $(GENERIC_BDS) == TRUE > + INF MdeModulePkg/Application/UiApp/UiApp.inf > +!endif > # > # Bds > # > @@ -313,7 +316,11 @@ READ_LOCK_STATUS = TRUE > INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf > INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf > INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf > +!if $(GENERIC_BDS) == TRUE > + INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf > +!else > INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf > +!endif > > [FV.FVMAIN_COMPACT] > FvAlignment = 16 > diff --git a/Silicon/Hisilicon/Hisilicon.dsc.inc b/Silicon/Hisilicon/Hisilicon.dsc.inc > index cc23673..308064b 100644 > --- a/Silicon/Hisilicon/Hisilicon.dsc.inc > +++ b/Silicon/Hisilicon/Hisilicon.dsc.inc > @@ -263,6 +263,7 @@ > gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1 > gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0 > gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320 > + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4 > > # DEBUG_ASSERT_ENABLED 0x01 > # DEBUG_PRINT_ENABLED 0x02 > diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c > new file mode 100644 > index 0000000..5d8d58e > --- /dev/null > +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c > @@ -0,0 +1,588 @@ > +/** @file > + Implementation for PlatformBootManagerLib library class interfaces. > + > + Copyright (c) 2018, ARM Ltd. All rights reserved.<BR> > + Copyright (c) 2018, Hisilicon Limited. All rights reserved. > + Copyright (c) 2018, Linaro Ltd. 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 <IndustryStandard/Pci22.h> > +#include <Library/DevicePathLib.h> > +#include <Library/PcdLib.h> > +#include <Library/UefiBootManagerLib.h> > +#include <Library/UefiLib.h> > +#include <Protocol/DevicePath.h> > +#include <Protocol/EsrtManagement.h> > +#include <Protocol/GenericMemoryTest.h> > +#include <Protocol/GraphicsOutput.h> > +#include <Protocol/LoadedImage.h> > +#include <Protocol/PciIo.h> > +#include <Protocol/PciRootBridgeIo.h> > +#include <Guid/EventGroup.h> > +#include <Guid/TtyTerm.h> > + > +#include "PlatformBm.h" > + > +#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) } > + > + > +#pragma pack (1) > +typedef struct { > + VENDOR_DEVICE_PATH SerialDxe; > + UART_DEVICE_PATH Uart; > + VENDOR_DEFINED_DEVICE_PATH TermType; > + EFI_DEVICE_PATH_PROTOCOL End; > +} PLATFORM_SERIAL_CONSOLE; > +#pragma pack () > + > +#define SERIAL_DXE_FILE_GUID { \ > + 0xD3987D4B, 0x971A, 0x435F, \ > + { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \ > + } > + > +EFI_GUID EblAppGuid2 = {0x3CEF354A,0x3B7A,0x4519,{0xAD,0x70,0x72,0xA1,0x34,0x69,0x83,0x11}}; > + > +STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = { > + // > + // VENDOR_DEVICE_PATH SerialDxe > + // > + { > + { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) }, > + SERIAL_DXE_FILE_GUID > + }, > + > + // > + // UART_DEVICE_PATH Uart > + // > + { > + { MESSAGING_DEVICE_PATH, MSG_UART_DP, DP_NODE_LEN (UART_DEVICE_PATH) }, > + 0, // Reserved > + FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate > + FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits > + FixedPcdGet8 (PcdUartDefaultParity), // Parity > + FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits > + }, > + > + // > + // VENDOR_DEFINED_DEVICE_PATH TermType > + // > + { > + { > + MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, > + DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH) > + } > + // > + // Guid to be filled in dynamically > + // > + }, > + > + // > + // EFI_DEVICE_PATH_PROTOCOL End > + // > + { > + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, > + DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL) > + } > +}; > + > + > +#pragma pack (1) > +typedef struct { > + USB_CLASS_DEVICE_PATH Keyboard; > + EFI_DEVICE_PATH_PROTOCOL End; > +} PLATFORM_USB_KEYBOARD; > +#pragma pack () > + > +STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = { > + // > + // USB_CLASS_DEVICE_PATH Keyboard > + // > + { > + { > + MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP, > + DP_NODE_LEN (USB_CLASS_DEVICE_PATH) > + }, > + 0xFFFF, // VendorId: any > + 0xFFFF, // ProductId: any > + 3, // DeviceClass: HID > + 1, // DeviceSubClass: boot > + 1 // DeviceProtocol: keyboard > + }, > + > + // > + // EFI_DEVICE_PATH_PROTOCOL End > + // > + { > + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, > + DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL) > + } > +}; > + > + > +/** > + Check if the handle satisfies a particular condition. > + > + @param[in] Handle The handle to check. > + @param[in] ReportText A caller-allocated string passed in for reporting > + purposes. It must never be NULL. > + > + @retval TRUE The condition is satisfied. > + @retval FALSE Otherwise. This includes the case when the condition could not > + be fully evaluated due to an error. > +**/ > +typedef > +BOOLEAN > +(EFIAPI *FILTER_FUNCTION) ( > + IN EFI_HANDLE Handle, > + IN CONST CHAR16 *ReportText > + ); > + > + > +/** > + Process a handle. > + > + @param[in] Handle The handle to process. > + @param[in] ReportText A caller-allocated string passed in for reporting > + purposes. It must never be NULL. > +**/ > +typedef > +VOID > +(EFIAPI *CALLBACK_FUNCTION) ( > + IN EFI_HANDLE Handle, > + IN CONST CHAR16 *ReportText > + ); > + > +/** > + Locate all handles that carry the specified protocol, filter them with a > + callback function, and pass each handle that passes the filter to another > + callback. > + > + @param[in] ProtocolGuid The protocol to look for. > + > + @param[in] Filter The filter function to pass each handle to. If this > + parameter is NULL, then all handles are processed. > + > + @param[in] Process The callback function to pass each handle to that > + clears the filter. > +**/ > +STATIC > +VOID > +FilterAndProcess ( > + IN EFI_GUID *ProtocolGuid, > + IN FILTER_FUNCTION Filter OPTIONAL, > + IN CALLBACK_FUNCTION Process > + ) > +{ > + EFI_STATUS Status; > + EFI_HANDLE *Handles; > + UINTN NoHandles; > + UINTN Idx; > + > + Status = gBS->LocateHandleBuffer (ByProtocol, ProtocolGuid, > + NULL /* SearchKey */, &NoHandles, &Handles); > + if (EFI_ERROR (Status)) { > + // > + // This is not an error, just an informative condition. > + // > + DEBUG ((DEBUG_VERBOSE, "%a: %g: %r\n", __FUNCTION__, ProtocolGuid, > + Status)); > + return; > + } > + > + ASSERT (NoHandles > 0); > + for (Idx = 0; Idx < NoHandles; ++Idx) { > + CHAR16 *DevicePathText; > + STATIC CHAR16 Fallback[] = L"<device path unavailable>"; > + > + // > + // The ConvertDevicePathToText() function handles NULL input transparently. > + // > + DevicePathText = ConvertDevicePathToText ( > + DevicePathFromHandle (Handles[Idx]), > + FALSE, // DisplayOnly > + FALSE // AllowShortcuts > + ); > + if (DevicePathText == NULL) { > + DevicePathText = Fallback; > + } > + > + if (Filter == NULL || Filter (Handles[Idx], DevicePathText)) { > + Process (Handles[Idx], DevicePathText); > + } > + > + if (DevicePathText != Fallback) { > + FreePool (DevicePathText); > + } > + } > + gBS->FreePool (Handles); > +} > + > + > +/** > + This FILTER_FUNCTION checks if a handle corresponds to a PCI display device. > +**/ > +STATIC > +BOOLEAN > +EFIAPI > +IsPciDisplay ( > + IN EFI_HANDLE Handle, > + IN CONST CHAR16 *ReportText > + ) > +{ > + EFI_STATUS Status; > + EFI_PCI_IO_PROTOCOL *PciIo; > + PCI_TYPE00 Pci; > + > + Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid, > + (VOID**)&PciIo); > + if (EFI_ERROR (Status)) { > + // > + // This is not an error worth reporting. > + // > + return FALSE; > + } > + > + Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0 /* Offset */, > + sizeof Pci / sizeof (UINT32), &Pci); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %s: %r\n", __FUNCTION__, ReportText, Status)); > + return FALSE; > + } > + > + return IS_PCI_DISPLAY (&Pci); > +} > + > + > +/** > + This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking > + the matching driver to produce all first-level child handles. > +**/ > +STATIC > +VOID > +EFIAPI > +Connect ( > + IN EFI_HANDLE Handle, > + IN CONST CHAR16 *ReportText > + ) > +{ > + EFI_STATUS Status; > + > + Status = gBS->ConnectController ( > + Handle, // ControllerHandle > + NULL, // DriverImageHandle > + NULL, // RemainingDevicePath -- produce all children > + FALSE // Recursive > + ); > + DEBUG ((EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE, "%a: %s: %r\n", > + __FUNCTION__, ReportText, Status)); > +} > + > + > +/** > + This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the > + handle, and adds it to ConOut and ErrOut. > +**/ > +STATIC > +VOID > +EFIAPI > +AddOutput ( > + IN EFI_HANDLE Handle, > + IN CONST CHAR16 *ReportText > + ) > +{ > + EFI_STATUS Status; > + EFI_DEVICE_PATH_PROTOCOL *DevicePath; > + > + DevicePath = DevicePathFromHandle (Handle); > + if (DevicePath == NULL) { > + DEBUG ((DEBUG_ERROR, "%a: %s: handle %p: device path not found\n", > + __FUNCTION__, ReportText, Handle)); > + return; > + } > + > + Status = EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %s: adding to ConOut: %r\n", __FUNCTION__, > + ReportText, Status)); > + return; > + } > + > + Status = EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__, > + ReportText, Status)); > + return; > + } > + > + DEBUG ((DEBUG_VERBOSE, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__, > + ReportText)); > +} > + > +STATIC > +VOID > +PlatformRegisterFvBootOption ( > + EFI_GUID *FileGuid, > + CHAR16 *Description, > + UINT32 Attributes > + ) > +{ > + EFI_STATUS Status; > + INTN 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 = DevicePathFromHandle (LoadedImage->DeviceHandle); > + ASSERT (DevicePath != NULL); > + DevicePath = AppendDevicePathNode ( > + DevicePath, > + (EFI_DEVICE_PATH_PROTOCOL *) &FileNode > + ); > + ASSERT (DevicePath != NULL); > + > + Status = EfiBootManagerInitializeLoadOption ( > + &NewOption, > + LoadOptionNumberUnassigned, > + LoadOptionTypeBoot, > + Attributes, > + Description, > + DevicePath, > + NULL, > + 0 > + ); > + ASSERT_EFI_ERROR (Status); > + FreePool (DevicePath); > + > + BootOptions = EfiBootManagerGetLoadOptions ( > + &BootOptionCount, LoadOptionTypeBoot > + ); > + > + OptionIndex = EfiBootManagerFindLoadOption ( > + &NewOption, BootOptions, BootOptionCount > + ); > + > + if (OptionIndex == -1) { > + Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN); > + ASSERT_EFI_ERROR (Status); > + } > + EfiBootManagerFreeLoadOption (&NewOption); > + EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); > +} > + > + > +STATIC > +VOID > +PlatformRegisterOptionsAndKeys ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + EFI_INPUT_KEY Enter; > + EFI_INPUT_KEY F2; > + EFI_INPUT_KEY Esc; > + EFI_BOOT_MANAGER_LOAD_OPTION BootOption; > + > + // > + // Register ENTER as CONTINUE key > + // > + Enter.ScanCode = SCAN_NULL; > + Enter.UnicodeChar = CHAR_CARRIAGE_RETURN; > + Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL); > + ASSERT_EFI_ERROR (Status); > + > + // > + // Map F2 and ESC to Boot Manager Menu > + // > + F2.ScanCode = SCAN_F2; > + F2.UnicodeChar = CHAR_NULL; > + Esc.ScanCode = SCAN_ESC; > + Esc.UnicodeChar = CHAR_NULL; > + > + Status = EfiBootManagerGetBootManagerMenu (&BootOption); > + ASSERT_EFI_ERROR (Status); > + Status = EfiBootManagerAddKeyOptionVariable ( > + NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL > + ); > + ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED); > + Status = EfiBootManagerAddKeyOptionVariable ( > + NULL, (UINT16) BootOption.OptionNumber, 0, &Esc, NULL > + ); > + ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED); > +} > + STATIC > +VOID > +UpdateMemory ( > + ) > +{ > + EFI_STATUS Status; > + EFI_GENERIC_MEMORY_TEST_PROTOCOL* MemoryTest; > + BOOLEAN RequireSoftECCInit = FALSE; > + No initializers please, use assignments > + //Add MemoryTest for memmap add above 4G memory. Space after // > + Status = gBS->LocateProtocol (&gEfiGenericMemTestProtocolGuid, NULL, (VOID**)&MemoryTest); > + if (!EFI_ERROR (Status)) { > + (VOID)MemoryTest->MemoryTestInit (MemoryTest, IGNORE, &RequireSoftECCInit); Why the VOID cast? > + } else { > + DEBUG ((DEBUG_ERROR, "LocateProtocol for GenericMemTestProtocol fail(%r)\n", Status)); > + } > + Check line length > + return; > +} > + > +// > +// BDS Platform Functions > +// > +/** > + Do the platform init, can be customized by OEM/IBV > + Possible things that can be done in PlatformBootManagerBeforeConsole: > + > Update console variable: 1. include hot-plug devices; > + > 2. Clear ConIn and add SOL for AMT > + > Register new Driver#### or Boot#### > + > Register new Key####: e.g.: F12 > + > Signal ReadyToLock event > + > Authentication action: 1. connect Auth devices; > + > 2. Identify auto logon user. > +**/ > +VOID > +EFIAPI > +PlatformBootManagerBeforeConsole ( > + VOID > + ) > +{ > + // > + // Signal EndOfDxe PI Event > + // > + EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid); > + You need to call EsrtManagement->SyncEsrtFmp () here as well, not only in PlatformBootManagerAfterConsole > + UpdateMemory (); > + > + // > + // Locate the PCI root bridges and make the PCI bus driver connect each, > + // non-recursively. This will produce a number of child handles with PciIo on > + // them. > + // > + FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid, NULL, Connect); > + > + // > + // Find all display class PCI devices (using the handles from the previous > + // step), and connect them non-recursively. This should produce a number of > + // child handles with GOPs on them. > + // > + FilterAndProcess (&gEfiPciIoProtocolGuid, IsPciDisplay, Connect); > + > + // > + // Now add the device path of all handles with GOP on them to ConOut and > + // ErrOut. > + // > + FilterAndProcess (&gEfiGraphicsOutputProtocolGuid, NULL, AddOutput); > + > + // > + // Add the hardcoded short-form USB keyboard device path to ConIn. > + // > + EfiBootManagerUpdateConsoleVariable (ConIn, > + (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL); > + > + // > + // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut. > + // > + ASSERT (FixedPcdGet8 (PcdDefaultTerminalType) == 4); > + CopyGuid (&mSerialConsole.TermType.Guid, &gEfiTtyTermGuid); > + > + EfiBootManagerUpdateConsoleVariable (ConIn, > + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); > + EfiBootManagerUpdateConsoleVariable (ConOut, > + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); > + EfiBootManagerUpdateConsoleVariable (ErrOut, > + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); > + > + // > + // Register platform-specific boot options and keyboard shortcuts. > + // > + PlatformRegisterOptionsAndKeys (); > +} > + > +/** > + Do the platform specific action after the console is ready > + Possible things that can be done in PlatformBootManagerAfterConsole: > + > Console post action: > + > Dynamically switch output mode from 100x31 to 80x25 for certain senarino > + > Signal console ready platform customized event > + > Run diagnostics like memory testing > + > Connect certain devices > + > Dispatch aditional option roms > + > Special boot: e.g.: USB boot, enter UI > +**/ > +VOID > +EFIAPI > +PlatformBootManagerAfterConsole ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + ESRT_MANAGEMENT_PROTOCOL *EsrtManagement = NULL; > + > + // > + // Show the splash screen. > + // > + EnableQuietBoot (PcdGetPtr (PcdLogoFile)); > + Please use BootLogoLib from MdeModulePkg, and drop the IntelFrameworkModulePkg dependency > + // > + // Connect the rest of the devices. > + // > + EfiBootManagerConnectAll (); > + > + // > + // Enumerate all possible boot options. > + // > + EfiBootManagerRefreshAllBootOption (); > + > + // > + //Sync Esrt Table > + // Space after // > + Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtManagement); Line length > + if (!EFI_ERROR (Status)) { > + Status = EsrtManagement->SyncEsrtFmp (); > + } > + > + // > + // Register UEFI Shell > + // > + PlatformRegisterFvBootOption ( > + PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE > + ); > +} > + > +/** > + This function is called each second during the boot manager waits the > + timeout. > + > + @param TimeoutRemain The remaining timeout. > +**/ > +VOID > +EFIAPI > +PlatformBootManagerWaitCallback ( > + UINT16 TimeoutRemain > + ) > +{ > + Print(L"\r%-2d seconds left, Press Esc or F2 to enter Setup.", TimeoutRemain); > +} > diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h > new file mode 100644 > index 0000000..0a3c626 > --- /dev/null > +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h > @@ -0,0 +1,59 @@ > +/** @file > + Head file for BDS Platform specific code > + > + Copyright (C) 2015-2016, Red Hat, Inc. > + Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR> > + Copyright (c) 2016, Linaro Ltd. 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. > + > +**/ > + > +#ifndef _PLATFORM_BM_H_ > +#define _PLATFORM_BM_H_ > + > +#include <Library/BaseLib.h> > +#include <Library/BaseMemoryLib.h> > +#include <Library/DebugLib.h> > +#include <Library/DevicePathLib.h> > +#include <Library/MemoryAllocationLib.h> > +#include <Library/UefiBootServicesTableLib.h> > +#include <Library/UefiLib.h> > +#include <Library/UefiRuntimeServicesTableLib.h> > + > +/** > + Use SystemTable Conout to stop video based Simple Text Out consoles from > + going to the video device. Put up LogoFile on every video device that is a > + console. > + > + @param[in] LogoFile File name of logo to display on the center of the > + screen. > + > + @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo > + displayed. > + @retval EFI_UNSUPPORTED Logo not found > +**/ > +EFI_STATUS > +EnableQuietBoot ( > + IN EFI_GUID *LogoFile > + ); > + > +/** > + Use SystemTable Conout to turn on video based Simple Text Out consoles. The > + Simple Text Out screens will now be synced up with all non video output > + devices > + > + @retval EFI_SUCCESS UGA devices are back in text mode and synced up. > +**/ > +EFI_STATUS > +DisableQuietBoot ( > + VOID > + ); > + > +#endif // _PLATFORM_BM_H_ Please don't reuse this, use BootLogoLib instead. > diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > new file mode 100644 > index 0000000..ae274f3 > --- /dev/null > +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > @@ -0,0 +1,89 @@ > +## @file > +# Implementation for PlatformBootManagerLib library class interfaces. > +# > +# Copyright (C) 2015-2016, Red Hat, Inc. > +# Copyright (c) 2014, ARM Ltd. All rights reserved.<BR> > +# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR> > +# Copyright (c) 2016, Linaro Ltd. 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. > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 0x0000001A > + BASE_NAME = PlatformBootManagerLib > + FILE_GUID = 92FD2DE3-B9CB-4B35-8141-42AD34D73C9F Don't reuse GUIDs, create your own > + MODULE_TYPE = DXE_DRIVER > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = PlatformBootManagerLib|DXE_DRIVER > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = ARM AARCH64 > +# > + > +[Sources] > + PlatformBm.c > + QuietBoot.c > + > +[Packages] > + IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec Please drop this reference > + MdeModulePkg/MdeModulePkg.dec > + MdePkg/MdePkg.dec > + Silicon/Hisilicon/HisiPkg.dec > + > +[LibraryClasses] > + BaseLib > + BaseMemoryLib > + DebugLib > + DevicePathLib > + DxeServicesLib > + MemoryAllocationLib > + PcdLib > + PrintLib > + UefiBootManagerLib > + UefiBootServicesTableLib > + UefiLib > + > +[FeaturePcd] > + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable Please drop this reference > + gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport > + > +[FixedPcd] > + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile > + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile and these 2 > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits > + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType > + > +[Pcd] > + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut > + > +[Guids] > + gEfiFileInfoGuid > + gEfiFileSystemInfoGuid > + gEfiFileSystemVolumeLabelInfoIdGuid > + gEfiEndOfDxeEventGroupGuid > + gEfiTtyTermGuid > + > +[Protocols] > + gEfiDevicePathProtocolGuid > + gEfiFirmwareVolume2ProtocolGuid > + gEfiGenericMemTestProtocolGuid > + gEfiGraphicsOutputProtocolGuid > + gEfiLoadedImageProtocolGuid > + gEfiOEMBadgingProtocolGuid > + gEfiPciRootBridgeIoProtocolGuid > + gEfiSimpleFileSystemProtocolGuid > + gEsrtManagementProtocolGuid Does your code really use all of these? > diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c b/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c Please don't copy this file, use BootLogoLib instead > new file mode 100644 > index 0000000..0bd15da > --- /dev/null > +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c > @@ -0,0 +1,681 @@ > +/** @file > +Platform BDS function for quiet boot support. > + > +Copyright (c) 2018, ARM Ltd. All rights reserved.<BR> > +Copyright (c) 2018, Hisilicon Limited. All rights reserved. > +Copyright (c) 2018, Linaro Ltd. 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 <IndustryStandard/Bmp.h> > +#include <Library/DxeServicesLib.h> > +#include <Protocol/BootLogo.h> > +#include <Protocol/OEMBadging.h> > +#include <Protocol/UgaDraw.h> > + > +#include "PlatformBm.h" > + > +/** > + Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer > + is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt > + buffer is passed in it will be used if it is big enough. > + > + @param BmpImage Pointer to BMP file > + @param BmpImageSize Number of bytes in BmpImage > + @param GopBlt Buffer containing GOP version of BmpImage. > + @param GopBltSize Size of GopBlt in bytes. > + @param PixelHeight Height of GopBlt/BmpImage in pixels > + @param PixelWidth Width of GopBlt/BmpImage in pixels > + > + @retval EFI_SUCCESS GopBlt and GopBltSize are returned. > + @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image > + @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough. > + GopBltSize will contain the required size. > + @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate. > + > +**/ > +STATIC > +EFI_STATUS > +ConvertBmpToGopBlt ( > + IN VOID *BmpImage, > + IN UINTN BmpImageSize, > + IN OUT VOID **GopBlt, > + IN OUT UINTN *GopBltSize, > + OUT UINTN *PixelHeight, > + OUT UINTN *PixelWidth > + ) > +{ > + UINT8 *Image; > + UINT8 *ImageHeader; > + BMP_IMAGE_HEADER *BmpHeader; > + BMP_COLOR_MAP *BmpColorMap; > + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer; > + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; > + UINT64 BltBufferSize; > + UINTN Index; > + UINTN Height; > + UINTN Width; > + UINTN ImageIndex; > + UINT32 DataSizePerLine; > + BOOLEAN IsAllocated; > + UINT32 ColorMapNum; > + > + if (sizeof (BMP_IMAGE_HEADER) > BmpImageSize) { > + return EFI_INVALID_PARAMETER; > + } > + > + BmpHeader = (BMP_IMAGE_HEADER *) BmpImage; > + > + if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') { > + return EFI_UNSUPPORTED; > + } > + > + // > + // Doesn't support compress. > + // > + if (BmpHeader->CompressionType != 0) { > + return EFI_UNSUPPORTED; > + } > + > + // > + // Only support BITMAPINFOHEADER format. > + // BITMAPFILEHEADER + BITMAPINFOHEADER = BMP_IMAGE_HEADER > + // > + if (BmpHeader->HeaderSize != sizeof (BMP_IMAGE_HEADER) - OFFSET_OF(BMP_IMAGE_HEADER, HeaderSize)) { > + return EFI_UNSUPPORTED; > + } > + > + // > + // The data size in each line must be 4 byte alignment. > + // > + DataSizePerLine = ((BmpHeader->PixelWidth * BmpHeader->BitPerPixel + 31) >> 3) & (~0x3); > + BltBufferSize = MultU64x32 (DataSizePerLine, BmpHeader->PixelHeight); > + if (BltBufferSize > (UINT32) ~0) { > + return EFI_INVALID_PARAMETER; > + } > + > + if ((BmpHeader->Size != BmpImageSize) || > + (BmpHeader->Size < BmpHeader->ImageOffset) || > + (BmpHeader->Size - BmpHeader->ImageOffset != BmpHeader->PixelHeight * DataSizePerLine)) { > + return EFI_INVALID_PARAMETER; > + } > + > + // > + // Calculate Color Map offset in the image. > + // > + Image = BmpImage; > + BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER)); > + if (BmpHeader->ImageOffset < sizeof (BMP_IMAGE_HEADER)) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (BmpHeader->ImageOffset > sizeof (BMP_IMAGE_HEADER)) { > + switch (BmpHeader->BitPerPixel) { > + case 1: > + ColorMapNum = 2; > + break; > + case 4: > + ColorMapNum = 16; > + break; > + case 8: > + ColorMapNum = 256; > + break; > + default: > + ColorMapNum = 0; > + break; > + } > + // > + // BMP file may has padding data between the bmp header section and the bmp data section. > + // > + if (BmpHeader->ImageOffset - sizeof (BMP_IMAGE_HEADER) < sizeof (BMP_COLOR_MAP) * ColorMapNum) { > + return EFI_INVALID_PARAMETER; > + } > + } > + > + // > + // Calculate graphics image data address in the image > + // > + Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset; > + ImageHeader = Image; > + > + // > + // Calculate the BltBuffer needed size. > + // > + BltBufferSize = MultU64x32 ((UINT64) BmpHeader->PixelWidth, BmpHeader->PixelHeight); > + // > + // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow > + // > + if (BltBufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { > + return EFI_UNSUPPORTED; > + } > + BltBufferSize = MultU64x32 (BltBufferSize, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); > + > + IsAllocated = FALSE; > + if (*GopBlt == NULL) { > + // > + // GopBlt is not allocated by caller. > + // > + *GopBltSize = (UINTN) BltBufferSize; > + *GopBlt = AllocatePool (*GopBltSize); > + IsAllocated = TRUE; > + if (*GopBlt == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + } else { > + // > + // GopBlt has been allocated by caller. > + // > + if (*GopBltSize < (UINTN) BltBufferSize) { > + *GopBltSize = (UINTN) BltBufferSize; > + return EFI_BUFFER_TOO_SMALL; > + } > + } > + > + *PixelWidth = BmpHeader->PixelWidth; > + *PixelHeight = BmpHeader->PixelHeight; > + > + // > + // Convert image from BMP to Blt buffer format > + // > + BltBuffer = *GopBlt; > + for (Height = 0; Height < BmpHeader->PixelHeight; Height++) { > + Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth]; > + for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) { > + switch (BmpHeader->BitPerPixel) { > + case 1: > + // > + // Convert 1-bit (2 colors) BMP to 24-bit color > + // > + for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) { > + Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red; > + Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green; > + Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue; > + Blt++; > + Width++; > + } > + > + Blt--; > + Width--; > + break; > + > + case 4: > + // > + // Convert 4-bit (16 colors) BMP Palette to 24-bit color > + // > + Index = (*Image) >> 4; > + Blt->Red = BmpColorMap[Index].Red; > + Blt->Green = BmpColorMap[Index].Green; > + Blt->Blue = BmpColorMap[Index].Blue; > + if (Width < (BmpHeader->PixelWidth - 1)) { > + Blt++; > + Width++; > + Index = (*Image) & 0x0f; > + Blt->Red = BmpColorMap[Index].Red; > + Blt->Green = BmpColorMap[Index].Green; > + Blt->Blue = BmpColorMap[Index].Blue; > + } > + break; > + > + case 8: > + // > + // Convert 8-bit (256 colors) BMP Palette to 24-bit color > + // > + Blt->Red = BmpColorMap[*Image].Red; > + Blt->Green = BmpColorMap[*Image].Green; > + Blt->Blue = BmpColorMap[*Image].Blue; > + break; > + > + case 24: > + // > + // It is 24-bit BMP. > + // > + Blt->Blue = *Image++; > + Blt->Green = *Image++; > + Blt->Red = *Image; > + break; > + > + default: > + // > + // Other bit format BMP is not supported. > + // > + if (IsAllocated) { > + FreePool (*GopBlt); > + *GopBlt = NULL; > + } > + return EFI_UNSUPPORTED; > + }; > + > + } > + > + ImageIndex = (UINTN) (Image - ImageHeader); > + if ((ImageIndex % 4) != 0) { > + // > + // Bmp Image starts each row on a 32-bit boundary! > + // > + Image = Image + (4 - (ImageIndex % 4)); > + } > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + Use SystemTable Conout to stop video based Simple Text Out consoles from going > + to the video device. Put up LogoFile on every video device that is a console. > + > + @param[in] LogoFile File name of logo to display on the center of the screen. > + > + @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed. > + @retval EFI_UNSUPPORTED Logo not found > + > +**/ > +EFI_STATUS > +EnableQuietBoot ( > + IN EFI_GUID *LogoFile > + ) > +{ > + EFI_STATUS Status; > + EFI_OEM_BADGING_PROTOCOL *Badging; > + UINT32 SizeOfX; > + UINT32 SizeOfY; > + INTN DestX; > + INTN DestY; > + UINT8 *ImageData; > + UINTN ImageSize; > + UINTN BltSize; > + UINT32 Instance; > + EFI_BADGING_FORMAT Format; > + EFI_BADGING_DISPLAY_ATTRIBUTE Attribute; > + UINTN CoordinateX; > + UINTN CoordinateY; > + UINTN Height; > + UINTN Width; > + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; > + EFI_UGA_DRAW_PROTOCOL *UgaDraw; > + UINT32 ColorDepth; > + UINT32 RefreshRate; > + EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; > + EFI_BOOT_LOGO_PROTOCOL *BootLogo; > + UINTN NumberOfLogos; > + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LogoBlt; > + UINTN LogoDestX; > + UINTN LogoDestY; > + UINTN LogoHeight; > + UINTN LogoWidth; > + UINTN NewDestX; > + UINTN NewDestY; > + UINTN NewHeight; > + UINTN NewWidth; > + UINT64 BufferSize; > + > + UgaDraw = NULL; > + // > + // Try to open GOP first > + // > + Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput); > + if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) { > + GraphicsOutput = NULL; > + // > + // Open GOP failed, try to open UGA > + // > + Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw); > + } > + if (EFI_ERROR (Status)) { > + return EFI_UNSUPPORTED; > + } > + > + // > + // Try to open Boot Logo Protocol. > + // > + BootLogo = NULL; > + gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo); > + > + // > + // Erase Cursor from screen > + // > + gST->ConOut->EnableCursor (gST->ConOut, FALSE); > + > + Badging = NULL; > + Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging); > + > + if (GraphicsOutput != NULL) { > + SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution; > + SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution; > + > + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { > + Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate); > + if (EFI_ERROR (Status)) { > + return EFI_UNSUPPORTED; > + } > + } else { > + return EFI_UNSUPPORTED; > + } > + > + Blt = NULL; > + NumberOfLogos = 0; > + LogoDestX = 0; > + LogoDestY = 0; > + LogoHeight = 0; > + LogoWidth = 0; > + NewDestX = 0; > + NewDestY = 0; > + NewHeight = 0; > + NewWidth = 0; > + Instance = 0; > + Height = 0; > + Width = 0; > + while (1) { > + ImageData = NULL; > + ImageSize = 0; > + > + if (Badging != NULL) { > + // > + // Get image from OEMBadging protocol. > + // > + Status = Badging->GetImage ( > + Badging, > + &Instance, > + &Format, > + &ImageData, > + &ImageSize, > + &Attribute, > + &CoordinateX, > + &CoordinateY > + ); > + if (EFI_ERROR (Status)) { > + goto Done; > + } > + > + // > + // Currently only support BMP format. > + // > + if (Format != EfiBadgingFormatBMP) { > + if (ImageData != NULL) { > + FreePool (ImageData); > + } > + continue; > + } > + } else { > + // > + // Get the specified image from FV. > + // > + Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize); > + if (EFI_ERROR (Status)) { > + return EFI_UNSUPPORTED; > + } > + > + CoordinateX = 0; > + CoordinateY = 0; > + if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) { > + Attribute = EfiBadgingDisplayAttributeCenter; > + } else { > + Attribute = EfiBadgingDisplayAttributeCustomized; > + } > + } > + > + if (Blt != NULL) { > + FreePool (Blt); > + } > + Blt = NULL; > + Status = ConvertBmpToGopBlt ( > + ImageData, > + ImageSize, > + (VOID **) &Blt, > + &BltSize, > + &Height, > + &Width > + ); > + if (EFI_ERROR (Status)) { > + FreePool (ImageData); > + > + if (Badging == NULL) { > + return Status; > + } else { > + continue; > + } > + } > + > + // > + // Calculate the display position according to Attribute. > + // > + switch (Attribute) { > + case EfiBadgingDisplayAttributeLeftTop: > + DestX = CoordinateX; > + DestY = CoordinateY; > + break; > + > + case EfiBadgingDisplayAttributeCenterTop: > + DestX = (SizeOfX - Width) / 2; > + DestY = CoordinateY; > + break; > + > + case EfiBadgingDisplayAttributeRightTop: > + DestX = (SizeOfX - Width - CoordinateX); > + DestY = CoordinateY;; > + break; > + > + case EfiBadgingDisplayAttributeCenterRight: > + DestX = (SizeOfX - Width - CoordinateX); > + DestY = (SizeOfY - Height) / 2; > + break; > + > + case EfiBadgingDisplayAttributeRightBottom: > + DestX = (SizeOfX - Width - CoordinateX); > + DestY = (SizeOfY - Height - CoordinateY); > + break; > + > + case EfiBadgingDisplayAttributeCenterBottom: > + DestX = (SizeOfX - Width) / 2; > + DestY = (SizeOfY - Height - CoordinateY); > + break; > + > + case EfiBadgingDisplayAttributeLeftBottom: > + DestX = CoordinateX; > + DestY = (SizeOfY - Height - CoordinateY); > + break; > + > + case EfiBadgingDisplayAttributeCenterLeft: > + DestX = CoordinateX; > + DestY = (SizeOfY - Height) / 2; > + break; > + > + case EfiBadgingDisplayAttributeCenter: > + DestX = (SizeOfX - Width) / 2; > + DestY = (SizeOfY - Height) / 2; > + break; > + > + case EfiBadgingDisplayAttributeCustomized: > + DestX = (SizeOfX - Width) / 2; > + DestY = ((SizeOfY * 382) / 1000) - Height / 2; > + break; > + > + default: > + DestX = CoordinateX; > + DestY = CoordinateY; > + break; > + } > + > + if ((DestX >= 0) && (DestY >= 0)) { > + if (GraphicsOutput != NULL) { > + Status = GraphicsOutput->Blt ( > + GraphicsOutput, > + Blt, > + EfiBltBufferToVideo, > + 0, > + 0, > + (UINTN) DestX, > + (UINTN) DestY, > + Width, > + Height, > + Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) > + ); > + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { > + Status = UgaDraw->Blt ( > + UgaDraw, > + (EFI_UGA_PIXEL *) Blt, > + EfiUgaBltBufferToVideo, > + 0, > + 0, > + (UINTN) DestX, > + (UINTN) DestY, > + Width, > + Height, > + Width * sizeof (EFI_UGA_PIXEL) > + ); > + } else { > + Status = EFI_UNSUPPORTED; > + } > + > + // > + // Report displayed Logo information. > + // > + if (!EFI_ERROR (Status)) { > + NumberOfLogos++; > + > + if (LogoWidth == 0) { > + // > + // The first Logo. > + // > + LogoDestX = (UINTN) DestX; > + LogoDestY = (UINTN) DestY; > + LogoWidth = Width; > + LogoHeight = Height; > + } else { > + // > + // Merge new logo with old one. > + // > + NewDestX = MIN ((UINTN) DestX, LogoDestX); > + NewDestY = MIN ((UINTN) DestY, LogoDestY); > + NewWidth = MAX ((UINTN) DestX + Width, LogoDestX + LogoWidth) - NewDestX; > + NewHeight = MAX ((UINTN) DestY + Height, LogoDestY + LogoHeight) - NewDestY; > + > + LogoDestX = NewDestX; > + LogoDestY = NewDestY; > + LogoWidth = NewWidth; > + LogoHeight = NewHeight; > + } > + } > + } > + > + FreePool (ImageData); > + > + if (Badging == NULL) { > + break; > + } > + } > + > +Done: > + if (BootLogo == NULL || NumberOfLogos == 0) { > + // > + // No logo displayed. > + // > + if (Blt != NULL) { > + FreePool (Blt); > + } > + > + return Status; > + } > + > + // > + // Advertise displayed Logo information. > + // > + if (NumberOfLogos == 1) { > + // > + // Only one logo displayed, use its Blt buffer directly for BootLogo protocol. > + // > + LogoBlt = Blt; > + Status = EFI_SUCCESS; > + } else { > + // > + // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation. > + // > + if (Blt != NULL) { > + FreePool (Blt); > + } > + > + // > + // Ensure the LogoHeight * LogoWidth doesn't overflow > + // > + if (LogoHeight > DivU64x64Remainder ((UINTN) ~0, LogoWidth, NULL)) { > + return EFI_UNSUPPORTED; > + } > + BufferSize = MultU64x64 (LogoWidth, LogoHeight); > + > + // > + // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow > + // > + if (BufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { > + return EFI_UNSUPPORTED; > + } > + > + LogoBlt = AllocateZeroPool ((UINTN)BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); > + if (LogoBlt == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + if (GraphicsOutput != NULL) { > + Status = GraphicsOutput->Blt ( > + GraphicsOutput, > + LogoBlt, > + EfiBltVideoToBltBuffer, > + LogoDestX, > + LogoDestY, > + 0, > + 0, > + LogoWidth, > + LogoHeight, > + LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) > + ); > + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { > + Status = UgaDraw->Blt ( > + UgaDraw, > + (EFI_UGA_PIXEL *) LogoBlt, > + EfiUgaVideoToBltBuffer, > + LogoDestX, > + LogoDestY, > + 0, > + 0, > + LogoWidth, > + LogoHeight, > + LogoWidth * sizeof (EFI_UGA_PIXEL) > + ); > + } else { > + Status = EFI_UNSUPPORTED; > + } > + } > + > + if (!EFI_ERROR (Status)) { > + BootLogo->SetBootLogo (BootLogo, LogoBlt, LogoDestX, LogoDestY, LogoWidth, LogoHeight); > + } > + FreePool (LogoBlt); > + > + return Status; > +} > + > +/** > + Use SystemTable Conout to turn on video based Simple Text Out consoles. The > + Simple Text Out screens will now be synced up with all non video output devices > + > + @retval EFI_SUCCESS UGA devices are back in text mode and synced up. > + > +**/ > +EFI_STATUS > +DisableQuietBoot ( > + VOID > + ) > +{ > + > + // > + // Enable Cursor on Screen > + // > + gST->ConOut->EnableCursor (gST->ConOut, TRUE); > + return EFI_SUCCESS; > +} > + > -- > 1.9.1 > _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Please provide a detailed commit message. For example, explain that: - Generic BDS use configurable build-time, enabled by default. (Why? Is this intended to be temporary?) - Hisilicon-specific PlatformBootManagerLib added. (Why? What features are added compared to default one?) Minor comments below. On Thu, Jan 18, 2018 at 11:01:31PM +0800, Ming Huang wrote: > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ming Huang <huangming23@huawei.com> > Signed-off-by: Heyi Guo <heyi.guo@linaro.org> > Signed-off-by: Jason Zhang <zhangjinsong2@huawei.com> > --- > Platform/Hisilicon/D03/D03.dsc | 24 + > Platform/Hisilicon/D03/D03.fdf | 7 + > Platform/Hisilicon/D05/D05.dsc | 27 +- > Platform/Hisilicon/D05/D05.fdf | 7 + > Silicon/Hisilicon/Hisilicon.dsc.inc | 1 + > Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c | 588 +++++++++++++++++ > Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h | 59 ++ > Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 89 +++ > Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c | 681 ++++++++++++++++++++ > 9 files changed, 1481 insertions(+), 2 deletions(-) > > diff --git a/Platform/Hisilicon/D03/D03.dsc b/Platform/Hisilicon/D03/D03.dsc > index b434f68..f7efff5 100644 > --- a/Platform/Hisilicon/D03/D03.dsc > +++ b/Platform/Hisilicon/D03/D03.dsc > @@ -28,6 +28,7 @@ > BUILD_TARGETS = DEBUG|RELEASE > SKUID_IDENTIFIER = DEFAULT > FLASH_DEFINITION = Platform/Hisilicon/$(PLATFORM_NAME)/$(PLATFORM_NAME).fdf > + DEFINE GENERIC_BDS = TRUE > > !include Silicon/Hisilicon/Hisilicon.dsc.inc > > @@ -68,6 +69,14 @@ > CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf > GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf > PlatformBdsLib|Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf > +!if $(GENERIC_BDS) == TRUE > + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf > + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf > + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf > + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf > + PlatformBootManagerLib|Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf > +!endif > CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf > > # USB Requirements > @@ -188,6 +197,9 @@ > > gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE > gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } > +!if $(GENERIC_BDS) == TRUE > + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }|VOID*|0x0001006b > +!endif > > gHisiTokenSpaceGuid.PcdSysControlBaseAddress|0x40010000 > gHisiTokenSpaceGuid.PcdMailBoxAddress|0x0000FFF8 > @@ -405,6 +417,14 @@ > MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf > MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf > > +!if $(GENERIC_BDS) == TRUE > + MdeModulePkg/Application/UiApp/UiApp.inf { > + <LibraryClasses> > + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf > + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf > + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf > + } > +!endif > MdeModulePkg/Application/HelloWorld/HelloWorld.inf > # > # Bds > @@ -457,7 +477,11 @@ > > MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf > MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf > +!if $(GENERIC_BDS) == TRUE > + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf > +!else > IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf > +!endif > > # > # UEFI application (Shell Embedded Boot Loader) > diff --git a/Platform/Hisilicon/D03/D03.fdf b/Platform/Hisilicon/D03/D03.fdf > index 0b38eb4..0d704b5 100644 > --- a/Platform/Hisilicon/D03/D03.fdf > +++ b/Platform/Hisilicon/D03/D03.fdf > @@ -283,6 +283,9 @@ READ_LOCK_STATUS = TRUE > INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf > !endif #$(INCLUDE_TFTP_COMMAND) > > +!if $(GENERIC_BDS) == TRUE > + INF MdeModulePkg/Application/UiApp/UiApp.inf > +!endif > # > # Bds > # > @@ -291,7 +294,11 @@ READ_LOCK_STATUS = TRUE > INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf > INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf > INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf > +!if $(GENERIC_BDS) == TRUE > + INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf > +!else > INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf > +!endif > > [FV.FVMAIN_COMPACT] > FvAlignment = 16 > diff --git a/Platform/Hisilicon/D05/D05.dsc b/Platform/Hisilicon/D05/D05.dsc > index 710339c..57370dc 100644 > --- a/Platform/Hisilicon/D05/D05.dsc > +++ b/Platform/Hisilicon/D05/D05.dsc > @@ -31,7 +31,7 @@ > DEFINE EDK2_SKIP_PEICORE=0 > DEFINE NETWORK_IP6_ENABLE = FALSE > DEFINE HTTP_BOOT_ENABLE = FALSE > - > + DEFINE GENERIC_BDS = TRUE Please don't randomly drop whitespace or move it around. > !include Silicon/Hisilicon/Hisilicon.dsc.inc > > [LibraryClasses.common] > @@ -84,6 +84,14 @@ > CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf > GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf > PlatformBdsLib|Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf > +!if $(GENERIC_BDS) == TRUE > + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf > + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf > + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf > + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf > + PlatformBootManagerLib|Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf > +!endif > CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf > > # USB Requirements > @@ -119,6 +127,7 @@ > # It could be set FALSE to save size. > gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE > gHisiTokenSpaceGuid.PcdIsItsSupported|TRUE > + gEfiMdeModulePkgTokenSpaceGuid.PcdHiiOsRuntimeSupport|FALSE > > [PcdsFixedAtBuild.common] > gArmPlatformTokenSpaceGuid.PcdCoreCount|8 > @@ -203,7 +212,9 @@ > > gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE > gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } > - Please don't randomly drop whitespace or move it around. > +!if $(GENERIC_BDS) == TRUE > + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }|VOID*|0x0001006b > +!endif > gHisiTokenSpaceGuid.PcdSysControlBaseAddress|0x40010000 > gHisiTokenSpaceGuid.PcdMailBoxAddress|0x0000FFF8 > > @@ -560,6 +571,14 @@ > MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf > MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf > > +!if $(GENERIC_BDS) == TRUE > + MdeModulePkg/Application/UiApp/UiApp.inf { > + <LibraryClasses> > + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf > + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf > + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf > + } > +!endif > # > # Bds > # > @@ -610,7 +629,11 @@ > MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf > MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf > MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf > +!if $(GENERIC_BDS) == TRUE > + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf > +!else > IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf > +!endif > # > # UEFI application (Shell Embedded Boot Loader) > # > diff --git a/Platform/Hisilicon/D05/D05.fdf b/Platform/Hisilicon/D05/D05.fdf > index 97de4d2..d209210 100644 > --- a/Platform/Hisilicon/D05/D05.fdf > +++ b/Platform/Hisilicon/D05/D05.fdf > @@ -305,6 +305,9 @@ READ_LOCK_STATUS = TRUE > INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf > !endif #$(INCLUDE_TFTP_COMMAND) > > +!if $(GENERIC_BDS) == TRUE > + INF MdeModulePkg/Application/UiApp/UiApp.inf > +!endif > # > # Bds > # > @@ -313,7 +316,11 @@ READ_LOCK_STATUS = TRUE > INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf > INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf > INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf > +!if $(GENERIC_BDS) == TRUE > + INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf > +!else > INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf > +!endif > > [FV.FVMAIN_COMPACT] > FvAlignment = 16 > diff --git a/Silicon/Hisilicon/Hisilicon.dsc.inc b/Silicon/Hisilicon/Hisilicon.dsc.inc > index cc23673..308064b 100644 > --- a/Silicon/Hisilicon/Hisilicon.dsc.inc > +++ b/Silicon/Hisilicon/Hisilicon.dsc.inc > @@ -263,6 +263,7 @@ > gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1 > gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0 > gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320 > + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4 > > # DEBUG_ASSERT_ENABLED 0x01 > # DEBUG_PRINT_ENABLED 0x02 > diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c > new file mode 100644 > index 0000000..5d8d58e > --- /dev/null > +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c > @@ -0,0 +1,588 @@ > +/** @file > + Implementation for PlatformBootManagerLib library class interfaces. > + > + Copyright (c) 2018, ARM Ltd. All rights reserved.<BR> > + Copyright (c) 2018, Hisilicon Limited. All rights reserved. > + Copyright (c) 2018, Linaro Ltd. 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 <IndustryStandard/Pci22.h> > +#include <Library/DevicePathLib.h> > +#include <Library/PcdLib.h> > +#include <Library/UefiBootManagerLib.h> > +#include <Library/UefiLib.h> > +#include <Protocol/DevicePath.h> > +#include <Protocol/EsrtManagement.h> > +#include <Protocol/GenericMemoryTest.h> > +#include <Protocol/GraphicsOutput.h> > +#include <Protocol/LoadedImage.h> > +#include <Protocol/PciIo.h> > +#include <Protocol/PciRootBridgeIo.h> > +#include <Guid/EventGroup.h> > +#include <Guid/TtyTerm.h> > + > +#include "PlatformBm.h" > + > +#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) } > + > + > +#pragma pack (1) > +typedef struct { > + VENDOR_DEVICE_PATH SerialDxe; > + UART_DEVICE_PATH Uart; > + VENDOR_DEFINED_DEVICE_PATH TermType; > + EFI_DEVICE_PATH_PROTOCOL End; > +} PLATFORM_SERIAL_CONSOLE; > +#pragma pack () > + > +#define SERIAL_DXE_FILE_GUID { \ > + 0xD3987D4B, 0x971A, 0x435F, \ > + { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \ > + } > + > +EFI_GUID EblAppGuid2 = {0x3CEF354A,0x3B7A,0x4519,{0xAD,0x70,0x72,0xA1,0x34,0x69,0x83,0x11}}; > + > +STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = { > + // > + // VENDOR_DEVICE_PATH SerialDxe > + // > + { > + { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) }, > + SERIAL_DXE_FILE_GUID > + }, > + > + // > + // UART_DEVICE_PATH Uart > + // > + { > + { MESSAGING_DEVICE_PATH, MSG_UART_DP, DP_NODE_LEN (UART_DEVICE_PATH) }, > + 0, // Reserved > + FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate > + FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits > + FixedPcdGet8 (PcdUartDefaultParity), // Parity > + FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits > + }, > + > + // > + // VENDOR_DEFINED_DEVICE_PATH TermType > + // > + { > + { > + MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, > + DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH) > + } > + // > + // Guid to be filled in dynamically > + // > + }, > + > + // > + // EFI_DEVICE_PATH_PROTOCOL End > + // > + { > + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, > + DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL) > + } > +}; > + > + > +#pragma pack (1) > +typedef struct { > + USB_CLASS_DEVICE_PATH Keyboard; > + EFI_DEVICE_PATH_PROTOCOL End; > +} PLATFORM_USB_KEYBOARD; > +#pragma pack () > + > +STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = { > + // > + // USB_CLASS_DEVICE_PATH Keyboard > + // > + { > + { > + MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP, > + DP_NODE_LEN (USB_CLASS_DEVICE_PATH) > + }, > + 0xFFFF, // VendorId: any > + 0xFFFF, // ProductId: any > + 3, // DeviceClass: HID > + 1, // DeviceSubClass: boot > + 1 // DeviceProtocol: keyboard > + }, > + > + // > + // EFI_DEVICE_PATH_PROTOCOL End > + // > + { > + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, > + DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL) > + } > +}; > + > + > +/** > + Check if the handle satisfies a particular condition. > + > + @param[in] Handle The handle to check. > + @param[in] ReportText A caller-allocated string passed in for reporting > + purposes. It must never be NULL. > + > + @retval TRUE The condition is satisfied. > + @retval FALSE Otherwise. This includes the case when the condition could not > + be fully evaluated due to an error. > +**/ > +typedef > +BOOLEAN > +(EFIAPI *FILTER_FUNCTION) ( > + IN EFI_HANDLE Handle, > + IN CONST CHAR16 *ReportText > + ); > + > + > +/** > + Process a handle. > + > + @param[in] Handle The handle to process. > + @param[in] ReportText A caller-allocated string passed in for reporting > + purposes. It must never be NULL. > +**/ > +typedef > +VOID > +(EFIAPI *CALLBACK_FUNCTION) ( > + IN EFI_HANDLE Handle, > + IN CONST CHAR16 *ReportText > + ); > + > +/** > + Locate all handles that carry the specified protocol, filter them with a > + callback function, and pass each handle that passes the filter to another > + callback. > + > + @param[in] ProtocolGuid The protocol to look for. > + > + @param[in] Filter The filter function to pass each handle to. If this > + parameter is NULL, then all handles are processed. > + > + @param[in] Process The callback function to pass each handle to that > + clears the filter. > +**/ > +STATIC > +VOID > +FilterAndProcess ( > + IN EFI_GUID *ProtocolGuid, > + IN FILTER_FUNCTION Filter OPTIONAL, > + IN CALLBACK_FUNCTION Process > + ) > +{ > + EFI_STATUS Status; > + EFI_HANDLE *Handles; > + UINTN NoHandles; > + UINTN Idx; > + > + Status = gBS->LocateHandleBuffer (ByProtocol, ProtocolGuid, > + NULL /* SearchKey */, &NoHandles, &Handles); > + if (EFI_ERROR (Status)) { > + // > + // This is not an error, just an informative condition. > + // > + DEBUG ((DEBUG_VERBOSE, "%a: %g: %r\n", __FUNCTION__, ProtocolGuid, > + Status)); > + return; > + } > + > + ASSERT (NoHandles > 0); > + for (Idx = 0; Idx < NoHandles; ++Idx) { > + CHAR16 *DevicePathText; > + STATIC CHAR16 Fallback[] = L"<device path unavailable>"; > + > + // > + // The ConvertDevicePathToText() function handles NULL input transparently. > + // > + DevicePathText = ConvertDevicePathToText ( > + DevicePathFromHandle (Handles[Idx]), > + FALSE, // DisplayOnly > + FALSE // AllowShortcuts > + ); > + if (DevicePathText == NULL) { > + DevicePathText = Fallback; > + } > + > + if (Filter == NULL || Filter (Handles[Idx], DevicePathText)) { > + Process (Handles[Idx], DevicePathText); > + } > + > + if (DevicePathText != Fallback) { > + FreePool (DevicePathText); > + } > + } > + gBS->FreePool (Handles); > +} > + > + > +/** > + This FILTER_FUNCTION checks if a handle corresponds to a PCI display device. > +**/ > +STATIC > +BOOLEAN > +EFIAPI > +IsPciDisplay ( > + IN EFI_HANDLE Handle, > + IN CONST CHAR16 *ReportText > + ) > +{ > + EFI_STATUS Status; > + EFI_PCI_IO_PROTOCOL *PciIo; > + PCI_TYPE00 Pci; > + > + Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid, > + (VOID**)&PciIo); > + if (EFI_ERROR (Status)) { > + // > + // This is not an error worth reporting. > + // > + return FALSE; > + } > + > + Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0 /* Offset */, > + sizeof Pci / sizeof (UINT32), &Pci); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %s: %r\n", __FUNCTION__, ReportText, Status)); > + return FALSE; > + } > + > + return IS_PCI_DISPLAY (&Pci); > +} > + > + > +/** > + This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking > + the matching driver to produce all first-level child handles. > +**/ > +STATIC > +VOID > +EFIAPI > +Connect ( > + IN EFI_HANDLE Handle, > + IN CONST CHAR16 *ReportText > + ) > +{ > + EFI_STATUS Status; > + > + Status = gBS->ConnectController ( > + Handle, // ControllerHandle > + NULL, // DriverImageHandle > + NULL, // RemainingDevicePath -- produce all children > + FALSE // Recursive > + ); > + DEBUG ((EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE, "%a: %s: %r\n", > + __FUNCTION__, ReportText, Status)); > +} > + > + > +/** > + This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the > + handle, and adds it to ConOut and ErrOut. > +**/ > +STATIC > +VOID > +EFIAPI > +AddOutput ( > + IN EFI_HANDLE Handle, > + IN CONST CHAR16 *ReportText > + ) > +{ > + EFI_STATUS Status; > + EFI_DEVICE_PATH_PROTOCOL *DevicePath; > + > + DevicePath = DevicePathFromHandle (Handle); > + if (DevicePath == NULL) { > + DEBUG ((DEBUG_ERROR, "%a: %s: handle %p: device path not found\n", > + __FUNCTION__, ReportText, Handle)); > + return; > + } > + > + Status = EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %s: adding to ConOut: %r\n", __FUNCTION__, > + ReportText, Status)); > + return; > + } > + > + Status = EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__, > + ReportText, Status)); > + return; > + } > + > + DEBUG ((DEBUG_VERBOSE, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__, > + ReportText)); > +} > + > +STATIC > +VOID > +PlatformRegisterFvBootOption ( > + EFI_GUID *FileGuid, > + CHAR16 *Description, > + UINT32 Attributes > + ) > +{ > + EFI_STATUS Status; > + INTN 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 = DevicePathFromHandle (LoadedImage->DeviceHandle); > + ASSERT (DevicePath != NULL); > + DevicePath = AppendDevicePathNode ( > + DevicePath, > + (EFI_DEVICE_PATH_PROTOCOL *) &FileNode > + ); > + ASSERT (DevicePath != NULL); > + > + Status = EfiBootManagerInitializeLoadOption ( > + &NewOption, > + LoadOptionNumberUnassigned, > + LoadOptionTypeBoot, > + Attributes, > + Description, > + DevicePath, > + NULL, > + 0 > + ); > + ASSERT_EFI_ERROR (Status); > + FreePool (DevicePath); > + > + BootOptions = EfiBootManagerGetLoadOptions ( > + &BootOptionCount, LoadOptionTypeBoot > + ); > + > + OptionIndex = EfiBootManagerFindLoadOption ( > + &NewOption, BootOptions, BootOptionCount > + ); > + > + if (OptionIndex == -1) { > + Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN); > + ASSERT_EFI_ERROR (Status); > + } > + EfiBootManagerFreeLoadOption (&NewOption); > + EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); > +} > + > + > +STATIC > +VOID > +PlatformRegisterOptionsAndKeys ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + EFI_INPUT_KEY Enter; > + EFI_INPUT_KEY F2; > + EFI_INPUT_KEY Esc; > + EFI_BOOT_MANAGER_LOAD_OPTION BootOption; > + > + // > + // Register ENTER as CONTINUE key > + // > + Enter.ScanCode = SCAN_NULL; > + Enter.UnicodeChar = CHAR_CARRIAGE_RETURN; > + Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL); > + ASSERT_EFI_ERROR (Status); > + > + // > + // Map F2 and ESC to Boot Manager Menu > + // > + F2.ScanCode = SCAN_F2; > + F2.UnicodeChar = CHAR_NULL; > + Esc.ScanCode = SCAN_ESC; > + Esc.UnicodeChar = CHAR_NULL; > + > + Status = EfiBootManagerGetBootManagerMenu (&BootOption); > + ASSERT_EFI_ERROR (Status); > + Status = EfiBootManagerAddKeyOptionVariable ( > + NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL > + ); > + ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED); > + Status = EfiBootManagerAddKeyOptionVariable ( > + NULL, (UINT16) BootOption.OptionNumber, 0, &Esc, NULL > + ); > + ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED); > +} > + > +VOID > +UpdateMemory ( > + ) > +{ > + EFI_STATUS Status; > + EFI_GENERIC_MEMORY_TEST_PROTOCOL* MemoryTest; > + BOOLEAN RequireSoftECCInit = FALSE; > + > + //Add MemoryTest for memmap add above 4G memory. > + Status = gBS->LocateProtocol (&gEfiGenericMemTestProtocolGuid, NULL, (VOID**)&MemoryTest); Line length. > + if (!EFI_ERROR (Status)) { > + (VOID)MemoryTest->MemoryTestInit (MemoryTest, IGNORE, &RequireSoftECCInit); > + } else { > + DEBUG ((DEBUG_ERROR, "LocateProtocol for GenericMemTestProtocol fail(%r)\n", Status)); Line length. > + } > + > + return; > +} > + > +// > +// BDS Platform Functions > +// > +/** > + Do the platform init, can be customized by OEM/IBV > + Possible things that can be done in PlatformBootManagerBeforeConsole: > + > Update console variable: 1. include hot-plug devices; > + > 2. Clear ConIn and add SOL for AMT > + > Register new Driver#### or Boot#### > + > Register new Key####: e.g.: F12 > + > Signal ReadyToLock event > + > Authentication action: 1. connect Auth devices; > + > 2. Identify auto logon user. Please don't use ">" in this way, it confuses review (at least for me). > +**/ > +VOID > +EFIAPI > +PlatformBootManagerBeforeConsole ( > + VOID > + ) > +{ > + // > + // Signal EndOfDxe PI Event > + // > + EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid); > + > + UpdateMemory (); > + > + // > + // Locate the PCI root bridges and make the PCI bus driver connect each, > + // non-recursively. This will produce a number of child handles with PciIo on > + // them. > + // > + FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid, NULL, Connect); > + > + // > + // Find all display class PCI devices (using the handles from the previous > + // step), and connect them non-recursively. This should produce a number of > + // child handles with GOPs on them. > + // > + FilterAndProcess (&gEfiPciIoProtocolGuid, IsPciDisplay, Connect); > + > + // > + // Now add the device path of all handles with GOP on them to ConOut and > + // ErrOut. > + // > + FilterAndProcess (&gEfiGraphicsOutputProtocolGuid, NULL, AddOutput); > + > + // > + // Add the hardcoded short-form USB keyboard device path to ConIn. > + // > + EfiBootManagerUpdateConsoleVariable (ConIn, > + (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL); > + > + // > + // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut. > + // > + ASSERT (FixedPcdGet8 (PcdDefaultTerminalType) == 4); > + CopyGuid (&mSerialConsole.TermType.Guid, &gEfiTtyTermGuid); > + > + EfiBootManagerUpdateConsoleVariable (ConIn, > + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); > + EfiBootManagerUpdateConsoleVariable (ConOut, > + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); > + EfiBootManagerUpdateConsoleVariable (ErrOut, > + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); > + > + // > + // Register platform-specific boot options and keyboard shortcuts. > + // > + PlatformRegisterOptionsAndKeys (); > +} > + > +/** > + Do the platform specific action after the console is ready > + Possible things that can be done in PlatformBootManagerAfterConsole: > + > Console post action: > + > Dynamically switch output mode from 100x31 to 80x25 for certain senarino > + > Signal console ready platform customized event > + > Run diagnostics like memory testing > + > Connect certain devices > + > Dispatch aditional option roms > + > Special boot: e.g.: USB boot, enter UI Please don't use ">" in this way, it confuses review (at least for me). > +**/ > +VOID > +EFIAPI > +PlatformBootManagerAfterConsole ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + ESRT_MANAGEMENT_PROTOCOL *EsrtManagement = NULL; > + > + // > + // Show the splash screen. > + // > + EnableQuietBoot (PcdGetPtr (PcdLogoFile)); > + > + // > + // Connect the rest of the devices. > + // > + EfiBootManagerConnectAll (); > + > + // > + // Enumerate all possible boot options. > + // > + EfiBootManagerRefreshAllBootOption (); > + > + // > + //Sync Esrt Table > + // > + Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtManagement); Line length. > + if (!EFI_ERROR (Status)) { > + Status = EsrtManagement->SyncEsrtFmp (); > + } > + > + // > + // Register UEFI Shell > + // > + PlatformRegisterFvBootOption ( > + PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE > + ); > +} > + > +/** > + This function is called each second during the boot manager waits the > + timeout. > + > + @param TimeoutRemain The remaining timeout. > +**/ > +VOID > +EFIAPI > +PlatformBootManagerWaitCallback ( > + UINT16 TimeoutRemain > + ) > +{ > + Print(L"\r%-2d seconds left, Press Esc or F2 to enter Setup.", TimeoutRemain); Space before (. > +} > diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h > new file mode 100644 > index 0000000..0a3c626 > --- /dev/null > +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h > @@ -0,0 +1,59 @@ > +/** @file > + Head file for BDS Platform specific code > + > + Copyright (C) 2015-2016, Red Hat, Inc. > + Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR> > + Copyright (c) 2016, Linaro Ltd. 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. > + > +**/ > + > +#ifndef _PLATFORM_BM_H_ > +#define _PLATFORM_BM_H_ > + > +#include <Library/BaseLib.h> > +#include <Library/BaseMemoryLib.h> > +#include <Library/DebugLib.h> > +#include <Library/DevicePathLib.h> > +#include <Library/MemoryAllocationLib.h> > +#include <Library/UefiBootServicesTableLib.h> > +#include <Library/UefiLib.h> > +#include <Library/UefiRuntimeServicesTableLib.h> > + > +/** > + Use SystemTable Conout to stop video based Simple Text Out consoles from > + going to the video device. Put up LogoFile on every video device that is a > + console. > + > + @param[in] LogoFile File name of logo to display on the center of the > + screen. > + > + @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo > + displayed. > + @retval EFI_UNSUPPORTED Logo not found > +**/ > +EFI_STATUS > +EnableQuietBoot ( > + IN EFI_GUID *LogoFile > + ); > + > +/** > + Use SystemTable Conout to turn on video based Simple Text Out consoles. The > + Simple Text Out screens will now be synced up with all non video output > + devices > + > + @retval EFI_SUCCESS UGA devices are back in text mode and synced up. > +**/ > +EFI_STATUS > +DisableQuietBoot ( > + VOID > + ); > + > +#endif // _PLATFORM_BM_H_ > diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > new file mode 100644 > index 0000000..ae274f3 > --- /dev/null > +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > @@ -0,0 +1,89 @@ > +## @file > +# Implementation for PlatformBootManagerLib library class interfaces. > +# > +# Copyright (C) 2015-2016, Red Hat, Inc. > +# Copyright (c) 2014, ARM Ltd. All rights reserved.<BR> > +# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR> > +# Copyright (c) 2016, Linaro Ltd. 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. > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 0x0001001a > + BASE_NAME = PlatformBootManagerLib > + FILE_GUID = 92FD2DE3-B9CB-4B35-8141-42AD34D73C9F > + MODULE_TYPE = DXE_DRIVER > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = PlatformBootManagerLib|DXE_DRIVER > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = ARM AARCH64 > +# > + > +[Sources] > + PlatformBm.c > + QuietBoot.c > + > +[Packages] > + IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + MdePkg/MdePkg.dec > + Silicon/Hisilicon/HisiPkg.dec > + > +[LibraryClasses] > + BaseLib > + BaseMemoryLib > + DebugLib > + DevicePathLib > + DxeServicesLib > + MemoryAllocationLib > + PcdLib > + PrintLib > + UefiBootManagerLib > + UefiBootServicesTableLib > + UefiLib > + > +[FeaturePcd] > + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable > + gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport > + > +[FixedPcd] > + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile > + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits > + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType > + > +[Pcd] > + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut > + > +[Guids] > + gEfiFileInfoGuid > + gEfiFileSystemInfoGuid > + gEfiFileSystemVolumeLabelInfoIdGuid > + gEfiEndOfDxeEventGroupGuid Please sort alphabetically (move gEfiEndOfDxeEventGroupGuid first). > + gEfiTtyTermGuid > + > +[Protocols] > + gEfiDevicePathProtocolGuid > + gEfiFirmwareVolume2ProtocolGuid > + gEfiGenericMemTestProtocolGuid > + gEfiGraphicsOutputProtocolGuid > + gEfiLoadedImageProtocolGuid > + gEfiOEMBadgingProtocolGuid > + gEfiPciRootBridgeIoProtocolGuid > + gEfiSimpleFileSystemProtocolGuid > + gEsrtManagementProtocolGuid > diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c b/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c > new file mode 100644 > index 0000000..0bd15da > --- /dev/null > +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c > @@ -0,0 +1,681 @@ > +/** @file > +Platform BDS function for quiet boot support. > + > +Copyright (c) 2018, ARM Ltd. All rights reserved.<BR> > +Copyright (c) 2018, Hisilicon Limited. All rights reserved. > +Copyright (c) 2018, Linaro Ltd. 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 <IndustryStandard/Bmp.h> > +#include <Library/DxeServicesLib.h> > +#include <Protocol/BootLogo.h> > +#include <Protocol/OEMBadging.h> > +#include <Protocol/UgaDraw.h> > + > +#include "PlatformBm.h" > + > +/** > + Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer > + is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt > + buffer is passed in it will be used if it is big enough. > + > + @param BmpImage Pointer to BMP file > + @param BmpImageSize Number of bytes in BmpImage > + @param GopBlt Buffer containing GOP version of BmpImage. > + @param GopBltSize Size of GopBlt in bytes. > + @param PixelHeight Height of GopBlt/BmpImage in pixels > + @param PixelWidth Width of GopBlt/BmpImage in pixels > + > + @retval EFI_SUCCESS GopBlt and GopBltSize are returned. > + @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image > + @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough. > + GopBltSize will contain the required size. > + @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate. > + > +**/ > +STATIC > +EFI_STATUS > +ConvertBmpToGopBlt ( > + IN VOID *BmpImage, > + IN UINTN BmpImageSize, > + IN OUT VOID **GopBlt, > + IN OUT UINTN *GopBltSize, > + OUT UINTN *PixelHeight, > + OUT UINTN *PixelWidth > + ) > +{ > + UINT8 *Image; > + UINT8 *ImageHeader; > + BMP_IMAGE_HEADER *BmpHeader; > + BMP_COLOR_MAP *BmpColorMap; > + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer; > + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; > + UINT64 BltBufferSize; > + UINTN Index; > + UINTN Height; > + UINTN Width; > + UINTN ImageIndex; > + UINT32 DataSizePerLine; > + BOOLEAN IsAllocated; > + UINT32 ColorMapNum; > + > + if (sizeof (BMP_IMAGE_HEADER) > BmpImageSize) { > + return EFI_INVALID_PARAMETER; > + } > + > + BmpHeader = (BMP_IMAGE_HEADER *) BmpImage; > + > + if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') { > + return EFI_UNSUPPORTED; > + } > + > + // > + // Doesn't support compress. > + // > + if (BmpHeader->CompressionType != 0) { > + return EFI_UNSUPPORTED; > + } > + > + // > + // Only support BITMAPINFOHEADER format. > + // BITMAPFILEHEADER + BITMAPINFOHEADER = BMP_IMAGE_HEADER > + // > + if (BmpHeader->HeaderSize != sizeof (BMP_IMAGE_HEADER) - OFFSET_OF(BMP_IMAGE_HEADER, HeaderSize)) { Line length. > + return EFI_UNSUPPORTED; > + } > + > + // > + // The data size in each line must be 4 byte alignment. > + // > + DataSizePerLine = ((BmpHeader->PixelWidth * BmpHeader->BitPerPixel + 31) >> 3) & (~0x3); Line length. > + BltBufferSize = MultU64x32 (DataSizePerLine, BmpHeader->PixelHeight); > + if (BltBufferSize > (UINT32) ~0) { > + return EFI_INVALID_PARAMETER; > + } > + > + if ((BmpHeader->Size != BmpImageSize) || > + (BmpHeader->Size < BmpHeader->ImageOffset) || > + (BmpHeader->Size - BmpHeader->ImageOffset != BmpHeader->PixelHeight * DataSizePerLine)) { Line length. In general, this file seems to mainly duplicate generically useful functions found in various locations in the edk2 tree. Could this instead be broken out into one or several helper libraries to keep in edk2? / Leif > + return EFI_INVALID_PARAMETER; > + } > + > + // > + // Calculate Color Map offset in the image. > + // > + Image = BmpImage; > + BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER)); > + if (BmpHeader->ImageOffset < sizeof (BMP_IMAGE_HEADER)) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (BmpHeader->ImageOffset > sizeof (BMP_IMAGE_HEADER)) { > + switch (BmpHeader->BitPerPixel) { > + case 1: > + ColorMapNum = 2; > + break; > + case 4: > + ColorMapNum = 16; > + break; > + case 8: > + ColorMapNum = 256; > + break; > + default: > + ColorMapNum = 0; > + break; > + } > + // > + // BMP file may has padding data between the bmp header section and the bmp data section. > + // > + if (BmpHeader->ImageOffset - sizeof (BMP_IMAGE_HEADER) < sizeof (BMP_COLOR_MAP) * ColorMapNum) { > + return EFI_INVALID_PARAMETER; > + } > + } > + > + // > + // Calculate graphics image data address in the image > + // > + Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset; > + ImageHeader = Image; > + > + // > + // Calculate the BltBuffer needed size. > + // > + BltBufferSize = MultU64x32 ((UINT64) BmpHeader->PixelWidth, BmpHeader->PixelHeight); > + // > + // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow > + // > + if (BltBufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { > + return EFI_UNSUPPORTED; > + } > + BltBufferSize = MultU64x32 (BltBufferSize, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); > + > + IsAllocated = FALSE; > + if (*GopBlt == NULL) { > + // > + // GopBlt is not allocated by caller. > + // > + *GopBltSize = (UINTN) BltBufferSize; > + *GopBlt = AllocatePool (*GopBltSize); > + IsAllocated = TRUE; > + if (*GopBlt == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + } else { > + // > + // GopBlt has been allocated by caller. > + // > + if (*GopBltSize < (UINTN) BltBufferSize) { > + *GopBltSize = (UINTN) BltBufferSize; > + return EFI_BUFFER_TOO_SMALL; > + } > + } > + > + *PixelWidth = BmpHeader->PixelWidth; > + *PixelHeight = BmpHeader->PixelHeight; > + > + // > + // Convert image from BMP to Blt buffer format > + // > + BltBuffer = *GopBlt; > + for (Height = 0; Height < BmpHeader->PixelHeight; Height++) { > + Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth]; > + for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) { > + switch (BmpHeader->BitPerPixel) { > + case 1: > + // > + // Convert 1-bit (2 colors) BMP to 24-bit color > + // > + for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) { > + Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red; > + Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green; > + Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue; > + Blt++; > + Width++; > + } > + > + Blt--; > + Width--; > + break; > + > + case 4: > + // > + // Convert 4-bit (16 colors) BMP Palette to 24-bit color > + // > + Index = (*Image) >> 4; > + Blt->Red = BmpColorMap[Index].Red; > + Blt->Green = BmpColorMap[Index].Green; > + Blt->Blue = BmpColorMap[Index].Blue; > + if (Width < (BmpHeader->PixelWidth - 1)) { > + Blt++; > + Width++; > + Index = (*Image) & 0x0f; > + Blt->Red = BmpColorMap[Index].Red; > + Blt->Green = BmpColorMap[Index].Green; > + Blt->Blue = BmpColorMap[Index].Blue; > + } > + break; > + > + case 8: > + // > + // Convert 8-bit (256 colors) BMP Palette to 24-bit color > + // > + Blt->Red = BmpColorMap[*Image].Red; > + Blt->Green = BmpColorMap[*Image].Green; > + Blt->Blue = BmpColorMap[*Image].Blue; > + break; > + > + case 24: > + // > + // It is 24-bit BMP. > + // > + Blt->Blue = *Image++; > + Blt->Green = *Image++; > + Blt->Red = *Image; > + break; > + > + default: > + // > + // Other bit format BMP is not supported. > + // > + if (IsAllocated) { > + FreePool (*GopBlt); > + *GopBlt = NULL; > + } > + return EFI_UNSUPPORTED; > + }; > + > + } > + > + ImageIndex = (UINTN) (Image - ImageHeader); > + if ((ImageIndex % 4) != 0) { > + // > + // Bmp Image starts each row on a 32-bit boundary! > + // > + Image = Image + (4 - (ImageIndex % 4)); > + } > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + Use SystemTable Conout to stop video based Simple Text Out consoles from going > + to the video device. Put up LogoFile on every video device that is a console. > + > + @param[in] LogoFile File name of logo to display on the center of the screen. > + > + @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed. > + @retval EFI_UNSUPPORTED Logo not found > + > +**/ > +EFI_STATUS > +EnableQuietBoot ( > + IN EFI_GUID *LogoFile > + ) > +{ > + EFI_STATUS Status; > + EFI_OEM_BADGING_PROTOCOL *Badging; > + UINT32 SizeOfX; > + UINT32 SizeOfY; > + INTN DestX; > + INTN DestY; > + UINT8 *ImageData; > + UINTN ImageSize; > + UINTN BltSize; > + UINT32 Instance; > + EFI_BADGING_FORMAT Format; > + EFI_BADGING_DISPLAY_ATTRIBUTE Attribute; > + UINTN CoordinateX; > + UINTN CoordinateY; > + UINTN Height; > + UINTN Width; > + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; > + EFI_UGA_DRAW_PROTOCOL *UgaDraw; > + UINT32 ColorDepth; > + UINT32 RefreshRate; > + EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; > + EFI_BOOT_LOGO_PROTOCOL *BootLogo; > + UINTN NumberOfLogos; > + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LogoBlt; > + UINTN LogoDestX; > + UINTN LogoDestY; > + UINTN LogoHeight; > + UINTN LogoWidth; > + UINTN NewDestX; > + UINTN NewDestY; > + UINTN NewHeight; > + UINTN NewWidth; > + UINT64 BufferSize; > + > + UgaDraw = NULL; > + // > + // Try to open GOP first > + // > + Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput); > + if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) { > + GraphicsOutput = NULL; > + // > + // Open GOP failed, try to open UGA > + // > + Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw); > + } > + if (EFI_ERROR (Status)) { > + return EFI_UNSUPPORTED; > + } > + > + // > + // Try to open Boot Logo Protocol. > + // > + BootLogo = NULL; > + gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo); > + > + // > + // Erase Cursor from screen > + // > + gST->ConOut->EnableCursor (gST->ConOut, FALSE); > + > + Badging = NULL; > + Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging); > + > + if (GraphicsOutput != NULL) { > + SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution; > + SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution; > + > + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { > + Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate); > + if (EFI_ERROR (Status)) { > + return EFI_UNSUPPORTED; > + } > + } else { > + return EFI_UNSUPPORTED; > + } > + > + Blt = NULL; > + NumberOfLogos = 0; > + LogoDestX = 0; > + LogoDestY = 0; > + LogoHeight = 0; > + LogoWidth = 0; > + NewDestX = 0; > + NewDestY = 0; > + NewHeight = 0; > + NewWidth = 0; > + Instance = 0; > + Height = 0; > + Width = 0; > + while (1) { > + ImageData = NULL; > + ImageSize = 0; > + > + if (Badging != NULL) { > + // > + // Get image from OEMBadging protocol. > + // > + Status = Badging->GetImage ( > + Badging, > + &Instance, > + &Format, > + &ImageData, > + &ImageSize, > + &Attribute, > + &CoordinateX, > + &CoordinateY > + ); > + if (EFI_ERROR (Status)) { > + goto Done; > + } > + > + // > + // Currently only support BMP format. > + // > + if (Format != EfiBadgingFormatBMP) { > + if (ImageData != NULL) { > + FreePool (ImageData); > + } > + continue; > + } > + } else { > + // > + // Get the specified image from FV. > + // > + Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize); > + if (EFI_ERROR (Status)) { > + return EFI_UNSUPPORTED; > + } > + > + CoordinateX = 0; > + CoordinateY = 0; > + if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) { > + Attribute = EfiBadgingDisplayAttributeCenter; > + } else { > + Attribute = EfiBadgingDisplayAttributeCustomized; > + } > + } > + > + if (Blt != NULL) { > + FreePool (Blt); > + } > + Blt = NULL; > + Status = ConvertBmpToGopBlt ( > + ImageData, > + ImageSize, > + (VOID **) &Blt, > + &BltSize, > + &Height, > + &Width > + ); > + if (EFI_ERROR (Status)) { > + FreePool (ImageData); > + > + if (Badging == NULL) { > + return Status; > + } else { > + continue; > + } > + } > + > + // > + // Calculate the display position according to Attribute. > + // > + switch (Attribute) { > + case EfiBadgingDisplayAttributeLeftTop: > + DestX = CoordinateX; > + DestY = CoordinateY; > + break; > + > + case EfiBadgingDisplayAttributeCenterTop: > + DestX = (SizeOfX - Width) / 2; > + DestY = CoordinateY; > + break; > + > + case EfiBadgingDisplayAttributeRightTop: > + DestX = (SizeOfX - Width - CoordinateX); > + DestY = CoordinateY;; > + break; > + > + case EfiBadgingDisplayAttributeCenterRight: > + DestX = (SizeOfX - Width - CoordinateX); > + DestY = (SizeOfY - Height) / 2; > + break; > + > + case EfiBadgingDisplayAttributeRightBottom: > + DestX = (SizeOfX - Width - CoordinateX); > + DestY = (SizeOfY - Height - CoordinateY); > + break; > + > + case EfiBadgingDisplayAttributeCenterBottom: > + DestX = (SizeOfX - Width) / 2; > + DestY = (SizeOfY - Height - CoordinateY); > + break; > + > + case EfiBadgingDisplayAttributeLeftBottom: > + DestX = CoordinateX; > + DestY = (SizeOfY - Height - CoordinateY); > + break; > + > + case EfiBadgingDisplayAttributeCenterLeft: > + DestX = CoordinateX; > + DestY = (SizeOfY - Height) / 2; > + break; > + > + case EfiBadgingDisplayAttributeCenter: > + DestX = (SizeOfX - Width) / 2; > + DestY = (SizeOfY - Height) / 2; > + break; > + > + case EfiBadgingDisplayAttributeCustomized: > + DestX = (SizeOfX - Width) / 2; > + DestY = ((SizeOfY * 382) / 1000) - Height / 2; > + break; > + > + default: > + DestX = CoordinateX; > + DestY = CoordinateY; > + break; > + } > + > + if ((DestX >= 0) && (DestY >= 0)) { > + if (GraphicsOutput != NULL) { > + Status = GraphicsOutput->Blt ( > + GraphicsOutput, > + Blt, > + EfiBltBufferToVideo, > + 0, > + 0, > + (UINTN) DestX, > + (UINTN) DestY, > + Width, > + Height, > + Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) > + ); > + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { > + Status = UgaDraw->Blt ( > + UgaDraw, > + (EFI_UGA_PIXEL *) Blt, > + EfiUgaBltBufferToVideo, > + 0, > + 0, > + (UINTN) DestX, > + (UINTN) DestY, > + Width, > + Height, > + Width * sizeof (EFI_UGA_PIXEL) > + ); > + } else { > + Status = EFI_UNSUPPORTED; > + } > + > + // > + // Report displayed Logo information. > + // > + if (!EFI_ERROR (Status)) { > + NumberOfLogos++; > + > + if (LogoWidth == 0) { > + // > + // The first Logo. > + // > + LogoDestX = (UINTN) DestX; > + LogoDestY = (UINTN) DestY; > + LogoWidth = Width; > + LogoHeight = Height; > + } else { > + // > + // Merge new logo with old one. > + // > + NewDestX = MIN ((UINTN) DestX, LogoDestX); > + NewDestY = MIN ((UINTN) DestY, LogoDestY); > + NewWidth = MAX ((UINTN) DestX + Width, LogoDestX + LogoWidth) - NewDestX; > + NewHeight = MAX ((UINTN) DestY + Height, LogoDestY + LogoHeight) - NewDestY; > + > + LogoDestX = NewDestX; > + LogoDestY = NewDestY; > + LogoWidth = NewWidth; > + LogoHeight = NewHeight; > + } > + } > + } > + > + FreePool (ImageData); > + > + if (Badging == NULL) { > + break; > + } > + } > + > +Done: > + if (BootLogo == NULL || NumberOfLogos == 0) { > + // > + // No logo displayed. > + // > + if (Blt != NULL) { > + FreePool (Blt); > + } > + > + return Status; > + } > + > + // > + // Advertise displayed Logo information. > + // > + if (NumberOfLogos == 1) { > + // > + // Only one logo displayed, use its Blt buffer directly for BootLogo protocol. > + // > + LogoBlt = Blt; > + Status = EFI_SUCCESS; > + } else { > + // > + // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation. > + // > + if (Blt != NULL) { > + FreePool (Blt); > + } > + > + // > + // Ensure the LogoHeight * LogoWidth doesn't overflow > + // > + if (LogoHeight > DivU64x64Remainder ((UINTN) ~0, LogoWidth, NULL)) { > + return EFI_UNSUPPORTED; > + } > + BufferSize = MultU64x64 (LogoWidth, LogoHeight); > + > + // > + // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow > + // > + if (BufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { > + return EFI_UNSUPPORTED; > + } > + > + LogoBlt = AllocateZeroPool ((UINTN)BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); > + if (LogoBlt == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + if (GraphicsOutput != NULL) { > + Status = GraphicsOutput->Blt ( > + GraphicsOutput, > + LogoBlt, > + EfiBltVideoToBltBuffer, > + LogoDestX, > + LogoDestY, > + 0, > + 0, > + LogoWidth, > + LogoHeight, > + LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) > + ); > + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { > + Status = UgaDraw->Blt ( > + UgaDraw, > + (EFI_UGA_PIXEL *) LogoBlt, > + EfiUgaVideoToBltBuffer, > + LogoDestX, > + LogoDestY, > + 0, > + 0, > + LogoWidth, > + LogoHeight, > + LogoWidth * sizeof (EFI_UGA_PIXEL) > + ); > + } else { > + Status = EFI_UNSUPPORTED; > + } > + } > + > + if (!EFI_ERROR (Status)) { > + BootLogo->SetBootLogo (BootLogo, LogoBlt, LogoDestX, LogoDestY, LogoWidth, LogoHeight); > + } > + FreePool (LogoBlt); > + > + return Status; > +} > + > +/** > + Use SystemTable Conout to turn on video based Simple Text Out consoles. The > + Simple Text Out screens will now be synced up with all non video output devices > + > + @retval EFI_SUCCESS UGA devices are back in text mode and synced up. > + > +**/ > +EFI_STATUS > +DisableQuietBoot ( > + VOID > + ) > +{ > + > + // > + // Enable Cursor on Screen > + // > + gST->ConOut->EnableCursor (gST->ConOut, TRUE); > + return EFI_SUCCESS; > +} > + > -- > 1.9.1 > _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
On 2018/1/23 2:38, Leif Lindholm wrote: > Please provide a detailed commit message. > For example, explain that: > - Generic BDS use configurable build-time, enabled by default. > (Why? Is this intended to be temporary?) > - Hisilicon-specific PlatformBootManagerLib added. > (Why? What features are added compared to default one?) > > Minor comments below. > > On Thu, Jan 18, 2018 at 11:01:31PM +0800, Ming Huang wrote: >> Contributed-under: TianoCore Contribution Agreement 1.1 >> Signed-off-by: Ming Huang <huangming23@huawei.com> >> Signed-off-by: Heyi Guo <heyi.guo@linaro.org> >> Signed-off-by: Jason Zhang <zhangjinsong2@huawei.com> >> --- >> Platform/Hisilicon/D03/D03.dsc | 24 + >> Platform/Hisilicon/D03/D03.fdf | 7 + >> Platform/Hisilicon/D05/D05.dsc | 27 +- >> Platform/Hisilicon/D05/D05.fdf | 7 + >> Silicon/Hisilicon/Hisilicon.dsc.inc | 1 + >> Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c | 588 +++++++++++++++++ >> Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h | 59 ++ >> Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 89 +++ >> Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c | 681 ++++++++++++++++++++ >> 9 files changed, 1481 insertions(+), 2 deletions(-) >> >> diff --git a/Platform/Hisilicon/D03/D03.dsc b/Platform/Hisilicon/D03/D03.dsc >> index b434f68..f7efff5 100644 >> --- a/Platform/Hisilicon/D03/D03.dsc >> +++ b/Platform/Hisilicon/D03/D03.dsc >> @@ -28,6 +28,7 @@ >> BUILD_TARGETS = DEBUG|RELEASE >> SKUID_IDENTIFIER = DEFAULT >> FLASH_DEFINITION = Platform/Hisilicon/$(PLATFORM_NAME)/$(PLATFORM_NAME).fdf >> + DEFINE GENERIC_BDS = TRUE >> >> !include Silicon/Hisilicon/Hisilicon.dsc.inc >> >> @@ -68,6 +69,14 @@ >> CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf >> GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf >> PlatformBdsLib|Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf >> +!if $(GENERIC_BDS) == TRUE >> + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf >> + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf >> + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf >> + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf >> + PlatformBootManagerLib|Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf >> + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf >> +!endif >> CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf >> >> # USB Requirements >> @@ -188,6 +197,9 @@ >> >> gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE >> gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } >> +!if $(GENERIC_BDS) == TRUE >> + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }|VOID*|0x0001006b >> +!endif >> >> gHisiTokenSpaceGuid.PcdSysControlBaseAddress|0x40010000 >> gHisiTokenSpaceGuid.PcdMailBoxAddress|0x0000FFF8 >> @@ -405,6 +417,14 @@ >> MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf >> MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf >> >> +!if $(GENERIC_BDS) == TRUE >> + MdeModulePkg/Application/UiApp/UiApp.inf { >> + <LibraryClasses> >> + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf >> + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf >> + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf >> + } >> +!endif >> MdeModulePkg/Application/HelloWorld/HelloWorld.inf >> # >> # Bds >> @@ -457,7 +477,11 @@ >> >> MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf >> MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf >> +!if $(GENERIC_BDS) == TRUE >> + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf >> +!else >> IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf >> +!endif >> >> # >> # UEFI application (Shell Embedded Boot Loader) >> diff --git a/Platform/Hisilicon/D03/D03.fdf b/Platform/Hisilicon/D03/D03.fdf >> index 0b38eb4..0d704b5 100644 >> --- a/Platform/Hisilicon/D03/D03.fdf >> +++ b/Platform/Hisilicon/D03/D03.fdf >> @@ -283,6 +283,9 @@ READ_LOCK_STATUS = TRUE >> INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf >> !endif #$(INCLUDE_TFTP_COMMAND) >> >> +!if $(GENERIC_BDS) == TRUE >> + INF MdeModulePkg/Application/UiApp/UiApp.inf >> +!endif >> # >> # Bds >> # >> @@ -291,7 +294,11 @@ READ_LOCK_STATUS = TRUE >> INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf >> INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf >> INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf >> +!if $(GENERIC_BDS) == TRUE >> + INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf >> +!else >> INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf >> +!endif >> >> [FV.FVMAIN_COMPACT] >> FvAlignment = 16 >> diff --git a/Platform/Hisilicon/D05/D05.dsc b/Platform/Hisilicon/D05/D05.dsc >> index 710339c..57370dc 100644 >> --- a/Platform/Hisilicon/D05/D05.dsc >> +++ b/Platform/Hisilicon/D05/D05.dsc >> @@ -31,7 +31,7 @@ >> DEFINE EDK2_SKIP_PEICORE=0 >> DEFINE NETWORK_IP6_ENABLE = FALSE >> DEFINE HTTP_BOOT_ENABLE = FALSE >> - >> + DEFINE GENERIC_BDS = TRUE > > Please don't randomly drop whitespace or move it around. > >> !include Silicon/Hisilicon/Hisilicon.dsc.inc >> >> [LibraryClasses.common] >> @@ -84,6 +84,14 @@ >> CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf >> GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf >> PlatformBdsLib|Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf >> +!if $(GENERIC_BDS) == TRUE >> + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf >> + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf >> + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf >> + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf >> + PlatformBootManagerLib|Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf >> + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf >> +!endif >> CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf >> >> # USB Requirements >> @@ -119,6 +127,7 @@ >> # It could be set FALSE to save size. >> gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE >> gHisiTokenSpaceGuid.PcdIsItsSupported|TRUE >> + gEfiMdeModulePkgTokenSpaceGuid.PcdHiiOsRuntimeSupport|FALSE >> >> [PcdsFixedAtBuild.common] >> gArmPlatformTokenSpaceGuid.PcdCoreCount|8 >> @@ -203,7 +212,9 @@ >> >> gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE >> gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } >> - > > Please don't randomly drop whitespace or move it around. > >> +!if $(GENERIC_BDS) == TRUE >> + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }|VOID*|0x0001006b >> +!endif >> gHisiTokenSpaceGuid.PcdSysControlBaseAddress|0x40010000 >> gHisiTokenSpaceGuid.PcdMailBoxAddress|0x0000FFF8 >> >> @@ -560,6 +571,14 @@ >> MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf >> MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf >> >> +!if $(GENERIC_BDS) == TRUE >> + MdeModulePkg/Application/UiApp/UiApp.inf { >> + <LibraryClasses> >> + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf >> + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf >> + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf >> + } >> +!endif >> # >> # Bds >> # >> @@ -610,7 +629,11 @@ >> MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf >> MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf >> MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf >> +!if $(GENERIC_BDS) == TRUE >> + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf >> +!else >> IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf >> +!endif >> # >> # UEFI application (Shell Embedded Boot Loader) >> # >> diff --git a/Platform/Hisilicon/D05/D05.fdf b/Platform/Hisilicon/D05/D05.fdf >> index 97de4d2..d209210 100644 >> --- a/Platform/Hisilicon/D05/D05.fdf >> +++ b/Platform/Hisilicon/D05/D05.fdf >> @@ -305,6 +305,9 @@ READ_LOCK_STATUS = TRUE >> INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf >> !endif #$(INCLUDE_TFTP_COMMAND) >> >> +!if $(GENERIC_BDS) == TRUE >> + INF MdeModulePkg/Application/UiApp/UiApp.inf >> +!endif >> # >> # Bds >> # >> @@ -313,7 +316,11 @@ READ_LOCK_STATUS = TRUE >> INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf >> INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf >> INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf >> +!if $(GENERIC_BDS) == TRUE >> + INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf >> +!else >> INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf >> +!endif >> >> [FV.FVMAIN_COMPACT] >> FvAlignment = 16 >> diff --git a/Silicon/Hisilicon/Hisilicon.dsc.inc b/Silicon/Hisilicon/Hisilicon.dsc.inc >> index cc23673..308064b 100644 >> --- a/Silicon/Hisilicon/Hisilicon.dsc.inc >> +++ b/Silicon/Hisilicon/Hisilicon.dsc.inc >> @@ -263,6 +263,7 @@ >> gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1 >> gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0 >> gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320 >> + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4 >> >> # DEBUG_ASSERT_ENABLED 0x01 >> # DEBUG_PRINT_ENABLED 0x02 >> diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c >> new file mode 100644 >> index 0000000..5d8d58e >> --- /dev/null >> +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c >> @@ -0,0 +1,588 @@ >> +/** @file >> + Implementation for PlatformBootManagerLib library class interfaces. >> + >> + Copyright (c) 2018, ARM Ltd. All rights reserved.<BR> >> + Copyright (c) 2018, Hisilicon Limited. All rights reserved. >> + Copyright (c) 2018, Linaro Ltd. 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 <IndustryStandard/Pci22.h> >> +#include <Library/DevicePathLib.h> >> +#include <Library/PcdLib.h> >> +#include <Library/UefiBootManagerLib.h> >> +#include <Library/UefiLib.h> >> +#include <Protocol/DevicePath.h> >> +#include <Protocol/EsrtManagement.h> >> +#include <Protocol/GenericMemoryTest.h> >> +#include <Protocol/GraphicsOutput.h> >> +#include <Protocol/LoadedImage.h> >> +#include <Protocol/PciIo.h> >> +#include <Protocol/PciRootBridgeIo.h> >> +#include <Guid/EventGroup.h> >> +#include <Guid/TtyTerm.h> >> + >> +#include "PlatformBm.h" >> + >> +#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) } >> + >> + >> +#pragma pack (1) >> +typedef struct { >> + VENDOR_DEVICE_PATH SerialDxe; >> + UART_DEVICE_PATH Uart; >> + VENDOR_DEFINED_DEVICE_PATH TermType; >> + EFI_DEVICE_PATH_PROTOCOL End; >> +} PLATFORM_SERIAL_CONSOLE; >> +#pragma pack () >> + >> +#define SERIAL_DXE_FILE_GUID { \ >> + 0xD3987D4B, 0x971A, 0x435F, \ >> + { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \ >> + } >> + >> +EFI_GUID EblAppGuid2 = {0x3CEF354A,0x3B7A,0x4519,{0xAD,0x70,0x72,0xA1,0x34,0x69,0x83,0x11}}; >> + >> +STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = { >> + // >> + // VENDOR_DEVICE_PATH SerialDxe >> + // >> + { >> + { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) }, >> + SERIAL_DXE_FILE_GUID >> + }, >> + >> + // >> + // UART_DEVICE_PATH Uart >> + // >> + { >> + { MESSAGING_DEVICE_PATH, MSG_UART_DP, DP_NODE_LEN (UART_DEVICE_PATH) }, >> + 0, // Reserved >> + FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate >> + FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits >> + FixedPcdGet8 (PcdUartDefaultParity), // Parity >> + FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits >> + }, >> + >> + // >> + // VENDOR_DEFINED_DEVICE_PATH TermType >> + // >> + { >> + { >> + MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, >> + DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH) >> + } >> + // >> + // Guid to be filled in dynamically >> + // >> + }, >> + >> + // >> + // EFI_DEVICE_PATH_PROTOCOL End >> + // >> + { >> + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, >> + DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL) >> + } >> +}; >> + >> + >> +#pragma pack (1) >> +typedef struct { >> + USB_CLASS_DEVICE_PATH Keyboard; >> + EFI_DEVICE_PATH_PROTOCOL End; >> +} PLATFORM_USB_KEYBOARD; >> +#pragma pack () >> + >> +STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = { >> + // >> + // USB_CLASS_DEVICE_PATH Keyboard >> + // >> + { >> + { >> + MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP, >> + DP_NODE_LEN (USB_CLASS_DEVICE_PATH) >> + }, >> + 0xFFFF, // VendorId: any >> + 0xFFFF, // ProductId: any >> + 3, // DeviceClass: HID >> + 1, // DeviceSubClass: boot >> + 1 // DeviceProtocol: keyboard >> + }, >> + >> + // >> + // EFI_DEVICE_PATH_PROTOCOL End >> + // >> + { >> + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, >> + DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL) >> + } >> +}; >> + >> + >> +/** >> + Check if the handle satisfies a particular condition. >> + >> + @param[in] Handle The handle to check. >> + @param[in] ReportText A caller-allocated string passed in for reporting >> + purposes. It must never be NULL. >> + >> + @retval TRUE The condition is satisfied. >> + @retval FALSE Otherwise. This includes the case when the condition could not >> + be fully evaluated due to an error. >> +**/ >> +typedef >> +BOOLEAN >> +(EFIAPI *FILTER_FUNCTION) ( >> + IN EFI_HANDLE Handle, >> + IN CONST CHAR16 *ReportText >> + ); >> + >> + >> +/** >> + Process a handle. >> + >> + @param[in] Handle The handle to process. >> + @param[in] ReportText A caller-allocated string passed in for reporting >> + purposes. It must never be NULL. >> +**/ >> +typedef >> +VOID >> +(EFIAPI *CALLBACK_FUNCTION) ( >> + IN EFI_HANDLE Handle, >> + IN CONST CHAR16 *ReportText >> + ); >> + >> +/** >> + Locate all handles that carry the specified protocol, filter them with a >> + callback function, and pass each handle that passes the filter to another >> + callback. >> + >> + @param[in] ProtocolGuid The protocol to look for. >> + >> + @param[in] Filter The filter function to pass each handle to. If this >> + parameter is NULL, then all handles are processed. >> + >> + @param[in] Process The callback function to pass each handle to that >> + clears the filter. >> +**/ >> +STATIC >> +VOID >> +FilterAndProcess ( >> + IN EFI_GUID *ProtocolGuid, >> + IN FILTER_FUNCTION Filter OPTIONAL, >> + IN CALLBACK_FUNCTION Process >> + ) >> +{ >> + EFI_STATUS Status; >> + EFI_HANDLE *Handles; >> + UINTN NoHandles; >> + UINTN Idx; >> + >> + Status = gBS->LocateHandleBuffer (ByProtocol, ProtocolGuid, >> + NULL /* SearchKey */, &NoHandles, &Handles); >> + if (EFI_ERROR (Status)) { >> + // >> + // This is not an error, just an informative condition. >> + // >> + DEBUG ((DEBUG_VERBOSE, "%a: %g: %r\n", __FUNCTION__, ProtocolGuid, >> + Status)); >> + return; >> + } >> + >> + ASSERT (NoHandles > 0); >> + for (Idx = 0; Idx < NoHandles; ++Idx) { >> + CHAR16 *DevicePathText; >> + STATIC CHAR16 Fallback[] = L"<device path unavailable>"; >> + >> + // >> + // The ConvertDevicePathToText() function handles NULL input transparently. >> + // >> + DevicePathText = ConvertDevicePathToText ( >> + DevicePathFromHandle (Handles[Idx]), >> + FALSE, // DisplayOnly >> + FALSE // AllowShortcuts >> + ); >> + if (DevicePathText == NULL) { >> + DevicePathText = Fallback; >> + } >> + >> + if (Filter == NULL || Filter (Handles[Idx], DevicePathText)) { >> + Process (Handles[Idx], DevicePathText); >> + } >> + >> + if (DevicePathText != Fallback) { >> + FreePool (DevicePathText); >> + } >> + } >> + gBS->FreePool (Handles); >> +} >> + >> + >> +/** >> + This FILTER_FUNCTION checks if a handle corresponds to a PCI display device. >> +**/ >> +STATIC >> +BOOLEAN >> +EFIAPI >> +IsPciDisplay ( >> + IN EFI_HANDLE Handle, >> + IN CONST CHAR16 *ReportText >> + ) >> +{ >> + EFI_STATUS Status; >> + EFI_PCI_IO_PROTOCOL *PciIo; >> + PCI_TYPE00 Pci; >> + >> + Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid, >> + (VOID**)&PciIo); >> + if (EFI_ERROR (Status)) { >> + // >> + // This is not an error worth reporting. >> + // >> + return FALSE; >> + } >> + >> + Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0 /* Offset */, >> + sizeof Pci / sizeof (UINT32), &Pci); >> + if (EFI_ERROR (Status)) { >> + DEBUG ((DEBUG_ERROR, "%a: %s: %r\n", __FUNCTION__, ReportText, Status)); >> + return FALSE; >> + } >> + >> + return IS_PCI_DISPLAY (&Pci); >> +} >> + >> + >> +/** >> + This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking >> + the matching driver to produce all first-level child handles. >> +**/ >> +STATIC >> +VOID >> +EFIAPI >> +Connect ( >> + IN EFI_HANDLE Handle, >> + IN CONST CHAR16 *ReportText >> + ) >> +{ >> + EFI_STATUS Status; >> + >> + Status = gBS->ConnectController ( >> + Handle, // ControllerHandle >> + NULL, // DriverImageHandle >> + NULL, // RemainingDevicePath -- produce all children >> + FALSE // Recursive >> + ); >> + DEBUG ((EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE, "%a: %s: %r\n", >> + __FUNCTION__, ReportText, Status)); >> +} >> + >> + >> +/** >> + This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the >> + handle, and adds it to ConOut and ErrOut. >> +**/ >> +STATIC >> +VOID >> +EFIAPI >> +AddOutput ( >> + IN EFI_HANDLE Handle, >> + IN CONST CHAR16 *ReportText >> + ) >> +{ >> + EFI_STATUS Status; >> + EFI_DEVICE_PATH_PROTOCOL *DevicePath; >> + >> + DevicePath = DevicePathFromHandle (Handle); >> + if (DevicePath == NULL) { >> + DEBUG ((DEBUG_ERROR, "%a: %s: handle %p: device path not found\n", >> + __FUNCTION__, ReportText, Handle)); >> + return; >> + } >> + >> + Status = EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL); >> + if (EFI_ERROR (Status)) { >> + DEBUG ((DEBUG_ERROR, "%a: %s: adding to ConOut: %r\n", __FUNCTION__, >> + ReportText, Status)); >> + return; >> + } >> + >> + Status = EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL); >> + if (EFI_ERROR (Status)) { >> + DEBUG ((DEBUG_ERROR, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__, >> + ReportText, Status)); >> + return; >> + } >> + >> + DEBUG ((DEBUG_VERBOSE, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__, >> + ReportText)); >> +} >> + >> +STATIC >> +VOID >> +PlatformRegisterFvBootOption ( >> + EFI_GUID *FileGuid, >> + CHAR16 *Description, >> + UINT32 Attributes >> + ) >> +{ >> + EFI_STATUS Status; >> + INTN 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 = DevicePathFromHandle (LoadedImage->DeviceHandle); >> + ASSERT (DevicePath != NULL); >> + DevicePath = AppendDevicePathNode ( >> + DevicePath, >> + (EFI_DEVICE_PATH_PROTOCOL *) &FileNode >> + ); >> + ASSERT (DevicePath != NULL); >> + >> + Status = EfiBootManagerInitializeLoadOption ( >> + &NewOption, >> + LoadOptionNumberUnassigned, >> + LoadOptionTypeBoot, >> + Attributes, >> + Description, >> + DevicePath, >> + NULL, >> + 0 >> + ); >> + ASSERT_EFI_ERROR (Status); >> + FreePool (DevicePath); >> + >> + BootOptions = EfiBootManagerGetLoadOptions ( >> + &BootOptionCount, LoadOptionTypeBoot >> + ); >> + >> + OptionIndex = EfiBootManagerFindLoadOption ( >> + &NewOption, BootOptions, BootOptionCount >> + ); >> + >> + if (OptionIndex == -1) { >> + Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN); >> + ASSERT_EFI_ERROR (Status); >> + } >> + EfiBootManagerFreeLoadOption (&NewOption); >> + EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); >> +} >> + >> + >> +STATIC >> +VOID >> +PlatformRegisterOptionsAndKeys ( >> + VOID >> + ) >> +{ >> + EFI_STATUS Status; >> + EFI_INPUT_KEY Enter; >> + EFI_INPUT_KEY F2; >> + EFI_INPUT_KEY Esc; >> + EFI_BOOT_MANAGER_LOAD_OPTION BootOption; >> + >> + // >> + // Register ENTER as CONTINUE key >> + // >> + Enter.ScanCode = SCAN_NULL; >> + Enter.UnicodeChar = CHAR_CARRIAGE_RETURN; >> + Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL); >> + ASSERT_EFI_ERROR (Status); >> + >> + // >> + // Map F2 and ESC to Boot Manager Menu >> + // >> + F2.ScanCode = SCAN_F2; >> + F2.UnicodeChar = CHAR_NULL; >> + Esc.ScanCode = SCAN_ESC; >> + Esc.UnicodeChar = CHAR_NULL; >> + >> + Status = EfiBootManagerGetBootManagerMenu (&BootOption); >> + ASSERT_EFI_ERROR (Status); >> + Status = EfiBootManagerAddKeyOptionVariable ( >> + NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL >> + ); >> + ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED); >> + Status = EfiBootManagerAddKeyOptionVariable ( >> + NULL, (UINT16) BootOption.OptionNumber, 0, &Esc, NULL >> + ); >> + ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED); >> +} >> + >> +VOID >> +UpdateMemory ( >> + ) >> +{ >> + EFI_STATUS Status; >> + EFI_GENERIC_MEMORY_TEST_PROTOCOL* MemoryTest; >> + BOOLEAN RequireSoftECCInit = FALSE; >> + >> + //Add MemoryTest for memmap add above 4G memory. >> + Status = gBS->LocateProtocol (&gEfiGenericMemTestProtocolGuid, NULL, (VOID**)&MemoryTest); > > Line length. > >> + if (!EFI_ERROR (Status)) { >> + (VOID)MemoryTest->MemoryTestInit (MemoryTest, IGNORE, &RequireSoftECCInit); >> + } else { >> + DEBUG ((DEBUG_ERROR, "LocateProtocol for GenericMemTestProtocol fail(%r)\n", Status)); > > Line length. > >> + } >> + >> + return; >> +} >> + >> +// >> +// BDS Platform Functions >> +// >> +/** >> + Do the platform init, can be customized by OEM/IBV >> + Possible things that can be done in PlatformBootManagerBeforeConsole: >> + > Update console variable: 1. include hot-plug devices; >> + > 2. Clear ConIn and add SOL for AMT >> + > Register new Driver#### or Boot#### >> + > Register new Key####: e.g.: F12 >> + > Signal ReadyToLock event >> + > Authentication action: 1. connect Auth devices; >> + > 2. Identify auto logon user. > > Please don't use ">" in this way, it confuses review (at least for me). > >> +**/ >> +VOID >> +EFIAPI >> +PlatformBootManagerBeforeConsole ( >> + VOID >> + ) >> +{ >> + // >> + // Signal EndOfDxe PI Event >> + // >> + EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid); >> + >> + UpdateMemory (); >> + >> + // >> + // Locate the PCI root bridges and make the PCI bus driver connect each, >> + // non-recursively. This will produce a number of child handles with PciIo on >> + // them. >> + // >> + FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid, NULL, Connect); >> + >> + // >> + // Find all display class PCI devices (using the handles from the previous >> + // step), and connect them non-recursively. This should produce a number of >> + // child handles with GOPs on them. >> + // >> + FilterAndProcess (&gEfiPciIoProtocolGuid, IsPciDisplay, Connect); >> + >> + // >> + // Now add the device path of all handles with GOP on them to ConOut and >> + // ErrOut. >> + // >> + FilterAndProcess (&gEfiGraphicsOutputProtocolGuid, NULL, AddOutput); >> + >> + // >> + // Add the hardcoded short-form USB keyboard device path to ConIn. >> + // >> + EfiBootManagerUpdateConsoleVariable (ConIn, >> + (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL); >> + >> + // >> + // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut. >> + // >> + ASSERT (FixedPcdGet8 (PcdDefaultTerminalType) == 4); >> + CopyGuid (&mSerialConsole.TermType.Guid, &gEfiTtyTermGuid); >> + >> + EfiBootManagerUpdateConsoleVariable (ConIn, >> + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); >> + EfiBootManagerUpdateConsoleVariable (ConOut, >> + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); >> + EfiBootManagerUpdateConsoleVariable (ErrOut, >> + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); >> + >> + // >> + // Register platform-specific boot options and keyboard shortcuts. >> + // >> + PlatformRegisterOptionsAndKeys (); >> +} >> + >> +/** >> + Do the platform specific action after the console is ready >> + Possible things that can be done in PlatformBootManagerAfterConsole: >> + > Console post action: >> + > Dynamically switch output mode from 100x31 to 80x25 for certain senarino >> + > Signal console ready platform customized event >> + > Run diagnostics like memory testing >> + > Connect certain devices >> + > Dispatch aditional option roms >> + > Special boot: e.g.: USB boot, enter UI > > Please don't use ">" in this way, it confuses review (at least for me). > >> +**/ >> +VOID >> +EFIAPI >> +PlatformBootManagerAfterConsole ( >> + VOID >> + ) >> +{ >> + EFI_STATUS Status; >> + ESRT_MANAGEMENT_PROTOCOL *EsrtManagement = NULL; >> + >> + // >> + // Show the splash screen. >> + // >> + EnableQuietBoot (PcdGetPtr (PcdLogoFile)); >> + >> + // >> + // Connect the rest of the devices. >> + // >> + EfiBootManagerConnectAll (); >> + >> + // >> + // Enumerate all possible boot options. >> + // >> + EfiBootManagerRefreshAllBootOption (); >> + >> + // >> + //Sync Esrt Table >> + // >> + Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtManagement); > > Line length. > >> + if (!EFI_ERROR (Status)) { >> + Status = EsrtManagement->SyncEsrtFmp (); >> + } >> + >> + // >> + // Register UEFI Shell >> + // >> + PlatformRegisterFvBootOption ( >> + PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE >> + ); >> +} >> + >> +/** >> + This function is called each second during the boot manager waits the >> + timeout. >> + >> + @param TimeoutRemain The remaining timeout. >> +**/ >> +VOID >> +EFIAPI >> +PlatformBootManagerWaitCallback ( >> + UINT16 TimeoutRemain >> + ) >> +{ >> + Print(L"\r%-2d seconds left, Press Esc or F2 to enter Setup.", TimeoutRemain); > > Space before (. > >> +} >> diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h >> new file mode 100644 >> index 0000000..0a3c626 >> --- /dev/null >> +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h >> @@ -0,0 +1,59 @@ >> +/** @file >> + Head file for BDS Platform specific code >> + >> + Copyright (C) 2015-2016, Red Hat, Inc. >> + Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR> >> + Copyright (c) 2016, Linaro Ltd. 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. >> + >> +**/ >> + >> +#ifndef _PLATFORM_BM_H_ >> +#define _PLATFORM_BM_H_ >> + >> +#include <Library/BaseLib.h> >> +#include <Library/BaseMemoryLib.h> >> +#include <Library/DebugLib.h> >> +#include <Library/DevicePathLib.h> >> +#include <Library/MemoryAllocationLib.h> >> +#include <Library/UefiBootServicesTableLib.h> >> +#include <Library/UefiLib.h> >> +#include <Library/UefiRuntimeServicesTableLib.h> >> + >> +/** >> + Use SystemTable Conout to stop video based Simple Text Out consoles from >> + going to the video device. Put up LogoFile on every video device that is a >> + console. >> + >> + @param[in] LogoFile File name of logo to display on the center of the >> + screen. >> + >> + @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo >> + displayed. >> + @retval EFI_UNSUPPORTED Logo not found >> +**/ >> +EFI_STATUS >> +EnableQuietBoot ( >> + IN EFI_GUID *LogoFile >> + ); >> + >> +/** >> + Use SystemTable Conout to turn on video based Simple Text Out consoles. The >> + Simple Text Out screens will now be synced up with all non video output >> + devices >> + >> + @retval EFI_SUCCESS UGA devices are back in text mode and synced up. >> +**/ >> +EFI_STATUS >> +DisableQuietBoot ( >> + VOID >> + ); >> + >> +#endif // _PLATFORM_BM_H_ >> diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf >> new file mode 100644 >> index 0000000..ae274f3 >> --- /dev/null >> +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf >> @@ -0,0 +1,89 @@ >> +## @file >> +# Implementation for PlatformBootManagerLib library class interfaces. >> +# >> +# Copyright (C) 2015-2016, Red Hat, Inc. >> +# Copyright (c) 2014, ARM Ltd. All rights reserved.<BR> >> +# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR> >> +# Copyright (c) 2016, Linaro Ltd. 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. >> +# >> +## >> + >> +[Defines] >> + INF_VERSION = 0x00010005 > > 0x0001001a > >> + BASE_NAME = PlatformBootManagerLib >> + FILE_GUID = 92FD2DE3-B9CB-4B35-8141-42AD34D73C9F >> + MODULE_TYPE = DXE_DRIVER >> + VERSION_STRING = 1.0 >> + LIBRARY_CLASS = PlatformBootManagerLib|DXE_DRIVER >> + >> +# >> +# The following information is for reference only and not required by the build tools. >> +# >> +# VALID_ARCHITECTURES = ARM AARCH64 >> +# >> + >> +[Sources] >> + PlatformBm.c >> + QuietBoot.c >> + >> +[Packages] >> + IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec >> + MdeModulePkg/MdeModulePkg.dec >> + MdePkg/MdePkg.dec >> + Silicon/Hisilicon/HisiPkg.dec >> + >> +[LibraryClasses] >> + BaseLib >> + BaseMemoryLib >> + DebugLib >> + DevicePathLib >> + DxeServicesLib >> + MemoryAllocationLib >> + PcdLib >> + PrintLib >> + UefiBootManagerLib >> + UefiBootServicesTableLib >> + UefiLib >> + >> +[FeaturePcd] >> + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable >> + gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport >> + >> +[FixedPcd] >> + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile >> + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile >> + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate >> + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits >> + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity >> + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits >> + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType >> + >> +[Pcd] >> + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut >> + >> +[Guids] >> + gEfiFileInfoGuid >> + gEfiFileSystemInfoGuid >> + gEfiFileSystemVolumeLabelInfoIdGuid >> + gEfiEndOfDxeEventGroupGuid > > Please sort alphabetically (move gEfiEndOfDxeEventGroupGuid first). > >> + gEfiTtyTermGuid >> + >> +[Protocols] >> + gEfiDevicePathProtocolGuid >> + gEfiFirmwareVolume2ProtocolGuid >> + gEfiGenericMemTestProtocolGuid >> + gEfiGraphicsOutputProtocolGuid >> + gEfiLoadedImageProtocolGuid >> + gEfiOEMBadgingProtocolGuid >> + gEfiPciRootBridgeIoProtocolGuid >> + gEfiSimpleFileSystemProtocolGuid >> + gEsrtManagementProtocolGuid >> diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c b/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c >> new file mode 100644 >> index 0000000..0bd15da >> --- /dev/null >> +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c >> @@ -0,0 +1,681 @@ >> +/** @file >> +Platform BDS function for quiet boot support. >> + >> +Copyright (c) 2018, ARM Ltd. All rights reserved.<BR> >> +Copyright (c) 2018, Hisilicon Limited. All rights reserved. >> +Copyright (c) 2018, Linaro Ltd. 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 <IndustryStandard/Bmp.h> >> +#include <Library/DxeServicesLib.h> >> +#include <Protocol/BootLogo.h> >> +#include <Protocol/OEMBadging.h> >> +#include <Protocol/UgaDraw.h> >> + >> +#include "PlatformBm.h" >> + >> +/** >> + Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer >> + is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt >> + buffer is passed in it will be used if it is big enough. >> + >> + @param BmpImage Pointer to BMP file >> + @param BmpImageSize Number of bytes in BmpImage >> + @param GopBlt Buffer containing GOP version of BmpImage. >> + @param GopBltSize Size of GopBlt in bytes. >> + @param PixelHeight Height of GopBlt/BmpImage in pixels >> + @param PixelWidth Width of GopBlt/BmpImage in pixels >> + >> + @retval EFI_SUCCESS GopBlt and GopBltSize are returned. >> + @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image >> + @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough. >> + GopBltSize will contain the required size. >> + @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate. >> + >> +**/ >> +STATIC >> +EFI_STATUS >> +ConvertBmpToGopBlt ( >> + IN VOID *BmpImage, >> + IN UINTN BmpImageSize, >> + IN OUT VOID **GopBlt, >> + IN OUT UINTN *GopBltSize, >> + OUT UINTN *PixelHeight, >> + OUT UINTN *PixelWidth >> + ) >> +{ >> + UINT8 *Image; >> + UINT8 *ImageHeader; >> + BMP_IMAGE_HEADER *BmpHeader; >> + BMP_COLOR_MAP *BmpColorMap; >> + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer; >> + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; >> + UINT64 BltBufferSize; >> + UINTN Index; >> + UINTN Height; >> + UINTN Width; >> + UINTN ImageIndex; >> + UINT32 DataSizePerLine; >> + BOOLEAN IsAllocated; >> + UINT32 ColorMapNum; >> + >> + if (sizeof (BMP_IMAGE_HEADER) > BmpImageSize) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + BmpHeader = (BMP_IMAGE_HEADER *) BmpImage; >> + >> + if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') { >> + return EFI_UNSUPPORTED; >> + } >> + >> + // >> + // Doesn't support compress. >> + // >> + if (BmpHeader->CompressionType != 0) { >> + return EFI_UNSUPPORTED; >> + } >> + >> + // >> + // Only support BITMAPINFOHEADER format. >> + // BITMAPFILEHEADER + BITMAPINFOHEADER = BMP_IMAGE_HEADER >> + // >> + if (BmpHeader->HeaderSize != sizeof (BMP_IMAGE_HEADER) - OFFSET_OF(BMP_IMAGE_HEADER, HeaderSize)) { > > Line length. > >> + return EFI_UNSUPPORTED; >> + } >> + >> + // >> + // The data size in each line must be 4 byte alignment. >> + // >> + DataSizePerLine = ((BmpHeader->PixelWidth * BmpHeader->BitPerPixel + 31) >> 3) & (~0x3); > > Line length. > >> + BltBufferSize = MultU64x32 (DataSizePerLine, BmpHeader->PixelHeight); >> + if (BltBufferSize > (UINT32) ~0) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + if ((BmpHeader->Size != BmpImageSize) || >> + (BmpHeader->Size < BmpHeader->ImageOffset) || >> + (BmpHeader->Size - BmpHeader->ImageOffset != BmpHeader->PixelHeight * DataSizePerLine)) { > > Line length. > > In general, this file seems to mainly duplicate generically useful > functions found in various locations in the edk2 tree. > Could this instead be broken out into one or several helper libraries > to keep in edk2? > > / > Leif > Yes, this file QuietBoot.c will be deleted and replace with BootLogoLib in edk2 as Ard suggested. >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + // >> + // Calculate Color Map offset in the image. >> + // >> + Image = BmpImage; >> + BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER)); >> + if (BmpHeader->ImageOffset < sizeof (BMP_IMAGE_HEADER)) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + if (BmpHeader->ImageOffset > sizeof (BMP_IMAGE_HEADER)) { >> + switch (BmpHeader->BitPerPixel) { >> + case 1: >> + ColorMapNum = 2; >> + break; >> + case 4: >> + ColorMapNum = 16; >> + break; >> + case 8: >> + ColorMapNum = 256; >> + break; >> + default: >> + ColorMapNum = 0; >> + break; >> + } >> + // >> + // BMP file may has padding data between the bmp header section and the bmp data section. >> + // >> + if (BmpHeader->ImageOffset - sizeof (BMP_IMAGE_HEADER) < sizeof (BMP_COLOR_MAP) * ColorMapNum) { >> + return EFI_INVALID_PARAMETER; >> + } >> + } >> + >> + // >> + // Calculate graphics image data address in the image >> + // >> + Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset; >> + ImageHeader = Image; >> + >> + // >> + // Calculate the BltBuffer needed size. >> + // >> + BltBufferSize = MultU64x32 ((UINT64) BmpHeader->PixelWidth, BmpHeader->PixelHeight); >> + // >> + // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow >> + // >> + if (BltBufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { >> + return EFI_UNSUPPORTED; >> + } >> + BltBufferSize = MultU64x32 (BltBufferSize, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); >> + >> + IsAllocated = FALSE; >> + if (*GopBlt == NULL) { >> + // >> + // GopBlt is not allocated by caller. >> + // >> + *GopBltSize = (UINTN) BltBufferSize; >> + *GopBlt = AllocatePool (*GopBltSize); >> + IsAllocated = TRUE; >> + if (*GopBlt == NULL) { >> + return EFI_OUT_OF_RESOURCES; >> + } >> + } else { >> + // >> + // GopBlt has been allocated by caller. >> + // >> + if (*GopBltSize < (UINTN) BltBufferSize) { >> + *GopBltSize = (UINTN) BltBufferSize; >> + return EFI_BUFFER_TOO_SMALL; >> + } >> + } >> + >> + *PixelWidth = BmpHeader->PixelWidth; >> + *PixelHeight = BmpHeader->PixelHeight; >> + >> + // >> + // Convert image from BMP to Blt buffer format >> + // >> + BltBuffer = *GopBlt; >> + for (Height = 0; Height < BmpHeader->PixelHeight; Height++) { >> + Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth]; >> + for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) { >> + switch (BmpHeader->BitPerPixel) { >> + case 1: >> + // >> + // Convert 1-bit (2 colors) BMP to 24-bit color >> + // >> + for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) { >> + Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red; >> + Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green; >> + Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue; >> + Blt++; >> + Width++; >> + } >> + >> + Blt--; >> + Width--; >> + break; >> + >> + case 4: >> + // >> + // Convert 4-bit (16 colors) BMP Palette to 24-bit color >> + // >> + Index = (*Image) >> 4; >> + Blt->Red = BmpColorMap[Index].Red; >> + Blt->Green = BmpColorMap[Index].Green; >> + Blt->Blue = BmpColorMap[Index].Blue; >> + if (Width < (BmpHeader->PixelWidth - 1)) { >> + Blt++; >> + Width++; >> + Index = (*Image) & 0x0f; >> + Blt->Red = BmpColorMap[Index].Red; >> + Blt->Green = BmpColorMap[Index].Green; >> + Blt->Blue = BmpColorMap[Index].Blue; >> + } >> + break; >> + >> + case 8: >> + // >> + // Convert 8-bit (256 colors) BMP Palette to 24-bit color >> + // >> + Blt->Red = BmpColorMap[*Image].Red; >> + Blt->Green = BmpColorMap[*Image].Green; >> + Blt->Blue = BmpColorMap[*Image].Blue; >> + break; >> + >> + case 24: >> + // >> + // It is 24-bit BMP. >> + // >> + Blt->Blue = *Image++; >> + Blt->Green = *Image++; >> + Blt->Red = *Image; >> + break; >> + >> + default: >> + // >> + // Other bit format BMP is not supported. >> + // >> + if (IsAllocated) { >> + FreePool (*GopBlt); >> + *GopBlt = NULL; >> + } >> + return EFI_UNSUPPORTED; >> + }; >> + >> + } >> + >> + ImageIndex = (UINTN) (Image - ImageHeader); >> + if ((ImageIndex % 4) != 0) { >> + // >> + // Bmp Image starts each row on a 32-bit boundary! >> + // >> + Image = Image + (4 - (ImageIndex % 4)); >> + } >> + } >> + >> + return EFI_SUCCESS; >> +} >> + >> +/** >> + Use SystemTable Conout to stop video based Simple Text Out consoles from going >> + to the video device. Put up LogoFile on every video device that is a console. >> + >> + @param[in] LogoFile File name of logo to display on the center of the screen. >> + >> + @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed. >> + @retval EFI_UNSUPPORTED Logo not found >> + >> +**/ >> +EFI_STATUS >> +EnableQuietBoot ( >> + IN EFI_GUID *LogoFile >> + ) >> +{ >> + EFI_STATUS Status; >> + EFI_OEM_BADGING_PROTOCOL *Badging; >> + UINT32 SizeOfX; >> + UINT32 SizeOfY; >> + INTN DestX; >> + INTN DestY; >> + UINT8 *ImageData; >> + UINTN ImageSize; >> + UINTN BltSize; >> + UINT32 Instance; >> + EFI_BADGING_FORMAT Format; >> + EFI_BADGING_DISPLAY_ATTRIBUTE Attribute; >> + UINTN CoordinateX; >> + UINTN CoordinateY; >> + UINTN Height; >> + UINTN Width; >> + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; >> + EFI_UGA_DRAW_PROTOCOL *UgaDraw; >> + UINT32 ColorDepth; >> + UINT32 RefreshRate; >> + EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; >> + EFI_BOOT_LOGO_PROTOCOL *BootLogo; >> + UINTN NumberOfLogos; >> + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LogoBlt; >> + UINTN LogoDestX; >> + UINTN LogoDestY; >> + UINTN LogoHeight; >> + UINTN LogoWidth; >> + UINTN NewDestX; >> + UINTN NewDestY; >> + UINTN NewHeight; >> + UINTN NewWidth; >> + UINT64 BufferSize; >> + >> + UgaDraw = NULL; >> + // >> + // Try to open GOP first >> + // >> + Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput); >> + if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) { >> + GraphicsOutput = NULL; >> + // >> + // Open GOP failed, try to open UGA >> + // >> + Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw); >> + } >> + if (EFI_ERROR (Status)) { >> + return EFI_UNSUPPORTED; >> + } >> + >> + // >> + // Try to open Boot Logo Protocol. >> + // >> + BootLogo = NULL; >> + gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo); >> + >> + // >> + // Erase Cursor from screen >> + // >> + gST->ConOut->EnableCursor (gST->ConOut, FALSE); >> + >> + Badging = NULL; >> + Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging); >> + >> + if (GraphicsOutput != NULL) { >> + SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution; >> + SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution; >> + >> + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { >> + Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate); >> + if (EFI_ERROR (Status)) { >> + return EFI_UNSUPPORTED; >> + } >> + } else { >> + return EFI_UNSUPPORTED; >> + } >> + >> + Blt = NULL; >> + NumberOfLogos = 0; >> + LogoDestX = 0; >> + LogoDestY = 0; >> + LogoHeight = 0; >> + LogoWidth = 0; >> + NewDestX = 0; >> + NewDestY = 0; >> + NewHeight = 0; >> + NewWidth = 0; >> + Instance = 0; >> + Height = 0; >> + Width = 0; >> + while (1) { >> + ImageData = NULL; >> + ImageSize = 0; >> + >> + if (Badging != NULL) { >> + // >> + // Get image from OEMBadging protocol. >> + // >> + Status = Badging->GetImage ( >> + Badging, >> + &Instance, >> + &Format, >> + &ImageData, >> + &ImageSize, >> + &Attribute, >> + &CoordinateX, >> + &CoordinateY >> + ); >> + if (EFI_ERROR (Status)) { >> + goto Done; >> + } >> + >> + // >> + // Currently only support BMP format. >> + // >> + if (Format != EfiBadgingFormatBMP) { >> + if (ImageData != NULL) { >> + FreePool (ImageData); >> + } >> + continue; >> + } >> + } else { >> + // >> + // Get the specified image from FV. >> + // >> + Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize); >> + if (EFI_ERROR (Status)) { >> + return EFI_UNSUPPORTED; >> + } >> + >> + CoordinateX = 0; >> + CoordinateY = 0; >> + if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) { >> + Attribute = EfiBadgingDisplayAttributeCenter; >> + } else { >> + Attribute = EfiBadgingDisplayAttributeCustomized; >> + } >> + } >> + >> + if (Blt != NULL) { >> + FreePool (Blt); >> + } >> + Blt = NULL; >> + Status = ConvertBmpToGopBlt ( >> + ImageData, >> + ImageSize, >> + (VOID **) &Blt, >> + &BltSize, >> + &Height, >> + &Width >> + ); >> + if (EFI_ERROR (Status)) { >> + FreePool (ImageData); >> + >> + if (Badging == NULL) { >> + return Status; >> + } else { >> + continue; >> + } >> + } >> + >> + // >> + // Calculate the display position according to Attribute. >> + // >> + switch (Attribute) { >> + case EfiBadgingDisplayAttributeLeftTop: >> + DestX = CoordinateX; >> + DestY = CoordinateY; >> + break; >> + >> + case EfiBadgingDisplayAttributeCenterTop: >> + DestX = (SizeOfX - Width) / 2; >> + DestY = CoordinateY; >> + break; >> + >> + case EfiBadgingDisplayAttributeRightTop: >> + DestX = (SizeOfX - Width - CoordinateX); >> + DestY = CoordinateY;; >> + break; >> + >> + case EfiBadgingDisplayAttributeCenterRight: >> + DestX = (SizeOfX - Width - CoordinateX); >> + DestY = (SizeOfY - Height) / 2; >> + break; >> + >> + case EfiBadgingDisplayAttributeRightBottom: >> + DestX = (SizeOfX - Width - CoordinateX); >> + DestY = (SizeOfY - Height - CoordinateY); >> + break; >> + >> + case EfiBadgingDisplayAttributeCenterBottom: >> + DestX = (SizeOfX - Width) / 2; >> + DestY = (SizeOfY - Height - CoordinateY); >> + break; >> + >> + case EfiBadgingDisplayAttributeLeftBottom: >> + DestX = CoordinateX; >> + DestY = (SizeOfY - Height - CoordinateY); >> + break; >> + >> + case EfiBadgingDisplayAttributeCenterLeft: >> + DestX = CoordinateX; >> + DestY = (SizeOfY - Height) / 2; >> + break; >> + >> + case EfiBadgingDisplayAttributeCenter: >> + DestX = (SizeOfX - Width) / 2; >> + DestY = (SizeOfY - Height) / 2; >> + break; >> + >> + case EfiBadgingDisplayAttributeCustomized: >> + DestX = (SizeOfX - Width) / 2; >> + DestY = ((SizeOfY * 382) / 1000) - Height / 2; >> + break; >> + >> + default: >> + DestX = CoordinateX; >> + DestY = CoordinateY; >> + break; >> + } >> + >> + if ((DestX >= 0) && (DestY >= 0)) { >> + if (GraphicsOutput != NULL) { >> + Status = GraphicsOutput->Blt ( >> + GraphicsOutput, >> + Blt, >> + EfiBltBufferToVideo, >> + 0, >> + 0, >> + (UINTN) DestX, >> + (UINTN) DestY, >> + Width, >> + Height, >> + Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) >> + ); >> + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { >> + Status = UgaDraw->Blt ( >> + UgaDraw, >> + (EFI_UGA_PIXEL *) Blt, >> + EfiUgaBltBufferToVideo, >> + 0, >> + 0, >> + (UINTN) DestX, >> + (UINTN) DestY, >> + Width, >> + Height, >> + Width * sizeof (EFI_UGA_PIXEL) >> + ); >> + } else { >> + Status = EFI_UNSUPPORTED; >> + } >> + >> + // >> + // Report displayed Logo information. >> + // >> + if (!EFI_ERROR (Status)) { >> + NumberOfLogos++; >> + >> + if (LogoWidth == 0) { >> + // >> + // The first Logo. >> + // >> + LogoDestX = (UINTN) DestX; >> + LogoDestY = (UINTN) DestY; >> + LogoWidth = Width; >> + LogoHeight = Height; >> + } else { >> + // >> + // Merge new logo with old one. >> + // >> + NewDestX = MIN ((UINTN) DestX, LogoDestX); >> + NewDestY = MIN ((UINTN) DestY, LogoDestY); >> + NewWidth = MAX ((UINTN) DestX + Width, LogoDestX + LogoWidth) - NewDestX; >> + NewHeight = MAX ((UINTN) DestY + Height, LogoDestY + LogoHeight) - NewDestY; >> + >> + LogoDestX = NewDestX; >> + LogoDestY = NewDestY; >> + LogoWidth = NewWidth; >> + LogoHeight = NewHeight; >> + } >> + } >> + } >> + >> + FreePool (ImageData); >> + >> + if (Badging == NULL) { >> + break; >> + } >> + } >> + >> +Done: >> + if (BootLogo == NULL || NumberOfLogos == 0) { >> + // >> + // No logo displayed. >> + // >> + if (Blt != NULL) { >> + FreePool (Blt); >> + } >> + >> + return Status; >> + } >> + >> + // >> + // Advertise displayed Logo information. >> + // >> + if (NumberOfLogos == 1) { >> + // >> + // Only one logo displayed, use its Blt buffer directly for BootLogo protocol. >> + // >> + LogoBlt = Blt; >> + Status = EFI_SUCCESS; >> + } else { >> + // >> + // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation. >> + // >> + if (Blt != NULL) { >> + FreePool (Blt); >> + } >> + >> + // >> + // Ensure the LogoHeight * LogoWidth doesn't overflow >> + // >> + if (LogoHeight > DivU64x64Remainder ((UINTN) ~0, LogoWidth, NULL)) { >> + return EFI_UNSUPPORTED; >> + } >> + BufferSize = MultU64x64 (LogoWidth, LogoHeight); >> + >> + // >> + // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow >> + // >> + if (BufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { >> + return EFI_UNSUPPORTED; >> + } >> + >> + LogoBlt = AllocateZeroPool ((UINTN)BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); >> + if (LogoBlt == NULL) { >> + return EFI_OUT_OF_RESOURCES; >> + } >> + >> + if (GraphicsOutput != NULL) { >> + Status = GraphicsOutput->Blt ( >> + GraphicsOutput, >> + LogoBlt, >> + EfiBltVideoToBltBuffer, >> + LogoDestX, >> + LogoDestY, >> + 0, >> + 0, >> + LogoWidth, >> + LogoHeight, >> + LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) >> + ); >> + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { >> + Status = UgaDraw->Blt ( >> + UgaDraw, >> + (EFI_UGA_PIXEL *) LogoBlt, >> + EfiUgaVideoToBltBuffer, >> + LogoDestX, >> + LogoDestY, >> + 0, >> + 0, >> + LogoWidth, >> + LogoHeight, >> + LogoWidth * sizeof (EFI_UGA_PIXEL) >> + ); >> + } else { >> + Status = EFI_UNSUPPORTED; >> + } >> + } >> + >> + if (!EFI_ERROR (Status)) { >> + BootLogo->SetBootLogo (BootLogo, LogoBlt, LogoDestX, LogoDestY, LogoWidth, LogoHeight); >> + } >> + FreePool (LogoBlt); >> + >> + return Status; >> +} >> + >> +/** >> + Use SystemTable Conout to turn on video based Simple Text Out consoles. The >> + Simple Text Out screens will now be synced up with all non video output devices >> + >> + @retval EFI_SUCCESS UGA devices are back in text mode and synced up. >> + >> +**/ >> +EFI_STATUS >> +DisableQuietBoot ( >> + VOID >> + ) >> +{ >> + >> + // >> + // Enable Cursor on Screen >> + // >> + gST->ConOut->EnableCursor (gST->ConOut, TRUE); >> + return EFI_SUCCESS; >> +} >> + >> -- >> 1.9.1 >> > > . > -- Best Regards, Ming _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
diff --git a/Platform/Hisilicon/D03/D03.dsc b/Platform/Hisilicon/D03/D03.dsc index b434f68..f7efff5 100644 --- a/Platform/Hisilicon/D03/D03.dsc +++ b/Platform/Hisilicon/D03/D03.dsc @@ -28,6 +28,7 @@ BUILD_TARGETS = DEBUG|RELEASE SKUID_IDENTIFIER = DEFAULT FLASH_DEFINITION = Platform/Hisilicon/$(PLATFORM_NAME)/$(PLATFORM_NAME).fdf + DEFINE GENERIC_BDS = TRUE !include Silicon/Hisilicon/Hisilicon.dsc.inc @@ -68,6 +69,14 @@ CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf PlatformBdsLib|Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf +!if $(GENERIC_BDS) == TRUE + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + PlatformBootManagerLib|Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf +!endif CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf # USB Requirements @@ -188,6 +197,9 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } +!if $(GENERIC_BDS) == TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }|VOID*|0x0001006b +!endif gHisiTokenSpaceGuid.PcdSysControlBaseAddress|0x40010000 gHisiTokenSpaceGuid.PcdMailBoxAddress|0x0000FFF8 @@ -405,6 +417,14 @@ MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf +!if $(GENERIC_BDS) == TRUE + MdeModulePkg/Application/UiApp/UiApp.inf { + <LibraryClasses> + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf + } +!endif MdeModulePkg/Application/HelloWorld/HelloWorld.inf # # Bds @@ -457,7 +477,11 @@ MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf +!if $(GENERIC_BDS) == TRUE + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +!else IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf +!endif # # UEFI application (Shell Embedded Boot Loader) diff --git a/Platform/Hisilicon/D03/D03.fdf b/Platform/Hisilicon/D03/D03.fdf index 0b38eb4..0d704b5 100644 --- a/Platform/Hisilicon/D03/D03.fdf +++ b/Platform/Hisilicon/D03/D03.fdf @@ -283,6 +283,9 @@ READ_LOCK_STATUS = TRUE INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf !endif #$(INCLUDE_TFTP_COMMAND) +!if $(GENERIC_BDS) == TRUE + INF MdeModulePkg/Application/UiApp/UiApp.inf +!endif # # Bds # @@ -291,7 +294,11 @@ READ_LOCK_STATUS = TRUE INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf +!if $(GENERIC_BDS) == TRUE + INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +!else INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf +!endif [FV.FVMAIN_COMPACT] FvAlignment = 16 diff --git a/Platform/Hisilicon/D05/D05.dsc b/Platform/Hisilicon/D05/D05.dsc index 710339c..57370dc 100644 --- a/Platform/Hisilicon/D05/D05.dsc +++ b/Platform/Hisilicon/D05/D05.dsc @@ -31,7 +31,7 @@ DEFINE EDK2_SKIP_PEICORE=0 DEFINE NETWORK_IP6_ENABLE = FALSE DEFINE HTTP_BOOT_ENABLE = FALSE - + DEFINE GENERIC_BDS = TRUE !include Silicon/Hisilicon/Hisilicon.dsc.inc [LibraryClasses.common] @@ -84,6 +84,14 @@ CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf PlatformBdsLib|Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf +!if $(GENERIC_BDS) == TRUE + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + PlatformBootManagerLib|Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf +!endif CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf # USB Requirements @@ -119,6 +127,7 @@ # It could be set FALSE to save size. gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE gHisiTokenSpaceGuid.PcdIsItsSupported|TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdHiiOsRuntimeSupport|FALSE [PcdsFixedAtBuild.common] gArmPlatformTokenSpaceGuid.PcdCoreCount|8 @@ -203,7 +212,9 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } - +!if $(GENERIC_BDS) == TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }|VOID*|0x0001006b +!endif gHisiTokenSpaceGuid.PcdSysControlBaseAddress|0x40010000 gHisiTokenSpaceGuid.PcdMailBoxAddress|0x0000FFF8 @@ -560,6 +571,14 @@ MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf +!if $(GENERIC_BDS) == TRUE + MdeModulePkg/Application/UiApp/UiApp.inf { + <LibraryClasses> + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf + } +!endif # # Bds # @@ -610,7 +629,11 @@ MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf +!if $(GENERIC_BDS) == TRUE + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +!else IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf +!endif # # UEFI application (Shell Embedded Boot Loader) # diff --git a/Platform/Hisilicon/D05/D05.fdf b/Platform/Hisilicon/D05/D05.fdf index 97de4d2..d209210 100644 --- a/Platform/Hisilicon/D05/D05.fdf +++ b/Platform/Hisilicon/D05/D05.fdf @@ -305,6 +305,9 @@ READ_LOCK_STATUS = TRUE INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf !endif #$(INCLUDE_TFTP_COMMAND) +!if $(GENERIC_BDS) == TRUE + INF MdeModulePkg/Application/UiApp/UiApp.inf +!endif # # Bds # @@ -313,7 +316,11 @@ READ_LOCK_STATUS = TRUE INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf +!if $(GENERIC_BDS) == TRUE + INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +!else INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf +!endif [FV.FVMAIN_COMPACT] FvAlignment = 16 diff --git a/Silicon/Hisilicon/Hisilicon.dsc.inc b/Silicon/Hisilicon/Hisilicon.dsc.inc index cc23673..308064b 100644 --- a/Silicon/Hisilicon/Hisilicon.dsc.inc +++ b/Silicon/Hisilicon/Hisilicon.dsc.inc @@ -263,6 +263,7 @@ gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1 gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0 gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320 + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4 # DEBUG_ASSERT_ENABLED 0x01 # DEBUG_PRINT_ENABLED 0x02 diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c new file mode 100644 index 0000000..5d8d58e --- /dev/null +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c @@ -0,0 +1,588 @@ +/** @file + Implementation for PlatformBootManagerLib library class interfaces. + + Copyright (c) 2018, ARM Ltd. All rights reserved.<BR> + Copyright (c) 2018, Hisilicon Limited. All rights reserved. + Copyright (c) 2018, Linaro Ltd. 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 <IndustryStandard/Pci22.h> +#include <Library/DevicePathLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootManagerLib.h> +#include <Library/UefiLib.h> +#include <Protocol/DevicePath.h> +#include <Protocol/EsrtManagement.h> +#include <Protocol/GenericMemoryTest.h> +#include <Protocol/GraphicsOutput.h> +#include <Protocol/LoadedImage.h> +#include <Protocol/PciIo.h> +#include <Protocol/PciRootBridgeIo.h> +#include <Guid/EventGroup.h> +#include <Guid/TtyTerm.h> + +#include "PlatformBm.h" + +#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) } + + +#pragma pack (1) +typedef struct { + VENDOR_DEVICE_PATH SerialDxe; + UART_DEVICE_PATH Uart; + VENDOR_DEFINED_DEVICE_PATH TermType; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_SERIAL_CONSOLE; +#pragma pack () + +#define SERIAL_DXE_FILE_GUID { \ + 0xD3987D4B, 0x971A, 0x435F, \ + { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \ + } + +EFI_GUID EblAppGuid2 = {0x3CEF354A,0x3B7A,0x4519,{0xAD,0x70,0x72,0xA1,0x34,0x69,0x83,0x11}}; + +STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = { + // + // VENDOR_DEVICE_PATH SerialDxe + // + { + { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) }, + SERIAL_DXE_FILE_GUID + }, + + // + // UART_DEVICE_PATH Uart + // + { + { MESSAGING_DEVICE_PATH, MSG_UART_DP, DP_NODE_LEN (UART_DEVICE_PATH) }, + 0, // Reserved + FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate + FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits + FixedPcdGet8 (PcdUartDefaultParity), // Parity + FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits + }, + + // + // VENDOR_DEFINED_DEVICE_PATH TermType + // + { + { + MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, + DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH) + } + // + // Guid to be filled in dynamically + // + }, + + // + // EFI_DEVICE_PATH_PROTOCOL End + // + { + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, + DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL) + } +}; + + +#pragma pack (1) +typedef struct { + USB_CLASS_DEVICE_PATH Keyboard; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_USB_KEYBOARD; +#pragma pack () + +STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = { + // + // USB_CLASS_DEVICE_PATH Keyboard + // + { + { + MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP, + DP_NODE_LEN (USB_CLASS_DEVICE_PATH) + }, + 0xFFFF, // VendorId: any + 0xFFFF, // ProductId: any + 3, // DeviceClass: HID + 1, // DeviceSubClass: boot + 1 // DeviceProtocol: keyboard + }, + + // + // EFI_DEVICE_PATH_PROTOCOL End + // + { + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, + DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL) + } +}; + + +/** + Check if the handle satisfies a particular condition. + + @param[in] Handle The handle to check. + @param[in] ReportText A caller-allocated string passed in for reporting + purposes. It must never be NULL. + + @retval TRUE The condition is satisfied. + @retval FALSE Otherwise. This includes the case when the condition could not + be fully evaluated due to an error. +**/ +typedef +BOOLEAN +(EFIAPI *FILTER_FUNCTION) ( + IN EFI_HANDLE Handle, + IN CONST CHAR16 *ReportText + ); + + +/** + Process a handle. + + @param[in] Handle The handle to process. + @param[in] ReportText A caller-allocated string passed in for reporting + purposes. It must never be NULL. +**/ +typedef +VOID +(EFIAPI *CALLBACK_FUNCTION) ( + IN EFI_HANDLE Handle, + IN CONST CHAR16 *ReportText + ); + +/** + Locate all handles that carry the specified protocol, filter them with a + callback function, and pass each handle that passes the filter to another + callback. + + @param[in] ProtocolGuid The protocol to look for. + + @param[in] Filter The filter function to pass each handle to. If this + parameter is NULL, then all handles are processed. + + @param[in] Process The callback function to pass each handle to that + clears the filter. +**/ +STATIC +VOID +FilterAndProcess ( + IN EFI_GUID *ProtocolGuid, + IN FILTER_FUNCTION Filter OPTIONAL, + IN CALLBACK_FUNCTION Process + ) +{ + EFI_STATUS Status; + EFI_HANDLE *Handles; + UINTN NoHandles; + UINTN Idx; + + Status = gBS->LocateHandleBuffer (ByProtocol, ProtocolGuid, + NULL /* SearchKey */, &NoHandles, &Handles); + if (EFI_ERROR (Status)) { + // + // This is not an error, just an informative condition. + // + DEBUG ((DEBUG_VERBOSE, "%a: %g: %r\n", __FUNCTION__, ProtocolGuid, + Status)); + return; + } + + ASSERT (NoHandles > 0); + for (Idx = 0; Idx < NoHandles; ++Idx) { + CHAR16 *DevicePathText; + STATIC CHAR16 Fallback[] = L"<device path unavailable>"; + + // + // The ConvertDevicePathToText() function handles NULL input transparently. + // + DevicePathText = ConvertDevicePathToText ( + DevicePathFromHandle (Handles[Idx]), + FALSE, // DisplayOnly + FALSE // AllowShortcuts + ); + if (DevicePathText == NULL) { + DevicePathText = Fallback; + } + + if (Filter == NULL || Filter (Handles[Idx], DevicePathText)) { + Process (Handles[Idx], DevicePathText); + } + + if (DevicePathText != Fallback) { + FreePool (DevicePathText); + } + } + gBS->FreePool (Handles); +} + + +/** + This FILTER_FUNCTION checks if a handle corresponds to a PCI display device. +**/ +STATIC +BOOLEAN +EFIAPI +IsPciDisplay ( + IN EFI_HANDLE Handle, + IN CONST CHAR16 *ReportText + ) +{ + EFI_STATUS Status; + EFI_PCI_IO_PROTOCOL *PciIo; + PCI_TYPE00 Pci; + + Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid, + (VOID**)&PciIo); + if (EFI_ERROR (Status)) { + // + // This is not an error worth reporting. + // + return FALSE; + } + + Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0 /* Offset */, + sizeof Pci / sizeof (UINT32), &Pci); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %s: %r\n", __FUNCTION__, ReportText, Status)); + return FALSE; + } + + return IS_PCI_DISPLAY (&Pci); +} + + +/** + This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking + the matching driver to produce all first-level child handles. +**/ +STATIC +VOID +EFIAPI +Connect ( + IN EFI_HANDLE Handle, + IN CONST CHAR16 *ReportText + ) +{ + EFI_STATUS Status; + + Status = gBS->ConnectController ( + Handle, // ControllerHandle + NULL, // DriverImageHandle + NULL, // RemainingDevicePath -- produce all children + FALSE // Recursive + ); + DEBUG ((EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE, "%a: %s: %r\n", + __FUNCTION__, ReportText, Status)); +} + + +/** + This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the + handle, and adds it to ConOut and ErrOut. +**/ +STATIC +VOID +EFIAPI +AddOutput ( + IN EFI_HANDLE Handle, + IN CONST CHAR16 *ReportText + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + + DevicePath = DevicePathFromHandle (Handle); + if (DevicePath == NULL) { + DEBUG ((DEBUG_ERROR, "%a: %s: handle %p: device path not found\n", + __FUNCTION__, ReportText, Handle)); + return; + } + + Status = EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %s: adding to ConOut: %r\n", __FUNCTION__, + ReportText, Status)); + return; + } + + Status = EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__, + ReportText, Status)); + return; + } + + DEBUG ((DEBUG_VERBOSE, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__, + ReportText)); +} + +STATIC +VOID +PlatformRegisterFvBootOption ( + EFI_GUID *FileGuid, + CHAR16 *Description, + UINT32 Attributes + ) +{ + EFI_STATUS Status; + INTN 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 = DevicePathFromHandle (LoadedImage->DeviceHandle); + ASSERT (DevicePath != NULL); + DevicePath = AppendDevicePathNode ( + DevicePath, + (EFI_DEVICE_PATH_PROTOCOL *) &FileNode + ); + ASSERT (DevicePath != NULL); + + Status = EfiBootManagerInitializeLoadOption ( + &NewOption, + LoadOptionNumberUnassigned, + LoadOptionTypeBoot, + Attributes, + Description, + DevicePath, + NULL, + 0 + ); + ASSERT_EFI_ERROR (Status); + FreePool (DevicePath); + + BootOptions = EfiBootManagerGetLoadOptions ( + &BootOptionCount, LoadOptionTypeBoot + ); + + OptionIndex = EfiBootManagerFindLoadOption ( + &NewOption, BootOptions, BootOptionCount + ); + + if (OptionIndex == -1) { + Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN); + ASSERT_EFI_ERROR (Status); + } + EfiBootManagerFreeLoadOption (&NewOption); + EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); +} + + +STATIC +VOID +PlatformRegisterOptionsAndKeys ( + VOID + ) +{ + EFI_STATUS Status; + EFI_INPUT_KEY Enter; + EFI_INPUT_KEY F2; + EFI_INPUT_KEY Esc; + EFI_BOOT_MANAGER_LOAD_OPTION BootOption; + + // + // Register ENTER as CONTINUE key + // + Enter.ScanCode = SCAN_NULL; + Enter.UnicodeChar = CHAR_CARRIAGE_RETURN; + Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL); + ASSERT_EFI_ERROR (Status); + + // + // Map F2 and ESC to Boot Manager Menu + // + F2.ScanCode = SCAN_F2; + F2.UnicodeChar = CHAR_NULL; + Esc.ScanCode = SCAN_ESC; + Esc.UnicodeChar = CHAR_NULL; + + Status = EfiBootManagerGetBootManagerMenu (&BootOption); + ASSERT_EFI_ERROR (Status); + Status = EfiBootManagerAddKeyOptionVariable ( + NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL + ); + ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED); + Status = EfiBootManagerAddKeyOptionVariable ( + NULL, (UINT16) BootOption.OptionNumber, 0, &Esc, NULL + ); + ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED); +} + +VOID +UpdateMemory ( + ) +{ + EFI_STATUS Status; + EFI_GENERIC_MEMORY_TEST_PROTOCOL* MemoryTest; + BOOLEAN RequireSoftECCInit = FALSE; + + //Add MemoryTest for memmap add above 4G memory. + Status = gBS->LocateProtocol (&gEfiGenericMemTestProtocolGuid, NULL, (VOID**)&MemoryTest); + if (!EFI_ERROR (Status)) { + (VOID)MemoryTest->MemoryTestInit (MemoryTest, IGNORE, &RequireSoftECCInit); + } else { + DEBUG ((DEBUG_ERROR, "LocateProtocol for GenericMemTestProtocol fail(%r)\n", Status)); + } + + return; +} + +// +// BDS Platform Functions +// +/** + Do the platform init, can be customized by OEM/IBV + Possible things that can be done in PlatformBootManagerBeforeConsole: + > Update console variable: 1. include hot-plug devices; + > 2. Clear ConIn and add SOL for AMT + > Register new Driver#### or Boot#### + > Register new Key####: e.g.: F12 + > Signal ReadyToLock event + > Authentication action: 1. connect Auth devices; + > 2. Identify auto logon user. +**/ +VOID +EFIAPI +PlatformBootManagerBeforeConsole ( + VOID + ) +{ + // + // Signal EndOfDxe PI Event + // + EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid); + + UpdateMemory (); + + // + // Locate the PCI root bridges and make the PCI bus driver connect each, + // non-recursively. This will produce a number of child handles with PciIo on + // them. + // + FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid, NULL, Connect); + + // + // Find all display class PCI devices (using the handles from the previous + // step), and connect them non-recursively. This should produce a number of + // child handles with GOPs on them. + // + FilterAndProcess (&gEfiPciIoProtocolGuid, IsPciDisplay, Connect); + + // + // Now add the device path of all handles with GOP on them to ConOut and + // ErrOut. + // + FilterAndProcess (&gEfiGraphicsOutputProtocolGuid, NULL, AddOutput); + + // + // Add the hardcoded short-form USB keyboard device path to ConIn. + // + EfiBootManagerUpdateConsoleVariable (ConIn, + (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL); + + // + // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut. + // + ASSERT (FixedPcdGet8 (PcdDefaultTerminalType) == 4); + CopyGuid (&mSerialConsole.TermType.Guid, &gEfiTtyTermGuid); + + EfiBootManagerUpdateConsoleVariable (ConIn, + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); + EfiBootManagerUpdateConsoleVariable (ConOut, + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); + EfiBootManagerUpdateConsoleVariable (ErrOut, + (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL); + + // + // Register platform-specific boot options and keyboard shortcuts. + // + PlatformRegisterOptionsAndKeys (); +} + +/** + Do the platform specific action after the console is ready + Possible things that can be done in PlatformBootManagerAfterConsole: + > Console post action: + > Dynamically switch output mode from 100x31 to 80x25 for certain senarino + > Signal console ready platform customized event + > Run diagnostics like memory testing + > Connect certain devices + > Dispatch aditional option roms + > Special boot: e.g.: USB boot, enter UI +**/ +VOID +EFIAPI +PlatformBootManagerAfterConsole ( + VOID + ) +{ + EFI_STATUS Status; + ESRT_MANAGEMENT_PROTOCOL *EsrtManagement = NULL; + + // + // Show the splash screen. + // + EnableQuietBoot (PcdGetPtr (PcdLogoFile)); + + // + // Connect the rest of the devices. + // + EfiBootManagerConnectAll (); + + // + // Enumerate all possible boot options. + // + EfiBootManagerRefreshAllBootOption (); + + // + //Sync Esrt Table + // + Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtManagement); + if (!EFI_ERROR (Status)) { + Status = EsrtManagement->SyncEsrtFmp (); + } + + // + // Register UEFI Shell + // + PlatformRegisterFvBootOption ( + PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE + ); +} + +/** + This function is called each second during the boot manager waits the + timeout. + + @param TimeoutRemain The remaining timeout. +**/ +VOID +EFIAPI +PlatformBootManagerWaitCallback ( + UINT16 TimeoutRemain + ) +{ + Print(L"\r%-2d seconds left, Press Esc or F2 to enter Setup.", TimeoutRemain); +} diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h new file mode 100644 index 0000000..0a3c626 --- /dev/null +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.h @@ -0,0 +1,59 @@ +/** @file + Head file for BDS Platform specific code + + Copyright (C) 2015-2016, Red Hat, Inc. + Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2016, Linaro Ltd. 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. + +**/ + +#ifndef _PLATFORM_BM_H_ +#define _PLATFORM_BM_H_ + +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/DevicePathLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> + +/** + Use SystemTable Conout to stop video based Simple Text Out consoles from + going to the video device. Put up LogoFile on every video device that is a + console. + + @param[in] LogoFile File name of logo to display on the center of the + screen. + + @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo + displayed. + @retval EFI_UNSUPPORTED Logo not found +**/ +EFI_STATUS +EnableQuietBoot ( + IN EFI_GUID *LogoFile + ); + +/** + Use SystemTable Conout to turn on video based Simple Text Out consoles. The + Simple Text Out screens will now be synced up with all non video output + devices + + @retval EFI_SUCCESS UGA devices are back in text mode and synced up. +**/ +EFI_STATUS +DisableQuietBoot ( + VOID + ); + +#endif // _PLATFORM_BM_H_ diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf new file mode 100644 index 0000000..ae274f3 --- /dev/null +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -0,0 +1,89 @@ +## @file +# Implementation for PlatformBootManagerLib library class interfaces. +# +# Copyright (C) 2015-2016, Red Hat, Inc. +# Copyright (c) 2014, ARM Ltd. All rights reserved.<BR> +# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2016, Linaro Ltd. 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PlatformBootManagerLib + FILE_GUID = 92FD2DE3-B9CB-4B35-8141-42AD34D73C9F + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = PlatformBootManagerLib|DXE_DRIVER + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = ARM AARCH64 +# + +[Sources] + PlatformBm.c + QuietBoot.c + +[Packages] + IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Hisilicon/HisiPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + DevicePathLib + DxeServicesLib + MemoryAllocationLib + PcdLib + PrintLib + UefiBootManagerLib + UefiBootServicesTableLib + UefiLib + +[FeaturePcd] + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable + gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport + +[FixedPcd] + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType + +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut + +[Guids] + gEfiFileInfoGuid + gEfiFileSystemInfoGuid + gEfiFileSystemVolumeLabelInfoIdGuid + gEfiEndOfDxeEventGroupGuid + gEfiTtyTermGuid + +[Protocols] + gEfiDevicePathProtocolGuid + gEfiFirmwareVolume2ProtocolGuid + gEfiGenericMemTestProtocolGuid + gEfiGraphicsOutputProtocolGuid + gEfiLoadedImageProtocolGuid + gEfiOEMBadgingProtocolGuid + gEfiPciRootBridgeIoProtocolGuid + gEfiSimpleFileSystemProtocolGuid + gEsrtManagementProtocolGuid diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c b/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c new file mode 100644 index 0000000..0bd15da --- /dev/null +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/QuietBoot.c @@ -0,0 +1,681 @@ +/** @file +Platform BDS function for quiet boot support. + +Copyright (c) 2018, ARM Ltd. All rights reserved.<BR> +Copyright (c) 2018, Hisilicon Limited. All rights reserved. +Copyright (c) 2018, Linaro Ltd. 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 <IndustryStandard/Bmp.h> +#include <Library/DxeServicesLib.h> +#include <Protocol/BootLogo.h> +#include <Protocol/OEMBadging.h> +#include <Protocol/UgaDraw.h> + +#include "PlatformBm.h" + +/** + Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer + is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt + buffer is passed in it will be used if it is big enough. + + @param BmpImage Pointer to BMP file + @param BmpImageSize Number of bytes in BmpImage + @param GopBlt Buffer containing GOP version of BmpImage. + @param GopBltSize Size of GopBlt in bytes. + @param PixelHeight Height of GopBlt/BmpImage in pixels + @param PixelWidth Width of GopBlt/BmpImage in pixels + + @retval EFI_SUCCESS GopBlt and GopBltSize are returned. + @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image + @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough. + GopBltSize will contain the required size. + @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate. + +**/ +STATIC +EFI_STATUS +ConvertBmpToGopBlt ( + IN VOID *BmpImage, + IN UINTN BmpImageSize, + IN OUT VOID **GopBlt, + IN OUT UINTN *GopBltSize, + OUT UINTN *PixelHeight, + OUT UINTN *PixelWidth + ) +{ + UINT8 *Image; + UINT8 *ImageHeader; + BMP_IMAGE_HEADER *BmpHeader; + BMP_COLOR_MAP *BmpColorMap; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; + UINT64 BltBufferSize; + UINTN Index; + UINTN Height; + UINTN Width; + UINTN ImageIndex; + UINT32 DataSizePerLine; + BOOLEAN IsAllocated; + UINT32 ColorMapNum; + + if (sizeof (BMP_IMAGE_HEADER) > BmpImageSize) { + return EFI_INVALID_PARAMETER; + } + + BmpHeader = (BMP_IMAGE_HEADER *) BmpImage; + + if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') { + return EFI_UNSUPPORTED; + } + + // + // Doesn't support compress. + // + if (BmpHeader->CompressionType != 0) { + return EFI_UNSUPPORTED; + } + + // + // Only support BITMAPINFOHEADER format. + // BITMAPFILEHEADER + BITMAPINFOHEADER = BMP_IMAGE_HEADER + // + if (BmpHeader->HeaderSize != sizeof (BMP_IMAGE_HEADER) - OFFSET_OF(BMP_IMAGE_HEADER, HeaderSize)) { + return EFI_UNSUPPORTED; + } + + // + // The data size in each line must be 4 byte alignment. + // + DataSizePerLine = ((BmpHeader->PixelWidth * BmpHeader->BitPerPixel + 31) >> 3) & (~0x3); + BltBufferSize = MultU64x32 (DataSizePerLine, BmpHeader->PixelHeight); + if (BltBufferSize > (UINT32) ~0) { + return EFI_INVALID_PARAMETER; + } + + if ((BmpHeader->Size != BmpImageSize) || + (BmpHeader->Size < BmpHeader->ImageOffset) || + (BmpHeader->Size - BmpHeader->ImageOffset != BmpHeader->PixelHeight * DataSizePerLine)) { + return EFI_INVALID_PARAMETER; + } + + // + // Calculate Color Map offset in the image. + // + Image = BmpImage; + BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER)); + if (BmpHeader->ImageOffset < sizeof (BMP_IMAGE_HEADER)) { + return EFI_INVALID_PARAMETER; + } + + if (BmpHeader->ImageOffset > sizeof (BMP_IMAGE_HEADER)) { + switch (BmpHeader->BitPerPixel) { + case 1: + ColorMapNum = 2; + break; + case 4: + ColorMapNum = 16; + break; + case 8: + ColorMapNum = 256; + break; + default: + ColorMapNum = 0; + break; + } + // + // BMP file may has padding data between the bmp header section and the bmp data section. + // + if (BmpHeader->ImageOffset - sizeof (BMP_IMAGE_HEADER) < sizeof (BMP_COLOR_MAP) * ColorMapNum) { + return EFI_INVALID_PARAMETER; + } + } + + // + // Calculate graphics image data address in the image + // + Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset; + ImageHeader = Image; + + // + // Calculate the BltBuffer needed size. + // + BltBufferSize = MultU64x32 ((UINT64) BmpHeader->PixelWidth, BmpHeader->PixelHeight); + // + // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow + // + if (BltBufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { + return EFI_UNSUPPORTED; + } + BltBufferSize = MultU64x32 (BltBufferSize, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); + + IsAllocated = FALSE; + if (*GopBlt == NULL) { + // + // GopBlt is not allocated by caller. + // + *GopBltSize = (UINTN) BltBufferSize; + *GopBlt = AllocatePool (*GopBltSize); + IsAllocated = TRUE; + if (*GopBlt == NULL) { + return EFI_OUT_OF_RESOURCES; + } + } else { + // + // GopBlt has been allocated by caller. + // + if (*GopBltSize < (UINTN) BltBufferSize) { + *GopBltSize = (UINTN) BltBufferSize; + return EFI_BUFFER_TOO_SMALL; + } + } + + *PixelWidth = BmpHeader->PixelWidth; + *PixelHeight = BmpHeader->PixelHeight; + + // + // Convert image from BMP to Blt buffer format + // + BltBuffer = *GopBlt; + for (Height = 0; Height < BmpHeader->PixelHeight; Height++) { + Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth]; + for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) { + switch (BmpHeader->BitPerPixel) { + case 1: + // + // Convert 1-bit (2 colors) BMP to 24-bit color + // + for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) { + Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red; + Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green; + Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue; + Blt++; + Width++; + } + + Blt--; + Width--; + break; + + case 4: + // + // Convert 4-bit (16 colors) BMP Palette to 24-bit color + // + Index = (*Image) >> 4; + Blt->Red = BmpColorMap[Index].Red; + Blt->Green = BmpColorMap[Index].Green; + Blt->Blue = BmpColorMap[Index].Blue; + if (Width < (BmpHeader->PixelWidth - 1)) { + Blt++; + Width++; + Index = (*Image) & 0x0f; + Blt->Red = BmpColorMap[Index].Red; + Blt->Green = BmpColorMap[Index].Green; + Blt->Blue = BmpColorMap[Index].Blue; + } + break; + + case 8: + // + // Convert 8-bit (256 colors) BMP Palette to 24-bit color + // + Blt->Red = BmpColorMap[*Image].Red; + Blt->Green = BmpColorMap[*Image].Green; + Blt->Blue = BmpColorMap[*Image].Blue; + break; + + case 24: + // + // It is 24-bit BMP. + // + Blt->Blue = *Image++; + Blt->Green = *Image++; + Blt->Red = *Image; + break; + + default: + // + // Other bit format BMP is not supported. + // + if (IsAllocated) { + FreePool (*GopBlt); + *GopBlt = NULL; + } + return EFI_UNSUPPORTED; + }; + + } + + ImageIndex = (UINTN) (Image - ImageHeader); + if ((ImageIndex % 4) != 0) { + // + // Bmp Image starts each row on a 32-bit boundary! + // + Image = Image + (4 - (ImageIndex % 4)); + } + } + + return EFI_SUCCESS; +} + +/** + Use SystemTable Conout to stop video based Simple Text Out consoles from going + to the video device. Put up LogoFile on every video device that is a console. + + @param[in] LogoFile File name of logo to display on the center of the screen. + + @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed. + @retval EFI_UNSUPPORTED Logo not found + +**/ +EFI_STATUS +EnableQuietBoot ( + IN EFI_GUID *LogoFile + ) +{ + EFI_STATUS Status; + EFI_OEM_BADGING_PROTOCOL *Badging; + UINT32 SizeOfX; + UINT32 SizeOfY; + INTN DestX; + INTN DestY; + UINT8 *ImageData; + UINTN ImageSize; + UINTN BltSize; + UINT32 Instance; + EFI_BADGING_FORMAT Format; + EFI_BADGING_DISPLAY_ATTRIBUTE Attribute; + UINTN CoordinateX; + UINTN CoordinateY; + UINTN Height; + UINTN Width; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; + EFI_UGA_DRAW_PROTOCOL *UgaDraw; + UINT32 ColorDepth; + UINT32 RefreshRate; + EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; + EFI_BOOT_LOGO_PROTOCOL *BootLogo; + UINTN NumberOfLogos; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LogoBlt; + UINTN LogoDestX; + UINTN LogoDestY; + UINTN LogoHeight; + UINTN LogoWidth; + UINTN NewDestX; + UINTN NewDestY; + UINTN NewHeight; + UINTN NewWidth; + UINT64 BufferSize; + + UgaDraw = NULL; + // + // Try to open GOP first + // + Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput); + if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) { + GraphicsOutput = NULL; + // + // Open GOP failed, try to open UGA + // + Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw); + } + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + // + // Try to open Boot Logo Protocol. + // + BootLogo = NULL; + gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo); + + // + // Erase Cursor from screen + // + gST->ConOut->EnableCursor (gST->ConOut, FALSE); + + Badging = NULL; + Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging); + + if (GraphicsOutput != NULL) { + SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution; + SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution; + + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { + Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + } else { + return EFI_UNSUPPORTED; + } + + Blt = NULL; + NumberOfLogos = 0; + LogoDestX = 0; + LogoDestY = 0; + LogoHeight = 0; + LogoWidth = 0; + NewDestX = 0; + NewDestY = 0; + NewHeight = 0; + NewWidth = 0; + Instance = 0; + Height = 0; + Width = 0; + while (1) { + ImageData = NULL; + ImageSize = 0; + + if (Badging != NULL) { + // + // Get image from OEMBadging protocol. + // + Status = Badging->GetImage ( + Badging, + &Instance, + &Format, + &ImageData, + &ImageSize, + &Attribute, + &CoordinateX, + &CoordinateY + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + // + // Currently only support BMP format. + // + if (Format != EfiBadgingFormatBMP) { + if (ImageData != NULL) { + FreePool (ImageData); + } + continue; + } + } else { + // + // Get the specified image from FV. + // + Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + CoordinateX = 0; + CoordinateY = 0; + if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) { + Attribute = EfiBadgingDisplayAttributeCenter; + } else { + Attribute = EfiBadgingDisplayAttributeCustomized; + } + } + + if (Blt != NULL) { + FreePool (Blt); + } + Blt = NULL; + Status = ConvertBmpToGopBlt ( + ImageData, + ImageSize, + (VOID **) &Blt, + &BltSize, + &Height, + &Width + ); + if (EFI_ERROR (Status)) { + FreePool (ImageData); + + if (Badging == NULL) { + return Status; + } else { + continue; + } + } + + // + // Calculate the display position according to Attribute. + // + switch (Attribute) { + case EfiBadgingDisplayAttributeLeftTop: + DestX = CoordinateX; + DestY = CoordinateY; + break; + + case EfiBadgingDisplayAttributeCenterTop: + DestX = (SizeOfX - Width) / 2; + DestY = CoordinateY; + break; + + case EfiBadgingDisplayAttributeRightTop: + DestX = (SizeOfX - Width - CoordinateX); + DestY = CoordinateY;; + break; + + case EfiBadgingDisplayAttributeCenterRight: + DestX = (SizeOfX - Width - CoordinateX); + DestY = (SizeOfY - Height) / 2; + break; + + case EfiBadgingDisplayAttributeRightBottom: + DestX = (SizeOfX - Width - CoordinateX); + DestY = (SizeOfY - Height - CoordinateY); + break; + + case EfiBadgingDisplayAttributeCenterBottom: + DestX = (SizeOfX - Width) / 2; + DestY = (SizeOfY - Height - CoordinateY); + break; + + case EfiBadgingDisplayAttributeLeftBottom: + DestX = CoordinateX; + DestY = (SizeOfY - Height - CoordinateY); + break; + + case EfiBadgingDisplayAttributeCenterLeft: + DestX = CoordinateX; + DestY = (SizeOfY - Height) / 2; + break; + + case EfiBadgingDisplayAttributeCenter: + DestX = (SizeOfX - Width) / 2; + DestY = (SizeOfY - Height) / 2; + break; + + case EfiBadgingDisplayAttributeCustomized: + DestX = (SizeOfX - Width) / 2; + DestY = ((SizeOfY * 382) / 1000) - Height / 2; + break; + + default: + DestX = CoordinateX; + DestY = CoordinateY; + break; + } + + if ((DestX >= 0) && (DestY >= 0)) { + if (GraphicsOutput != NULL) { + Status = GraphicsOutput->Blt ( + GraphicsOutput, + Blt, + EfiBltBufferToVideo, + 0, + 0, + (UINTN) DestX, + (UINTN) DestY, + Width, + Height, + Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) + ); + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { + Status = UgaDraw->Blt ( + UgaDraw, + (EFI_UGA_PIXEL *) Blt, + EfiUgaBltBufferToVideo, + 0, + 0, + (UINTN) DestX, + (UINTN) DestY, + Width, + Height, + Width * sizeof (EFI_UGA_PIXEL) + ); + } else { + Status = EFI_UNSUPPORTED; + } + + // + // Report displayed Logo information. + // + if (!EFI_ERROR (Status)) { + NumberOfLogos++; + + if (LogoWidth == 0) { + // + // The first Logo. + // + LogoDestX = (UINTN) DestX; + LogoDestY = (UINTN) DestY; + LogoWidth = Width; + LogoHeight = Height; + } else { + // + // Merge new logo with old one. + // + NewDestX = MIN ((UINTN) DestX, LogoDestX); + NewDestY = MIN ((UINTN) DestY, LogoDestY); + NewWidth = MAX ((UINTN) DestX + Width, LogoDestX + LogoWidth) - NewDestX; + NewHeight = MAX ((UINTN) DestY + Height, LogoDestY + LogoHeight) - NewDestY; + + LogoDestX = NewDestX; + LogoDestY = NewDestY; + LogoWidth = NewWidth; + LogoHeight = NewHeight; + } + } + } + + FreePool (ImageData); + + if (Badging == NULL) { + break; + } + } + +Done: + if (BootLogo == NULL || NumberOfLogos == 0) { + // + // No logo displayed. + // + if (Blt != NULL) { + FreePool (Blt); + } + + return Status; + } + + // + // Advertise displayed Logo information. + // + if (NumberOfLogos == 1) { + // + // Only one logo displayed, use its Blt buffer directly for BootLogo protocol. + // + LogoBlt = Blt; + Status = EFI_SUCCESS; + } else { + // + // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation. + // + if (Blt != NULL) { + FreePool (Blt); + } + + // + // Ensure the LogoHeight * LogoWidth doesn't overflow + // + if (LogoHeight > DivU64x64Remainder ((UINTN) ~0, LogoWidth, NULL)) { + return EFI_UNSUPPORTED; + } + BufferSize = MultU64x64 (LogoWidth, LogoHeight); + + // + // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow + // + if (BufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { + return EFI_UNSUPPORTED; + } + + LogoBlt = AllocateZeroPool ((UINTN)BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); + if (LogoBlt == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + if (GraphicsOutput != NULL) { + Status = GraphicsOutput->Blt ( + GraphicsOutput, + LogoBlt, + EfiBltVideoToBltBuffer, + LogoDestX, + LogoDestY, + 0, + 0, + LogoWidth, + LogoHeight, + LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) + ); + } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) { + Status = UgaDraw->Blt ( + UgaDraw, + (EFI_UGA_PIXEL *) LogoBlt, + EfiUgaVideoToBltBuffer, + LogoDestX, + LogoDestY, + 0, + 0, + LogoWidth, + LogoHeight, + LogoWidth * sizeof (EFI_UGA_PIXEL) + ); + } else { + Status = EFI_UNSUPPORTED; + } + } + + if (!EFI_ERROR (Status)) { + BootLogo->SetBootLogo (BootLogo, LogoBlt, LogoDestX, LogoDestY, LogoWidth, LogoHeight); + } + FreePool (LogoBlt); + + return Status; +} + +/** + Use SystemTable Conout to turn on video based Simple Text Out consoles. The + Simple Text Out screens will now be synced up with all non video output devices + + @retval EFI_SUCCESS UGA devices are back in text mode and synced up. + +**/ +EFI_STATUS +DisableQuietBoot ( + VOID + ) +{ + + // + // Enable Cursor on Screen + // + gST->ConOut->EnableCursor (gST->ConOut, TRUE); + return EFI_SUCCESS; +} +