mkimage: Allow padding to any length
authorSimon Glass <sjg@chromium.org>
Sun, 30 Aug 2015 22:55:22 +0000 (16:55 -0600)
committerSimon Glass <sjg@chromium.org>
Thu, 3 Sep 2015 03:28:23 +0000 (21:28 -0600)
At present there is an arbitrary limit of 4KB for padding. Rockchip needs
more than that, so remove this restriction.

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

index e81d4550835c6763bcab21e0b2b8ab2bf46baba3..c50af0510dc0b997ec5a63d20bca917fe621bed8 100644 (file)
@@ -488,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) {
@@ -563,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;
                }
        }