]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
imagetool: move common code to imagetool module
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Thu, 15 Jan 2015 04:48:05 +0000 (02:48 -0200)
committerTom Rini <trini@ti.com>
Thu, 29 Jan 2015 18:38:41 +0000 (13:38 -0500)
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>
tools/dumpimage.c
tools/imagetool.c
tools/imagetool.h
tools/mkimage.c

index 542ee2821096fd41614dc05de3f5ab789840e374..0228e183abd30f0c70161f7cbc48af00f21c3a23 100644 (file)
@@ -55,67 +55,6 @@ static void dumpimage_register(struct image_type_params *tparams)
        debug("Registered %s\n", tparams->name);
 }
 
-/**
- * dumpimage_get_type() - find the image type params for a given image type
- *
- * Scan all registered image types and check the input type_id for each
- * supported image type
- *
- * @return respective image_type_params pointer. If the input type is not
- * supported by any of registered image types, returns NULL
- */
-static struct image_type_params *dumpimage_get_type(int type)
-{
-       struct image_type_params *curr;
-
-       for (curr = dumpimage_tparams; curr != NULL; curr = curr->next) {
-               if (curr->check_image_type) {
-                       if (!curr->check_image_type(type))
-                               return curr;
-               }
-       }
-       return NULL;
-}
-
-/*
- * dumpimage_verify_print_header() - verifies the image header
- *
- * Scan registered image types and verify the image_header for each
- * supported image type. If verification is successful, this prints
- * the respective header.
- *
- * @return 0 on success, negative if input image format does not match with
- * any of supported image types
- */
-static int dumpimage_verify_print_header(void *ptr, struct stat *sbuf)
-{
-       int retval = -1;
-       struct image_type_params *curr;
-
-       for (curr = dumpimage_tparams; curr != NULL; curr = curr->next) {
-               if (curr->verify_header) {
-                       retval = curr->verify_header((unsigned char *)ptr,
-                                                    sbuf->st_size, &params);
-                       if (retval != 0)
-                               continue;
-                       /*
-                        * 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;
-}
-
 /*
  * dumpimage_extract_datafile -
  *
@@ -203,7 +142,7 @@ int main(int argc, char **argv)
                usage();
 
        /* set tparams as per input type_id */
-       tparams = dumpimage_get_type(params.type);
+       tparams = imagetool_get_type(params.type, dumpimage_tparams);
        if (tparams == NULL) {
                fprintf(stderr, "%s: unsupported type %s\n",
                        params.cmdname, genimg_get_type_name(params.type));
@@ -273,7 +212,8 @@ int main(int argc, char **argv)
                         * Print the image information for matched image type
                         * Returns the error code if not matched
                         */
-                       retval = dumpimage_verify_print_header(ptr, &sbuf);
+                       retval = imagetool_verify_print_header(ptr, &sbuf,
+                                       tparams, &params);
                }
 
                (void)munmap((void *)ptr, sbuf.st_size);
index 98717bdeddcf39fe9988e6f14ab6b35d8ed6f2b0..e4de7af9845753eda63045d2da1ea5a30111f3af 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "imagetool.h"
 
+#include <image.h>
+
 /*
  * Callback function to register a image type within a tool
  */
@@ -62,3 +64,52 @@ void register_image_type(struct image_type_params *tparams)
 {
        register_func(tparams);
 }
+
+struct image_type_params *imagetool_get_type(
+       int type,
+       struct image_type_params *tparams)
+{
+       struct image_type_params *curr;
+
+       for (curr = tparams; curr != NULL; curr = curr->next) {
+               if (curr->check_image_type) {
+                       if (!curr->check_image_type(type))
+                               return curr;
+               }
+       }
+       return NULL;
+}
+
+int imagetool_verify_print_header(
+       void *ptr,
+       struct stat *sbuf,
+       struct image_type_params *tparams,
+       struct image_tool_params *params)
+{
+       int retval = -1;
+       struct image_type_params *curr;
+
+       for (curr = 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;
+}
index 8bce059482737bb5030ed36d68cafc28838a4084..eb2750cf69eca6c0b079f63cf30e304c3e009ed8 100644 (file)
@@ -150,6 +150,37 @@ void register_image_tool(imagetool_register_t image_register);
  */
 void register_image_type(struct image_type_params *tparams);
 
+/**
+ * imagetool_get_type() - find the image type params for a given image type
+ *
+ * It scans all registers image type supports
+ * checks the input type 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 *imagetool_get_type(
+       int type,
+       struct image_type_params *tparams);
+
+/*
+ * imagetool_verify_print_header() - verifies the image header
+ *
+ * Scan registered image types and verify the image_header for each
+ * supported image type. If verification is successful, this prints
+ * the respective header.
+ *
+ * @return 0 on success, negative if input image format does not match with
+ * any of supported image types
+ */
+int imagetool_verify_print_header(
+       void *ptr,
+       struct stat *sbuf,
+       struct image_type_params *tparams,
+       struct image_tool_params *params);
+
 /*
  * There is a c file associated with supported image type low level code
  * for ex. default_image.c, fit_image.c
index c70408c9ba02375ae959e20d438e4e65acfd75b0..c04a2abee5dfe5c4a5a7805dfc30dc488c3ee5bd 100644 (file)
@@ -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",