mirror of
https://github.com/u-boot/u-boot.git
synced 2024-11-28 07:03:31 +08:00
tools: dumpimage: Simplify internal logic
There are 3 supported modes of operation: 1) Show version 2) List image contents 3) Extract image component Option (1) terminates early, so only options (2) and (3) remain. Remove redundant check for these modes. Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
This commit is contained in:
parent
12b831879a
commit
11e3c1fd3b
@ -60,7 +60,7 @@ int main(int argc, char **argv)
|
||||
int ifd = -1;
|
||||
struct stat sbuf;
|
||||
char *ptr;
|
||||
int retval = 0;
|
||||
int retval = EXIT_SUCCESS;
|
||||
struct image_type_params *tparams = NULL;
|
||||
|
||||
params.cmdname = *argv;
|
||||
@ -135,65 +135,54 @@ int main(int argc, char **argv)
|
||||
|
||||
ifd = open(params.imagefile, O_RDONLY|O_BINARY);
|
||||
if (ifd < 0) {
|
||||
fprintf(stderr, "%s: Can't open \"%s\": %s\n",
|
||||
params.cmdname, params.imagefile,
|
||||
strerror(errno));
|
||||
fprintf(stderr, "%s: Can't open \"%s\": %s\n", params.cmdname,
|
||||
params.imagefile, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (params.lflag || params.iflag) {
|
||||
if (fstat(ifd, &sbuf) < 0) {
|
||||
fprintf(stderr, "%s: Can't stat \"%s\": %s\n",
|
||||
params.cmdname, params.imagefile,
|
||||
strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((uint32_t)sbuf.st_size < tparams->header_size) {
|
||||
fprintf(stderr,
|
||||
"%s: Bad size: \"%s\" is not valid image\n",
|
||||
params.cmdname, params.imagefile);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, ifd, 0);
|
||||
if (ptr == MAP_FAILED) {
|
||||
fprintf(stderr, "%s: Can't read \"%s\": %s\n",
|
||||
params.cmdname, params.imagefile,
|
||||
strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Both calls bellow scan through dumpimage registry for all
|
||||
* supported image types and verify the input image file
|
||||
* header for match
|
||||
*/
|
||||
if (params.iflag) {
|
||||
/*
|
||||
* Extract the data files from within the matched
|
||||
* image type. Returns the error code if not matched
|
||||
*/
|
||||
retval = dumpimage_extract_subimage(tparams, ptr,
|
||||
&sbuf);
|
||||
} else {
|
||||
/*
|
||||
* Print the image information for matched image type
|
||||
* Returns the error code if not matched
|
||||
*/
|
||||
retval = imagetool_verify_print_header(ptr, &sbuf,
|
||||
tparams, ¶ms);
|
||||
}
|
||||
|
||||
(void)munmap((void *)ptr, sbuf.st_size);
|
||||
(void)close(ifd);
|
||||
|
||||
return retval;
|
||||
if (fstat(ifd, &sbuf) < 0) {
|
||||
fprintf(stderr, "%s: Can't stat \"%s\": %s\n", params.cmdname,
|
||||
params.imagefile, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((uint32_t)sbuf.st_size < tparams->header_size) {
|
||||
fprintf(stderr, "%s: Bad size: \"%s\" is not valid image\n",
|
||||
params.cmdname, params.imagefile);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, ifd, 0);
|
||||
if (ptr == MAP_FAILED) {
|
||||
fprintf(stderr, "%s: Can't read \"%s\": %s\n", params.cmdname,
|
||||
params.imagefile, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Both calls bellow scan through dumpimage registry for all
|
||||
* supported image types and verify the input image file
|
||||
* header for match
|
||||
*/
|
||||
if (params.iflag) {
|
||||
/*
|
||||
* Extract the data files from within the matched
|
||||
* image type. Returns the error code if not matched
|
||||
*/
|
||||
retval = dumpimage_extract_subimage(tparams, ptr, &sbuf);
|
||||
} else {
|
||||
/*
|
||||
* Print the image information for matched image type
|
||||
* Returns the error code if not matched
|
||||
*/
|
||||
retval = imagetool_verify_print_header(ptr, &sbuf, tparams,
|
||||
¶ms);
|
||||
}
|
||||
|
||||
(void)munmap((void *)ptr, sbuf.st_size);
|
||||
(void)close(ifd);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
|
Loading…
Reference in New Issue
Block a user