]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
tools: Add a function to obtain the size of a file
authorSimon Glass <sjg@chromium.org>
Tue, 23 Feb 2016 05:55:49 +0000 (22:55 -0700)
committerTom Rini <trini@konsulko.com>
Mon, 14 Mar 2016 23:18:27 +0000 (19:18 -0400)
This will be used in mkimage when working out the required size of the FIT
based on the files to be placed into it.

Signed-off-by: Simon Glass <sjg@chromium.org>
doc/mkimage.1
tools/imagetool.c
tools/imagetool.h

index b48f70bb3cc7a0222d8a21d9d1122e69af2ddf4f..1b9d18cbc9f4ab8951ac6409769b18938eb8401a 100644 (file)
@@ -164,7 +164,7 @@ skipping those for which keys cannot be found. Also add a comment.
 .nf
 .B mkimage -f kernel.its -k /public/signing-keys -K u-boot.dtb \\\\
 .br
-.B -c "Kernel 3.8 image for production devices" kernel.itb
+.B -c """Kernel 3.8 image for production devices""" kernel.itb
 .fi
 
 .P
@@ -175,7 +175,7 @@ with unavailable keys are skipped.
 .nf
 .B mkimage -F -k /secret/signing-keys -K u-boot.dtb \\\\
 .br
-.B -c "Kernel 3.8 image for production devices" kernel.itb
+.B -c """Kernel 3.8 image for production devices""" kernel.itb
 .fi
 
 .SH HOMEPAGE
index 4b0b73db5277a07629bc306156b37f12ae440d82..351211cd5387b9e727ce22501428d2a6af19cc7b 100644 (file)
@@ -91,3 +91,25 @@ int imagetool_save_subimage(
 
        return 0;
 }
+
+int imagetool_get_filesize(struct image_tool_params *params, const char *fname)
+{
+       struct stat sbuf;
+       int fd;
+
+       fd = open(fname, O_RDONLY | O_BINARY);
+       if (fd < 0) {
+               fprintf(stderr, "%s: Can't open %s: %s\n",
+                       params->cmdname, fname, strerror(errno));
+               return -1;
+       }
+
+       if (fstat(fd, &sbuf) < 0) {
+               fprintf(stderr, "%s: Can't stat %s: %s\n",
+                       params->cmdname, fname, strerror(errno));
+               return -1;
+       }
+       close(fd);
+
+       return sbuf.st_size;
+}
index e0397f771618236b67fc4e2ed6505595492d3f38..3cf42ac96ab1d84c89385d461b8ef1b464cf69f6 100644 (file)
@@ -181,6 +181,18 @@ int imagetool_save_subimage(
        ulong file_data,
        ulong file_len);
 
+/**
+ * imagetool_get_filesize() - Utility function to obtain the size of a file
+ *
+ * This function prints a message if an error occurs, showing the error that
+ * was obtained.
+ *
+ * @params:    mkimage parameters
+ * @fname:     filename to check
+ * @return size of file, or -ve value on error
+ */
+int imagetool_get_filesize(struct image_tool_params *params, const char *fname);
+
 /*
  * There is a c file associated with supported image type low level code
  * for ex. default_image.c, fit_image.c