From nobody Wed May 8 21:03:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+79951+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+79951+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1630325303; cv=none; d=zohomail.com; s=zohoarc; b=C9X+qVPTN/ScotUOvjLhhFfU3ztodW2848TK//PJvpr6j43kGh3YMLCUzuuarqJbKLtxkYTerfzgApv/uHNPFPayvwPP+Sb95rMHD7cEy7RWGvvr5sFpEk1EN0ukdfIbUdlU/JT7w9VkNeFMxG3GKJTwoIJ9KudVCK8ux+OaNp0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630325303; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=7IlY5uQwkm5yDROJVTyyIRV2FZpA1D9/+0krGVVcU0I=; b=Zn4QuKzs0bjaOHQsJcSj1NLRZprxFuaoRZpRTePRZGQV3bPjXu4BangElVNpBZSQYjhaSGnIgJ/KQORxDwYqNsU0wth2HyISmdyXPHB+aKEP/Kb0n19gHYVLJH94Ok7nTelyOC5oitLgyoAAvuumpTinIB0MXZv/0qQAsh1kJ8k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+79951+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1630325303540424.84331139752305; Mon, 30 Aug 2021 05:08:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Hu4cYY1788612xBF6ZBJeMEU; Mon, 30 Aug 2021 05:08:23 -0700 X-Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by mx.groups.io with SMTP id smtpd.web11.15913.1630325301923891720 for ; Mon, 30 Aug 2021 05:08:22 -0700 X-Received: by mail-lj1-f177.google.com with SMTP id y6so25515825lje.2 for ; Mon, 30 Aug 2021 05:08:21 -0700 (PDT) X-Gm-Message-State: 2vqCqzX4Z8rZkKjqX4rlJqKHx1787277AA= X-Google-Smtp-Source: ABdhPJztjNmDIlXpQPDxPQkNhNz+DsCq9BJ+y/mmqn+o++KyAewjryRQe70I+/qjzlPyqf7FtCGFwg== X-Received: by 2002:a2e:2283:: with SMTP id i125mr20688843lji.485.1630325299903; Mon, 30 Aug 2021 05:08:19 -0700 (PDT) X-Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id z13sm1494963lfu.0.2021.08.30.05.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 05:08:19 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, sami.mujawar@arm.com, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, Grzegorz Bernacki , Sunny Wang Subject: [edk2-devel] [PATCH v3] ArmPkg: Enable boot discovery policy for ARM package. Date: Mon, 30 Aug 2021 14:08:05 +0200 Message-Id: <20210830120805.175714-1-gjb@semihalf.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gjb@semihalf.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1630325303; bh=nKiDiEV59A7IVrJ+Rz5KVQdYJb5Ub4K+YWfHEMKvabM=; h=Cc:Date:From:Reply-To:Subject:To; b=PVKolxNayy5ayT9HFj8jkeBt5AO5ti+sBg+ux8uExrO79Xo8kOYk8Af5zfLzMG9PWEH iilrzVwvMnnfAwcm2+CrtAJ4U8Qn+/N+WQrf7TOG1PaMYe3Ccm1icoSbAj2y6xdDu7F/P uoPR25WMVClzMOUhAShHtMw6RHT5TAnpcq8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1630325304179100001 Content-Type: text/plain; charset="utf-8" This commit adds code which check BootDiscoveryPolicy variable and calls Boot Policy Manager Protocol to connect device specified by the variable. To enable that mechanism for platform EfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy PCD must be added to DSC file and BootDiscoveryPolicyUiLib should be added to UiApp libraries. Signed-off-by: Grzegorz Bernacki Reviewed-by: Sunny Wang Reviewed-by: Sami Mujawar --- Notes: v2: - fix error from CI =20 v3: - use local variable DiscoveryPolicy to initialize BootDiscoveryPolicy - coding style fixes - run EfiBootManagerRefreshAllBootOption () only if BootDiscoveryPolicy ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 5 + ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c | 118 +++= ++++++++++++++++- 2 files changed, 122 insertions(+), 1 deletion(-) diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.i= nf b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index 353d7a967b..86751b45f8 100644 --- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -65,11 +65,15 @@ =20 [Pcd] gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut + gEfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy =20 [Guids] + gBootDiscoveryPolicyMgrFormsetGuid gEdkiiNonDiscoverableEhciDeviceGuid gEdkiiNonDiscoverableUhciDeviceGuid gEdkiiNonDiscoverableXhciDeviceGuid + gEfiBootManagerPolicyNetworkGuid + gEfiBootManagerPolicyConnectAllGuid gEfiFileInfoGuid gEfiFileSystemInfoGuid gEfiFileSystemVolumeLabelInfoIdGuid @@ -79,6 +83,7 @@ =20 [Protocols] gEdkiiNonDiscoverableDeviceProtocolGuid + gEfiBootManagerPolicyProtocolGuid gEfiDevicePathProtocolGuid gEfiGraphicsOutputProtocolGuid gEfiLoadedImageProtocolGuid diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmPkg/Li= brary/PlatformBootManagerLib/PlatformBm.c index 5ceb23d822..1e4020487a 100644 --- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c +++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c @@ -2,9 +2,10 @@ Implementation for PlatformBootManagerLib library class interfaces. =20 Copyright (C) 2015-2016, Red Hat, Inc. - Copyright (c) 2014 - 2019, ARM Ltd. All rights reserved.
+ Copyright (c) 2014 - 2021, ARM Ltd. All rights reserved.
Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
Copyright (c) 2016, Linaro Ltd. All rights reserved.
+ Copyright (c) 2021, Semihalf All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -19,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -703,6 +706,113 @@ HandleCapsules ( =20 #define VERSION_STRING_PREFIX L"Tianocore/EDK2 firmware version " =20 +/** + This functions checks the value of BootDiscoverPolicy variable and + connect devices of class specified by that variable. Then it refreshes + Boot order for newly discovered boot device. + + @retval EFI_SUCCESS Devices connected successfully or connection + not required. + @retval others Return values from GetVariable(), LocateProtocol() + and ConnectDeviceClass(). +**/ +STATIC +EFI_STATUS +BootDiscoveryPolicyHandler ( + VOID + ) +{ + EFI_STATUS Status; + UINT32 DiscoveryPolicy; + UINT32 DiscoveryPolicyOld; + UINTN Size; + EFI_BOOT_MANAGER_POLICY_PROTOCOL *BMPolicy; + EFI_GUID *Class; + + Size =3D sizeof (DiscoveryPolicy); + Status =3D gRT->GetVariable ( + BOOT_DISCOVERY_POLICY_VAR, + &gBootDiscoveryPolicyMgrFormsetGuid, + NULL, + &Size, + &DiscoveryPolicy + ); + if (Status =3D=3D EFI_NOT_FOUND) { + DiscoveryPolicy =3D PcdGet32 (PcdBootDiscoveryPolicy); + Status =3D PcdSet32S (PcdBootDiscoveryPolicy, DiscoveryPolicy); + if (Status =3D=3D EFI_NOT_FOUND) { + return EFI_SUCCESS; + } else if (EFI_ERROR (Status)) { + return Status; + } + } else if (EFI_ERROR (Status)) { + return Status; + } + + if (DiscoveryPolicy =3D=3D BDP_CONNECT_MINIMAL) { + return EFI_SUCCESS; + } + + switch (DiscoveryPolicy) { + case BDP_CONNECT_NET: + Class =3D &gEfiBootManagerPolicyNetworkGuid; + break; + case BDP_CONNECT_ALL: + Class =3D &gEfiBootManagerPolicyConnectAllGuid; + break; + default: + DEBUG (( + DEBUG_INFO, + "%a - Unexpected DiscoveryPolicy (0x%x). Run Minimal Discovery Pol= icy\n", + __FUNCTION__, + DiscoveryPolicy + )); + return EFI_SUCCESS; + } + + Status =3D gBS->LocateProtocol ( + &gEfiBootManagerPolicyProtocolGuid, + NULL, + (VOID **)&BMPolicy + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a - Failed to locate gEfiBootManagerPolicyProtoc= olGuid." + "Driver connect will be skipped.\n", __FUNCTION__)); + return Status; + } + + Status =3D BMPolicy->ConnectDeviceClass (BMPolicy, Class); + if (EFI_ERROR (Status)){ + DEBUG ((DEBUG_ERROR, "%a - ConnectDeviceClass returns - %r\n", __FUNCT= ION__, Status)); + return Status; + } + + // + // Refresh Boot Options if Boot Discovery Policy has been changed + // + Size =3D sizeof (DiscoveryPolicyOld); + Status =3D gRT->GetVariable ( + BOOT_DISCOVERY_POLICY_OLD_VAR, + &gBootDiscoveryPolicyMgrFormsetGuid, + NULL, + &Size, + &DiscoveryPolicyOld + ); + if ((Status =3D=3D EFI_NOT_FOUND) || (DiscoveryPolicyOld !=3D DiscoveryP= olicy)) { + EfiBootManagerRefreshAllBootOption (); + + Status =3D gRT->SetVariable ( + BOOT_DISCOVERY_POLICY_OLD_VAR, + &gBootDiscoveryPolicyMgrFormsetGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_A= CCESS, + sizeof (DiscoveryPolicyOld), + &DiscoveryPolicy + ); + } + + return EFI_SUCCESS; +} + /** Do the platform specific action after the console is ready Possible things that can be done in PlatformBootManagerAfterConsole: @@ -753,6 +863,12 @@ PlatformBootManagerAfterConsole ( } } =20 + // + // Connect device specified by BootDiscoverPolicy variable and + // refresh Boot order for newly discovered boot devices + // + BootDiscoveryPolicyHandler (); + // // On ARM, there is currently no reason to use the phased capsule // update approach where some capsules are dispatched before EndOfDxe --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#79951): https://edk2.groups.io/g/devel/message/79951 Mute This Topic: https://groups.io/mt/85249148/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-