* [Qemu-devel] [PATCH 1/6] device_tree.c: Introduce a function to check multiple strings for dts
2014-08-25 4:00 [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts john.liuli
@ 2014-08-25 4:00 ` john.liuli
2014-08-25 4:00 ` [Qemu-devel] [PATCH 2/6] device_tree.c: dump three kind data types of dts to a file desciptor john.liuli
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: john.liuli @ 2014-08-25 4:00 UTC (permalink / raw)
To: peter.crosthwaite, agraf; +Cc: Li Liu, qemu-devel
From: Li Liu <john.liuli@huawei.com>
dts property's value can be multiple strings. So introduce a function
to check a data with a given length to see if it is all printable and
has a valid terminator. It can contain either a single string, or
multiple strings each of non-zero length.
Signed-off-by: Li Liu <john.liuli@huawei.com>
---
device_tree.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/device_tree.c b/device_tree.c
index ca83504..29d9acc 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -345,3 +345,35 @@ int qemu_fdt_setprop_sized_cells_from_array(void *fdt,
return qemu_fdt_setprop(fdt, node_path, property, propcells,
cellnum * sizeof(uint32_t));
}
+
+/*
+ * Check a data of a given length to see if it is all printable and
+ * has a valid terminator. The data can contain either a single string,
+ * or multiple strings each of non-zero length.
+ */
+static int dts_is_printable_strings(const void *data, int len)
+{
+ const char *str = (char *)data;
+ int substrs = 0;
+ int substr_len = 0;
+ int i;
+
+ for (i = 0; i < len; i++) {
+ if (str[i] == '\0') {
+ if (substr_len) {
+ substr_len = 0;
+ substrs++;
+ continue;
+ } else {
+ /* substr is empty */
+ return 0;
+ }
+ } else if (isprint(str[i])) {
+ substr_len++;
+ } else {
+ return 0;
+ }
+ }
+
+ return substrs && !substr_len;
+}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH 2/6] device_tree.c: dump three kind data types of dts to a file desciptor
2014-08-25 4:00 [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts john.liuli
2014-08-25 4:00 ` [Qemu-devel] [PATCH 1/6] device_tree.c: Introduce a function to check multiple strings for dts john.liuli
@ 2014-08-25 4:00 ` john.liuli
2014-08-25 4:00 ` [Qemu-devel] [PATCH 3/6] device_tree.c: Format a blob in memory as dts stream and dump to a file john.liuli
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: john.liuli @ 2014-08-25 4:00 UTC (permalink / raw)
To: peter.crosthwaite, agraf; +Cc: Li Liu, qemu-devel
From: Li Liu <john.liuli@huawei.com>
dump three kind data types 'strings', 'cell' and 'bytes' of dts
to a file desciptor.
Signed-off-by: Li Liu <john.liuli@huawei.com>
---
device_tree.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/device_tree.c b/device_tree.c
index 29d9acc..14d4015 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -377,3 +377,42 @@ static int dts_is_printable_strings(const void *data, int len)
return substrs && !substr_len;
}
+
+static void dts_write_data(FILE *fp, const char *data, int len)
+{
+ int i;
+ const char *p = data;
+ const char *s;
+
+ if (len == 0) {
+ return;
+ }
+
+ if (dts_is_printable_strings(data, len)) {
+ fprintf(fp, " = ");
+
+ s = data;
+ do {
+ fprintf(fp, "\"%s\"", s);
+ s += strlen(s) + 1;
+ if (s < data + len) {
+ fprintf(fp, ", ");
+ }
+ } while (s < data + len);
+ } else if ((len % 4) == 0) {
+ const uint32_t *cell = (const uint32_t *)data;
+
+ fprintf(fp, " = <");
+ for (i = 0; i < len; i += 4) {
+ fprintf(fp, "0x%x%s", fdt32_to_cpu(cell[i / 4]),
+ i < (len - 4) ? " " : "");
+ }
+ fprintf(fp, ">");
+ } else {
+ fprintf(fp, " = [");
+ for (i = 0; i < len; i++) {
+ fprintf(fp, "%02hhx%s", *p++, i < len - 1 ? " " : "");
+ }
+ fprintf(fp, "]");
+ }
+}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH 3/6] device_tree.c: Format a blob in memory as dts stream and dump to a file.
2014-08-25 4:00 [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts john.liuli
2014-08-25 4:00 ` [Qemu-devel] [PATCH 1/6] device_tree.c: Introduce a function to check multiple strings for dts john.liuli
2014-08-25 4:00 ` [Qemu-devel] [PATCH 2/6] device_tree.c: dump three kind data types of dts to a file desciptor john.liuli
@ 2014-08-25 4:00 ` john.liuli
2014-08-25 4:00 ` [Qemu-devel] [PATCH 4/6] device_tree.c: add the main function to analyse the parameter 'dumpdts' john.liuli
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: john.liuli @ 2014-08-25 4:00 UTC (permalink / raw)
To: peter.crosthwaite, agraf; +Cc: Li Liu, qemu-devel
From: Li Liu <john.liuli@huawei.com>
The outputed stream format is compatile with
'dtc -I dtb -O dts xxx.dtb'.
Signed-off-by: Li Liu <john.liuli@huawei.com>
---
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH 4/6] device_tree.c: add the main function to analyse the parameter 'dumpdts'
2014-08-25 4:00 [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts john.liuli
` (2 preceding siblings ...)
2014-08-25 4:00 ` [Qemu-devel] [PATCH 3/6] device_tree.c: Format a blob in memory as dts stream and dump to a file john.liuli
@ 2014-08-25 4:00 ` john.liuli
2014-08-25 4:00 ` [Qemu-devel] [PATCH 5/6] machine: add 'dumpdts' parameter to 'machine' optslist john.liuli
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: john.liuli @ 2014-08-25 4:00 UTC (permalink / raw)
To: peter.crosthwaite, agraf; +Cc: Li Liu, qemu-devel
From: Li Liu <john.liuli@huawei.com>
add the main function to analyse the parameter 'dumpdts' as a
filename the dts will be dumped to.
Signed-off-by: Li Liu <john.liuli@huawei.com>
---
device_tree.c | 21 +++++++++++++++++++++
include/sysemu/device_tree.h | 1 +
2 files changed, 22 insertions(+)
diff --git a/device_tree.c b/device_tree.c
index 1e407d2..b9a924f 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -496,3 +496,24 @@ static void qemu_write_dts(FILE *fp, void *fdt)
fprintf(fp, ";\n");
}
}
+
+void qemu_fdt_dumpdts(void *fdt)
+{
+ FILE *fp;
+ const char *filename = qemu_opt_get(qemu_get_machine_opts(), "dumpdts");
+
+ if (!filename || !fdt) {
+ return;
+ }
+
+ fp = fopen(filename, "w");
+ if (!fp) {
+ fprintf(stderr, "Failed to open file '%s'\n", filename);
+ goto ret;
+ }
+
+ qemu_write_dts(fp, fdt);
+
+ret:
+ fclose(fp);
+}
diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
index 899f05c..27145fb 100644
--- a/include/sysemu/device_tree.h
+++ b/include/sysemu/device_tree.h
@@ -50,6 +50,7 @@ int qemu_fdt_add_subnode(void *fdt, const char *name);
} while (0)
void qemu_fdt_dumpdtb(void *fdt, int size);
+void qemu_fdt_dumpdts(void *fdt);
/**
* qemu_fdt_setprop_sized_cells_from_array:
--
1.7.9.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH 5/6] machine: add 'dumpdts' parameter to 'machine' optslist.
2014-08-25 4:00 [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts john.liuli
` (3 preceding siblings ...)
2014-08-25 4:00 ` [Qemu-devel] [PATCH 4/6] device_tree.c: add the main function to analyse the parameter 'dumpdts' john.liuli
@ 2014-08-25 4:00 ` john.liuli
2014-08-25 4:00 ` [Qemu-devel] [PATCH 6/6] arm: Allow dumping generated dtb to dts file john.liuli
2014-08-25 12:22 ` [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts Peter Maydell
6 siblings, 0 replies; 10+ messages in thread
From: john.liuli @ 2014-08-25 4:00 UTC (permalink / raw)
To: peter.crosthwaite, agraf; +Cc: Li Liu, qemu-devel
From: Li Liu <john.liuli@huawei.com>
Signed-off-by: Li Liu <john.liuli@huawei.com>
---
vl.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/vl.c b/vl.c
index b796c67..853f748 100644
--- a/vl.c
+++ b/vl.c
@@ -357,6 +357,10 @@ static QemuOptsList qemu_machine_opts = {
.type = QEMU_OPT_STRING,
.help = "Dump current dtb to a file and quit",
}, {
+ .name = "dumpdts",
+ .type = QEMU_OPT_STRING,
+ .help = "Convert current dtb to dts and dump to a file",
+ },{
.name = "phandle_start",
.type = QEMU_OPT_NUMBER,
.help = "The first phandle ID we may generate dynamically",
--
1.7.9.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH 6/6] arm: Allow dumping generated dtb to dts file
2014-08-25 4:00 [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts john.liuli
` (4 preceding siblings ...)
2014-08-25 4:00 ` [Qemu-devel] [PATCH 5/6] machine: add 'dumpdts' parameter to 'machine' optslist john.liuli
@ 2014-08-25 4:00 ` john.liuli
2014-08-25 12:22 ` [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts Peter Maydell
6 siblings, 0 replies; 10+ messages in thread
From: john.liuli @ 2014-08-25 4:00 UTC (permalink / raw)
To: peter.crosthwaite, agraf; +Cc: Li Liu, qemu-devel
From: Li Liu <john.liuli@huawei.com>
By calling qemu_fdt_dumdts before qemu_fdt_dumpdtb.
Signed-off-by: Li Liu <john.liuli@huawei.com>
---
hw/arm/boot.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index e32f2f4..18cc8ac 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -394,6 +394,7 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo)
binfo->modify_dtb(binfo, fdt);
}
+ qemu_fdt_dumpdts(fdt);
qemu_fdt_dumpdtb(fdt, size);
cpu_physical_memory_write(addr, fdt, size);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts
2014-08-25 4:00 [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts john.liuli
` (5 preceding siblings ...)
2014-08-25 4:00 ` [Qemu-devel] [PATCH 6/6] arm: Allow dumping generated dtb to dts file john.liuli
@ 2014-08-25 12:22 ` Peter Maydell
2014-08-26 2:04 ` Li Liu
6 siblings, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2014-08-25 12:22 UTC (permalink / raw)
To: john.liuli; +Cc: Peter Crosthwaite, Alexander Graf, QEMU Developers
On 25 August 2014 05:00, john.liuli <john.liuli@huawei.com> wrote:
> From: Li Liu <john.liuli@huawei.com>
>
> This patchset let qemu can convert dtb file to dts for two demands:
>
> Some archtectures may generate the dtb file dynamically through
> qemu device tree functions. So this let it's possiable to dump final
> dtb to dts and save it as a reference.
>
> For novices to debugging the issues caused by wrong dtb parameters.
> It will be easy to check the dts directly without copying the
> dtb which may be generated by 'dumpdtb' to the PC and dtc or fdtdump
> it.
>
> The outputed dts format is compatile with 'dtc -I dtb -O dts xxx.dtb'.
> There's a new parameter 'dumpdts' which is similar to 'dumpdtb'. so try
> it like '-machine dumpdts=/tmp/xxx.dts'.
Hi. Thanks for this patchset, but I'm afraid this doesn't
seem to me like something that should be in QEMU.
As you say, you can easily turn the dtb blob into a source file
with dtc. That gets you a definitely-correct disassembly of the
blob, and we don't need to maintain a possibly-buggy
reimplementation of the dtb disassembler in QEMU.
thanks
-- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts
2014-08-25 12:22 ` [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts Peter Maydell
@ 2014-08-26 2:04 ` Li Liu
2014-08-26 2:41 ` Peter Crosthwaite
0 siblings, 1 reply; 10+ messages in thread
From: Li Liu @ 2014-08-26 2:04 UTC (permalink / raw)
To: Peter Maydell; +Cc: Peter Crosthwaite, Alexander Graf, QEMU Developers
On 2014/8/25 20:22, Peter Maydell wrote:
> On 25 August 2014 05:00, john.liuli <john.liuli@huawei.com> wrote:
>> From: Li Liu <john.liuli@huawei.com>
>>
>> This patchset let qemu can convert dtb file to dts for two demands:
>>
>> Some archtectures may generate the dtb file dynamically through
>> qemu device tree functions. So this let it's possiable to dump final
>> dtb to dts and save it as a reference.
>>
>> For novices to debugging the issues caused by wrong dtb parameters.
>> It will be easy to check the dts directly without copying the
>> dtb which may be generated by 'dumpdtb' to the PC and dtc or fdtdump
>> it.
>>
>> The outputed dts format is compatile with 'dtc -I dtb -O dts xxx.dtb'.
>> There's a new parameter 'dumpdts' which is similar to 'dumpdtb'. so try
>> it like '-machine dumpdts=/tmp/xxx.dts'.
>
> Hi. Thanks for this patchset, but I'm afraid this doesn't
> seem to me like something that should be in QEMU.
> As you say, you can easily turn the dtb blob into a source file
> with dtc. That gets you a definitely-correct disassembly of the
> blob, and we don't need to maintain a possibly-buggy
> reimplementation of the dtb disassembler in QEMU.
>
> thanks
> -- PMM
>
That makes sense. It's mostly used for debugging.
Best regards
Li.
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH 0/6] add dumpdts ability to convert dtb to dts
2014-08-26 2:04 ` Li Liu
@ 2014-08-26 2:41 ` Peter Crosthwaite
0 siblings, 0 replies; 10+ messages in thread
From: Peter Crosthwaite @ 2014-08-26 2:41 UTC (permalink / raw)
To: Li Liu; +Cc: Peter Maydell, Alexander Graf, QEMU Developers
On Tue, Aug 26, 2014 at 12:04 PM, Li Liu <john.liuli@huawei.com> wrote:
>
>
> On 2014/8/25 20:22, Peter Maydell wrote:
>> On 25 August 2014 05:00, john.liuli <john.liuli@huawei.com> wrote:
>>> From: Li Liu <john.liuli@huawei.com>
>>>
>>> This patchset let qemu can convert dtb file to dts for two demands:
>>>
>>> Some archtectures may generate the dtb file dynamically through
>>> qemu device tree functions. So this let it's possiable to dump final
>>> dtb to dts and save it as a reference.
>>>
>>> For novices to debugging the issues caused by wrong dtb parameters.
>>> It will be easy to check the dts directly without copying the
>>> dtb which may be generated by 'dumpdtb' to the PC and dtc or fdtdump
>>> it.
>>>
>>> The outputed dts format is compatile with 'dtc -I dtb -O dts xxx.dtb'.
>>> There's a new parameter 'dumpdts' which is similar to 'dumpdtb'. so try
>>> it like '-machine dumpdts=/tmp/xxx.dts'.
>>
>> Hi. Thanks for this patchset, but I'm afraid this doesn't
>> seem to me like something that should be in QEMU.
>> As you say, you can easily turn the dtb blob into a source file
>> with dtc. That gets you a definitely-correct disassembly of the
>> blob, and we don't need to maintain a possibly-buggy
>> reimplementation of the dtb disassembler in QEMU.
>>
+1. With DTC source on-hand (in the submodule) it might be possible to
link the actual dtc dissassembler into QEMU, but I think external
scripting of the dtc tool is easiest.
Regards,
Peter
>> thanks
>> -- PMM
>>
>
> That makes sense. It's mostly used for debugging.
>
> Best regards
> Li.
>
>>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread