]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mkimage: Set up a file size parameter and keep it updated
authorSimon Glass <sjg@chromium.org>
Tue, 23 Jun 2015 21:39:12 +0000 (15:39 -0600)
committerSimon Glass <sjg@chromium.org>
Tue, 21 Jul 2015 23:39:29 +0000 (17:39 -0600)
Some functions called by mkimage would like to know the output file size.
Initially this is the same as the input file size, but it may be affected by
adding headers, etc.

Add this information to the image parameters.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
tools/imagetool.h
tools/mkimage.c

index b7874f47cd228f0a6aaf93f9098979f36a7ca5ca..99bbf2f459e5ae2d66bb69a25b55011a990b84c3 100644 (file)
@@ -59,6 +59,7 @@ struct image_tool_params {
        const char *keydest;    /* Destination .dtb for public key */
        const char *comment;    /* Comment to add to signature node */
        int require_keys;       /* 1 to mark signing keys as 'required' */
+       int file_size;          /* Total size of output file */
 };
 
 /*
index 8808d70444c20b6f219755596215095cce38df62..e81d4550835c6763bcab21e0b2b8ab2bf46baba3 100644 (file)
@@ -75,6 +75,7 @@ int main(int argc, char **argv)
        int retval = 0;
        struct image_type_params *tparams = NULL;
        int pad_len = 0;
+       int dfd;
 
        params.cmdname = *argv;
        params.addr = params.ep = 0;
@@ -310,6 +311,22 @@ NXTARG:            ;
                exit (retval);
        }
 
+       dfd = open(params.datafile, O_RDONLY | O_BINARY);
+       if (dfd < 0) {
+               fprintf(stderr, "%s: Can't open %s: %s\n",
+                       params.cmdname, params.datafile, strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+
+       if (fstat(dfd, &sbuf) < 0) {
+               fprintf(stderr, "%s: Can't stat %s: %s\n",
+                       params.cmdname, params.datafile, strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+
+       params.file_size = sbuf.st_size + tparams->header_size;
+       close(dfd);
+
        /*
         * In case there an header with a variable
         * length will be added, the corresponding
@@ -409,6 +426,7 @@ NXTARG:             ;
                        params.cmdname, params.imagefile, strerror(errno));
                exit (EXIT_FAILURE);
        }
+       params.file_size = sbuf.st_size;
 
        ptr = mmap(0, sbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, ifd, 0);
        if (ptr == MAP_FAILED) {