[U-Boot] [PATCH] RFC: Adjustments to dumpimage for Guilherme

Simon Glass sjg at chromium.org
Tue Oct 1 22:35:25 CEST 2013


Here are some suggested changes after I tried using your tool. It's very
useful so I hope it can be merged.

1. Truncate the output file
2. Support uImage files that hold a single image
3. Allow specifying an output filename

Signed-off-by: Simon Glass <sjg at chromium.org>
---
 tools/default_image.c | 17 +++++++++--------
 tools/dumpimage.c     | 15 ++++++++++-----
 tools/imagetool.h     |  1 +
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/tools/default_image.c b/tools/default_image.c
index b0a0d40..9947aaf 100644
--- a/tools/default_image.c
+++ b/tools/default_image.c
@@ -121,9 +121,9 @@ static int image_save_datafile (struct image_tool_params *params,
 				ulong file_data, ulong file_len)
 {
 	int dfd;
-	const char *datafile = params->datafile;
+	const char *datafile = params->outfile;
 
-	dfd = open (datafile, O_RDWR|O_CREAT|O_BINARY, S_IRUSR|S_IWUSR);
+	dfd = open (datafile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRUSR|S_IWUSR);
 	if (dfd < 0) {
 		fprintf (stderr, "%s: Can't open \"%s\": %s\n",
 				params->cmdname, datafile, strerror(errno));
@@ -145,12 +145,12 @@ static int image_save_datafile (struct image_tool_params *params,
 static int image_extract_datafile (void *ptr, struct image_tool_params *params)
 {
 	const image_header_t *hdr = (const image_header_t *)ptr;
+	ulong file_data;
+	ulong file_len;
 
 	if (image_check_type (hdr, IH_TYPE_MULTI)) {
 		ulong idx = params->pflag;
 		ulong count;
-		ulong file_data = 0;
-		ulong file_len = 0;
 
 		/* get the number of data files present in the image */
 		count = image_multi_count (hdr);
@@ -163,12 +163,13 @@ static int image_extract_datafile (void *ptr, struct image_tool_params *params)
 					params->cmdname, idx, params->imagefile);
 			return -1;
 		}
-
-		/* save the "data file" into the file system */
-		return image_save_datafile (params, file_data, file_len);
+	} else {
+		file_data = image_get_data(hdr);
+		file_len = image_get_size(hdr);
 	}
 
-	return -1;
+	/* save the "data file" into the file system */
+	return image_save_datafile(params, file_data, file_len);
 }
 
 /*
diff --git a/tools/dumpimage.c b/tools/dumpimage.c
index cb5cb44..c08e398 100644
--- a/tools/dumpimage.c
+++ b/tools/dumpimage.c
@@ -192,6 +192,11 @@ main (int argc, char **argv)
 				params.imagefile = *(++argv);
 				params.iflag = 1;
 				goto NXTARG;
+			case 'o':
+				if (--argc <= 0)
+					usage ();
+				params.outfile = *++argv;
+				goto NXTARG;
 			case 'p':
 				if (--argc <= 0)
 					usage ();
@@ -232,12 +237,12 @@ NXTARG:		;
 		if (tparams->check_params (&params))
 			usage ();
 
-	if (params.iflag) {
+	if (params.iflag)
 		params.datafile = *argv;
-	}
-	else {
+	else
 		params.imagefile = *argv;
-	}
+	if (!params.outfile)
+		params.outfile = params.datafile;
 
 	ifd = open (params.imagefile, O_RDONLY|O_BINARY);
 	if (ifd < 0) {
@@ -307,7 +312,7 @@ usage (void)
 	fprintf (stderr, "Usage: %s -l image\n"
 			 "          -l ==> list image header information\n",
 		params.cmdname);
-	fprintf (stderr, "       %s -i image -p position data_file\n"
+	fprintf (stderr, "       %s -i image [-p position] [-o outfile] data_file\n"
 			 "          -i ==> extract from the 'image' a specific 'data_file'"
 			 ", indexed by 'position' (starting at 0)\n",
 		params.cmdname);
diff --git a/tools/imagetool.h b/tools/imagetool.h
index d0dd4ac..b88286d 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -52,6 +52,7 @@ struct image_tool_params {
 	char *datafile;
 	char *imagefile;
 	char *cmdname;
+	const char *outfile;	/* Output filename */
 	const char *keydir;	/* Directory holding private keys */
 	const char *keydest;	/* Destination .dtb for public key */
 	const char *comment;	/* Comment to add to signature node */
-- 
1.8.4



More information about the U-Boot mailing list