diff --git a/common/image.c b/common/image.c index 985127f8ea..3d159945d3 100644 --- a/common/image.c +++ b/common/image.c @@ -239,7 +239,7 @@ ulong image_multi_count(const image_header_t *hdr) size = (uint32_t *)image_get_data(hdr); /* count non empty slots */ - for (i = 0; size[i]; ++i) + for (i = 0; size[i] != IMAGE_PARAM_INVAL; ++i) count++; return count; diff --git a/include/image.h b/include/image.h index c0e6b1a727..56bd0dade0 100644 --- a/include/image.h +++ b/include/image.h @@ -709,6 +709,8 @@ int boot_get_kbd(struct lmb *lmb, bd_t **kbd); /*******************************************************************/ /* Legacy format specific code (prefixed with image_) */ /*******************************************************************/ +#define IMAGE_PARAM_INVAL 0xffffffff + static inline uint32_t image_get_header_size(void) { return (sizeof(image_header_t)); diff --git a/tools/mkimage.c b/tools/mkimage.c index ffc91d2319..a13d86f0aa 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -479,7 +479,7 @@ int main(int argc, char **argv) } size = cpu_to_uimage (sbuf.st_size); } else { - size = 0; + size = IMAGE_PARAM_INVAL; } if (write(ifd, (char *)&size, sizeof(size)) != sizeof(size)) { @@ -650,6 +650,11 @@ copy_file (int ifd, const char *datafile, int pad) exit (EXIT_FAILURE); } + if (sbuf.st_size == 0) { + (void) close (dfd); + return; + } + ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0); if (ptr == MAP_FAILED) { fprintf (stderr, "%s: Can't read %s: %s\n",