From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by mx.groups.io with SMTP id smtpd.web12.6647.1626268880782339729 for ; Wed, 14 Jul 2021 06:21:21 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=uQjFg+4f; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.167.54, mailfrom: gjb@semihalf.com) Received: by mail-lf1-f54.google.com with SMTP id 22so3512544lfy.12 for ; Wed, 14 Jul 2021 06:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dL8G01lAS0Tcty0K5s1jkDm6uBOV9Qq57fiqyNLrtts=; b=uQjFg+4fyjrF22ZDV+sPkjO/KVYq/5kV1ZTFkz7zfKCwZ8oGvsnnxhg8cSafiLxoLK MHoUleK2hEyAFxkw+Zsr9Fe90g6zclsrjI39R55/HxAUA6OHzVLr3GvtPhEEAeGnaKKW /sU0my/SySOWKv+xqaq++C5kQDH4OOCM8e0a0VdAYehVYXN9aOlMQJug9z4nwu8jhaqI HTvt89Imx5YsfMlACfFnA5zRPVn9gh54Enyi4PxvVuvdOLe1whhSlXkOHfri2UUZNJ45 bcSWnsORoKhE+1YzjCAAvseGO/hF12d61Kxdw+d/yardUniKZ8RTKo4URbZIzOudv2Te Si+A== 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:mime-version:content-transfer-encoding; bh=dL8G01lAS0Tcty0K5s1jkDm6uBOV9Qq57fiqyNLrtts=; b=gWo4L0eKb+F8SH69Onxb9blE9zn4q+H8UuKf1mhpJ8ZouWMuBlDtT3BdweaJ7TyHYC JOgBDKZTzcYHjxNiXlUwJTR4KBc3we+h8tCEIxy8LV9d9fed/2EVGD88LtVz9i9BVGu0 MVEbIYh1fMwmFaEq+49rYLWn7hNaucHWaTcnhTnuxT/73dL33DXKFvopdCpAT8b5Zus7 fWhTDWUK92ITCCy1YrQhV2FZD1Epd4gvHxO8X9HYOaSxZcl38w7btMXLXj1apKmbhKMU wFwed6Xbo5YCI+GtKIAqtQbHoJ35DXse/uYm9bV1bqLp5O7/kicL/OmAa6cZzPrsZAne CPNQ== X-Gm-Message-State: AOAM5306mQPPnCe/FUlAVlqNluOoFvuXIPxyElwV1Y2IvPUk5KyWArc4 D0EBvYXQcBjYiOm5wtG8AYJ3CXIkzpmDD3x3 X-Google-Smtp-Source: ABdhPJw5xt1Ehmi7IdkXfMToER+B0DiOj5+kW4IEq98Ai4MN2/ZZWJEVBQqM00mX+QF+AygfU6UXkw== X-Received: by 2002:a05:6512:511:: with SMTP id o17mr8267882lfb.396.1626268878787; Wed, 14 Jul 2021 06:21:18 -0700 (PDT) Return-Path: Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e22sm237931ljl.31.2021.07.14.06.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 06:21:18 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, pete@akeo.ie, jian.j.wang@intel.com, hao.a.wu@intel.com, dandan.bi@intel.com, eric.dong@intel.com, Grzegorz Bernacki Subject: [PATCH v3 1/1] MdeModulePkg: Add BootDiscoveryPolicyUiLib. Date: Wed, 14 Jul 2021 15:21:01 +0200 Message-Id: <20210714132103.1341207-2-gjb@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210714132103.1341207-1-gjb@semihalf.com> References: <20210714132103.1341207-1-gjb@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This library extends Boot Maintenance Menu and allows to select Boot Discovery Policy. When choice is made BootDiscoveryPolicy variable is set. Platform code can use this variable to decide which class of device shall be connected. Signed-off-by: Grzegorz Bernacki --- MdeModulePkg/MdeModulePkg.dec | 6 + MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.inf | 52 +++++++ MdeModulePkg/Include/Guid/BootDiscoveryPolicy.h | 22 +++ MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.c | 160 ++++++++++++++++++++ MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.uni | 18 +++ MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLibStrings.uni | 29 ++++ MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLibVfr.Vfr | 44 ++++++ 7 files changed, 331 insertions(+) create mode 100644 MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.inf create mode 100644 MdeModulePkg/Include/Guid/BootDiscoveryPolicy.h create mode 100644 MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.c create mode 100644 MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.uni create mode 100644 MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLibStrings.uni create mode 100644 MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLibVfr.Vfr diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index ad84421cf3..4e1c291768 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -425,6 +425,9 @@ ## Include/UniversalPayload/SerialPortInfo.h gUniversalPayloadSerialPortInfoGuid = { 0xaa7e190d, 0xbe21, 0x4409, { 0x8e, 0x67, 0xa2, 0xcd, 0xf, 0x61, 0xe1, 0x70 } } + ## GUID used for Boot Discovery Policy FormSet guid and related variables. + gBootDiscoveryPolicyMgrFormsetGuid = { 0x5b6f7107, 0xbb3c, 0x4660, { 0x92, 0xcd, 0x54, 0x26, 0x90, 0x28, 0x0b, 0xbd } } + [Ppis] ## Include/Ppi/AtaController.h gPeiAtaControllerPpiGuid = { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0, 0x7a, 0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }} @@ -1600,6 +1603,9 @@ # @Prompt Console Output Row of Text Setup gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutRow|25|UINT32|0x4000000e + ## Specify the Boot Discovery Policy settings + gEfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy|2|UINT32|0x4000000f + [PcdsFixedAtBuild.AARCH64, PcdsPatchableInModule.AARCH64] gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions|0x20|UINT32|0x0001004c diff --git a/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.inf b/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.inf new file mode 100644 index 0000000000..1fb4d43caa --- /dev/null +++ b/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.inf @@ -0,0 +1,52 @@ +## @file +# Library for BDS phase to use Boot Discovery Policy +# +# Copyright (c) 2021, ARM Ltd. All rights reserved.
+# Copyright (c) 2021, Semihalf All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BootDiscoveryPolicyUiLib + MODULE_UNI_FILE = BootDiscoveryPolicyUiLib.uni + FILE_GUID = BE73105A-B13D-4B57-A41A-463DBD15FE10 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL|DXE_DRIVER UEFI_APPLICATION + CONSTRUCTOR = BootDiscoveryPolicyUiLibConstructor + DESTRUCTOR = BootDiscoveryPolicyUiLibDestructor +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# + +[Sources] + BootDiscoveryPolicyUiLib.c + BootDiscoveryPolicyUiLibStrings.uni + BootDiscoveryPolicyUiLibVfr.Vfr + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + DevicePathLib + BaseLib + UefiRuntimeServicesTableLib + UefiBootServicesTableLib + DebugLib + HiiLib + UefiLib + BaseMemoryLib + +[Guids] + gBootDiscoveryPolicyMgrFormsetGuid + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy ## PRODUCES + +[Depex] + gEfiHiiDatabaseProtocolGuid AND gPcdProtocolGuid diff --git a/MdeModulePkg/Include/Guid/BootDiscoveryPolicy.h b/MdeModulePkg/Include/Guid/BootDiscoveryPolicy.h new file mode 100644 index 0000000000..8eb0968a16 --- /dev/null +++ b/MdeModulePkg/Include/Guid/BootDiscoveryPolicy.h @@ -0,0 +1,22 @@ +/** @file + Definition for structure & defines exported by Boot Discovery Policy UI + + Copyright (c) 2021, ARM Ltd. All rights reserved.
+ Copyright (c) 2021, Semihalf All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _BOOT_DISCOVERY_POLICY_UI_LIB_H_ +#define _BOOT_DISCOVERY_POLICY_UI_LIB_H_ + +#define BDP_CONNECT_MINIMAL 0 /* Do not connect any additional devices */ +#define BDP_CONNECT_NET 1 +#define BDP_CONNECT_ALL 2 + +#define BOOT_DISCOVERY_POLICY_MGR_FORMSET_GUID { 0x5b6f7107, 0xbb3c, 0x4660, { 0x92, 0xcd, 0x54, 0x26, 0x90, 0x28, 0x0b, 0xbd } } + +#define BOOT_DISCOVERY_POLICY_VAR L"BootDiscoveryPolicy" + +#endif diff --git a/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.c b/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.c new file mode 100644 index 0000000000..6814d0bb8f --- /dev/null +++ b/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.c @@ -0,0 +1,160 @@ +/** @file + Boot Discovery Policy UI for Boot Maintenance menu. + + Copyright (c) 2021, ARM Ltd. All rights reserved.
+ Copyright (c) 2021, Semihalf All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/// +/// HII specific Vendor Device Path definition. +/// +typedef struct { + VENDOR_DEVICE_PATH VendorDevicePath; + EFI_DEVICE_PATH_PROTOCOL End; +} HII_VENDOR_DEVICE_PATH; + +extern unsigned char BootDiscoveryPolicyUiLibVfrBin[]; + +EFI_HII_HANDLE mBPHiiHandle = NULL; +EFI_HANDLE mBPDriverHandle = NULL; + +STATIC HII_VENDOR_DEVICE_PATH mVendorDevicePath = { + { + { + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + { + (UINT8)(sizeof (VENDOR_DEVICE_PATH)), + (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8) + } + }, + BOOT_DISCOVERY_POLICY_MGR_FORMSET_GUID + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + (UINT8)(END_DEVICE_PATH_LENGTH), + (UINT8)((END_DEVICE_PATH_LENGTH) >> 8) + } + } +}; + +/** + + Initialize Boot Maintenance Menu library. + + @param ImageHandle The image handle. + @param SystemTable The system table. + + @retval EFI_SUCCESS Install Boot manager menu success. + @retval Other Return error status.gBPDisplayLibGuid + +**/ +EFI_STATUS +EFIAPI +BootDiscoveryPolicyUiLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + UINTN Size; + UINT32 BootDiscoveryPolicy; + + Size = sizeof (UINT32); + Status = gRT->GetVariable ( + BOOT_DISCOVERY_POLICY_VAR, + &gBootDiscoveryPolicyMgrFormsetGuid, + NULL, + &Size, + &BootDiscoveryPolicy + ); + if (EFI_ERROR (Status)) { + Status = PcdSet32S (PcdBootDiscoveryPolicy, PcdGet32 (PcdBootDiscoveryPolicy)); + ASSERT_EFI_ERROR (Status); + } + + Status = gBS->InstallMultipleProtocolInterfaces ( + &mBPDriverHandle, + &gEfiDevicePathProtocolGuid, + &mVendorDevicePath, + NULL + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Publish our HII data + // + mBPHiiHandle = HiiAddPackages ( + &gBootDiscoveryPolicyMgrFormsetGuid, + mBPDriverHandle, + BootDiscoveryPolicyUiLibVfrBin, + BootDiscoveryPolicyUiLibStrings, + NULL + ); + if (mBPHiiHandle == NULL) { + gBS->UninstallMultipleProtocolInterfaces ( + mBPDriverHandle, + &gEfiDevicePathProtocolGuid, + &mVendorDevicePath, + NULL + ); + + return EFI_OUT_OF_RESOURCES; + } + + return EFI_SUCCESS; +} + +/** + Destructor of Boot Maintenance menu library. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The destructor completed successfully. + @retval Other value The destructor did not complete successfully. + +**/ +EFI_STATUS +EFIAPI +BootDiscoveryPolicyUiLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + + if (mBPDriverHandle != NULL) { + gBS->UninstallProtocolInterface ( + mBPDriverHandle, + &gEfiDevicePathProtocolGuid, + &mVendorDevicePath + ); + mBPDriverHandle = NULL; + } + + if (mBPHiiHandle != NULL) { + HiiRemovePackages (mBPHiiHandle); + mBPHiiHandle = NULL; + } + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.uni b/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.uni new file mode 100644 index 0000000000..eea3ca6c8d --- /dev/null +++ b/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.uni @@ -0,0 +1,18 @@ +// /** @file +// Boot Discovery Policy UI module. +// +// Copyright (c) 2021, ARM Ltd. All rights reserved.
+// Copyright (c) 2021, Semihalf All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT +#language en-US "Boot Discovery Policy UI module." + +#string STR_MODULE_DESCRIPTION +#language en-US "Boot Discovery Policy UI module." + + diff --git a/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLibStrings.uni b/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLibStrings.uni new file mode 100644 index 0000000000..736011c9bb --- /dev/null +++ b/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLibStrings.uni @@ -0,0 +1,29 @@ +// *++ +// +// Copyright (c) 2021, ARM Ltd. All rights reserved.
+// Copyright (c) 2021, Semihalf All rights reserved.
+// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// Module Name: +// +// BootDiscoveryPolicyUiLibStrings.uni +// +// Abstract: +// +// String definitions for Boot Discovery Policy UI. +// +// --*/ + +/=# + + +#langdef en-US "English" + +#string STR_FORM_BDP_MAIN_TITLE #language en-US "Boot Discovery Policy" + +#string STR_FORM_BDP_CONN_MIN #language en-US "Minimal" + +#string STR_FORM_BDP_CONN_NET #language en-US "Connect Network Devices" + +#string STR_FORM_BDP_CONN_ALL #language en-US "Connect All Devices" + diff --git a/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLibVfr.Vfr b/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLibVfr.Vfr new file mode 100644 index 0000000000..0de87ec34f --- /dev/null +++ b/MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLibVfr.Vfr @@ -0,0 +1,44 @@ +///** @file +// +// Formset for Boot Discovery Policy UI +// +// Copyright (c) 2021, ARM Ltd. All rights reserved.
+// Copyright (c) 2021, Semihalf All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +//**/ + +#include +#include "Guid/BootDiscoveryPolicy.h" +#include + +typedef struct { + UINT32 BootDiscoveryPolicy; +} BOOT_DISCOVERY_POLICY_VARSTORE_DATA; + +formset + guid = BOOT_DISCOVERY_POLICY_MGR_FORMSET_GUID, + title = STRING_TOKEN(STR_FORM_BDP_MAIN_TITLE), + help = STRING_TOKEN(STR_FORM_BDP_MAIN_TITLE), + classguid = EFI_IFR_BOOT_MAINTENANCE_GUID, + + efivarstore BOOT_DISCOVERY_POLICY_VARSTORE_DATA, + attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + name = BootDiscoveryPolicy, + guid = BOOT_DISCOVERY_POLICY_MGR_FORMSET_GUID; + + form formid = 0x0001, + title = STRING_TOKEN(STR_FORM_BDP_MAIN_TITLE); + + oneof varid = BootDiscoveryPolicy.BootDiscoveryPolicy, + prompt = STRING_TOKEN(STR_FORM_BDP_MAIN_TITLE), + help = STRING_TOKEN(STR_FORM_BDP_MAIN_TITLE), + flags = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED, + option text = STRING_TOKEN(STR_FORM_BDP_CONN_MIN), value = BDP_CONNECT_MINIMAL, flags = DEFAULT; + option text = STRING_TOKEN(STR_FORM_BDP_CONN_NET), value = BDP_CONNECT_NET, flags = 0; + option text = STRING_TOKEN(STR_FORM_BDP_CONN_ALL), value = BDP_CONNECT_ALL, flags = 0; + endoneof; + + endform; +endformset; -- 2.25.1