diff mbox series

[U-Boot,2/5] tools: dumpimage: Simplify arguments

Message ID 20190126023154.19749-2-martyn.welch@collabora.com
State Accepted
Commit 12b831879a765722c1a94ca75c6adb6f80759cd9
Delegated to: Tom Rini
Headers show
Series [U-Boot,1/5] tools: dumpimage: Provide more feedback on error | expand

Commit Message

Martyn Welch Jan. 26, 2019, 2:31 a.m. UTC
The dump image utility has very confusing syntax. If called to list image
contents ("-l") it takes the image name as a positional argument. If the
utility is called to extract something from the image, the image must be
provided via the optional argument "-i" as well as the positional argument
but the value passed in the positional argument will be completely
ignored.

Simplify dumpimage by always providing the image as the first positional
argument. Assume we want to dump something from the image if we do not
provide the "-l" option for now.

Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
---

 tools/dumpimage.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

Comments

Tom Rini Feb. 3, 2019, 1:09 a.m. UTC | #1
On Sat, Jan 26, 2019 at 02:31:51AM +0000, Martyn Welch wrote:

> The dump image utility has very confusing syntax. If called to list image
> contents ("-l") it takes the image name as a positional argument. If the
> utility is called to extract something from the image, the image must be
> provided via the optional argument "-i" as well as the positional argument
> but the value passed in the positional argument will be completely
> ignored.
> 
> Simplify dumpimage by always providing the image as the first positional
> argument. Assume we want to dump something from the image if we do not
> provide the "-l" option for now.
> 
> Signed-off-by: Martyn Welch <martyn.welch@collabora.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/tools/dumpimage.c b/tools/dumpimage.c
index 2847e6c0b4..1b92dec364 100644
--- a/tools/dumpimage.c
+++ b/tools/dumpimage.c
@@ -65,17 +65,14 @@  int main(int argc, char **argv)
 
 	params.cmdname = *argv;
 
-	while ((opt = getopt(argc, argv, "li:o:T:p:V")) != -1) {
+	while ((opt = getopt(argc, argv, "lo:T:p:V")) != -1) {
 		switch (opt) {
 		case 'l':
 			params.lflag = 1;
 			break;
-		case 'i':
-			params.imagefile = optarg;
-			params.iflag = 1;
-			break;
 		case 'o':
 			params.outfile = optarg;
+			params.iflag = 1;
 			break;
 		case 'T':
 			params.type = genimg_get_type_id(optarg);
@@ -108,6 +105,8 @@  int main(int argc, char **argv)
 		usage();
 	}
 
+	params.imagefile = argv[optind];
+
 	/* set tparams as per input type_id */
 	tparams = imagetool_get_type(params.type);
 	if (tparams == NULL) {
@@ -128,12 +127,11 @@  int main(int argc, char **argv)
 		}
 	}
 
-	if (params.iflag)
-		params.datafile = argv[optind];
-	else
-		params.imagefile = argv[optind];
-	if (!params.outfile)
-		params.outfile = params.datafile;
+	if (!params.lflag && !params.outfile) {
+		fprintf(stderr, "%s: No output file provided\n",
+			params.cmdname);
+		exit(EXIT_FAILURE);
+	}
 
 	ifd = open(params.imagefile, O_RDONLY|O_BINARY);
 	if (ifd < 0) {
@@ -204,10 +202,9 @@  static void usage(void)
 		"          -l ==> list image header information\n",
 		params.cmdname);
 	fprintf(stderr,
-		"       %s -i image -T type [-p position] [-o outfile] data_file\n"
-		"          -i ==> extract from the 'image' a specific 'data_file'\n"
+		"       %s -T type [-p position] [-o outfile] image\n"
 		"          -T ==> set image type to 'type'\n"
-		"          -p ==> 'position' (starting at 0) of the 'data_file' inside the 'image'\n",
+		"          -p ==> 'position' (starting at 0) of the component to extract from image\n",
 		params.cmdname);
 	fprintf(stderr,
 		"       %s -V ==> print version information and exit\n",