]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
riscv: Expand the DT size before copy reserved memory node
authorBin Meng <bin.meng@windriver.com>
Fri, 26 Jun 2020 01:16:07 +0000 (18:16 -0700)
committerAndes <uboot@andestech.com>
Thu, 2 Jul 2020 02:03:09 +0000 (10:03 +0800)
The FDT blob might not have sufficient space to hold a copy of
reserved memory node. Expand it before the copy.

Reported-by: Rick Chen <rick@andestech.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Rick Chen <rick@andestech.com>
arch/riscv/lib/fdt_fixup.c

index 5f523f0e07d5e2c6fecdead37b393bb0f92ae98f..160ccca76e02d2b93524d9c3e3cf77d435c17bf3 100644 (file)
@@ -41,6 +41,18 @@ int riscv_fdt_copy_resv_mem_node(const void *src, void *dst)
                return 0;
        }
 
+       /*
+        * Extend the FDT by the following estimated size:
+        *
+        * Each PMP memory region entry occupies 64 bytes.
+        * With 16 PMP memory regions we need 64 * 16 = 1024 bytes.
+        */
+       err = fdt_open_into(dst, dst, fdt_totalsize(dst) + 1024);
+       if (err < 0) {
+               printf("Device Tree can't be expanded to accommodate new node");
+               return err;
+       }
+
        fdt_for_each_subnode(node, src, offset) {
                name = fdt_get_name(src, node, NULL);