From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4001:c0b::241; helo=mail-it0-x241.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-it0-x241.google.com (mail-it0-x241.google.com [IPv6:2607:f8b0:4001:c0b::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CA90B22344333 for ; Sat, 20 Jan 2018 02:35:39 -0800 (PST) Received: by mail-it0-x241.google.com with SMTP id c16so4884762itc.5 for ; Sat, 20 Jan 2018 02:41:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=NcPhZfRgG6Y4QqxswIVLwpcFKJnJpPCnr3i5C4+iSI0=; b=b0hy1EPAFeMEPZI204AfumMpO3yerIQ64DeI1j1bD36R1Sj9yNkrAjiq2LQ/azXEkl v6EEzOSL1t2rXqCtisjjI+8xotJ97IX09k6v30Ipz9QMBDsbdb8weQjlx161jzSPk6Mx b3DDO1viv1KMPp/cK+hfxAVno+BcS6emloKjw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=NcPhZfRgG6Y4QqxswIVLwpcFKJnJpPCnr3i5C4+iSI0=; b=rZVAIMuakE88RP53JmUV89BHh1AmofZFeOrqZlm21eeLWvsN+kYCOPmVW9UjVE2K3z dyc2LHogJNTUXuOD6dRwJPZYDNvSWgfgLvgU2z78DRhNBDM0tPQIrjpiq/Z7rJas0B6c +tP83lQZeFXcnTRpzDwJ8XHSIPWRWUE8+t5UuWR6GarGAIIIksM7R3Gv53s725oT4KhM s7xENgd71HQFeRR5pfmt9iNJ4cFgvHs3n6xdJbKe2ocQb7Kp0n8IENNopiJPcc+G4w2R W1IALplzNxDFUdfv29bsJj4SnveSEm3YqX36qY8G+576etIjB8EoYUGqhMz54UbpExi+ j6bA== X-Gm-Message-State: AKwxytd6aWltNct456qGDhv+ZCCLpntKrDBvtT9iwD3cGGtAkfhew2cG XMK+kNXbruJDvZ6gsBNuwHbWs7n3oiXzv8NrMxOHeg== X-Google-Smtp-Source: AH8x226vWkmAzBXqMaHw7BfU7aW5/C+tYgVvfp+1i+yhJSay9UnKhkuaN7rTywqBPv+NqjVBApPhI2wTtvzhWzgXSvU= X-Received: by 10.36.128.5 with SMTP id g5mr1223091itd.17.1516444862358; Sat, 20 Jan 2018 02:41:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.112.13 with HTTP; Sat, 20 Jan 2018 02:41:01 -0800 (PST) In-Reply-To: <1516287703-35516-4-git-send-email-huangming23@huawei.com> References: <1516287703-35516-1-git-send-email-huangming23@huawei.com> <1516287703-35516-4-git-send-email-huangming23@huawei.com> From: Ard Biesheuvel Date: Sat, 20 Jan 2018 10:41:01 +0000 Message-ID: To: Ming Huang Cc: Leif Lindholm , linaro-uefi , "edk2-devel@lists.01.org" , Graeme Gregory , guoheyi@huawei.com, wanghuiqiang , huangming , Jason Zhang , Mengfanrong , waip23@126.com Subject: Re: [PATCH edk2-platforms v1 03/14] Hisilicon D03/D05: Optimize the feature of BMC set boot option X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jan 2018 10:35:40 -0000 Content-Type: text/plain; charset="UTF-8" On 18 January 2018 at 15:01, Ming Huang wrote: > Modify the feature of BMC set boot option as switching generic > BDS. Move main functions to BmcConfigBootLib. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ming Huang > Signed-off-by: Heyi Guo > --- > Platform/Hisilicon/D03/D03.dsc | 1 + > Platform/Hisilicon/D05/D05.dsc | 1 + > Silicon/Hisilicon/Include/Library/BmcConfigBootLib.h | 31 ++ > Silicon/Hisilicon/Library/BmcConfigBootLib/BmcConfigBootLib.c | 454 ++++++++++++++++++++ > Silicon/Hisilicon/Library/BmcConfigBootLib/BmcConfigBootLib.inf | 51 +++ > Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c | 7 + > Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 1 + > Silicon/Hisilicon/Library/PlatformIntelBdsLib/IntelBdsPlatform.c | 434 +------------------ > Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf | 4 +- > 9 files changed, 548 insertions(+), 436 deletions(-) > > diff --git a/Platform/Hisilicon/D03/D03.dsc b/Platform/Hisilicon/D03/D03.dsc > index f7efff5..b2eae7d 100644 > --- a/Platform/Hisilicon/D03/D03.dsc > +++ b/Platform/Hisilicon/D03/D03.dsc > @@ -70,6 +70,7 @@ > GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf > PlatformBdsLib|Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf > !if $(GENERIC_BDS) == TRUE > + BmcConfigBootLib|Silicon/Hisilicon/Library/BmcConfigBootLib/BmcConfigBootLib.inf > UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf > SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf > diff --git a/Platform/Hisilicon/D05/D05.dsc b/Platform/Hisilicon/D05/D05.dsc > index 57370dc..b89cea3 100644 > --- a/Platform/Hisilicon/D05/D05.dsc > +++ b/Platform/Hisilicon/D05/D05.dsc > @@ -85,6 +85,7 @@ > GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf > PlatformBdsLib|Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf > !if $(GENERIC_BDS) == TRUE > + BmcConfigBootLib|Silicon/Hisilicon/Library/BmcConfigBootLib/BmcConfigBootLib.inf > UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf > SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf > diff --git a/Silicon/Hisilicon/Include/Library/BmcConfigBootLib.h b/Silicon/Hisilicon/Include/Library/BmcConfigBootLib.h > new file mode 100644 > index 0000000..d937234 > --- /dev/null > +++ b/Silicon/Hisilicon/Include/Library/BmcConfigBootLib.h > @@ -0,0 +1,31 @@ > +/** @file > +* > +* Copyright (c) 2017, Hisilicon Limited. All rights reserved. > +* Copyright (c) 2017, Linaro Limited. All rights reserved. > +* > +* This program and the accompanying materials > +* are licensed and made available under the terms and conditions of the BSD License > +* which accompanies this distribution. The full text of the license may be found at > +* http://opensource.org/licenses/bsd-license.php > +* > +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > +* > +**/ > + > +#ifndef _BMC_CONFIG_BOOT_LIB_H_ > +#define _BMC_CONFIG_BOOT_LIB_H_ > + > +VOID > +EFIAPI > +RestoreBootOrder ( > + VOID > + ); > + > +VOID > +EFIAPI > +HandleBmcBootType ( > + VOID > + ); > + > +#endif > diff --git a/Silicon/Hisilicon/Library/BmcConfigBootLib/BmcConfigBootLib.c b/Silicon/Hisilicon/Library/BmcConfigBootLib/BmcConfigBootLib.c > new file mode 100644 > index 0000000..c446f93 > --- /dev/null > +++ b/Silicon/Hisilicon/Library/BmcConfigBootLib/BmcConfigBootLib.c > @@ -0,0 +1,454 @@ > +/** @file > +* > +* Copyright (c) 2017, Hisilicon Limited. All rights reserved. > +* Copyright (c) 2017, Linaro Limited. All rights reserved. > +* > +* This program and the accompanying materials > +* are licensed and made available under the terms and conditions of the BSD License > +* which accompanies this distribution. The full text of the license may be found at > +* http://opensource.org/licenses/bsd-license.php > +* > +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > +* > +**/ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +GUID gOemBootVariableGuid = {0xb7784577, 0x5aaf, 0x4557, {0xa1, 0x99, > + 0xd4, 0xa4, 0x2f, 0x45, 0x06, 0xf8} }; > + I know you are just moving this around, but this should be defined in HisiPkg.dec not here > +STATIC > +UINT16 > +GetBBSTypeFromFileSysPath ( > + IN CHAR16 *UsbPathTxt, > + IN CHAR16 *FileSysPathTxt, > + IN EFI_DEVICE_PATH_PROTOCOL *FileSysPath > + ) > +{ > + EFI_DEVICE_PATH_PROTOCOL *Node; > + > + if (StrnCmp (UsbPathTxt, FileSysPathTxt, StrLen (UsbPathTxt)) == 0) { > + Node = FileSysPath; > + while (!IsDevicePathEnd (Node)) { > + if ((DevicePathType (Node) == MEDIA_DEVICE_PATH) && > + (DevicePathSubType (Node) == MEDIA_CDROM_DP)) { > + return BBS_TYPE_CDROM; > + } > + Node = NextDevicePathNode (Node); > + } > + } > + > + return BBS_TYPE_UNKNOWN; > +} > + > +STATIC > +UINT16 > +GetBBSTypeFromUsbPath ( > + IN CONST EFI_DEVICE_PATH_PROTOCOL *UsbPath > + ) > +{ > + EFI_STATUS Status; > + EFI_HANDLE *FileSystemHandles; > + UINTN NumberFileSystemHandles; > + UINTN Index; > + EFI_DEVICE_PATH_PROTOCOL *FileSysPath; > + EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText; > + CHAR16 *UsbPathTxt; > + CHAR16 *FileSysPathTxt; > + UINT16 Result; > + > + Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **) &DevPathToText); line length Also, if it is an error for gEfiDevicePathToTextProtocolGuid to be unavailable, you can add it to your DEPEX instead and just use ASSERT_EFI_ERROR() here > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Locate DevicePathToTextPro %r\n", Status)); > + return BBS_TYPE_UNKNOWN; > + } > + > + Result = BBS_TYPE_UNKNOWN; > + UsbPathTxt = DevPathToText->ConvertDevicePathToText (UsbPath, TRUE, TRUE); > + if (UsbPathTxt == NULL) { > + return Result; > + } > + > + Status = gBS->LocateHandleBuffer ( > + ByProtocol, > + &gEfiSimpleFileSystemProtocolGuid, > + NULL, > + &NumberFileSystemHandles, > + &FileSystemHandles > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Locate SimpleFileSystemProtocol error(%r)\n", Status)); > + FreePool (UsbPathTxt); > + return BBS_TYPE_UNKNOWN; > + } > + > + for (Index = 0; Index < NumberFileSystemHandles; Index++) { > + FileSysPath = DevicePathFromHandle (FileSystemHandles[Index]); > + FileSysPathTxt = DevPathToText->ConvertDevicePathToText (FileSysPath, TRUE, TRUE); > + > + if (FileSysPathTxt == NULL) { > + continue; > + } > + > + Result = GetBBSTypeFromFileSysPath (UsbPathTxt, FileSysPathTxt, FileSysPath); > + FreePool (FileSysPathTxt); > + > + if (Result != BBS_TYPE_UNKNOWN) { > + break; > + } > + } > + > + if (NumberFileSystemHandles != 0) { > + FreePool (FileSystemHandles); > + } > + > + FreePool (UsbPathTxt); > + > + return Result; > +} > + > +STATIC > +UINT16 > +GetBBSTypeFromMessagingDevicePath ( > + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, > + IN EFI_DEVICE_PATH_PROTOCOL *Node > + ) > +{ > + VENDOR_DEVICE_PATH *Vendor; > + UINT16 Result; > + > + Result = BBS_TYPE_UNKNOWN; > + > + switch (DevicePathSubType (Node)) { > + case MSG_MAC_ADDR_DP: > + Result = BBS_TYPE_EMBEDDED_NETWORK; > + break; > + > + case MSG_USB_DP: > + Result = GetBBSTypeFromUsbPath (DevicePath); > + if (Result == BBS_TYPE_UNKNOWN) { > + Result = BBS_TYPE_USB; Just one space after = > + } > + break; > + > + case MSG_SATA_DP: > + Result = BBS_TYPE_HARDDRIVE; > + break; > + > + case MSG_VENDOR_DP: > + Vendor = (VENDOR_DEVICE_PATH *) (Node); > + if ((&Vendor->Guid) != NULL) { Remove redundant () > + if (CompareGuid (&Vendor->Guid, &((EFI_GUID) DEVICE_PATH_MESSAGING_SAS))) { > + Result = BBS_TYPE_HARDDRIVE; > + } > + } > + break; > + > + default: > + Result = BBS_TYPE_UNKNOWN; > + break; > + } > + > + return Result; > +} > + > +STATIC > +UINT16 > +GetBBSTypeByDevicePath ( > + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath > + ) > +{ > + EFI_DEVICE_PATH_PROTOCOL *Node; > + UINT16 Result; > + > + Result = BBS_TYPE_UNKNOWN; > + if (DevicePath == NULL) { > + return Result; > + } > + > + Node = DevicePath; > + while (!IsDevicePathEnd (Node)) { > + switch (DevicePathType (Node)) { > + case MEDIA_DEVICE_PATH: > + if (DevicePathSubType (Node) == MEDIA_CDROM_DP) { > + Result = BBS_TYPE_CDROM; > + } > + break; > + > + case MESSAGING_DEVICE_PATH: > + Result = GetBBSTypeFromMessagingDevicePath (DevicePath, Node); > + break; > + > + default: > + Result = BBS_TYPE_UNKNOWN; > + break; > + } > + > + if (Result != BBS_TYPE_UNKNOWN) { > + break; > + } > + > + Node = NextDevicePathNode (Node); > + } > + > + return Result; > +} > + > +STATIC > +EFI_STATUS > +GetBmcBootOptionsSetting ( > + OUT IPMI_GET_BOOT_OPTION *BmcBootOpt > + ) > +{ > + EFI_STATUS Status; > + > + Status = IpmiCmdGetSysBootOptions (BmcBootOpt); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Get iBMC BootOpts %r!\n", Status)); > + return Status; > + } > + > + if (BmcBootOpt->BootFlagsValid != BOOT_OPTION_BOOT_FLAG_VALID) { > + return EFI_NOT_FOUND; > + } > + > + if (BmcBootOpt->Persistent) { > + BmcBootOpt->BootFlagsValid = BOOT_OPTION_BOOT_FLAG_VALID; > + } else { > + BmcBootOpt->BootFlagsValid = BOOT_OPTION_BOOT_FLAG_INVALID; > + } > + > + Status = IpmiCmdSetSysBootOptions (BmcBootOpt); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Set iBMC BootOpts %r!\n", Status)); > + } > + > + return Status; > +} > + > +VOID > +RestoreBootOrder ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + UINT16 *BootOrder; > + UINTN BootOrderSize; > + > + GetVariable2 (L"BootOrderBackup", &gOemBootVariableGuid, (VOID **) &BootOrder, &BootOrderSize); line length > + if (BootOrder == NULL) { > + return ; > + } > + > + Print (L"\nRestore BootOrder(%d).\n", BootOrderSize / sizeof (UINT16)); > + > + Status = gRT->SetVariable ( > + L"BootOrder", > + &gEfiGlobalVariableGuid, > + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, line length > + BootOrderSize, > + BootOrder > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "SetVariable BootOrder %r!\n", Status)); > + } > + > + Status = gRT->SetVariable ( > + L"BootOrderBackup", > + &gOemBootVariableGuid, > + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, > + 0, > + NULL > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "SetVariable BootOrderBackup %r!\n", Status)); > + } > + > + FreePool (BootOrder); > + > + return; Remove this return > +} > + > + STATIC > +VOID EFIAPI > +RestoreBootOrderOnReadyToBoot ( > + IN EFI_EVENT Event, > + IN VOID *Context > + ) > +{ > + // restore BootOrder variable in normal condition. > + RestoreBootOrder (); > +} > + > +STATIC > +VOID > +UpdateBootOrder ( > + IN UINT16 *NewOrder, > + IN UINT16 *BootOrder, > + IN UINTN BootOrderSize > + ) > +{ > + EFI_STATUS Status; > + EFI_EVENT Event; > + > + Status = gRT->SetVariable ( > + L"BootOrderBackup", > + &gOemBootVariableGuid, > + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, > + BootOrderSize, > + BootOrder > + ); > + if (EFI_ERROR (Status)) { no DEBUG()? > + return; > + } > + > + Status = gRT->SetVariable ( > + L"BootOrder", > + &gEfiGlobalVariableGuid, > + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, line length > + BootOrderSize, > + NewOrder > + ); > + if (EFI_ERROR (Status)) { no DEBUG()? > + return; > + } > + > + // Register notify function to restore BootOrder variable on ReadyToBoot Event. > + Status = gBS->CreateEventEx ( > + EVT_NOTIFY_SIGNAL, > + TPL_CALLBACK, > + RestoreBootOrderOnReadyToBoot, > + NULL, > + &gEfiEventReadyToBootGuid, > + &Event > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Create ready to boot event %r!\n", Status)); > + } > + > + return; Remove this > +} > + > +STATIC > +VOID > +SetBootOrder ( > + IN UINT16 BootType > + ) > +{ > + EFI_STATUS Status; > + UINT16 *NewOrder; > + UINT16 *RemainBoots; > + UINT16 *BootOrder; > + UINTN BootOrderSize; > + EFI_BOOT_MANAGER_LOAD_OPTION Option; > + CHAR16 OptionName[sizeof ("Boot####")]; > + UINTN Index; > + UINTN SelectCnt; > + UINTN RemainCnt; > + > + GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrder, &BootOrderSize); > + if (BootOrder == NULL) { > + return ; > + } > + > + NewOrder = AllocatePool (BootOrderSize); > + RemainBoots = AllocatePool (BootOrderSize); > + if ((NewOrder == NULL) || (RemainBoots == NULL)) { > + DEBUG ((DEBUG_ERROR, "Out of resources.")); > + goto Exit; > + } > + > + SelectCnt = 0; > + RemainCnt = 0; > + > + for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) { > + UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]); > + Status = EfiBootManagerVariableToLoadOption (OptionName, &Option); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Boot%04x is invalid option!\n", BootOrder[Index])); > + continue; > + } > + > + if (GetBBSTypeByDevicePath (Option.FilePath) == BootType) { > + NewOrder[SelectCnt++] = BootOrder[Index]; > + } else { > + RemainBoots[RemainCnt++] = BootOrder[Index]; > + } > + } > + > + if (SelectCnt != 0) { > + // append RemainBoots to NewOrder > + for (Index = 0; Index < RemainCnt; Index++) { > + NewOrder[SelectCnt + Index] = RemainBoots[Index]; > + } > + > + if (CompareMem (NewOrder, BootOrder, BootOrderSize) != 0) { > + UpdateBootOrder (NewOrder, BootOrder, BootOrderSize); > + } > + } > + > +Exit: > + FreePool (BootOrder); > + if (NewOrder != NULL) { > + FreePool (NewOrder); > + } > + if (RemainBoots != NULL) { > + FreePool (RemainBoots); > + } > + > + return ; Remove this > +} > + > +VOID > +HandleBmcBootType ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + IPMI_GET_BOOT_OPTION BmcBootOpt; > + UINT16 BootType; > + > + Status = GetBmcBootOptionsSetting (&BmcBootOpt); > + if (EFI_ERROR (Status)) { > + return; > + } > + > + Print (L"Boot Type from BMC is %x\n", BmcBootOpt.BootDeviceSelector); > + > + switch (BmcBootOpt.BootDeviceSelector) { > + case ForcePxe: > + BootType = BBS_TYPE_EMBEDDED_NETWORK; > + break; > + > + case ForcePrimaryRemovableMedia: > + BootType = BBS_TYPE_USB; > + break; > + > + case ForceDefaultHardDisk: > + BootType = BBS_TYPE_HARDDRIVE; > + break; > + > + case ForceDefaultCD: > + BootType = BBS_TYPE_CDROM; > + break; > + > + default: > + return; > + } > + > + SetBootOrder (BootType); > +} > + > diff --git a/Silicon/Hisilicon/Library/BmcConfigBootLib/BmcConfigBootLib.inf b/Silicon/Hisilicon/Library/BmcConfigBootLib/BmcConfigBootLib.inf > new file mode 100644 > index 0000000..7e407b4 > --- /dev/null > +++ b/Silicon/Hisilicon/Library/BmcConfigBootLib/BmcConfigBootLib.inf > @@ -0,0 +1,51 @@ > +#/** @file > +# > +# Copyright (c) 2015, Hisilicon Limited. All rights reserved. > +# Copyright (c) 2015, Linaro Limited. All rights reserved. > +# > +# This program and the accompanying materials > +# are licensed and made available under the terms and conditions of the BSD License > +# which accompanies this distribution. The full text of the license may be found at > +# http://opensource.org/licenses/bsd-license.php > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > +# > +#**/ > + > +[Defines] > + INF_VERSION = 0x00010005 0x0000001A > + BASE_NAME = BmcConfigBootLib > + FILE_GUID = f174d192-7208-46c1-b9d1-65b2db06ad3b > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = BmcConfigBootLib > + > +[Sources.common] > + BmcConfigBootLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + Silicon/Hisilicon/HisiPkg.dec > + > +[LibraryClasses] > + BaseLib > + BaseMemoryLib > + DebugLib > + DevicePathLib > + IpmiCmdLib > + PcdLib > + PrintLib > + UefiBootManagerLib > + > +[BuildOptions] > + Remove empty sections please > +[Pcd] > + > +[Guids] > + gEfiEventReadyToBootGuid > + > +[Protocols] > + gEfiDevicePathToTextProtocolGuid ## CONSUMES > + gEfiSimpleFileSystemProtocolGuid ## CONSUMES > diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c > index 5d8d58e..845519f 100644 > --- a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c > +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBm.c > @@ -16,6 +16,7 @@ > **/ > > #include > +#include > #include > #include > #include > @@ -474,6 +475,10 @@ PlatformBootManagerBeforeConsole ( > // > EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid); > > + // restore BootOrder variable if previous BMC boot override attempt > + // left it in a modified state > + RestoreBootOrder (); > + > UpdateMemory (); > > // > @@ -570,6 +575,8 @@ PlatformBootManagerAfterConsole ( > PlatformRegisterFvBootOption ( > PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE > ); > + > + HandleBmcBootType (); > } > > /** > diff --git a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > index ae274f3..7b151a9 100644 > --- a/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > +++ b/Silicon/Hisilicon/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > @@ -44,6 +44,7 @@ > [LibraryClasses] > BaseLib > BaseMemoryLib > + BmcConfigBootLib > DebugLib > DevicePathLib > DxeServicesLib > diff --git a/Silicon/Hisilicon/Library/PlatformIntelBdsLib/IntelBdsPlatform.c b/Silicon/Hisilicon/Library/PlatformIntelBdsLib/IntelBdsPlatform.c > index dc23e46..20015da 100644 > --- a/Silicon/Hisilicon/Library/PlatformIntelBdsLib/IntelBdsPlatform.c > +++ b/Silicon/Hisilicon/Library/PlatformIntelBdsLib/IntelBdsPlatform.c > @@ -20,25 +20,19 @@ > **/ > > #include > +#include > #include > -#include > -#include > #include > #include > #include > #include > #include > -#include > #include > #include > #include > -#include > > #include "IntelBdsPlatform.h" > > -GUID gOemBootVaraibleGuid = {0xb7784577, 0x5aaf, 0x4557, {0xa1, 0x99, > - 0xd4, 0xa4, 0x2f, 0x45, 0x06, 0xf8} }; > - > //3CEF354A-3B7A-4519-AD70-72A134698311 > GUID gEblFileGuid = {0x3CEF354A, 0x3B7A, 0x4519, {0xAD, 0x70, > 0x72, 0xA1, 0x34, 0x69, 0x83, 0x11} }; > @@ -149,432 +143,6 @@ STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = { > } > }; > > -STATIC > -UINT16 > -GetBBSTypeFromFileSysPath ( > - IN CHAR16 *UsbPathTxt, > - IN CHAR16 *FileSysPathTxt, > - IN EFI_DEVICE_PATH_PROTOCOL *FileSysPath > - ) > -{ > - EFI_DEVICE_PATH_PROTOCOL *Node; > - > - if (StrnCmp (UsbPathTxt, FileSysPathTxt, StrLen (UsbPathTxt)) == 0) { > - Node = FileSysPath; > - while (!IsDevicePathEnd (Node)) { > - if ((DevicePathType (Node) == MEDIA_DEVICE_PATH) && > - (DevicePathSubType (Node) == MEDIA_CDROM_DP)) { > - return BBS_TYPE_CDROM; > - } > - Node = NextDevicePathNode (Node); > - } > - } > - > - return BBS_TYPE_UNKNOWN; > -} > - > -STATIC > -UINT16 > -GetBBSTypeFromUsbPath ( > - IN CONST EFI_DEVICE_PATH_PROTOCOL *UsbPath > - ) > -{ > - EFI_STATUS Status; > - EFI_HANDLE *FileSystemHandles; > - UINTN NumberFileSystemHandles; > - UINTN Index; > - EFI_DEVICE_PATH_PROTOCOL *FileSysPath; > - EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText; > - CHAR16 *UsbPathTxt; > - CHAR16 *FileSysPathTxt; > - UINT16 Result; > - > - Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **) &DevPathToText); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "Locate DevicePathToTextPro %r\n", Status)); > - return BBS_TYPE_UNKNOWN; > - } > - > - Result = BBS_TYPE_UNKNOWN; > - UsbPathTxt = DevPathToText->ConvertDevicePathToText (UsbPath, TRUE, TRUE); > - if (UsbPathTxt == NULL) { > - return Result; > - } > - > - Status = gBS->LocateHandleBuffer ( > - ByProtocol, > - &gEfiSimpleFileSystemProtocolGuid, > - NULL, > - &NumberFileSystemHandles, > - &FileSystemHandles > - ); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "Locate SimpleFileSystemProtocol error(%r)\n", Status)); > - FreePool (UsbPathTxt); > - return BBS_TYPE_UNKNOWN; > - } > - > - for (Index = 0; Index < NumberFileSystemHandles; Index++) { > - FileSysPath = DevicePathFromHandle (FileSystemHandles[Index]); > - FileSysPathTxt = DevPathToText->ConvertDevicePathToText (FileSysPath, TRUE, TRUE); > - > - if (FileSysPathTxt == NULL) { > - continue; > - } > - > - Result = GetBBSTypeFromFileSysPath (UsbPathTxt, FileSysPathTxt, FileSysPath); > - FreePool (FileSysPathTxt); > - > - if (Result != BBS_TYPE_UNKNOWN) { > - break; > - } > - } > - > - if (NumberFileSystemHandles != 0) { > - FreePool (FileSystemHandles); > - } > - > - FreePool (UsbPathTxt); > - > - return Result; > -} > - > -STATIC > -UINT16 > -GetBBSTypeFromMessagingDevicePath ( > - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, > - IN EFI_DEVICE_PATH_PROTOCOL *Node > - ) > -{ > - VENDOR_DEVICE_PATH *Vendor; > - UINT16 Result; > - > - Result = BBS_TYPE_UNKNOWN; > - > - switch (DevicePathSubType (Node)) { > - case MSG_MAC_ADDR_DP: > - Result = BBS_TYPE_EMBEDDED_NETWORK; > - break; > - > - case MSG_USB_DP: > - Result = GetBBSTypeFromUsbPath (DevicePath); > - if (Result == BBS_TYPE_UNKNOWN) { > - Result = BBS_TYPE_USB; > - } > - break; > - > - case MSG_SATA_DP: > - Result = BBS_TYPE_HARDDRIVE; > - break; > - > - case MSG_VENDOR_DP: > - Vendor = (VENDOR_DEVICE_PATH *) (Node); > - if ((&Vendor->Guid) != NULL) { > - if (CompareGuid (&Vendor->Guid, &((EFI_GUID) DEVICE_PATH_MESSAGING_SAS))) { > - Result = BBS_TYPE_HARDDRIVE; > - } > - } > - break; > - > - default: > - Result = BBS_TYPE_UNKNOWN; > - break; > - } > - > - return Result; > -} > - > -STATIC > -UINT16 > -GetBBSTypeByDevicePath ( > - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath > - ) > -{ > - EFI_DEVICE_PATH_PROTOCOL *Node; > - UINT16 Result; > - > - Result = BBS_TYPE_UNKNOWN; > - if (DevicePath == NULL) { > - return Result; > - } > - > - Node = DevicePath; > - while (!IsDevicePathEnd (Node)) { > - switch (DevicePathType (Node)) { > - case MEDIA_DEVICE_PATH: > - if (DevicePathSubType (Node) == MEDIA_CDROM_DP) { > - Result = BBS_TYPE_CDROM; > - } > - break; > - > - case MESSAGING_DEVICE_PATH: > - Result = GetBBSTypeFromMessagingDevicePath (DevicePath, Node); > - break; > - > - default: > - Result = BBS_TYPE_UNKNOWN; > - break; > - } > - > - if (Result != BBS_TYPE_UNKNOWN) { > - break; > - } > - > - Node = NextDevicePathNode (Node); > - } > - > - return Result; > -} > - > -STATIC > -EFI_STATUS > -GetBmcBootOptionsSetting ( > - OUT IPMI_GET_BOOT_OPTION *BmcBootOpt > - ) > -{ > - EFI_STATUS Status; > - > - Status = IpmiCmdGetSysBootOptions (BmcBootOpt); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "Get iBMC BootOpts %r!\n", Status)); > - return Status; > - } > - > - if (BmcBootOpt->BootFlagsValid != BOOT_OPTION_BOOT_FLAG_VALID) { > - return EFI_NOT_FOUND; > - } > - > - if (BmcBootOpt->Persistent) { > - BmcBootOpt->BootFlagsValid = BOOT_OPTION_BOOT_FLAG_VALID; > - } else { > - BmcBootOpt->BootFlagsValid = BOOT_OPTION_BOOT_FLAG_INVALID; > - } > - > - Status = IpmiCmdSetSysBootOptions (BmcBootOpt); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "Set iBMC BootOpts %r!\n", Status)); > - } > - > - return Status; > -} > - > -STATIC > -VOID > -RestoreBootOrder ( > - VOID > - ) > -{ > - EFI_STATUS Status; > - UINT16 *BootOrder; > - UINTN BootOrderSize; > - > - GetVariable2 (L"BootOrderBackup", &gOemBootVaraibleGuid, (VOID **) &BootOrder, &BootOrderSize); > - if (BootOrder == NULL) { > - return ; > - } > - > - Print (L"Restore BootOrder(%d).\n", BootOrderSize / sizeof (UINT16)); > - > - Status = gRT->SetVariable ( > - L"BootOrder", > - &gEfiGlobalVariableGuid, > - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, > - BootOrderSize, > - BootOrder > - ); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "SetVariable BootOrder %r!\n", Status)); > - } > - > - Status = gRT->SetVariable ( > - L"BootOrderBackup", > - &gOemBootVaraibleGuid, > - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, > - 0, > - NULL > - ); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "SetVariable BootOrderBackup %r!\n", Status)); > - } > - > - FreePool (BootOrder); > - > - return; > -} > - > - > -VOID > -RestoreBootOrderOnReadyToBoot ( > - IN EFI_EVENT Event, > - IN VOID *Context > - ) > -{ > - // restore BootOrder variable in normal condition. > - RestoreBootOrder (); > -} > - > -STATIC > -VOID > -UpdateBootOrder ( > - IN UINT16 *NewOrder, > - IN UINT16 *BootOrder, > - IN UINTN BootOrderSize > - ) > -{ > - EFI_STATUS Status; > - EFI_EVENT Event; > - > - Status = gRT->SetVariable ( > - L"BootOrderBackup", > - &gOemBootVaraibleGuid, > - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, > - BootOrderSize, > - BootOrder > - ); > - if (EFI_ERROR (Status)) { > - return; > - } > - > - Status = gRT->SetVariable ( > - L"BootOrder", > - &gEfiGlobalVariableGuid, > - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, > - BootOrderSize, > - NewOrder > - ); > - if (EFI_ERROR (Status)) { > - return; > - } > - > - // Register notify function to restore BootOrder variable on ReadyToBoot Event. > - Status = gBS->CreateEventEx ( > - EVT_NOTIFY_SIGNAL, > - TPL_CALLBACK, > - RestoreBootOrderOnReadyToBoot, > - NULL, > - &gEfiEventReadyToBootGuid, > - &Event > - ); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "Create ready to boot event %r!\n", Status)); > - } > - > - return; > -} > - > -STATIC > -VOID > -SetBootOrder ( > - IN UINT16 BootType > - ) > -{ > - UINT16 *NewOrder; > - UINT16 *RemainBoots; > - UINT16 *BootOrder; > - UINTN BootOrderSize; > - CHAR16 OptionName[sizeof ("Boot####")]; > - UINTN Index; > - LIST_ENTRY BootOptionList; > - BDS_COMMON_OPTION *Option; > - UINTN SelectCnt; > - UINTN RemainCnt; > - > - InitializeListHead (&BootOptionList); > - > - GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrder, &BootOrderSize); > - if (BootOrder == NULL) { > - return ; > - } > - > - NewOrder = AllocatePool (BootOrderSize); > - RemainBoots = AllocatePool (BootOrderSize); > - if ((NewOrder == NULL) || (RemainBoots == NULL)) { > - DEBUG ((DEBUG_ERROR, "Out of resources.")); > - goto Exit; > - } > - > - SelectCnt = 0; > - RemainCnt = 0; > - > - for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) { > - UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]); > - Option = BdsLibVariableToOption (&BootOptionList, OptionName); > - if (Option == NULL) { > - DEBUG ((DEBUG_ERROR, "Boot%04x is invalid option!\n", BootOrder[Index])); > - continue; > - } > - > - if (GetBBSTypeByDevicePath (Option->DevicePath) == BootType) { > - NewOrder[SelectCnt++] = BootOrder[Index]; > - } else { > - RemainBoots[RemainCnt++] = BootOrder[Index]; > - } > - } > - > - if (SelectCnt != 0) { > - // append RemainBoots to NewOrder > - for (Index = 0; Index < RemainCnt; Index++) { > - NewOrder[SelectCnt + Index] = RemainBoots[Index]; > - } > - > - if (CompareMem (NewOrder, BootOrder, BootOrderSize) != 0) { > - UpdateBootOrder (NewOrder, BootOrder, BootOrderSize); > - } > - } > - > -Exit: > - FreePool (BootOrder); > - if (NewOrder != NULL) { > - FreePool (NewOrder); > - } > - if (RemainBoots != NULL) { > - FreePool (RemainBoots); > - } > - > - return ; > -} > - > -STATIC > -VOID > -HandleBmcBootType ( > - VOID > - ) > -{ > - EFI_STATUS Status; > - IPMI_GET_BOOT_OPTION BmcBootOpt; > - UINT16 BootType; > - > - Status = GetBmcBootOptionsSetting (&BmcBootOpt); > - if (EFI_ERROR (Status)) { > - return; > - } > - > - Print (L"Boot Type from BMC is %x\n", BmcBootOpt.BootDeviceSelector); > - > - switch (BmcBootOpt.BootDeviceSelector) { > - case ForcePxe: > - BootType = BBS_TYPE_EMBEDDED_NETWORK; > - break; > - > - case ForcePrimaryRemovableMedia: > - BootType = BBS_TYPE_USB; > - break; > - > - case ForceDefaultHardDisk: > - BootType = BBS_TYPE_HARDDRIVE; > - break; > - > - case ForceDefaultCD: > - BootType = BBS_TYPE_CDROM; > - break; > - > - default: > - return; > - } > - > - SetBootOrder (BootType); > -} > - > // > // BDS Platform Functions > // > diff --git a/Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf b/Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf > index 0feec06..793c7dc 100644 > --- a/Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf > +++ b/Silicon/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf > @@ -47,10 +47,10 @@ > [LibraryClasses] > BaseLib > BaseMemoryLib > + BmcConfigBootLib > DebugLib > DevicePathLib > GenericBdsLib > - IpmiCmdLib > MemoryAllocationLib > PcdLib > PrintLib > @@ -70,14 +70,12 @@ > > [Guids] > gEfiEndOfDxeEventGroupGuid > - gEfiEventReadyToBootGuid > gEfiFileInfoGuid > gEfiFileSystemInfoGuid > gEfiFileSystemVolumeLabelInfoIdGuid > > [Protocols] > gEfiDevicePathProtocolGuid > - gEfiDevicePathToTextProtocolGuid > gEfiGraphicsOutputProtocolGuid > gEfiLoadedImageProtocolGuid > gEfiPciRootBridgeIoProtocolGuid > -- > 1.9.1 >