]> git.sur5r.net Git - u-boot/blobdiff - tools/mkimage.c
input: Add a few more keyboard keycodes
[u-boot] / tools / mkimage.c
index 8808d70444c20b6f219755596215095cce38df62..8af9d50e2cd9916109e5807510755fb131c54f4b 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) {
@@ -470,12 +488,6 @@ copy_file (int ifd, const char *datafile, int pad)
        int size;
        struct image_type_params *tparams = imagetool_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) {
@@ -545,11 +557,18 @@ copy_file (int ifd, const char *datafile, int pad)
                        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);
+               while (pad > 0) {
+                       int todo = sizeof(zeros);
+
+                       if (todo > pad)
+                               todo = pad;
+                       if (write(ifd, (char *)&zeros, todo) != todo) {
+                               fprintf(stderr, "%s: Write error on %s: %s\n",
+                                       params.cmdname, params.imagefile,
+                                       strerror(errno));
+                               exit(EXIT_FAILURE);
+                       }
+                       pad -= todo;
                }
        }
 
@@ -576,7 +595,7 @@ static void usage(void)
                params.cmdname);
        fprintf(stderr, "       %s [-D dtc_options] [-f fit-image.its|-F] fit-image\n",
                params.cmdname);
-       fprintf(stderr, "          -D => set options for device tree compiler\n"
+       fprintf(stderr, "          -D => set all options for device tree compiler\n"
                        "          -f => input filename for FIT source\n");
 #ifdef CONFIG_FIT_SIGNATURE
        fprintf(stderr, "Signing / verified boot options: [-k keydir] [-K dtb] [ -c <comment>] [-r]\n"