summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Boie2013-08-21 17:48:40 -0500
committerAndrew Boie2013-09-09 15:13:33 -0500
commitd35ce3563b4d86702cec4c8f7031fb8a1c55cac2 (patch)
treedcbbb0894f475de81940203e2e8a7f7a2587efc9 /mkbootimg
parent2e63e71f3116f0330b3bf61dde7deca235dd40ac (diff)
downloadplatform-system-core-d35ce3563b4d86702cec4c8f7031fb8a1c55cac2.tar.gz
platform-system-core-d35ce3563b4d86702cec4c8f7031fb8a1c55cac2.tar.xz
platform-system-core-d35ce3563b4d86702cec4c8f7031fb8a1c55cac2.zip
mkbootimg: support longer kernel command lines
We can't simply increase the value of BOOT_ARGS_SIZE since that would break past binary compatibility; the offset of 'id' would change. This can cause serious problems with incremental OTA updates. Instead, define a supplemental field which stores command line information beyond the first 512 bytes. A value of 1024 was chosen to keep the total size of struct boot_img_hdr under the smallest page size of 2048 bytes. Even if the extra_cmdline field is used, the original cmdline field is still always NULL-terminated to avoid issues with older bootloaders that haven't been updated. Change-Id: I887e6f1db351a5b71a61e3a03363cf8856123d74 Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Diffstat (limited to 'mkbootimg')
-rw-r--r--mkbootimg/bootimg.h7
-rw-r--r--mkbootimg/mkbootimg.c13
2 files changed, 17 insertions, 3 deletions
diff --git a/mkbootimg/bootimg.h b/mkbootimg/bootimg.h
index 242ab35db..9171d85a7 100644
--- a/mkbootimg/bootimg.h
+++ b/mkbootimg/bootimg.h
@@ -24,6 +24,7 @@ typedef struct boot_img_hdr boot_img_hdr;
24#define BOOT_MAGIC_SIZE 8 24#define BOOT_MAGIC_SIZE 8
25#define BOOT_NAME_SIZE 16 25#define BOOT_NAME_SIZE 16
26#define BOOT_ARGS_SIZE 512 26#define BOOT_ARGS_SIZE 512
27#define BOOT_EXTRA_ARGS_SIZE 1024
27 28
28struct boot_img_hdr 29struct boot_img_hdr
29{ 30{
@@ -43,10 +44,14 @@ struct boot_img_hdr
43 unsigned unused[2]; /* future expansion: should be 0 */ 44 unsigned unused[2]; /* future expansion: should be 0 */
44 45
45 unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */ 46 unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */
46 47
47 unsigned char cmdline[BOOT_ARGS_SIZE]; 48 unsigned char cmdline[BOOT_ARGS_SIZE];
48 49
49 unsigned id[8]; /* timestamp / checksum / sha1 / etc */ 50 unsigned id[8]; /* timestamp / checksum / sha1 / etc */
51
52 /* Supplemental command line data; kept here to maintain
53 * binary compatibility with older versions of mkbootimg */
54 unsigned char extra_cmdline[BOOT_EXTRA_ARGS_SIZE];
50}; 55};
51 56
52/* 57/*
diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c
index 34a879b5a..d598f0395 100644
--- a/mkbootimg/mkbootimg.c
+++ b/mkbootimg/mkbootimg.c
@@ -114,6 +114,7 @@ int main(int argc, char **argv)
114 unsigned ramdisk_offset = 0x01000000; 114 unsigned ramdisk_offset = 0x01000000;
115 unsigned second_offset = 0x00f00000; 115 unsigned second_offset = 0x00f00000;
116 unsigned tags_offset = 0x00000100; 116 unsigned tags_offset = 0x00000100;
117 size_t cmdlen;
117 118
118 argc--; 119 argc--;
119 argv++; 120 argv++;
@@ -192,11 +193,19 @@ int main(int argc, char **argv)
192 193
193 memcpy(hdr.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE); 194 memcpy(hdr.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE);
194 195
195 if(strlen(cmdline) > (BOOT_ARGS_SIZE - 1)) { 196 cmdlen = strlen(cmdline);
197 if(cmdlen > (BOOT_ARGS_SIZE + BOOT_EXTRA_ARGS_SIZE - 2)) {
196 fprintf(stderr,"error: kernel commandline too large\n"); 198 fprintf(stderr,"error: kernel commandline too large\n");
197 return 1; 199 return 1;
198 } 200 }
199 strcpy((char*)hdr.cmdline, cmdline); 201 /* Even if we need to use the supplemental field, ensure we
202 * are still NULL-terminated */
203 strncpy((char *)hdr.cmdline, cmdline, BOOT_ARGS_SIZE - 1);
204 hdr.cmdline[BOOT_ARGS_SIZE - 1] = '\0';
205 if (cmdlen >= (BOOT_ARGS_SIZE - 1)) {
206 cmdline += (BOOT_ARGS_SIZE - 1);
207 strncpy((char *)hdr.extra_cmdline, cmdline, BOOT_EXTRA_ARGS_SIZE);
208 }
200 209
201 kernel_data = load_file(kernel_fn, &hdr.kernel_size); 210 kernel_data = load_file(kernel_fn, &hdr.kernel_size);
202 if(kernel_data == 0) { 211 if(kernel_data == 0) {