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>
diff --git a/tools/imagetool.c b/tools/imagetool.c
index ba1f64a..5ad6d74 100644
--- a/tools/imagetool.c
+++ b/tools/imagetool.c
@@ -26,6 +26,12 @@
return NULL;
}
+static int imagetool_verify_print_header_by_type(
+ void *ptr,
+ struct stat *sbuf,
+ struct image_type_params *tparams,
+ struct image_tool_params *params);
+
int imagetool_verify_print_header(
void *ptr,
struct stat *sbuf,
@@ -39,6 +45,9 @@
struct image_type_params **start = __start_image_type;
struct image_type_params **end = __stop_image_type;
+ if (tparams)
+ return imagetool_verify_print_header_by_type(ptr, sbuf, tparams, params);
+
for (curr = start; curr != end; curr++) {
if ((*curr)->verify_header) {
retval = (*curr)->verify_header((unsigned char *)ptr,
@@ -65,7 +74,7 @@
return retval;
}
-int imagetool_verify_print_header_by_type(
+static int imagetool_verify_print_header_by_type(
void *ptr,
struct stat *sbuf,
struct image_type_params *tparams,