qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "john.liuli" <john.liuli@huawei.com>
To: peter.crosthwaite@xilinx.com, agraf@suse.de
Cc: Li Liu <john.liuli@huawei.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/6] device_tree.c: dump three kind data types of dts to a file desciptor
Date: Mon, 25 Aug 2014 12:00:33 +0800	[thread overview]
Message-ID: <1408939237-8444-3-git-send-email-john.liuli@huawei.com> (raw)
In-Reply-To: <1408939237-8444-1-git-send-email-john.liuli@huawei.com>

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

  parent reply	other threads:[~2014-08-25  4:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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 ` [Qemu-devel] [PATCH 4/6] device_tree.c: add the main function to analyse the parameter 'dumpdts' john.liuli
2014-08-25  4:00 ` [Qemu-devel] [PATCH 5/6] machine: add 'dumpdts' parameter to 'machine' optslist 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
2014-08-26  2:04   ` Li Liu
2014-08-26  2:41     ` Peter Crosthwaite

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1408939237-8444-3-git-send-email-john.liuli@huawei.com \
    --to=john.liuli@huawei.com \
    --cc=agraf@suse.de \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).