From 64ea6442695aee6bc1096672716f12245425ff4c Mon Sep 17 00:00:00 2001 From: James Buren Date: Mon, 16 Nov 2020 18:23:30 +0000 Subject: [PATCH] mkboot: fix the buffer size used for constructing the final firmware image It was short by a fair number of bytes which could be reached when attempting to insert bootloaders near the maximum size of 64k. This ensures even the largest acceptable bootloader will not overflow the buffer. Change-Id: I8fbc92d4e3452192bf47104d7a32b49248eefc0e --- tools/mkboot.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/mkboot.c b/tools/mkboot.c index 77f65d9dc7..b305da2eae 100644 --- a/tools/mkboot.c +++ b/tools/mkboot.c @@ -23,6 +23,13 @@ #include #include "mkboot.h" +#define SECTOR_SIZE 0x200 +#define RAW_IMAGE_SIZE 0x400000 +#define TOTAL_IMAGE_SIZE (RAW_IMAGE_SIZE + HEADER2_SIZE) +#define ALIGNED_IMAGE_SIZE (TOTAL_IMAGE_SIZE + SECTOR_SIZE - (TOTAL_IMAGE_SIZE % SECTOR_SIZE)) +#define HEADER1_SIZE SECTOR_SIZE +#define HEADER2_SIZE 0x20 + #ifndef RBUTIL static void usage(void) { @@ -63,7 +70,12 @@ int main(int argc, char *argv[]) } #endif -static unsigned char image[0x400000 + 0x220 + 0x400000/0x200]; +/* + * initial header size plus + * the rounded up size (includes the raw data and its length header) plus + * the checksums for the raw data and its length header + */ +static unsigned char image[ALIGNED_IMAGE_SIZE + HEADER1_SIZE + ALIGNED_IMAGE_SIZE / SECTOR_SIZE]; int mkboot_iriver(const char* infile, const char* bootfile, const char* outfile, int origin) {