The Raspberry Pi has the "tryboot" feature where it can boot from a
different partition enabling failsafe A/B updates. After boot the
firmware adds some properties in /chosen/bootloader, e.g. partition.

Copy the complete /chosen/bootloader node with all its properties to the
OS device tree.

Signed-off-by: Gregor Herburger <[email protected]>
Tested-by: Peter Robinson <[email protected]>
---
 board/raspberrypi/rpi/rpi.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
index 8354fec833cc..ba8a2c1ba4cf 100644
--- a/board/raspberrypi/rpi/rpi.c
+++ b/board/raspberrypi/rpi/rpi.c
@@ -594,6 +594,39 @@ int board_fdt_blob_setup(void **fdtp)
        return 0;
 }
 
+int copy_node_all_properties(void *dst, void *src, const char *path, const 
char *node)
+{
+       int src_parent, dst_parent;
+       int src_node, dst_node;
+       int prop;
+       int len;
+
+       src_parent = fdt_path_offset(src, path);
+       dst_parent = fdt_path_offset(dst, path);
+       if (src_parent < 0 || dst_parent < 0)
+               return -1;
+
+       src_node = fdt_subnode_offset(src, src_parent, node);
+       if (src_node < 0)
+               return -1;
+
+       dst_node = fdt_find_or_add_subnode(dst, dst_parent, node);
+       if (dst_node < 0)
+               return -1;
+
+       fdt_for_each_property_offset(prop, src, src_node) {
+               const char *name;
+               const void *value = fdt_getprop_by_offset(src, prop, &name, 
&len);
+
+               if (!value || !name)
+                       continue;
+
+               fdt_setprop(dst, dst_node, name, value, len);
+       }
+
+       return 0;
+}
+
 int copy_property(void *dst, void *src, char *path, char *property)
 {
        int dst_offset, src_offset;
@@ -656,6 +689,9 @@ void  update_fdt_from_fw(void *fdt, void *fw_fdt)
 
        /* copy uart clk as provided by the firmware */
        copy_property(fdt, fw_fdt, "/clocks/clk-uart", "clock-frequency");
+
+       /* Copy the bootloader node */
+       copy_node_all_properties(fdt, fw_fdt, "/chosen", "bootloader");
 }
 
 int ft_board_setup(void *blob, struct bd_info *bd)

-- 
2.47.3

Reply via email to