···11+From 65d90cd17ad7cd3f9aeeb805a08be780fc5bae1a Mon Sep 17 00:00:00 2001
22+From: Sjoerd Simons <sjoerd@collabora.com>
33+Date: Sun, 22 Aug 2021 16:36:55 +0200
44+Subject: [PATCH] rpi: Copy properties from firmware dtb to the loaded dtb
55+66+The RPI firmware adjusts several property values in the dtb it passes
77+to u-boot depending on the board/SoC revision. Inherit some of these
88+when u-boot loads a dtb itself. Specificaly copy:
99+1010+* /model: The firmware provides a more specific string
1111+* /memreserve: The firmware defines a reserved range, better keep it
1212+* emmc2bus and pcie0 dma-ranges: The C0T revision of the bcm2711 Soc (as
1313+ present on rpi 400 and some rpi 4B boards) has different values for
1414+ these then the B0T revision. So these need to be adjusted to boot on
1515+ these boards
1616+* blconfig: The firmware defines the memory area where the blconfig
1717+ stored. Copy those over so it can be enabled.
1818+* /chosen/kaslr-seed: The firmware generates a kaslr seed, take advantage
1919+ of that.
2020+2121+Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
2222+Origin: https://patchwork.ozlabs.org/project/uboot/patch/20210822143656.289891-1-sjoerd@collabora.com/
2323+---
2424+ board/raspberrypi/rpi/rpi.c | 48 +++++++++++++++++++++++++++++++++++++
2525+ 1 file changed, 48 insertions(+)
2626+2727+diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
2828+index 372b26b6f2..64b8684b68 100644
2929+--- a/board/raspberrypi/rpi/rpi.c
3030++++ b/board/raspberrypi/rpi/rpi.c
3131+@@ -495,10 +495,58 @@ void *board_fdt_blob_setup(void)
3232+ return (void *)fw_dtb_pointer;
3333+ }
3434+3535++int copy_property(void *dst, void *src, char *path, char *property)
3636++{
3737++ int dst_offset, src_offset;
3838++ const fdt32_t *prop;
3939++ int len;
4040++
4141++ src_offset = fdt_path_offset(src, path);
4242++ dst_offset = fdt_path_offset(dst, path);
4343++
4444++ if (src_offset < 0 || dst_offset < 0)
4545++ return -1;
4646++
4747++ prop = fdt_getprop(src, src_offset, property, &len);
4848++ if (!prop)
4949++ return -1;
5050++
5151++ return fdt_setprop(dst, dst_offset, property, prop, len);
5252++}
5353++
5454++/* Copy tweaks from the firmware dtb to the loaded dtb */
5555++void update_fdt_from_fw(void *fdt, void *fw_fdt)
5656++{
5757++ /* Using dtb from firmware directly; leave it alone */
5858++ if (fdt == fw_fdt)
5959++ return;
6060++
6161++ /* The firmware provides a more precie model; so copy that */
6262++ copy_property(fdt, fw_fdt, "/", "model");
6363++
6464++ /* memory reserve as suggested by the firmware */
6565++ copy_property(fdt, fw_fdt, "/", "memreserve");
6666++
6767++ /* Adjust dma-ranges for the SD card and PCI bus as they can depend on
6868++ * the SoC revision
6969++ */
7070++ copy_property(fdt, fw_fdt, "emmc2bus", "dma-ranges");
7171++ copy_property(fdt, fw_fdt, "pcie0", "dma-ranges");
7272++
7373++ /* Bootloader configuration template exposes as nvmem */
7474++ if (copy_property(fdt, fw_fdt, "blconfig", "reg") == 0)
7575++ copy_property(fdt, fw_fdt, "blconfig", "status");
7676++
7777++ /* kernel address randomisation seed as provided by the firmware */
7878++ copy_property(fdt, fw_fdt, "/chosen", "kaslr-seed");
7979++}
8080++
8181+ int ft_board_setup(void *blob, struct bd_info *bd)
8282+ {
8383+ int node;
8484+8585++ update_fdt_from_fw(blob, (void *)fw_dtb_pointer);
8686++
8787+ node = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
8888+ if (node < 0)
8989+ lcd_dt_simplefb_add_node(blob);
9090+--
9191+2.32.0
9292+