Skip to content

Commit

Permalink
Platform/RaspberryPi: Enable Boot Discovery Policy.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Sunny Wang <[email protected]>
Reviewed-by: Pete Batard <[email protected]>
Tested-by: Pete Batard <[email protected]>
  • Loading branch information
semihalf-bernacki-grzegorz authored and ardbiesheuvel committed Aug 3, 2021
1 parent 73ccc21 commit 2e87ce8
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
91 changes: 91 additions & 0 deletions Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -19,10 +20,12 @@
#include <Library/UefiBootManagerLib.h>
#include <Library/UefiLib.h>
#include <Library/PrintLib.h>
#include <Protocol/BootManagerPolicy.h>
#include <Protocol/DevicePath.h>
#include <Protocol/EsrtManagement.h>
#include <Protocol/GraphicsOutput.h>
#include <Protocol/LoadedImage.h>
#include <Guid/BootDiscoveryPolicy.h>
#include <Guid/EventGroup.h>
#include <Guid/TtyTerm.h>
#include <ConfigVars.h>
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,25 @@
gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType

[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut
gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
gRaspberryPiTokenSpaceGuid.PcdBootPolicy

[Guids]
gBootDiscoveryPolicyMgrFormsetGuid
gEfiFileInfoGuid
gEfiFileSystemInfoGuid
gEfiFileSystemVolumeLabelInfoIdGuid
gEfiEndOfDxeEventGroupGuid
gEfiTtyTermGuid
gUefiShellFileGuid
gEfiEventExitBootServicesGuid
gEfiBootManagerPolicyNetworkGuid
gEfiBootManagerPolicyConnectAllGuid

[Protocols]
gEfiBootManagerPolicyProtocolGuid
gEfiDevicePathProtocolGuid
gEfiGraphicsOutputProtocolGuid
gEfiLoadedImageProtocolGuid
Expand Down
3 changes: 3 additions & 0 deletions Platform/RaspberryPi/RPi4/RPi4.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
#
Expand Down Expand Up @@ -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
Expand All @@ -690,6 +692,7 @@
Platform/RaspberryPi/Drivers/LogoDxe/LogoDxe.inf
MdeModulePkg/Application/UiApp/UiApp.inf {
<LibraryClasses>
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
Expand Down
1 change: 1 addition & 0 deletions Platform/RaspberryPi/RPi4/RPi4.fdf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e87ce8

Please sign in to comment.