Blame view
tools/mkimage.c
15.5 KB
5b1d71372 Initial revision |
1 |
/* |
9d25438fe [new uImage] Add ... |
2 3 |
* (C) Copyright 2008 Semihalf * |
89a4d6b12 tools: mkimage: s... |
4 |
* (C) Copyright 2000-2009 |
5b1d71372 Initial revision |
5 6 |
* DENX Software Engineering * Wolfgang Denk, wd@denx.de |
0c852a288 * Patch by Rahul ... |
7 |
* |
1a4596601 Add GPL-2.0+ SPDX... |
8 |
* SPDX-License-Identifier: GPL-2.0+ |
5b1d71372 Initial revision |
9 |
*/ |
b97a2a0a2 [new uImage] Defi... |
10 |
#include "mkimage.h" |
5b1d71372 Initial revision |
11 |
#include <image.h> |
976b38c07 mkimage: add "-V"... |
12 |
#include <version.h> |
89a4d6b12 tools: mkimage: s... |
13 14 15 16 17 18 19 20 |
static void copy_file(int, const char *, int); static void usage(void); /* image_type_params link list to maintain registered image type supports */ struct image_type_params *mkimage_tparams = NULL; /* parameters initialized by core will be used by the image type code */ |
f86ed6a8d tools: moved code... |
21 |
struct image_tool_params params = { |
89a4d6b12 tools: mkimage: s... |
22 23 24 25 26 |
.os = IH_OS_LINUX, .arch = IH_ARCH_PPC, .type = IH_TYPE_KERNEL, .comp = IH_COMP_GZIP, .dtc = MKIMAGE_DEFAULT_DTC_OPTIONS, |
04387d24a mkimage: fix Segm... |
27 |
.imagename = "", |
5d898a00f powerpc/CoreNet: ... |
28 |
.imagename2 = "", |
89a4d6b12 tools: mkimage: s... |
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
}; /* * mkimage_register - * * It is used to register respective image generation/list support to the * mkimage core * * the input struct image_type_params is checked and appended to the link * list, if the input structure is already registered, error */ void mkimage_register (struct image_type_params *tparams) { struct image_type_params **tp; if (!tparams) { fprintf (stderr, "%s: %s: Null input ", params.cmdname, __FUNCTION__); exit (EXIT_FAILURE); } /* scan the linked list, check for registry and point the last one */ for (tp = &mkimage_tparams; *tp != NULL; tp = &(*tp)->next) { if (!strcmp((*tp)->name, tparams->name)) { fprintf (stderr, "%s: %s already registered ", params.cmdname, tparams->name); return; } } /* add input struct entry at the end of link list */ *tp = tparams; /* mark input entry as last entry in the link list */ tparams->next = NULL; debug ("Registered %s ", tparams->name); } /* * mkimage_get_type - * * It scans all registers image type supports * checks the input type_id for each supported image type * * if successful, * returns respective image_type_params pointer if success * if input type_id is not supported by any of image_type_support * returns NULL */ struct image_type_params *mkimage_get_type(int type) { struct image_type_params *curr; for (curr = mkimage_tparams; curr != NULL; curr = curr->next) { if (curr->check_image_type) { if (!curr->check_image_type (type)) return curr; } } return NULL; } /* * mkimage_verify_print_header - * * It scans mkimage_tparams link list, * verifies image_header for each supported image type * if verification is successful, prints respective header * * returns negative if input image format does not match with any of * supported image types */ int mkimage_verify_print_header (void *ptr, struct stat *sbuf) { int retval = -1; struct image_type_params *curr; for (curr = mkimage_tparams; curr != NULL; curr = curr->next ) { if (curr->verify_header) { retval = curr->verify_header ( (unsigned char *)ptr, sbuf->st_size, ¶ms); if (retval == 0) { /* * Print the image information * if verify is successful */ if (curr->print_header) curr->print_header (ptr); else { fprintf (stderr, "%s: print_header undefined for %s ", params.cmdname, curr->name); } break; } } } return retval; } |
5b1d71372 Initial revision |
134 135 136 137 |
int main (int argc, char **argv) { |
9d25438fe [new uImage] Add ... |
138 |
int ifd = -1; |
5b1d71372 Initial revision |
139 |
struct stat sbuf; |
a2513e27e mkimage: Fix stri... |
140 |
char *ptr; |
449609f5b tools: mkimage: F... |
141 |
int retval = 0; |
89a4d6b12 tools: mkimage: s... |
142 |
struct image_type_params *tparams = NULL; |
9bac0bb37 tools: add variab... |
143 |
int pad_len = 0; |
5b1d71372 Initial revision |
144 |
|
f86ed6a8d tools: moved code... |
145 146 |
/* Init all image generation/list support */ register_image_tool(mkimage_register); |
5b1d71372 Initial revision |
147 |
|
89a4d6b12 tools: mkimage: s... |
148 149 |
params.cmdname = *argv; params.addr = params.ep = 0; |
5b1d71372 Initial revision |
150 151 152 153 154 |
while (--argc > 0 && **++argv == '-') { while (*++*argv) { switch (**argv) { case 'l': |
89a4d6b12 tools: mkimage: s... |
155 |
params.lflag = 1; |
5b1d71372 Initial revision |
156 157 158 |
break; case 'A': if ((--argc <= 0) || |
89a4d6b12 tools: mkimage: s... |
159 160 |
(params.arch = genimg_get_arch_id (*++argv)) < 0) |
5b1d71372 Initial revision |
161 162 |
usage (); goto NXTARG; |
4f6104270 mkimage: Add -c o... |
163 164 165 166 167 |
case 'c': if (--argc <= 0) usage(); params.comment = *++argv; goto NXTARG; |
5b1d71372 Initial revision |
168 169 |
case 'C': if ((--argc <= 0) || |
89a4d6b12 tools: mkimage: s... |
170 171 |
(params.comp = genimg_get_comp_id (*++argv)) < 0) |
5b1d71372 Initial revision |
172 173 |
usage (); goto NXTARG; |
9d25438fe [new uImage] Add ... |
174 175 176 |
case 'D': if (--argc <= 0) usage (); |
89a4d6b12 tools: mkimage: s... |
177 |
params.dtc = *++argv; |
9d25438fe [new uImage] Add ... |
178 |
goto NXTARG; |
5b1d71372 Initial revision |
179 180 |
case 'O': if ((--argc <= 0) || |
89a4d6b12 tools: mkimage: s... |
181 182 |
(params.os = genimg_get_os_id (*++argv)) < 0) |
5b1d71372 Initial revision |
183 184 185 186 |
usage (); goto NXTARG; case 'T': if ((--argc <= 0) || |
89a4d6b12 tools: mkimage: s... |
187 188 |
(params.type = genimg_get_type_id (*++argv)) < 0) |
5b1d71372 Initial revision |
189 190 191 192 193 194 |
usage (); goto NXTARG; case 'a': if (--argc <= 0) usage (); |
a2513e27e mkimage: Fix stri... |
195 |
params.addr = strtoul (*++argv, &ptr, 16); |
5b1d71372 Initial revision |
196 197 198 199 |
if (*ptr) { fprintf (stderr, "%s: invalid load address %s ", |
89a4d6b12 tools: mkimage: s... |
200 |
params.cmdname, *argv); |
5b1d71372 Initial revision |
201 202 203 204 205 206 |
exit (EXIT_FAILURE); } goto NXTARG; case 'd': if (--argc <= 0) usage (); |
89a4d6b12 tools: mkimage: s... |
207 208 |
params.datafile = *++argv; params.dflag = 1; |
5b1d71372 Initial revision |
209 210 211 212 |
goto NXTARG; case 'e': if (--argc <= 0) usage (); |
a2513e27e mkimage: Fix stri... |
213 |
params.ep = strtoul (*++argv, &ptr, 16); |
5b1d71372 Initial revision |
214 215 216 217 |
if (*ptr) { fprintf (stderr, "%s: invalid entry point %s ", |
89a4d6b12 tools: mkimage: s... |
218 |
params.cmdname, *argv); |
5b1d71372 Initial revision |
219 220 |
exit (EXIT_FAILURE); } |
89a4d6b12 tools: mkimage: s... |
221 |
params.eflag = 1; |
5b1d71372 Initial revision |
222 |
goto NXTARG; |
9d25438fe [new uImage] Add ... |
223 224 225 |
case 'f': if (--argc <= 0) usage (); |
95d77b447 mkimage: Add -F o... |
226 227 228 |
params.datafile = *++argv; /* no break */ case 'F': |
1a99de2cb tools/mkimage: As... |
229 230 231 232 233 |
/* * The flattened image tree (FIT) format * requires a flattened device tree image type */ params.type = IH_TYPE_FLATDT; |
fbc1c8f6f tools/mkimage: Re... |
234 |
params.fflag = 1; |
9d25438fe [new uImage] Add ... |
235 |
goto NXTARG; |
80e4df8ac mkimage: Add -k o... |
236 237 238 239 240 |
case 'k': if (--argc <= 0) usage(); params.keydir = *++argv; goto NXTARG; |
e29495d37 mkimage: Add -K t... |
241 242 243 244 245 |
case 'K': if (--argc <= 0) usage(); params.keydest = *++argv; goto NXTARG; |
5b1d71372 Initial revision |
246 247 248 |
case 'n': if (--argc <= 0) usage (); |
89a4d6b12 tools: mkimage: s... |
249 |
params.imagename = *++argv; |
5b1d71372 Initial revision |
250 |
goto NXTARG; |
399c744b2 mkimage: Add -r o... |
251 252 253 |
case 'r': params.require_keys = 1; break; |
5d898a00f powerpc/CoreNet: ... |
254 255 256 257 258 259 260 261 262 |
case 'R': if (--argc <= 0) usage(); /* * This entry is for the second configuration * file, if only one is not enough. */ params.imagename2 = *++argv; goto NXTARG; |
f0662105b mkimage: Add vari... |
263 264 265 |
case 's': params.skipcpy = 1; break; |
5b1d71372 Initial revision |
266 |
case 'v': |
89a4d6b12 tools: mkimage: s... |
267 |
params.vflag++; |
5b1d71372 Initial revision |
268 |
break; |
976b38c07 mkimage: add "-V"... |
269 270 271 272 |
case 'V': printf("mkimage version %s ", PLAIN_VERSION); exit(EXIT_SUCCESS); |
5b1d71372 Initial revision |
273 |
case 'x': |
89a4d6b12 tools: mkimage: s... |
274 |
params.xflag++; |
5b1d71372 Initial revision |
275 276 277 278 279 280 281 |
break; default: usage (); } } NXTARG: ; } |
89a4d6b12 tools: mkimage: s... |
282 283 284 285 286 287 288 289 290 291 292 |
if (argc != 1) usage (); /* set tparams as per input type_id */ tparams = mkimage_get_type(params.type); if (tparams == NULL) { fprintf (stderr, "%s: unsupported type %s ", params.cmdname, genimg_get_type_name(params.type)); exit (EXIT_FAILURE); } |
5b1d71372 Initial revision |
293 |
|
89a4d6b12 tools: mkimage: s... |
294 295 296 297 298 299 300 301 302 303 |
/* * check the passed arguments parameters meets the requirements * as per image type to be generated/listed */ if (tparams->check_params) if (tparams->check_params (¶ms)) usage (); if (!params.eflag) { params.ep = params.addr; |
5b1d71372 Initial revision |
304 |
/* If XIP, entry point must be after the U-Boot header */ |
89a4d6b12 tools: mkimage: s... |
305 306 |
if (params.xflag) params.ep += tparams->header_size; |
5b1d71372 Initial revision |
307 |
} |
89a4d6b12 tools: mkimage: s... |
308 |
params.imagefile = *argv; |
5b1d71372 Initial revision |
309 |
|
c81296c16 tools/mkimage: Pr... |
310 311 312 313 314 315 316 317 318 |
if (params.fflag){ if (tparams->fflag_handle) /* * in some cases, some additional processing needs * to be done if fflag is defined * * For ex. fit_handle_file for Fit file support */ retval = tparams->fflag_handle(¶ms); |
5b1d71372 Initial revision |
319 |
|
c81296c16 tools/mkimage: Pr... |
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
if (retval != EXIT_SUCCESS) exit (retval); } if (params.lflag || params.fflag) { ifd = open (params.imagefile, O_RDONLY|O_BINARY); } else { ifd = open (params.imagefile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0666); } if (ifd < 0) { fprintf (stderr, "%s: Can't open %s: %s ", params.cmdname, params.imagefile, strerror(errno)); exit (EXIT_FAILURE); |
5b1d71372 Initial revision |
337 |
} |
c81296c16 tools/mkimage: Pr... |
338 |
if (params.lflag || params.fflag) { |
5b1d71372 Initial revision |
339 340 341 342 343 344 |
/* * list header information of existing image */ if (fstat(ifd, &sbuf) < 0) { fprintf (stderr, "%s: Can't stat %s: %s ", |
89a4d6b12 tools: mkimage: s... |
345 346 |
params.cmdname, params.imagefile, strerror(errno)); |
5b1d71372 Initial revision |
347 348 |
exit (EXIT_FAILURE); } |
89a4d6b12 tools: mkimage: s... |
349 |
if ((unsigned)sbuf.st_size < tparams->header_size) { |
5b1d71372 Initial revision |
350 |
fprintf (stderr, |
89a4d6b12 tools: mkimage: s... |
351 352 353 |
"%s: Bad size: \"%s\" is not valid image ", params.cmdname, params.imagefile); |
5b1d71372 Initial revision |
354 355 |
exit (EXIT_FAILURE); } |
fa956fde6 mkimage: make mma... |
356 357 |
ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, ifd, 0); if (ptr == MAP_FAILED) { |
5b1d71372 Initial revision |
358 359 |
fprintf (stderr, "%s: Can't read %s: %s ", |
89a4d6b12 tools: mkimage: s... |
360 361 |
params.cmdname, params.imagefile, strerror(errno)); |
5b1d71372 Initial revision |
362 363 |
exit (EXIT_FAILURE); } |
89a4d6b12 tools: mkimage: s... |
364 365 366 367 368 369 370 |
/* * scan through mkimage registry for all supported image types * and verify the input image file header for match * Print the image information for matched image type * Returns the error code if not matched */ retval = mkimage_verify_print_header (ptr, &sbuf); |
5b1d71372 Initial revision |
371 |
|
5b1d71372 Initial revision |
372 373 |
(void) munmap((void *)ptr, sbuf.st_size); (void) close (ifd); |
f7644c0bf tools: mkimage : ... |
374 |
exit (retval); |
5b1d71372 Initial revision |
375 376 377 |
} /* |
f0662105b mkimage: Add vari... |
378 379 380 381 |
* In case there an header with a variable * length will be added, the corresponding * function is called. This is responsible to * allocate memory for the header itself. |
5b1d71372 Initial revision |
382 |
*/ |
f0662105b mkimage: Add vari... |
383 |
if (tparams->vrec_header) |
9bac0bb37 tools: add variab... |
384 |
pad_len = tparams->vrec_header(¶ms, tparams); |
f0662105b mkimage: Add vari... |
385 386 |
else memset(tparams->hdr, 0, tparams->header_size); |
5b1d71372 Initial revision |
387 |
|
89a4d6b12 tools: mkimage: s... |
388 389 |
if (write(ifd, tparams->hdr, tparams->header_size) != tparams->header_size) { |
5b1d71372 Initial revision |
390 391 |
fprintf (stderr, "%s: Write error on %s: %s ", |
89a4d6b12 tools: mkimage: s... |
392 |
params.cmdname, params.imagefile, strerror(errno)); |
5b1d71372 Initial revision |
393 394 |
exit (EXIT_FAILURE); } |
d1be8f922 mkimage: Fix vari... |
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
if (!params.skipcpy) { if (params.type == IH_TYPE_MULTI || params.type == IH_TYPE_SCRIPT) { char *file = params.datafile; uint32_t size; for (;;) { char *sep = NULL; if (file) { if ((sep = strchr(file, ':')) != NULL) { *sep = '\0'; } if (stat (file, &sbuf) < 0) { fprintf (stderr, "%s: Can't stat %s: %s ", params.cmdname, file, strerror(errno)); exit (EXIT_FAILURE); } size = cpu_to_uimage (sbuf.st_size); } else { size = 0; |
5b1d71372 Initial revision |
418 |
} |
d1be8f922 mkimage: Fix vari... |
419 420 421 422 423 |
if (write(ifd, (char *)&size, sizeof(size)) != sizeof(size)) { fprintf (stderr, "%s: Write error on %s: %s ", params.cmdname, params.imagefile, strerror(errno)); |
5b1d71372 Initial revision |
424 425 |
exit (EXIT_FAILURE); } |
5b1d71372 Initial revision |
426 |
|
d1be8f922 mkimage: Fix vari... |
427 428 429 |
if (!file) { break; } |
5b1d71372 Initial revision |
430 |
|
d1be8f922 mkimage: Fix vari... |
431 432 433 434 435 436 |
if (sep) { *sep = ':'; file = sep + 1; } else { file = NULL; } |
5b1d71372 Initial revision |
437 |
} |
d1be8f922 mkimage: Fix vari... |
438 |
file = params.datafile; |
5b1d71372 Initial revision |
439 |
|
d1be8f922 mkimage: Fix vari... |
440 441 442 443 444 445 446 447 448 449 450 |
for (;;) { char *sep = strchr(file, ':'); if (sep) { *sep = '\0'; copy_file (ifd, file, 1); *sep++ = ':'; file = sep; } else { copy_file (ifd, file, 0); break; } |
5b1d71372 Initial revision |
451 |
} |
5d898a00f powerpc/CoreNet: ... |
452 453 454 |
} else if (params.type == IH_TYPE_PBLIMAGE) { /* PBL has special Image format, implements its' own */ pbl_load_uboot(ifd, ¶ms); |
d1be8f922 mkimage: Fix vari... |
455 |
} else { |
9bac0bb37 tools: add variab... |
456 |
copy_file(ifd, params.datafile, pad_len); |
5b1d71372 Initial revision |
457 |
} |
5b1d71372 Initial revision |
458 459 460 |
} /* We're a bit of paranoid */ |
89a4d6b12 tools: mkimage: s... |
461 462 463 464 |
#if defined(_POSIX_SYNCHRONIZED_IO) && \ !defined(__sun__) && \ !defined(__FreeBSD__) && \ !defined(__APPLE__) |
5b1d71372 Initial revision |
465 466 467 468 469 470 471 472 |
(void) fdatasync (ifd); #else (void) fsync (ifd); #endif if (fstat(ifd, &sbuf) < 0) { fprintf (stderr, "%s: Can't stat %s: %s ", |
89a4d6b12 tools: mkimage: s... |
473 |
params.cmdname, params.imagefile, strerror(errno)); |
5b1d71372 Initial revision |
474 475 |
exit (EXIT_FAILURE); } |
fa956fde6 mkimage: make mma... |
476 477 |
ptr = mmap(0, sbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, ifd, 0); if (ptr == MAP_FAILED) { |
5b1d71372 Initial revision |
478 479 |
fprintf (stderr, "%s: Can't map %s: %s ", |
89a4d6b12 tools: mkimage: s... |
480 |
params.cmdname, params.imagefile, strerror(errno)); |
5b1d71372 Initial revision |
481 482 |
exit (EXIT_FAILURE); } |
89a4d6b12 tools: mkimage: s... |
483 484 485 486 487 488 489 490 491 |
/* Setup the image header as per input image type*/ if (tparams->set_header) tparams->set_header (ptr, &sbuf, ifd, ¶ms); else { fprintf (stderr, "%s: Can't set header for %s: %s ", params.cmdname, tparams->name, strerror(errno)); exit (EXIT_FAILURE); } |
5b1d71372 Initial revision |
492 |
|
89a4d6b12 tools: mkimage: s... |
493 494 495 496 497 498 499 500 501 |
/* Print the image information by processing image header */ if (tparams->print_header) tparams->print_header (ptr); else { fprintf (stderr, "%s: Can't print header for %s: %s ", params.cmdname, tparams->name, strerror(errno)); exit (EXIT_FAILURE); } |
5b1d71372 Initial revision |
502 503 504 505 |
(void) munmap((void *)ptr, sbuf.st_size); /* We're a bit of paranoid */ |
89a4d6b12 tools: mkimage: s... |
506 507 508 509 |
#if defined(_POSIX_SYNCHRONIZED_IO) && \ !defined(__sun__) && \ !defined(__FreeBSD__) && \ !defined(__APPLE__) |
5b1d71372 Initial revision |
510 511 512 513 514 515 516 517 |
(void) fdatasync (ifd); #else (void) fsync (ifd); #endif if (close(ifd)) { fprintf (stderr, "%s: Write error on %s: %s ", |
89a4d6b12 tools: mkimage: s... |
518 |
params.cmdname, params.imagefile, strerror(errno)); |
5b1d71372 Initial revision |
519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
exit (EXIT_FAILURE); } exit (EXIT_SUCCESS); } static void copy_file (int ifd, const char *datafile, int pad) { int dfd; struct stat sbuf; unsigned char *ptr; int tail; int zero = 0; |
9bac0bb37 tools: add variab... |
533 |
uint8_t zeros[4096]; |
5b1d71372 Initial revision |
534 535 |
int offset = 0; int size; |
89a4d6b12 tools: mkimage: s... |
536 |
struct image_type_params *tparams = mkimage_get_type (params.type); |
5b1d71372 Initial revision |
537 |
|
9bac0bb37 tools: add variab... |
538 539 540 541 542 543 544 545 |
if (pad >= sizeof(zeros)) { fprintf(stderr, "%s: Can't pad to %d ", params.cmdname, pad); exit(EXIT_FAILURE); } memset(zeros, 0, sizeof(zeros)); |
89a4d6b12 tools: mkimage: s... |
546 |
if (params.vflag) { |
5b1d71372 Initial revision |
547 548 549 |
fprintf (stderr, "Adding Image %s ", datafile); } |
ef1464cc0 * Patch by Anders... |
550 |
if ((dfd = open(datafile, O_RDONLY|O_BINARY)) < 0) { |
5b1d71372 Initial revision |
551 552 |
fprintf (stderr, "%s: Can't open %s: %s ", |
89a4d6b12 tools: mkimage: s... |
553 |
params.cmdname, datafile, strerror(errno)); |
5b1d71372 Initial revision |
554 555 556 557 558 559 |
exit (EXIT_FAILURE); } if (fstat(dfd, &sbuf) < 0) { fprintf (stderr, "%s: Can't stat %s: %s ", |
89a4d6b12 tools: mkimage: s... |
560 |
params.cmdname, datafile, strerror(errno)); |
5b1d71372 Initial revision |
561 562 |
exit (EXIT_FAILURE); } |
fa956fde6 mkimage: make mma... |
563 564 |
ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0); if (ptr == MAP_FAILED) { |
5b1d71372 Initial revision |
565 566 |
fprintf (stderr, "%s: Can't read %s: %s ", |
89a4d6b12 tools: mkimage: s... |
567 |
params.cmdname, datafile, strerror(errno)); |
5b1d71372 Initial revision |
568 569 |
exit (EXIT_FAILURE); } |
89a4d6b12 tools: mkimage: s... |
570 |
if (params.xflag) { |
5b1d71372 Initial revision |
571 572 573 574 575 576 |
unsigned char *p = NULL; /* * XIP: do not append the image_header_t at the * beginning of the file, but consume the space * reserved for it. */ |
89a4d6b12 tools: mkimage: s... |
577 |
if ((unsigned)sbuf.st_size < tparams->header_size) { |
5b1d71372 Initial revision |
578 579 580 |
fprintf (stderr, "%s: Bad size: \"%s\" is too small for XIP ", |
89a4d6b12 tools: mkimage: s... |
581 |
params.cmdname, datafile); |
5b1d71372 Initial revision |
582 583 |
exit (EXIT_FAILURE); } |
89a4d6b12 tools: mkimage: s... |
584 |
for (p = ptr; p < ptr + tparams->header_size; p++) { |
5b1d71372 Initial revision |
585 586 587 588 |
if ( *p != 0xff ) { fprintf (stderr, "%s: Bad file: \"%s\" has invalid buffer for XIP ", |
89a4d6b12 tools: mkimage: s... |
589 |
params.cmdname, datafile); |
5b1d71372 Initial revision |
590 591 592 |
exit (EXIT_FAILURE); } } |
89a4d6b12 tools: mkimage: s... |
593 |
offset = tparams->header_size; |
5b1d71372 Initial revision |
594 595 596 597 598 599 |
} size = sbuf.st_size - offset; if (write(ifd, ptr + offset, size) != size) { fprintf (stderr, "%s: Write error on %s: %s ", |
89a4d6b12 tools: mkimage: s... |
600 |
params.cmdname, params.imagefile, strerror(errno)); |
5b1d71372 Initial revision |
601 602 |
exit (EXIT_FAILURE); } |
9bac0bb37 tools: add variab... |
603 604 |
tail = size % 4; if ((pad == 1) && (tail != 0)) { |
5b1d71372 Initial revision |
605 606 607 608 |
if (write(ifd, (char *)&zero, 4-tail) != 4-tail) { fprintf (stderr, "%s: Write error on %s: %s ", |
89a4d6b12 tools: mkimage: s... |
609 610 |
params.cmdname, params.imagefile, strerror(errno)); |
5b1d71372 Initial revision |
611 612 |
exit (EXIT_FAILURE); } |
9bac0bb37 tools: add variab... |
613 614 615 616 617 618 619 620 |
} else if (pad > 1) { if (write(ifd, (char *)&zeros, pad) != pad) { fprintf(stderr, "%s: Write error on %s: %s ", params.cmdname, params.imagefile, strerror(errno)); exit(EXIT_FAILURE); } |
5b1d71372 Initial revision |
621 622 623 624 625 |
} (void) munmap((void *)ptr, sbuf.st_size); (void) close (dfd); } |
f1cc458cf mkimage: added 's... |
626 |
static void usage(void) |
5b1d71372 Initial revision |
627 628 629 |
{ fprintf (stderr, "Usage: %s -l image " |
9d25438fe [new uImage] Add ... |
630 631 |
" -l ==> list image header information ", |
89a4d6b12 tools: mkimage: s... |
632 |
params.cmdname); |
9d25438fe [new uImage] Add ... |
633 634 635 636 637 |
fprintf (stderr, " %s [-x] -A arch -O os -T type -C comp " "-a addr -e ep -n name -d data_file[:data_file...] image " " -A ==> set architecture to 'arch' " |
5b1d71372 Initial revision |
638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
" -O ==> set operating system to 'os' " " -T ==> set image type to 'type' " " -C ==> set compression type 'comp' " " -a ==> set load address to 'addr' (hex) " " -e ==> set entry point to 'ep' (hex) " " -n ==> set image name to 'name' " " -d ==> use image data from 'datafile' " |
9d25438fe [new uImage] Add ... |
652 653 |
" -x ==> set XIP (execute in place) ", |
89a4d6b12 tools: mkimage: s... |
654 |
params.cmdname); |
95d77b447 mkimage: Add -F o... |
655 656 |
fprintf(stderr, " %s [-D dtc_options] [-f fit-image.its|-F] fit-image ", |
89a4d6b12 tools: mkimage: s... |
657 |
params.cmdname); |
80e4df8ac mkimage: Add -k o... |
658 659 660 661 662 |
fprintf(stderr, " -D => set options for device tree compiler " " -f => input filename for FIT source "); #ifdef CONFIG_FIT_SIGNATURE |
399c744b2 mkimage: Add -r o... |
663 664 |
fprintf(stderr, "Signing / verified boot options: [-k keydir] [-K dtb] [ -c <comment>] [-r] " |
e29495d37 mkimage: Add -K t... |
665 666 |
" -k => set directory containing private keys " |
95d77b447 mkimage: Add -F o... |
667 668 |
" -K => write public keys to this .dtb file " |
4f6104270 mkimage: Add -c o... |
669 670 |
" -c => add comment in signature node " |
399c744b2 mkimage: Add -r o... |
671 672 673 674 |
" -F => re-sign existing FIT image " " -r => mark keys used as 'required' in dtb "); |
80e4df8ac mkimage: Add -k o... |
675 676 677 678 |
#else fprintf(stderr, "Signing / verified boot not supported (CONFIG_FIT_SIGNATURE undefined) "); #endif |
976b38c07 mkimage: add "-V"... |
679 680 681 |
fprintf (stderr, " %s -V ==> print version information and exit ", params.cmdname); |
9d25438fe [new uImage] Add ... |
682 |
|
5b1d71372 Initial revision |
683 684 |
exit (EXIT_FAILURE); } |