Fix for Raspberry Pi firmware properties

This commit is contained in:
Peter Robinson 2021-08-24 14:08:33 +01:00
parent e63667d6b3
commit 319f8123df
2 changed files with 166 additions and 1 deletions

View File

@ -0,0 +1,161 @@
From patchwork Sun Aug 22 14:36:55 2021
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Sjoerd Simons <sjoerd@collabora.com>
X-Patchwork-Id: 1519427
X-Patchwork-Delegate: matthias.bgg@gmail.com
Return-Path: <u-boot-bounces@lists.denx.de>
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Authentication-Results: ozlabs.org;
spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de
(client-ip=85.214.62.61; helo=phobos.denx.de;
envelope-from=u-boot-bounces@lists.denx.de; receiver=<UNKNOWN>)
Received: from phobos.denx.de (phobos.denx.de [85.214.62.61])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (4096 bits))
(No client certificate requested)
by ozlabs.org (Postfix) with ESMTPS id 4GsydW6ksJz9sW8
for <incoming@patchwork.ozlabs.org>; Mon, 23 Aug 2021 00:37:35 +1000 (AEST)
Received: from h2850616.stratoserver.net (localhost [IPv6:::1])
by phobos.denx.de (Postfix) with ESMTP id E456680C87;
Sun, 22 Aug 2021 16:37:28 +0200 (CEST)
Authentication-Results: phobos.denx.de;
dmarc=fail (p=none dis=none) header.from=collabora.com
Authentication-Results: phobos.denx.de;
spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de
Received: by phobos.denx.de (Postfix, from userid 109)
id 2DF9A80612; Sun, 22 Aug 2021 16:37:03 +0200 (CEST)
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de
X-Spam-Level:
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,
SPF_PASS autolearn=ham autolearn_force=no version=3.4.2
Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk
[IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by phobos.denx.de (Postfix) with ESMTPS id E18A480612
for <u-boot@lists.denx.de>; Sun, 22 Aug 2021 16:36:58 +0200 (CEST)
Authentication-Results: phobos.denx.de;
dmarc=pass (p=none dis=none) header.from=collabora.com
Authentication-Results: phobos.denx.de;
spf=pass smtp.mailfrom=sjoerd@collabora.com
Received: from beast.luon.net (unknown
[IPv6:2a00:bba0:114f:8c00:40e2:7ff:fef4:3122])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested) (Authenticated sender: sjoerd)
by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 7EB361F42806;
Sun, 22 Aug 2021 15:36:58 +0100 (BST)
Received: by beast.luon.net (Postfix, from userid 1000)
id 3CAF1819617; Sun, 22 Aug 2021 16:36:56 +0200 (CEST)
From: Sjoerd Simons <sjoerd@collabora.com>
To: u-boot@lists.denx.de
Cc: Ariel D'Alessandro <ariel.dalessandro@collabora.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Matthias Brugger <mbrugger@suse.com>,
Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
Peter Robinson <pbrobinson@gmail.com>
Subject: [PATCH] rpi: Copy properties from firmware dtb to the loaded dtb
Date: Sun, 22 Aug 2021 16:36:55 +0200
Message-Id: <20210822143656.289891-1-sjoerd@collabora.com>
X-Mailer: git-send-email 2.33.0
MIME-Version: 1.0
X-Mailman-Approved-At: Sun, 22 Aug 2021 16:37:27 +0200
X-BeenThere: u-boot@lists.denx.de
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: U-Boot discussion <u-boot.lists.denx.de>
List-Unsubscribe: <https://lists.denx.de/options/u-boot>,
<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>
List-Archive: <https://lists.denx.de/pipermail/u-boot/>
List-Post: <mailto:u-boot@lists.denx.de>
List-Help: <mailto:u-boot-request@lists.denx.de?subject=help>
List-Subscribe: <https://lists.denx.de/listinfo/u-boot>,
<mailto:u-boot-request@lists.denx.de?subject=subscribe>
Errors-To: u-boot-bounces@lists.denx.de
Sender: "U-Boot" <u-boot-bounces@lists.denx.de>
X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de
X-Virus-Status: Clean
The RPI firmware adjusts several property values in the dtb it passes
to u-boot depending on the board/SoC revision. Inherit some of these
when u-boot loads a dtb itself. Specificaly copy:
* /model: The firmware provides a more specific string
* /memreserve: The firmware defines a reserved range, better keep it
* emmc2bus and pcie0 dma-ranges: The C0T revision of the bcm2711 Soc (as
present on rpi 400 and some rpi 4B boards) has different values for
these then the B0T revision. So these need to be adjusted to boot on
these boards
* blconfig: The firmware defines the memory area where the blconfig
stored. Copy those over so it can be enabled.
* /chosen/kaslr-seed: The firmware generates a kaslr seed, take advantage
of that.
Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
---
board/raspberrypi/rpi/rpi.c | 47 +++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
index df52a4689f..d9467f4bda 100644
--- a/board/raspberrypi/rpi/rpi.c
+++ b/board/raspberrypi/rpi/rpi.c
@@ -495,8 +495,55 @@ void *board_fdt_blob_setup(void)
return (void *)fw_dtb_pointer;
}
+int copy_property(void *dst, void *src, char *path, char *property)
+{
+ int dst_offset, src_offset;
+ const fdt32_t *prop;
+ int len;
+
+ src_offset = fdt_path_offset(src, path);
+ dst_offset = fdt_path_offset(dst, path);
+
+ if (src_offset < 0 || dst_offset < 0)
+ return -1;
+
+ prop = fdt_getprop(src, src_offset, property, &len);
+ if (!prop)
+ return -1;
+
+ return fdt_setprop(dst, dst_offset, property, prop, len);
+}
+
+/* Copy tweaks from the firmware dtb to the loaded dtb */
+void update_fdt_from_fw(void *fdt, void *fw_fdt)
+{
+ /* Using dtb from firmware directly; leave it alone */
+ if (fdt == fw_fdt)
+ return;
+
+ /* The firmware provides a more precie model; so copy that */
+ copy_property(fdt, fw_fdt, "/", "model");
+
+ /* memory reserve as suggested by the firmware */
+ copy_property(fdt, fw_fdt, "/", "memreserve");
+
+ /* Adjust dma-ranges for the SD card and PCI bus as they can depend on
+ * the SoC revision
+ */
+ copy_property(fdt, fw_fdt, "emmc2bus", "dma-ranges");
+ copy_property(fdt, fw_fdt, "pcie0", "dma-ranges");
+
+ /* Bootloader configuration template exposes as nvmem */
+ if (copy_property(fdt, fw_fdt, "blconfig", "reg") == 0)
+ copy_property(fdt, fw_fdt, "blconfig", "status");
+
+ /* kernel address randomisation seed as provided by the firmware */
+ copy_property(fdt, fw_fdt, "/chosen", "kaslr-seed");
+}
+
int ft_board_setup(void *blob, struct bd_info *bd)
{
+ update_fdt_from_fw(blob, (void *)fw_dtb_pointer);
/*
* For now, we simply always add the simplefb DT node. Later, we
* should be more intelligent, and e.g. only do this if no enabled DT

View File

@ -2,7 +2,7 @@
Name: uboot-tools
Version: 2021.10
Release: 0.3%{?candidate:.%{candidate}}%{?dist}
Release: 0.4%{?candidate:.%{candidate}}%{?dist}
Summary: U-Boot utilities
License: GPLv2+ BSD LGPL-2.1+ LGPL-2.0+
URL: http://www.denx.de/wiki/U-Boot
@ -19,6 +19,7 @@ Source4: aarch64-chromebooks
Patch1: uefi-distro-load-FDT-from-any-partition-on-boot-device.patch
# RPi - uses RPI firmware device tree for HAT support
Patch2: rpi-Enable-using-the-DT-provided-by-the-Raspberry-Pi.patch
Patch3: rpi-Copy-properties-from-firmware-dtb-to-the-loaded-dtb.patch
# Board fixes and enablement
# AllWinner improvements
@ -255,6 +256,9 @@ cp -p board/warp7/README builds/docs/README.warp7
%endif
%changelog
* Tue Aug 24 2021 Peter Robinson <pbrobinson@fedoraproject.org> - 2021.10-0.4.rc2
- Fix for Raspberry Pi firmware properties
* Mon Aug 23 2021 Peter Robinson <pbrobinson@fedoraproject.org> - 2021.10-0.3.rc2
- Fix for rockchip SPI