Skip to content

Commit 16738f9

Browse files
David NgGiulio Cervera
authored andcommitted
mkbootimg: Add --dt parameter to specify DT image
New optional --dt parameter to specify a kernel device tree image. Change-Id: I7e2c48c25c04165642eedadc3dc16a082dd99eb0
1 parent c965274 commit 16738f9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

mkbootimg/bootimg.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ struct boot_img_hdr
4040

4141
unsigned tags_addr; /* physical addr for kernel tags */
4242
unsigned page_size; /* flash page size we assume */
43-
unsigned unused[2]; /* future expansion: should be 0 */
44-
43+
unsigned dt_size; /* device tree in bytes */
44+
unsigned unused; /* future expansion: should be 0 */
4545
unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */
4646

4747
unsigned char cmdline[BOOT_ARGS_SIZE];
@@ -59,10 +59,13 @@ struct boot_img_hdr
5959
** +-----------------+
6060
** | second stage | o pages
6161
** +-----------------+
62+
** | device tree | p pages
63+
** +-----------------+
6264
**
6365
** n = (kernel_size + page_size - 1) / page_size
6466
** m = (ramdisk_size + page_size - 1) / page_size
6567
** o = (second_size + page_size - 1) / page_size
68+
** p = (dt_size + page_size - 1) / page_size
6669
**
6770
** 0. all entities are page_size aligned in flash
6871
** 1. kernel and ramdisk are required (size != 0)

mkbootimg/mkbootimg.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ int usage(void)
6666
" [ --base <address> ]\n"
6767
" [ --pagesize <pagesize> ]\n"
6868
" [ --ramdisk_offset <address> ]\n"
69+
" [ --dt <filename> ]\n"
6970
" -o|--output <filename>\n"
7071
);
7172
return 1;
@@ -106,6 +107,8 @@ int main(int argc, char **argv)
106107
char *cmdline = "";
107108
char *bootimg = 0;
108109
char *board = "";
110+
char *dt_fn = 0;
111+
void *dt_data = 0;
109112
unsigned pagesize = 2048;
110113
int fd;
111114
SHA_CTX ctx;
@@ -157,6 +160,8 @@ int main(int argc, char **argv)
157160
fprintf(stderr,"error: unsupported page size %d\n", pagesize);
158161
return -1;
159162
}
163+
} else if(!strcmp(arg, "--dt")) {
164+
dt_fn = val;
160165
} else {
161166
return usage();
162167
}
@@ -223,6 +228,14 @@ int main(int argc, char **argv)
223228
}
224229
}
225230

231+
if(dt_fn) {
232+
dt_data = load_file(dt_fn, &hdr.dt_size);
233+
if (dt_data == 0) {
234+
fprintf(stderr,"error: could not load device tree image '%s'\n", dt_fn);
235+
return 1;
236+
}
237+
}
238+
226239
/* put a hash of the contents in the header so boot images can be
227240
* differentiated based on their first 2k.
228241
*/
@@ -233,6 +246,10 @@ int main(int argc, char **argv)
233246
SHA_update(&ctx, &hdr.ramdisk_size, sizeof(hdr.ramdisk_size));
234247
SHA_update(&ctx, second_data, hdr.second_size);
235248
SHA_update(&ctx, &hdr.second_size, sizeof(hdr.second_size));
249+
if(dt_data) {
250+
SHA_update(&ctx, dt_data, hdr.dt_size);
251+
SHA_update(&ctx, &hdr.dt_size, sizeof(hdr.dt_size));
252+
}
236253
sha = SHA_final(&ctx);
237254
memcpy(hdr.id, sha,
238255
SHA_DIGEST_SIZE > sizeof(hdr.id) ? sizeof(hdr.id) : SHA_DIGEST_SIZE);
@@ -257,6 +274,10 @@ int main(int argc, char **argv)
257274
if(write_padding(fd, pagesize, hdr.ramdisk_size)) goto fail;
258275
}
259276

277+
if(dt_data) {
278+
if(write(fd, dt_data, hdr.dt_size) != hdr.dt_size) goto fail;
279+
if(write_padding(fd, pagesize, hdr.dt_size)) goto fail;
280+
}
260281
return 0;
261282

262283
fail:

0 commit comments

Comments
 (0)