aboutsummaryrefslogtreecommitdiff
path: root/tools/mkimage.c
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2022-02-13 01:09:46 +0100
committerTom Rini <trini@konsulko.com>2022-02-28 10:33:11 -0500
commit11f29d443622070c9423ed5fda74b9564570aac7 (patch)
tree3f69b209af8f00ed44ee648aeeebe3d8114f221e /tools/mkimage.c
parenta900c7f8161b74fc66ec715e68e7244b53f04298 (diff)
downloadu-boot-11f29d443622070c9423ed5fda74b9564570aac7.zip
u-boot-11f29d443622070c9423ed5fda74b9564570aac7.tar.gz
u-boot-11f29d443622070c9423ed5fda74b9564570aac7.tar.bz2
tools: mkimage/dumpimage: Allow to use -l with -T
Currently -l option for mkimage and dumpimage ignores option -T and always tries to autodetect image type. With this change it is possible to tell mkimage and dumpimage to parse image file as specific type (and not random autodetected type). This allows to use mkimage -l or dumpimage -l as tool for validating image. params.type for -l option is now by default initialized to zero (IH_TYPE_INVALID) instead of IH_TYPE_KERNEL. imagetool_get_type() for IH_TYPE_INVALID returns NULL, which is assigned to tparams. mkimage and dumpimage code is extended to handle tparams with NULL for -l option. And imagetool_verify_print_header() is extended to do validation via tparams if is not NULL. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/mkimage.c')
-rw-r--r--tools/mkimage.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/tools/mkimage.c b/tools/mkimage.c
index c8f4ecd..7601451 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -82,8 +82,9 @@ static int show_valid_options(enum ih_category category)
static void usage(const char *msg)
{
fprintf(stderr, "Error: %s\n", msg);
- fprintf(stderr, "Usage: %s -l image\n"
- " -l ==> list image header information\n",
+ fprintf(stderr, "Usage: %s [-T type] -l image\n"
+ " -l ==> list image header information\n"
+ " -T ==> parse image file as 'type'\n",
params.cmdname);
fprintf(stderr,
" %s [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image\n"
@@ -329,7 +330,7 @@ static void process_args(int argc, char **argv)
params.datafile = datafile;
else if (!params.datafile)
usage("Missing data file for auto-FIT (use -d)");
- } else if (type != IH_TYPE_INVALID) {
+ } else if (params.lflag || type != IH_TYPE_INVALID) {
if (type == IH_TYPE_SCRIPT && !params.datafile)
usage("Missing data file for script (use -d)");
params.type = type;
@@ -358,7 +359,7 @@ int main(int argc, char **argv)
/* set tparams as per input type_id */
tparams = imagetool_get_type(params.type);
- if (tparams == NULL) {
+ if (tparams == NULL && !params.lflag) {
fprintf (stderr, "%s: unsupported type %s\n",
params.cmdname, genimg_get_type_name(params.type));
exit (EXIT_FAILURE);
@@ -368,14 +369,14 @@ int main(int argc, char **argv)
* check the passed arguments parameters meets the requirements
* as per image type to be generated/listed
*/
- if (tparams->check_params)
+ if (tparams && tparams->check_params)
if (tparams->check_params (&params))
usage("Bad parameters for image type");
if (!params.eflag) {
params.ep = params.addr;
/* If XIP, entry point must be after the U-Boot header */
- if (params.xflag)
+ if (params.xflag && tparams)
params.ep += tparams->header_size;
}
@@ -436,7 +437,7 @@ int main(int argc, char **argv)
params.cmdname, params.imagefile);
exit (EXIT_FAILURE);
#endif
- } else if (sbuf.st_size < (off_t)tparams->header_size) {
+ } else if (tparams && sbuf.st_size < (off_t)tparams->header_size) {
fprintf (stderr,
"%s: Bad size: \"%s\" is not valid image: size %llu < %u\n",
params.cmdname, params.imagefile,
@@ -455,21 +456,12 @@ int main(int argc, char **argv)
exit (EXIT_FAILURE);
}
- if (params.fflag) {
- /*
- * Verifies the header format based on the expected header for image
- * type in tparams
- */
- retval = imagetool_verify_print_header_by_type(ptr, &sbuf,
- tparams, &params);
- } else {
- /**
- * When listing the image, we are not given the image type. Simply check all
- * image types to find one that matches our header
- */
- retval = imagetool_verify_print_header(ptr, &sbuf,
- tparams, &params);
- }
+ /*
+ * Verifies the header format based on the expected header for image
+ * type in tparams. If tparams is NULL simply check all image types
+ * to find one that matches our header.
+ */
+ retval = imagetool_verify_print_header(ptr, &sbuf, tparams, &params);
(void) munmap((void *)ptr, sbuf.st_size);
(void) close (ifd);