From 6d0642494993f39440a4d6e95f88c0456ee6d689 Mon Sep 17 00:00:00 2001 From: Antoine Mazeas Date: Fri, 19 Aug 2022 10:56:45 +0200 Subject: rpi: Copy properties from firmware dtb to the loaded dtb 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 Reviewed-by: Simon Glass Signed-off-by: Peter Robinson --- board/raspberrypi/rpi/rpi.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'board/raspberrypi/rpi/rpi.c') diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index 8603c93de77..d4b059c6204 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -503,10 +503,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); -- cgit v1.2.3 From 4a45086c0ca874858d4064ee26d45199bcab494d Mon Sep 17 00:00:00 2001 From: Antoine Mazeas Date: Fri, 19 Aug 2022 10:56:46 +0200 Subject: rpi: Copy eth PHY address from fw DT to loaded DT Some Raspberry Pi 400 boards, specifically rev 1.1, have a different address for the ethernet PHY device than what is provided by the kernel DTB. The correct address is provided by the firmware, so we should carry it over into the loaded device tree so that ethernet works on such boards. Signed-off-by: Antoine Mazeas Signed-off-by: Peter Robinson --- board/raspberrypi/rpi/rpi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'board/raspberrypi/rpi/rpi.c') diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index d4b059c6204..fc1fffedfb7 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -547,6 +547,9 @@ void update_fdt_from_fw(void *fdt, void *fw_fdt) /* kernel address randomisation seed as provided by the firmware */ copy_property(fdt, fw_fdt, "/chosen", "kaslr-seed"); + + /* address of the PHY device as provided by the firmware */ + copy_property(fdt, fw_fdt, "ethernet0/mdio@e14/ethernet-phy@1", "reg"); } int ft_board_setup(void *blob, struct bd_info *bd) -- cgit v1.2.3 From 0e8c94054fd80535e868900deb978a9a1ebcab67 Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Tue, 28 Feb 2023 10:17:26 +0000 Subject: rpi: Update the RPi Zero 2W DT filename Update the Raspberry Pi Zero 2W device tree file name to match what landed upstream. Signed-off-by: Peter Robinson --- board/raspberrypi/rpi/rpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'board/raspberrypi/rpi/rpi.c') diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index fc1fffedfb7..1057ebb9948 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -158,7 +158,7 @@ static const struct rpi_model rpi_models_new_scheme[] = { }, [0x12] = { "Zero 2 W", - DTB_DIR "bcm2837-rpi-zero-2.dtb", + DTB_DIR "bcm2837-rpi-zero-2-w.dtb", false, }, [0x13] = { -- cgit v1.2.3