Skip to contentSkip to conversation

fdt_resize(): fix actualsize calculations with unaligned blobs

PATCH New Peter Korsgaard 2 participants 2 messages Jan 14, 2009 – Jan 17, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fdt_resize(): fix actualsize calculations with unaligned blobs

The code in fdt_resize() to extend the fdt size to end on a page boundary is wrong for fdt's not located at an address aligned on a page boundary. What's even worse, the code would make actualsize shrink rather than grow if (blob & 0xfff) was bigger than the amount of padding added by ALIGN(), causing fdt_add_mem_rsv to fail.

Fix it by aligning end address (blob + size) to a page boundary instead. For aligned fdt's this is equivalent to what we had before.

---
This was already discussed back in October:

    http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/48912
 But the commit (f242a08871) only fixed part of the problem.
 common/fdt_support.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
common/fdt_support.c +1 -1
index 5a83bca..a79bc08 100644
@@ -610,7 +610,7 @@ int fdt_resize(void *blob)
 		fdt_size_dt_strings(blob) + sizeof(struct fdt_reserve_entry);
 
 	/* Make it so the fdt ends on a page boundary */
-	actualsize = ALIGN(actualsize, 0x1000);
+	actualsize = ALIGN(actualsize + ((uint)blob & 0xfff), 0x1000);
 	actualsize = actualsize - ((uint)blob & 0xfff);
 
 	/* Change the fdt header to reflect the correct size */
Signature · 1 line
1.5.6.5
#1 lore raw

PATCH 1/1 fdt_resize(): fix actualsize calculations with unaligned blobs

Quoted 10 lines · Peter Korsgaard

The code in fdt_resize() to extend the fdt size to end on a page boundary is wrong for fdt's not located at an address aligned on a page boundary. What's even worse, the code would make actualsize shrink rather than grow if (blob & 0xfff) was bigger than the amount of padding added by ALIGN(), causing fdt_add_mem_rsv to fail.

Fix it by aligning end address (blob + size) to a page boundary instead. For aligned fdt's this is equivalent to what we had before.

Applied to u-boot-fdt. I will call for Wolfgang to pull shortly.

Thanks,
gvb