From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59019) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLlXk-00035O-86 for qemu-devel@nongnu.org; Mon, 25 Aug 2014 00:06:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XLlXe-0006v7-Er for qemu-devel@nongnu.org; Mon, 25 Aug 2014 00:06:07 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:43043) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLlXd-0006sh-Qc for qemu-devel@nongnu.org; Mon, 25 Aug 2014 00:06:02 -0400 From: "john.liuli" Date: Mon, 25 Aug 2014 12:00:33 +0800 Message-ID: <1408939237-8444-3-git-send-email-john.liuli@huawei.com> In-Reply-To: <1408939237-8444-1-git-send-email-john.liuli@huawei.com> References: <1408939237-8444-1-git-send-email-john.liuli@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH 2/6] device_tree.c: dump three kind data types of dts to a file desciptor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: peter.crosthwaite@xilinx.com, agraf@suse.de Cc: Li Liu , qemu-devel@nongnu.org From: Li Liu dump three kind data types 'strings', 'cell' and 'bytes' of dts to a file desciptor. Signed-off-by: Li Liu --- 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