From patchwork Mon Mar 20 13:11:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chenhui Sun X-Patchwork-Id: 95548 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp939571qgd; Mon, 20 Mar 2017 06:23:37 -0700 (PDT) X-Received: by 10.36.43.194 with SMTP id h185mr10515043ita.121.1490016217790; Mon, 20 Mar 2017 06:23:37 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v1si10673457itb.117.2017.03.20.06.23.37; Mon, 20 Mar 2017 06:23:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linaro-uefi-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linaro-uefi-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=linaro-uefi-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 4AFCA60A3C; Mon, 20 Mar 2017 13:23:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id A6A2763EB1; Mon, 20 Mar 2017 13:17:52 +0000 (UTC) X-Original-To: linaro-uefi@lists.linaro.org Delivered-To: linaro-uefi@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id BAB0663E81; Mon, 20 Mar 2017 13:17:37 +0000 (UTC) Received: from mail-pg0-f51.google.com (mail-pg0-f51.google.com [74.125.83.51]) by lists.linaro.org (Postfix) with ESMTPS id 12D7463E83 for ; Mon, 20 Mar 2017 13:15:45 +0000 (UTC) Received: by mail-pg0-f51.google.com with SMTP id n190so77337503pga.0 for ; Mon, 20 Mar 2017 06:15:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uD2oHLcFBtP1vqWqJQs6S8juyOjlCkW7ZrAs//3++rU=; b=Ip0+C4WY/43v/Ms1+N0oHI3veQn9RFkf3k3DdhzCQAZUQstBMIisOQviLKnjcS30NT QHt3g/cANboNHwLZFH4VynqPftu8DPA3w4dZPsynBpNbuIG5Bd+m5ZSq/6t9jb79DHD5 nYQOehyaUrQr5WeQMnqdlwDoe3znHgEEhUzgPp3UyShtRjJguzz9zuWGcF9yCZ6c8rM+ tdA66RcKuMVgE7PikMjZ92NWxRRqkFCFSEUpbyCkEC2781u1UPqhC3Op6hAa1FHb0IyT Xn7tfzyR6rtxy9yHMYvgGdDeXCicewqyzFIZTcA/yxHa53EfxX5i5V9milhCn+8cIq3Z ekrg== X-Gm-Message-State: AFeK/H0B4/YZ0PyZaSo18Tez51F+m/v+672LFFwsp/lqKSfJY/55bixykX0cMPorJxedNyByJuM= X-Received: by 10.98.103.75 with SMTP id b72mr32625074pfc.105.1490015744254; Mon, 20 Mar 2017 06:15:44 -0700 (PDT) Received: from localhost.localdomain ([119.145.15.121]) by smtp.gmail.com with ESMTPSA id a62sm33573787pgc.60.2017.03.20.06.15.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Mar 2017 06:15:43 -0700 (PDT) From: Chenhui Sun To: leif.lindholm@linaro.org, linaro-uefi@lists.linaro.org Date: Mon, 20 Mar 2017 21:11:25 +0800 Message-Id: <1490015485-53685-22-git-send-email-chenhui.sun@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490015485-53685-1-git-send-email-chenhui.sun@linaro.org> References: <1490015485-53685-1-git-send-email-chenhui.sun@linaro.org> Cc: huangming , Chenhui Sun , sunchenhui@huawei.com, wanghuiqiang@huawei.com Subject: [Linaro-uefi] [Linaro-uefi v1 21/21] Hisilicon D03/D05: get boot option from BMC X-BeenThere: linaro-uefi@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-uefi-bounces@lists.linaro.org Sender: "Linaro-uefi" Support the feature that BIOS get boot option from BMC and put it in the first boot order. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: huangming Signed-off-by: Chenhui Sun --- .../Library/PlatformIntelBdsLib/IntelBdsPlatform.c | 310 +++++++++++++++++++++ .../PlatformIntelBdsLib/PlatformIntelBdsLib.inf | 2 + Platforms/Hisilicon/D03/D03.dsc | 1 - Platforms/Hisilicon/D05/D05.dsc | 1 - 4 files changed, 312 insertions(+), 2 deletions(-) diff --git a/Chips/Hisilicon/Library/PlatformIntelBdsLib/IntelBdsPlatform.c b/Chips/Hisilicon/Library/PlatformIntelBdsLib/IntelBdsPlatform.c index efefeb6..7bba2f4 100644 --- a/Chips/Hisilicon/Library/PlatformIntelBdsLib/IntelBdsPlatform.c +++ b/Chips/Hisilicon/Library/PlatformIntelBdsLib/IntelBdsPlatform.c @@ -19,18 +19,108 @@ **/ +#include #include #include +#include +#include #include #include +#include #include #include +#include #include #include #include #include "IntelBdsPlatform.h" +#define BOOT_OPTION_BOOT_FLAG_VALID 1 +#define BOOT_OPTION_BOOT_FLAG_INVALID 0 + +typedef enum { + NoOverride = 0x0, + ForcePxe, + ForceDefaultHardDisk, + ForceDefaultHardDiskSafeMode, + ForceDefaultDiagnosticPartition, + ForceDefaultCD, + ForceSetupUtility, + ForceRemoteRemovableMedia, + ForceRemoteCD, + ForcePrimaryRemoteMedia, + ForceRemoteHardDisk = 0xB, + ForcePrimaryRemovableMedia = 0xF +} BOOT_DEVICE_SELECTOR; + +// Get System Boot Option data structure +// +typedef struct { + UINT8 ParameterVersion :4; + UINT8 Reserved1 :4; + UINT8 ParameterSelector :7; + UINT8 ParameterValid :1; + // + // Boot Flags Data 1 + // + UINT8 Reserved2 :5; + UINT8 BiosBootType :1; + UINT8 Persistent :1; + UINT8 BootFlagsValid :1; + // + // Boot Flags Data 2 + // + UINT8 LockResetBtn :1; + UINT8 ScreenBlank :1; + UINT8 BootDeviceSelector :4; + UINT8 LockKeyboard :1; + UINT8 ClearCmos :1; + // + // Boot Flags Data 3 + // + UINT8 ConsoleRedirectionControl :2; + UINT8 LockSleepBtn :1; + UINT8 UserPasswordByPass :1; + UINT8 Reserved3 :1; + UINT8 FirmwareVerbosity :2; + UINT8 LockPowerBtn :1; + // + // Boot Flags Data 4 + // + UINT8 MuxControlOverride :3; + UINT8 ShareModeOverride :1; + UINT8 Reserved4 :4; + // + // Boot Flags Data 5 + // + UINT8 DeviceInstanceSelector :5; + UINT8 Reserved5 :3; +} IPMI_GET_BOOT_OPTION; + +#define EFI_ACPI_PCI_SAS_DEVICE_PATH_GUID \ + { \ + 0xA0441D0, 0x0, 0x0, {0x1, 0x1, 0x06, 0x0, 0x0, 0x0, 0x1, 0x1 } \ + } + +typedef struct{ + UINT8 NodeType; + UINT8 NodeSubType; + EFI_GUID *Guid; + UINTN DeviceType; +}OemDeviceType; + +OemDeviceType DeviceTypeArray[]={ + {MESSAGING_DEVICE_PATH, MSG_SATA_DP, NULL, BBS_TYPE_HARDDRIVE}, + {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, &((EFI_GUID)EFI_ACPI_PCI_SAS_DEVICE_PATH_GUID), BBS_TYPE_HARDDRIVE}, + {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, &((EFI_GUID)DEVICE_PATH_MESSAGING_SAS), BBS_TYPE_HARDDRIVE}, + {MESSAGING_DEVICE_PATH, MSG_USB_DP, NULL, BBS_TYPE_USB}, + {MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, NULL, BBS_TYPE_EMBEDDED_NETWORK}, + {MEDIA_DEVICE_PATH, MEDIA_CDROM_DP, NULL, BBS_TYPE_CDROM} +}; + +EFI_STATUS IpmiCmdGetSysBootOptions(OUT IPMI_GET_BOOT_OPTION *BootOption ); +EFI_STATUS IpmiCmdSetSysBootOptions(IPMI_GET_BOOT_OPTION *BootOption ); //3CEF354A-3B7A-4519-AD70-72A134698311 GUID gEblFileGuid = {0x3CEF354A, 0x3B7A, 0x4519, {0xAD, 0x70, @@ -361,6 +451,223 @@ AddOutput ( ReportText)); } +UINT16 DeviceTypeFoundInFileSystemHandles (EFI_DEVICE_PATH_PROTOCOL *DevicePathIn) +{ + EFI_STATUS Status; + EFI_HANDLE *FileSystemHandles; + UINTN NumberFileSystemHandles; + UINTN Index; + EFI_DEVICE_PATH_PROTOCOL *DevicePathGot; + EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol; + CHAR16* DevicePathTxtIn = NULL; + CHAR16* DevicePathTxtGot = NULL; + EFI_DEVICE_PATH_PROTOCOL *DevicePathNode = NULL; + UINT16 Result = BBS_TYPE_UNKNOWN; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiSimpleFileSystemProtocolGuid, + NULL, + &NumberFileSystemHandles, + &FileSystemHandles + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a(%d):error!\n", __FUNCTION__,__LINE__)); + return BBS_TYPE_UNKNOWN; + } + + Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a(%d):error!\n", __FUNCTION__,__LINE__)); + return BBS_TYPE_UNKNOWN; + } + DevicePathTxtIn = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePathIn, TRUE, TRUE); + + for (Index = 0; Index < NumberFileSystemHandles; Index++) { + DevicePathGot = DevicePathFromHandle (FileSystemHandles[Index]); + DevicePathTxtGot = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePathGot, TRUE, TRUE); + + if (StrnCmp(DevicePathTxtIn, DevicePathTxtGot, StrLen(DevicePathTxtIn)) == 0) { + DevicePathNode = DevicePathGot; + while (!IsDevicePathEnd (DevicePathNode)) { + if ((DevicePathNode->Type == MEDIA_DEVICE_PATH) && (DevicePathNode->SubType == MEDIA_CDROM_DP)) { + Result = BBS_TYPE_CDROM; + break; + } + DevicePathNode = NextDevicePathNode (DevicePathNode); + } + } + + if (Result != BBS_TYPE_UNKNOWN) { + break; + } + } + + if (NumberFileSystemHandles != 0) { + FreePool (FileSystemHandles); + } + if (DevicePathTxtGot != NULL) { + FreePool (DevicePathTxtGot); + } + if (DevicePathTxtIn != NULL) { + FreePool (DevicePathTxtIn); + } + + return Result; +} + +UINT16 UniGetEfiDeviceType( + IN BDS_COMMON_OPTION *BootOption +) +{ + EFI_DEVICE_PATH_PROTOCOL* DevicePathNode; + UINTN DeviceCnt; + UINTN Loop; + VENDOR_DEVICE_PATH *Vender; + UINT16 Result; + + DeviceCnt = sizeof (DeviceTypeArray) / sizeof (OemDeviceType); + DevicePathNode = BootOption->DevicePath; + while (!IsDevicePathEnd (DevicePathNode)) { + for (Loop = 0; Loop < DeviceCnt; Loop++) { + if ((DevicePathType (DevicePathNode) == DeviceTypeArray[Loop].NodeType) && + (DevicePathSubType (DevicePathNode) == MSG_VENDOR_DP)) { + Vender = (VENDOR_DEVICE_PATH*)(DevicePathNode); + if (CompareMem(&(Vender->Guid), DeviceTypeArray[Loop].Guid, sizeof(EFI_GUID)) == 0) { + return DeviceTypeArray[Loop].DeviceType; + } + } else if ((DevicePathType (DevicePathNode) == MESSAGING_DEVICE_PATH) && + (DevicePathSubType (DevicePathNode) == MSG_USB_DP)) { + Result = DeviceTypeFoundInFileSystemHandles (BootOption->DevicePath); + if (Result != BBS_TYPE_UNKNOWN) { + return Result; + } + } else if ((DevicePathType (DevicePathNode) == DeviceTypeArray[Loop].NodeType) && + (DevicePathSubType (DevicePathNode) == DeviceTypeArray[Loop].NodeSubType)) { + return DeviceTypeArray[Loop].DeviceType; + } + } + + DevicePathNode = NextDevicePathNode (DevicePathNode); + } + + return BBS_TYPE_UNKNOWN; +} + +EFI_STATUS GetBmcBootOptionsSetting (IPMI_GET_BOOT_OPTION *BmcBootOpt) +{ + EFI_STATUS Status = EFI_SUCCESS; + + Status = IpmiCmdGetSysBootOptions (BmcBootOpt); + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "%a - %d Get iBMC BootOpts %r!\n", __FUNCTION__, __LINE__,Status)); + return Status; + } + + if (BmcBootOpt->BootFlagsValid != BOOT_OPTION_BOOT_FLAG_VALID) { + DEBUG ((DEBUG_ERROR, "%a - %d BootFlags is Invalid !\n", __FUNCTION__, __LINE__)); + return EFI_INVALID_PARAMETER; + } + + 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, "%a - %d Set iBMC BootOpts %r!\n", __FUNCTION__, __LINE__, Status)); + } + + return Status; +} + +VOID ProductBdsPolicyAfterSetup ( VOID ) +{ + EFI_STATUS Status = EFI_SUCCESS; + IPMI_GET_BOOT_OPTION BmcBootOpt; + UINT16 *OptionOrder; + UINTN OptionOrderSize; + UINTN DeviceType = BBS_TYPE_UNKNOWN; + UINTN Index; + BDS_COMMON_OPTION *Option; + CHAR16 OptionName[20]; + LIST_ENTRY BootOptionList; + UINT16 BootIdx; + UINT16 *BootNextBuf; + + InitializeListHead (&BootOptionList); + + Status = GetBmcBootOptionsSetting (&BmcBootOpt); + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "%a - %d : %r!\n", __FUNCTION__, __LINE__,Status)); + return; + } + + if (BmcBootOpt.BootDeviceSelector == ForcePrimaryRemovableMedia) { + DeviceType = BBS_TYPE_USB; + } else if (BmcBootOpt.BootDeviceSelector == ForcePxe) { + DeviceType = BBS_TYPE_EMBEDDED_NETWORK; + } else if (BmcBootOpt.BootDeviceSelector == ForceDefaultHardDisk) { + DeviceType = BBS_TYPE_HARDDRIVE; + } else if (BmcBootOpt.BootDeviceSelector == ForceDefaultCD) { + DeviceType = BBS_TYPE_CDROM; + } else { + return; + } + + DEBUG ((DEBUG_ERROR, "BMC set BootType=%x\n", DeviceType)); + + OptionOrder = BdsLibGetVariableAndSize ( + L"BootOrder", + &gEfiGlobalVariableGuid, + &OptionOrderSize + ); + if (OptionOrder == NULL) { + DEBUG ((DEBUG_ERROR, "%a - %d error\n", __FUNCTION__, __LINE__)); + return; + } + + BootIdx = 0; + BootNextBuf = (UINT16*)AllocatePool(OptionOrderSize); + if (BootNextBuf == NULL) { + DEBUG ((DEBUG_ERROR, "Out of resources.\n")); + return; + } + + for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) { + UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionOrder[Index]); + Option = BdsLibVariableToOption (&BootOptionList, OptionName); + if (Option == NULL) { + DEBUG((DEBUG_ERROR, "%a - %d Boot%04x is Null!\n", __FUNCTION__, __LINE__, OptionOrder[Index])); + continue; + } + + if (DeviceType == UniGetEfiDeviceType(Option)) { + BootNextBuf[BootIdx] = OptionOrder[Index]; + BootIdx++; + } + RemoveEntryList (&Option->Link); + FreePool (Option); + } + + if (BootIdx > 0) { + Status = gRT->SetVariable ( + L"BootNext", + &gEfiGlobalVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + BootIdx*sizeof(UINT16), + BootNextBuf + ); + DEBUG ((DEBUG_ERROR, "Set BootNext %r, size=%x\n", Status, BootIdx*sizeof(UINT16))); + } + + FreePool (OptionOrder); + FreePool (BootNextBuf); + + return; +} /** The function will execute with as the platform policy, current policy @@ -469,6 +776,9 @@ PlatformBdsPolicyBehavior ( // BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder"); + //get boot option from BMC + ProductBdsPolicyAfterSetup(); + //PlatformBdsEnterFrontPage (GetFrontPageTimeoutFromQemu(), TRUE); Print (L"Press Enter to boot OS immediately.\n"); Print (L"Press any other key in %d seconds to stop automatical booting...\n", PcdGet16(PcdPlatformBootTimeOut)); diff --git a/Chips/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf b/Chips/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf index baceb57..a09683d 100644 --- a/Chips/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf +++ b/Chips/Hisilicon/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf @@ -49,6 +49,7 @@ DebugLib DevicePathLib GenericBdsLib + IpmiCmdLib MemoryAllocationLib PcdLib PrintLib @@ -78,3 +79,4 @@ gEfiLoadedImageProtocolGuid gEfiPciRootBridgeIoProtocolGuid gEfiSimpleFileSystemProtocolGuid + gEfiDevicePathToTextProtocolGuid diff --git a/Platforms/Hisilicon/D03/D03.dsc b/Platforms/Hisilicon/D03/D03.dsc index 24c88a3..05dd5d8 100644 --- a/Platforms/Hisilicon/D03/D03.dsc +++ b/Platforms/Hisilicon/D03/D03.dsc @@ -367,7 +367,6 @@ OpenPlatformPkg/Chips/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.inf MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { - NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf } MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf diff --git a/Platforms/Hisilicon/D05/D05.dsc b/Platforms/Hisilicon/D05/D05.dsc index 9de1be6..efdedfd 100644 --- a/Platforms/Hisilicon/D05/D05.dsc +++ b/Platforms/Hisilicon/D05/D05.dsc @@ -487,7 +487,6 @@ OpenPlatformPkg/Chips/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.inf MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { - NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf } MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf