Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 198F9C32771 for ; Fri, 19 Aug 2022 14:08:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 22BAF84BF3; Fri, 19 Aug 2022 16:06:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=karthanis.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=karthanis.net header.i=@karthanis.net header.b="ummK3bWp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 279E084A7B; Fri, 19 Aug 2022 10:57:45 +0200 (CEST) Received: from smtp-190c.mail.infomaniak.ch (smtp-190c.mail.infomaniak.ch [IPv6:2001:1600:4:17::190c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C4D2984A2C for ; Fri, 19 Aug 2022 10:57:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=karthanis.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=antoine@karthanis.net Received: from smtp-3-0000.mail.infomaniak.ch (unknown [10.4.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4M8FyG3PHzzMq0p1; Fri, 19 Aug 2022 10:57:42 +0200 (CEST) Received: from localhost.localdomain (unknown [88.168.170.86]) by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4M8FyF5jQXzlrKcx; Fri, 19 Aug 2022 10:57:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=karthanis.net; s=20191114; t=1660899462; bh=tIvNc767NoIlYCkzX8R3Rne0F7NKwIWOEcFXO0yogAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ummK3bWpo4TceEYdDKTr7juk66k71Xa83t9mgXUxiS6u9/hcAnvoAy6/ZZMv1WFAz oI4YIgLOQCC6pKQfClvfHq/PrCJeDzS77QxbTO+yC0lqlcYD641+0skBU3bHZYG93X 47mWg/PnEFTibxZwY7kAz1Bt1f53w07XriRmjti4= From: Antoine Mazeas To: u-boot@lists.denx.de Cc: Matthias Brugger , Antoine Mazeas , Sjoerd Simons Subject: [RESEND PATCH 1/2] rpi: Copy properties from firmware dtb to the loaded dtb Date: Fri, 19 Aug 2022 10:56:45 +0200 Message-Id: <20220819085646.341575-2-antoine@karthanis.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819085646.341575-1-antoine@karthanis.net> References: <20220819085646.341575-1-antoine@karthanis.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 19 Aug 2022 16:06:11 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 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 Signed-off-by: Antoine Mazeas --- board/raspberrypi/rpi/rpi.c | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index 17b8108cc8..28b6f52506 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -504,10 +504,58 @@ void *board_fdt_blob_setup(int *err) 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) { int node; + update_fdt_from_fw(blob, (void *)fw_dtb_pointer); + node = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer"); if (node < 0) fdt_simplefb_add_node(blob); -- 2.37.2