From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by mx.groups.io with SMTP id smtpd.web11.7485.1583474053060243274 for ; Thu, 05 Mar 2020 21:54:13 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UkWSY4jM; spf=pass (domain: gmail.com, ip: 209.85.219.48, mailfrom: andrey.warkentin@gmail.com) Received: by mail-qv1-f48.google.com with SMTP id u10so458852qvi.2 for ; Thu, 05 Mar 2020 21:54:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=uU4BzXtLUX4Kk2hXD1kOh2sVkew6rcuVFeoeVN+p15I=; b=UkWSY4jMOyoHy4j3Uw97eHktvYfmpmEgGaMWrPI/oqzCMns5quZbv9XiUPNkWaXgam a8bEhlHWDg/avFFWiFy44Eyw8hU064dcXX/NlcTRFiIuzpKqpLysAJFYV96X9JWnu8Hs CqdqQMLqOxRuNq9GnCOZYhNDhlxtCH21sai9dQJXWrUq6etUXGuqmZQWDwLa3jdx4pWF hlVzipUcSlmFTbInhIBs8J8Cb7skcSuxlQPrpX8+pO7lhaFzB1SLVbixFM7qHmL+/3pT f+wHuddniWQZj9DyLdNWM54+V2d36M1FdNX7/yJqQT195x+IZ50DMngPgWHTPnirjOGB QgjQ== 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; bh=uU4BzXtLUX4Kk2hXD1kOh2sVkew6rcuVFeoeVN+p15I=; b=eh4pil9LOugOOjUkqE0guYXs4PXBjzCQ+buKRee8ilZ72KGbWXLa2+m+vdxsQqKT8E xm09ej26CPCJ+EZRb/MEckqMGsAK2kdxeJHkkxBpWLXHgg8XuUk+ZZGCT+cNvtfaBuMy mHmg4Yn4UqgZn8Z4ewJv/079K4RZcbhizMWurmU/6nEMyub0yVjZLrG1Fjj9ObsEM+ft Q/+c4WUgOzuWf362Hpl17v50nEQ5G40ig4L3k72Xe2chs4aFXZ6ptAlw53ZIi0M1MTlv 6FeptitnlWAccy28CfDSK9F1LL4zjHQ1WQ/sPJSrNkUMQ3wcxgtiss1URiIrpHW8qS9O F4cQ== X-Gm-Message-State: ANhLgQ3wctQ3diRZFQ8AY7qqmIidLwP1QfxK8/z+x0CqMSG8JbIzNFrg m6lWjFjnrpvC5Y0Npc2E8hE0LGCdhVo= X-Google-Smtp-Source: ADFU+vt5ezWL+E8aUJkXLBkVF/fQBpnv7iFeMhuSfFtRyerEXmGa3C7vDXm/PpoGuYcDbqol6VFmXQ== X-Received: by 2002:a05:6214:1650:: with SMTP id f16mr1549952qvw.94.1583474051776; Thu, 05 Mar 2020 21:54:11 -0800 (PST) Return-Path: Received: from ubuntu.localdomain (c-24-147-160-127.hsd1.ma.comcast.net. [24.147.160.127]) by smtp.gmail.com with ESMTPSA id z194sm17214178qkb.28.2020.03.05.21.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 21:54:11 -0800 (PST) From: "Andrei Warkentin" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif@nuviainc.com, pete@akeo.ie, philmd@redhat.com Subject: [edk2-platforms][PATCH 1/1] Platform/RaspberryPi: fix FDT handling for RPi4 Date: Thu, 5 Mar 2020 21:53:22 -0800 Message-Id: <20200306055323.39073-1-andrey.warkentin@gmail.com> X-Mailer: git-send-email 2.17.1 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 --- Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf | 2 ++ Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c | 13 ++++++++++++- Platform/RaspberryPi/RPi4/RPi4.dsc | 10 +++++++--- Platform/RaspberryPi/RPi4/RPi4.fdf | 20 +++++++------------- Platform/RaspberryPi/RPi4/Readme.md | 10 +++++----- Platform/RaspberryPi/RaspberryPi.dec | 15 ++++++++------- 6 files changed, 41 insertions(+), 29 deletions(-) diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf index 77cdbe39..3aac6a98 100644 --- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf +++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf @@ -44,6 +44,8 @@ [FixedPcd] gArmTokenSpaceGuid.PcdFdBaseAddress gArmTokenSpaceGuid.PcdFvBaseAddress + gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress + gRaspberryPiTokenSpaceGuid.PcdFdtSize gArmPlatformTokenSpaceGuid.PcdCoreCount gArmTokenSpaceGuid.PcdArmPrimaryCoreMask gArmTokenSpaceGuid.PcdArmPrimaryCore diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c index e795a885..dec8e09d 100644 --- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c +++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c @@ -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. // diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4/RPi4.dsc index da62dc5b..2e98c3e1 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -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 @@ -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 diff --git a/Platform/RaspberryPi/RPi4/RPi4.fdf b/Platform/RaspberryPi/RPi4/RPi4.fdf index c3832035..a59d3b60 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.fdf +++ b/Platform/RaspberryPi/RPi4/RPi4.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,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 @@ -76,7 +70,7 @@ FV = FVMAIN_COMPACT # # NV_VARIABLE_STORE -0x001e0000|0x0000e000 +0x001d0000|0x0000e000 gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize DATA = { @@ -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 = { @@ -138,7 +132,7 @@ DATA = { } # NV_FTW_WORKING data -0x001f0000|0x00010000 +0x001e0000|0x00010000 gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ################################################################################ diff --git a/Platform/RaspberryPi/RPi4/Readme.md b/Platform/RaspberryPi/RPi4/Readme.md index 21c9fd4f..e2f0d698 100644 --- a/Platform/RaspberryPi/RPi4/Readme.md +++ b/Platform/RaspberryPi/RPi4/Readme.md @@ -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 ``` @@ -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` diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec index 25058ccc..3ebb83d9 100644 --- a/Platform/RaspberryPi/RaspberryPi.dec +++ b/Platform/RaspberryPi/RaspberryPi.dec @@ -36,13 +36,14 @@ [PcdsFixedAtBuild.common] gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress|0x10000|UINT32|0x00000001 - gRaspberryPiTokenSpaceGuid.PcdFirmwareBlockSize|0x0|UINT32|0x00000002 - gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogBase|0x0|UINT32|0x00000003 - gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize|0x0|UINT32|0x00000004 - gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|0x0|UINT32|0x00000005 - gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x00000006 - gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x00000007 - gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x0|UINT32|0x00000008 + gRaspberryPiTokenSpaceGuid.PcdFdtSize|0x10000|UINT32|0x00000002 + gRaspberryPiTokenSpaceGuid.PcdFirmwareBlockSize|0x0|UINT32|0x00000003 + gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogBase|0x0|UINT32|0x00000004 + gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize|0x0|UINT32|0x00000005 + gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|0x0|UINT32|0x00000006 + gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x00000007 + gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x00000008 + gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x0|UINT32|0x00000009 [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d -- 2.17.1