]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dumpimage: add 'T' option to explicitly set the image type
authorGuilherme Maciel Ferreira <guilherme.maciel@datacom.ind.br>
Thu, 15 Jan 2015 04:54:40 +0000 (02:54 -0200)
committerTom Rini <trini@ti.com>
Thu, 29 Jan 2015 18:38:41 +0000 (13:38 -0500)
Some image types, like "KeyStone GP", do not have magic numbers to
distinguish them from other image types. Thus, the automatic image
type discovery does not work correctly.

This patch also fix some integer type mismatches.

Signed-off-by: Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
README
test/image/test-imagetools.sh
tools/dumpimage.c
tools/gpimage-common.c
tools/mkimage.c

diff --git a/README b/README
index fefa71c0a6c5f3adf8ed437e6956227a0e502e8b..a11e74aff1b923f3c7cd8381305c32640a61a28e 100644 (file)
--- a/README
+++ b/README
@@ -5899,9 +5899,10 @@ option performs the converse operation of the mkimage's second form (the "-d"
 option). Given an image built by mkimage, the dumpimage extracts a "data file"
 from the image:
 
-       tools/dumpimage -i image -p position data_file
-         -i ==> extract from the 'image' a specific 'data_file', \
-          indexed by 'position'
+       tools/dumpimage -i image -T type -p position data_file
+         -i ==> extract from the 'image' a specific 'data_file'
+         -T ==> set image type to 'type'
+         -p ==> 'position' (starting at 0) of the 'data_file' inside the 'image'
 
 
 Installing a Linux Image:
index 9e299e1e57aa40f88f373008293900b7ca4281ef..8aaaade5a0fba7317f1e93c586be6dac34b0a1e6 100755 (executable)
@@ -13,9 +13,9 @@
 # ./test/image/test-imagetools.sh
 
 BASEDIR=sandbox
-SRCDIR=sandbox/boot
+SRCDIR=${BASEDIR}/boot
 IMAGE_NAME="v1.0-test"
-IMAGE=linux.img
+IMAGE_MULTI=linux.img
 DATAFILE0=vmlinuz
 DATAFILE1=initrd.img
 DATAFILE2=System.map
@@ -34,14 +34,14 @@ cleanup()
        for file in ${DATAFILES}; do
                rm -f ${file} ${SRCDIR}/${file}
        done
-       rm -f ${IMAGE} ${DUMPIMAGE_LIST} ${MKIMAGE_LIST} ${TEST_OUT}
+       rm -f ${IMAGE_MULTI} ${DUMPIMAGE_LIST} ${MKIMAGE_LIST} ${TEST_OUT}
        rmdir ${SRCDIR}
 }
 
 # Check that two files are the same
 assert_equal()
 {
-       if ! diff $1 $2; then
+       if ! diff -u $1 $2; then
                echo "Failed."
                cleanup
                exit 1
@@ -82,35 +82,39 @@ do_cmd_redir()
        ${cmd} >${redir}
 }
 
-# Write files into an image
-create_image()
+# Write files into an multi-file image
+create_multi_image()
 {
        local files="${SRCDIR}/${DATAFILE0}:${SRCDIR}/${DATAFILE1}"
        files+=":${SRCDIR}/${DATAFILE2}"
 
-       echo -e "\nBuilding image..."
+       echo -e "\nBuilding multi-file image..."
        do_cmd ${MKIMAGE} -A x86 -O linux -T multi -n \"${IMAGE_NAME}\" \
-               -d ${files} ${IMAGE}
+               -d ${files} ${IMAGE_MULTI}
        echo "done."
 }
 
-# Extract files from an image
-extract_image()
+# Extract files from an multi-file image
+extract_multi_image()
 {
-       echo -e "\nExtracting image contents..."
-       do_cmd ${DUMPIMAGE} -i ${IMAGE} -p 0 ${DATAFILE0}
-       do_cmd ${DUMPIMAGE} -i ${IMAGE} -p 1 ${DATAFILE1}
-       do_cmd ${DUMPIMAGE} -i ${IMAGE} -p 2 ${DATAFILE2}
-       do_cmd ${DUMPIMAGE} -i ${IMAGE} -p 2 ${DATAFILE2} -o ${TEST_OUT}
+       echo -e "\nExtracting multi-file image contents..."
+       do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 0 ${DATAFILE0}
+       do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 1 ${DATAFILE1}
+       do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 2 ${DATAFILE2}
+       do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 2 ${DATAFILE2} -o ${TEST_OUT}
        echo "done."
 }
 
 # List the contents of a file
+# Args:
+#    image filename
 list_image()
 {
+       local image="$1"
+
        echo -e "\nListing image contents..."
-       do_cmd_redir ${MKIMAGE_LIST} ${MKIMAGE} -l ${IMAGE}
-       do_cmd_redir ${DUMPIMAGE_LIST} ${DUMPIMAGE} -l ${IMAGE}
+       do_cmd_redir ${MKIMAGE_LIST} ${MKIMAGE} -l ${image}
+       do_cmd_redir ${DUMPIMAGE_LIST} ${DUMPIMAGE} -l ${image}
        echo "done."
 }
 
@@ -120,16 +124,16 @@ main()
 
        create_files
 
-       # Compress and extract multifile images, compare the result
-       create_image
-       extract_image
+       # Compress and extract multi-file images, compare the result
+       create_multi_image
+       extract_multi_image
        for file in ${DATAFILES}; do
                assert_equal ${file} ${SRCDIR}/${file}
        done
        assert_equal ${TEST_OUT} ${DATAFILE2}
 
-       # List contents and compares output fro tools
-       list_image
+       # List contents of multi-file image and compares output from tools
+       list_image ${IMAGE_MULTI}
        assert_equal ${DUMPIMAGE_LIST} ${MKIMAGE_LIST}
 
        # Remove files created
index 80bf583b396b85942b6b607678982847a4b42165..8f1527a9e77fe166d28cd8bbdb59a409cc50e579 100644 (file)
@@ -12,9 +12,6 @@
 
 static void usage(void);
 
