summaryrefslogtreecommitdiff
path: root/tools/imagetool.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2016-02-22 22:55:49 -0700
committerTom Rini <trini@konsulko.com>2016-03-14 19:18:27 -0400
commit3837ce65bd57991ebd7f8235db4040596d3125a4 (patch)
treeede2998fd140a6df42046f407add22c86ff14a18 /tools/imagetool.c
parentd505a09c1e8fa512aeb3c077048d521f1be302ff (diff)
downloadu-boot-imx-3837ce65bd57991ebd7f8235db4040596d3125a4.zip
u-boot-imx-3837ce65bd57991ebd7f8235db4040596d3125a4.tar.gz
u-boot-imx-3837ce65bd57991ebd7f8235db4040596d3125a4.tar.bz2
tools: Add a function to obtain the size of a file
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>
Diffstat (limited to 'tools/imagetool.c')
-rw-r--r--tools/imagetool.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/imagetool.c b/tools/imagetool.c
index 4b0b73d..351211c 100644
--- a/tools/imagetool.c
+++ b/tools/imagetool.c
@@ -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;
+}