blob: a4dc6e1e357d1cf5e8e4d584e3ecdd066f6c687a [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From dd195778a9930b7967b21a3b8eb390b70253dbad Mon Sep 17 00:00:00 2001
2From: David Ng <dave@codeaurora.org>
3Date: Fri, 27 Jul 2012 17:15:03 -0700
4Subject: [PATCH] mkbootimg: Add --dt parameter to specify DT image
5
6New optional --dt parameter to specify a kernel device
7tree image.
8
9Upstream-Status: Inappropriate
10---
11 mkbootimg/bootimg.h | 7 +++++--
12 mkbootimg/mkbootimg.c | 21 +++++++++++++++++++++
13 2 files changed, 26 insertions(+), 2 deletions(-)
14
15diff --git a/mkbootimg/bootimg.h b/mkbootimg/bootimg.h
16index 9171d85a7b..308c537d6b 100644
17--- a/mkbootimg/bootimg.h
18+++ b/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)
44diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c
45index fc92b4dc30..658052cdf2 100644
46--- a/mkbootimg/mkbootimg.c
47+++ b/mkbootimg/mkbootimg.c
48@@ -65,6 +65,7 @@ int usage(void)
49 " [ --board <boardname> ]\n"
50 " [ --base <address> ]\n"
51 " [ --pagesize <pagesize> ]\n"
52+ " [ --dt <filename> ]\n"
53 " -o|--output <filename>\n"
54 );
55 return 1;
56@@ -105,6 +106,8 @@ int main(int argc, char **argv)
57 char *cmdline = "";
58 char *bootimg = 0;
59 char *board = "";
60+ char *dt_fn = 0;
61+ void *dt_data = 0;
62 unsigned pagesize = 2048;
63 int fd;
64 SHA_CTX ctx;
65@@ -158,6 +161,8 @@ int main(int argc, char **argv)
66 fprintf(stderr,"error: unsupported page size %d\n", pagesize);
67 return -1;
68 }
69+ } else if(!strcmp(arg, "--dt")) {
70+ dt_fn = val;
71 } else {
72 return usage();
73 }
74@@ -232,6 +237,14 @@ int main(int argc, char **argv)
75 }
76 }
77
78+ if(dt_fn) {
79+ dt_data = load_file(dt_fn, &hdr.dt_size);
80+ if (dt_data == 0) {
81+ fprintf(stderr,"error: could not load device tree image '%s'\n", dt_fn);
82+ return 1;
83+ }
84+ }
85+
86 /* put a hash of the contents in the header so boot images can be
87 * differentiated based on their first 2k.
88 */
89@@ -242,6 +255,10 @@ int main(int argc, char **argv)
90 SHA_update(&ctx, &hdr.ramdisk_size, sizeof(hdr.ramdisk_size));
91 SHA_update(&ctx, second_data, hdr.second_size);
92 SHA_update(&ctx, &hdr.second_size, sizeof(hdr.second_size));
93+ if(dt_data) {
94+ SHA_update(&ctx, dt_data, hdr.dt_size);
95+ SHA_update(&ctx, &hdr.dt_size, sizeof(hdr.dt_size));
96+ }
97 sha = SHA_final(&ctx);
98 memcpy(hdr.id, sha,
99 SHA_DIGEST_SIZE > sizeof(hdr.id) ? sizeof(hdr.id) : SHA_DIGEST_SIZE);
100@@ -266,6 +283,10 @@ int main(int argc, char **argv)
101 if(write_padding(fd, pagesize, hdr.second_size)) goto fail;
102 }
103
104+ if(dt_data) {
105+ if(write(fd, dt_data, hdr.dt_size) != (ssize_t) hdr.dt_size) goto fail;
106+ if(write_padding(fd, pagesize, hdr.dt_size)) goto fail;
107+ }
108 return 0;
109
110 fail: