Skip to content

Commit

Permalink
Platform/RPi: Make Device Tree provision a runtime (BIOS setup) choice
Browse files Browse the repository at this point in the history
With this and the previous commit, ACPI_BASIC_MODE_ENABLE becomes
superfluous so remove it.

New option defaults to enabled on Pi 3, disabled on Pi 4.

Signed-off-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
  • Loading branch information
pbatard authored and Ard Biesheuvel committed Mar 3, 2020
1 parent 874750a commit da7cb41
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 19 deletions.
8 changes: 8 additions & 0 deletions Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ SetupVariables (
PcdSet32 (PcdRamLimitTo3GB, 0);
}

Size = sizeof (UINT32);
Status = gRT->GetVariable (L"OptDeviceTree",
&gConfigDxeFormSetGuid,
NULL, &Size, &Var32);
if (EFI_ERROR (Status)) {
PcdSet32 (PcdOptDeviceTree, PcdGet32 (PcdOptDeviceTree));
}

Size = sizeof (UINT32);
Status = gRT->GetVariable (L"SdIsArasan",
&gConfigDxeFormSetGuid,
Expand Down
1 change: 1 addition & 0 deletions Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot
gRaspberryPiTokenSpaceGuid.PcdOptDeviceTree
gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB
gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB

Expand Down
5 changes: 5 additions & 0 deletions Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
#string STR_ADVANCED_3GB_OFF #language en-US "Disabled"
#string STR_ADVANCED_3GB_ON #language en-US "Enabled"

#string STR_ADVANCED_DT_PROMPT #language en-US "Device Tree"
#string STR_ADVANCED_DT_HELP #language en-US "Disable this option to force OSes such as GNU/Linux to use ACPI"
#string STR_ADVANCED_DT_OFF #language en-US "Disabled (Force ACPI)"
#string STR_ADVANCED_DT_ON #language en-US "Enabled"

/*
* MMC/SD configuration.
*/
Expand Down
21 changes: 21 additions & 0 deletions Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ typedef struct {
UINT32 Enabled;
} ADVANCED_RAM_LIMIT_TO_3GB_VARSTORE_DATA;

typedef struct {
/*
* 0 - Do not provide a Device Tree to the OS
* 1 - Provide a Device Tree to the OS
*/
UINT32 Enabled;
} ADVANCED_DEVICE_TREE_VARSTORE_DATA;

typedef struct {
/*
* 0 - Don't disable multi-block.
Expand Down Expand Up @@ -162,6 +170,11 @@ formset
name = RamLimitTo3GB,
guid = CONFIGDXE_FORM_SET_GUID;

efivarstore ADVANCED_DEVICE_TREE_VARSTORE_DATA,
attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
name = OptDeviceTree,
guid = CONFIGDXE_FORM_SET_GUID;

efivarstore MMC_DISMULTI_VARSTORE_DATA,
attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
name = MmcDisableMulti,
Expand Down Expand Up @@ -279,6 +292,14 @@ formset
option text = STRING_TOKEN(STR_ADVANCED_3GB_ON), value = 1, flags = 0;
endoneof;
endif;

oneof varid = OptDeviceTree.Enabled,
prompt = STRING_TOKEN(STR_ADVANCED_DT_PROMPT),
help = STRING_TOKEN(STR_ADVANCED_DT_HELP),
flags = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
option text = STRING_TOKEN(STR_ADVANCED_DT_OFF), value = 0, flags = 0;
option text = STRING_TOKEN(STR_ADVANCED_DT_ON), value = 1, flags = DEFAULT;
endoneof;
endform;

form formid = 0x1003,
Expand Down
5 changes: 5 additions & 0 deletions Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ FdtDxeInitialize (
UINT32 BoardRevision;
BOOLEAN Internal;

if (PcdGet32 (PcdOptDeviceTree) == 0) {
DEBUG ((DEBUG_INFO, "Device Tree disabled per user configuration\n"));
return EFI_SUCCESS;
}

Status = gBS->LocateProtocol (&gRaspberryPiFirmwareProtocolGuid, NULL,
(VOID**)&mFwProtocol);
ASSERT_EFI_ERROR (Status);
Expand Down
3 changes: 3 additions & 0 deletions Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@

[FixedPcd]
gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress

[Pcd]
gRaspberryPiTokenSpaceGuid.PcdOptDeviceTree
5 changes: 5 additions & 0 deletions Platform/RaspberryPi/RPi3/RPi3.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@
gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|L"RamMoreThan3GB"|gConfigDxeFormSetGuid|0x0|0
gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|L"RamLimitTo3GB"|gConfigDxeFormSetGuid|0x0|0

#
# Device Tree
#
gRaspberryPiTokenSpaceGuid.PcdOptDeviceTree|L"OptDeviceTree"|gConfigDxeFormSetGuid|0x0|1

#
# Common UEFI ones.
#
Expand Down
10 changes: 5 additions & 5 deletions Platform/RaspberryPi/RPi4/RPi4.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
DEFINE SECURE_BOOT_ENABLE = FALSE
DEFINE INCLUDE_TFTP_COMMAND = FALSE
DEFINE DEBUG_PRINT_ERROR_LEVEL = 0x8000004F
DEFINE ACPI_BASIC_MODE_ENABLE = FALSE

!ifndef TFA_BUILD_ARTIFACTS
#
Expand Down Expand Up @@ -271,8 +270,6 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|FALSE

gRaspberryPiTokenSpaceGuid.PcdAcpiBasicMode|$(ACPI_BASIC_MODE_ENABLE)

[PcdsFixedAtBuild.common]
gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000
gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000
Expand Down Expand Up @@ -483,6 +480,11 @@
gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|L"RamMoreThan3GB"|gConfigDxeFormSetGuid|0x0|0
gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|L"RamLimitTo3GB"|gConfigDxeFormSetGuid|0x0|1

#
# Device Tree
#
gRaspberryPiTokenSpaceGuid.PcdOptDeviceTree|L"OptDeviceTree"|gConfigDxeFormSetGuid|0x0|0

#
# Common UEFI ones.
#
Expand Down Expand Up @@ -575,9 +577,7 @@

ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
!if $(ACPI_BASIC_MODE_ENABLE) == FALSE
Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf
!endif
Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
ArmPkg/Drivers/TimerDxe/TimerDxe.inf
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
Expand Down
2 changes: 0 additions & 2 deletions Platform/RaspberryPi/RPi4/RPi4.fdf
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ READ_LOCK_STATUS = TRUE

INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
INF Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
!if $(ACPI_BASIC_MODE_ENABLE) == FALSE
INF Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf
!endif
INF Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
Expand Down
15 changes: 6 additions & 9 deletions Platform/RaspberryPi/RPi4/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ Raspberry Pi is a trademark of the [Raspberry Pi Foundation](https://www.raspber
This firmware is still in development stage, meaning that it comes with the
following __major__ limitations:

- USB may only work in pre-OS phase at this stage due to nonstandard ECAM,
missing/incomplete ACPI tables as well as other factors. For Linux, using
the `ACPI_BASIC_MODE_ENABLE` build option may help.
- xHCI USB may only work in pre-OS phase due to nonstandard DMA constraints.
For 4 GB models running Linux, limiting the RAM to 3 GB should help.
The 3 GB limitation is currently enabled by default in the user settings.
- Device Tree boot of OSes such as Linux may not work at all.
For this reason, the provision of a Device Tree is disabled by default in
the user settings, in order to enforce ACPI boot.
- Serial I/O from the OS may not work due to CPU throttling affecting the
miniUART baudrate. This can be worked around by using the PL011 UART
through the device tree overlays.
Expand All @@ -27,12 +30,6 @@ following __major__ limitations:

Build instructions from the top level edk2-platforms Readme.md apply.

The following additional build options are also available:
- `-D ACPI_BASIC_MODE_ENABLE=1`: Limits OS visible memory to 3 GB and forces
ACPI (by disabling the Device Tree driver altogether). This may be required
to boot Operating Systems such as Linux on account of the current PCIe/xHCI
limitations.

# Booting the firmware

1. Format a uSD card as FAT16 or FAT32
Expand Down
4 changes: 1 addition & 3 deletions Platform/RaspberryPi/RaspberryPi.dec
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
gRaspberryPiTokenSpaceGuid.PcdCustomCpuClock|0|UINT32|0x00000016
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes|0|UINT8|0x00000017
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot|0|UINT32|0x00000018
gRaspberryPiTokenSpaceGuid.PcdOptDeviceTree|1|UINT32|0x0000001B
gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|0|UINT32|0x00000019
gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|0|UINT32|0x0000001A

[PcdsFeatureFlag.common]
gRaspberryPiTokenSpaceGuid.PcdAcpiBasicMode|FALSE|BOOLEAN|0x0000001B

0 comments on commit da7cb41

Please sign in to comment.