devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
To: Devicetree Discuss
	<devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org>
Subject: [PATCH v5 3/5] ftdump: use utilfdt to read blob
Date: Thu, 22 Sep 2011 10:11:04 -0700	[thread overview]
Message-ID: <1316711466-14199-4-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1316711466-14199-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>

Now that we have utilfdt_read(), ftdump should use it too.

Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Acked-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
---
 ftdump.c |   32 ++++----------------------------
 1 files changed, 4 insertions(+), 28 deletions(-)

diff --git a/ftdump.c b/ftdump.c
index db932e3..cc55fe2 100644
--- a/ftdump.c
+++ b/ftdump.c
@@ -13,8 +13,6 @@
 
 #include "util.h"
 
-#define FTDUMP_BUF_SIZE	65536
-
 #define ALIGN(x, a)	(((x) + ((a) - 1)) & ~((a) - 1))
 #define PALIGN(p, a)	((void *)(ALIGN((unsigned long)(p), (a))))
 #define GET_CELL(p)	(p += 4, *((const uint32_t *)(p-4)))
@@ -147,40 +145,18 @@ static void dump_blob(void *blob)
 
 int main(int argc, char *argv[])
 {
-	FILE *fp;
 	char *buf;
-	int size;
 
 	if (argc < 2) {
 		fprintf(stderr, "supply input filename\n");
 		return 5;
 	}
 
-	if (strcmp(argv[1], "-") == 0) {
-		fp = stdin;
-	} else {
-		fp = fopen(argv[1], "rb");
-		if (fp == NULL) {
-			fprintf(stderr, "unable to open %s\n", argv[1]);
-			return 10;
-		}
-	}
-
-	buf = malloc(FTDUMP_BUF_SIZE);
-	if (!buf) {
-		fprintf(stderr, "Couldn't allocate %d byte buffer\n", FTDUMP_BUF_SIZE);
+	buf = utilfdt_read(argv[1]);
+	if (buf)
+		dump_blob(buf);
+	else
 		return 10;
-	}
-
-	size = fread(buf, 1, FTDUMP_BUF_SIZE, fp);
-	if (size == FTDUMP_BUF_SIZE) {
-		fprintf(stderr, "file too large (maximum is %d bytes)\n", FTDUMP_BUF_SIZE);
-		return 10;
-	}
-
-	dump_blob(buf);
-
-	fclose(fp);
 
 	return 0;
 }
-- 
1.7.3.1

  parent reply	other threads:[~2011-09-22 17:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-22 17:11 [PATCH v5 0/5] Add fdtget and fdtput for access to fdt from build system Simon Glass
     [not found] ` <1316711466-14199-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-22 17:11   ` [PATCH v5 1/5] Add fdt read/write utility functions Simon Glass
     [not found]     ` <1316711466-14199-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-22 18:54       ` Jon Loeliger
     [not found]         ` <E1R6oQ2-00016C-DY-CYoMK+44s/E@public.gmane.org>
2011-09-22 19:07           ` Simon Glass
2011-09-22 17:11   ` [PATCH v5 2/5] Make testutils use utilfdt Simon Glass
     [not found]     ` <1316711466-14199-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-22 18:55       ` Jon Loeliger
2011-09-22 17:11   ` Simon Glass [this message]
     [not found]     ` <1316711466-14199-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-22 18:55       ` [PATCH v5 3/5] ftdump: use utilfdt to read blob Jon Loeliger
2011-09-22 17:11   ` [PATCH v5 4/5] Add fdtget utility to read property values from a device tree Simon Glass
     [not found]     ` <1316711466-14199-5-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-23  1:20       ` David Gibson
     [not found]         ` <20110923012007.GG12286-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-12-16  1:37           ` Simon Glass
     [not found]             ` <CAPnjgZ0Na+zAX2cj=b1HbyGW5iNLGLn2rAeQEfZ9LwBLDW6a1w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-20 12:01               ` David Gibson
     [not found]                 ` <20111220120148.GB5133-MK4v0fQdeXQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-12-22  6:47                   ` Simon Glass
     [not found]                     ` <CAPnjgZ3Y897hEQ2+qLO711Cuv9BvkQvcxusG1XQAyiG3UZ-M0g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-22 14:17                       ` Jon Loeliger
     [not found]                         ` <E1RdjSE-0007a8-86-CYoMK+44s/E@public.gmane.org>
2012-01-04  0:44                           ` Simon Glass
2011-09-22 17:11   ` [PATCH v5 5/5] Add fdtput utility to write property values to " Simon Glass
     [not found]     ` <1316711466-14199-6-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-23  1:20       ` David Gibson

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=1316711466-14199-4-git-send-email-sjg@chromium.org \
    --to=sjg-f7+t8e8rja9g9huczpvpmw@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.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).