Hi everyone, could I get some feedback on this patch, in particular if creating a temporary overlay is the right way to create the /system node if necessary? If yes, I intend to add error checks and minimize the buffer size, otherwise rework it for whatever is the better approach.
Best regards, Fiona Am 11.02.25 um 14:58 schrieb Fiona Klute:
Both the Raspberry Pi downstream kernel [1] and some userspace tools [2] use the revision property to identify the board, and the latter fails if it is absent. The firmware creates the /system node, so we need to do the same. [1] https://github.com/raspberrypi/linux/blob/0f292fbb6346b05766152902076895558ac23f9a/arch/arm/mach-bcm/board_bcm2835.c#L23-L33 [2] https://github.com/jgarff/rpi_ws281x/blob/7fc0bf8b31d715bbecf28e852ede5aaa388180da/rpihw.c#L579 Signed-off-by: Fiona Klute <[email protected]> Cc: Matthias Brugger <[email protected]> Cc: Peter Robinson <[email protected]> Cc: Tom Rini <[email protected]> --- I'm sending this as RFC because I'm not sure if creating a temporary overlay is the best approach here, advice on a better way to create the /system node if needed is very much welcome. I know I'll need to add more error checks, I'll do that after I know I have the right approach. board/raspberrypi/rpi/rpi.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index aa39afa338a..647716127c7 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -550,6 +550,41 @@ int copy_property(void *dst, void *src, char *path, char *property) return fdt_setprop(dst, dst_offset, property, prop, len); } +int copy_system_node(void *fdt, void *fw_fdt) +{ + const fdt32_t *prop; + char fdto[2048]; + int src_offset; + int len; + + src_offset = fdt_path_offset(fw_fdt, "/system"); + if (src_offset < 0) + return -1; + + fdt_create(fdto, sizeof(fdto)); + fdt_finish_reservemap(fdto); + fdt_begin_node(fdto, ""); + fdt_begin_node(fdto, "fragment"); + fdt_property_string(fdto, "target-path", "/"); + fdt_begin_node(fdto, "__overlay__"); + fdt_begin_node(fdto, "system"); + + prop = fdt_getprop(fw_fdt, src_offset, "linux,serial", &len); + if (prop) + fdt_property(fdto, "linux,serial", prop, len); + prop = fdt_getprop(fw_fdt, src_offset, "linux,revision", &len); + if (prop) + fdt_property(fdto, "linux,revision", prop, len); + + fdt_end_node(fdto); + fdt_end_node(fdto); + fdt_end_node(fdto); + fdt_end_node(fdto); + fdt_finish(fdto); + + fdt_overlay_apply_verbose(fdt, fdto); +} + /* Copy tweaks from the firmware dtb to the loaded dtb */ void update_fdt_from_fw(void *fdt, void *fw_fdt) { @@ -560,6 +595,8 @@ void update_fdt_from_fw(void *fdt, void *fw_fdt) /* The firmware provides a more precise model; so copy that */ copy_property(fdt, fw_fdt, "/", "model"); + copy_system_node(fdt, fw_fdt); + /* memory reserve as suggested by the firmware */ copy_property(fdt, fw_fdt, "/", "memreserve");

