Skip to contentSkip to conversation

rpi: Copy eth PHY address from fw DT to loaded DT

PATCH RESEND In review Antoine Mazeas 4 participants 10 messages Aug 19, 2022 – Jan 9, 2023 Broadcom BCM2711/BCM2835 Arm architecture

lore
Share & tools
lore
#0 lore raw

cover rpi: Copy eth PHY address from fw DT to loaded DT

Sjoerd Simons submitted the original patch (0001) to carry over some firmware-provided properties into the loaded device tree. This did not fix an issue with Raspberry Pi 400 rev 1.1 boards which would not be able to find the ethernet PHY device at the address specified by the kernel device tree.

Patch 0002 expands on Sjoerd's design to also carry over the real ethernet PHY address, enabling the kernel to find and enable a working ethernet on pi 400 rev 1.1 boards.

Antoine Mazeas (2):
rpi: Copy properties from firmware dtb to the loaded dtb
rpi: Copy eth PHY address from fw DT to loaded DT

 board/raspberrypi/rpi/rpi.c | 51 +++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
Signature · 1 line
2.37.2
#1 lore raw

PATCH RESEND 1/2 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.

---

 board/raspberrypi/rpi/rpi.c | 48 +++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
board/raspberrypi/rpi/rpi.c +48 -0
index 17b8108cc8..28b6f52506 100644
@@ -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);
Signature · 1 line
2.37.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [RESEND PATCH 1/2] rpi: Copy properties from firmware dtb to the loaded dtb

Hi Antoine,

Quoted 16 lines · Antoine Mazeas

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.

Quoted 6 lines

---

 board/raspberrypi/rpi/rpi.c | 48 +++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

I wonder if anyone has tried to drop the private firmware on the boards?

At some point copy_property() should move to fdt_support.c if others use it

#3 lore raw

Re: [RESEND PATCH 1/2] rpi: Copy properties from firmware dtb to the loaded dtb

Thanks Simon,

Can I ask you to clarify what you meant by "drop the private firmware"? For the record, this patch was tested using the vendored firmware from Raspberry Pi, v1.20220331, and subsequently v1.20220811 when it came out.

I'm happy to do the requested change now if you think it is preferable.

Regards

Le 22/08/2022 à 18:39, Simon Glass a écrit :

Quoted 31 lines

Hi Antoine,

Quoted 16 lines · Antoine Mazeas

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.

Quoted 6 lines

---

  board/raspberrypi/rpi/rpi.c | 48 +++++++++++++++++++++++++++++++++++++
  1 file changed, 48 insertions(+)

I wonder if anyone has tried to drop the private firmware on the boards?

At some point copy_property() should move to fdt_support.c if others use it

#4 lore raw

Re: [RESEND PATCH 1/2] rpi: Copy properties from firmware dtb to the loaded dtb

Hi Antoine,

Quoted 4 lines · Antoine Mazeas

Thanks Simon,

Can I ask you to clarify what you meant by "drop the private firmware"?

Replace the private binary with a full U-Boot implementation. I hope that the vendor might do it one day.

Quoted 5 lines

For the record, this patch was tested using the vendored firmware from Raspberry Pi, v1.20220331, and subsequently v1.20220811 when it came out.

I'm happy to do the requested change now if you think it is preferable.

No need, it's fine. We'll keep an eye out for it if someone else uses your function.

Regards,
Simon

Quoted 35 lines

Regards

Quoted 31 lines · Simon Glass

Hi Antoine,

Quoted 16 lines · Antoine Mazeas

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.

Quoted 6 lines

---

  board/raspberrypi/rpi/rpi.c | 48 +++++++++++++++++++++++++++++++++++++
  1 file changed, 48 insertions(+)

I wonder if anyone has tried to drop the private firmware on the boards?

At some point copy_property() should move to fdt_support.c if others use it

#5 lore raw

Re: [RESEND PATCH 1/2] rpi: Copy properties from firmware dtb to the loaded dtb

Hi Simon,

Le 23/08/2022 à 15:38, Simon Glass a écrit :

Quoted 10 lines

Hi Antoine,

Quoted 4 lines · Antoine Mazeas

Thanks Simon,

Can I ask you to clarify what you meant by "drop the private firmware"?

Replace the private binary with a full U-Boot implementation. I hope that the vendor might do it one day.

