···1+From 65d90cd17ad7cd3f9aeeb805a08be780fc5bae1a Mon Sep 17 00:00:00 2001
2+From: Sjoerd Simons <sjoerd@collabora.com>
3+Date: Sun, 22 Aug 2021 16:36:55 +0200
4+Subject: [PATCH] rpi: Copy properties from firmware dtb to the loaded dtb
5+6+The RPI firmware adjusts several property values in the dtb it passes
7+to u-boot depending on the board/SoC revision. Inherit some of these
8+when u-boot loads a dtb itself. Specificaly copy:
9+10+* /model: The firmware provides a more specific string
11+* /memreserve: The firmware defines a reserved range, better keep it
12+* emmc2bus and pcie0 dma-ranges: The C0T revision of the bcm2711 Soc (as
13+ present on rpi 400 and some rpi 4B boards) has different values for
14+ these then the B0T revision. So these need to be adjusted to boot on
15+ these boards
16+* blconfig: The firmware defines the memory area where the blconfig
17+ stored. Copy those over so it can be enabled.
18+* /chosen/kaslr-seed: The firmware generates a kaslr seed, take advantage
19+ of that.
20+21+Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
22+Origin: https://patchwork.ozlabs.org/project/uboot/patch/20210822143656.289891-1-sjoerd@collabora.com/
23+---
24+ board/raspberrypi/rpi/rpi.c | 48 +++++++++++++++++++++++++++++++++++++
25+ 1 file changed, 48 insertions(+)
26+27+diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
28+index 372b26b6f2..64b8684b68 100644
29+--- a/board/raspberrypi/rpi/rpi.c
30++++ b/board/raspberrypi/rpi/rpi.c
31+@@ -495,10 +495,58 @@ void *board_fdt_blob_setup(void)
32+ return (void *)fw_dtb_pointer;
33+ }
34+35++int copy_property(void *dst, void *src, char *path, char *property)
36++{
37++ int dst_offset, src_offset;
38++ const fdt32_t *prop;
39++ int len;
40++
41++ src_offset = fdt_path_offset(src, path);
42++ dst_offset = fdt_path_offset(dst, path);
43++
44++ if (src_offset < 0 || dst_offset < 0)
45++ return -1;
46++
47++ prop = fdt_getprop(src, src_offset, property, &len);
48++ if (!prop)
49++ return -1;
50++
51++ return fdt_setprop(dst, dst_offset, property, prop, len);
52++}
53++
54++/* Copy tweaks from the firmware dtb to the loaded dtb */
55++void update_fdt_from_fw(void *fdt, void *fw_fdt)
56++{
57++ /* Using dtb from firmware directly; leave it alone */
58++ if (fdt == fw_fdt)
59++ return;
60++
61++ /* The firmware provides a more precie model; so copy that */
62++ copy_property(fdt, fw_fdt, "/", "model");
63++
64++ /* memory reserve as suggested by the firmware */
65++ copy_property(fdt, fw_fdt, "/", "memreserve");
66++
67++ /* Adjust dma-ranges for the SD card and PCI bus as they can depend on
68++ * the SoC revision
69++ */
70++ copy_property(fdt, fw_fdt, "emmc2bus", "dma-ranges");
71++ copy_property(fdt, fw_fdt, "pcie0", "dma-ranges");
72++
73++ /* Bootloader configuration template exposes as nvmem */
74++ if (copy_property(fdt, fw_fdt, "blconfig", "reg") == 0)
75++ copy_property(fdt, fw_fdt, "blconfig", "status");
76++
77++ /* kernel address randomisation seed as provided by the firmware */
78++ copy_property(fdt, fw_fdt, "/chosen", "kaslr-seed");
79++}
80++
81+ int ft_board_setup(void *blob, struct bd_info *bd)
82+ {
83+ int node;
84+85++ update_fdt_from_fw(blob, (void *)fw_dtb_pointer);
86++
87+ node = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
88+ if (node < 0)
89+ lcd_dt_simplefb_add_node(blob);
90+--
91+2.32.0
92+