Add signature support

Change-Id: Idf5b6144b78e156e6c77e656cfe14097750259e5
tirimbino
Ketut Putu Kumajaya 11 years ago committed by Christopher N. Hesse
parent 6384637a7c
commit 0c2cc5a940
  1. 2
      dtbhtool/bootimg.h
  2. 18
      dtbhtool/mkbootimg.c
  3. 14
      dtbhtool/unpackbootimg.c

@ -61,6 +61,8 @@ struct boot_img_hdr
** +-----------------+ ** +-----------------+
** | device tree | p pages ** | device tree | p pages
** +-----------------+ ** +-----------------+
** | signature | 256 bytes
** +-----------------+
** **
** n = (kernel_size + page_size - 1) / page_size ** n = (kernel_size + page_size - 1) / page_size
** m = (ramdisk_size + page_size - 1) / page_size ** m = (ramdisk_size + page_size - 1) / page_size

@ -67,6 +67,7 @@ int usage(void)
" [ --pagesize <pagesize> ]\n" " [ --pagesize <pagesize> ]\n"
" [ --ramdisk_offset <address> ]\n" " [ --ramdisk_offset <address> ]\n"
" [ --dt <filename> ]\n" " [ --dt <filename> ]\n"
" [ --signature <filename> ]\n"
" -o|--output <filename>\n" " -o|--output <filename>\n"
); );
return 1; return 1;
@ -109,6 +110,8 @@ int main(int argc, char **argv)
char *board = ""; char *board = "";
char *dt_fn = 0; char *dt_fn = 0;
void *dt_data = 0; void *dt_data = 0;
char *sig_fn = 0;
void *sig_data = 0;
unsigned pagesize = 2048; unsigned pagesize = 2048;
int fd; int fd;
SHA_CTX ctx; SHA_CTX ctx;
@ -162,6 +165,8 @@ int main(int argc, char **argv)
} }
} else if(!strcmp(arg, "--dt")) { } else if(!strcmp(arg, "--dt")) {
dt_fn = val; dt_fn = val;
} else if(!strcmp(arg, "--signature")) {
sig_fn = val;
} else { } else {
return usage(); 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 /* put a hash of the contents in the header so boot images can be
* differentiated based on their first 2k. * 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(fd, dt_data, hdr.dt_size) != hdr.dt_size) goto fail;
if(write_padding(fd, pagesize, 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; return 0;
fail: fail:

@ -203,7 +203,19 @@ int main(int argc, char** argv)
total_read += header.dt_size; total_read += header.dt_size;
fwrite(dt, header.dt_size, 1, r); fwrite(dt, header.dt_size, 1, r);
fclose(d); 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); fclose(f);
//printf("Total Read: %d\n", total_read); //printf("Total Read: %d\n", total_read);

Loading…
Cancel
Save