I'm not aware whether this has been done, this would make things easier and more obvious for sure.

Quoted 8 lines
Quoted 5 lines

For the record, this patch was tested using the vendored firmware from Raspberry Pi, v1.20220331, and subsequently v1.20220811 when it came out.

I'm happy to do the requested change now if you think it is preferable.

No need, it's fine. We'll keep an eye out for it if someone else uses your function.

Thank you, sounds good!

Regards
Antoine

Quoted 39 lines

Regards,
Simon

Quoted 35 lines

Regards

Quoted 31 lines · Simon Glass

Hi Antoine,

Quoted 16 lines · Antoine Mazeas

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.

Quoted 6 lines

---

   board/raspberrypi/rpi/rpi.c | 48 +++++++++++++++++++++++++++++++++++++
   1 file changed, 48 insertions(+)

I wonder if anyone has tried to drop the private firmware on the boards?

At some point copy_property() should move to fdt_support.c if others use it

#6 lore raw

PATCH RESEND 2/2 rpi: Copy eth PHY address from fw DT to loaded DT

In reply to Antoine Mazeas

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.

---

 board/raspberrypi/rpi/rpi.c | 3 +++
 1 file changed, 3 insertions(+)
board/raspberrypi/rpi/rpi.c +3 -0
index 28b6f52506..793fd1aa30 100644
@@ -548,6 +548,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)
Signature · 1 line
2.37.2
#7 lore raw
In reply to Antoine Mazeas

Why did you need to resend it?

Quoted 22 lines · Antoine Mazeas

Sjoerd Simons submitted the original patch (0001) to carry over some firmware-provided properties into the loaded device tree. This did not fix an issue with Raspberry Pi 400 rev 1.1 boards which would not be able to find the ethernet PHY device at the address specified by the kernel device tree.

Patch 0002 expands on Sjoerd's design to also carry over the real ethernet PHY address, enabling the kernel to find and enable a working ethernet on pi 400 rev 1.1 boards.

Antoine Mazeas (2):
rpi: Copy properties from firmware dtb to the loaded dtb
rpi: Copy eth PHY address from fw DT to loaded DT

 board/raspberrypi/rpi/rpi.c | 51 +++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

--
2.37.2

#8 lore raw

I had not used patman in the first instance and Matthias Brugger was not cc’ed with the patch properly. Given that I had no feedback, I thought best to resubmit via patman this time in case it had not been seen the first time because of this. However patman also picked up a different series title and did not allow for superseding the first submission.

I hope this lapse in process does not reflect too badly on this patch.

Regards

Quoted 25 lines · Peter Robinson

Why did you need to resend it?

Quoted 21 lines · Antoine Mazeas

Sjoerd Simons submitted the original patch (0001) to carry over some firmware-provided properties into the loaded device tree. This did not fix an issue with Raspberry Pi 400 rev 1.1 boards which would not be able to find the ethernet PHY device at the address specified by the kernel device tree.

Patch 0002 expands on Sjoerd's design to also carry over the real ethernet PHY address, enabling the kernel to find and enable a working ethernet on pi 400 rev 1.1 boards.

Antoine Mazeas (2):
rpi: Copy properties from firmware dtb to the loaded dtb
rpi: Copy eth PHY address from fw DT to loaded DT

board/raspberrypi/rpi/rpi.c | 51 +++++++++++++++++++++++++++++++++++++

1 file changed, 51 insertions(+)

--
2.37.2

Tested-by on the v1 series
#9 lore raw
In reply to Antoine Mazeas
Quoted 11 lines

Sjoerd Simons submitted the original patch (0001) to carry over some firmware-provided properties into the loaded device tree. This did not fix an issue with Raspberry Pi 400 rev 1.1 boards which would not be able to find the ethernet PHY device at the address specified by the kernel device tree.

Patch 0002 expands on Sjoerd's design to also carry over the real ethernet PHY address, enabling the kernel to find and enable a working ethernet on pi 400 rev 1.1 boards.

Quoted 6 lines

Antoine Mazeas (2):
rpi: Copy properties from firmware dtb to the loaded dtb
rpi: Copy eth PHY address from fw DT to loaded DT

 board/raspberrypi/rpi/rpi.c | 51 +++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

Thanks!!! These patches help u-boot boot Endelss OS on RPi 400.