summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndres Morales2015-05-07 15:52:55 -0500
committerAndres Morales2015-05-08 11:20:07 -0500
commit61fc19540146509d8faddb48996f8a53c68c3300 (patch)
tree21440049133f7d19e3bb61374251f92aeb3f0976 /mkbootimg
parentf85f111620afba9bad222661c1c34aee731d415b (diff)
downloadplatform-system-core-61fc19540146509d8faddb48996f8a53c68c3300.tar.gz
platform-system-core-61fc19540146509d8faddb48996f8a53c68c3300.tar.xz
platform-system-core-61fc19540146509d8faddb48996f8a53c68c3300.zip
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.c88
1 files changed, 54 insertions, 34 deletions
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 @@
21#include <unistd.h> 21#include <unistd.h>
22#include <fcntl.h> 22#include <fcntl.h>
23#include <errno.h> 23#include <errno.h>
24#include <stdbool.h>
24 25
25#include "mincrypt/sha.h" 26#include "mincrypt/sha.h"
26#include "bootimg.h" 27#include "bootimg.h"
@@ -65,6 +66,7 @@ int usage(void)
65 " [ --board <boardname> ]\n" 66 " [ --board <boardname> ]\n"
66 " [ --base <address> ]\n" 67 " [ --base <address> ]\n"
67 " [ --pagesize <pagesize> ]\n" 68 " [ --pagesize <pagesize> ]\n"
69 " [ --id ]\n"
68 " -o|--output <filename>\n" 70 " -o|--output <filename>\n"
69 ); 71 );
70 return 1; 72 return 1;
@@ -74,6 +76,14 @@ int usage(void)
74 76
75static unsigned char padding[16384] = { 0, }; 77static unsigned char padding[16384] = { 0, };
76 78
79static void print_id(const uint8_t *id, size_t id_len) {
80 printf("0x");
81 for (unsigned i = 0; i < id_len; i++) {
82 printf("%02x", id[i]);
83 }
84 printf("\n");
85}
86
77int write_padding(int fd, unsigned pagesize, unsigned itemsize) 87int write_padding(int fd, unsigned pagesize, unsigned itemsize)
78{ 88{
79 unsigned pagemask = pagesize - 1; 89 unsigned pagemask = pagesize - 1;
@@ -121,42 +131,48 @@ int main(int argc, char **argv)
121 131
122 memset(&hdr, 0, sizeof(hdr)); 132 memset(&hdr, 0, sizeof(hdr));
123 133
134 bool get_id = false;
124 while(argc > 0){ 135 while(argc > 0){
125 char *arg = argv[0]; 136 char *arg = argv[0];
126 char *val = argv[1]; 137 if (!strcmp(arg, "--id")) {
127 if(argc < 2) { 138 get_id = true;
128 return usage(); 139 argc -= 1;
129 } 140 argv += 1;
130 argc -= 2; 141 } else if(argc >= 2) {
131 argv += 2; 142 char *val = argv[1];
132 if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) { 143 argc -= 2;
133 bootimg = val; 144 argv += 2;
134 } else if(!strcmp(arg, "--kernel")) { 145 if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) {
135 kernel_fn = val; 146 bootimg = val;
136 } else if(!strcmp(arg, "--ramdisk")) { 147 } else if(!strcmp(arg, "--kernel")) {
137 ramdisk_fn = val; 148 kernel_fn = val;
138 } else if(!strcmp(arg, "--second")) { 149 } else if(!strcmp(arg, "--ramdisk")) {
139 second_fn = val; 150 ramdisk_fn = val;
140 } else if(!strcmp(arg, "--cmdline")) { 151 } else if(!strcmp(arg, "--second")) {
141 cmdline = val; 152 second_fn = val;
142 } else if(!strcmp(arg, "--base")) { 153 } else if(!strcmp(arg, "--cmdline")) {
143 base = strtoul(val, 0, 16); 154 cmdline = val;
144 } else if(!strcmp(arg, "--kernel_offset")) { 155 } else if(!strcmp(arg, "--base")) {
145 kernel_offset = strtoul(val, 0, 16); 156 base = strtoul(val, 0, 16);
146 } else if(!strcmp(arg, "--ramdisk_offset")) { 157 } else if(!strcmp(arg, "--kernel_offset")) {
147 ramdisk_offset = strtoul(val, 0, 16); 158 kernel_offset = strtoul(val, 0, 16);
148 } else if(!strcmp(arg, "--second_offset")) { 159 } else if(!strcmp(arg, "--ramdisk_offset")) {
149 second_offset = strtoul(val, 0, 16); 160 ramdisk_offset = strtoul(val, 0, 16);
150 } else if(!strcmp(arg, "--tags_offset")) { 161 } else if(!strcmp(arg, "--second_offset")) {
151 tags_offset = strtoul(val, 0, 16); 162 second_offset = strtoul(val, 0, 16);
152 } else if(!strcmp(arg, "--board")) { 163 } else if(!strcmp(arg, "--tags_offset")) {
153 board = val; 164 tags_offset = strtoul(val, 0, 16);
154 } else if(!strcmp(arg,"--pagesize")) { 165 } else if(!strcmp(arg, "--board")) {
155 pagesize = strtoul(val, 0, 10); 166 board = val;
156 if ((pagesize != 2048) && (pagesize != 4096) 167 } else if(!strcmp(arg,"--pagesize")) {
157 && (pagesize != 8192) && (pagesize != 16384)) { 168 pagesize = strtoul(val, 0, 10);
158 fprintf(stderr,"error: unsupported page size %d\n", pagesize); 169 if ((pagesize != 2048) && (pagesize != 4096)
159 return -1; 170 && (pagesize != 8192) && (pagesize != 16384)) {
171 fprintf(stderr,"error: unsupported page size %d\n", pagesize);
172 return -1;
173 }
174 } else {
175 return usage();
160 } 176 }
161 } else { 177 } else {
162 return usage(); 178 return usage();
@@ -266,6 +282,10 @@ int main(int argc, char **argv)
266 if(write_padding(fd, pagesize, hdr.second_size)) goto fail; 282 if(write_padding(fd, pagesize, hdr.second_size)) goto fail;
267 } 283 }
268 284
285 if (get_id) {
286 print_id(sha, sizeof(hdr.id));
287 }
288
269 return 0; 289 return 0;
270 290
271fail: 291fail: