Skip to content

Commit

Permalink
Add signature support
Browse files Browse the repository at this point in the history
Change-Id: Idf5b6144b78e156e6c77e656cfe14097750259e5
  • Loading branch information
kumajaya authored and raymanfx committed Jan 4, 2017
1 parent 6384637 commit 0c2cc5a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dtbhtool/bootimg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions dtbhtool/mkbootimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int usage(void)
" [ --pagesize <pagesize> ]\n"
" [ --ramdisk_offset <address> ]\n"
" [ --dt <filename> ]\n"
" [ --signature <filename> ]\n"
" -o|--output <filename>\n"
);
return 1;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 13 additions & 1 deletion dtbhtool/unpackbootimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0c2cc5a

Please sign in to comment.