[U-Boot] [PATCH v2] tools/mkimage: use lseek rather than fstat for file size for -l option
Peter Korsgaard
jacmet at sunsite.dk
Wed Dec 3 12:35:25 CET 2008
Use lseek rather than fstat for file size for list mode, so
mkimage -l /dev/mtdblockN works (stat returns st_size == 0 for devices).
Notice that you have to use /dev/mtdblockN and not /dev/mtdN, as the
latter doesn't support mmap.
Signed-off-by: Peter Korsgaard <jacmet at sunsite.dk>
---
tools/mkimage.c | 14 ++++++++------
1 files changed, 8 insertions(+), 6 deletions(-)
Changes since v1:
- Incorporate remarks from Thomas/Wolfgang
(update error message, don't use struct stat)
diff --git a/tools/mkimage.c b/tools/mkimage.c
index b19cd6f..1d4619d 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -202,23 +202,25 @@ NXTARG: ;
}
if (lflag) {
+ off_t size;
/*
* list header information of existing image
*/
- if (fstat(ifd, &sbuf) < 0) {
- fprintf (stderr, "%s: Can't stat %s: %s\n",
+ size = lseek(ifd, 0, SEEK_END);
+ if (size == (off_t)-1) {
+ fprintf (stderr, "%s: Can't get size of %s: %s\n",
cmdname, imagefile, strerror(errno));
exit (EXIT_FAILURE);
}
- if ((unsigned)sbuf.st_size < image_get_header_size ()) {
+ if ((unsigned)size < image_get_header_size ()) {
fprintf (stderr,
"%s: Bad size: \"%s\" is no valid image\n",
cmdname, imagefile);
exit (EXIT_FAILURE);
}
- ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, ifd, 0);
+ ptr = mmap(0, size, PROT_READ, MAP_SHARED, ifd, 0);
if (ptr == MAP_FAILED) {
fprintf (stderr, "%s: Can't read %s: %s\n",
cmdname, imagefile, strerror(errno));
@@ -227,14 +229,14 @@ NXTARG: ;
if (fdt_check_header (ptr)) {
/* old-style image */
- image_verify_header ((char *)ptr, sbuf.st_size);
+ image_verify_header ((char *)ptr, size);
image_print_contents ((image_header_t *)ptr);
} else {
/* FIT image */
fit_print_contents (ptr);
}
- (void) munmap((void *)ptr, sbuf.st_size);
+ (void) munmap((void *)ptr, size);
(void) close (ifd);
exit (EXIT_SUCCESS);
--
1.5.6.5
More information about the U-Boot
mailing list