diff options
author | Andres Morales <anmorales@google.com> | 2015-05-07 13:52:55 -0700 |
---|---|---|
committer | Andres Morales <anmorales@google.com> | 2015-05-07 15:02:23 -0700 |
commit | 7f9259f6523dd8bd42948b3524c3c6570a3bdf31 (patch) | |
tree | 6b8faa8edfbd996e9ad1844781ab8dbc331bb28c /mkbootimg | |
parent | 95108f18443f22440653bf1648c969816ca852dd (diff) | |
download | system_core-7f9259f6523dd8bd42948b3524c3c6570a3bdf31.zip system_core-7f9259f6523dd8bd42948b3524c3c6570a3bdf31.tar.gz system_core-7f9259f6523dd8bd42948b3524c3c6570a3bdf31.tar.bz2 |
mkbootimg: make mkbootimg print image cksum to stdout
used by the build system as a fingerprint for the image
Change-Id: Ifaf230b881e68d921a8158ed2e8a3ee41f27a4b3
Diffstat (limited to 'mkbootimg')
-rw-r--r-- | mkbootimg/mkbootimg.c | 88 |
1 files changed, 54 insertions, 34 deletions
diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c index a4ab7e1..8fd9a3b 100644 --- a/mkbootimg/mkbootimg.c +++ b/mkbootimg/mkbootimg.c @@ -21,6 +21,7 @@ #include <unistd.h> #include <fcntl.h> #include <errno.h> +#include <stdbool.h> #include "mincrypt/sha.h" #include "bootimg.h" @@ -65,6 +66,7 @@ int usage(void) " [ --board <boardname> ]\n" " [ --base <address> ]\n" " [ --pagesize <pagesize> ]\n" + " [ --id ]\n" " -o|--output <filename>\n" ); return 1; @@ -74,6 +76,14 @@ int usage(void) static unsigned char padding[16384] = { 0, }; +static void print_id(const uint8_t *id, size_t id_len) { + printf("0x"); + for (unsigned i = 0; i < id_len; i++) { + printf("%02x", id[i]); + } + printf("\n"); +} + int write_padding(int fd, unsigned pagesize, unsigned itemsize) { unsigned pagemask = pagesize - 1; @@ -121,42 +131,48 @@ int main(int argc, char **argv) memset(&hdr, 0, sizeof(hdr)); + bool get_id = false; while(argc > 0){ char *arg = argv[0]; - char *val = argv[1]; - if(argc < 2) { - return usage(); - } - argc -= 2; - argv += 2; - if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) { - bootimg = val; - } else if(!strcmp(arg, "--kernel")) { - kernel_fn = val; - } else if(!strcmp(arg, "--ramdisk")) { - ramdisk_fn = val; - } else if(!strcmp(arg, "--second")) { - second_fn = val; - } else if(!strcmp(arg, "--cmdline")) { - cmdline = val; - } else if(!strcmp(arg, "--base")) { - base = strtoul(val, 0, 16); - } else if(!strcmp(arg, "--kernel_offset")) { - kernel_offset = strtoul(val, 0, 16); - } else if(!strcmp(arg, "--ramdisk_offset")) { - ramdisk_offset = strtoul(val, 0, 16); - } else if(!strcmp(arg, "--second_offset")) { - second_offset = strtoul(val, 0, 16); - } else if(!strcmp(arg, "--tags_offset")) { - tags_offset = strtoul(val, 0, 16); - } else if(!strcmp(arg, "--board")) { - board = val; - } else if(!strcmp(arg,"--pagesize")) { - pagesize = strtoul(val, 0, 10); - if ((pagesize != 2048) && (pagesize != 4096) - && (pagesize != 8192) && (pagesize != 16384)) { - fprintf(stderr,"error: unsupported page size %d\n", pagesize); - return -1; + if (!strcmp(arg, "--id")) { + get_id = true; + argc -= 1; + argv += 1; + } else if(argc >= 2) { + char *val = argv[1]; + argc -= 2; + argv += 2; + if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) { + bootimg = val; + } else if(!strcmp(arg, "--kernel")) { + kernel_fn = val; + } else if(!strcmp(arg, "--ramdisk")) { + ramdisk_fn = val; + } else if(!strcmp(arg, "--second")) { + second_fn = val; + } else if(!strcmp(arg, "--cmdline")) { + cmdline = val; + } else if(!strcmp(arg, "--base")) { + base = strtoul(val, 0, 16); + } else if(!strcmp(arg, "--kernel_offset")) { + kernel_offset = strtoul(val, 0, 16); + } else if(!strcmp(arg, "--ramdisk_offset")) { + ramdisk_offset = strtoul(val, 0, 16); + } else if(!strcmp(arg, "--second_offset")) { + second_offset = strtoul(val, 0, 16); + } else if(!strcmp(arg, "--tags_offset")) { + tags_offset = strtoul(val, 0, 16); + } else if(!strcmp(arg, "--board")) { + board = val; + } else if(!strcmp(arg,"--pagesize")) { + pagesize = strtoul(val, 0, 10); + if ((pagesize != 2048) && (pagesize != 4096) + && (pagesize != 8192) && (pagesize != 16384)) { + fprintf(stderr,"error: unsupported page size %d\n", pagesize); + return -1; + } + } else { + return usage(); } } else { return usage(); @@ -261,6 +277,10 @@ int main(int argc, char **argv) if(write_padding(fd, pagesize, hdr.second_size)) goto fail; } + if (get_id) { + print_id(sha, sizeof(hdr.id)); + } + return 0; fail: |