Skip to content

Commit

Permalink
Platform/RaspberryPi: fix FDT handling for RPi4
Browse files Browse the repository at this point in the history
A rev-up of start4.elf VPU firmware meant that the previous scheme of
loading the DTB over top of RPI_EFI.FD no longer works - the DT is now
loaded way before the armstub, so any overlap means the DT is overridden.

This change re-arranges a few items in the FD, allowing the DTB to loaded
directly after the FD in physical memory.

This moves UEFI image down by 0x10000, and reduces the FD image size by
0x10000, leaving space for a DTB to be loaded by config.txt at 0x1f0000.

You need a matching "rev RPi4 TF-A for DTB fix" patch to edk2-non-osi,
as it requires a TF-A build with these options:

PRELOADED_BL33_BASE=0x20000 RPI3_PRELOADED_DTB_BASE=0x1f0000

Note: the same problem still affects the Pi 3, and will be
fixed in a separate change.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
Reviewed-by: Pete Batard <pete@akeo.ie>
Tested-by: Pete Batard <pete@akeo.ie>
  • Loading branch information
andreiw authored and Ard Biesheuvel committed Mar 6, 2020
1 parent 91ed4f9 commit 828fcbf
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
[FixedPcd]
gArmTokenSpaceGuid.PcdFdBaseAddress
gArmTokenSpaceGuid.PcdFvBaseAddress
gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress
gRaspberryPiTokenSpaceGuid.PcdFdtSize
gArmPlatformTokenSpaceGuid.PcdCoreCount
gArmTokenSpaceGuid.PcdArmPrimaryCoreMask
gArmTokenSpaceGuid.PcdArmPrimaryCore
Expand Down
13 changes: 12 additions & 1 deletion Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,18 @@ ArmPlatformGetVirtualMemoryMap (
VirtualMemoryInfo[Index].Type = RPI_MEM_RUNTIME_REGION;
VirtualMemoryInfo[Index++].Name = L"FD Variables";

if (BCM2711_SOC_REGISTERS == 0) {
if (BCM2711_SOC_REGISTERS != 0) {
//
// Only the Pi 4 firmware today expects the DTB to directly follow the
// FD instead of overlapping the FD.
//
VirtualMemoryTable[Index].PhysicalBase = FixedPcdGet32 (PcdFdtBaseAddress);
VirtualMemoryTable[Index].VirtualBase = VirtualMemoryTable[Index].PhysicalBase;
VirtualMemoryTable[Index].Length = FixedPcdGet32 (PcdFdtSize);;
VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
VirtualMemoryInfo[Index].Type = RPI_MEM_RESERVED_REGION;
VirtualMemoryInfo[Index++].Name = L"Flattened Device Tree";
} else {
//
// TF-A reserved RAM only exists for the Pi 3 TF-A.
//
Expand Down
10 changes: 7 additions & 3 deletions Platform/RaspberryPi/RPi4/RPi4.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@
gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1
gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0
gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320
gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress|0x20000
#
# Follows right after the FD image.
#
gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress|0x001f0000

# DEBUG_ASSERT_ENABLED 0x01
# DEBUG_PRINT_ENABLED 0x02
Expand Down Expand Up @@ -393,8 +396,9 @@
# Size of the region used by UEFI in permanent memory (Reserved 64MB)
gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000
#
# This matches PcdFvBaseAddress, since everything less is ATF, and
# will be reserved away.
# 0x00000000 - 0x001F0000 FD (PcdFdBaseAddress, PcdFdSize)
# 0x001F0000 - 0x00200000 DTB (PcdFdtBaseAddress, PcdFdtSize)
# 0x00200000 - ... RAM (PcdSystemMemoryBase, PcdSystemMemorySize)
#
gArmTokenSpaceGuid.PcdSystemMemoryBase|0x00200000
gArmTokenSpaceGuid.PcdSystemMemorySize|0x3fe00000
Expand Down
20 changes: 7 additions & 13 deletions Platform/RaspberryPi/RPi4/RPi4.fdf
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

[FD.RPI_EFI]
BaseAddress = 0x00000000|gArmTokenSpaceGuid.PcdFdBaseAddress
Size = 0x00200000|gArmTokenSpaceGuid.PcdFdSize
Size = 0x001f0000|gArmTokenSpaceGuid.PcdFdSize
ErasePolarity = 1

BlockSize = 0x00001000|gRaspberryPiTokenSpaceGuid.PcdFirmwareBlockSize
NumBlocks = 0x200
NumBlocks = 0x1f0

################################################################################
#
Expand All @@ -53,16 +53,10 @@ NumBlocks = 0x200
0x00000000|0x00020000
FILE = $(TFA_BUILD_BL31)

#
# DTB.
#
0x00020000|0x00010000
DATA = { 0x00 }

#
# UEFI image
#
0x00030000|0x001b0000
0x00020000|0x001b0000
gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
FV = FVMAIN_COMPACT

Expand All @@ -76,7 +70,7 @@ FV = FVMAIN_COMPACT
#

# NV_VARIABLE_STORE
0x001e0000|0x0000e000
0x001d0000|0x0000e000
gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize

DATA = {
Expand Down Expand Up @@ -119,11 +113,11 @@ DATA = {
}

# NV_EVENT_LOG
0x001ee000|0x00001000
0x001de000|0x00001000
gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogBase|gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize

# NV_FTW_WORKING header
0x001ef000|0x00001000
0x001df000|0x00001000
gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize

DATA = {
Expand All @@ -138,7 +132,7 @@ DATA = {
}

# NV_FTW_WORKING data
0x001f0000|0x00010000
0x001e0000|0x00010000
gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize

################################################################################
Expand Down
10 changes: 5 additions & 5 deletions Platform/RaspberryPi/RPi4/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ Build instructions from the top level edk2-platforms Readme.md apply.
```
Additionally, if you want to use PL011 instead of the miniUART, you can add the lines:
```
device_tree_address=0x20000
device_tree_end=0x30000
device_tree_address=0x1f0000
device_tree_end=0x200000
device_tree=bcm2711-rpi-4-b.dtb
dtoverlay=miniuart-bt
```
Expand Down Expand Up @@ -80,12 +80,12 @@ You can pass a custom Device Tree and overlays using the following:
```
(...)
disable_commandline_tags=2
device_tree_address=0x20000
device_tree_end=0x30000
device_tree_address=0x1f0000
device_tree_end=0x200000
device_tree=bcm2711-rpi-4-b.dtb
```
Note: the address range **must** be `[0x20000:0x30000]`.
Note: the address range **must** be `[0x1f0000:0x200000]`.
`dtoverlay` and `dtparam` parameters are also supported **when** providing a Device Tree`.
## Custom `bootargs`
Expand Down
1 change: 1 addition & 0 deletions Platform/RaspberryPi/RaspberryPi.dec
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x00000006
gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x00000007
gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x0|UINT32|0x00000008
gRaspberryPiTokenSpaceGuid.PcdFdtSize|0x10000|UINT32|0x00000009

[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d
Expand Down

0 comments on commit 828fcbf

Please sign in to comment.