]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - scripts/dtc/fdtdump.c
2 * fdtdump.c - Contributed by Pantelis Antoniou <pantelis.antoniou AT gmail.com>
12 #include <libfdt_env.h>
16 #define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
17 #define PALIGN(p, a) ((void *)(ALIGN((unsigned long)(p), (a))))
18 #define GET_CELL(p) (p += 4, *((const uint32_t *)(p-4)))
20 static void print_data(const char *data
, int len
)
25 /* no data, don't print */
29 if (util_is_printable_string(data
, len
)) {
30 printf(" = \"%s\"", (const char *)data
);
31 } else if ((len
% 4) == 0) {
33 for (i
= 0; i
< len
; i
+= 4)
34 printf("0x%08x%s", fdt32_to_cpu(GET_CELL(p
)),
35 i
< (len
- 4) ? " " : "");
39 for (i
= 0; i
< len
; i
++)
40 printf("%02x%s", *p
++, i
< len
- 1 ? " " : "");
45 static void dump_blob(void *blob
)
47 struct fdt_header
*bph
= blob
;
48 uint32_t off_mem_rsvmap
= fdt32_to_cpu(bph
->off_mem_rsvmap
);
49 uint32_t off_dt
= fdt32_to_cpu(bph
->off_dt_struct
);
50 uint32_t off_str
= fdt32_to_cpu(bph
->off_dt_strings
);
51 struct fdt_reserve_entry
*p_rsvmap
=
52 (struct fdt_reserve_entry
*)((char *)blob
+ off_mem_rsvmap
);
53 const char *p_struct
= (const char *)blob
+ off_dt
;
54 const char *p_strings
= (const char *)blob
+ off_str
;
55 uint32_t version
= fdt32_to_cpu(bph
->version
);
56 uint32_t totalsize
= fdt32_to_cpu(bph
->totalsize
);
58 const char *p
, *s
, *t
;
66 printf("/dts-v1/;\n");
67 printf("// magic:\t\t0x%x\n", fdt32_to_cpu(bph
->magic
));
68 printf("// totalsize:\t\t0x%x (%d)\n", totalsize
, totalsize
);
69 printf("// off_dt_struct:\t0x%x\n", off_dt
);
70 printf("// off_dt_strings:\t0x%x\n", off_str
);
71 printf("// off_mem_rsvmap:\t0x%x\n", off_mem_rsvmap
);
72 printf("// version:\t\t%d\n", version
);
73 printf("// last_comp_version:\t%d\n",
74 fdt32_to_cpu(bph
->last_comp_version
));
76 printf("// boot_cpuid_phys:\t0x%x\n",
77 fdt32_to_cpu(bph
->boot_cpuid_phys
));
80 printf("// size_dt_strings:\t0x%x\n",
81 fdt32_to_cpu(bph
->size_dt_strings
));
83 printf("// size_dt_struct:\t0x%x\n",
84 fdt32_to_cpu(bph
->size_dt_struct
));
88 addr
= fdt64_to_cpu(p_rsvmap
[i
].address
);
89 size
= fdt64_to_cpu(p_rsvmap
[i
].size
);
90 if (addr
== 0 && size
== 0)
93 printf("/memreserve/ %llx %llx;\n",
94 (unsigned long long)addr
, (unsigned long long)size
);
98 while ((tag
= fdt32_to_cpu(GET_CELL(p
))) != FDT_END
) {
100 /* printf("tag: 0x%08x (%d)\n", tag, p - p_struct); */
102 if (tag
== FDT_BEGIN_NODE
) {
104 p
= PALIGN(p
+ strlen(s
) + 1, 4);
109 printf("%*s%s {\n", depth
* shift
, "", s
);
115 if (tag
== FDT_END_NODE
) {
118 printf("%*s};\n", depth
* shift
, "");
122 if (tag
== FDT_NOP
) {
123 printf("%*s// [NOP]\n", depth
* shift
, "");
127 if (tag
!= FDT_PROP
) {
128 fprintf(stderr
, "%*s ** Unknown tag 0x%08x\n", depth
* shift
, "", tag
);
131 sz
= fdt32_to_cpu(GET_CELL(p
));
132 s
= p_strings
+ fdt32_to_cpu(GET_CELL(p
));
133 if (version
< 16 && sz
>= 8)
137 p
= PALIGN(p
+ sz
, 4);
139 printf("%*s%s", depth
* shift
, "", s
);
146 int main(int argc
, char *argv
[])
151 fprintf(stderr
, "supply input filename\n");
155 buf
= utilfdt_read(argv
[1]);