From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by mx.groups.io with SMTP id smtpd.web10.6843.1588325758107453062 for ; Fri, 01 May 2020 02:35:58 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=qg1foVAj; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.128.68, mailfrom: pete@akeo.ie) Received: by mail-wm1-f68.google.com with SMTP id h4so5392458wmb.4 for ; Fri, 01 May 2020 02:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=KzaMhyZjxiWE1REw4hIG3a1lpHTfoj4ouhus+z2PasA=; b=qg1foVAjKXo54lMlATWyh/tTYjsBMSPXeguZ6dYsE26ycjSRRHGQjQS0xHi6kfgvoT d0uplSKBCceevHKOInlXbeb8EVC3XS3FT0Hcm0sA+8yOx+AhBVnmK+ncyluMTEnWGvpj 2oBs2x+H321XoZUMri1nLahwVv2TtUq/U3xFWsAnQtYksfyDmEQK5A+RpVgVcllL/Qdq NAom5rqw4IjIZaB0JBovFoK+8s5vBO2MGWyuriMYxX+b1sJljhqPdNzu6B9PTUIkWQmp ZwnksAGLaUnnNNnCc0G3HxKMzNumpFdXOpkk+BIhQZjIPxJXY68M45qphIjsI6otM0V1 CLJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=KzaMhyZjxiWE1REw4hIG3a1lpHTfoj4ouhus+z2PasA=; b=S+SGaDqlrNy9loEbBBnZnHtk+A5d/zOOq4nZCJ58JV5D1AqJFoO8xjbYUS0XV0OY8d XQ8u859vwlifS5Kmiy7YOQH6Ycc4YWCzWYXN4JrWBBxWNkN7MOznjWw6+LqS3qArflYd spQN9tlIh5wdhBA1jwL5zeqZKNQOOLynp4/Jk757443hyjVB77PGcWvH4nOvzrKFVy73 ET171IaaV4i4Pwe+4rdWEhWgP8upGKeunZHjdCfJR5K3U3ue3dbdpFMxsCSA6od9rSIp A8TK7dZUagbduMqh85Y62ExjVEVs0OlqRnSnVzX3lTo+mjPJEymI0t5MUZJbDOm+ZFpY 1jiw== X-Gm-Message-State: AGi0PuYFsC8TjzWiiRsPwgRyrXm7mTrhWkQx1CgfAUWT3mg8a9NDFU0u hk2Ot+i3CoExdJ3UyYl776RhxA== X-Google-Smtp-Source: APiQypJY4fthPooxyf9UbfXTfE1pf23GHjgH4FHRPCp7RVbMLHSB282/Miqs1dypwUx5dILJFQ3RaA== X-Received: by 2002:a1c:750a:: with SMTP id o10mr3087472wmc.124.1588325755751; Fri, 01 May 2020 02:35:55 -0700 (PDT) Return-Path: Received: from [10.0.0.122] ([84.203.75.87]) by smtp.googlemail.com with ESMTPSA id i1sm3433003wrx.22.2020.05.01.02.35.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 May 2020 02:35:54 -0700 (PDT) Subject: Re: [edk2-platforms][PATCH 1/2] RPi3/RPi4: fix RPi 3 VPU-passed FDT handling by unifying with RPi4 implementation To: Andrei Warkentin , devel@edk2.groups.io Cc: ard.biesheuvel@arm.com, leif@nuviainc.com, philmd@redhat.com References: <20200430191901.89372-1-andrey.warkentin@gmail.com> <20200430191901.89372-2-andrey.warkentin@gmail.com> From: "Pete Batard" Message-ID: Date: Fri, 1 May 2020 10:35:53 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200430191901.89372-2-andrey.warkentin@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit 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 > --- > 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 Tested-on: Pi 3B, Pi 3B+