From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by mx.groups.io with SMTP id smtpd.web11.2355.1628238648524628310 for ; Fri, 06 Aug 2021 01:30:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=O2ffy6J+; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.208.169, mailfrom: gjb@semihalf.com) Received: by mail-lj1-f169.google.com with SMTP id x7so10798658ljn.10 for ; Fri, 06 Aug 2021 01:30:48 -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=4TMZtFlj6QHxwdMVv+rItMvnJ6hO1jWkS32hh8Ygbik=; b=O2ffy6J+UyCTxRFmN95QDZ4pVuP+SKbqbHdGRcqSBox8oP0uO5J37NyLlMaU8WC44N kAg8MsBBWvQwdjbwjQb4FvLJy3HBqQCMHFYgPozf2nnc1BMJG38Ot6xpZIWDpyp4b8a5 0aK6sfau8qQA0pw4LaIfLF63/09SyBNbkm+5KULgVCOxM9MMSxlAycTa1UL7dLpbe+xZ rhlcMSjc0ZR/gtRsxewuS49oy6e/PYSRRIDIpzIPSAssAtWnCdZP77VoqjU3578nUu0m /TuKC8Hdv+o8jViZAWaUonqEC5TlVivj44HU66xOW/wAfjkC3q9uM0PCPk7ZWlbxvNPk jkaQ== 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=4TMZtFlj6QHxwdMVv+rItMvnJ6hO1jWkS32hh8Ygbik=; b=QL40tjXH9VMSWWE/NXPYLT8bNa8DBuGh7I1IPievqE/BYLm59Jc3yqDTt8byO5XT2l QafjmL9rL3XpIa+t3/3GMEzgj3n7HCcQcv/KZMj6VMkCq/sGLi7qBNWphdM8BmFWE/CX nJRSYKbYiSHTc44QqcHQo+OKuHZQe3pQcqceKrz6y6GIF2h1kC4J44GnPTdN4yS7AK5t BdafeomfXL6askqgqF55WfMhoAg9rS/eBp6n4H8Pa/kEs2v+mHYiqC+AUfLwb8AbvgtO PwOmWQlr0qDGdf2BSoI4WAMrRD87mTROCiU/6pNUxdNSPh4UEcG2v2k4d7gu+oR3Enj3 kGhw== X-Gm-Message-State: AOAM5312jVdUGFE4sCAnm0AapMPpsXAjlvao/+eCTXBzNitFQzPR8zWV ptyZdl9AC7GuiqN/kUR3p3IPBOmc6XZGHw== X-Google-Smtp-Source: ABdhPJxGWbc57ayLX6B8huFk8UD63jx9x0/9nMZhCxJTQDC5bskKTjmuxUQlZMMkut9DaeySQvbuxA== X-Received: by 2002:a2e:b0c8:: with SMTP id g8mr3213920ljl.444.1628238646375; Fri, 06 Aug 2021 01:30:46 -0700 (PDT) Return-Path: Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id t30sm764185lft.152.2021.08.06.01.30.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Aug 2021 01:30:46 -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, Grzegorz Bernacki Subject: [PATCH] ArmPkg: Enable boot discovery policy for ARM package. Date: Fri, 6 Aug 2021 10:30:26 +0200 Message-Id: <20210806083026.3295056-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 --- ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 5 + ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c | 96 +++++++++++++++++++- 2 files changed, 100 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..4332c45bb7 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,91 @@ 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 succesfully or connection + not required. + @retval others Return values from GetVariable(), LocateProtocol() + and ConnectDeviceClass(). +--*/ +STATIC +EFI_STATUS +BootDiscoveryPolicyHandler ( + VOID + ) +{ + EFI_STATUS Status; + UINT32 DiscoveryPolicy; + 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) { + Status = PcdSet32S (PcdBootDiscoveryPolicy, PcdGet32 (PcdBootDiscoveryPolicy)); + if (Status == EFI_NOT_FOUND) { + return EFI_SUCCESS; + } else if (EFI_ERROR (Status)) { + return Status; + } + DiscoveryPolicy = PcdGet32 (PcdBootDiscoveryPolicy); + } 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; + } + + EfiBootManagerRefreshAllBootOption(); + + return EFI_SUCCESS; +} + /** Do the platform specific action after the console is ready Possible things that can be done in PlatformBootManagerAfterConsole: @@ -753,6 +841,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