From: "Andrei Warkentin" <andrey.warkentin@gmail.com>
To: devel@edk2.groups.io
Cc: ard.biesheuvel@arm.com, leif@nuviainc.com, pete@akeo.ie,
philmd@redhat.com
Subject: [edk2-platforms][PATCH 1/2] RPi3/RPi4: fix RPi 3 VPU-passed FDT handling by unifying with RPi4 implementation
Date: Thu, 30 Apr 2020 12:19:00 -0700 [thread overview]
Message-ID: <20200430191901.89372-2-andrey.warkentin@gmail.com> (raw)
In-Reply-To: <20200430191901.89372-1-andrey.warkentin@gmail.com>
A rev-up of start.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.
Unlike the Pi 4 implementation, we can't move the UEFI image down in memory,
as that needs a TF-A changem so it just reduces the size by 0x10000. The
same base address (0x1f0000) is used as on the Pi 4.
The Pi 3 FDF can be further unified with Pi 4 after work on TF-A to move
to a single BL32-based Pi 3 TF-A implementation.
Tested: Pi 3A+, Pi 2B v1.2, Pi 4B (4GB).
Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
---
Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c | 44 ++++++++++----------
Platform/RaspberryPi/RPi3/RPi3.dsc | 9 +++-
Platform/RaspberryPi/RPi3/RPi3.fdf | 36 ++++++++--------
Platform/RaspberryPi/RPi4/RPi4.dsc | 7 ++--
Platform/RaspberryPi/RPi4/RPi4.fdf | 8 ++++
Platform/RaspberryPi/RaspberryPi.dec | 6 ++-
6 files changed, 63 insertions(+), 47 deletions(-)
diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
index dec8e09d..aae189ec 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
+++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
@@ -94,29 +94,27 @@ ArmPlatformGetVirtualMemoryMap (
VirtualMemoryInfo[Index].Type = RPI_MEM_RUNTIME_REGION;
VirtualMemoryInfo[Index++].Name = L"FD Variables";
- 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.
- //
- // This is 2MB that directly follows the FD.
- //
- VirtualMemoryTable[Index].PhysicalBase = (FixedPcdGet64(PcdFdBaseAddress) + FixedPcdGet32(PcdFdSize));
- VirtualMemoryTable[Index].VirtualBase = VirtualMemoryTable[Index].PhysicalBase;
- VirtualMemoryTable[Index].Length = FixedPcdGet64 (PcdSystemMemoryBase) - VirtualMemoryTable[Index].PhysicalBase;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
- VirtualMemoryInfo[Index].Type = RPI_MEM_RESERVED_REGION;
- VirtualMemoryInfo[Index++].Name = L"TF-A RAM";
+ //
+ // Both the the Pi 4 and Pi 3 implementations expect the DTB to directly follow 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";
+ if (BCM2711_SOC_REGISTERS == 0) {
+ //
+ // TF-A reserved RAM only exists for the Pi 3 TF-A.
+ //
+ // This is 2MB that directly follows the FD.
+ //
+ VirtualMemoryTable[Index].PhysicalBase = (FixedPcdGet64(PcdFdBaseAddress) + FixedPcdGet32(PcdFdSize));
+ VirtualMemoryTable[Index].VirtualBase = VirtualMemoryTable[Index].PhysicalBase;
+ VirtualMemoryTable[Index].Length = FixedPcdGet64 (PcdSystemMemoryBase) - VirtualMemoryTable[Index].PhysicalBase;
+ VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+ VirtualMemoryInfo[Index].Type = RPI_MEM_RESERVED_REGION;
+ VirtualMemoryInfo[Index++].Name = L"TF-A RAM";
}
// Base System RAM
diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
index d4a3d49d..563fb891 100644
--- a/Platform/RaspberryPi/RPi3/RPi3.dsc
+++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
@@ -387,8 +387,13 @@
# 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 - 0x00400000 TFA (BL2 / BL31 / BL32 "secure SRAM")
+ # 0x00400000 - ... RAM (PcdSystemMemoryBase, PcdSystemMemorySize)
+ #
+ # This matches PcdFvBaseAddress, since everything less is FD + TF-A RAM,
+ # thus will be reserved away.
#
gArmTokenSpaceGuid.PcdSystemMemoryBase|0x00400000
gArmTokenSpaceGuid.PcdSystemMemorySize|0x3FC00000
diff --git a/Platform/RaspberryPi/RPi3/RPi3.fdf b/Platform/RaspberryPi/RPi3/RPi3.fdf
index d334d3be..daedc443 100644
--- a/Platform/RaspberryPi/RPi3/RPi3.fdf
+++ b/Platform/RaspberryPi/RPi3/RPi3.fdf
@@ -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
################################################################################
#
@@ -53,12 +53,6 @@ NumBlocks = 0x200
0x00000000|0x00010000
FILE = $(TFA_BUILD_BL1)
-#
-# DTB.
-#
-0x00010000|0x00010000
-DATA = { 0x00 }
-
#
# ATF secondary boot image in FIP format (BL2 + BL31)
#
@@ -68,21 +62,21 @@ FILE = $(TFA_BUILD_FIP)
#
# UEFI image
#
-0x00030000|0x001b0000
+0x00030000|0x001a0000
gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
FV = FVMAIN_COMPACT
#
# Variables (0x20000 overall).
#
-# 0x001e0000 - 0x001edfff EFI_FIRMWARE_VOLUME_HEADER
-# 0x001ee000 - 0x001eefff Event log
-# 0x001ef000 - 0x001effff EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER-
-# 0x001f0000 - 0x001fffff Data
+# 0x001d0000 - 0x001ddfff EFI_FIRMWARE_VOLUME_HEADER
+# 0x001de000 - 0x001defff Event log
+# 0x001df000 - 0x001dffff EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER-
+# 0x001e0000 - 0x001effff Data
#
# NV_VARIABLE_STORE
-0x001e0000|0x0000e000
+0x001d0000|0x0000e000
gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
DATA = {
@@ -125,11 +119,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 = {
@@ -144,9 +138,17 @@ DATA = {
}
# NV_FTW_WORKING data
-0x001f0000|0x00010000
+0x001e0000|0x00010000
gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+#
+# This is just for documentation purposes! The DTB reserved space is not part of the FD,
+# but this is exactly where it is expected to be.
+#
+# 0x001f0000|0x10000
+# gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress|gRaspberryPiTokenSpaceGuid.PcdFdtSize
+#
+
################################################################################
#
# FV Section
diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4/RPi4.dsc
index c401533a..4deccd9d 100644
--- a/Platform/RaspberryPi/RPi4/RPi4.dsc
+++ b/Platform/RaspberryPi/RPi4/RPi4.dsc
@@ -275,10 +275,6 @@
gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1
gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0
gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320
- #
- # Follows right after the FD image.
- #
- gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress|0x001f0000
# DEBUG_ASSERT_ENABLED 0x01
# DEBUG_PRINT_ENABLED 0x02
@@ -398,6 +394,9 @@
# 0x001F0000 - 0x00200000 DTB (PcdFdtBaseAddress, PcdFdtSize)
# 0x00200000 - ... RAM (PcdSystemMemoryBase, PcdSystemMemorySize)
#
+ # This matches PcdFvBaseAddress, since everything less is the FD, and
+ # will be reserved away.
+ #
gArmTokenSpaceGuid.PcdSystemMemoryBase|0x00200000
gArmTokenSpaceGuid.PcdSystemMemorySize|0x3fe00000
diff --git a/Platform/RaspberryPi/RPi4/RPi4.fdf b/Platform/RaspberryPi/RPi4/RPi4.fdf
index b2164363..c3e9cfc4 100644
--- a/Platform/RaspberryPi/RPi4/RPi4.fdf
+++ b/Platform/RaspberryPi/RPi4/RPi4.fdf
@@ -135,6 +135,14 @@ DATA = {
0x001e0000|0x00010000
gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+#
+# This is just for documentation purposes! The DTB reserved space is not part of the FD,
+# but this is exactly where it is expected to be.
+#
+# 0x001f0000|0x10000
+# gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress|gRaspberryPiTokenSpaceGuid.PcdFdtSize
+#
+
################################################################################
#
# FV Section
diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec
index d59b5481..b66322be 100644
--- a/Platform/RaspberryPi/RaspberryPi.dec
+++ b/Platform/RaspberryPi/RaspberryPi.dec
@@ -35,7 +35,11 @@
gRaspberryPiDefaultFdtGuid = {0xDF5DA223, 0x1D27, 0x47C3, { 0x8D, 0x1B, 0x9A, 0x41, 0xB5, 0x5A, 0x18, 0xBC}}
[PcdsFixedAtBuild.common]
- gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress|0x10000|UINT32|0x00000001
+ #
+ # Space reserved for config.txt-specced DTB follows right after the FD image
+ # in both RPi3 and RP4 implementations.
+ #
+ gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress|0x001f0000|UINT32|0x00000001
gRaspberryPiTokenSpaceGuid.PcdFirmwareBlockSize|0x0|UINT32|0x00000002
gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogBase|0x0|UINT32|0x00000003
gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize|0x0|UINT32|0x00000004
--
2.17.1
next prev parent reply other threads:[~2020-04-30 19:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-30 19:18 [edk2-platforms][PATCH 0/2] Fixing FDT handling on Pi 3 Andrei Warkentin
2020-04-30 19:19 ` Andrei Warkentin [this message]
2020-05-01 9:35 ` [edk2-platforms][PATCH 1/2] RPi3/RPi4: fix RPi 3 VPU-passed FDT handling by unifying with RPi4 implementation Pete Batard
2020-04-30 19:19 ` [edk2-platforms][PATCH 2/2] RPi: update Pi3 and Pi4 readmes with correct info on FDT handling Andrei Warkentin
2020-05-01 9:43 ` Pete Batard
2020-05-01 10:30 ` [edk2-platforms][PATCH 0/2] Fixing FDT handling on Pi 3 Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200430191901.89372-2-andrey.warkentin@gmail.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox