]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
tools: add variable padding of data image in mkimage
authorStefano Babic <sbabic@denx.de>
Mon, 19 Aug 2013 17:03:19 +0000 (19:03 +0200)
committerStefano Babic <sbabic@denx.de>
Sat, 31 Aug 2013 13:06:29 +0000 (15:06 +0200)
Use previously unused return value of function vrec_header
to return a padding size to generic mkimage. This padding
size is used in copy_files to pad with zeros after copying
the data image.

Signed-off-by: Stefano Babic <sbabic@denx.de>
tools/mkimage.c
tools/mkimage.h

index b700b9e8c0eb424b9022a2f21f54201d0cef3dee..58d25faed4b4b663f1f07ca94a7d27ad440d168a 100644 (file)
@@ -137,6 +137,7 @@ main (int argc, char **argv)
        char *ptr;
        int retval = 0;
        struct image_type_params *tparams = NULL;
+       int pad_len = 0;
 
        /* Init Freescale PBL Boot image generation/list support */
        init_pbl_image_type();
@@ -391,7 +392,7 @@ NXTARG:             ;
         * allocate memory for the header itself.
         */
        if (tparams->vrec_header)
-               tparams->vrec_header(&params, tparams);
+               pad_len = tparams->vrec_header(&params, tparams);
        else
                memset(tparams->hdr, 0, tparams->header_size);
 
@@ -463,7 +464,7 @@ NXTARG:             ;
                        /* PBL has special Image format, implements its' own */
                        pbl_load_uboot(ifd, &params);
                } else {
-                       copy_file (ifd, params.datafile, 0);
+                       copy_file(ifd, params.datafile, pad_len);
                }
        }
 
@@ -537,10 +538,19 @@ copy_file (int ifd, const char *datafile, int pad)
        unsigned char *ptr;
        int tail;
        int zero = 0;
+       uint8_t zeros[4096];
        int offset = 0;
        int size;
        struct image_type_params *tparams = mkimage_get_type (params.type);
 
+       if (pad >= sizeof(zeros)) {
+               fprintf(stderr, "%s: Can't pad to %d\n",
+                       params.cmdname, pad);
+               exit(EXIT_FAILURE);
+       }
+
+       memset(zeros, 0, sizeof(zeros));
+
        if (params.vflag) {
                fprintf (stderr, "Adding Image %s\n", datafile);
        }
@@ -598,7 +608,8 @@ copy_file (int ifd, const char *datafile, int pad)
                exit (EXIT_FAILURE);
        }
 
-       if (pad && ((tail = size % 4) != 0)) {
+       tail = size % 4;
+       if ((pad == 1) && (tail != 0)) {
 
                if (write(ifd, (char *)&zero, 4-tail) != 4-tail) {
                        fprintf (stderr, "%s: Write error on %s: %s\n",
@@ -606,6 +617,13 @@ copy_file (int ifd, const char *datafile, int pad)
                                strerror(errno));
                        exit (EXIT_FAILURE);
                }
+       } else if (pad > 1) {
+               if (write(ifd, (char *)&zeros, pad) != pad) {
+                       fprintf(stderr, "%s: Write error on %s: %s\n",
+                               params.cmdname, params.imagefile,
+                               strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
        }
 
        (void) munmap((void *)ptr, sbuf.st_size);
index 950e19067f0a34b25328b5d691bd51d0b56a63fd..ecb30322824870ef06391ab506c7c219a879a49f 100644 (file)
@@ -132,7 +132,10 @@ struct image_type_params {
        /*
         * This callback function will be executed for variable size record
         * It is expected to build this header in memory and return its length
-        * and a pointer to it
+        * and a pointer to it by using image_type_params.header_size and
+        * image_type_params.hdr. The return value shall indicate if an
+        * additional padding should be used when copying the data image
+        * by returning the padding length.
         */
        int (*vrec_header) (struct mkimage_params *,
                struct image_type_params *);