summaryrefslogtreecommitdiff
path: root/tools/dumpimage.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/dumpimage.c
parenta900c7f8161b74fc66ec715e68e7244b53f04298 (diff)
downloadu-boot-11f29d443622070c9423ed5fda74b9564570aac7.tar.gz
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/dumpimage.c')
-rw-r--r--tools/dumpimage.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/tools/dumpimage.c b/tools/dumpimage.c
index e5481435a7..4791dd0dfe 100644
--- a/tools/dumpimage.c
+++ b/tools/dumpimage.c
@@ -12,9 +12,7 @@
static void usage(void);
/* parameters initialized by core will be used by the image type code */
-static struct image_tool_params params = {
- .type = IH_TYPE_KERNEL,
-};
+static struct image_tool_params params;
/*
* dumpimage_extract_subimage -
@@ -110,7 +108,7 @@ int main(int argc, char **argv)
}
}
- if (argc < 2)
+ if (argc < 2 || (params.iflag && params.lflag))
usage();
if (optind >= argc) {
@@ -122,7 +120,7 @@ int main(int argc, char **argv)
/* set tparams as per input type_id */
tparams = imagetool_get_type(params.type);
- if (tparams == NULL) {
+ if (!params.lflag && tparams == NULL) {
fprintf(stderr, "%s: unsupported type: %s\n",
params.cmdname, genimg_get_type_name(params.type));
exit(EXIT_FAILURE);
@@ -132,7 +130,7 @@ 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)) {
fprintf(stderr, "%s: Parameter check failed\n",
params.cmdname);
@@ -159,7 +157,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
- if ((uint32_t)sbuf.st_size < tparams->header_size) {
+ if (tparams && (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);
@@ -203,8 +201,9 @@ int main(int argc, char **argv)
static void usage(void)
{
- 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 [-T type] [-p position] [-o outfile] image\n"