[U-Boot] [PATCH] tools/mkimage: ignore trailing garbage

Peter Korsgaard jacmet at sunsite.dk
Mon Dec 1 17:23:16 CET 2008


Ignore trailing data after the uimage data and only complain if the
file is too small.

(E.G. if the uImage was stored in flash and hence padded to the flash
sector size).

Signed-off-by: Peter Korsgaard <jacmet at sunsite.dk>
---
 tools/mkimage.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/tools/mkimage.c b/tools/mkimage.c
index 967fe9a..58fd20f 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -523,7 +523,14 @@ image_verify_header (char *ptr, int image_size)
 	}
 
 	data = ptr + sizeof(image_header_t);
-	len  = image_size - sizeof(image_header_t) ;
+	len  = ntohl(hdr->ih_size);
+	if (len > (image_size - sizeof(image_header_t))) {
+		fprintf (stderr,
+			"%s: ERROR: \"%s\" is too short (%d vs %d bytes)!\n",
+			 cmdname, imagefile,
+			 image_size - sizeof(image_header_t), len);
+		exit (EXIT_FAILURE);
+	}
 
 	if (crc32 (0, data, len) != ntohl(hdr->ih_dcrc)) {
 		fprintf (stderr,
-- 
1.5.6.5



More information about the U-Boot mailing list