diff mbox

core/fdt: Always add a reserve map

Message ID 20170608115122.6978-1-oohall@gmail.com
State Accepted
Headers show

Commit Message

Oliver O'Halloran June 8, 2017, 11:51 a.m. UTC
Currently we skip adding the reserved ranges block to the generated
FDT blob if we are excluding the root node. This can result in a DTB
that dtc will barf on because the reserved memory ranges overlap with
the start of the dt_struct block. As an example:

$ fdtdump broken.dtb -d
/dts-v1/;
// magic:               0xd00dfeed
// totalsize:           0x7f3 (2035)
// off_dt_struct:       0x30  <----\
// off_dt_strings:      0x7b8       | this is bad!
// off_mem_rsvmap:      0x30  <----/
// version:             17
// last_comp_version:   16
// boot_cpuid_phys:     0x0
// size_dt_strings:     0x3b
// size_dt_struct:      0x788

/memreserve/ 0x100000000 0x300000004;
/memreserve/ 0x3300000001 0x169626d2c;
/memreserve/ 0x706369652d736c6f 0x7473000000000003;
	*continues*

With this patch:

$ fdtdump working.dtb -d
/dts-v1/;
// magic:               0xd00dfeed
// totalsize:           0x803 (2051)
// off_dt_struct:       0x40
// off_dt_strings:      0x7c8
// off_mem_rsvmap:      0x30
// version:             17
// last_comp_version:   16
// boot_cpuid_phys:     0x0
// size_dt_strings:     0x3b
// size_dt_struct:      0x788

// 0040: tag: 0x00000001 (FDT_BEGIN_NODE)
/ {
// 0048: tag: 0x00000003 (FDT_PROP)
// 07fb: string: phandle
// 0054: value
    phandle = <0x00000001>;
	*continues*

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 core/fdt.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Stewart Smith June 15, 2017, 4:07 a.m. UTC | #1
Oliver O'Halloran <oohall@gmail.com> writes:
> Currently we skip adding the reserved ranges block to the generated
> FDT blob if we are excluding the root node. This can result in a DTB
> that dtc will barf on because the reserved memory ranges overlap with
> the start of the dt_struct block. As an example:
>
> $ fdtdump broken.dtb -d
> /dts-v1/;
> // magic:               0xd00dfeed
> // totalsize:           0x7f3 (2035)
> // off_dt_struct:       0x30  <----\
> // off_dt_strings:      0x7b8       | this is bad!
> // off_mem_rsvmap:      0x30  <----/
> // version:             17
> // last_comp_version:   16
> // boot_cpuid_phys:     0x0
> // size_dt_strings:     0x3b
> // size_dt_struct:      0x788
>
> /memreserve/ 0x100000000 0x300000004;
> /memreserve/ 0x3300000001 0x169626d2c;
> /memreserve/ 0x706369652d736c6f 0x7473000000000003;
> 	*continues*
>
> With this patch:
>
> $ fdtdump working.dtb -d
> /dts-v1/;
> // magic:               0xd00dfeed
> // totalsize:           0x803 (2051)
> // off_dt_struct:       0x40
> // off_dt_strings:      0x7c8
> // off_mem_rsvmap:      0x30
> // version:             17
> // last_comp_version:   16
> // boot_cpuid_phys:     0x0
> // size_dt_strings:     0x3b
> // size_dt_struct:      0x788
>
> // 0040: tag: 0x00000001 (FDT_BEGIN_NODE)
> / {
> // 0048: tag: 0x00000003 (FDT_PROP)
> // 07fb: string: phandle
> // 0054: value
>     phandle = <0x00000001>;
> 	*continues*
>
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>

Merged to master as of 106557d9d1888765cf6fccca7fe0dcf2b8fbe7fb
diff mbox

Patch

diff --git a/core/fdt.c b/core/fdt.c
index eabbd5411a47..0131c5e21f84 100644
--- a/core/fdt.c
+++ b/core/fdt.c
@@ -172,6 +172,9 @@  static int __create_dtb(void *fdt, size_t len,
 	fdt_create(fdt, len);
 	if (root == dt_root && !exclusive)
 		create_dtb_reservemap(fdt, root);
+	else
+		fdt_finish_reservemap(fdt);
+
 	flatten_dt_node(fdt, root, exclusive);
 
 	save_err(fdt_finish(fdt));