[PATCH v2 2/6] ftdump: use util_read_fdt

Simon Glass sjg at chromium.org
Thu Sep 8 05:54:16 EST 2011


Now that we have this function, ftdump should use it too.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
 Makefile        |    2 +-
 Makefile.ftdump |    3 ++-
 ftdump.c        |   33 +++++----------------------------
 3 files changed, 8 insertions(+), 30 deletions(-)

diff --git a/Makefile b/Makefile
index 2172d9a..0baada5 100644
--- a/Makefile
+++ b/Makefile
@@ -178,7 +178,7 @@ convert-dtsv0: $(CONVERT_OBJS)
 	@$(VECHO) LD $@
 	$(LINK.c) -o $@ $^
 
-ftdump:	$(FTDUMP_OBJS)
+ftdump:	$(FTDUMP_OBJS) $(LIBFDT_archive)
 
 
 #
diff --git a/Makefile.ftdump b/Makefile.ftdump
index 2744a18..dc3a2c1 100644
--- a/Makefile.ftdump
+++ b/Makefile.ftdump
@@ -6,7 +6,8 @@
 
 FTDUMP_SRCS = \
 	ftdump.c \
-	util.c
+	util.c \
+	utilfdt.c
 
 FTDUMP_GEN_SRCS =
 
diff --git a/ftdump.c b/ftdump.c
index db932e3..43c09c0 100644
--- a/ftdump.c
+++ b/ftdump.c
@@ -12,8 +12,7 @@
 #include <libfdt_env.h>
 
 #include "util.h"
-
-#define FTDUMP_BUF_SIZE	65536
+#include "utilfdt.h"
 
 #define ALIGN(x, a)	(((x) + ((a) - 1)) & ~((a) - 1))
 #define PALIGN(p, a)	((void *)(ALIGN((unsigned long)(p), (a))))
@@ -147,40 +146,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 = util_read_fdt(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



More information about the devicetree-discuss mailing list