summaryrefslogtreecommitdiffstats
path: root/tools/mkboot.c
diff options
context:
space:
mode:
authorJames Buren <braewoods+rb@braewoods.net>2020-11-16 18:23:30 +0000
committerJames Buren <braewoods+rb@braewoods.net>2020-11-16 18:23:30 +0000
commit64ea6442695aee6bc1096672716f12245425ff4c (patch)
treee3b5dc756375885e122b75652f2ace411d872c4a /tools/mkboot.c
parent63691ad1067911ebbded3e93301ae08ddadf59b9 (diff)
downloadrockbox-64ea644269.tar.gz
rockbox-64ea644269.tar.bz2
rockbox-64ea644269.zip
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
Diffstat (limited to 'tools/mkboot.c')
-rw-r--r--tools/mkboot.c14
1 files changed, 13 insertions, 1 deletions
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 <string.h>
#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)
{