]> Git Repo - J-u-boot.git/blobdiff - tools/dumpimage.c
tools: kwbimage: Set BOOT_FROM by default to SPI
[J-u-boot.git] / tools / dumpimage.c
index e17e979b04d3af0ce43b6a586d62b5213c17fa31..e5481435a7644add00810f7d6a7548762d2cb79a 100644 (file)
@@ -35,14 +35,23 @@ static int dumpimage_extract_subimage(struct image_type_params *tparams,
        if (tparams->verify_header) {
                retval = tparams->verify_header((unsigned char *)ptr,
                                sbuf->st_size, &params);
-               if (retval != 0)
+               if (retval != 0) {
+                       fprintf(stderr, "%s: failed to verify header of %s\n",
+                               params.cmdname, tparams->name);
                        return -1;
+               }
+
                /*
                 * Extract the file from the image
                 * if verify is successful
                 */
                if (tparams->extract_subimage) {
                        retval = tparams->extract_subimage(ptr, &params);
+                       if (retval != 0) {
+                               fprintf(stderr, "%s: extract_subimage failed for %s\n",
+                                       params.cmdname, tparams->name);
+                               return -3;
+                       }
                } else {
                        fprintf(stderr,
                                "%s: extract_subimage undefined for %s\n",
@@ -65,7 +74,7 @@ int main(int argc, char **argv)
 
        params.cmdname = *argv;
 
-       while ((opt = getopt(argc, argv, "lo:T:p:V")) != -1) {
+       while ((opt = getopt(argc, argv, "hlo:T:p:V")) != -1) {
                switch (opt) {
                case 'l':
                        params.lflag = 1;
@@ -79,7 +88,7 @@ int main(int argc, char **argv)
                        if (params.type < 0) {
                                fprintf(stderr, "%s: Invalid type\n",
                                        params.cmdname);
-                               usage();
+                               exit(EXIT_FAILURE);
                        }
                        break;
                case 'p':
@@ -94,15 +103,19 @@ int main(int argc, char **argv)
                case 'V':
                        printf("dumpimage version %s\n", PLAIN_VERSION);
                        exit(EXIT_SUCCESS);
+               case 'h':
                default:
                        usage();
                        break;
                }
        }
 
+       if (argc < 2)
+               usage();
+
        if (optind >= argc) {
                fprintf(stderr, "%s: image file missing\n", params.cmdname);
-               usage();
+               exit(EXIT_FAILURE);
        }
 
        params.imagefile = argv[optind];
@@ -123,7 +136,7 @@ int main(int argc, char **argv)
                if (tparams->check_params(&params)) {
                        fprintf(stderr, "%s: Parameter check failed\n",
                                params.cmdname);
-                       usage();
+                       exit(EXIT_FAILURE);
                }
        }
 
@@ -170,6 +183,9 @@ int main(int argc, char **argv)
                 * image type. Returns the error code if not matched
                 */
                retval = dumpimage_extract_subimage(tparams, ptr, &sbuf);
+               if (retval)
+                       fprintf(stderr, "%s: Can't extract subimage from %s\n",
+                               params.cmdname, params.imagefile);
        } else {
                /*
                 * Print the image information for matched image type
@@ -191,13 +207,17 @@ static void usage(void)
                "          -l ==> list image header information\n",
                params.cmdname);
        fprintf(stderr,
-               "       %s -T type [-p position] [-o outfile] image\n"
-               "          -T ==> set image type to 'type'\n"
-               "          -p ==> 'position' (starting at 0) of the component to extract from image\n",
+               "       %s [-T type] [-p position] [-o outfile] image\n"
+               "          -T ==> declare image type as 'type'\n"
+               "          -p ==> 'position' (starting at 0) of the component to extract from image\n"
+               "          -o ==> extract component to file 'outfile'\n",
+               params.cmdname);
+       fprintf(stderr,
+               "       %s -h ==> print usage information and exit\n",
                params.cmdname);
        fprintf(stderr,
                "       %s -V ==> print version information and exit\n",
                params.cmdname);
 
-       exit(EXIT_FAILURE);
+       exit(EXIT_SUCCESS);
 }
This page took 0.028784 seconds and 4 git commands to generate.