From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=Omu/iB46; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.208.177, mailfrom: gjb@semihalf.com) Received: by mail-lj1-f177.google.com with SMTP id y6so25515825lje.2 for ; Mon, 30 Aug 2021 05:08:21 -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:mime-version :content-transfer-encoding; bh=OLHkhEpM0DR8oaAEHsKWQdROztGaDjbTKm8K/q/jLXI=; b=Omu/iB46SEBBDO/ba+9VSbNZITUW3wHRinWK2nBsqy5ULYPlo8l1H0bIdAhQmM+HVo 9ZRlUN/L9kOnVSZc4F/pXQbnVh6q4ZW4hStin270BtNSBDwUROECJvtUZ8Y+yO47dprq HdJEk5BgH2RTa4FuhYkOyMfME29VIs49Ydj1OevyINXq7NEBMdVdNVJ9PzKD81yGicKu 1iSszE4Sll7FVo8/PdcS/Poqq8ta/vZ3w2AbO2/VlRGQ5HsLtS1Qpk5+VkoBQm44d9pJ q1U9iLAZXE0vGWcXIZp7xn0deujNkzZKQW5N9292ttPDymlorrN2HetUK47IpyV3++sn FkYw== 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:mime-version :content-transfer-encoding; bh=OLHkhEpM0DR8oaAEHsKWQdROztGaDjbTKm8K/q/jLXI=; b=DDzTVFNhcXxDY0w0TlSanSDxIvhPQHU9Au6dVCkTAvP2kfffHkMy6TB7Y5Gb08zac5 y8v8UOIAcm90pG8dzfCY0m66T980MXh4iXK1EJ4xTQiFSvKC/PtYOXtodCJ2uzWZJWg7 8F7VcULJzNUeJse9vL/6gXKGesQZCZKQ5FJESX6ajGv+tdb7w/OxwOiNpCWx4NVulTJJ BjfaZ3d58u9eo/HpkAf47FrKu723Wwu2k713ZnRtJeamr3WSIqJOt5OwFUVwAKfcxP+0 XcnAHW2VN/Tn2Ra95rLAuxX/skIYiFSnMPa17C/Il4nKuIlDR/6gNe9mnEx1MEXlCVqE 99Rg== X-Gm-Message-State: AOAM531mPagKf23dSCVYYS1Z8ujoetKFco/ScPbEwJC/rjjZGSz56KnQ e1f4woNf6QhHndJ1K37PfWqi2Ho5rQjgog== 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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.inf 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 @@ [Pcd] gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut + gEfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy [Guids] + gBootDiscoveryPolicyMgrFormsetGuid gEdkiiNonDiscoverableEhciDeviceGuid gEdkiiNonDiscoverableUhciDeviceGuid gEdkiiNonDiscoverableXhciDeviceGuid + gEfiBootManagerPolicyNetworkGuid + gEfiBootManagerPolicyConnectAllGuid gEfiFileInfoGuid gEfiFileSystemInfoGuid gEfiFileSystemVolumeLabelInfoIdGuid @@ -79,6 +83,7 @@ [Protocols] gEdkiiNonDiscoverableDeviceProtocolGuid + gEfiBootManagerPolicyProtocolGuid gEfiDevicePathProtocolGuid gEfiGraphicsOutputProtocolGuid gEfiLoadedImageProtocolGuid diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmPkg/Library/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. 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.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -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 ( #define VERSION_STRING_PREFIX L"Tianocore/EDK2 firmware version " +/** + 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 = sizeof (DiscoveryPolicy); + Status = gRT->GetVariable ( + BOOT_DISCOVERY_POLICY_VAR, + &gBootDiscoveryPolicyMgrFormsetGuid, + NULL, + &Size, + &DiscoveryPolicy + ); + if (Status == EFI_NOT_FOUND) { + DiscoveryPolicy = PcdGet32 (PcdBootDiscoveryPolicy); + Status = PcdSet32S (PcdBootDiscoveryPolicy, DiscoveryPolicy); + if (Status == EFI_NOT_FOUND) { + return EFI_SUCCESS; + } else if (EFI_ERROR (Status)) { + return Status; + } + } else if (EFI_ERROR (Status)) { + return Status; + } + + if (DiscoveryPolicy == BDP_CONNECT_MINIMAL) { + return EFI_SUCCESS; + } + + switch (DiscoveryPolicy) { + case BDP_CONNECT_NET: + Class = &gEfiBootManagerPolicyNetworkGuid; + break; + case BDP_CONNECT_ALL: + Class = &gEfiBootManagerPolicyConnectAllGuid; + break; + default: + DEBUG (( + DEBUG_INFO, + "%a - Unexpected DiscoveryPolicy (0x%x). Run Minimal Discovery Policy\n", + __FUNCTION__, + DiscoveryPolicy + )); + return EFI_SUCCESS; + } + + Status = gBS->LocateProtocol ( + &gEfiBootManagerPolicyProtocolGuid, + NULL, + (VOID **)&BMPolicy + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a - Failed to locate gEfiBootManagerPolicyProtocolGuid." + "Driver connect will be skipped.\n", __FUNCTION__)); + return Status; + } + + Status = BMPolicy->ConnectDeviceClass (BMPolicy, Class); + if (EFI_ERROR (Status)){ + DEBUG ((DEBUG_ERROR, "%a - ConnectDeviceClass returns - %r\n", __FUNCTION__, Status)); + return Status; + } + + // + // Refresh Boot Options if Boot Discovery Policy has been changed + // + Size = sizeof (DiscoveryPolicyOld); + Status = gRT->GetVariable ( + BOOT_DISCOVERY_POLICY_OLD_VAR, + &gBootDiscoveryPolicyMgrFormsetGuid, + NULL, + &Size, + &DiscoveryPolicyOld + ); + if ((Status == EFI_NOT_FOUND) || (DiscoveryPolicyOld != DiscoveryPolicy)) { + EfiBootManagerRefreshAllBootOption (); + + Status = gRT->SetVariable ( + BOOT_DISCOVERY_POLICY_OLD_VAR, + &gBootDiscoveryPolicyMgrFormsetGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + 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 ( } } + // + // 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 -- 2.25.1