Skip to content

Commit

Permalink
Merge "mkbootimg: Add --dt parameter to specify DT image" into cm-10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio Cervera authored and Gerrit Code Review committed Sep 28, 2013
2 parents f3409d2 + 16738f9 commit cb943b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mkbootimg/bootimg.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ struct boot_img_hdr

unsigned tags_addr; /* physical addr for kernel tags */
unsigned page_size; /* flash page size we assume */
unsigned unused[2]; /* future expansion: should be 0 */

unsigned dt_size; /* device tree in bytes */
unsigned unused; /* future expansion: should be 0 */
unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */

unsigned char cmdline[BOOT_ARGS_SIZE];
Expand All @@ -59,10 +59,13 @@ struct boot_img_hdr
** +-----------------+
** | second stage | o pages
** +-----------------+
** | device tree | p pages
** +-----------------+
**
** n = (kernel_size + page_size - 1) / page_size
** m = (ramdisk_size + page_size - 1) / page_size
** o = (second_size + page_size - 1) / page_size
** p = (dt_size + page_size - 1) / page_size
**
** 0. all entities are page_size aligned in flash
** 1. kernel and ramdisk are required (size != 0)
Expand Down
21 changes: 21 additions & 0 deletions mkbootimg/mkbootimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ int usage(void)
" [ --base <address> ]\n"
" [ --pagesize <pagesize> ]\n"
" [ --ramdisk_offset <address> ]\n"
" [ --dt <filename> ]\n"
" -o|--output <filename>\n"
);
return 1;
Expand Down Expand Up @@ -106,6 +107,8 @@ int main(int argc, char **argv)
char *cmdline = "";
char *bootimg = 0;
char *board = "";
char *dt_fn = 0;
void *dt_data = 0;
unsigned pagesize = 2048;
int fd;
SHA_CTX ctx;
Expand Down Expand Up @@ -157,6 +160,8 @@ int main(int argc, char **argv)
fprintf(stderr,"error: unsupported page size %d\n", pagesize);
return -1;
}
} else if(!strcmp(arg, "--dt")) {
dt_fn = val;
} else {
return usage();
}
Expand Down Expand Up @@ -223,6 +228,14 @@ int main(int argc, char **argv)
}
}

if(dt_fn) {
dt_data = load_file(dt_fn, &hdr.dt_size);
if (dt_data == 0) {
fprintf(stderr,"error: could not load device tree image '%s'\n", dt_fn);
return 1;
}
}

/* put a hash of the contents in the header so boot images can be
* differentiated based on their first 2k.
*/
Expand All @@ -233,6 +246,10 @@ int main(int argc, char **argv)
SHA_update(&ctx, &hdr.ramdisk_size, sizeof(hdr.ramdisk_size));
SHA_update(&ctx, second_data, hdr.second_size);
SHA_update(&ctx, &hdr.second_size, sizeof(hdr.second_size));
if(dt_data) {
SHA_update(&ctx, dt_data, hdr.dt_size);
SHA_update(&ctx, &hdr.dt_size, sizeof(hdr.dt_size));
}
sha = SHA_final(&ctx);
memcpy(hdr.id, sha,
SHA_DIGEST_SIZE > sizeof(hdr.id) ? sizeof(hdr.id) : SHA_DIGEST_SIZE);
Expand All @@ -257,6 +274,10 @@ int main(int argc, char **argv)
if(write_padding(fd, pagesize, hdr.ramdisk_size)) goto fail;
}

if(dt_data) {
if(write(fd, dt_data, hdr.dt_size) != hdr.dt_size) goto fail;
if(write_padding(fd, pagesize, hdr.dt_size)) goto fail;
}
return 0;

fail:
Expand Down

0 comments on commit cb943b1

Please sign in to comment.