From 40d08d0f10c628337658fbc2ad220132cda676bb Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Fri, 27 Mar 2020 18:02:55 +0800 Subject: [PATCH] tools: mkimage: support pack empty file for multi image Muilt image bootflow requires ramdisk as a mandory component, so that we have to pack a empty ramdisk into multi image at some time. Signed-off-by: Joseph Chen Change-Id: I551ae832fbc68514ead0a3337148593e3113394f --- common/image.c | 2 +- include/image.h | 2 ++ tools/mkimage.c | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) 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",