From bc7bb0cb21f9a11cb5ee966160fbb524a851cbb4 Mon Sep 17 00:00:00 2001 From: Ketut Putu Kumajaya Date: Mon, 23 Jun 2014 20:18:46 +0700 Subject: [PATCH] Add signature support Change-Id: Idf5b6144b78e156e6c77e656cfe14097750259e5 --- dtbhtool/bootimg.h | 2 ++ dtbhtool/mkbootimg.c | 18 ++++++++++++++++++ dtbhtool/unpackbootimg.c | 14 +++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/dtbhtool/bootimg.h b/dtbhtool/bootimg.h index 4692f0c..ef0e61c 100644 --- a/dtbhtool/bootimg.h +++ b/dtbhtool/bootimg.h @@ -61,6 +61,8 @@ struct boot_img_hdr ** +-----------------+ ** | device tree | p pages ** +-----------------+ +** | signature | 256 bytes +** +-----------------+ ** ** n = (kernel_size + page_size - 1) / page_size ** m = (ramdisk_size + page_size - 1) / page_size diff --git a/dtbhtool/mkbootimg.c b/dtbhtool/mkbootimg.c index 06fc95b..09e2e78 100644 --- a/dtbhtool/mkbootimg.c +++ b/dtbhtool/mkbootimg.c @@ -67,6 +67,7 @@ int usage(void) " [ --pagesize ]\n" " [ --ramdisk_offset
]\n" " [ --dt ]\n" + " [ --signature ]\n" " -o|--output \n" ); return 1; @@ -109,6 +110,8 @@ int main(int argc, char **argv) char *board = ""; char *dt_fn = 0; void *dt_data = 0; + char *sig_fn = 0; + void *sig_data = 0; unsigned pagesize = 2048; int fd; SHA_CTX ctx; @@ -162,6 +165,8 @@ int main(int argc, char **argv) } } else if(!strcmp(arg, "--dt")) { dt_fn = val; + } else if(!strcmp(arg, "--signature")) { + sig_fn = val; } else { return usage(); } @@ -236,6 +241,14 @@ int main(int argc, char **argv) } } + if(sig_fn) { + sig_data = load_file(sig_fn, 0); + if (sig_data == 0) { + fprintf(stderr,"error: could not load signature '%s'\n", sig_fn); + return 1; + } + } + /* put a hash of the contents in the header so boot images can be * differentiated based on their first 2k. */ @@ -278,6 +291,11 @@ int main(int argc, char **argv) if(write(fd, dt_data, hdr.dt_size) != hdr.dt_size) goto fail; if(write_padding(fd, pagesize, hdr.dt_size)) goto fail; } + + if(sig_data) { + if(write(fd, sig_data, 256) != 256) goto fail; + } + return 0; fail: diff --git a/dtbhtool/unpackbootimg.c b/dtbhtool/unpackbootimg.c index 3d2fda7..aef2166 100644 --- a/dtbhtool/unpackbootimg.c +++ b/dtbhtool/unpackbootimg.c @@ -203,7 +203,19 @@ int main(int argc, char** argv) total_read += header.dt_size; fwrite(dt, header.dt_size, 1, r); fclose(d); - + + total_read += read_padding(f, header.dt_size, pagesize); + + sprintf(tmp, "%s/%s", directory, basename(filename)); + strcat(tmp, "-signature"); + FILE *fsig = fopen(tmp, "wb"); + byte* bsig = (byte*)malloc(256); + //printf("Reading signature...\n"); + fread(bsig, 256, 1, f); + total_read += 256; + fwrite(bsig, 256, 1, r); + fclose(fsig); + fclose(f); //printf("Total Read: %d\n", total_read); -- 2.20.1