From patchwork Thu Jan 18 15:01:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 124976 Delivered-To: patch@linaro.org Received: by 10.80.140.226 with SMTP id r31csp3635927edr; Thu, 18 Jan 2018 07:02:09 -0800 (PST) X-Google-Smtp-Source: ACJfBotAUqM498VMsk+uyMaoeh5r9OdE8UN9PgZov/BKOsqi8HXcl7iiW3VT9EbJvsw9SkMacNtY X-Received: by 10.99.151.26 with SMTP id n26mr35707198pge.87.1516287729002; Thu, 18 Jan 2018 07:02:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516287728; cv=none; d=google.com; s=arc-20160816; b=TZyZJPnkzgyQZXQJZaA8ueqR2XCFXYBOypN3LCh0Gw+EFMmxEgVwBzUB+FRijmsVMb gGP9EFy+rDe4iUDT1vgY2MqG/Q0vInLRZnkwF5ZAKjFYWggg24syuZ5n3uwjOzfX3MRb LDPHnECgCYq6wuTYTr6SGnkXHQqosLr445ANOlGMFtU+Y6qS+I10Yhy5HolO2LHQQBJC qToExkw3I4DwTHVMCz/odUrLM6RmLxJ7qLcvUscoNfQVrAKKwK6toJoX5kibKuX9Mx3c g6rbqsGaR+lX1nzK1t+gmjjerL1iW6kNQVjdMbGKJq9k7VafSzZRsbf2QfSkIzjIPt70 TDsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=qry6eRu6JLIKPWPtfB3DKA1qAJMUi+MOZzBhGmk+580=; b=jLFiGzQvDHP5uSBnLc+nsGmplVTCnEZ9ZbNv4YfYFzOSt89SBHElD2oTVxdJt0l7FI WY8po08DitVrWNdCynXVwhnAZ0lBI3lDVI9Yxe3N6hfHKZM34QP/kRM389Yy8aBFRGjC iC44TGlxorW5v7oK5357mfz4K/LrgvM8HgNQqdBq6v8P9tfmqvp2RbGgg5EXnVvEuxo3 Re2ifk9ye3s01KZqAz26RKzZZrWOgHe3tsitGRIuk3q/zWqUK3YNHQpsSsJOUs+hvJcP kWv32J6rY9UvC2QudzJY4BhKT7hL+LD6IeW4kPORD6EPHmzEss3ITytxbJh62I/eWeu6 lJ4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HPUrAh+y; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id y24si7092472pfa.194.2018.01.18.07.02.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 07:02:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HPUrAh+y; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7B03A2232BDF6; Thu, 18 Jan 2018 06:56:43 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c00::243; helo=mail-pf0-x243.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf0-x243.google.com (mail-pf0-x243.google.com [IPv6:2607:f8b0:400e:c00::243]) (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 E6972222DDC12 for ; Thu, 18 Jan 2018 06:56:41 -0800 (PST) Received: by mail-pf0-x243.google.com with SMTP id e11so14775990pff.6 for ; Thu, 18 Jan 2018 07:02:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IoY0ZZkRu4820bkcU1P2qLmZUDU0cvKMtpUHmW9UiUw=; b=HPUrAh+yUGA66or7iuSinMQY5dJcYAIHD1KKVDxvbzsT1yi8eW4L0828tPIMcSJBYq NRDVkUZdwMbxciUWbPpSMgBXsVAu2EjeEt9d7m5MJPc2YbYKhUnzvierq8TSjebPz8T6 xjFT5SAXYKuZfi0wlu+UAa99/L6N15z2UUHjg= 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=IoY0ZZkRu4820bkcU1P2qLmZUDU0cvKMtpUHmW9UiUw=; b=mW6WW9dEg0qP4LuGl+mj8yGmOxTIMrQ1LTDa+AkCbeko9PNh/3q0e4f0kHQpb8XGBO xvk26tMccF6XT4gm19ANC7dC81RDXMUngMWua8NWFcy5YMAZqA4n/WPKGXq+Gof7T9Qg djMiKV3RImLqjN+XyZXl8Ijh+8sPYlc5s/w8FWZO545qfEfVrf26nj3BmprLF8solUBT avUbgeaUMZddZeukz9SwowIC3ocpypCHA90Y5Ppd70fnfxabCH+ioC1Vw6Porz840F/N Hnn9zyHKMhFwiHkGdEKTs/P8mgfnHW/BrJY+w04HvSjzRkYKmPhXj4gyu6Q9tu9ABW8R vITw== X-Gm-Message-State: AKwxytcXTk+W9u8Fb0FKDNhD0DSRvGdli6hu/TiENImhU2Fq+YFv/S9F FXSk1xVjod+rXMaB0pLDnZXc6Q== X-Received: by 10.98.67.138 with SMTP id l10mr9198545pfi.72.1516287722505; Thu, 18 Jan 2018 07:02:02 -0800 (PST) Received: from localhost.localdomain ([120.31.149.194]) by smtp.gmail.com with ESMTPSA id j14sm13621815pfh.94.2018.01.18.07.01.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Jan 2018 07:02:01 -0800 (PST) From: Ming Huang X-Google-Original-From: Ming Huang To: leif.lindholm@linaro.org, linaro-uefi@lists.linaro.org, edk2-devel@lists.01.org, graeme.gregory@linaro.org Date: Thu, 18 Jan 2018 23:01:32 +0800 Message-Id: <1516287703-35516-4-git-send-email-huangming23@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1516287703-35516-1-git-send-email-huangming23@huawei.com> References: <1516287703-35516-1-git-send-email-huangming23@huawei.com> Subject: [edk2] [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: , Cc: huangming23@huawei.com, ard.biesheuvel@linaro.org, zhangjinsong2@huawei.com, Heyi Guo , wanghuiqiang@huawei.com, guoheyi@huawei.com, waip23@126.com, mengfanrong@huawei.com MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(-) -- 1.9.1 _______________________________________________ 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 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} }; + +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; +} + +VOID +RestoreBootOrder ( + VOID + ) +{ + EFI_STATUS Status; + UINT16 *BootOrder; + UINTN BootOrderSize; + + GetVariable2 (L"BootOrderBackup", &gOemBootVariableGuid, (VOID **) &BootOrder, &BootOrderSize); + 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, + 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; +} + + +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", + &gOemBootVariableGuid, + 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 + ) +{ + 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 ; +} + +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 + 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] + +[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