From 61fc19540146509d8faddb48996f8a53c68c3300 Mon Sep 17 00:00:00 2001 From: Andres Morales Date: Thu, 7 May 2015 13:52:55 -0700 Subject: mkbootimg: make mkbootimg print image cksum to stdout used by the build system as a fingerprint for the image Change-Id: Ifaf230b881e68d921a8158ed2e8a3ee41f27a4b3 --- mkbootimg/mkbootimg.c | 88 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 34 deletions(-) (limited to 'mkbootimg') diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c index 31f76e4e5..1a6e4cd85 100644 --- a/mkbootimg/mkbootimg.c +++ b/mkbootimg/mkbootimg.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "mincrypt/sha.h" #include "bootimg.h" @@ -65,6 +66,7 @@ int usage(void) " [ --board ]\n" " [ --base
]\n" " [ --pagesize ]\n" + " [ --id ]\n" " -o|--output \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(); @@ -266,6 +282,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: -- cgit v1.2.3