[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/6] device_tree.c: Format a blob in memory as dts s
From: |
john.liuli |
Subject: |
[Qemu-devel] [PATCH 3/6] device_tree.c: Format a blob in memory as dts stream and dump to a file. |
Date: |
Mon, 25 Aug 2014 12:00:34 +0800 |
From: Li Liu <address@hidden>
The outputed stream format is compatile with
'dtc -I dtb -O dts xxx.dtb'.
Signed-off-by: Li Liu <address@hidden>
---
device_tree.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/device_tree.c b/device_tree.c
index 14d4015..1e407d2 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -416,3 +416,83 @@ static void dts_write_data(FILE *fp, const char *data, int
len)
fprintf(fp, "]");
}
}
+
+static void dts_write_prefix(FILE *fp, int depth)
+{
+ int i;
+
+ for (i = 0; i < depth; i++) {
+ fprintf(fp, "%c", '\t');
+ }
+}
+
+#define PALIGN(p, a) ((void *)(QEMU_ALIGN_UP((unsigned long)(p), (a))))
+#define GET_CELL(p) (p += 4, *((const uint32_t *)(p - 4)))
+
+static void qemu_write_dts(FILE *fp, void *fdt)
+{
+ const char *p, *name, *data;
+ uint32_t tag;
+ int len, num, depth = 0;
+ int i;
+
+ const char *fdt_struct = (const char *)fdt + fdt_off_dt_struct(fdt);
+ const char *fdt_strings = (const char *)fdt + fdt_off_dt_strings(fdt);
+
+ fprintf(fp, "/dts-v1/;\n");
+
+ num = fdt_num_mem_rsv(fdt);
+ fprintf(fp, "%s", num ? "\n" : "");
+ for (i = 0; i < num; i++) {
+ uint64_t addr, size;
+
+ fdt_get_mem_rsv(fdt, i, &addr, &size);
+ fprintf(fp, "/memreserve/\t0x%016llx 0x%016llx;\n",
+ (unsigned long long)addr, (unsigned long long)size);
+ }
+
+ p = fdt_struct;
+ while ((tag = fdt32_to_cpu(GET_CELL(p))) != FDT_END) {
+ if (tag == FDT_BEGIN_NODE) {
+ name = p;
+ p = PALIGN(p + strlen(name) + 1, 4);
+ if (*name == '\0') {
+ name = "/";
+ }
+
+ fprintf(fp, "\n");
+ dts_write_prefix(fp, depth);
+ fprintf(fp, "%s {\n", name);
+
+ depth++;
+ continue;
+ }
+
+ if (tag == FDT_END_NODE) {
+ depth--;
+
+ dts_write_prefix(fp, depth);
+ fprintf(fp, "};\n");
+ continue;
+ }
+
+ if (tag == FDT_NOP) {
+ continue;
+ }
+
+ if (tag != FDT_PROP) {
+ fprintf(stderr, "FDT: Unknown tag 0x%08x\n", tag);
+ break;
+ }
+
+ len = fdt32_to_cpu(GET_CELL(p));
+ name = fdt_strings + fdt32_to_cpu(GET_CELL(p));
+ data = p;
+ p = PALIGN(p + len, 4);
+
+ dts_write_prefix(fp, depth);
+ fprintf(fp, "%s", name);
+ dts_write_data(fp, data, len);
+ fprintf(fp, ";\n");
+ }
+}
--
1.7.9.5
- [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts, john.liuli, 2014/08/25
- [Qemu-devel] [PATCH 3/6] device_tree.c: Format a blob in memory as dts stream and dump to a file.,
john.liuli <=
- [Qemu-devel] [PATCH 1/6] device_tree.c: Introduce a function to check multiple strings for dts, john.liuli, 2014/08/25
- [Qemu-devel] [PATCH 2/6] device_tree.c: dump three kind data types of dts to a file desciptor, john.liuli, 2014/08/25
- [Qemu-devel] [PATCH 4/6] device_tree.c: add the main function to analyse the parameter 'dumpdts', john.liuli, 2014/08/25
- [Qemu-devel] [PATCH 6/6] arm: Allow dumping generated dtb to dts file, john.liuli, 2014/08/25
- [Qemu-devel] [PATCH 5/6] machine: add 'dumpdts' parameter to 'machine' optslist., john.liuli, 2014/08/25
- Re: [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts, Peter Maydell, 2014/08/25