blob: 35bb766a7f6c65c8d8626a23a325f9f4e39ccd69 [file] [log] [blame]
Patrick Williamsddad1a12017-02-23 20:36:32 -06001From cc5e7b02a3be57709a1aed6e34be100b82a71620 Mon Sep 17 00:00:00 2001
2From: David Ng <dave@codeaurora.org>
3Date: Fri, 27 Jul 2012 17:15:03 -0700
4Subject: [PATCH 1/2] mkbootimg: Add --dt parameter to specify DT image
5
6New optional --dt parameter to specify a kernel device
7tree image.
8
9Change-Id: Ie29a11cbf4138426bfd19ae486d69a5fcbd8f442
10
11Upstream-Status: Inappropriate
12---
13 system/core/mkbootimg/bootimg.h | 7 +++++--
14 system/core/mkbootimg/mkbootimg.c | 21 +++++++++++++++++++++
15 2 files changed, 26 insertions(+), 2 deletions(-)
16
17--- a/system/core/mkbootimg/bootimg.h
18+++ b/system/core/mkbootimg/bootimg.h
19@@ -41,8 +41,8 @@ struct boot_img_hdr
20
21 unsigned tags_addr; /* physical addr for kernel tags */
22 unsigned page_size; /* flash page size we assume */
23- unsigned unused[2]; /* future expansion: should be 0 */
24-
25+ unsigned dt_size; /* device tree in bytes */
26+ unsigned unused; /* future expansion: should be 0 */
27 unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */
28
29 unsigned char cmdline[BOOT_ARGS_SIZE];
30@@ -64,10 +64,13 @@ struct boot_img_hdr
31 ** +-----------------+
32 ** | second stage | o pages
33 ** +-----------------+
34+** | device tree | p pages
35+** +-----------------+
36 **
37 ** n = (kernel_size + page_size - 1) / page_size
38 ** m = (ramdisk_size + page_size - 1) / page_size
39 ** o = (second_size + page_size - 1) / page_size
40+** p = (dt_size + page_size - 1) / page_size
41 **
42 ** 0. all entities are page_size aligned in flash
43 ** 1. kernel and ramdisk are required (size != 0)
44--- a/system/core/mkbootimg/mkbootimg.c
45+++ b/system/core/mkbootimg/mkbootimg.c
46@@ -65,6 +65,7 @@ int usage(void)
47 " [ --board <boardname> ]\n"
48 " [ --base <address> ]\n"
49 " [ --pagesize <pagesize> ]\n"
50+ " [ --dt <filename> ]\n"
51 " -o|--output <filename>\n"
52 );
53 return 1;
54@@ -105,6 +106,8 @@ int main(int argc, char **argv)
55 char *cmdline = "";
56 char *bootimg = 0;
57 char *board = "";
58+ char *dt_fn = 0;
59+ void *dt_data = 0;
60 unsigned pagesize = 2048;
61 int fd;
62 SHA_CTX ctx;
63@@ -158,6 +161,8 @@ int main(int argc, char **argv)
64 fprintf(stderr,"error: unsupported page size %d\n", pagesize);
65 return -1;
66 }
67+ } else if(!strcmp(arg, "--dt")) {
68+ dt_fn = val;
69 } else {
70 return usage();
71 }
72@@ -232,6 +237,14 @@ int main(int argc, char **argv)
73 }
74 }
75
76+ if(dt_fn) {
77+ dt_data = load_file(dt_fn, &hdr.dt_size);
78+ if (dt_data == 0) {
79+ fprintf(stderr,"error: could not load device tree image '%s'\n", dt_fn);
80+ return 1;
81+ }
82+ }
83+
84 /* put a hash of the contents in the header so boot images can be
85 * differentiated based on their first 2k.
86 */
87@@ -242,6 +255,10 @@ int main(int argc, char **argv)
88 SHA_update(&ctx, &hdr.ramdisk_size, sizeof(hdr.ramdisk_size));
89 SHA_update(&ctx, second_data, hdr.second_size);
90 SHA_update(&ctx, &hdr.second_size, sizeof(hdr.second_size));
91+ if(dt_data) {
92+ SHA_update(&ctx, dt_data, hdr.dt_size);
93+ SHA_update(&ctx, &hdr.dt_size, sizeof(hdr.dt_size));
94+ }
95 sha = SHA_final(&ctx);
96 memcpy(hdr.id, sha,
97 SHA_DIGEST_SIZE > sizeof(hdr.id) ? sizeof(hdr.id) : SHA_DIGEST_SIZE);
98@@ -266,6 +283,10 @@ int main(int argc, char **argv)
99 if(write_padding(fd, pagesize, hdr.second_size)) goto fail;
100 }
101
102+ if(dt_data) {
103+ if(write(fd, dt_data, hdr.dt_size) != (ssize_t) hdr.dt_size) goto fail;
104+ if(write_padding(fd, pagesize, hdr.dt_size)) goto fail;
105+ }
106 return 0;
107
108 fail: