From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) by mx.groups.io with SMTP id smtpd.web12.1537.1588274358730823733 for ; Thu, 30 Apr 2020 12:19:18 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dmyevUlm; spf=pass (domain: gmail.com, ip: 209.85.219.67, mailfrom: andrey.warkentin@gmail.com) Received: by mail-qv1-f67.google.com with SMTP id fb4so3617952qvb.7 for ; Thu, 30 Apr 2020 12:19:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iDq+pDm3LUgKWQi3V5nkB2atzY/9AVLXkgReFWgnw9M=; b=dmyevUlmogiRTgG6j+wXA6NRt+Gg8QQKfmwHXoN5K7EQq8B4dNKSSzMXQd/2f4fkqH JmORaQCURru2IlZYIcL8DsfbatxTbk7i0cwoNO6tdthIN5cgskivGAy0GiftfwkmT3Fg isRiPdz1L/7xoE5mGGTm0d6yvTLG1SAqLag/TPx3fh+a/ywqQcgvRETfW5Opb7Uz0/O9 fsRTRx4LX3hi7CIbdr++dZ/t9aYstI+++rQsC1WGRjzrcbuSlNGr9nzcQl7LFswjFwxi qtqEzpFIN4e+7bPvIe9TQw8e04h7zZMqfy2PrHBKZxIstLYv8V/nBD3AXSj34hWYXA+e 4Lag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iDq+pDm3LUgKWQi3V5nkB2atzY/9AVLXkgReFWgnw9M=; b=AgfAD1keUcgQm6tigND7S05pTa1WpkaO9PY5YqITSGqtIRMrfp4phBPsAH2HJ4z73L oVKHlGoXdZsbm6v4Zk9k6WAW3NdKmRJAHhmKCe1VQo/uKQafxYy3s0VcITXlN7PPbTQ4 FulOE31U76796gd+J7ko8vnd9DLPogyvAcvB3lh8xhEbM5rboQxzKHAJAnZajoTAVoTI mda0VYrTSMB6hsOExD2bzmicnjR5kSXer3HIVAWujsPD+itYtcGIi22nWya7PbRT/4OR OE7FewskIrs4n0nuiX/znudEoWPqnokxnBkWWxh50LZjKBxqVSCYho/WNCIxADUfJ+hG afPA== X-Gm-Message-State: AGi0PuYARwGruI7nuDaJTnwPT8LD/KGTaYidw+uOmF0DD4l+IvS8TL5w H7uPDUPIKt7Yr1mzMJWJIYa8sVVrk5Y= X-Google-Smtp-Source: APiQypJGayQ0tPLRPn/vZvzyF6VdzQukHOPElEZCABnbZ/bkbEfwsoBLbISS1geysAN2RoAAxM1Zkg== X-Received: by 2002:a05:6214:593:: with SMTP id bx19mr457736qvb.238.1588274357371; Thu, 30 Apr 2020 12:19:17 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-98-214-99-181.hsd1.il.comcast.net. [98.214.99.181]) by smtp.gmail.com with ESMTPSA id d188sm778733qkg.59.2020.04.30.12.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 12:19:17 -0700 (PDT) From: "Andrei Warkentin" 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 Message-Id: <20200430191901.89372-2-andrey.warkentin@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430191901.89372-1-andrey.warkentin@gmail.com> References: <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 --- 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