summaryrefslogtreecommitdiff
path: root/tools/mkimage.c
diff options
context:
space:
mode:
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>2015-01-15 02:48:05 -0200
committerTom Rini <trini@ti.com>2015-01-29 13:38:41 -0500
commit0ca6691c2ec20ff264d882854c339795579991f5 (patch)
tree87dfba3b64f749fc0a0e3215b4ee7513ed3e42a2 /tools/mkimage.c
parent44f145fd81f73a5c5adc490b0da91b80a4c7790a (diff)
imagetool: move common code to imagetool module
The get_type() and verify_print_header() functions have the same code on both dumpimage.c and mkimage.c modules. Signed-off-by: Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Diffstat (limited to 'tools/mkimage.c')
-rw-r--r--tools/mkimage.c72
1 files changed, 5 insertions, 67 deletions
diff --git a/tools/mkimage.c b/tools/mkimage.c
index c70408c9ba..c04a2abee5 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -65,70 +65,6 @@ void mkimage_register (struct image_type_params *tparams)
debug ("Registered %s\n", tparams->name);
}
-/*
- * mkimage_get_type -
- *
- * It scans all registers image type supports
- * checks the input type_id for each supported image type
- *
- * if successful,
- * returns respective image_type_params pointer if success
- * if input type_id is not supported by any of image_type_support
- * returns NULL
- */
-struct image_type_params *mkimage_get_type(int type)
-{
- struct image_type_params *curr;
-
- for (curr = mkimage_tparams; curr != NULL; curr = curr->next) {
- if (curr->check_image_type) {
- if (!curr->check_image_type (type))
- return curr;
- }
- }
- return NULL;
-}
-
-/*
- * mkimage_verify_print_header -
- *
- * It scans mkimage_tparams link list,
- * verifies image_header for each supported image type
- * if verification is successful, prints respective header
- *
- * returns negative if input image format does not match with any of
- * supported image types
- */
-int mkimage_verify_print_header (void *ptr, struct stat *sbuf)
-{
- int retval = -1;
- struct image_type_params *curr;
-
- for (curr = mkimage_tparams; curr != NULL; curr = curr->next ) {
- if (curr->verify_header) {
- retval = curr->verify_header (
- (unsigned char *)ptr, sbuf->st_size,
- &params);
-
- if (retval == 0) {
- /*
- * Print the image information
- * if verify is successful
- */
- if (curr->print_header)
- curr->print_header (ptr);
- else {
- fprintf (stderr,
- "%s: print_header undefined for %s\n",
- params.cmdname, curr->name);
- }
- break;
- }
- }
- }
- return retval;
-}
-
int
main (int argc, char **argv)
{
@@ -279,7 +215,7 @@ NXTARG: ;
usage ();
/* set tparams as per input type_id */
- tparams = mkimage_get_type(params.type);
+ tparams = imagetool_get_type(params.type, mkimage_tparams);
if (tparams == NULL) {
fprintf (stderr, "%s: unsupported type %s\n",
params.cmdname, genimg_get_type_name(params.type));
@@ -363,7 +299,8 @@ NXTARG: ;
* Print the image information for matched image type
* Returns the error code if not matched
*/
- retval = mkimage_verify_print_header (ptr, &sbuf);
+ retval = imagetool_verify_print_header(ptr, &sbuf,
+ tparams, &params);
(void) munmap((void *)ptr, sbuf.st_size);
(void) close (ifd);
@@ -529,7 +466,8 @@ copy_file (int ifd, const char *datafile, int pad)
uint8_t zeros[4096];
int offset = 0;
int size;
- struct image_type_params *tparams = mkimage_get_type (params.type);
+ struct image_type_params *tparams = imagetool_get_type(params.type,
+ mkimage_tparams);
if (pad >= sizeof(zeros)) {
fprintf(stderr, "%s: Can't pad to %d\n",