Skip to contentSkip to conversation

device_tree.c: Terminate the empty reservemap in create_device_tree()

PATCH In review Peter Maydell 2 participants 2 messages Sep 10, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 device_tree.c: Terminate the empty reservemap in create_device_tree()

Device trees created with create_device_tree() may not have any entries in their reservemap, because the FDT API requires that the reservemap is completed before any FDT nodes are added, and create_device_tree() itself creates a node. However we were not calling fdt_finish_reservemap(), which meant that there was no terminator in the reservemap list and whatever happened to be at the start of the FDT data section would end up being interpreted as reservemap entries. Avoid this by calling fdt_finish_reservemap() to add the terminator.

---
On ARM this manifested as a DTB with
/memreserve/ 0x0000000100000000 0x0000000200000009;
and my mach-virt test kernel wasn't booting as a result.

 device_tree.c |    4 ++++
 1 file changed, 4 insertions(+)
device_tree.c +4 -0
index ffec99a..391da8c 100644
@@ -41,6 +41,10 @@ void *create_device_tree(int *sizep)
     if (ret < 0) {
         goto fail;
     }
+    ret = fdt_finish_reservemap(fdt);
+    if (ret < 0) {
+        goto fail;
+    }
     ret = fdt_begin_node(fdt, "");
     if (ret < 0) {
         goto fail;
Signature · 1 line
1.7.9.5
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Peter Maydell

Device trees created with create_device_tree() may not have any entries in their reservemap, because the FDT API requires that the reservemap is completed before any FDT nodes are added, and create_device_tree() itself creates a node. However we were not calling fdt_finish_reservemap(), which meant that there was no terminator in the reservemap list and whatever happened to be at the start of the FDT data section would end up being interpreted as reservemap entries. Avoid this by calling fdt_finish_reservemap() to add the terminator.

Peter C, will you take this into your tree?

Alex