diff options
author | Tom Rini <trini@konsulko.com> | 2021-07-14 20:10:34 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-07-14 20:10:34 -0400 |
commit | c11f5abce84f630c92304683d5bde3204c5612c4 (patch) | |
tree | 29f4a7db27669fac1ea7b7eb8821b5440b09af0d /tools/mkimage.c | |
parent | eae8c7c33829c3bd25a792600c1fe6ed842a1ddc (diff) | |
parent | 963fde31559f50ceb4f5965f00d79f8747a9d217 (diff) |
Merge branch '2021-07-14-build-and-host-updates'
- Resync Kbuild with the v4.20 Linux Kernel release
- Update checkpatch.pl
- Assorted other tooling updates
Diffstat (limited to 'tools/mkimage.c')
-rw-r--r-- | tools/mkimage.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/tools/mkimage.c b/tools/mkimage.c index cc7b242faf..302bfcf971 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -12,6 +12,9 @@ #include "imximage.h" #include <image.h> #include <version.h> +#ifdef __linux__ +#include <sys/ioctl.h> +#endif static void copy_file(int, const char *, int); @@ -402,6 +405,7 @@ int main(int argc, char **argv) } if (params.lflag || params.fflag) { + uint64_t size; /* * list header information of existing image */ @@ -412,14 +416,34 @@ int main(int argc, char **argv) exit (EXIT_FAILURE); } - if ((unsigned)sbuf.st_size < tparams->header_size) { + if ((sbuf.st_mode & S_IFMT) == S_IFBLK) { +#ifdef __linux__ +#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64) +#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ +#endif + if (ioctl(ifd, BLKGETSIZE64, &size) < 0) { + fprintf (stderr, + "%s: failed to get size of block device \"%s\"\n", + params.cmdname, params.imagefile); + exit (EXIT_FAILURE); + } +#else fprintf (stderr, - "%s: Bad size: \"%s\" is not valid image\n", + "%s: \"%s\" is block device, don't know how to get its size\n", params.cmdname, params.imagefile); exit (EXIT_FAILURE); +#endif + } else if ((unsigned)sbuf.st_size < tparams->header_size) { + fprintf (stderr, + "%s: Bad size: \"%s\" is not valid image: size %ld < %u\n", + params.cmdname, params.imagefile, + sbuf.st_size, tparams->header_size); + exit (EXIT_FAILURE); + } else { + size = sbuf.st_size; } - 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", params.cmdname, params.imagefile, |