From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by mx.groups.io with SMTP id smtpd.web11.18880.1627906733979059570 for ; Mon, 02 Aug 2021 05:18:54 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=EK9+7Zia; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.208.172, mailfrom: gjb@semihalf.com) Received: by mail-lj1-f172.google.com with SMTP id u20so23702208ljo.0 for ; Mon, 02 Aug 2021 05:18:53 -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=dCi9VmyAxST2vvLyiJWtCSvidCcUBjPtWFLXFVLNLVI=; b=EK9+7ZiaoJAB4fFQ5K41WDzd8oBfZsYv/LPuFTiLNvoTvDFvy7HASEHWaWQfOA8m+w 5yZHvQkvrmf/ZrJtx2HzSHNhrSvWPILJAPFuE++LOtdYwj7gmX0D0g46XnuSTHwOG/OF +7IXYj049yK3GQU8RhMCR8jO5k+VSdWAwxjYwJlh6J3ulUWlrxpilFZE9zQ1Mmbk4bLG 5ByIByINLIvMec+3FP4Yta4TTx9uaw2CZkHwV/sRCwkh63PJnJej17QB81ItygtCzMsL xC3Lu/j9uCzS8RhVWez3tBHEIhsmjEzfhq+bDfVPopks8mRDEpAu8Ngxpq2C3xcOsgu7 AwXw== 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=dCi9VmyAxST2vvLyiJWtCSvidCcUBjPtWFLXFVLNLVI=; b=HtfKLoRlprRlpyu8uGyRWTfFc7h4FrkownibeHBAk0zjA2DFFm9DM1FwLn8ChejQ5w EIRlnLfep/gtryD5n7uHLpxVgvBBuUURxC0bIW9cdFsAlfi51GjYiGhj5bmiB9k3R2xb oCZwINbUVh8JCm/ISlUKpwRNlTGcQyVsp87tO6qu7azWgx3eooSuRreWjpgJJYERvlbv gEK7gWFyMIES/NBZ2l0cVbU9J7w1xqIDup6MbMzeBspKWgN20nv/w6HXl5ffS1eORwXx Mgiwb//DKIKG2CqmgX2SAYJVgqDGmx0qUQZUI4sv6ZdW5dclguabS2HRgZmC+8ksh2+A cJEw== X-Gm-Message-State: AOAM533SD5rWymMmuxSN/iA+W7O8xryElegCNktSDkDd0IT/jNJ1gyjF m8SYw8Fp39qcRoe4gun5Q/4hDbJHxtpqZkMU X-Google-Smtp-Source: ABdhPJxLx05d143OD39jE02lv53NxSw38fsksHi0UoznJlNC3L7VY7+2rDGQizveKrsEFYuXSrNz6g== X-Received: by 2002:a05:651c:1108:: with SMTP id d8mr11207904ljo.127.1627906732137; Mon, 02 Aug 2021 05:18:52 -0700 (PDT) Return-Path: Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id p14sm647879lfa.117.2021.08.02.05.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 05:18:51 -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 , Sunny Wang Subject: [edk2-platforms PATCH v5 1/2] Platform/RaspberryPi: Enable Boot Discovery Policy. Date: Mon, 2 Aug 2021 14:18:36 +0200 Message-Id: <20210802121837.2913575-3-gjb@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210802121837.2913575-1-gjb@semihalf.com> References: <20210802121837.2913575-1-gjb@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This commit modify platform boot to check the value of BootDiscoveryPolicy variable and use BootPolicyManager Protocol to connect devices specified by the variable. Signed-off-by: Grzegorz Bernacki Reviewed-by: Sunny Wang --- Platform/RaspberryPi/RPi4/RPi4.dsc | 3 + Platform/RaspberryPi/RPi4/RPi4.fdf | 1 + Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 5 ++ Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c | 91 ++++++++++++++++++++ 4 files changed, 100 insertions(+) diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4/RPi4.dsc index fd73c4d14b..8b9beac64a 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -555,6 +555,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn|L"Columns"|gRaspberryPiTokenSpaceGuid|0x0|80 gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutRow|L"Rows"|gRaspberryPiTokenSpaceGuid|0x0|25 gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow|L"Rows"|gRaspberryPiTokenSpaceGuid|0x0|25 + gEfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy|L"BootDiscoveryPolicy"|gBootDiscoveryPolicyMgrFormsetGuid|0 [PcdsDynamicDefault.common] # @@ -682,6 +683,7 @@ # # Bds # + MdeModulePkg/Universal/BootManagerPolicyDxe/BootManagerPolicyDxe.inf MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf @@ -690,6 +692,7 @@ Platform/RaspberryPi/Drivers/LogoDxe/LogoDxe.inf MdeModulePkg/Application/UiApp/UiApp.inf { + NULL|MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.inf NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf NULL|Platform/RaspberryPi/Library/PlatformUiAppLib/PlatformUiAppLib.inf diff --git a/Platform/RaspberryPi/RPi4/RPi4.fdf b/Platform/RaspberryPi/RPi4/RPi4.fdf index 1e13909a57..371197a93e 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.fdf +++ b/Platform/RaspberryPi/RPi4/RPi4.fdf @@ -253,6 +253,7 @@ READ_LOCK_STATUS = TRUE # # Bds # + INF MdeModulePkg/Universal/BootManagerPolicyDxe/BootManagerPolicyDxe.inf INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf diff --git a/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index fbf510ab96..4ef2f791ae 100644 --- a/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -61,11 +61,13 @@ gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType [Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut gRaspberryPiTokenSpaceGuid.PcdSdIsArasan gRaspberryPiTokenSpaceGuid.PcdBootPolicy [Guids] + gBootDiscoveryPolicyMgrFormsetGuid gEfiFileInfoGuid gEfiFileSystemInfoGuid gEfiFileSystemVolumeLabelInfoIdGuid @@ -73,8 +75,11 @@ gEfiTtyTermGuid gUefiShellFileGuid gEfiEventExitBootServicesGuid + gEfiBootManagerPolicyNetworkGuid + gEfiBootManagerPolicyConnectAllGuid [Protocols] + gEfiBootManagerPolicyProtocolGuid gEfiDevicePathProtocolGuid gEfiGraphicsOutputProtocolGuid gEfiLoadedImageProtocolGuid diff --git a/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c b/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c index d081fdae63..d944d1a38d 100644 --- a/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c +++ b/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c @@ -6,6 +6,7 @@ * Copyright (c) 2015-2016, Red Hat, Inc. * Copyright (c) 2014-2021, ARM Ltd. All rights reserved. * Copyright (c) 2004-2016, Intel Corporation. All rights reserved. + * Copyright (c) 2021, Semihalf All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent * @@ -19,10 +20,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -598,6 +601,89 @@ PlatformBootManagerBeforeConsole ( FilterAndProcess (&gEfiUsb2HcProtocolGuid, NULL, Connect); } +/** + Connect device specified by BootDiscoverPolicy variable and refresh + 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)); + DiscoveryPolicy = PcdGet32 (PcdBootDiscoveryPolicy); + 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_ERROR, "%a - Failed to locate gEfiBootManagerPolicyProtocolGuid - %r\n", __FUNCTION__, Status)); + 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: @@ -644,6 +730,11 @@ PlatformBootManagerAfterConsole ( DEBUG ((DEBUG_INFO, "Boot Policy is Fast Boot. Skip connecting all devices\n")); } + Status = BootDiscoveryPolicyHandler (); + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_INFO, "Error applying Boot Discovery Policy:%r\n", Status)); + } + Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL, (VOID**)&EsrtManagement); if (!EFI_ERROR (Status)) { EsrtManagement->SyncEsrtFmp (); -- 2.25.1