diff mbox

[U-Boot,v2,17/27] tools: Add a function to obtain the size of a file

Message ID 1456206959-29115-18-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Simon Glass Feb. 23, 2016, 5:55 a.m. UTC
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>
---

Changes in v2: None

 doc/mkimage.1     |  4 ++--
 tools/imagetool.c | 22 ++++++++++++++++++++++
 tools/imagetool.h | 12 ++++++++++++
 3 files changed, 36 insertions(+), 2 deletions(-)

Comments

Tom Rini March 15, 2016, 11:54 a.m. UTC | #1
On Mon, Feb 22, 2016 at 10:55:49PM -0700, Simon Glass wrote:

> 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>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/doc/mkimage.1 b/doc/mkimage.1
index b48f70b..1b9d18c 100644
--- a/doc/mkimage.1
+++ b/doc/mkimage.1
@@ -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
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;
+}
diff --git a/tools/imagetool.h b/tools/imagetool.h
index e0397f7..3cf42ac 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -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