[U-Boot] [PATCH] tools: fit_common: allow opening of block devices

Radek Dostál radek.dostal at streamunlimited.com
Thu Jun 21 12:48:43 UTC 2018


During manufacturing it is useful to be able to verify integrity of
secondary fit image by just running
`./fit_check_sign -f /dev/mtdblock? -k ...`
This was unfortunately failing as fstat(fd, sbuf) was setting
sbuf->st_size to zero, which caused mmap to fail later on.

Signed-off-by: Radek Dostál <radek.dostal at streamunlimited.com>
Reviewed-by: Vladimir Koutny <vladimir.koutny at streamunlimited.com>
---
 tools/fit_common.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/fit_common.c b/tools/fit_common.c
index d96085e..2c917d3 100644
--- a/tools/fit_common.c
+++ b/tools/fit_common.c
@@ -22,6 +22,8 @@
 #include "fit_common.h"
 #include <image.h>
 #include <u-boot/crc.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
 
 int fit_verify_header(unsigned char *ptr, int image_size,
 			struct image_tool_params *params)
@@ -58,6 +60,14 @@ int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
 		goto err;
 	}
 
+	if (sbuf->st_size == 0 && S_ISBLK(sbuf->st_mode)) {
+		if (ioctl(fd, BLKGETSIZE64, &sbuf->st_size) < 0) {
+			fprintf(stderr, "%s: Can't determine size of %s: %s\n",
+				cmdname, fname, strerror(errno));
+			goto err;
+		}
+	}
+
 	if (size_inc) {
 		sbuf->st_size += size_inc;
 		if (ftruncate(fd, sbuf->st_size)) {
-- 
2.7.4



More information about the U-Boot mailing list