[edk2-devel] [edk2-platforms][PATCH 1/2] RPi3/RPi4: fix RPi 3 VPU-passed FDT handling by unifying with RPi4 implementation

Pete Batard pete at akeo.ie
Fri May 1 09:35:53 UTC 2020


On 2020.04.30 20:19, Andrei Warkentin wrote:
> 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 at 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
> 

Reviewed-by: Pete Batard <pete at akeo.ie>
Tested-on: Pi 3B, Pi 3B+

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#58498): https://edk2.groups.io/g/devel/message/58498
Mute This Topic: https://groups.io/mt/73382824/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list