-/* image_type_params linked list to maintain registered image types supports */
-static struct image_type_params *dumpimage_tparams;
-
 /* parameters initialized by core will be used by the image type code */
 static struct image_tool_params params = {
        .type = IH_TYPE_KERNEL,
@@ -31,33 +28,27 @@ static struct image_tool_params params = {
  * returns negative if input image format does not match with any of
  * supported image types
  */
-static int dumpimage_extract_datafile(void *ptr, struct stat *sbuf)
+static int dumpimage_extract_datafile(struct image_type_params *tparams,
+               void *ptr, struct stat *sbuf)
 {
        int retval = -1;
-       struct image_type_params *curr;
-       struct image_type_params *start = ll_entry_start(
-                       struct image_type_params, image_type);
-       struct image_type_params *end = ll_entry_end(
-                       struct image_type_params, image_type);
-
-       for (curr = start; curr != end; curr++) {
-               if (curr->verify_header) {
-                       retval = curr->verify_header((unsigned char *)ptr,
-                                                    sbuf->st_size, &params);
-                       if (retval != 0)
-                               continue;
-                       /*
-                        * Extract the file from the image
-                        * if verify is successful
-                        */
-                       if (curr->extract_datafile) {
-                               curr->extract_datafile(ptr, &params);
-                       } else {
-                               fprintf(stderr,
-                                       "%s: extract_datafile undefined for %s\n",
-                                       params.cmdname, curr->name);
-                       break;
-                       }
+
+       if (tparams->verify_header) {
+               retval = tparams->verify_header((unsigned char *)ptr,
+                               sbuf->st_size, &params);
+               if (retval != 0)
+                       return -1;
+               /*
+                * Extract the file from the image
+                * if verify is successful
+                */
+               if (tparams->extract_datafile) {
+                       retval = tparams->extract_datafile(ptr, &params);
+               } else {
+                       fprintf(stderr,
+                               "%s: extract_datafile undefined for %s\n",
+                               params.cmdname, tparams->name);
+                       return -2;
                }
        }
 
@@ -75,7 +66,7 @@ int main(int argc, char **argv)
 
        params.cmdname = *argv;
 
-       while ((opt = getopt(argc, argv, "li:o:p:V")) != -1) {
+       while ((opt = getopt(argc, argv, "li:o:T:p:V")) != -1) {
                switch (opt) {
                case 'l':
                        params.lflag = 1;
@@ -87,6 +78,12 @@ int main(int argc, char **argv)
                case 'o':
                        params.outfile = optarg;
                        break;
+               case 'T':
+                       params.type = genimg_get_type_id(optarg);
+                       if (params.type < 0) {
+                               usage();
+                       }
+                       break;
                case 'p':
                        params.pflag = strtoul(optarg, &ptr, 10);
                        if (*ptr) {
@@ -101,6 +98,7 @@ int main(int argc, char **argv)
                        exit(EXIT_SUCCESS);
                default:
                        usage();
+                       break;
                }
        }
 
@@ -110,7 +108,7 @@ int main(int argc, char **argv)
        /* set tparams as per input type_id */
        tparams = imagetool_get_type(params.type);
        if (tparams == NULL) {
-               fprintf(stderr, "%s: unsupported type %s\n",
+               fprintf(stderr, "%s: unsupported type: %s\n",
                        params.cmdname, genimg_get_type_name(params.type));
                exit(EXIT_FAILURE);
        }
@@ -147,7 +145,7 @@ int main(int argc, char **argv)
                        exit(EXIT_FAILURE);
                }
 
-               if ((unsigned)sbuf.st_size < tparams->header_size) {
+               if ((uint32_t)sbuf.st_size < tparams->header_size) {
                        fprintf(stderr,
                                "%s: Bad size: \"%s\" is not valid image\n",
                                params.cmdname, params.imagefile);
@@ -172,7 +170,8 @@ int main(int argc, char **argv)
                         * Extract the data files from within the matched
                         * image type. Returns the error code if not matched
                         */
-                       retval = dumpimage_extract_datafile(ptr, &sbuf);
+                       retval = dumpimage_extract_datafile(tparams, ptr,
+                                       &sbuf);
                } else {
                        /*
                         * Print the image information for matched image type
@@ -199,9 +198,10 @@ static void usage(void)
                "          -l ==> list image header information\n",
                params.cmdname);
        fprintf(stderr,
-               "       %s -i image [-p position] [-o outfile] data_file\n"
-               "          -i ==> extract from the 'image' a specific 'data_file'"
-               ", indexed by 'position' (starting at 0)\n",
+               "       %s -i image -T type [-p position] [-o outfile] data_file\n"
+               "          -i ==> extract from the 'image' a specific 'data_file'\n"
+               "          -T ==> set image type to 'type'\n"
+               "          -p ==> 'position' (starting at 0) of the 'data_file' inside the 'image'\n",
                params.cmdname);
        fprintf(stderr,
                "       %s -V ==> print version information and exit\n",
index b343a3aa8b7c2964eb58d5098149504f947344af..5ad52be4377467614c36a2de18d94c9c0c6f5351 100644 (file)
@@ -32,7 +32,8 @@ void to_be32(uint32_t *gph_size, uint32_t *gph_load_addr)
 
 int gph_verify_header(struct gp_header *gph, int be)
 {
-       uint32_t gph_size = gph->size, gph_load_addr = gph->load_addr;
+       uint32_t gph_size = gph->size;
+       uint32_t gph_load_addr = gph->load_addr;
 
        if (be)
                to_be32(&gph_size, &gph_load_addr);
index f668487c89be594e8d8523b43abb8488a7767376..5ccd951048cef587686d264575aae6ea7623e90f 100644 (file)
@@ -15,9 +15,6 @@
 static void copy_file(int, const char *, int);
 static void usage(void);
 
-/* image_type_params link list to maintain registered image type supports */
-struct image_type_params *mkimage_tparams = NULL;
-
 /* parameters initialized by core will be used by the image type code */
 struct image_tool_params params = {
        .os = IH_OS_LINUX,