X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=tools%2Fmkimage.c;h=eeb1b106682e3dc71068d5759105ed2c7a75dbd9;hb=5c23712dbdeeaef84ee28a18dc23abd479a95ede;hp=c43b20772694e9d78c880001c4187d2e32d8aaca;hpb=c7138920b85ac05c7601105dd9961142995191cf;p=karo-tx-uboot.git diff --git a/tools/mkimage.c b/tools/mkimage.c index c43b207726..eeb1b10668 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -23,6 +23,7 @@ #include "mkimage.h" #include +#include static void copy_file(int, const char *, int); static void usage(void); @@ -37,6 +38,7 @@ struct mkimage_params params = { .type = IH_TYPE_KERNEL, .comp = IH_COMP_GZIP, .dtc = MKIMAGE_DEFAULT_DTC_OPTIONS, + .imagename = "", }; /* @@ -144,14 +146,24 @@ main (int argc, char **argv) { int ifd = -1; struct stat sbuf; - unsigned char *ptr; + char *ptr; int retval = 0; struct image_type_params *tparams = NULL; + /* Init Kirkwood Boot image generation/list support */ + init_kwb_image_type (); + /* Init Freescale imx Boot image generation/list support */ + init_imx_image_type (); /* Init FIT image generation/list support */ init_fit_image_type (); + /* Init TI OMAP Boot image generation/list support */ + init_omap_image_type(); /* Init Default image generation/list support */ init_default_image_type (); + /* Init Davinci UBL support */ + init_ubl_image_type(); + /* Init Davinci AIS support */ + init_ais_image_type(); params.cmdname = *argv; params.addr = params.ep = 0; @@ -196,8 +208,7 @@ main (int argc, char **argv) case 'a': if (--argc <= 0) usage (); - params.addr = strtoul (*++argv, - (char **)&ptr, 16); + params.addr = strtoul (*++argv, &ptr, 16); if (*ptr) { fprintf (stderr, "%s: invalid load address %s\n", @@ -214,8 +225,7 @@ main (int argc, char **argv) case 'e': if (--argc <= 0) usage (); - params.ep = strtoul (*++argv, - (char **)&ptr, 16); + params.ep = strtoul (*++argv, &ptr, 16); if (*ptr) { fprintf (stderr, "%s: invalid entry point %s\n", @@ -227,6 +237,11 @@ main (int argc, char **argv) case 'f': if (--argc <= 0) usage (); + /* + * The flattened image tree (FIT) format + * requires a flattened device tree image type + */ + params.type = IH_TYPE_FLATDT; params.datafile = *++argv; params.fflag = 1; goto NXTARG; @@ -235,9 +250,15 @@ main (int argc, char **argv) usage (); params.imagename = *++argv; goto NXTARG; + case 's': + params.skipcpy = 1; + break; case 'v': params.vflag++; break; + case 'V': + printf("mkimage version %s\n", PLAIN_VERSION); + exit(EXIT_SUCCESS); case 'x': params.xflag++; break; @@ -274,39 +295,37 @@ NXTARG: ; params.ep += tparams->header_size; } - /* - * If XIP, ensure the entry point is equal to the load address plus - * the size of the U-Boot header. - */ - if (params.xflag) { - if (params.ep != params.addr + tparams->header_size) { - fprintf (stderr, - "%s: For XIP, the entry point must be the load addr + %lu\n", - params.cmdname, - (unsigned long)tparams->header_size); - exit (EXIT_FAILURE); - } - } - params.imagefile = *argv; - if (!params.fflag){ - if (params.lflag) { - ifd = open (params.imagefile, O_RDONLY|O_BINARY); - } else { - ifd = open (params.imagefile, - O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0666); - } + 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); - if (ifd < 0) { - fprintf (stderr, "%s: Can't open %s: %s\n", - params.cmdname, params.imagefile, - strerror(errno)); - exit (EXIT_FAILURE); - } + 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\n", + params.cmdname, params.imagefile, + strerror(errno)); + exit (EXIT_FAILURE); } - if (params.lflag) { + if (params.lflag || params.fflag) { /* * list header information of existing image */ @@ -343,26 +362,19 @@ NXTARG: ; (void) munmap((void *)ptr, sbuf.st_size); (void) close (ifd); - exit (retval); - } else 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); - exit (retval); } /* - * Must be -w then: - * - * write dummy header, to be fixed later + * 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. */ - memset (tparams->hdr, 0, tparams->header_size); + if (tparams->vrec_header) + tparams->vrec_header(¶ms, tparams); + else + memset(tparams->hdr, 0, tparams->header_size); if (write(ifd, tparams->hdr, tparams->header_size) != tparams->header_size) { @@ -371,63 +383,66 @@ NXTARG: ; exit (EXIT_FAILURE); } - 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 (!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\n", + params.cmdname, file, strerror(errno)); + exit (EXIT_FAILURE); + } + size = cpu_to_uimage (sbuf.st_size); + } else { + size = 0; } - if (stat (file, &sbuf) < 0) { - fprintf (stderr, "%s: Can't stat %s: %s\n", - params.cmdname, file, strerror(errno)); + if (write(ifd, (char *)&size, sizeof(size)) != sizeof(size)) { + fprintf (stderr, "%s: Write error on %s: %s\n", + params.cmdname, params.imagefile, + strerror(errno)); exit (EXIT_FAILURE); } - size = cpu_to_uimage (sbuf.st_size); - } else { - size = 0; - } - if (write(ifd, (char *)&size, sizeof(size)) != sizeof(size)) { - fprintf (stderr, "%s: Write error on %s: %s\n", - params.cmdname, params.imagefile, - strerror(errno)); - exit (EXIT_FAILURE); - } + if (!file) { + break; + } - if (!file) { - break; + if (sep) { + *sep = ':'; + file = sep + 1; + } else { + file = NULL; + } } - if (sep) { - *sep = ':'; - file = sep + 1; - } else { - file = NULL; - } - } + file = params.datafile; - file = params.datafile; - - for (;;) { - char *sep = strchr(file, ':'); - if (sep) { - *sep = '\0'; - copy_file (ifd, file, 1); - *sep++ = ':'; - file = sep; - } else { - copy_file (ifd, file, 0); - break; + for (;;) { + char *sep = strchr(file, ':'); + if (sep) { + *sep = '\0'; + copy_file (ifd, file, 1); + *sep++ = ':'; + file = sep; + } else { + copy_file (ifd, file, 0); + break; + } } + } else { + copy_file (ifd, params.datafile, 0); } - } else { - copy_file (ifd, params.datafile, 0); } /* We're a bit of paranoid */ @@ -595,6 +610,8 @@ usage () params.cmdname); fprintf (stderr, " %s [-D dtc_options] -f fit-image.its fit-image\n", params.cmdname); + fprintf (stderr, " %s -V ==> print version information and exit\n", + params.cmdname); exit (EXIT_FAILURE); }