From nobody Thu Mar 28 15:01:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+45435+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+45435+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1565615210; cv=none; d=zoho.com; s=zohoarc; b=Zq2Qq9cOqnR32ofc509t5+AUHHUI6CU2li3EQz7u71Mtkg6IW96Mk7mzBlD3JO+0HawhK29t/+bMw2ZRo0U2TvZySowKSEt5u9T6Jjqo7eCebaMBZykQHxG6FN3OKeB9H30SpjZVkpKqNSlQaa+AVnAdW47NSE360CFR3zEE9S0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565615210; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=/sVLAa8Uze/iDp2KInbWYllY+phP1hL3cUqaz6FuBaE=; b=ZTo4oXi3cVVasUreHmfB6nMmtlV87VQpGwGS6ZUFcsNh9DHBIpq0HOZp0Qpl6REujQBY9p8od6xfL7YwlyGPLS6KBe/cBrATtPwRyEU9NvdhYmQ0xU9qHkCsuzHZqnGn3t4tqaWFEwp9XM9RVdSY1bkbbnfS934o2Y4j1q2PI0M= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+45435+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1565615210593210.94837426079755; Mon, 12 Aug 2019 06:06:50 -0700 (PDT) Return-Path: X-Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by groups.io with SMTP; Mon, 12 Aug 2019 06:06:49 -0700 X-Received: by mail-wr1-f67.google.com with SMTP id z1so104498356wru.13 for ; Mon, 12 Aug 2019 06:06:48 -0700 (PDT) X-Gm-Message-State: APjAAAUrD/EPpP+URiqb4H69p6YiLaAtOk0T4ZyQoGslXbzkAY112gey Bzz06xWmG9re9Ll8da3f9YIX07nc1sc= X-Google-Smtp-Source: APXvYqwuUhHFm5GYu/SJM8A1mWjRcBNmFNPO5jYdNIGBf/moAoED8JJj63lOsCBXYpFI8XbTf4BUvQ== X-Received: by 2002:adf:f646:: with SMTP id x6mr43120432wrp.18.1565615207200; Mon, 12 Aug 2019 06:06:47 -0700 (PDT) X-Received: from localhost.localdomain ([84.203.61.230]) by smtp.gmail.com with ESMTPSA id n2sm11330167wmi.38.2019.08.12.06.06.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Aug 2019 06:06:46 -0700 (PDT) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org Subject: [edk2-devel] [edk2-platforms: PATCH 1/1] Platforms/RPi3: Add multiple embedded Device Tree selection Date: Mon, 12 Aug 2019 14:06:34 +0100 Message-Id: <20190812130634.7224-2-pete@akeo.ie> In-Reply-To: <20190812130634.7224-1-pete@akeo.ie> References: <20190812130634.7224-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1565615210; bh=SKn9dHJazFd7mXQEmpd0Mzu++5L8YpnQ8TN3mlTiWp8=; h=Cc:Date:From:Reply-To:Subject:To; b=P09SeDfTp4aE9aQc6bSwDNfGqBAXnfI2wj2q2Y6UBesd6DePENKgwWCgPMH0fc0iBgT aC+ZUfqUnTQFoQFiVB9Pcsm1FdUQpvwrxxFpKUiEg8ZYWMdQT29HbKph0a7bk1x1jSXvA vScuMnWHp4yfVaAUtpIEc89qBvEb6TdtRwI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The Raspberry Pi 3 platform currently has 2 different models, each with a different Device Tree. Rather than embedding a single one, and requiring users to manually provide the other, this patch ensures that we now embed both and and serve the relevant one at runtime. Signed-off-by: Pete Batard --- Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c | 57 ++++++++++++++++-= --- Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.inf | 3 +- Platform/RaspberryPi/RPi3/RPi3.dec | 3 +- Platform/RaspberryPi/RPi3/RPi3.fdf | 6 ++- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c b/Platform/R= aspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c index c84e5b2767e2..7c0ab75e7cb1 100644 --- a/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c +++ b/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c @@ -20,6 +20,11 @@ =20 #include =20 +CONST EFI_GUID *mFdtGuid[] =3D { + &gRaspberryPiFdtGuid1, + &gRaspberryPiFdtGuid2, + }; + STATIC VOID *mFdtImage; =20 STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol; @@ -368,7 +373,9 @@ FdtDxeInitialize ( EFI_STATUS Status; VOID *FdtImage; UINTN FdtSize; + UINTN FdtIndex; INT32 Retval; + UINT32 BoardRevision; BOOLEAN Internal; =20 Status =3D gBS->LocateProtocol (&gRaspberryPiFirmwareProtocolGuid, NULL, @@ -383,13 +390,41 @@ FdtDxeInitialize ( * Have FDT passed via config.txt. */ FdtSize =3D fdt_totalsize (FdtImage); - DEBUG ((DEBUG_INFO, "DTB passed via config.txt of 0x%lx bytes\n", FdtS= ize)); + DEBUG ((DEBUG_INFO, "Device Tree passed via config.txt (0x%lx bytes)\n= ", FdtSize)); Status =3D EFI_SUCCESS; } else { + /* + * Use one of the embedded FDT's. + */ Internal =3D TRUE; - DEBUG ((DEBUG_INFO, "No/bad FDT at %p (%a), trying internal DTB...\n", - FdtImage, fdt_strerror (Retval))); - Status =3D GetSectionFromAnyFv (&gRaspberryPiFdtFileGuid, EFI_SECTION_= RAW, 0, + DEBUG ((DEBUG_INFO, "No/Bad Device Tree found at address 0x%p (%a), " + "looking up internal one...\n", FdtImage, fdt_strerror (Retval))); + /* + * Query the board revision to differentiate between models. + */ + Status =3D mFwProtocol->GetModelRevision (&BoardRevision); + if (EFI_ERROR (Status)) { + FdtIndex =3D 0; + DEBUG ((DEBUG_ERROR, "Failed to get board type: %r\n", Status)); + } else { + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-c= odes/README.md + switch ((BoardRevision >> 4) & 0xFF) { + case 0x08: // Raspberry 3 Model B + DEBUG ((DEBUG_INFO, "Using RPi3 Model B internal Device Tree\n")); + FdtIndex =3D 0; + break; + case 0x0D: // Raspberry 3 Model B+ + DEBUG ((DEBUG_INFO, "Using RPi3 Model B+ internal Device Tree\n")); + FdtIndex =3D 1; + break; + default: + DEBUG ((DEBUG_INFO, "Using default internal Device Tree\n")); + FdtIndex =3D 0; + break; + } + } + ASSERT (FdtIndex < ARRAY_SIZE (mFdtGuid)); + Status =3D GetSectionFromAnyFv (mFdtGuid[FdtIndex], EFI_SECTION_RAW, 0, &FdtImage, &FdtSize); if (Status =3D=3D EFI_SUCCESS) { if (fdt_check_header (FdtImage) !=3D 0) { @@ -419,27 +454,27 @@ FdtDxeInitialize ( =20 Status =3D SanitizePSCI (); if (EFI_ERROR (Status)) { - Print (L"Failed to sanitize PSCI (error %d)\n", Status); + Print (L"Failed to sanitize PSCI: %r\n", Status); } =20 Status =3D CleanMemoryNodes (); if (EFI_ERROR (Status)) { - Print (L"Failed to clean memory nodes (error %d)\n", Status); + Print (L"Failed to clean memory nodes: %r\n", Status); } =20 Status =3D CleanSimpleFramebuffer (); if (EFI_ERROR (Status)) { - Print (L"Failed to clean frame buffer (error %d)\n", Status); + Print (L"Failed to clean frame buffer: %r\n", Status); } =20 Status =3D FixEthernetAliases (); if (EFI_ERROR (Status)) { - Print (L"Failed to fix ethernet aliases (error %d)\n", Status); + Print (L"Failed to fix ethernet aliases: %r\n", Status); } =20 Status =3D UpdateMacAddress (); if (EFI_ERROR (Status)) { - Print (L"Failed to update MAC address (error %d)\n", Status); + Print (L"Failed to update MAC address: %r\n", Status); } =20 if (Internal) { @@ -448,11 +483,11 @@ FdtDxeInitialize ( */ Status =3D UpdateBootArgs (); if (EFI_ERROR (Status)) { - Print (L"Failed to update boot arguments (error %d)\n", Status); + Print (L"Failed to update boot arguments: %r\n", Status); } } =20 - DEBUG ((DEBUG_INFO, "Installed FDT is at %p\n", mFdtImage)); + DEBUG ((DEBUG_INFO, "Installed Device Tree at address 0x%p\n", mFdtImage= )); Status =3D gBS->InstallConfigurationTable (&gFdtTableGuid, mFdtImage); ASSERT_EFI_ERROR (Status); =20 diff --git a/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.inf b/Platform= /RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.inf index 5b0b1a09f374..c994a2b69d78 100644 --- a/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.inf +++ b/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.inf @@ -35,7 +35,8 @@ [LibraryClasses] =20 [Guids] gFdtTableGuid - gRaspberryPiFdtFileGuid + gRaspberryPiFdtGuid1 + gRaspberryPiFdtGuid2 =20 [Protocols] gRaspberryPiFirmwareProtocolGuid ## CONSUMES diff --git a/Platform/RaspberryPi/RPi3/RPi3.dec b/Platform/RaspberryPi/RPi3= /RPi3.dec index 22de439fde8f..d90ea8329818 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dec +++ b/Platform/RaspberryPi/RPi3/RPi3.dec @@ -24,7 +24,8 @@ [Protocols] =20 [Guids] gRaspberryPiTokenSpaceGuid =3D {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD3,= 0x63, 0xB0, 0xB8, 0xEE, 0xD6, 0xB5}} - gRaspberryPiFdtFileGuid =3D {0xDF5DA223, 0x1D27, 0x47C3, { 0x8D, 0x1B, 0= x9A, 0x41, 0xB5, 0x5A, 0x18, 0xBC}} + gRaspberryPiFdtGuid1 =3D {0xDF5DA223, 0x1D27, 0x47C3, { 0x8D, 0x1B, 0x9A= , 0x41, 0xB5, 0x5A, 0x18, 0xBC}} + gRaspberryPiFdtGuid2 =3D {0x3D523012, 0x73FE, 0x40E5, { 0x89, 0x2E, 0x1A= , 0x4D, 0xF6, 0x0F, 0x3C, 0x0C}} gRaspberryPiEventResetGuid =3D {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD3,= 0x63, 0xB4, 0xB4, 0xE4, 0xD4, 0xB4}} gConfigDxeFormSetGuid =3D {0xCD7CC258, 0x31DB, 0x22E6, {0x9F, 0x22, 0x63= , 0xB0, 0xB8, 0xEE, 0xD6, 0xB5}} =20 diff --git a/Platform/RaspberryPi/RPi3/RPi3.fdf b/Platform/RaspberryPi/RPi3= /RPi3.fdf index c62d649834c7..83753d84badc 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.fdf +++ b/Platform/RaspberryPi/RPi3/RPi3.fdf @@ -300,11 +300,15 @@ [FV.FvMain] INF Platform/RaspberryPi/$(PLATFORM_NAME)/Drivers/LogoDxe/LogoDxe.inf =20 # - # FDT (GUID matches gRaspberryPiFdtFileGuid in FdtDxe) + # Device Tree support + # GUIDs match gRaspberryPiFdtGuid# from FdtDxe. # FILE FREEFORM =3D DF5DA223-1D27-47C3-8D1B-9A41B55A18BC { SECTION RAW =3D Platform/RaspberryPi/$(PLATFORM_NAME)/DeviceTree/bcm27= 10-rpi-3-b.dtb } + FILE FREEFORM =3D 3D523012-73FE-40E5-892E-1A4DF60F3C0C { + SECTION RAW =3D Platform/RaspberryPi/$(PLATFORM_NAME)/DeviceTree/bcm27= 10-rpi-3-b-plus.dtb + } =20 [FV.FVMAIN_COMPACT] FvAlignment =3D 16 --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#45435): https://edk2.groups.io/g/devel/message/45435 Mute This Topic: https://groups.io/mt/32840411/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-