[PATCH 00/21] mkimage: Start to tidy up mkimage and friends

The current mkimage code is a bit messy: - the main() function is very long - two similarly named structs are used throughout: the first (struct image_tool_params) is not actually just parameters, the second (struct image_type_params) is confusingly similar - quite a bit of FIT processing happens right at the start of main(), which can be hard to follow - the program calls exit() from many different places This series renames the main structures, avoiding using the common 'params' word. It breaks up part of main() into separate functions and starts the process of exiting in one place. It also reverts a patch which causes an invalid 'loadables' property to be added with '-f auto'. More remains to be done, but this is a start. Simon Glass (21): mkimage: Move copy_file() higher in the file mkimage: Move code from main() to a new function mkimage: Return the exist code from run_mkimage() mkimage: Update usage() to return a value mkimage: Rename struct image_type_params to imgtool_funcs mkimage: Return struct image_tool_params to struct imgtool mkimage: Use a consistent parameter for struct imgtool * mkimage: Pass struct imgtool out from main() mkimage: Update add_content() to take an imgtool parameter mkimage: Update process_args() to take an imgtool parameter mkimage: Update verify_image() to take an imgtool parameter mkimage: Update copy_file() etc. to take an imgtool parameter mkimage: Update run_mkimage() to take an imgtool parameter mkimage: Drop the global for struct imgtool mkimage: Update process_args() to return a value always mkimage: Update verify_image() to return a value always mkimage: Update copy_file() et al to return a value always mkimage: Split out initial checking and processing mkimage: Split out file-opening into its own function mkimage: Move the list-or-process code into a function Revert "tools: fit_image: Add the loadable property to configs" tools/aisimage.c | 57 ++- tools/atmelimage.c | 27 +- tools/default_image.c | 54 +-- tools/dumpimage.c | 8 +- tools/fit_common.c | 5 +- tools/fit_common.h | 7 +- tools/fit_image.c | 239 ++++++----- tools/gpheader.h | 2 +- tools/gpimage-common.c | 8 +- tools/gpimage.c | 8 +- tools/imagetool.c | 56 +-- tools/imagetool.h | 67 ++- tools/imx8image.c | 12 +- tools/imx8mimage.c | 8 +- tools/imximage.c | 41 +- tools/kwbimage.c | 164 +++---- tools/lpc32xximage.c | 6 +- tools/mkimage.c | 869 +++++++++++++++++++++----------------- tools/mtk_image.c | 26 +- tools/mxsimage.c | 37 +- tools/omapimage.c | 11 +- tools/pblimage.c | 40 +- tools/renesas_spkgimage.c | 35 +- tools/rkcommon.c | 109 +++-- tools/rkcommon.h | 20 +- tools/rkimage.c | 8 +- tools/rkspi.c | 17 +- tools/sfspl.c | 25 +- tools/socfpgaimage.c | 66 ++- tools/stm32image.c | 10 +- tools/sunxi_egon.c | 37 +- tools/sunxi_toc0.c | 29 +- tools/ublimage.c | 24 +- tools/vybridimage.c | 6 +- tools/zynqimage.c | 24 +- tools/zynqmpbif.c | 14 +- tools/zynqmpimage.c | 42 +- tools/zynqmpimage.h | 2 +- 38 files changed, 1138 insertions(+), 1082 deletions(-) -- 2.43.0 base-commit: 816236b75e1b9248d282fb81e0c77426add8385a branch: loadd

It is confusing to have the main program in the moddle of the mkimage.c file. Move copy_file() higher, so that main() is at the bottom. Drop the now-unnecessary forward declaration. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 233 ++++++++++++++++++++++++------------------------ 1 file changed, 115 insertions(+), 118 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 2954626a283..385581b5078 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -18,8 +18,6 @@ #include <sys/ioctl.h> #endif -static void copy_file(int, const char *, int); - /* parameters initialized by core will be used by the image type code */ static struct image_tool_params params = { .os = IH_OS_LINUX, @@ -445,6 +443,121 @@ static void verify_image(const struct image_type_params *tparams) (void)close(ifd); } +static void copy_file(int ifd, const char *datafile, int pad) +{ + int dfd; + struct stat sbuf; + unsigned char *ptr; + int tail; + int zero = 0; + uint8_t zeros[4096]; + int offset = 0; + int size, ret; + struct image_type_params *tparams = imagetool_get_type(params.type); + + memset(zeros, 0, sizeof(zeros)); + + if (params.vflag) + fprintf(stderr, "Adding Image %s\n", datafile); + + dfd = open(datafile, O_RDONLY | O_BINARY); + if (dfd < 0) { + fprintf(stderr, "%s: Can't open %s: %s\n", + params.cmdname, datafile, strerror(errno)); + exit (EXIT_FAILURE); + } + + if (fstat(dfd, &sbuf) < 0) { + fprintf(stderr, "%s: Can't stat %s: %s\n", + params.cmdname, datafile, strerror(errno)); + exit (EXIT_FAILURE); + } + + if (sbuf.st_size == 0) { + fprintf(stderr, "%s: Input file %s is empty, bailing out\n", + params.cmdname, datafile); + exit (EXIT_FAILURE); + } + + ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0); + if (ptr == MAP_FAILED) { + fprintf(stderr, "%s: Can't read %s: %s\n", + params.cmdname, datafile, strerror(errno)); + exit (EXIT_FAILURE); + } + + if (params.xflag && + ((params.type > IH_TYPE_INVALID && params.type < IH_TYPE_FLATDT) || + params.type == IH_TYPE_KERNEL_NOLOAD || + params.type == IH_TYPE_FIRMWARE_IVT)) { + unsigned char *p = NULL; + /* + * XIP: do not append the struct legacy_img_hdr at the + * beginning of the file, but consume the space + * reserved for it. + */ + + if ((unsigned int)sbuf.st_size < tparams->header_size) { + fprintf(stderr, + "%s: Bad size: \"%s\" is too small for XIP\n", + params.cmdname, datafile); + exit (EXIT_FAILURE); + } + + for (p = ptr; p < ptr + tparams->header_size; p++) { + if (*p != 0xff) { + fprintf(stderr, + "%s: Bad file: \"%s\" has invalid buffer for XIP\n", + params.cmdname, datafile); + exit (EXIT_FAILURE); + } + } + + offset = tparams->header_size; + } + + size = sbuf.st_size - offset; + + ret = write(ifd, ptr + offset, size); + if (ret != size) { + if (ret < 0) + fprintf(stderr, "%s: Write error on %s: %s\n", + params.cmdname, params.imagefile, strerror(errno)); + else if (ret < size) + fprintf(stderr, "%s: Write only %d/%d bytes, " + "probably no space left on the device\n", + params.cmdname, ret, size); + exit (EXIT_FAILURE); + } + + tail = size % 4; + if (pad == 1 && tail != 0) { + if (write(ifd, (char *)&zero, 4 - tail) != 4 - tail) { + fprintf(stderr, "%s: Write error on %s: %s\n", + params.cmdname, params.imagefile, + strerror(errno)); + exit (EXIT_FAILURE); + } + } else if (pad > 1) { + while (pad > 0) { + int todo = sizeof(zeros); + + if (todo > pad) + todo = pad; + if (write(ifd, (char *)&zeros, todo) != todo) { + fprintf(stderr, "%s: Write error on %s: %s\n", + params.cmdname, params.imagefile, + strerror(errno)); + exit(EXIT_FAILURE); + } + pad -= todo; + } + } + + (void)munmap((void *)ptr, sbuf.st_size); + (void)close(dfd); +} + void copy_datafile(int ifd, char *file) { if (!file) @@ -822,119 +935,3 @@ int main(int argc, char **argv) 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; - uint8_t zeros[4096]; - int offset = 0; - int size, ret; - struct image_type_params *tparams = imagetool_get_type(params.type); - - memset(zeros, 0, sizeof(zeros)); - - if (params.vflag) { - fprintf (stderr, "Adding Image %s\n", datafile); - } - - if ((dfd = open(datafile, O_RDONLY|O_BINARY)) < 0) { - fprintf (stderr, "%s: Can't open %s: %s\n", - params.cmdname, datafile, strerror(errno)); - exit (EXIT_FAILURE); - } - - if (fstat(dfd, &sbuf) < 0) { - fprintf (stderr, "%s: Can't stat %s: %s\n", - params.cmdname, datafile, strerror(errno)); - exit (EXIT_FAILURE); - } - - if (sbuf.st_size == 0) { - fprintf (stderr, "%s: Input file %s is empty, bailing out\n", - params.cmdname, datafile); - exit (EXIT_FAILURE); - } - - ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0); - if (ptr == MAP_FAILED) { - fprintf (stderr, "%s: Can't read %s: %s\n", - params.cmdname, datafile, strerror(errno)); - exit (EXIT_FAILURE); - } - - if (params.xflag && - (((params.type > IH_TYPE_INVALID) && (params.type < IH_TYPE_FLATDT)) || - (params.type == IH_TYPE_KERNEL_NOLOAD) || (params.type == IH_TYPE_FIRMWARE_IVT))) { - unsigned char *p = NULL; - /* - * XIP: do not append the struct legacy_img_hdr at the - * beginning of the file, but consume the space - * reserved for it. - */ - - if ((unsigned)sbuf.st_size < tparams->header_size) { - fprintf (stderr, - "%s: Bad size: \"%s\" is too small for XIP\n", - params.cmdname, datafile); - exit (EXIT_FAILURE); - } - - for (p = ptr; p < ptr + tparams->header_size; p++) { - if ( *p != 0xff ) { - fprintf (stderr, - "%s: Bad file: \"%s\" has invalid buffer for XIP\n", - params.cmdname, datafile); - exit (EXIT_FAILURE); - } - } - - offset = tparams->header_size; - } - - size = sbuf.st_size - offset; - - ret = write(ifd, ptr + offset, size); - if (ret != size) { - if (ret < 0) - fprintf (stderr, "%s: Write error on %s: %s\n", - params.cmdname, params.imagefile, strerror(errno)); - else if (ret < size) - fprintf (stderr, "%s: Write only %d/%d bytes, "\ - "probably no space left on the device\n", - params.cmdname, ret, size); - exit (EXIT_FAILURE); - } - - tail = size % 4; - if ((pad == 1) && (tail != 0)) { - - if (write(ifd, (char *)&zero, 4-tail) != 4-tail) { - fprintf (stderr, "%s: Write error on %s: %s\n", - params.cmdname, params.imagefile, - strerror(errno)); - exit (EXIT_FAILURE); - } - } else if (pad > 1) { - while (pad > 0) { - int todo = sizeof(zeros); - - if (todo > pad) - todo = pad; - if (write(ifd, (char *)&zeros, todo) != todo) { - fprintf(stderr, "%s: Write error on %s: %s\n", - params.cmdname, params.imagefile, - strerror(errno)); - exit(EXIT_FAILURE); - } - pad -= todo; - } - } - - (void) munmap((void *)ptr, sbuf.st_size); - (void) close (dfd); -} -- 2.43.0

Create a new run_mkimage() function which will hold the top-level logic for mkimage. For the few cases where there is a 'return', use that as the exit code of the problem, preserving existing behaviour. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 385581b5078..0f432a20cfb 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -577,22 +577,23 @@ void copy_datafile(int ifd, char *file) } } -int main(int argc, char **argv) +/** + * run_mkimage() - Run the mkimage tool + * + * The program arguments are in params + * + * Return: 0 on success, or non-zero exit code + */ +static int run_mkimage(void) { - int ifd = -1; - struct stat sbuf; - char *ptr; - int retval = 0; struct image_type_params *tparams = NULL; + struct stat sbuf; int pad_len = 0; - int dfd; + int retval = 0; size_t map_len; - - params.cmdname = *argv; - params.addr = 0; - params.ep = 0; - - process_args(argc, argv); + int ifd = -1; + char *ptr; + int dfd; /* set tparams as per input type_id */ tparams = imagetool_get_type(params.type); @@ -935,3 +936,18 @@ int main(int argc, char **argv) exit (EXIT_SUCCESS); } + +int main(int argc, char **argv) +{ + int ret; + + params.cmdname = *argv; + params.addr = 0; + params.ep = 0; + + process_args(argc, argv); + + ret = run_mkimage(); + + return ret; +} -- 2.43.0

Rather than exiting in the middle of the function, return the exit code to main() so it can return it, in turn. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 0f432a20cfb..a8073485180 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -600,7 +600,7 @@ static int run_mkimage(void) if (tparams == NULL && !params.lflag) { fprintf (stderr, "%s: unsupported type %s\n", params.cmdname, genimg_get_type_name(params.type)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } /* @@ -622,7 +622,7 @@ static int run_mkimage(void) if (!tparams) { fprintf(stderr, "%s: Missing FIT support\n", params.cmdname); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } if (tparams->fflag_handle) /* @@ -648,7 +648,7 @@ static int run_mkimage(void) fprintf (stderr, "%s: Can't open %s: %s\n", params.cmdname, params.imagefile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } if (params.lflag || params.fflag) { @@ -660,7 +660,7 @@ static int run_mkimage(void) fprintf (stderr, "%s: Can't stat %s: %s\n", params.cmdname, params.imagefile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } if ((sbuf.st_mode & S_IFMT) == S_IFBLK) { @@ -672,13 +672,13 @@ static int run_mkimage(void) fprintf (stderr, "%s: failed to get size of block device \"%s\"\n", params.cmdname, params.imagefile); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } #else fprintf (stderr, "%s: \"%s\" is block device, don't know how to get its size\n", params.cmdname, params.imagefile); - exit (EXIT_FAILURE); + return EXIT_FAILURE; #endif } else if (tparams && sbuf.st_size < (off_t)tparams->header_size) { fprintf (stderr, @@ -686,7 +686,7 @@ static int run_mkimage(void) params.cmdname, params.imagefile, (unsigned long long) sbuf.st_size, tparams->header_size); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } else { size = sbuf.st_size; } @@ -696,7 +696,7 @@ static int run_mkimage(void) fprintf (stderr, "%s: Can't read %s: %s\n", params.cmdname, params.imagefile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } /* @@ -712,28 +712,28 @@ static int run_mkimage(void) summary_show(¶ms.summary, params.imagefile, params.keydest); - exit (retval); + return retval; } if (!params.skipcpy && params.type != IH_TYPE_MULTI && params.type != IH_TYPE_SCRIPT) { if (!params.datafile) { fprintf(stderr, "%s: Option -d with image data file was not specified\n", params.cmdname); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } dfd = open(params.datafile, O_RDONLY | O_BINARY); if (dfd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", params.cmdname, params.datafile, strerror(errno)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (fstat(dfd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", params.cmdname, params.datafile, strerror(errno)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } params.file_size = sbuf.st_size + tparams->header_size; @@ -755,7 +755,7 @@ static int run_mkimage(void) != tparams->header_size) { fprintf (stderr, "%s: Write error on %s: %s\n", params.cmdname, params.imagefile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } if (!params.skipcpy) { @@ -775,7 +775,7 @@ static int run_mkimage(void) if (stat (file, &sbuf) < 0) { fprintf (stderr, "%s: Can't stat %s: %s\n", params.cmdname, file, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } size = cpu_to_uimage (sbuf.st_size); } else { @@ -786,7 +786,7 @@ static int run_mkimage(void) fprintf (stderr, "%s: Write error on %s: %s\n", params.cmdname, params.imagefile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } if (!file) { @@ -855,7 +855,7 @@ static int run_mkimage(void) params.cmdname, params.imagefile, strerror(errno)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } if (write(ifd, &ivt_header, sizeof(flash_header_v2_t)) @@ -864,7 +864,7 @@ static int run_mkimage(void) params.cmdname, params.imagefile, strerror(errno)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } } @@ -883,7 +883,7 @@ static int run_mkimage(void) if (fstat(ifd, &sbuf) < 0) { fprintf (stderr, "%s: Can't stat %s: %s\n", params.cmdname, params.imagefile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } params.file_size = sbuf.st_size; @@ -892,7 +892,7 @@ static int run_mkimage(void) if (ptr == MAP_FAILED) { fprintf (stderr, "%s: Can't map %s: %s\n", params.cmdname, params.imagefile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } /* Setup the image header as per input image type*/ @@ -901,7 +901,7 @@ static int run_mkimage(void) else { fprintf (stderr, "%s: Can't set header for %s\n", params.cmdname, tparams->name); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } /* Print the image information by processing image header */ @@ -928,13 +928,13 @@ static int run_mkimage(void) if (close(ifd)) { fprintf (stderr, "%s: Write error on %s: %s\n", params.cmdname, params.imagefile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } if (tparams->verify_header) verify_image(tparams); - exit (EXIT_SUCCESS); + return 0; } int main(int argc, char **argv) -- 2.43.0

Rather than exiting in this function, return an exit code. The caller is then responsible for returning it, so update all the callers to return the value. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index a8073485180..8a132362a5b 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -78,7 +78,13 @@ static int show_valid_options(enum ih_category category) return 0; } -static void usage(const char *msg) +/** + * usage() - Print a usage message + * + * Return: + * EXIT_FAILURE (always) + */ +static int usage(const char *msg) { fprintf(stderr, "Error: %s\n", msg); fprintf(stderr, "Usage: %s [-T type] -l image\n" @@ -136,7 +142,7 @@ static void usage(const char *msg) fprintf(stderr, "Use '-T list' to see a list of available image types\n"); fprintf(stderr, "Long options are available; read the man page for details\n"); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } static int add_content(int type, const char *fname) @@ -197,7 +203,7 @@ static const struct option longopts[] = { { /* sentinel */ }, }; -static void process_args(int argc, char **argv) +static int process_args(int argc, char **argv) { char *ptr; int type = IH_TYPE_INVALID; @@ -219,7 +225,7 @@ static void process_args(int argc, char **argv) params.arch = genimg_get_arch_id(optarg); if (params.arch < 0) { show_valid_options(IH_ARCH); - usage("Invalid architecture"); + return usage("Invalid architecture"); } params.Aflag = 1; break; @@ -247,7 +253,7 @@ static void process_args(int argc, char **argv) params.comp = genimg_get_comp_id(optarg); if (params.comp < 0) { show_valid_options(IH_COMP); - usage("Invalid compression type"); + return usage("Invalid compression type"); } break; case 'd': @@ -315,7 +321,7 @@ static void process_args(int argc, char **argv) params.os = genimg_get_os_id(optarg); if (params.os < 0) { show_valid_options(IH_OS); - usage("Invalid operating system"); + return usage("Invalid operating system"); } break; case 'p': @@ -353,7 +359,7 @@ static void process_args(int argc, char **argv) type = genimg_get_type_id(optarg); if (type < 0) { show_valid_options(IH_TYPE); - usage("Invalid image type"); + return usage("Invalid image type"); } break; case 'v': @@ -366,7 +372,7 @@ static void process_args(int argc, char **argv) params.xflag++; break; default: - usage("Invalid option"); + return usage("Invalid option"); } } @@ -376,11 +382,12 @@ static void process_args(int argc, char **argv) if (params.auto_fit == AF_SIGNED_CONF) { if (!params.keyname || !params.algo_name) - usage("Missing key/algo for auto-FIT with signed configs (use -g -o)"); + return usage( + "Missing key/algo for auto-FIT with signed configs (use -g -o)"); } else if (params.auto_fit == AF_HASHED_IMG && params.keyname) { params.auto_fit = AF_SIGNED_IMG; if (!params.algo_name) - usage("Missing algorithm for auto-FIT with signed images (use -g)"); + return usage("Missing algorithm for auto-FIT with signed images (use -g)"); } /* @@ -394,15 +401,17 @@ static void process_args(int argc, char **argv) if (!params.auto_fit) params.datafile = datafile; else if (!params.datafile) - usage("Missing data file for auto-FIT (use -d)"); + return usage("Missing data file for auto-FIT (use -d)"); } else if (params.lflag || type != IH_TYPE_INVALID) { if (type == IH_TYPE_SCRIPT && !params.datafile) - usage("Missing data file for script (use -d)"); + return usage("Missing data file for script (use -d)"); params.type = type; } if (!params.imagefile) - usage("Missing output filename"); + return usage("Missing output filename"); + + return 0; } static void verify_image(const struct image_type_params *tparams) @@ -609,7 +618,7 @@ static int run_mkimage(void) */ if (tparams && tparams->check_params) if (tparams->check_params (¶ms)) - usage("Bad parameters for image type"); + return usage("Bad parameters for image type"); if (!params.eflag) { params.ep = params.addr; @@ -634,7 +643,7 @@ static int run_mkimage(void) retval = tparams->fflag_handle(¶ms); if (retval != EXIT_SUCCESS) - usage("Bad parameters for FIT image type"); + return usage("Bad parameters for FIT image type"); } if (params.lflag || params.fflag) { @@ -945,9 +954,9 @@ int main(int argc, char **argv) params.addr = 0; params.ep = 0; - process_args(argc, argv); - - ret = run_mkimage(); + ret = process_args(argc, argv); + if (!ret) + ret = run_mkimage(); return ret; } -- 2.43.0

The current name is quite confusing. Mostly this struct holds function pointers, not parameters. Rename it to imgtool_funcs, so that is has the same prefix as imgtool (introduced in the next patch) and it is clear that it provides functions. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/aisimage.c | 4 ++-- tools/atmelimage.c | 2 +- tools/dumpimage.c | 6 +++--- tools/imagetool.c | 20 ++++++++++---------- tools/imagetool.h | 28 +++++++++++++--------------- tools/imximage.c | 2 +- tools/kwbimage.c | 2 +- tools/mkimage.c | 6 +++--- tools/mtk_image.c | 2 +- tools/mxsimage.c | 4 ++-- tools/renesas_spkgimage.c | 2 +- tools/rkcommon.c | 2 +- tools/rkcommon.h | 2 +- tools/rkspi.c | 2 +- tools/sfspl.c | 2 +- tools/socfpgaimage.c | 6 +++--- tools/sunxi_egon.c | 2 +- tools/sunxi_toc0.c | 2 +- tools/zynqmpimage.c | 2 +- 19 files changed, 48 insertions(+), 50 deletions(-) diff --git a/tools/aisimage.c b/tools/aisimage.c index c5b33b559b0..697b3c0bad7 100644 --- a/tools/aisimage.c +++ b/tools/aisimage.c @@ -157,7 +157,7 @@ static void aisimage_print_header(const void *hdr, struct image_tool_params *par } static uint32_t *ais_insert_cmd_header(uint32_t cmd, uint32_t nargs, - uint32_t *parms, struct image_type_params *tparams, + uint32_t *parms, struct imgtool_funcs *tparams, uint32_t *ptr) { int i; @@ -252,7 +252,7 @@ static uint32_t *ais_copy_image(struct image_tool_params *params, } static int aisimage_generate(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { FILE *fd = NULL; char *line = NULL; diff --git a/tools/atmelimage.c b/tools/atmelimage.c index 6a2d9d8feab..e1909f39c45 100644 --- a/tools/atmelimage.c +++ b/tools/atmelimage.c @@ -238,7 +238,7 @@ static int atmel_check_params(struct image_tool_params *params) } static int atmel_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { uint32_t tmp; size_t pos; diff --git a/tools/dumpimage.c b/tools/dumpimage.c index 4791dd0dfe1..b15aee934c9 100644 --- a/tools/dumpimage.c +++ b/tools/dumpimage.c @@ -25,8 +25,8 @@ static struct image_tool_params params; * returns negative if input image format does not match with any of * supported image types */ -static int dumpimage_extract_subimage(struct image_type_params *tparams, - void *ptr, struct stat *sbuf) +static int dumpimage_extract_subimage(struct imgtool_funcs *tparams, + void *ptr, struct stat *sbuf) { int retval = -1; @@ -68,7 +68,7 @@ int main(int argc, char **argv) struct stat sbuf; char *ptr; int retval = EXIT_SUCCESS; - struct image_type_params *tparams = NULL; + struct imgtool_funcs *tparams = NULL; params.cmdname = *argv; diff --git a/tools/imagetool.c b/tools/imagetool.c index b293211cf88..b36b8d735a4 100644 --- a/tools/imagetool.c +++ b/tools/imagetool.c @@ -9,13 +9,13 @@ #include <image.h> -struct image_type_params *imagetool_get_type(int type) +struct imgtool_funcs *imagetool_get_type(int type) { - struct image_type_params **curr; + struct imgtool_funcs **curr; INIT_SECTION(image_type); - struct image_type_params **start = __start_image_type; - struct image_type_params **end = __stop_image_type; + struct imgtool_funcs **start = __start_image_type; + struct imgtool_funcs **end = __stop_image_type; for (curr = start; curr != end; curr++) { if ((*curr)->check_image_type) { @@ -29,21 +29,21 @@ struct image_type_params *imagetool_get_type(int type) static int imagetool_verify_print_header_by_type( void *ptr, struct stat *sbuf, - struct image_type_params *tparams, + struct imgtool_funcs *tparams, struct image_tool_params *params); int imagetool_verify_print_header( void *ptr, struct stat *sbuf, - struct image_type_params *tparams, + struct imgtool_funcs *tparams, struct image_tool_params *params) { int retval = -1; - struct image_type_params **curr; + struct imgtool_funcs **curr; INIT_SECTION(image_type); - struct image_type_params **start = __start_image_type; - struct image_type_params **end = __stop_image_type; + struct imgtool_funcs **start = __start_image_type; + struct imgtool_funcs **end = __stop_image_type; if (tparams) return imagetool_verify_print_header_by_type(ptr, sbuf, tparams, params); @@ -88,7 +88,7 @@ int imagetool_verify_print_header( static int imagetool_verify_print_header_by_type( void *ptr, struct stat *sbuf, - struct image_type_params *tparams, + struct imgtool_funcs *tparams, struct image_tool_params *params) { int retval = -1; diff --git a/tools/imagetool.h b/tools/imagetool.h index 57be608210a..3cbb053e42b 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -101,10 +101,8 @@ struct image_tool_params { struct image_summary summary; /* results of signing process */ }; -/* - * image type specific variables and callback functions - */ -struct image_type_params { +/** struct imgtool_funcs - image-type-specific variables and callbacks */ +struct imgtool_funcs { /* name is an identification tag string for added support */ char *name; /* @@ -163,13 +161,13 @@ struct image_type_params { /* * This callback function will be executed for variable size record * It is expected to build this header in memory and return its length - * and a pointer to it by using image_type_params.header_size and - * image_type_params.hdr. The return value shall indicate if an + * and a pointer to it by using imgtool_funcs.header_size and + * imgtool_funcs.hdr. The return value shall indicate if an * additional padding should be used when copying the data image * by returning the padding length. */ - int (*vrec_header) (struct image_tool_params *, - struct image_type_params *); + int (*vrec_header)(struct image_tool_params *, + struct imgtool_funcs *funcs); }; /** @@ -179,11 +177,11 @@ struct image_type_params { * checks the input type for each supported image type * * if successful, - * returns respective image_type_params pointer if success + * returns respective imgtool_funcs pointer if success * if input type_id is not supported by any of image_type_support * returns NULL */ -struct image_type_params *imagetool_get_type(int type); +struct imgtool_funcs *imagetool_get_type(int type); /* * imagetool_verify_print_header() - verifies the image header @@ -203,7 +201,7 @@ struct image_type_params *imagetool_get_type(int type); int imagetool_verify_print_header( void *ptr, struct stat *sbuf, - struct image_type_params *tparams, + struct imgtool_funcs *tparams, struct image_tool_params *params); /** @@ -286,14 +284,14 @@ int rockchip_copy_image(int fd, struct image_tool_params *mparams); } while (0) #define SECTION(name) __attribute__((section("__DATA, " #name))) -struct image_type_params **__start_image_type, **__stop_image_type; +struct imgtool_funcs **__start_image_type, **__stop_image_type; #else #define INIT_SECTION(name) /* no-op for ELF */ #define SECTION(name) __attribute__((section(#name))) /* We construct a table of pointers in an ELF section (pointers generally * go unpadded by gcc). ld creates boundary syms for us. */ -extern struct image_type_params *__start_image_type[], *__stop_image_type[]; +extern struct imgtool_funcs *__start_image_type[], *__stop_image_type[]; #endif /* __MACH__ */ #if !defined(__used) @@ -318,7 +316,7 @@ extern struct image_type_params *__start_image_type[], *__stop_image_type[]; _fflag_handle, \ _vrec_header \ ) \ - static struct image_type_params __cat(image_type_, _id) = \ + static struct imgtool_funcs __cat(image_type_, _id) = \ { \ .name = _name, \ .header_size = _header_size, \ @@ -332,7 +330,7 @@ extern struct image_type_params *__start_image_type[], *__stop_image_type[]; .fflag_handle = _fflag_handle, \ .vrec_header = _vrec_header \ }; \ - static struct image_type_params *SECTION(image_type) __used \ + static struct imgtool_funcs *SECTION(image_type) __used \ __cat(image_type_ptr_, _id) = &__cat(image_type_, _id) #endif /* _IMAGETOOL_H_ */ diff --git a/tools/imximage.c b/tools/imximage.c index 55231caf8f3..7a5dde617d9 100644 --- a/tools/imximage.c +++ b/tools/imximage.c @@ -967,7 +967,7 @@ static void generate_fspi_header(int ifd) #endif static int imximage_generate(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { struct imx_header *imxhdr; size_t alloc_len; diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 3dcf5ba66b9..d6c7206868e 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -2160,7 +2160,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, } static int kwbimage_generate(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { FILE *fcfg; struct stat s; diff --git a/tools/mkimage.c b/tools/mkimage.c index 8a132362a5b..6e50254452d 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -414,7 +414,7 @@ static int process_args(int argc, char **argv) return 0; } -static void verify_image(const struct image_type_params *tparams) +static void verify_image(const struct imgtool_funcs *tparams) { struct stat sbuf; void *ptr; @@ -462,7 +462,7 @@ static void copy_file(int ifd, const char *datafile, int pad) uint8_t zeros[4096]; int offset = 0; int size, ret; - struct image_type_params *tparams = imagetool_get_type(params.type); + struct imgtool_funcs *tparams = imagetool_get_type(params.type); memset(zeros, 0, sizeof(zeros)); @@ -595,7 +595,7 @@ void copy_datafile(int ifd, char *file) */ static int run_mkimage(void) { - struct image_type_params *tparams = NULL; + struct imgtool_funcs *tparams = NULL; struct stat sbuf; int pad_len = 0; int retval = 0; diff --git a/tools/mtk_image.c b/tools/mtk_image.c index 1b1aed59924..8a22b4ef789 100644 --- a/tools/mtk_image.c +++ b/tools/mtk_image.c @@ -244,7 +244,7 @@ static int mtk_image_check_params(struct image_tool_params *params) } static int mtk_image_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { if (use_lk_hdr) { tparams->header_size = sizeof(union lk_hdr); diff --git a/tools/mxsimage.c b/tools/mxsimage.c index 42df0698ca2..45c6e3624c9 100644 --- a/tools/mxsimage.c +++ b/tools/mxsimage.c @@ -2245,7 +2245,7 @@ static void mxsimage_print_header(const void *hdr, struct image_tool_params *par } static int sb_build_image(struct sb_image_ctx *ictx, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { struct sb_boot_image_header *sb_header = &ictx->payload; struct sb_section_ctx *sctx; @@ -2315,7 +2315,7 @@ static int sb_build_image(struct sb_image_ctx *ictx, } static int mxsimage_generate(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { int ret; struct sb_image_ctx ctx; diff --git a/tools/renesas_spkgimage.c b/tools/renesas_spkgimage.c index ce3b2b28ae7..ed80aec3c6b 100644 --- a/tools/renesas_spkgimage.c +++ b/tools/renesas_spkgimage.c @@ -217,7 +217,7 @@ static inline uint32_t roundup(uint32_t x, uint32_t y) } static int spkgimage_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { struct stat s; struct spkg_file *out_buf; diff --git a/tools/rkcommon.c b/tools/rkcommon.c index a0caa029cc0..f938b524329 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -544,7 +544,7 @@ void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size) } int rkcommon_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { /* * The SPL image looks as follows: diff --git a/tools/rkcommon.h b/tools/rkcommon.h index 5d2770a80f1..792a046c7af 100644 --- a/tools/rkcommon.h +++ b/tools/rkcommon.h @@ -102,6 +102,6 @@ void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size); * Return: 0 (always) */ int rkcommon_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams); + struct imgtool_funcs *tparams); #endif diff --git a/tools/rkspi.c b/tools/rkspi.c index f2530f7bde3..284d9dbc02c 100644 --- a/tools/rkspi.c +++ b/tools/rkspi.c @@ -58,7 +58,7 @@ static int rkspi_check_image_type(uint8_t type) * (i.e. only the first 2K of each 4K sector is used). */ static int rkspi_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { rkcommon_vrec_header(params, tparams); diff --git a/tools/sfspl.c b/tools/sfspl.c index 516e96e8dd9..e0c15243c9d 100644 --- a/tools/sfspl.c +++ b/tools/sfspl.c @@ -153,7 +153,7 @@ static void sfspl_set_header(void *buf, struct stat *sbuf, int infd, } static int sfspl_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { tparams->hdr = calloc(sizeof(struct spl_hdr), 1); diff --git a/tools/socfpgaimage.c b/tools/socfpgaimage.c index 953dfeed4d5..64c5f498355 100644 --- a/tools/socfpgaimage.c +++ b/tools/socfpgaimage.c @@ -398,7 +398,7 @@ static int sfp_fake_header_size(unsigned int size, uint8_t ver) } static int sfp_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams, uint8_t ver) + struct imgtool_funcs *tparams, uint8_t ver) { struct stat sbuf; @@ -413,13 +413,13 @@ static int sfp_vrec_header(struct image_tool_params *params, } static int socfpgaimage_vrec_header_v0(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { return sfp_vrec_header(params, tparams, 0); } static int socfpgaimage_vrec_header_v1(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { return sfp_vrec_header(params, tparams, 1); } diff --git a/tools/sunxi_egon.c b/tools/sunxi_egon.c index a514427809a..d0a55226a9e 100644 --- a/tools/sunxi_egon.c +++ b/tools/sunxi_egon.c @@ -172,7 +172,7 @@ static int egon_check_image_type(uint8_t type) } static int egon_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { int pad_size = ALIGN(params->bl_len ?: PAD_SIZE, PAD_SIZE_MIN); diff --git a/tools/sunxi_toc0.c b/tools/sunxi_toc0.c index 76693647a09..e52cbe325a3 100644 --- a/tools/sunxi_toc0.c +++ b/tools/sunxi_toc0.c @@ -889,7 +889,7 @@ static int toc0_check_image_type(uint8_t type) } static int toc0_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { tparams->hdr = calloc(tparams->header_size, 1); diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c index 4db9877127e..a075ac22bdd 100644 --- a/tools/zynqmpimage.c +++ b/tools/zynqmpimage.c @@ -499,7 +499,7 @@ static int zynqmpimage_extract_contents(void *ptr, struct image_tool_params *par } static int zynqmpimage_vrec_header(struct image_tool_params *params, - struct image_type_params *tparams) + struct imgtool_funcs *tparams) { struct stat path_stat; char *filename = params->imagename; -- 2.43.0

Update usage(), process_args() and run_mkimage() to pass the image-tool info around, so we can eventually drop the global. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 03492c795aa..0d661e77e4e 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -84,14 +84,14 @@ static int show_valid_options(enum ih_category category) * Return: * EXIT_FAILURE (always) */ -static int usage(const char *msg) +static int usage(const struct imgtool *itl, const char *msg) { fprintf(stderr, "Error: %s\n", msg); fprintf(stderr, "Usage: %s [-T type] -l image\n" " -l ==> list image header information\n" " -T ==> parse image file as 'type'\n" " -q ==> quiet\n", - params.cmdname); + itl->cmdname); fprintf(stderr, " %s [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image\n" " -A ==> set architecture to 'arch'\n" @@ -106,11 +106,11 @@ static int usage(const char *msg) " -x ==> set XIP (execute in place)\n" " -s ==> create an image with no data\n" " -v ==> verbose\n", - params.cmdname); + itl->cmdname); fprintf(stderr, " %s [-D dtc_options] [-f fit-image.its|-f auto|-f auto-conf|-F] [-b <dtb> [-b <dtb>]] [-E] [-B size] [-i <ramdisk.cpio.gz>] fit-image\n" " <dtb> file is used with -f auto, it may occur multiple times.\n", - params.cmdname); + itl->cmdname); fprintf(stderr, " -D => set all options for device tree compiler\n" " -f => input filename for FIT source\n" @@ -138,7 +138,7 @@ static int usage(const char *msg) #endif fprintf(stderr, " %s -V ==> print version information and exit\n", - params.cmdname); + itl->cmdname); fprintf(stderr, "Use '-T list' to see a list of available image types\n"); fprintf(stderr, "Long options are available; read the man page for details\n"); @@ -203,7 +203,7 @@ static const struct option longopts[] = { { /* sentinel */ }, }; -static int process_args(int argc, char **argv) +static int process_args(struct imgtool *itl, int argc, char **argv) { char *ptr; int type = IH_TYPE_INVALID; @@ -225,7 +225,7 @@ static int process_args(int argc, char **argv) params.arch = genimg_get_arch_id(optarg); if (params.arch < 0) { show_valid_options(IH_ARCH); - return usage("Invalid architecture"); + return usage(itl, "Invalid architecture"); } params.Aflag = 1; break; @@ -253,7 +253,7 @@ static int process_args(int argc, char **argv) params.comp = genimg_get_comp_id(optarg); if (params.comp < 0) { show_valid_options(IH_COMP); - return usage("Invalid compression type"); + return usage(itl, "Invalid compression type"); } break; case 'd': @@ -321,7 +321,7 @@ static int process_args(int argc, char **argv) params.os = genimg_get_os_id(optarg); if (params.os < 0) { show_valid_options(IH_OS); - return usage("Invalid operating system"); + return usage(itl, "Invalid operating system"); } break; case 'p': @@ -359,7 +359,7 @@ static int process_args(int argc, char **argv) type = genimg_get_type_id(optarg); if (type < 0) { show_valid_options(IH_TYPE); - return usage("Invalid image type"); + return usage(itl, "Invalid image type"); } break; case 'v': @@ -372,7 +372,7 @@ static int process_args(int argc, char **argv) params.xflag++; break; default: - return usage("Invalid option"); + return usage(itl, "Invalid option"); } } @@ -382,12 +382,13 @@ static int process_args(int argc, char **argv) if (params.auto_fit == AF_SIGNED_CONF) { if (!params.keyname || !params.algo_name) - return usage( + return usage(itl, "Missing key/algo for auto-FIT with signed configs (use -g -o)"); } else if (params.auto_fit == AF_HASHED_IMG && params.keyname) { params.auto_fit = AF_SIGNED_IMG; if (!params.algo_name) - return usage("Missing algorithm for auto-FIT with signed images (use -g)"); + return usage(itl, + "Missing algorithm for auto-FIT with signed images (use -g)"); } /* @@ -401,15 +402,17 @@ static int process_args(int argc, char **argv) if (!params.auto_fit) params.datafile = datafile; else if (!params.datafile) - return usage("Missing data file for auto-FIT (use -d)"); + return usage(itl, + "Missing data file for auto-FIT (use -d)"); } else if (params.lflag || type != IH_TYPE_INVALID) { if (type == IH_TYPE_SCRIPT && !params.datafile) - return usage("Missing data file for script (use -d)"); + return usage(itl, + "Missing data file for script (use -d)"); params.type = type; } if (!params.imagefile) - return usage("Missing output filename"); + return usage(itl, "Missing output filename"); return 0; } @@ -593,7 +596,7 @@ void copy_datafile(int ifd, char *file) * * Return: 0 on success, or non-zero exit code */ -static int run_mkimage(void) +static int run_mkimage(struct imgtool *itl) { struct imgtool_funcs *tparams = NULL; struct stat sbuf; @@ -618,7 +621,7 @@ static int run_mkimage(void) */ if (tparams && tparams->check_params) if (tparams->check_params (¶ms)) - return usage("Bad parameters for image type"); + return usage(itl, "Bad parameters for image type"); if (!params.eflag) { params.ep = params.addr; @@ -643,7 +646,7 @@ static int run_mkimage(void) retval = tparams->fflag_handle(¶ms); if (retval != EXIT_SUCCESS) - return usage("Bad parameters for FIT image type"); + return usage(itl, "Bad parameters for FIT image type"); } if (params.lflag || params.fflag) { @@ -954,9 +957,9 @@ int main(int argc, char **argv) params.addr = 0; params.ep = 0; - ret = process_args(argc, argv); + ret = process_args(¶ms, argc, argv); if (!ret) - ret = run_mkimage(); + ret = run_mkimage(¶ms); return ret; } -- 2.43.0

Pass this pointer in rather than using the global. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 0d661e77e4e..c90db7dad60 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -145,7 +145,7 @@ static int usage(const struct imgtool *itl, const char *msg) return EXIT_FAILURE; } -static int add_content(int type, const char *fname) +static int add_content(struct imgtool *itl, int type, const char *fname) { struct content_info *cont; @@ -154,11 +154,11 @@ static int add_content(int type, const char *fname) return -1; cont->type = type; cont->fname = fname; - if (params.content_tail) - params.content_tail->next = cont; + if (itl->content_tail) + itl->content_tail->next = cont; else - params.content_head = cont; - params.content_tail = cont; + itl->content_head = cont; + itl->content_tail = cont; return 0; } @@ -230,7 +230,7 @@ static int process_args(struct imgtool *itl, int argc, char **argv) params.Aflag = 1; break; case 'b': - if (add_content(IH_TYPE_FLATDT, optarg)) { + if (add_content(itl, IH_TYPE_FLATDT, optarg)) { fprintf(stderr, "%s: Out of memory adding content '%s'", params.cmdname, optarg); -- 2.43.0

Pass this pointer in rather than using the global. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 118 ++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index c90db7dad60..6074449e399 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -214,142 +214,142 @@ static int process_args(struct imgtool *itl, int argc, char **argv) longopts, NULL)) != -1) { switch (opt) { case 'a': - params.addr = strtoull(optarg, &ptr, 16); + itl->addr = strtoull(optarg, &ptr, 16); if (*ptr) { fprintf(stderr, "%s: invalid load address %s\n", - params.cmdname, optarg); + itl->cmdname, optarg); exit(EXIT_FAILURE); } break; case 'A': - params.arch = genimg_get_arch_id(optarg); - if (params.arch < 0) { + itl->arch = genimg_get_arch_id(optarg); + if (itl->arch < 0) { show_valid_options(IH_ARCH); return usage(itl, "Invalid architecture"); } - params.Aflag = 1; + itl->Aflag = 1; break; case 'b': if (add_content(itl, IH_TYPE_FLATDT, optarg)) { fprintf(stderr, "%s: Out of memory adding content '%s'", - params.cmdname, optarg); + itl->cmdname, optarg); exit(EXIT_FAILURE); } break; case 'B': - params.bl_len = strtoull(optarg, &ptr, 16); + itl->bl_len = strtoull(optarg, &ptr, 16); if (*ptr) { fprintf(stderr, "%s: invalid block length %s\n", - params.cmdname, optarg); + itl->cmdname, optarg); exit(EXIT_FAILURE); } break; case 'c': - params.comment = optarg; + itl->comment = optarg; break; case 'C': - params.comp = genimg_get_comp_id(optarg); - if (params.comp < 0) { + itl->comp = genimg_get_comp_id(optarg); + if (itl->comp < 0) { show_valid_options(IH_COMP); return usage(itl, "Invalid compression type"); } break; case 'd': - params.datafile = optarg; - params.dflag = 1; + itl->datafile = optarg; + itl->dflag = 1; break; case 'D': - params.dtc = optarg; + itl->dtc = optarg; break; case 'e': - params.ep = strtoull(optarg, &ptr, 16); + itl->ep = strtoull(optarg, &ptr, 16); if (*ptr) { fprintf(stderr, "%s: invalid entry point %s\n", - params.cmdname, optarg); + itl->cmdname, optarg); exit(EXIT_FAILURE); } - params.eflag = 1; + itl->eflag = 1; break; case 'E': - params.external_data = true; + itl->external_data = true; break; case 'f': datafile = optarg; if (!strcmp(datafile, "auto")) - params.auto_fit = AF_HASHED_IMG; + itl->auto_fit = AF_HASHED_IMG; else if (!strcmp(datafile, "auto-conf")) - params.auto_fit = AF_SIGNED_CONF; + itl->auto_fit = AF_SIGNED_CONF; /* fallthrough */ case 'F': /* * The flattened image tree (FIT) format * requires a flattened device tree image type */ - params.type = IH_TYPE_FLATDT; - params.fflag = 1; + itl->type = IH_TYPE_FLATDT; + itl->fflag = 1; break; case 'g': - params.keyname = optarg; + itl->keyname = optarg; break; case 'G': - params.keyfile = optarg; + itl->keyfile = optarg; break; case 'i': - params.fit_ramdisk = optarg; + itl->fit_ramdisk = optarg; break; case 'k': - params.keydir = optarg; + itl->keydir = optarg; break; case 'K': - params.keydest = optarg; + itl->keydest = optarg; break; case 'l': - params.lflag = 1; + itl->lflag = 1; break; case 'n': - params.imagename = optarg; + itl->imagename = optarg; break; case 'N': - params.engine_id = optarg; + itl->engine_id = optarg; break; case 'o': - params.algo_name = optarg; + itl->algo_name = optarg; break; case 'O': - params.os = genimg_get_os_id(optarg); - if (params.os < 0) { + itl->os = genimg_get_os_id(optarg); + if (itl->os < 0) { show_valid_options(IH_OS); return usage(itl, "Invalid operating system"); } break; case 'p': - params.external_offset = strtoull(optarg, &ptr, 16); + itl->external_offset = strtoull(optarg, &ptr, 16); if (*ptr) { fprintf(stderr, "%s: invalid offset size %s\n", - params.cmdname, optarg); + itl->cmdname, optarg); exit(EXIT_FAILURE); } break; case 'q': - params.quiet = 1; + itl->quiet = 1; break; case 'r': - params.require_keys = 1; + itl->require_keys = 1; break; case 'R': /* * This entry is for the second configuration * file, if only one is not enough. */ - params.imagename2 = optarg; + itl->imagename2 = optarg; break; case 's': - params.skipcpy = 1; + itl->skipcpy = 1; break; case 't': - params.reset_timestamp = 1; + itl->reset_timestamp = 1; break; case 'T': if (strcmp(optarg, "list") == 0) { @@ -363,13 +363,13 @@ static int process_args(struct imgtool *itl, int argc, char **argv) } break; case 'v': - params.vflag++; + itl->vflag++; break; case 'V': printf("mkimage version %s\n", PLAIN_VERSION); exit(EXIT_SUCCESS); case 'x': - params.xflag++; + itl->xflag++; break; default: return usage(itl, "Invalid option"); @@ -378,17 +378,17 @@ static int process_args(struct imgtool *itl, int argc, char **argv) /* The last parameter is expected to be the imagefile */ if (optind < argc) - params.imagefile = argv[optind]; + itl->imagefile = argv[optind]; - if (params.auto_fit == AF_SIGNED_CONF) { - if (!params.keyname || !params.algo_name) + if (itl->auto_fit == AF_SIGNED_CONF) { + if (!itl->keyname || !itl->algo_name) return usage(itl, - "Missing key/algo for auto-FIT with signed configs (use -g -o)"); - } else if (params.auto_fit == AF_HASHED_IMG && params.keyname) { - params.auto_fit = AF_SIGNED_IMG; - if (!params.algo_name) + "Missing key/algo for auto-FIT with signed configs (use -g -o)"); + } else if (itl->auto_fit == AF_HASHED_IMG && itl->keyname) { + itl->auto_fit = AF_SIGNED_IMG; + if (!itl->algo_name) return usage(itl, - "Missing algorithm for auto-FIT with signed images (use -g)"); + "Missing algorithm for auto-FIT with signed images (use -g)"); } /* @@ -396,22 +396,22 @@ static int process_args(struct imgtool *itl, int argc, char **argv) * in the FIT, which is separate from the file's image type (which * will always be IH_TYPE_FLATDT in this case). */ - if (params.type == IH_TYPE_FLATDT) { - params.fit_image_type = type ? type : IH_TYPE_KERNEL; + if (itl->type == IH_TYPE_FLATDT) { + itl->fit_image_type = type ? type : IH_TYPE_KERNEL; /* For auto-FIT, datafile has to be provided with -d */ - if (!params.auto_fit) - params.datafile = datafile; - else if (!params.datafile) + if (!itl->auto_fit) + itl->datafile = datafile; + else if (!itl->datafile) return usage(itl, "Missing data file for auto-FIT (use -d)"); - } else if (params.lflag || type != IH_TYPE_INVALID) { - if (type == IH_TYPE_SCRIPT && !params.datafile) + } else if (itl->lflag || type != IH_TYPE_INVALID) { + if (type == IH_TYPE_SCRIPT && !itl->datafile) return usage(itl, "Missing data file for script (use -d)"); - params.type = type; + itl->type = type; } - if (!params.imagefile) + if (!itl->imagefile) return usage(itl, "Missing output filename"); return 0; -- 2.43.0

Pass this pointer in rather than using the global. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 6074449e399..e83172124ca 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -417,41 +417,41 @@ static int process_args(struct imgtool *itl, int argc, char **argv) return 0; } -static void verify_image(const struct imgtool_funcs *tparams) +static void verify_image(struct imgtool *itl, const struct imgtool_funcs *tparams) { struct stat sbuf; void *ptr; int ifd; - ifd = open(params.imagefile, O_RDONLY | O_BINARY); + ifd = open(itl->imagefile, O_RDONLY | O_BINARY); if (ifd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - params.cmdname, params.imagefile, + itl->cmdname, itl->imagefile, strerror(errno)); exit(EXIT_FAILURE); } if (fstat(ifd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", - params.cmdname, params.imagefile, strerror(errno)); + itl->cmdname, itl->imagefile, strerror(errno)); exit(EXIT_FAILURE); } - params.file_size = sbuf.st_size; + itl->file_size = sbuf.st_size; - ptr = mmap(0, params.file_size, PROT_READ, MAP_SHARED, ifd, 0); + ptr = mmap(0, itl->file_size, PROT_READ, MAP_SHARED, ifd, 0); if (ptr == MAP_FAILED) { fprintf(stderr, "%s: Can't map %s: %s\n", - params.cmdname, params.imagefile, strerror(errno)); + itl->cmdname, itl->imagefile, strerror(errno)); exit(EXIT_FAILURE); } - if (tparams->verify_header((unsigned char *)ptr, params.file_size, ¶ms) != 0) { + if (tparams->verify_header((unsigned char *)ptr, itl->file_size, itl) != 0) { fprintf(stderr, "%s: Failed to verify header of %s\n", - params.cmdname, params.imagefile); + itl->cmdname, itl->imagefile); exit(EXIT_FAILURE); } - (void)munmap(ptr, params.file_size); + (void)munmap(ptr, itl->file_size); (void)close(ifd); } @@ -944,7 +944,7 @@ static int run_mkimage(struct imgtool *itl) } if (tparams->verify_header) - verify_image(tparams); + verify_image(itl, tparams); return 0; } -- 2.43.0

Pass this pointer in rather than using the global. Update copy_data_file() too since it calls copy_file() Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 52 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index e83172124ca..f27f6a23276 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -455,7 +455,7 @@ static void verify_image(struct imgtool *itl, const struct imgtool_funcs *tparam (void)close(ifd); } -static void copy_file(int ifd, const char *datafile, int pad) +static void copy_file(struct imgtool *itl, int ifd, const char *datafile, int pad) { int dfd; struct stat sbuf; @@ -465,43 +465,43 @@ static void copy_file(int ifd, const char *datafile, int pad) uint8_t zeros[4096]; int offset = 0; int size, ret; - struct imgtool_funcs *tparams = imagetool_get_type(params.type); + struct imgtool_funcs *tparams = imagetool_get_type(itl->type); memset(zeros, 0, sizeof(zeros)); - if (params.vflag) + if (itl->vflag) fprintf(stderr, "Adding Image %s\n", datafile); dfd = open(datafile, O_RDONLY | O_BINARY); if (dfd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - params.cmdname, datafile, strerror(errno)); + itl->cmdname, datafile, strerror(errno)); exit (EXIT_FAILURE); } if (fstat(dfd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", - params.cmdname, datafile, strerror(errno)); + itl->cmdname, datafile, strerror(errno)); exit (EXIT_FAILURE); } if (sbuf.st_size == 0) { fprintf(stderr, "%s: Input file %s is empty, bailing out\n", - params.cmdname, datafile); + itl->cmdname, datafile); exit (EXIT_FAILURE); } ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0); if (ptr == MAP_FAILED) { fprintf(stderr, "%s: Can't read %s: %s\n", - params.cmdname, datafile, strerror(errno)); + itl->cmdname, datafile, strerror(errno)); exit (EXIT_FAILURE); } - if (params.xflag && - ((params.type > IH_TYPE_INVALID && params.type < IH_TYPE_FLATDT) || - params.type == IH_TYPE_KERNEL_NOLOAD || - params.type == IH_TYPE_FIRMWARE_IVT)) { + if (itl->xflag && + ((itl->type > IH_TYPE_INVALID && itl->type < IH_TYPE_FLATDT) || + itl->type == IH_TYPE_KERNEL_NOLOAD || + itl->type == IH_TYPE_FIRMWARE_IVT)) { unsigned char *p = NULL; /* * XIP: do not append the struct legacy_img_hdr at the @@ -512,7 +512,7 @@ static void copy_file(int ifd, const char *datafile, int pad) if ((unsigned int)sbuf.st_size < tparams->header_size) { fprintf(stderr, "%s: Bad size: \"%s\" is too small for XIP\n", - params.cmdname, datafile); + itl->cmdname, datafile); exit (EXIT_FAILURE); } @@ -520,7 +520,7 @@ static void copy_file(int ifd, const char *datafile, int pad) if (*p != 0xff) { fprintf(stderr, "%s: Bad file: \"%s\" has invalid buffer for XIP\n", - params.cmdname, datafile); + itl->cmdname, datafile); exit (EXIT_FAILURE); } } @@ -534,19 +534,19 @@ static void copy_file(int ifd, const char *datafile, int pad) if (ret != size) { if (ret < 0) fprintf(stderr, "%s: Write error on %s: %s\n", - params.cmdname, params.imagefile, strerror(errno)); + itl->cmdname, itl->imagefile, strerror(errno)); else if (ret < size) fprintf(stderr, "%s: Write only %d/%d bytes, " "probably no space left on the device\n", - params.cmdname, ret, size); + itl->cmdname, ret, size); exit (EXIT_FAILURE); } tail = size % 4; - if (pad == 1 && tail != 0) { + if (pad == 1 && tail) { if (write(ifd, (char *)&zero, 4 - tail) != 4 - tail) { fprintf(stderr, "%s: Write error on %s: %s\n", - params.cmdname, params.imagefile, + itl->cmdname, itl->imagefile, strerror(errno)); exit (EXIT_FAILURE); } @@ -558,7 +558,7 @@ static void copy_file(int ifd, const char *datafile, int pad) todo = pad; if (write(ifd, (char *)&zeros, todo) != todo) { fprintf(stderr, "%s: Write error on %s: %s\n", - params.cmdname, params.imagefile, + itl->cmdname, itl->imagefile, strerror(errno)); exit(EXIT_FAILURE); } @@ -570,7 +570,7 @@ static void copy_file(int ifd, const char *datafile, int pad) (void)close(dfd); } -void copy_datafile(int ifd, char *file) +void copy_datafile(struct imgtool *itl, int ifd, char *file) { if (!file) return; @@ -579,11 +579,11 @@ void copy_datafile(int ifd, char *file) if (sep) { *sep = '\0'; - copy_file(ifd, file, 1); + copy_file(itl, ifd, file, 1); *sep++ = ':'; file = sep; } else { - copy_file(ifd, file, 0); + copy_file(itl, ifd, file, 0); break; } } @@ -650,10 +650,10 @@ static int run_mkimage(struct imgtool *itl) } if (params.lflag || params.fflag) { - ifd = open (params.imagefile, O_RDONLY|O_BINARY); + ifd = open(params.imagefile, O_RDONLY | O_BINARY); } else { - ifd = open (params.imagefile, - O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0666); + ifd = open(params.imagefile, + O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666); } if (ifd < 0) { @@ -812,7 +812,7 @@ static int run_mkimage(struct imgtool *itl) file = NULL; } } - copy_datafile(ifd, params.datafile); + copy_datafile(itl, ifd, params.datafile); } else if (params.type == IH_TYPE_PBLIMAGE) { /* PBL has special Image format, implements its' own */ pbl_load_uboot(ifd, ¶ms); @@ -846,7 +846,7 @@ static int run_mkimage(struct imgtool *itl) if (ret) return ret; } else { - copy_file(ifd, params.datafile, pad_len); + copy_file(itl, ifd, params.datafile, pad_len); } if (params.type == IH_TYPE_FIRMWARE_IVT) { /* Add alignment and IVT */ -- 2.43.0

Pass this pointer in rather than using the global. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 139 ++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index f27f6a23276..6e4ff8463bc 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -608,10 +608,10 @@ static int run_mkimage(struct imgtool *itl) int dfd; /* set tparams as per input type_id */ - tparams = imagetool_get_type(params.type); - if (tparams == NULL && !params.lflag) { + tparams = imagetool_get_type(itl->type); + if (!tparams && !itl->lflag) { fprintf (stderr, "%s: unsupported type %s\n", - params.cmdname, genimg_get_type_name(params.type)); + itl->cmdname, genimg_get_type_name(itl->type)); return EXIT_FAILURE; } @@ -620,20 +620,20 @@ static int run_mkimage(struct imgtool *itl) * as per image type to be generated/listed */ if (tparams && tparams->check_params) - if (tparams->check_params (¶ms)) + if (tparams->check_params(itl)) return usage(itl, "Bad parameters for image type"); - if (!params.eflag) { - params.ep = params.addr; + if (!itl->eflag) { + itl->ep = itl->addr; /* If XIP, entry point must be after the U-Boot header */ - if (params.xflag && tparams) - params.ep += tparams->header_size; + if (itl->xflag && tparams) + itl->ep += tparams->header_size; } - if (params.fflag){ + if (itl->fflag) { if (!tparams) { fprintf(stderr, "%s: Missing FIT support\n", - params.cmdname); + itl->cmdname); return EXIT_FAILURE; } if (tparams->fflag_handle) @@ -643,34 +643,34 @@ static int run_mkimage(struct imgtool *itl) * * For ex. fit_handle_file for Fit file support */ - retval = tparams->fflag_handle(¶ms); + retval = tparams->fflag_handle(itl); if (retval != EXIT_SUCCESS) return usage(itl, "Bad parameters for FIT image type"); } - if (params.lflag || params.fflag) { - ifd = open(params.imagefile, O_RDONLY | O_BINARY); + if (itl->lflag || itl->fflag) { + ifd = open(itl->imagefile, O_RDONLY | O_BINARY); } else { - ifd = open(params.imagefile, + ifd = open(itl->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, + itl->cmdname, itl->imagefile, strerror(errno)); return EXIT_FAILURE; } - if (params.lflag || params.fflag) { + if (itl->lflag || itl->fflag) { uint64_t size; /* * list header information of existing image */ if (fstat(ifd, &sbuf) < 0) { fprintf (stderr, "%s: Can't stat %s: %s\n", - params.cmdname, params.imagefile, + itl->cmdname, itl->imagefile, strerror(errno)); return EXIT_FAILURE; } @@ -683,19 +683,19 @@ static int run_mkimage(struct imgtool *itl) if (ioctl(ifd, BLKGETSIZE64, &size) < 0) { fprintf (stderr, "%s: failed to get size of block device \"%s\"\n", - params.cmdname, params.imagefile); + itl->cmdname, itl->imagefile); return EXIT_FAILURE; } #else fprintf (stderr, "%s: \"%s\" is block device, don't know how to get its size\n", - params.cmdname, params.imagefile); + itl->cmdname, itl->imagefile); return EXIT_FAILURE; #endif } else if (tparams && sbuf.st_size < (off_t)tparams->header_size) { fprintf (stderr, "%s: Bad size: \"%s\" is not valid image: size %llu < %u\n", - params.cmdname, params.imagefile, + itl->cmdname, itl->imagefile, (unsigned long long) sbuf.st_size, tparams->header_size); return EXIT_FAILURE; @@ -706,49 +706,48 @@ static int run_mkimage(struct imgtool *itl) ptr = mmap(0, size, PROT_READ, MAP_SHARED, ifd, 0); if (ptr == MAP_FAILED) { fprintf (stderr, "%s: Can't read %s: %s\n", - params.cmdname, params.imagefile, + itl->cmdname, itl->imagefile, strerror(errno)); return EXIT_FAILURE; } /* * Verifies the header format based on the expected header for image - * type in tparams. If tparams is NULL simply check all image types + * type in titl-> If tparams is NULL simply check all image types * to find one that matches our header. */ - retval = imagetool_verify_print_header(ptr, &sbuf, tparams, ¶ms); + retval = imagetool_verify_print_header(ptr, &sbuf, tparams, itl); (void) munmap((void *)ptr, sbuf.st_size); (void) close (ifd); if (!retval) - summary_show(¶ms.summary, params.imagefile, - params.keydest); + summary_show(&itl->summary, itl->imagefile, itl->keydest); return retval; } - if (!params.skipcpy && params.type != IH_TYPE_MULTI && params.type != IH_TYPE_SCRIPT) { - if (!params.datafile) { + if (!itl->skipcpy && itl->type != IH_TYPE_MULTI && itl->type != IH_TYPE_SCRIPT) { + if (!itl->datafile) { fprintf(stderr, "%s: Option -d with image data file was not specified\n", - params.cmdname); + itl->cmdname); return EXIT_FAILURE; } - dfd = open(params.datafile, O_RDONLY | O_BINARY); + dfd = open(itl->datafile, O_RDONLY | O_BINARY); if (dfd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - params.cmdname, params.datafile, + itl->cmdname, itl->datafile, strerror(errno)); return EXIT_FAILURE; } if (fstat(dfd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", - params.cmdname, params.datafile, + itl->cmdname, itl->datafile, strerror(errno)); return EXIT_FAILURE; } - params.file_size = sbuf.st_size + tparams->header_size; + itl->file_size = sbuf.st_size + tparams->header_size; close(dfd); } @@ -759,21 +758,21 @@ static int run_mkimage(struct imgtool *itl) * allocate memory for the header itself. */ if (tparams->vrec_header) - pad_len = tparams->vrec_header(¶ms, tparams); + pad_len = tparams->vrec_header(itl, tparams); else memset(tparams->hdr, 0, tparams->header_size); if (write(ifd, tparams->hdr, tparams->header_size) != tparams->header_size) { fprintf (stderr, "%s: Write error on %s: %s\n", - params.cmdname, params.imagefile, strerror(errno)); + itl->cmdname, itl->imagefile, strerror(errno)); return EXIT_FAILURE; } - if (!params.skipcpy) { - if (params.type == IH_TYPE_MULTI || - params.type == IH_TYPE_SCRIPT) { - char *file = params.datafile; + if (!itl->skipcpy) { + if (itl->type == IH_TYPE_MULTI || + itl->type == IH_TYPE_SCRIPT) { + char *file = itl->datafile; uint32_t size; for (;;) { @@ -786,7 +785,7 @@ static int run_mkimage(struct imgtool *itl) if (stat (file, &sbuf) < 0) { fprintf (stderr, "%s: Can't stat %s: %s\n", - params.cmdname, file, strerror(errno)); + itl->cmdname, file, strerror(errno)); return EXIT_FAILURE; } size = cpu_to_uimage (sbuf.st_size); @@ -796,7 +795,7 @@ static int run_mkimage(struct imgtool *itl) if (write(ifd, (char *)&size, sizeof(size)) != sizeof(size)) { fprintf (stderr, "%s: Write error on %s: %s\n", - params.cmdname, params.imagefile, + itl->cmdname, itl->imagefile, strerror(errno)); return EXIT_FAILURE; } @@ -812,60 +811,60 @@ static int run_mkimage(struct imgtool *itl) file = NULL; } } - copy_datafile(itl, ifd, params.datafile); - } else if (params.type == IH_TYPE_PBLIMAGE) { + copy_datafile(itl, ifd, itl->datafile); + } else if (itl->type == IH_TYPE_PBLIMAGE) { /* PBL has special Image format, implements its' own */ - pbl_load_uboot(ifd, ¶ms); - } else if (params.type == IH_TYPE_ZYNQMPBIF) { + pbl_load_uboot(ifd, itl); + } else if (itl->type == IH_TYPE_ZYNQMPBIF) { /* Image file is meta, walk through actual targets */ int ret; - ret = zynqmpbif_copy_image(ifd, ¶ms); + ret = zynqmpbif_copy_image(ifd, itl); if (ret) return ret; - } else if (params.type == IH_TYPE_IMX8IMAGE) { + } else if (itl->type == IH_TYPE_IMX8IMAGE) { /* i.MX8/8X has special Image format */ int ret; - ret = imx8image_copy_image(ifd, ¶ms); + ret = imx8image_copy_image(ifd, itl); if (ret) return ret; - } else if (params.type == IH_TYPE_IMX8MIMAGE) { + } else if (itl->type == IH_TYPE_IMX8MIMAGE) { /* i.MX8M has special Image format */ int ret; - ret = imx8mimage_copy_image(ifd, ¶ms); + ret = imx8mimage_copy_image(ifd, itl); if (ret) return ret; - } else if ((params.type == IH_TYPE_RKSD) || - (params.type == IH_TYPE_RKSPI)) { + } else if ((itl->type == IH_TYPE_RKSD) || + (itl->type == IH_TYPE_RKSPI)) { /* Rockchip has special Image format */ int ret; - ret = rockchip_copy_image(ifd, ¶ms); + ret = rockchip_copy_image(ifd, itl); if (ret) return ret; } else { - copy_file(itl, ifd, params.datafile, pad_len); + copy_file(itl, ifd, itl->datafile, pad_len); } - if (params.type == IH_TYPE_FIRMWARE_IVT) { + if (itl->type == IH_TYPE_FIRMWARE_IVT) { /* Add alignment and IVT */ - uint32_t aligned_filesize = ALIGN(params.file_size, + uint32_t aligned_filesize = ALIGN(itl->file_size, 0x1000); flash_header_v2_t ivt_header = { { 0xd1, 0x2000, 0x40 }, - params.addr, 0, 0, 0, params.addr + itl->addr, 0, 0, 0, itl->addr + aligned_filesize - tparams->header_size, - params.addr + aligned_filesize + itl->addr + aligned_filesize - tparams->header_size + 0x20, 0 }; - int i = params.file_size; + int i = itl->file_size; for (; i < aligned_filesize; i++) { if (write(ifd, (char *) &i, 1) != 1) { fprintf(stderr, "%s: Write error on %s: %s\n", - params.cmdname, - params.imagefile, + itl->cmdname, + itl->imagefile, strerror(errno)); return EXIT_FAILURE; } @@ -873,8 +872,8 @@ static int run_mkimage(struct imgtool *itl) if (write(ifd, &ivt_header, sizeof(flash_header_v2_t)) != sizeof(flash_header_v2_t)) { fprintf(stderr, "%s: Write error on %s: %s\n", - params.cmdname, - params.imagefile, + itl->cmdname, + itl->imagefile, strerror(errno)); return EXIT_FAILURE; } @@ -894,34 +893,34 @@ static int run_mkimage(struct imgtool *itl) if (fstat(ifd, &sbuf) < 0) { fprintf (stderr, "%s: Can't stat %s: %s\n", - params.cmdname, params.imagefile, strerror(errno)); + itl->cmdname, itl->imagefile, strerror(errno)); return EXIT_FAILURE; } - params.file_size = sbuf.st_size; + itl->file_size = sbuf.st_size; map_len = sbuf.st_size; ptr = mmap(0, map_len, PROT_READ | PROT_WRITE, MAP_SHARED, ifd, 0); if (ptr == MAP_FAILED) { fprintf (stderr, "%s: Can't map %s: %s\n", - params.cmdname, params.imagefile, strerror(errno)); + itl->cmdname, itl->imagefile, strerror(errno)); return EXIT_FAILURE; } /* Setup the image header as per input image type*/ if (tparams->set_header) - tparams->set_header (ptr, &sbuf, ifd, ¶ms); + tparams->set_header(ptr, &sbuf, ifd, itl); else { fprintf (stderr, "%s: Can't set header for %s\n", - params.cmdname, tparams->name); + itl->cmdname, tparams->name); return EXIT_FAILURE; } /* Print the image information by processing image header */ if (tparams->print_header) - tparams->print_header (ptr, ¶ms); + tparams->print_header(ptr, itl); else { fprintf (stderr, "%s: Can't print header for %s\n", - params.cmdname, tparams->name); + itl->cmdname, tparams->name); } (void)munmap((void *)ptr, map_len); @@ -939,7 +938,7 @@ static int run_mkimage(struct imgtool *itl) if (close(ifd)) { fprintf (stderr, "%s: Write error on %s: %s\n", - params.cmdname, params.imagefile, strerror(errno)); + itl->cmdname, itl->imagefile, strerror(errno)); return EXIT_FAILURE; } -- 2.43.0

Use a local variable for this state information. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 6e4ff8463bc..426b1965e14 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -18,17 +18,6 @@ #include <sys/ioctl.h> #endif -/* parameters initialized by core will be used by the image type code */ -static struct imgtool params = { - .os = IH_OS_LINUX, - .arch = IH_ARCH_PPC, - .type = IH_TYPE_KERNEL, - .comp = IH_COMP_GZIP, - .dtc = MKIMAGE_DEFAULT_DTC_OPTIONS, - .imagename = "", - .imagename2 = "", -}; - static enum ih_category cur_category; static int h_compare_category_name(const void *vtype1, const void *vtype2) @@ -950,15 +939,22 @@ static int run_mkimage(struct imgtool *itl) int main(int argc, char **argv) { + /* parameters initialized by core will be used by the image type code */ + struct imgtool itl = { + .cmdname = *argv, + .os = IH_OS_LINUX, + .arch = IH_ARCH_PPC, + .type = IH_TYPE_KERNEL, + .comp = IH_COMP_GZIP, + .dtc = MKIMAGE_DEFAULT_DTC_OPTIONS, + .imagename = "", + .imagename2 = "", + }; int ret; - params.cmdname = *argv; - params.addr = 0; - params.ep = 0; - - ret = process_args(¶ms, argc, argv); + ret = process_args(&itl, argc, argv); if (!ret) - ret = run_mkimage(¶ms); + ret = run_mkimage(&itl); return ret; } -- 2.43.0

Rather than exiting in this function, return an exit code. The caller already handles this. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 426b1965e14..23dd281e9ec 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -207,7 +207,7 @@ static int process_args(struct imgtool *itl, int argc, char **argv) if (*ptr) { fprintf(stderr, "%s: invalid load address %s\n", itl->cmdname, optarg); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } break; case 'A': @@ -223,7 +223,7 @@ static int process_args(struct imgtool *itl, int argc, char **argv) fprintf(stderr, "%s: Out of memory adding content '%s'", itl->cmdname, optarg); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } break; case 'B': @@ -231,7 +231,7 @@ static int process_args(struct imgtool *itl, int argc, char **argv) if (*ptr) { fprintf(stderr, "%s: invalid block length %s\n", itl->cmdname, optarg); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } break; @@ -257,7 +257,7 @@ static int process_args(struct imgtool *itl, int argc, char **argv) if (*ptr) { fprintf(stderr, "%s: invalid entry point %s\n", itl->cmdname, optarg); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } itl->eflag = 1; break; @@ -318,7 +318,7 @@ static int process_args(struct imgtool *itl, int argc, char **argv) if (*ptr) { fprintf(stderr, "%s: invalid offset size %s\n", itl->cmdname, optarg); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } break; case 'q': -- 2.43.0

Rather than exiting in this function, return an exit code. The caller is then responsible for returning it, so update it. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 23dd281e9ec..31a4813bd79 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -406,7 +406,7 @@ static int process_args(struct imgtool *itl, int argc, char **argv) return 0; } -static void verify_image(struct imgtool *itl, const struct imgtool_funcs *tparams) +static int verify_image(struct imgtool *itl, const struct imgtool_funcs *tparams) { struct stat sbuf; void *ptr; @@ -417,13 +417,13 @@ static void verify_image(struct imgtool *itl, const struct imgtool_funcs *tparam fprintf(stderr, "%s: Can't open %s: %s\n", itl->cmdname, itl->imagefile, strerror(errno)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (fstat(ifd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", itl->cmdname, itl->imagefile, strerror(errno)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } itl->file_size = sbuf.st_size; @@ -431,17 +431,19 @@ static void verify_image(struct imgtool *itl, const struct imgtool_funcs *tparam if (ptr == MAP_FAILED) { fprintf(stderr, "%s: Can't map %s: %s\n", itl->cmdname, itl->imagefile, strerror(errno)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (tparams->verify_header((unsigned char *)ptr, itl->file_size, itl) != 0) { fprintf(stderr, "%s: Failed to verify header of %s\n", itl->cmdname, itl->imagefile); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } (void)munmap(ptr, itl->file_size); (void)close(ifd); + + return 0; } static void copy_file(struct imgtool *itl, int ifd, const char *datafile, int pad) @@ -931,8 +933,8 @@ static int run_mkimage(struct imgtool *itl) return EXIT_FAILURE; } - if (tparams->verify_header) - verify_image(itl, tparams); + if (tparams->verify_header && verify_image(itl, tparams)) + return EXIT_FAILURE; return 0; } -- 2.43.0

Rather than exiting in copy_file() and copy_datafile(), return an exit code. The caller is then responsible for returning it, so update it. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 31a4813bd79..0e750ef87e9 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -446,7 +446,7 @@ static int verify_image(struct imgtool *itl, const struct imgtool_funcs *tparams return 0; } -static void copy_file(struct imgtool *itl, int ifd, const char *datafile, int pad) +static int copy_file(struct imgtool *itl, int ifd, const char *datafile, int pad) { int dfd; struct stat sbuf; @@ -467,26 +467,26 @@ static void copy_file(struct imgtool *itl, int ifd, const char *datafile, int pa if (dfd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", itl->cmdname, datafile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } if (fstat(dfd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", itl->cmdname, datafile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } if (sbuf.st_size == 0) { fprintf(stderr, "%s: Input file %s is empty, bailing out\n", itl->cmdname, datafile); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0); if (ptr == MAP_FAILED) { fprintf(stderr, "%s: Can't read %s: %s\n", itl->cmdname, datafile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } if (itl->xflag && @@ -504,7 +504,7 @@ static void copy_file(struct imgtool *itl, int ifd, const char *datafile, int pa fprintf(stderr, "%s: Bad size: \"%s\" is too small for XIP\n", itl->cmdname, datafile); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } for (p = ptr; p < ptr + tparams->header_size; p++) { @@ -512,7 +512,7 @@ static void copy_file(struct imgtool *itl, int ifd, const char *datafile, int pa fprintf(stderr, "%s: Bad file: \"%s\" has invalid buffer for XIP\n", itl->cmdname, datafile); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } } @@ -530,7 +530,7 @@ static void copy_file(struct imgtool *itl, int ifd, const char *datafile, int pa fprintf(stderr, "%s: Write only %d/%d bytes, " "probably no space left on the device\n", itl->cmdname, ret, size); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } tail = size % 4; @@ -539,7 +539,7 @@ static void copy_file(struct imgtool *itl, int ifd, const char *datafile, int pa fprintf(stderr, "%s: Write error on %s: %s\n", itl->cmdname, itl->imagefile, strerror(errno)); - exit (EXIT_FAILURE); + return EXIT_FAILURE; } } else if (pad > 1) { while (pad > 0) { @@ -551,7 +551,7 @@ static void copy_file(struct imgtool *itl, int ifd, const char *datafile, int pa fprintf(stderr, "%s: Write error on %s: %s\n", itl->cmdname, itl->imagefile, strerror(errno)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } pad -= todo; } @@ -559,25 +559,31 @@ static void copy_file(struct imgtool *itl, int ifd, const char *datafile, int pa (void)munmap((void *)ptr, sbuf.st_size); (void)close(dfd); + + return 0; } -void copy_datafile(struct imgtool *itl, int ifd, char *file) +static int copy_datafile(struct imgtool *itl, int ifd, char *file) { if (!file) - return; + return 0; for (;;) { char *sep = strchr(file, ':'); if (sep) { *sep = '\0'; - copy_file(itl, ifd, file, 1); + if (copy_file(itl, ifd, file, 1)) + return EXIT_FAILURE; *sep++ = ':'; file = sep; } else { - copy_file(itl, ifd, file, 0); + if (copy_file(itl, ifd, file, 0)) + return EXIT_FAILURE; break; } } + + return 0; } /** @@ -802,7 +808,8 @@ static int run_mkimage(struct imgtool *itl) file = NULL; } } - copy_datafile(itl, ifd, itl->datafile); + if (copy_datafile(itl, ifd, itl->datafile)) + return EXIT_FAILURE; } else if (itl->type == IH_TYPE_PBLIMAGE) { /* PBL has special Image format, implements its' own */ pbl_load_uboot(ifd, itl); @@ -836,7 +843,8 @@ static int run_mkimage(struct imgtool *itl) if (ret) return ret; } else { - copy_file(itl, ifd, itl->datafile, pad_len); + if (copy_file(itl, ifd, itl->datafile, pad_len)) + return EXIT_FAILURE; } if (itl->type == IH_TYPE_FIRMWARE_IVT) { /* Add alignment and IVT */ -- 2.43.0

The run_mkimage() function is long and complicated. Make a start by moving some initial checks out into their own check_params() function. Also move the FIT-processing into a new process_fit() function. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 93 +++++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 0e750ef87e9..5edc2123b40 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -587,65 +587,84 @@ static int copy_datafile(struct imgtool *itl, int ifd, char *file) } /** - * run_mkimage() - Run the mkimage tool - * - * The program arguments are in params + * check_params() - Do some initial checks on the parameters * - * Return: 0 on success, or non-zero exit code + * @itl: Image-tool info + * @tfuncs: image-tool functions + * Return: 0 if OK, non-zero on error */ -static int run_mkimage(struct imgtool *itl) +static int check_params(struct imgtool *itl, struct imgtool_funcs *tfuncs) { - struct imgtool_funcs *tparams = NULL; - struct stat sbuf; - int pad_len = 0; - int retval = 0; - size_t map_len; - int ifd = -1; - char *ptr; - int dfd; - /* set tparams as per input type_id */ - tparams = imagetool_get_type(itl->type); - if (!tparams && !itl->lflag) { + tfuncs = imagetool_get_type(itl->type); + if (!tfuncs && !itl->lflag) { fprintf (stderr, "%s: unsupported type %s\n", itl->cmdname, genimg_get_type_name(itl->type)); - return EXIT_FAILURE; + return -EINVAL; } /* * check the passed arguments parameters meets the requirements * as per image type to be generated/listed */ - if (tparams && tparams->check_params) - if (tparams->check_params(itl)) + if (tfuncs && tfuncs->check_params) + if (tfuncs->check_params(itl)) return usage(itl, "Bad parameters for image type"); if (!itl->eflag) { itl->ep = itl->addr; /* If XIP, entry point must be after the U-Boot header */ - if (itl->xflag && tparams) - itl->ep += tparams->header_size; + if (itl->xflag && tfuncs) + itl->ep += tfuncs->header_size; } - if (itl->fflag) { - if (!tparams) { - fprintf(stderr, "%s: Missing FIT support\n", - itl->cmdname); - return EXIT_FAILURE; - } - 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(itl); + return 0; +} - if (retval != EXIT_SUCCESS) - return usage(itl, "Bad parameters for FIT image type"); +static int process_fit(struct imgtool *itl, struct imgtool_funcs *tfuncs) +{ + if (!tfuncs) { + fprintf(stderr, "%s: Missing FIT support\n", + itl->cmdname); + return -ENOTSUP; } + /* + * in some cases, some additional processing needs to be done if fflag + * is defined + * + * E.g. fit_handle_file for Fit file support + */ + if (tfuncs->fflag_handle && tfuncs->fflag_handle(itl)) + return usage(itl, "Bad parameters for FIT image type"); + + return 0; +} + +/** + * run_mkimage() - Run the mkimage tool + * + * The program arguments are in params + * + * Return: 0 on success, or non-zero exit code + */ +static int run_mkimage(struct imgtool *itl) +{ + struct imgtool_funcs *tparams = NULL; + struct stat sbuf; + int pad_len = 0; + int retval = 0; + size_t map_len; + int ifd = -1; + char *ptr; + int dfd; + + tparams = imagetool_get_type(itl->type); + if (check_params(itl, tparams)) + return EXIT_FAILURE; + if (itl->fflag && process_fit(itl, tparams)) + return EXIT_FAILURE; + if (itl->lflag || itl->fflag) { ifd = open(itl->imagefile, O_RDONLY | O_BINARY); } else { -- 2.43.0

Add a new open_image() function to handle the initial opening of the output file. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 5edc2123b40..d1dcc5a6930 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -641,6 +641,33 @@ static int process_fit(struct imgtool *itl, struct imgtool_funcs *tfuncs) return 0; } +/** + * open_image() - Open the image file to create/update + * + * @itl: Image-tool info + * + * Return: file handle if OK, or -ve on error + */ +static int open_image(struct imgtool *itl) +{ + int ifd; + + if (itl->lflag || itl->fflag) { + ifd = open(itl->imagefile, O_RDONLY | O_BINARY); + } else { + ifd = open(itl->imagefile, + O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666); + } + + if (ifd < 0) { + fprintf(stderr, "%s: Can't open %s: %s\n", + itl->cmdname, itl->imagefile, strerror(errno)); + return -ENOENT; + } + + return ifd; +} + /** * run_mkimage() - Run the mkimage tool * @@ -665,19 +692,9 @@ static int run_mkimage(struct imgtool *itl) if (itl->fflag && process_fit(itl, tparams)) return EXIT_FAILURE; - if (itl->lflag || itl->fflag) { - ifd = open(itl->imagefile, O_RDONLY | O_BINARY); - } else { - ifd = open(itl->imagefile, - O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666); - } - - if (ifd < 0) { - fprintf (stderr, "%s: Can't open %s: %s\n", - itl->cmdname, itl->imagefile, - strerror(errno)); + ifd = open_image(itl); + if (ifd < 0) return EXIT_FAILURE; - } if (itl->lflag || itl->fflag) { uint64_t size; -- 2.43.0

For listing an image, or processing an existing FIT, an initial code path is used, then the program exits. Move this into its own function so it is clear that this is an early-return path. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/mkimage.c | 139 ++++++++++++++++++++++++++---------------------- 1 file changed, 76 insertions(+), 63 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index d1dcc5a6930..684e895938b 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -668,6 +668,80 @@ static int open_image(struct imgtool *itl) return ifd; } +/** + * list_or_process() - List the image, or do processing on it + * + * @itl: Image-tool info + * @tfuncs: image-tool functions + * @ifd: File handle of file to process + * + * Return: file handle if OK, or -ve on error + */ +static int list_or_process(struct imgtool *itl, struct imgtool_funcs *tfuncs, + int ifd) +{ + struct stat sbuf; + uint64_t size; + void *ptr; + int ret; + + if (fstat(ifd, &sbuf) < 0) { + fprintf(stderr, "%s: Can't stat %s: %s\n", itl->cmdname, + itl->imagefile, strerror(errno)); + return EXIT_FAILURE; + } + + if ((sbuf.st_mode & S_IFMT) == S_IFBLK) { +#ifdef __linux__ +#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64) +#define BLKGETSIZE64 _IOR(0x12, 114, size_t) /* return device size in bytes (u64 *arg) */ +#endif + if (ioctl(ifd, BLKGETSIZE64, &size) < 0) { + fprintf(stderr, + "%s: failed to get size of block device \"%s\"\n", + itl->cmdname, itl->imagefile); + return EXIT_FAILURE; + } +#else + fprintf(stderr, + "%s: \"%s\" is block device, don't know how to get its size\n", + itl->cmdname, itl->imagefile); + return EXIT_FAILURE; +#endif + } else if (tfuncs && sbuf.st_size < (off_t)tfuncs->header_size) { + fprintf(stderr, + "%s: Bad size: \"%s\" is not valid image: size %llu < %u\n", + itl->cmdname, itl->imagefile, + (unsigned long long)sbuf.st_size, + tfuncs->header_size); + return EXIT_FAILURE; + size = sbuf.st_size; + } else { + size = sbuf.st_size; + } + + ptr = mmap(0, size, PROT_READ, MAP_SHARED, ifd, 0); + if (ptr == MAP_FAILED) { + fprintf(stderr, "%s: Can't read %s: %s\n", itl->cmdname, + itl->imagefile, strerror(errno)); + return EXIT_FAILURE; + } + + /* + * Verify the header format based on the expected header for image + * type in titl-> If tfuncs is NULL simply check all image types + * to find one that matches our header. + */ + ret = imagetool_verify_print_header(ptr, &sbuf, tfuncs, itl); + + (void)munmap((void *)ptr, sbuf.st_size); + (void)close(ifd); + if (!ret) + summary_show(&itl->summary, itl->imagefile, itl->keydest); + + return ret; +} + /** * run_mkimage() - Run the mkimage tool * @@ -680,7 +754,6 @@ static int run_mkimage(struct imgtool *itl) struct imgtool_funcs *tparams = NULL; struct stat sbuf; int pad_len = 0; - int retval = 0; size_t map_len; int ifd = -1; char *ptr; @@ -696,68 +769,8 @@ static int run_mkimage(struct imgtool *itl) if (ifd < 0) return EXIT_FAILURE; - if (itl->lflag || itl->fflag) { - uint64_t size; - /* - * list header information of existing image - */ - if (fstat(ifd, &sbuf) < 0) { - fprintf (stderr, "%s: Can't stat %s: %s\n", - itl->cmdname, itl->imagefile, - strerror(errno)); - return EXIT_FAILURE; - } - - if ((sbuf.st_mode & S_IFMT) == S_IFBLK) { -#ifdef __linux__ -#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64) -#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ -#endif - if (ioctl(ifd, BLKGETSIZE64, &size) < 0) { - fprintf (stderr, - "%s: failed to get size of block device \"%s\"\n", - itl->cmdname, itl->imagefile); - return EXIT_FAILURE; - } -#else - fprintf (stderr, - "%s: \"%s\" is block device, don't know how to get its size\n", - itl->cmdname, itl->imagefile); - return EXIT_FAILURE; -#endif - } else if (tparams && sbuf.st_size < (off_t)tparams->header_size) { - fprintf (stderr, - "%s: Bad size: \"%s\" is not valid image: size %llu < %u\n", - itl->cmdname, itl->imagefile, - (unsigned long long) sbuf.st_size, - tparams->header_size); - return EXIT_FAILURE; - } else { - size = sbuf.st_size; - } - - ptr = mmap(0, size, PROT_READ, MAP_SHARED, ifd, 0); - if (ptr == MAP_FAILED) { - fprintf (stderr, "%s: Can't read %s: %s\n", - itl->cmdname, itl->imagefile, - strerror(errno)); - return EXIT_FAILURE; - } - - /* - * Verifies the header format based on the expected header for image - * type in titl-> If tparams is NULL simply check all image types - * to find one that matches our header. - */ - retval = imagetool_verify_print_header(ptr, &sbuf, tparams, itl); - - (void) munmap((void *)ptr, sbuf.st_size); - (void) close (ifd); - if (!retval) - summary_show(&itl->summary, itl->imagefile, itl->keydest); - - return retval; - } + if (itl->lflag || itl->fflag) + return list_or_process(itl, tparams, ifd); if (!itl->skipcpy && itl->type != IH_TYPE_MULTI && itl->type != IH_TYPE_SCRIPT) { if (!itl->datafile) { -- 2.43.0

This is not correct when building a kernel FIT, since it adds a second loadable in addition to the kernel. There may in fact be a bug in SPL FIT, in which case that should be fixed, rather than adding an invalid loadable to the FIT. This reverts commit cabde449b97799d4377f62b90374f261327a3a90. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/fit_image.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/fit_image.c b/tools/fit_image.c index aa71544f4cb..e2840cf48b4 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -381,7 +381,6 @@ static void fit_write_configs(struct imgtool *itl, char *fdt) typename = genimg_get_type_short_name(itl->fit_image_type); snprintf(str, sizeof(str), "%s-1", typename); fdt_property_string(fdt, typename, str); - fdt_property_string(fdt, FIT_LOADABLE_PROP, str); if (itl->fit_ramdisk) fdt_property_string(fdt, FIT_RAMDISK_PROP, -- 2.43.0

The existing name is confusing since it includes state as well as parameters. In fact it includes nearly everything known about the tool while it is running. Rename the struct to imgtool to reflect this. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/aisimage.c | 17 ++++++++--------- tools/atmelimage.c | 10 +++++----- tools/default_image.c | 10 +++++----- tools/dumpimage.c | 2 +- tools/fit_common.c | 5 ++--- tools/fit_common.h | 5 ++--- tools/fit_image.c | 26 +++++++++++++------------- tools/gpheader.h | 2 +- tools/gpimage-common.c | 2 +- tools/gpimage.c | 6 +++--- tools/imagetool.c | 8 ++++---- tools/imagetool.h | 39 ++++++++++++++++++++------------------- tools/imx8image.c | 8 ++++---- tools/imx8mimage.c | 8 ++++---- tools/imximage.c | 10 +++++----- tools/kwbimage.c | 30 +++++++++++++++--------------- tools/lpc32xximage.c | 6 +++--- tools/mkimage.c | 2 +- tools/mtk_image.c | 10 +++++----- tools/mxsimage.c | 10 +++++----- tools/omapimage.c | 6 +++--- tools/pblimage.c | 10 +++++----- tools/renesas_spkgimage.c | 11 +++++------ tools/rkcommon.c | 30 +++++++++++++++--------------- tools/rkcommon.h | 16 ++++++++-------- tools/rkimage.c | 2 +- tools/rkspi.c | 4 ++-- tools/sfspl.c | 12 ++++++------ tools/socfpgaimage.c | 24 ++++++++++++------------ tools/stm32image.c | 6 +++--- tools/sunxi_egon.c | 12 ++++++------ tools/sunxi_toc0.c | 10 +++++----- tools/ublimage.c | 8 ++++---- tools/vybridimage.c | 6 +++--- tools/zynqimage.c | 8 ++++---- tools/zynqmpbif.c | 6 +++--- tools/zynqmpimage.c | 12 ++++++------ tools/zynqmpimage.h | 2 +- 38 files changed, 199 insertions(+), 202 deletions(-) diff --git a/tools/aisimage.c b/tools/aisimage.c index 697b3c0bad7..f17eeb059de 100644 --- a/tools/aisimage.c +++ b/tools/aisimage.c @@ -113,7 +113,7 @@ static int get_ais_table_id(uint32_t *ptr) return -1; } -static void aisimage_print_header(const void *hdr, struct image_tool_params *params) +static void aisimage_print_header(const void *hdr, struct imgtool *params) { struct ais_header *ais_hdr = (struct ais_header *)hdr; uint32_t *ptr; @@ -174,7 +174,7 @@ static uint32_t *ais_insert_cmd_header(uint32_t cmd, uint32_t nargs, } -static uint32_t *ais_alloc_buffer(struct image_tool_params *params) +static uint32_t *ais_alloc_buffer(struct imgtool *params) { int dfd; struct stat sbuf; @@ -215,8 +215,7 @@ static uint32_t *ais_alloc_buffer(struct image_tool_params *params) return ptr; } -static uint32_t *ais_copy_image(struct image_tool_params *params, - uint32_t *aisptr) +static uint32_t *ais_copy_image(struct imgtool *params, uint32_t *aisptr) { int dfd; @@ -251,8 +250,8 @@ static uint32_t *ais_copy_image(struct image_tool_params *params, } -static int aisimage_generate(struct image_tool_params *params, - struct imgtool_funcs *tparams) +static int aisimage_generate(struct imgtool *params, + struct imgtool_funcs *tparams) { FILE *fd = NULL; char *line = NULL; @@ -369,7 +368,7 @@ static int aisimage_check_image_types(uint8_t type) } static int aisimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct ais_header *ais_hdr = (struct ais_header *)ptr; @@ -383,11 +382,11 @@ static int aisimage_verify_header(unsigned char *ptr, int image_size, } static void aisimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { } -int aisimage_check_params(struct image_tool_params *params) +int aisimage_check_params(struct imgtool *params) { if (!params) return CFG_INVALID; diff --git a/tools/atmelimage.c b/tools/atmelimage.c index e1909f39c45..279e26527e3 100644 --- a/tools/atmelimage.c +++ b/tools/atmelimage.c @@ -112,7 +112,7 @@ static int atmel_parse_pmecc_params(char *txt) } static int atmel_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { uint32_t *ints = (uint32_t *)ptr; size_t pos; @@ -182,7 +182,7 @@ static void atmel_print_pmecc_header(const uint32_t word) printf("\t\t====================\n"); } -static void atmel_print_header(const void *ptr, struct image_tool_params *params) +static void atmel_print_header(const void *ptr, struct imgtool *params) { uint32_t *ints = (uint32_t *)ptr; size_t pos; @@ -204,7 +204,7 @@ static void atmel_print_header(const void *ptr, struct image_tool_params *params } static void atmel_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { /* just save the image size into 6'th interrupt vector */ uint32_t *ints = (uint32_t *)ptr; @@ -224,7 +224,7 @@ static void atmel_set_header(void *ptr, struct stat *sbuf, int ifd, ints[pos] = cpu_to_le32(size); } -static int atmel_check_params(struct image_tool_params *params) +static int atmel_check_params(struct imgtool *params) { if (strlen(params->imagename) > 0) if (atmel_parse_pmecc_params(params->imagename)) @@ -237,7 +237,7 @@ static int atmel_check_params(struct image_tool_params *params) (params->lflag && !params->dflag))); } -static int atmel_vrec_header(struct image_tool_params *params, +static int atmel_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams) { uint32_t tmp; diff --git a/tools/default_image.c b/tools/default_image.c index 04bc85bf932..e7412c1cb2f 100644 --- a/tools/default_image.c +++ b/tools/default_image.c @@ -33,20 +33,20 @@ static int image_check_image_types(uint8_t type) return EXIT_FAILURE; } -static int image_check_params(struct image_tool_params *params) +static int image_check_params(struct imgtool *params) { return ((params->dflag && (params->fflag || params->lflag)) || (params->fflag && (params->dflag || params->lflag)) || (params->lflag && (params->dflag || params->fflag))); } -static void image_print_header(const void *ptr, struct image_tool_params *params) +static void image_print_header(const void *ptr, struct imgtool *params) { image_print_contents(ptr); } static int image_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { uint32_t len; const unsigned char *data; @@ -108,7 +108,7 @@ static int image_verify_header(unsigned char *ptr, int image_size, } static void image_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { uint32_t checksum; time_t time; @@ -165,7 +165,7 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd, image_set_hcrc(hdr, checksum); } -static int image_extract_subimage(void *ptr, struct image_tool_params *params) +static int image_extract_subimage(void *ptr, struct imgtool *params) { const struct legacy_img_hdr *hdr = (const struct legacy_img_hdr *)ptr; ulong file_data; diff --git a/tools/dumpimage.c b/tools/dumpimage.c index b15aee934c9..b0a8853c292 100644 --- a/tools/dumpimage.c +++ b/tools/dumpimage.c @@ -12,7 +12,7 @@ static void usage(void); /* parameters initialized by core will be used by the image type code */ -static struct image_tool_params params; +static struct imgtool params; /* * dumpimage_extract_subimage - diff --git a/tools/fit_common.c b/tools/fit_common.c index d1cde16c1cb..9e7646ac0ef 100644 --- a/tools/fit_common.c +++ b/tools/fit_common.c @@ -25,13 +25,12 @@ #define COPYFILE_BUFSIZE (64 * 1024) -void fit_print_header(const void *fit, struct image_tool_params *params) +void fit_print_header(const void *fit, struct imgtool *itl) { fit_print_contents(fit); } -int fit_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) +int fit_verify_header(unsigned char *ptr, int image_size, struct imgtool *itl) { int ret; diff --git a/tools/fit_common.h b/tools/fit_common.h index 2da4b9422d4..b1c46bfe74f 100644 --- a/tools/fit_common.h +++ b/tools/fit_common.h @@ -10,7 +10,7 @@ #include "mkimage.h" #include <image.h> -void fit_print_header(const void *fit, struct image_tool_params *params); +void fit_print_header(const void *fit, struct imgtool *params); /** * Verify the format of FIT header pointed to by ptr @@ -20,8 +20,7 @@ void fit_print_header(const void *fit, struct image_tool_params *params); * @params: mkimage parameters * Return: 0 if OK, -1 on error */ -int fit_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params); +int fit_verify_header(unsigned char *ptr, int image_size, struct imgtool *itl); int fit_check_image_types(uint8_t type); diff --git a/tools/fit_image.c b/tools/fit_image.c index caed8d5f901..be9779e0686 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -24,7 +24,7 @@ static struct legacy_img_hdr header; -static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, +static int fit_add_file_data(struct imgtool *params, size_t size_inc, const char *tmpfile) { int tfd, destfd = 0; @@ -97,7 +97,7 @@ err_keydest: /** * fit_calc_size() - Calculate the approximate size of the FIT we will generate */ -static int fit_calc_size(struct image_tool_params *params) +static int fit_calc_size(struct imgtool *params) { struct content_info *cont; int size, total_size; @@ -129,7 +129,7 @@ static int fit_calc_size(struct image_tool_params *params) return total_size; } -static int fdt_property_file(struct image_tool_params *params, +static int fdt_property_file(struct imgtool *params, void *fdt, const char *name, const char *fname) { struct stat sbuf; @@ -211,7 +211,7 @@ static void get_basename(char *str, int size, const char *fname) * a sign node to parent. Otherwise, just add a CRC. Rationale: if conf have * to be signed, image/dt have to be hashed even if there is a key name hint. */ -static void fit_add_hash_or_sign(struct image_tool_params *params, void *fdt, +static void fit_add_hash_or_sign(struct imgtool *params, void *fdt, bool is_images_subnode) { const char *hash_algo = "crc32"; @@ -262,7 +262,7 @@ static void fit_add_hash_or_sign(struct image_tool_params *params, void *fdt, * We always include the main image (params->datafile). If there are device * tree files, we include an fdt- node for each of those too. */ -static int fit_write_images(struct image_tool_params *params, char *fdt) +static int fit_write_images(struct imgtool *params, char *fdt) { struct content_info *cont; const char *typename; @@ -357,7 +357,7 @@ static int fit_write_images(struct image_tool_params *params, char *fdt) * * Otherwise we just create a configuration with the main image in it. */ -static void fit_write_configs(struct image_tool_params *params, char *fdt) +static void fit_write_configs(struct imgtool *params, char *fdt) { struct content_info *cont; const char *typename; @@ -410,7 +410,7 @@ static void fit_write_configs(struct image_tool_params *params, char *fdt) fdt_end_node(fdt); } -static int fit_build_fdt(struct image_tool_params *params, char *fdt, int size) +static int fit_build_fdt(struct imgtool *params, char *fdt, int size) { int ret; @@ -436,7 +436,7 @@ static int fit_build_fdt(struct image_tool_params *params, char *fdt, int size) return fdt_totalsize(fdt); } -static int fit_build(struct image_tool_params *params, const char *fname) +static int fit_build(struct imgtool *params, const char *fname) { char *buf; int size; @@ -493,7 +493,7 @@ err_buf: * This function cannot cope with FITs with 'data-offset' properties. All * data must be in 'data' properties on entry. */ -static int fit_extract_data(struct image_tool_params *params, const char *fname) +static int fit_extract_data(struct imgtool *params, const char *fname) { void *buf = NULL; int buf_ptr; @@ -617,7 +617,7 @@ err: return ret; } -static int fit_import_data(struct image_tool_params *params, const char *fname) +static int fit_import_data(struct imgtool *params, const char *fname) { void *fdt, *old_fdt; void *data = NULL; @@ -744,7 +744,7 @@ err: * returns: * only on success, otherwise calls exit (EXIT_FAILURE); */ -static int fit_handle_file(struct image_tool_params *params) +static int fit_handle_file(struct imgtool *params) { char tmpfile[MKIMAGE_MAX_TMPFILE_LEN]; char bakfile[MKIMAGE_MAX_TMPFILE_LEN + 4] = {0}; @@ -894,7 +894,7 @@ static int fit_image_extract( * returns: * zero in case of success or a negative value if fail. */ -static int fit_extract_contents(void *ptr, struct image_tool_params *params) +static int fit_extract_contents(void *ptr, struct imgtool *params) { int images_noffset; int noffset; @@ -948,7 +948,7 @@ static int fit_extract_contents(void *ptr, struct image_tool_params *params) return 0; } -static int fit_check_params(struct image_tool_params *params) +static int fit_check_params(struct imgtool *params) { if (params->auto_fit) return 0; diff --git a/tools/gpheader.h b/tools/gpheader.h index d5bf86e5893..7f71a1db3f9 100644 --- a/tools/gpheader.h +++ b/tools/gpheader.h @@ -35,5 +35,5 @@ int gph_verify_header(struct gp_header *gph, int be); void gph_print_header(const struct gp_header *gph, int be); void gph_set_header(struct gp_header *gph, uint32_t size, uint32_t load_addr, int be); -int gpimage_check_params(struct image_tool_params *params); +int gpimage_check_params(struct imgtool *params); #endif diff --git a/tools/gpimage-common.c b/tools/gpimage-common.c index fc6406b9133..3486819f4ca 100644 --- a/tools/gpimage-common.c +++ b/tools/gpimage-common.c @@ -72,7 +72,7 @@ void gph_set_header(struct gp_header *gph, uint32_t size, uint32_t load_addr, to_be32(&gph->size, &gph->load_addr); } -int gpimage_check_params(struct image_tool_params *params) +int gpimage_check_params(struct imgtool *params) { return (params->dflag && (params->fflag || params->lflag)) || (params->fflag && (params->dflag || params->lflag)) || diff --git a/tools/gpimage.c b/tools/gpimage.c index d2bc79d46b9..ac138ac9a6b 100644 --- a/tools/gpimage.c +++ b/tools/gpimage.c @@ -34,14 +34,14 @@ static int gpimage_check_image_types(uint8_t type) } static int gpimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct gp_header *gph = (struct gp_header *)ptr; return gph_verify_header(gph, 1); } -static void gpimage_print_header(const void *ptr, struct image_tool_params *params) +static void gpimage_print_header(const void *ptr, struct imgtool *params) { const struct gp_header *gph = (struct gp_header *)ptr; @@ -49,7 +49,7 @@ static void gpimage_print_header(const void *ptr, struct image_tool_params *para } static void gpimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { struct gp_header *gph = (struct gp_header *)ptr; diff --git a/tools/imagetool.c b/tools/imagetool.c index b36b8d735a4..726c3ceb2b2 100644 --- a/tools/imagetool.c +++ b/tools/imagetool.c @@ -30,13 +30,13 @@ static int imagetool_verify_print_header_by_type( void *ptr, struct stat *sbuf, struct imgtool_funcs *tparams, - struct image_tool_params *params); + struct imgtool *params); int imagetool_verify_print_header( void *ptr, struct stat *sbuf, struct imgtool_funcs *tparams, - struct image_tool_params *params) + struct imgtool *params) { int retval = -1; struct imgtool_funcs **curr; @@ -89,7 +89,7 @@ static int imagetool_verify_print_header_by_type( void *ptr, struct stat *sbuf, struct imgtool_funcs *tparams, - struct image_tool_params *params) + struct imgtool *params) { int retval = -1; @@ -150,7 +150,7 @@ int imagetool_save_subimage( return 0; } -int imagetool_get_filesize(struct image_tool_params *params, const char *fname) +int imagetool_get_filesize(struct imgtool *params, const char *fname) { struct stat sbuf; int fd; diff --git a/tools/imagetool.h b/tools/imagetool.h index 3cbb053e42b..42c8d8c8742 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -48,11 +48,13 @@ enum af_mode { }; /* + * struct imgtool() - Defines mkimage/dumpimage parameters and variables + * * This structure defines all such variables those are initialized by - * mkimage and dumpimage main core and need to be referred by image - * type specific functions + * mkimage and dumpimage main core and need to be referred by + * image-type-specific functions */ -struct image_tool_params { +struct imgtool { int dflag; int eflag; int fflag; @@ -120,7 +122,7 @@ struct imgtool_funcs { * * Returns 1 if parameter check is successful */ - int (*check_params) (struct image_tool_params *); + int (*check_params)(struct imgtool *itl); /* * This function is used by list command (i.e. mkimage -l <filename>) * image type verification code must be put here @@ -128,17 +130,17 @@ struct imgtool_funcs { * Returns 0 if image header verification is successful * otherwise, returns respective negative error codes */ - int (*verify_header) (unsigned char *, int, struct image_tool_params *); + int (*verify_header)(unsigned char *, int, struct imgtool *itl); /* Prints image information abstracting from image header */ - void (*print_header) (const void *, struct image_tool_params *); + void (*print_header)(const void *, struct imgtool *itl); /* * The header or image contents need to be set as per image type to * be generated using this callback function. * further output file post processing (for ex. checksum calculation, * padding bytes etc..) can also be done in this callback function. */ - void (*set_header) (void *, struct stat *, int, - struct image_tool_params *); + void (*set_header)(void *data, struct stat *sbuf, int ifd, + struct imgtool *itl); /* * This function is used by the command to retrieve a component * (sub-image) from the image (i.e. dumpimage -p <position> @@ -148,7 +150,7 @@ struct imgtool_funcs { * Returns 0 if the file was successfully retrieved from the image, * or a negative value on error. */ - int (*extract_subimage)(void *, struct image_tool_params *); + int (*extract_subimage)(void *, struct imgtool *itl); /* * Some image generation support for ex (default image type) supports * more than one type_ids, this callback function is used to check @@ -157,7 +159,7 @@ struct imgtool_funcs { */ int (*check_image_type) (uint8_t); /* This callback function will be executed if fflag is defined */ - int (*fflag_handle) (struct image_tool_params *); + int (*fflag_handle)(struct imgtool *itl); /* * This callback function will be executed for variable size record * It is expected to build this header in memory and return its length @@ -166,8 +168,7 @@ struct imgtool_funcs { * additional padding should be used when copying the data image * by returning the padding length. */ - int (*vrec_header)(struct image_tool_params *, - struct imgtool_funcs *funcs); + int (*vrec_header)(struct imgtool *itl, struct imgtool_funcs *funcs); }; /** @@ -202,7 +203,7 @@ int imagetool_verify_print_header( void *ptr, struct stat *sbuf, struct imgtool_funcs *tparams, - struct image_tool_params *params); + struct imgtool *params); /** * imagetool_save_subimage - store data into a file @@ -231,7 +232,7 @@ int imagetool_save_subimage( * @fname: filename to check * Return: size of file, or -ve value on error */ -int imagetool_get_filesize(struct image_tool_params *params, const char *fname); +int imagetool_get_filesize(struct imgtool *params, const char *fname); /** * imagetool_get_source_date() - Get timestamp for build output. @@ -254,11 +255,11 @@ time_t imagetool_get_source_date( * for ex. default_image.c, fit_image.c */ -void pbl_load_uboot(int fd, struct image_tool_params *mparams); -int zynqmpbif_copy_image(int fd, struct image_tool_params *mparams); -int imx8image_copy_image(int fd, struct image_tool_params *mparams); -int imx8mimage_copy_image(int fd, struct image_tool_params *mparams); -int rockchip_copy_image(int fd, struct image_tool_params *mparams); +void pbl_load_uboot(int fd, struct imgtool *mparams); +int zynqmpbif_copy_image(int fd, struct imgtool *mparams); +int imx8image_copy_image(int fd, struct imgtool *mparams); +int imx8mimage_copy_image(int fd, struct imgtool *mparams); +int rockchip_copy_image(int fd, struct imgtool *mparams); #define ___cat(a, b) a ## b #define __cat(a, b) ___cat(a, b) diff --git a/tools/imx8image.c b/tools/imx8image.c index a333ded46e2..bb15f078541 100644 --- a/tools/imx8image.c +++ b/tools/imx8image.c @@ -22,17 +22,17 @@ static uint16_t sw_version; static uint32_t custom_partition; static uint32_t scfw_flags; -int imx8image_check_params(struct image_tool_params *params) +int imx8image_check_params(struct imgtool *params) { return 0; } static void imx8image_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { } -static void imx8image_print_header(const void *ptr, struct image_tool_params *params) +static void imx8image_print_header(const void *ptr, struct imgtool *params) { } @@ -1125,7 +1125,7 @@ static int build_container(soc_type_t soc, uint32_t sector_size, return 0; } -int imx8image_copy_image(int outfd, struct image_tool_params *mparams) +int imx8image_copy_image(int outfd, struct imgtool *itl) { image_t *img_sp = param_stack; diff --git a/tools/imx8mimage.c b/tools/imx8mimage.c index 0f24ba75c0f..ecff9aff04d 100644 --- a/tools/imx8mimage.c +++ b/tools/imx8mimage.c @@ -49,17 +49,17 @@ static uint32_t get_cfg_value(char *token, char *name, int linenr) return value; } -int imx8mimage_check_params(struct image_tool_params *params) +int imx8mimage_check_params(struct imgtool *params) { return 0; } static void imx8mimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { } -static void imx8mimage_print_header(const void *ptr, struct image_tool_params *params) +static void imx8mimage_print_header(const void *ptr, struct imgtool *params) { } @@ -688,7 +688,7 @@ void build_image(int ofd) sld_load_addr, sld_header_off, sld_csf_off - sld_header_off); } -int imx8mimage_copy_image(int outfd, struct image_tool_params *mparams) +int imx8mimage_copy_image(int outfd, struct imgtool *mparams) { /* * SECO FW is a container image, this is to calculate the diff --git a/tools/imximage.c b/tools/imximage.c index 7a5dde617d9..9dd962e144f 100644 --- a/tools/imximage.c +++ b/tools/imximage.c @@ -803,7 +803,7 @@ static int imximage_check_image_types(uint8_t type) } static int imximage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct imx_header *imx_hdr = (struct imx_header *) ptr; @@ -813,7 +813,7 @@ static int imximage_verify_header(unsigned char *ptr, int image_size, return 0; } -static void imximage_print_header(const void *ptr, struct image_tool_params *params) +static void imximage_print_header(const void *ptr, struct imgtool *params) { struct imx_header *imx_hdr = (struct imx_header *) ptr; uint32_t version = detect_imximage_version(imx_hdr); @@ -832,7 +832,7 @@ static void imximage_print_header(const void *ptr, struct image_tool_params *par } static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { struct imx_header *imxhdr = (struct imx_header *)ptr; uint32_t dcd_len; @@ -886,7 +886,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd, } } -int imximage_check_params(struct image_tool_params *params) +int imximage_check_params(struct imgtool *params) { if (!params) return CFG_INVALID; @@ -966,7 +966,7 @@ static void generate_fspi_header(int ifd) } #endif -static int imximage_generate(struct image_tool_params *params, +static int imximage_generate(struct imgtool *params, struct imgtool_funcs *tparams) { struct imx_header *imxhdr; diff --git a/tools/kwbimage.c b/tools/kwbimage.c index d6c7206868e..03c818221c2 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -486,7 +486,7 @@ static int kwb_load_rsa_key(const char *keydir, const char *name, RSA **p_rsa) return 0; } -static int kwb_load_cfg_key(struct image_tool_params *params, +static int kwb_load_cfg_key(struct imgtool *params, unsigned int cfg_option, const char *key_name, RSA **p_key) { @@ -513,12 +513,12 @@ static int kwb_load_cfg_key(struct image_tool_params *params, return 0; } -static int kwb_load_kak(struct image_tool_params *params, RSA **p_kak) +static int kwb_load_kak(struct imgtool *params, RSA **p_kak) { return kwb_load_cfg_key(params, IMAGE_CFG_KAK, "KAK", p_kak); } -static int kwb_load_csk(struct image_tool_params *params, RSA **p_csk) +static int kwb_load_csk(struct imgtool *params, RSA **p_csk) { return kwb_load_cfg_key(params, IMAGE_CFG_CSK, "CSK", p_csk); } @@ -929,7 +929,7 @@ done: return ret; } -static int image_fill_xip_header(void *image, struct image_tool_params *params) +static int image_fill_xip_header(void *image, struct imgtool *params) { struct main_hdr_v1 *main_hdr = image; /* kwbimage v0 and v1 have same XIP members */ int version = kwbimage_version(image); @@ -1039,7 +1039,7 @@ static size_t image_headersz_v0(int *hasext) return headersz; } -static void *image_create_v0(size_t *dataoff, struct image_tool_params *params, +static void *image_create_v0(size_t *dataoff, struct imgtool *params, int payloadsz) { struct image_cfg_element *e; @@ -1369,7 +1369,7 @@ static int export_pub_kak_hash(RSA *kak, struct secure_hdr_v1 *secure_hdr) return res < 0 ? 1 : 0; } -static int kwb_sign_csk_with_kak(struct image_tool_params *params, +static int kwb_sign_csk_with_kak(struct imgtool *params, struct secure_hdr_v1 *secure_hdr, RSA *csk) { RSA *kak = NULL; @@ -1411,7 +1411,7 @@ static int kwb_sign_csk_with_kak(struct image_tool_params *params, return 0; } -static int add_secure_header_v1(struct image_tool_params *params, uint8_t *image_ptr, +static int add_secure_header_v1(struct imgtool *params, uint8_t *image_ptr, size_t image_size, uint8_t *header_ptr, size_t headersz, struct secure_hdr_v1 *secure_hdr) { @@ -1474,7 +1474,7 @@ static void finish_register_set_header_v1(uint8_t **cur, uint8_t **next_ext, *datai = 0; } -static void *image_create_v1(size_t *dataoff, struct image_tool_params *params, +static void *image_create_v1(size_t *dataoff, struct imgtool *params, uint8_t *ptr, int payloadsz) { struct image_cfg_element *e; @@ -1905,7 +1905,7 @@ static int image_get_version(void) } static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { FILE *fcfg; void *image = NULL; @@ -1997,7 +1997,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, free(image); } -static void kwbimage_print_header(const void *ptr, struct image_tool_params *params) +static void kwbimage_print_header(const void *ptr, struct imgtool *params) { struct main_hdr_v0 *mhdr = (struct main_hdr_v0 *)ptr; struct bin_hdr_v0 *bhdr; @@ -2052,7 +2052,7 @@ static int kwbimage_check_image_types(uint8_t type) } static int kwbimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { size_t header_size = kwbheader_size(ptr); uint8_t blockid; @@ -2159,7 +2159,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, return 0; } -static int kwbimage_generate(struct image_tool_params *params, +static int kwbimage_generate(struct imgtool *params, struct imgtool_funcs *tparams) { FILE *fcfg; @@ -2291,7 +2291,7 @@ static int kwbimage_generate(struct image_tool_params *params, } } -static int kwbimage_generate_config(void *ptr, struct image_tool_params *params) +static int kwbimage_generate_config(void *ptr, struct imgtool *params) { struct main_hdr_v0 *mhdr0 = (struct main_hdr_v0 *)ptr; struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr; @@ -2511,7 +2511,7 @@ static int kwbimage_generate_config(void *ptr, struct image_tool_params *params) return 0; } -static int kwbimage_extract_subimage(void *ptr, struct image_tool_params *params) +static int kwbimage_extract_subimage(void *ptr, struct imgtool *params) { struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr; size_t header_size = kwbheader_size(ptr); @@ -2581,7 +2581,7 @@ static int kwbimage_extract_subimage(void *ptr, struct image_tool_params *params return imagetool_save_subimage(params->outfile, image, size); } -static int kwbimage_check_params(struct image_tool_params *params) +static int kwbimage_check_params(struct imgtool *params) { if (!params->lflag && !params->iflag && !params->pflag && (!params->imagename || !strlen(params->imagename))) { diff --git a/tools/lpc32xximage.c b/tools/lpc32xximage.c index 715a55a5b5b..d1e5efea44c 100644 --- a/tools/lpc32xximage.c +++ b/tools/lpc32xximage.c @@ -80,7 +80,7 @@ static int lpc32xximage_check_image_types(uint8_t type) } static int lpc32xximage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; @@ -125,7 +125,7 @@ static void print_hdr_byte(struct nand_page_0_boot_header *hdr, int ofs) printf("header[%d] = %02x\n", ofs, hdr->data[ofs]); } -static void lpc32xximage_print_header(const void *ptr, struct image_tool_params *params) +static void lpc32xximage_print_header(const void *ptr, struct imgtool *params) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; @@ -137,7 +137,7 @@ static void lpc32xximage_print_header(const void *ptr, struct image_tool_params } static void lpc32xximage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; diff --git a/tools/mkimage.c b/tools/mkimage.c index 6e50254452d..03492c795aa 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -19,7 +19,7 @@ #endif /* parameters initialized by core will be used by the image type code */ -static struct image_tool_params params = { +static struct imgtool params = { .os = IH_OS_LINUX, .arch = IH_ARCH_PPC, .type = IH_TYPE_KERNEL, diff --git a/tools/mtk_image.c b/tools/mtk_image.c index 8a22b4ef789..deaa2ed930f 100644 --- a/tools/mtk_image.c +++ b/tools/mtk_image.c @@ -228,7 +228,7 @@ static int mtk_brom_parse_imagename(const char *imagename) return 0; } -static int mtk_image_check_params(struct image_tool_params *params) +static int mtk_image_check_params(struct imgtool *params) { if (!params->addr) { fprintf(stderr, "Error: Load Address must be set.\n"); @@ -243,7 +243,7 @@ static int mtk_image_check_params(struct image_tool_params *params) return mtk_brom_parse_imagename(params->imagename); } -static int mtk_image_vrec_header(struct image_tool_params *params, +static int mtk_image_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams) { if (use_lk_hdr) { @@ -488,7 +488,7 @@ static int mtk_image_verify_mt7621_header(const uint8_t *ptr, int print) } static int mtk_image_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct legacy_img_hdr *hdr = (struct legacy_img_hdr *)ptr; union lk_hdr *lk = (union lk_hdr *)ptr; @@ -510,7 +510,7 @@ static int mtk_image_verify_header(unsigned char *ptr, int image_size, return -1; } -static void mtk_image_print_header(const void *ptr, struct image_tool_params *params) +static void mtk_image_print_header(const void *ptr, struct imgtool *params) { struct legacy_img_hdr *hdr = (struct legacy_img_hdr *)ptr; union lk_hdr *lk = (union lk_hdr *)ptr; @@ -730,7 +730,7 @@ static void mtk_image_set_mt7621_header(void *ptr, off_t filesize, } static void mtk_image_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { union lk_hdr *lk = (union lk_hdr *)ptr; diff --git a/tools/mxsimage.c b/tools/mxsimage.c index 45c6e3624c9..1e483a74c9d 100644 --- a/tools/mxsimage.c +++ b/tools/mxsimage.c @@ -2171,11 +2171,11 @@ static int mxsimage_check_image_types(uint8_t type) } static void mxsimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { } -int mxsimage_check_params(struct image_tool_params *params) +int mxsimage_check_params(struct imgtool *params) { if (!params) return -1; @@ -2216,7 +2216,7 @@ static int mxsimage_verify_print_header(char *file, int silent) char *imagefile; static int mxsimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct sb_boot_image_header *hdr; @@ -2238,7 +2238,7 @@ static int mxsimage_verify_header(unsigned char *ptr, int image_size, return mxsimage_verify_print_header(params->imagefile, 1); } -static void mxsimage_print_header(const void *hdr, struct image_tool_params *params) +static void mxsimage_print_header(const void *hdr, struct imgtool *params) { if (imagefile) mxsimage_verify_print_header(imagefile, 0); @@ -2314,7 +2314,7 @@ static int sb_build_image(struct sb_image_ctx *ictx, return 0; } -static int mxsimage_generate(struct image_tool_params *params, +static int mxsimage_generate(struct imgtool *params, struct imgtool_funcs *tparams) { int ret; diff --git a/tools/omapimage.c b/tools/omapimage.c index b79c1c3b648..428dc782f9b 100644 --- a/tools/omapimage.c +++ b/tools/omapimage.c @@ -37,7 +37,7 @@ static int omapimage_check_image_types(uint8_t type) } static int omapimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct ch_toc *toc = (struct ch_toc *)ptr; struct gp_header *gph = (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE); @@ -85,7 +85,7 @@ static void omapimage_print_section(struct ch_settings *chs) chs->flags); } -static void omapimage_print_header(const void *ptr, struct image_tool_params *params) +static void omapimage_print_header(const void *ptr, struct imgtool *params) { const struct ch_toc *toc = (struct ch_toc *)ptr; const struct gp_header *gph = @@ -124,7 +124,7 @@ static int toc_offset(void *hdr, void *member) } static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { struct ch_toc *toc = (struct ch_toc *)ptr; struct ch_settings *chs = (struct ch_settings *) diff --git a/tools/pblimage.c b/tools/pblimage.c index 34650cf7b7c..17dff95c46d 100644 --- a/tools/pblimage.c +++ b/tools/pblimage.c @@ -185,7 +185,7 @@ static void add_end_cmd(void) pbl_size += 4; } -void pbl_load_uboot(int ifd, struct image_tool_params *params) +void pbl_load_uboot(int ifd, struct imgtool *params) { FILE *fp_uboot; int size, ret; @@ -232,7 +232,7 @@ static int pblimage_check_image_types(uint8_t type) } static int pblimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct pbl_header *pbl_hdr = (struct pbl_header *) ptr; uint32_t rcwheader; @@ -259,18 +259,18 @@ static int pblimage_verify_header(unsigned char *ptr, int image_size, return 0; } -static void pblimage_print_header(const void *ptr, struct image_tool_params *params) +static void pblimage_print_header(const void *ptr, struct imgtool *params) { printf("Image Type: Freescale PBL Boot Image\n"); } static void pblimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { /*nothing need to do, pbl_load_uboot takes care of whole file. */ } -int pblimage_check_params(struct image_tool_params *params) +int pblimage_check_params(struct imgtool *params) { FILE *fp_uboot; int fd; diff --git a/tools/renesas_spkgimage.c b/tools/renesas_spkgimage.c index ed80aec3c6b..8cc3a62081a 100644 --- a/tools/renesas_spkgimage.c +++ b/tools/renesas_spkgimage.c @@ -115,7 +115,7 @@ static int spkgimage_parse_config_file(char *filename) return 0; } -static int spkgimage_check_params(struct image_tool_params *params) +static int spkgimage_check_params(struct imgtool *params) { if (!params->addr) { fprintf(stderr, "Error: Load Address must be set.\n"); @@ -136,7 +136,7 @@ static int spkgimage_check_params(struct image_tool_params *params) } static int spkgimage_verify_header(unsigned char *ptr, int size, - struct image_tool_params *param) + struct imgtool *param) { struct spkg_file *file = (struct spkg_file *)ptr; struct spkg_hdr *header = (struct spkg_hdr *)ptr; @@ -182,8 +182,7 @@ static int spkgimage_verify_header(unsigned char *ptr, int size, return 0; } -static void spkgimage_print_header(const void *ptr, - struct image_tool_params *image) +static void spkgimage_print_header(const void *ptr, struct imgtool *image) { const struct spkg_hdr *h = ptr; uint32_t offset = le32_to_cpu(h->execution_offset); @@ -216,7 +215,7 @@ static inline uint32_t roundup(uint32_t x, uint32_t y) return ((x + y - 1) / y) * y; } -static int spkgimage_vrec_header(struct image_tool_params *params, +static int spkgimage_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams) { struct stat s; @@ -282,7 +281,7 @@ static int spkgimage_vrec_header(struct image_tool_params *params, } static void spkgimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { uint8_t *payload = ptr + SPKG_HEADER_SIZE * SPKG_HEADER_COUNT; uint8_t *file_end = payload + conf.blp_len + params->orig_file_size; diff --git a/tools/rkcommon.c b/tools/rkcommon.c index f938b524329..860008d4c81 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -177,7 +177,7 @@ static struct spl_info *rkcommon_get_spl_info(char *imagename) return NULL; } -static int rkcommon_get_aligned_size(struct image_tool_params *params, +static int rkcommon_get_aligned_size(struct imgtool *params, const char *fname) { int size; @@ -193,7 +193,7 @@ static int rkcommon_get_aligned_size(struct image_tool_params *params, return ROUND(size, RK_SIZE_ALIGN); } -int rkcommon_check_params(struct image_tool_params *params) +int rkcommon_check_params(struct imgtool *params) { int i, size; @@ -249,7 +249,7 @@ err_spl_info: return EXIT_FAILURE; } -const char *rkcommon_get_spl_hdr(struct image_tool_params *params) +const char *rkcommon_get_spl_hdr(struct imgtool *params) { struct spl_info *info = rkcommon_get_spl_info(params->imagename); @@ -259,7 +259,7 @@ const char *rkcommon_get_spl_hdr(struct image_tool_params *params) return info->spl_hdr; } -int rkcommon_get_spl_size(struct image_tool_params *params) +int rkcommon_get_spl_size(struct imgtool *params) { struct spl_info *info = rkcommon_get_spl_info(params->imagename); @@ -269,7 +269,7 @@ int rkcommon_get_spl_size(struct image_tool_params *params) return info->spl_size; } -bool rkcommon_need_rc4_spl(struct image_tool_params *params) +bool rkcommon_need_rc4_spl(struct imgtool *params) { struct spl_info *info = rkcommon_get_spl_info(params->imagename); @@ -279,7 +279,7 @@ bool rkcommon_need_rc4_spl(struct image_tool_params *params) return info->spl_rc4; } -bool rkcommon_is_header_v2(struct image_tool_params *params) +bool rkcommon_is_header_v2(struct imgtool *params) { struct spl_info *info = rkcommon_get_spl_info(params->imagename); @@ -295,7 +295,7 @@ static void do_sha256_hash(uint8_t *buf, uint32_t size, uint8_t *out) sha256_finish(&ctx, out); } -static void rkcommon_set_header0(void *buf, struct image_tool_params *params) +static void rkcommon_set_header0(void *buf, struct imgtool *params) { struct header0_info *hdr = buf; uint32_t init_boot_size; @@ -323,7 +323,7 @@ static void rkcommon_set_header0(void *buf, struct image_tool_params *params) rc4_encode(buf, RK_BLK_SIZE, rc4_key); } -static void rkcommon_set_header0_v2(void *buf, struct image_tool_params *params) +static void rkcommon_set_header0_v2(void *buf, struct imgtool *params) { struct header0_info_v2 *hdr = buf; uint32_t sector_offset, image_sector_count; @@ -357,7 +357,7 @@ static void rkcommon_set_header0_v2(void *buf, struct image_tool_params *params) } void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { struct header1_info *hdr = buf + RK_SPL_HDR_START; @@ -449,7 +449,7 @@ static int rkcommon_parse_header_v2(const void *buf, struct header0_info_v2 *hea } int rkcommon_verify_header(unsigned char *buf, int size, - struct image_tool_params *params) + struct imgtool *params) { struct header0_info header0; struct spl_info *img_spl_info, *spl_info; @@ -483,7 +483,7 @@ int rkcommon_verify_header(unsigned char *buf, int size, return -ENOENT; } -void rkcommon_print_header(const void *buf, struct image_tool_params *params) +void rkcommon_print_header(const void *buf, struct imgtool *params) { struct header0_info header0; struct header0_info_v2 header0_v2; @@ -543,7 +543,7 @@ void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size) } } -int rkcommon_vrec_header(struct image_tool_params *params, +int rkcommon_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams) { /* @@ -591,7 +591,7 @@ int rkcommon_vrec_header(struct image_tool_params *params, return 0; } -static int pad_file(struct image_tool_params *params, int ifd, int pad) +static int pad_file(struct imgtool *params, int ifd, int pad) { uint8_t zeros[4096]; @@ -614,7 +614,7 @@ static int pad_file(struct image_tool_params *params, int ifd, int pad) return 0; } -static int copy_file(struct image_tool_params *params, int ifd, +static int copy_file(struct imgtool *params, int ifd, const char *file, int padded_size) { int dfd; @@ -667,7 +667,7 @@ err_close: return -1; } -int rockchip_copy_image(int ifd, struct image_tool_params *params) +int rockchip_copy_image(int ifd, struct imgtool *params) { int ret; diff --git a/tools/rkcommon.h b/tools/rkcommon.h index 792a046c7af..50db6d3799c 100644 --- a/tools/rkcommon.h +++ b/tools/rkcommon.h @@ -21,7 +21,7 @@ enum { * * Return: 0 if OK, -1 if ERROR. */ -int rkcommon_check_params(struct image_tool_params *params); +int rkcommon_check_params(struct imgtool *params); /** * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image @@ -29,7 +29,7 @@ int rkcommon_check_params(struct image_tool_params *params); * Rockchip's bootrom requires the spl loader to start with a 4-bytes * header. The content of this header depends on the chip type. */ -const char *rkcommon_get_spl_hdr(struct image_tool_params *params); +const char *rkcommon_get_spl_hdr(struct imgtool *params); /** * rkcommon_get_spl_size() - get spl size for a Rockchip boot image @@ -39,7 +39,7 @@ const char *rkcommon_get_spl_hdr(struct image_tool_params *params); * for the bootrom. * The spl loader size should be sram size minus reserved size(if needed) */ -int rkcommon_get_spl_size(struct image_tool_params *params); +int rkcommon_get_spl_size(struct imgtool *params); /** * rkcommon_set_header() - set up the header for a Rockchip boot image @@ -49,7 +49,7 @@ int rkcommon_get_spl_size(struct image_tool_params *params); * @buf: Pointer to header place (must be at least 2KB in size) */ void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd, - struct image_tool_params *params); + struct imgtool *params); /** * rkcommon_verify_header() - verify the header for a Rockchip boot image @@ -59,7 +59,7 @@ void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd, * Return: 0 if OK */ int rkcommon_verify_header(unsigned char *buf, int size, - struct image_tool_params *params); + struct imgtool *params); /** * rkcommon_print_header() - print the header for a Rockchip boot image @@ -68,7 +68,7 @@ int rkcommon_verify_header(unsigned char *buf, int size, * * @buf: Pointer to the image (can be a read-only file-mapping) */ -void rkcommon_print_header(const void *buf, struct image_tool_params *params); +void rkcommon_print_header(const void *buf, struct imgtool *params); /** * rkcommon_need_rc4_spl() - check if rc4 encoded spl is required @@ -78,7 +78,7 @@ void rkcommon_print_header(const void *buf, struct image_tool_params *params); * handle unencrypted binaries. * Return: true or false depending on rc4 being required. */ -bool rkcommon_need_rc4_spl(struct image_tool_params *params); +bool rkcommon_need_rc4_spl(struct imgtool *params); /** * rkcommon_rc4_encode_spl() - encode the spl binary @@ -101,7 +101,7 @@ void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size); * * Return: 0 (always) */ -int rkcommon_vrec_header(struct image_tool_params *params, +int rkcommon_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams); #endif diff --git a/tools/rkimage.c b/tools/rkimage.c index 1c5540b1c3d..0fcf75f1b90 100644 --- a/tools/rkimage.c +++ b/tools/rkimage.c @@ -13,7 +13,7 @@ static uint32_t header; static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { memcpy(buf, rkcommon_get_spl_hdr(params), RK_SPL_HDR_SIZE); diff --git a/tools/rkspi.c b/tools/rkspi.c index 284d9dbc02c..4409b96dc10 100644 --- a/tools/rkspi.c +++ b/tools/rkspi.c @@ -17,7 +17,7 @@ enum { }; static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { int sector; unsigned int size; @@ -57,7 +57,7 @@ static int rkspi_check_image_type(uint8_t type) * The SPI payload needs to make space for odd half-sector layout used in flash * (i.e. only the first 2K of each 4K sector is used). */ -static int rkspi_vrec_header(struct image_tool_params *params, +static int rkspi_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams) { rkcommon_vrec_header(params, tparams); diff --git a/tools/sfspl.c b/tools/sfspl.c index e0c15243c9d..996f9009c52 100644 --- a/tools/sfspl.c +++ b/tools/sfspl.c @@ -46,7 +46,7 @@ struct spl_hdr { unsigned int zero2[91]; }; -static int sfspl_check_params(struct image_tool_params *params) +static int sfspl_check_params(struct imgtool *params) { /* Only the RISC-V architecture is supported */ if (params->Aflag && params->arch != IH_ARCH_RISCV) @@ -56,7 +56,7 @@ static int sfspl_check_params(struct image_tool_params *params) } static int sfspl_verify_header(unsigned char *buf, int size, - struct image_tool_params *params) + struct imgtool *params) { struct spl_hdr *hdr = (void *)buf; unsigned int hdr_size = le32_to_cpu(hdr->hdr_size); @@ -87,7 +87,7 @@ static int sfspl_verify_header(unsigned char *buf, int size, } static void sfspl_print_header(const void *buf, - struct image_tool_params *params) + struct imgtool *params) { struct spl_hdr *hdr = (void *)buf; unsigned int hdr_size = le32_to_cpu(hdr->hdr_size); @@ -98,7 +98,7 @@ static void sfspl_print_header(const void *buf, } static int sfspl_image_extract_subimage(void *ptr, - struct image_tool_params *params) + struct imgtool *params) { struct spl_hdr *hdr = (void *)ptr; unsigned char *buf = ptr; @@ -134,7 +134,7 @@ static int sfspl_check_image_type(uint8_t type) } static void sfspl_set_header(void *buf, struct stat *sbuf, int infd, - struct image_tool_params *params) + struct imgtool *params) { struct spl_hdr *hdr = buf; unsigned int file_size; @@ -152,7 +152,7 @@ static void sfspl_set_header(void *buf, struct stat *sbuf, int infd, hdr->crc32 = cpu_to_le32(crc); } -static int sfspl_vrec_header(struct image_tool_params *params, +static int sfspl_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams) { tparams->hdr = calloc(sizeof(struct spl_hdr), 1); diff --git a/tools/socfpgaimage.c b/tools/socfpgaimage.c index 64c5f498355..9f3b459a243 100644 --- a/tools/socfpgaimage.c +++ b/tools/socfpgaimage.c @@ -131,7 +131,7 @@ static uint16_t sfp_hdr_checksum(uint8_t *buf, unsigned char ver) static void sfp_build_header(uint8_t *buf, uint8_t ver, uint8_t flags, uint32_t length_bytes, - struct image_tool_params *params) + struct imgtool *params) { uint32_t entry_offset = params->eflag ? params->ep : ENTRY_POINT_OFFSET; struct socfpga_header_v0 header_v0 = { @@ -212,7 +212,7 @@ static int sfp_verify_header(const uint8_t *buf, uint8_t *ver) /* Sign the buffer and return the signed buffer size */ static int sfp_sign_buffer(uint8_t *buf, uint8_t ver, uint8_t flags, int len, int pad_64k, - struct image_tool_params *params) + struct imgtool *params) { uint32_t calc_crc; uint32_t crc_off; @@ -275,7 +275,7 @@ static int sfp_verify_buffer(const uint8_t *buf) /* mkimage glue functions */ static int socfpgaimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { if (image_size < 0x80) return -1; @@ -313,7 +313,7 @@ static void socfpgaimage_print_header_v1(struct socfpga_header_v1 *header) le16_to_cpu(header->checksum)); } -static void socfpgaimage_print_header(const void *ptr, struct image_tool_params *params) +static void socfpgaimage_print_header(const void *ptr, struct imgtool *params) { const void *header = ptr + HEADER_OFFSET; struct socfpga_header_v0 *header_v0; @@ -330,7 +330,7 @@ static void socfpgaimage_print_header(const void *ptr, struct image_tool_params } } -static int socfpgaimage_check_params_v0(struct image_tool_params *params) +static int socfpgaimage_check_params_v0(struct imgtool *params) { /* Not sure if we should be accepting fflags */ return (params->dflag && (params->fflag || params->lflag)) || @@ -338,7 +338,7 @@ static int socfpgaimage_check_params_v0(struct image_tool_params *params) (params->lflag && (params->dflag || params->fflag)); } -static int socfpgaimage_check_params_v1(struct image_tool_params *params) +static int socfpgaimage_check_params_v1(struct imgtool *params) { /* * If the entry point is specified, ensure it is >= ENTRY_POINT_OFFSET @@ -397,7 +397,7 @@ static int sfp_fake_header_size(unsigned int size, uint8_t ver) return align_size - size; } -static int sfp_vrec_header(struct image_tool_params *params, +static int sfp_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams, uint8_t ver) { struct stat sbuf; @@ -412,20 +412,20 @@ static int sfp_vrec_header(struct image_tool_params *params, } -static int socfpgaimage_vrec_header_v0(struct image_tool_params *params, +static int socfpgaimage_vrec_header_v0(struct imgtool *params, struct imgtool_funcs *tparams) { return sfp_vrec_header(params, tparams, 0); } -static int socfpgaimage_vrec_header_v1(struct image_tool_params *params, +static int socfpgaimage_vrec_header_v1(struct imgtool *params, struct imgtool_funcs *tparams) { return sfp_vrec_header(params, tparams, 1); } static void sfp_set_header(void *ptr, unsigned char ver, - struct image_tool_params *params) + struct imgtool *params) { uint8_t *buf = (uint8_t *)ptr; @@ -443,13 +443,13 @@ static void sfp_set_header(void *ptr, unsigned char ver, } static void socfpgaimage_set_header_v0(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { sfp_set_header(ptr, 0, params); } static void socfpgaimage_set_header_v1(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { sfp_set_header(ptr, 1, params); } diff --git a/tools/stm32image.c b/tools/stm32image.c index 5c6991f35de..52511af51e8 100644 --- a/tools/stm32image.c +++ b/tools/stm32image.c @@ -78,7 +78,7 @@ static int stm32image_check_image_types(uint8_t type) } static int stm32image_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct stm32_header *stm32hdr = (struct stm32_header *)ptr; int i; @@ -99,7 +99,7 @@ static int stm32image_verify_header(unsigned char *ptr, int image_size, return 0; } -static void stm32image_print_header(const void *ptr, struct image_tool_params *params) +static void stm32image_print_header(const void *ptr, struct imgtool *params) { struct stm32_header *stm32hdr = (struct stm32_header *)ptr; @@ -121,7 +121,7 @@ static void stm32image_print_header(const void *ptr, struct image_tool_params *p } static void stm32image_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { struct stm32_header *stm32hdr = (struct stm32_header *)ptr; diff --git a/tools/sunxi_egon.c b/tools/sunxi_egon.c index d0a55226a9e..26031497257 100644 --- a/tools/sunxi_egon.c +++ b/tools/sunxi_egon.c @@ -15,7 +15,7 @@ #define PAD_SIZE 8192 #define PAD_SIZE_MIN 512 -static int egon_get_arch(struct image_tool_params *params) +static int egon_get_arch(struct imgtool *params) { if (params->Aflag) return params->arch; @@ -24,7 +24,7 @@ static int egon_get_arch(struct image_tool_params *params) return IH_ARCH_ARM; } -static int egon_check_params(struct image_tool_params *params) +static int egon_check_params(struct imgtool *params) { /* * Check whether the architecture is supported. @@ -42,7 +42,7 @@ static int egon_check_params(struct image_tool_params *params) } static int egon_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { const struct boot_file_head *header = (void *)ptr; uint32_t length; @@ -82,7 +82,7 @@ static int egon_verify_header(unsigned char *ptr, int image_size, return EXIT_SUCCESS; } -static void egon_print_header(const void *buf, struct image_tool_params *params) +static void egon_print_header(const void *buf, struct imgtool *params) { const struct boot_file_head *header = buf; @@ -104,7 +104,7 @@ static void egon_print_header(const void *buf, struct image_tool_params *params) } static void egon_set_header(void *buf, struct stat *sbuf, int infd, - struct image_tool_params *params) + struct imgtool *params) { struct boot_file_head *header = buf; uint32_t *buf32 = buf; @@ -171,7 +171,7 @@ static int egon_check_image_type(uint8_t type) return type == IH_TYPE_SUNXI_EGON ? 0 : 1; } -static int egon_vrec_header(struct image_tool_params *params, +static int egon_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams) { int pad_size = ALIGN(params->bl_len ?: PAD_SIZE, PAD_SIZE_MIN); diff --git a/tools/sunxi_toc0.c b/tools/sunxi_toc0.c index e52cbe325a3..478c1abcbb4 100644 --- a/tools/sunxi_toc0.c +++ b/tools/sunxi_toc0.c @@ -667,7 +667,7 @@ err: return ret; } -static int toc0_check_params(struct image_tool_params *params) +static int toc0_check_params(struct imgtool *params) { if (!params->dflag) return -EINVAL; @@ -717,7 +717,7 @@ static int toc0_check_params(struct image_tool_params *params) } static int toc0_verify_header(unsigned char *buf, int image_size, - struct image_tool_params *params) + struct imgtool *params) { int ret = EXIT_FAILURE; RSA *root_key = NULL; @@ -757,7 +757,7 @@ static const char *toc0_item_name(uint32_t name) return "(unknown)"; } -static void toc0_print_header(const void *buf, struct image_tool_params *params) +static void toc0_print_header(const void *buf, struct imgtool *params) { const struct toc0_main_info *main_info = buf; const struct toc0_item_info *item_info = (void *)(main_info + 1); @@ -802,7 +802,7 @@ static void toc0_print_header(const void *buf, struct image_tool_params *params) } static void toc0_set_header(void *buf, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { uint32_t key_item_len = 0; uint8_t *key_item = NULL; @@ -888,7 +888,7 @@ static int toc0_check_image_type(uint8_t type) return type == IH_TYPE_SUNXI_TOC0 ? 0 : 1; } -static int toc0_vrec_header(struct image_tool_params *params, +static int toc0_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams) { tparams->hdr = calloc(tparams->header_size, 1); diff --git a/tools/ublimage.c b/tools/ublimage.c index a1bd807bfa0..70514285111 100644 --- a/tools/ublimage.c +++ b/tools/ublimage.c @@ -193,7 +193,7 @@ static int ublimage_check_image_types(uint8_t type) } static int ublimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct ubl_header *ubl_hdr = (struct ubl_header *)ptr; @@ -203,7 +203,7 @@ static int ublimage_verify_header(unsigned char *ptr, int image_size, return 0; } -static void ublimage_print_header(const void *ptr, struct image_tool_params *params) +static void ublimage_print_header(const void *ptr, struct imgtool *params) { struct ubl_header *ubl_hdr = (struct ubl_header *) ptr; @@ -211,7 +211,7 @@ static void ublimage_print_header(const void *ptr, struct image_tool_params *par } static void ublimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { struct ubl_header *ublhdr = (struct ubl_header *)ptr; @@ -219,7 +219,7 @@ static void ublimage_set_header(void *ptr, struct stat *sbuf, int ifd, parse_cfg_file(ublhdr, params->imagename); } -int ublimage_check_params(struct image_tool_params *params) +int ublimage_check_params(struct imgtool *params) { if (!params) return CFG_INVALID; diff --git a/tools/vybridimage.c b/tools/vybridimage.c index c38886fa903..31119d04554 100644 --- a/tools/vybridimage.c +++ b/tools/vybridimage.c @@ -59,7 +59,7 @@ static uint8_t vybridimage_sw_ecc(uint8_t byte) } static int vybridimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; @@ -93,7 +93,7 @@ static int vybridimage_verify_header(unsigned char *ptr, int image_size, } static void vybridimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; @@ -134,7 +134,7 @@ static void vybridimage_print_hdr_field(struct nand_page_0_boot_header *hdr, printf("header.fcb[%d] = %08x\n", idx, hdr->fcb[idx]); } -static void vybridimage_print_header(const void *ptr, struct image_tool_params *params) +static void vybridimage_print_header(const void *ptr, struct imgtool *params) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; diff --git a/tools/zynqimage.c b/tools/zynqimage.c index 359c93d1acd..af7b6f65629 100644 --- a/tools/zynqimage.c +++ b/tools/zynqimage.c @@ -139,7 +139,7 @@ static void zynqimage_default_header(struct zynq_header *ptr) /* mkimage glue functions */ static int zynqimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct zynq_header *zynqhdr = (struct zynq_header *)ptr; @@ -163,7 +163,7 @@ static int zynqimage_verify_header(unsigned char *ptr, int image_size, return 0; } -static void zynqimage_print_header(const void *ptr, struct image_tool_params *params) +static void zynqimage_print_header(const void *ptr, struct imgtool *params) { struct zynq_header *zynqhdr = (struct zynq_header *)ptr; int i; @@ -198,7 +198,7 @@ static void zynqimage_print_header(const void *ptr, struct image_tool_params *pa } } -static int zynqimage_check_params(struct image_tool_params *params) +static int zynqimage_check_params(struct imgtool *params) { if (!params) return 0; @@ -266,7 +266,7 @@ static void zynqimage_parse_initparams(struct zynq_header *zynqhdr, } static void zynqimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { struct zynq_header *zynqhdr = (struct zynq_header *)ptr; zynqimage_default_header(zynqhdr); diff --git a/tools/zynqmpbif.c b/tools/zynqmpbif.c index 82ce0ac1a52..f8acc07244f 100644 --- a/tools/zynqmpbif.c +++ b/tools/zynqmpbif.c @@ -84,7 +84,7 @@ static uint32_t zynqmp_csum(void *start, void *end) return ~checksum; } -static int zynqmpbif_check_params(struct image_tool_params *params) +static int zynqmpbif_check_params(struct imgtool *params) { if (!params) return 0; @@ -825,7 +825,7 @@ static char *skip_whitespace(char *str) return str; } -int zynqmpbif_copy_image(int outfd, struct image_tool_params *mparams) +int zynqmpbif_copy_image(int outfd, struct imgtool *mparams) { char *bif, *bifp, *bifpn; char *line; @@ -995,7 +995,7 @@ err: /* Needs to be stubbed out so we can print after creation */ static void zynqmpbif_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { } diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c index a075ac22bdd..5bef2a935bb 100644 --- a/tools/zynqmpimage.c +++ b/tools/zynqmpimage.c @@ -117,7 +117,7 @@ void zynqmpimage_default_header(struct zynqmp_header *ptr) /* mkimage glue functions */ static int zynqmpimage_verify_header(unsigned char *ptr, int image_size, - struct image_tool_params *params) + struct imgtool *params) { struct zynqmp_header *zynqhdr = (struct zynqmp_header *)ptr; @@ -263,7 +263,7 @@ static void print_partition(const void *ptr, const struct partition_header *ph) printf(" Checksum : 0x%08x\n", le32_to_cpu(ph->checksum)); } -void zynqmpimage_print_header(const void *ptr, struct image_tool_params *params) +void zynqmpimage_print_header(const void *ptr, struct imgtool *params) { struct zynqmp_header *zynqhdr = (struct zynqmp_header *)ptr; struct partition_header *ph; @@ -311,7 +311,7 @@ void zynqmpimage_print_header(const void *ptr, struct image_tool_params *params) free(dynamic_header); } -static int zynqmpimage_check_params(struct image_tool_params *params) +static int zynqmpimage_check_params(struct imgtool *params) { if (!params) return 0; @@ -439,7 +439,7 @@ static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr, } static void zynqmpimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct image_tool_params *params) + struct imgtool *params) { struct zynqmp_header *zynqhdr = (struct zynqmp_header *)ptr; zynqmpimage_default_header(zynqhdr); @@ -483,7 +483,7 @@ static int zynqmpimage_partition_extract(struct zynqmp_header *zynqhdr, * returns: * zero in case of success or a negative value if fail. */ -static int zynqmpimage_extract_contents(void *ptr, struct image_tool_params *params) +static int zynqmpimage_extract_contents(void *ptr, struct imgtool *params) { struct zynqmp_header *zynqhdr = (struct zynqmp_header *)ptr; struct partition_header *ph; @@ -498,7 +498,7 @@ static int zynqmpimage_extract_contents(void *ptr, struct image_tool_params *par return -1; } -static int zynqmpimage_vrec_header(struct image_tool_params *params, +static int zynqmpimage_vrec_header(struct imgtool *params, struct imgtool_funcs *tparams) { struct stat path_stat; diff --git a/tools/zynqmpimage.h b/tools/zynqmpimage.h index 7c47dc0763b..a79d4773d2c 100644 --- a/tools/zynqmpimage.h +++ b/tools/zynqmpimage.h @@ -141,7 +141,7 @@ struct zynqmp_header { }; void zynqmpimage_default_header(struct zynqmp_header *ptr); -void zynqmpimage_print_header(const void *ptr, struct image_tool_params *params); +void zynqmpimage_print_header(const void *ptr, struct imgtool *params); static inline struct image_header_table * zynqmp_get_iht(const struct zynqmp_header *zynqhdr) -- 2.43.0

Use the same 'itl' (for image-tool) whenever this parameter is passed around. This makes it easier to recognise. Move away from using the word 'parameters', since it contains essentially all of the info about the tool, not just parameters. Use 'info' instead. Signed-off-by: Simon Glass <sjg@chromium.org> --- tools/aisimage.c | 52 ++++----- tools/atmelimage.c | 27 +++-- tools/default_image.c | 54 ++++----- tools/fit_common.h | 4 +- tools/fit_image.c | 238 +++++++++++++++++++------------------- tools/gpheader.h | 2 +- tools/gpimage-common.c | 8 +- tools/gpimage.c | 8 +- tools/imagetool.c | 36 +++--- tools/imagetool.h | 8 +- tools/imx8image.c | 10 +- tools/imx8mimage.c | 6 +- tools/imximage.c | 41 ++++--- tools/kwbimage.c | 164 +++++++++++++------------- tools/lpc32xximage.c | 6 +- tools/mtk_image.c | 24 ++-- tools/mxsimage.c | 35 +++--- tools/omapimage.c | 11 +- tools/pblimage.c | 40 +++---- tools/renesas_spkgimage.c | 28 ++--- tools/rkcommon.c | 109 +++++++++-------- tools/rkcommon.h | 20 ++-- tools/rkimage.c | 8 +- tools/rkspi.c | 17 ++- tools/sfspl.c | 25 ++-- tools/socfpgaimage.c | 60 +++++----- tools/stm32image.c | 10 +- tools/sunxi_egon.c | 37 +++--- tools/sunxi_toc0.c | 29 +++-- tools/ublimage.c | 24 ++-- tools/vybridimage.c | 6 +- tools/zynqimage.c | 24 ++-- tools/zynqmpbif.c | 12 +- tools/zynqmpimage.c | 40 +++---- tools/zynqmpimage.h | 2 +- 35 files changed, 604 insertions(+), 621 deletions(-) diff --git a/tools/aisimage.c b/tools/aisimage.c index f17eeb059de..e41b9c5455c 100644 --- a/tools/aisimage.c +++ b/tools/aisimage.c @@ -113,7 +113,7 @@ static int get_ais_table_id(uint32_t *ptr) return -1; } -static void aisimage_print_header(const void *hdr, struct imgtool *params) +static void aisimage_print_header(const void *hdr, struct imgtool *itl) { struct ais_header *ais_hdr = (struct ais_header *)hdr; uint32_t *ptr; @@ -174,23 +174,23 @@ static uint32_t *ais_insert_cmd_header(uint32_t cmd, uint32_t nargs, } -static uint32_t *ais_alloc_buffer(struct imgtool *params) +static uint32_t *ais_alloc_buffer(struct imgtool *itl) { int dfd; struct stat sbuf; - char *datafile = params->datafile; + char *datafile = itl->datafile; uint32_t *ptr; dfd = open(datafile, O_RDONLY|O_BINARY); if (dfd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - params->cmdname, datafile, strerror(errno)); + itl->cmdname, datafile, strerror(errno)); exit(EXIT_FAILURE); } if (fstat(dfd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", - params->cmdname, datafile, strerror(errno)); + itl->cmdname, datafile, strerror(errno)); exit(EXIT_FAILURE); } @@ -206,7 +206,7 @@ static uint32_t *ais_alloc_buffer(struct imgtool *params) + MAX_CMD_BUFFER); if (!ptr) { fprintf(stderr, "%s: malloc return failure: %s\n", - params->cmdname, strerror(errno)); + itl->cmdname, strerror(errno)); exit(EXIT_FAILURE); } @@ -215,30 +215,30 @@ static uint32_t *ais_alloc_buffer(struct imgtool *params) return ptr; } -static uint32_t *ais_copy_image(struct imgtool *params, uint32_t *aisptr) +static uint32_t *ais_copy_image(struct imgtool *itl, uint32_t *aisptr) { int dfd; struct stat sbuf; - char *datafile = params->datafile; + char *datafile = itl->datafile; void *ptr; dfd = open(datafile, O_RDONLY|O_BINARY); if (dfd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - params->cmdname, datafile, strerror(errno)); + itl->cmdname, datafile, strerror(errno)); exit(EXIT_FAILURE); } if (fstat(dfd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", - params->cmdname, datafile, strerror(errno)); + itl->cmdname, datafile, strerror(errno)); exit(EXIT_FAILURE); } ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0); *aisptr++ = AIS_CMD_LOAD; - *aisptr++ = params->ep; + *aisptr++ = itl->ep; *aisptr++ = sbuf.st_size; memcpy((void *)aisptr, ptr, sbuf.st_size); aisptr += ALIGN(sbuf.st_size, WORD_ALIGN0) / sizeof(uint32_t); @@ -250,7 +250,7 @@ static uint32_t *ais_copy_image(struct imgtool *params, uint32_t *aisptr) } -static int aisimage_generate(struct imgtool *params, +static int aisimage_generate(struct imgtool *itl, struct imgtool_funcs *tparams) { FILE *fd = NULL; @@ -262,7 +262,7 @@ static int aisimage_generate(struct imgtool *params, int32_t cmd; uint32_t nargs, cmd_parms[10]; uint32_t value, size; - char *name = params->imagename; + char *name = itl->imagename; uint32_t *aishdr; fd = fopen(name, "r"); @@ -282,7 +282,7 @@ static int aisimage_generate(struct imgtool *params, * Start allocating a buffer suitable for most command * The buffer is then reallocated if it is too small */ - aishdr = ais_alloc_buffer(params); + aishdr = ais_alloc_buffer(itl); tparams->hdr = aishdr; *aishdr++ = AIS_MAGIC_WORD; @@ -347,11 +347,11 @@ static int aisimage_generate(struct imgtool *params, } fclose(fd); - aishdr = ais_copy_image(params, aishdr); + aishdr = ais_copy_image(itl, aishdr); /* Add Jmp & Close */ *aishdr++ = AIS_CMD_JMPCLOSE; - *aishdr++ = params->ep; + *aishdr++ = itl->ep; size = (aishdr - (uint32_t *)tparams->hdr) * sizeof(uint32_t); tparams->header_size = size; @@ -368,7 +368,7 @@ static int aisimage_check_image_types(uint8_t type) } static int aisimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct ais_header *ais_hdr = (struct ais_header *)ptr; @@ -382,18 +382,18 @@ static int aisimage_verify_header(unsigned char *ptr, int image_size, } static void aisimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { } -int aisimage_check_params(struct imgtool *params) +int aisimage_check_params(struct imgtool *itl) { - if (!params) + if (!itl) return CFG_INVALID; - if (!strlen(params->imagename)) { + if (!strlen(itl->imagename)) { fprintf(stderr, "Error: %s - Configuration file not specified, " "it is needed for aisimage generation\n", - params->cmdname); + itl->cmdname); return CFG_INVALID; } /* @@ -402,10 +402,10 @@ int aisimage_check_params(struct imgtool *params) * parameters are not sent at the same time * For example, if list is required a data image must not be provided */ - return (params->dflag && (params->fflag || params->lflag)) || - (params->fflag && (params->dflag || params->lflag)) || - (params->lflag && (params->dflag || params->fflag)) || - (params->xflag) || !(strlen(params->imagename)); + return (itl->dflag && (itl->fflag || itl->lflag)) || + (itl->fflag && (itl->dflag || itl->lflag)) || + (itl->lflag && (itl->dflag || itl->fflag)) || + (itl->xflag) || !(strlen(itl->imagename)); } /* diff --git a/tools/atmelimage.c b/tools/atmelimage.c index 279e26527e3..610d0f5d20e 100644 --- a/tools/atmelimage.c +++ b/tools/atmelimage.c @@ -112,7 +112,7 @@ static int atmel_parse_pmecc_params(char *txt) } static int atmel_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { uint32_t *ints = (uint32_t *)ptr; size_t pos; @@ -182,7 +182,7 @@ static void atmel_print_pmecc_header(const uint32_t word) printf("\t\t====================\n"); } -static void atmel_print_header(const void *ptr, struct imgtool *params) +static void atmel_print_header(const void *ptr, struct imgtool *itl) { uint32_t *ints = (uint32_t *)ptr; size_t pos; @@ -204,7 +204,7 @@ static void atmel_print_header(const void *ptr, struct imgtool *params) } static void atmel_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { /* just save the image size into 6'th interrupt vector */ uint32_t *ints = (uint32_t *)ptr; @@ -224,26 +224,25 @@ static void atmel_set_header(void *ptr, struct stat *sbuf, int ifd, ints[pos] = cpu_to_le32(size); } -static int atmel_check_params(struct imgtool *params) +static int atmel_check_params(struct imgtool *itl) { - if (strlen(params->imagename) > 0) - if (atmel_parse_pmecc_params(params->imagename)) + if (strlen(itl->imagename) > 0) + if (atmel_parse_pmecc_params(itl->imagename)) return EXIT_FAILURE; - return !(!params->eflag && - !params->fflag && - !params->xflag && - ((params->dflag && !params->lflag) || - (params->lflag && !params->dflag))); + return !(!itl->eflag && + !itl->fflag && + !itl->xflag && + ((itl->dflag && !itl->lflag) || + (itl->lflag && !itl->dflag))); } -static int atmel_vrec_header(struct imgtool *params, - struct imgtool_funcs *tparams) +static int atmel_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams) { uint32_t tmp; size_t pos; - if (strlen(params->imagename) == 0) + if (strlen(itl->imagename) == 0) return EXIT_SUCCESS; tmp = 0xC << 28; diff --git a/tools/default_image.c b/tools/default_image.c index e7412c1cb2f..62298860dc1 100644 --- a/tools/default_image.c +++ b/tools/default_image.c @@ -33,20 +33,20 @@ static int image_check_image_types(uint8_t type) return EXIT_FAILURE; } -static int image_check_params(struct imgtool *params) +static int image_check_params(struct imgtool *itl) { - return ((params->dflag && (params->fflag || params->lflag)) || - (params->fflag && (params->dflag || params->lflag)) || - (params->lflag && (params->dflag || params->fflag))); + return ((itl->dflag && (itl->fflag || itl->lflag)) || + (itl->fflag && (itl->dflag || itl->lflag)) || + (itl->lflag && (itl->dflag || itl->fflag))); } -static void image_print_header(const void *ptr, struct imgtool *params) +static void image_print_header(const void *ptr, struct imgtool *itl) { image_print_contents(ptr); } static int image_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { uint32_t len; const unsigned char *data; @@ -56,7 +56,7 @@ static int image_verify_header(unsigned char *ptr, int image_size, if (image_size < sizeof(struct legacy_img_hdr)) { debug("%s: Bad image size: \"%s\" is no valid image\n", - params->cmdname, params->imagefile); + itl->cmdname, itl->imagefile); return -FDT_ERR_BADSTRUCTURE; } @@ -69,7 +69,7 @@ static int image_verify_header(unsigned char *ptr, int image_size, if (be32_to_cpu(hdr->ih_magic) != IH_MAGIC) { debug("%s: Bad Magic Number: \"%s\" is no valid image\n", - params->cmdname, params->imagefile); + itl->cmdname, itl->imagefile); return -FDT_ERR_BADMAGIC; } @@ -81,7 +81,7 @@ static int image_verify_header(unsigned char *ptr, int image_size, if (crc32(0, data, len) != checksum) { debug("%s: ERROR: \"%s\" has bad header checksum!\n", - params->cmdname, params->imagefile); + itl->cmdname, itl->imagefile); return -FDT_ERR_BADSTATE; } @@ -94,21 +94,21 @@ static int image_verify_header(unsigned char *ptr, int image_size, if (image_size - sizeof(struct legacy_img_hdr) < len) { debug("%s: Bad image size: \"%s\" is no valid image\n", - params->cmdname, params->imagefile); + itl->cmdname, itl->imagefile); return -FDT_ERR_BADSTRUCTURE; } checksum = be32_to_cpu(hdr->ih_dcrc); if (crc32(0, data, len) != checksum) { debug("%s: ERROR: \"%s\" has corrupted data!\n", - params->cmdname, params->imagefile); + itl->cmdname, itl->imagefile); return -FDT_ERR_BADSTRUCTURE; } return 0; } static void image_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { uint32_t checksum; time_t time; @@ -123,11 +123,11 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd, sizeof(struct legacy_img_hdr)), sbuf->st_size - sizeof(struct legacy_img_hdr)); - time = imagetool_get_source_date(params->cmdname, sbuf->st_mtime); - ep = params->ep; - addr = params->addr; + time = imagetool_get_source_date(itl->cmdname, sbuf->st_mtime); + ep = itl->ep; + addr = itl->addr; - if (params->type == IH_TYPE_FIRMWARE_IVT) + if (itl->type == IH_TYPE_FIRMWARE_IVT) /* Add size of CSF minus IVT */ imagesize = sbuf->st_size - sizeof(struct legacy_img_hdr) + 0x2060 - sizeof(flash_header_v2_t); @@ -135,12 +135,12 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd, else imagesize = sbuf->st_size - sizeof(struct legacy_img_hdr); - if (params->type == IH_TYPE_FDT_LEGACY) + if (itl->type == IH_TYPE_FDT_LEGACY) type = IH_TYPE_FLATDT; else - type = params->type; + type = itl->type; - if (params->os == IH_OS_TEE) { + if (itl->os == IH_OS_TEE) { addr = optee_image_get_load_addr(hdr); ep = optee_image_get_entry_point(hdr); } @@ -152,12 +152,12 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd, image_set_load(hdr, addr); image_set_ep(hdr, ep); image_set_dcrc(hdr, checksum); - image_set_os(hdr, params->os); - image_set_arch(hdr, params->arch); + image_set_os(hdr, itl->os); + image_set_arch(hdr, itl->arch); image_set_type(hdr, type); - image_set_comp(hdr, params->comp); + image_set_comp(hdr, itl->comp); - image_set_name(hdr, params->imagename); + image_set_name(hdr, itl->imagename); checksum = crc32(0, (const unsigned char *)hdr, sizeof(struct legacy_img_hdr)); @@ -165,14 +165,14 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd, image_set_hcrc(hdr, checksum); } -static int image_extract_subimage(void *ptr, struct imgtool *params) +static int image_extract_subimage(void *ptr, struct imgtool *itl) { const struct legacy_img_hdr *hdr = (const struct legacy_img_hdr *)ptr; ulong file_data; ulong file_len; if (image_check_type(hdr, IH_TYPE_MULTI)) { - ulong idx = params->pflag; + ulong idx = itl->pflag; ulong count; /* get the number of data files present in the image */ @@ -183,7 +183,7 @@ static int image_extract_subimage(void *ptr, struct imgtool *params) if ((file_len == 0) || (idx >= count)) { fprintf(stderr, "%s: No such data file %ld in \"%s\"\n", - params->cmdname, idx, params->imagefile); + itl->cmdname, idx, itl->imagefile); return -1; } } else { @@ -192,7 +192,7 @@ static int image_extract_subimage(void *ptr, struct imgtool *params) } /* save the "data file" into the file system */ - return imagetool_save_subimage(params->outfile, file_data, file_len); + return imagetool_save_subimage(itl->outfile, file_data, file_len); } /* diff --git a/tools/fit_common.h b/tools/fit_common.h index b1c46bfe74f..e0eb4e166ba 100644 --- a/tools/fit_common.h +++ b/tools/fit_common.h @@ -10,14 +10,14 @@ #include "mkimage.h" #include <image.h> -void fit_print_header(const void *fit, struct imgtool *params); +void fit_print_header(const void *fit, struct imgtool *itl); /** * Verify the format of FIT header pointed to by ptr * * @ptr: image header to be verified * @image_size: size of while image - * @params: mkimage parameters + * @itl: mkimage parameters * Return: 0 if OK, -1 on error */ int fit_verify_header(unsigned char *ptr, int image_size, struct imgtool *itl); diff --git a/tools/fit_image.c b/tools/fit_image.c index be9779e0686..aa71544f4cb 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -24,7 +24,7 @@ static struct legacy_img_hdr header; -static int fit_add_file_data(struct imgtool *params, size_t size_inc, +static int fit_add_file_data(struct imgtool *itl, size_t size_inc, const char *tmpfile) { int tfd, destfd = 0; @@ -34,17 +34,17 @@ static int fit_add_file_data(struct imgtool *params, size_t size_inc, void *ptr; int ret = 0; - tfd = mmap_fdt(params->cmdname, tmpfile, size_inc, &ptr, &sbuf, true, + tfd = mmap_fdt(itl->cmdname, tmpfile, size_inc, &ptr, &sbuf, true, false); if (tfd < 0) { fprintf(stderr, "Cannot map FDT file '%s'\n", tmpfile); return -EIO; } - if (params->keydest) { + if (itl->keydest) { struct stat dest_sbuf; - destfd = mmap_fdt(params->cmdname, params->keydest, size_inc, + destfd = mmap_fdt(itl->cmdname, itl->keydest, size_inc, &dest_blob, &dest_sbuf, false, false); if (destfd < 0) { @@ -55,32 +55,32 @@ static int fit_add_file_data(struct imgtool *params, size_t size_inc, } /* for first image creation, add a timestamp at offset 0 i.e., root */ - if (params->datafile || params->reset_timestamp) { - time_t time = imagetool_get_source_date(params->cmdname, + if (itl->datafile || itl->reset_timestamp) { + time_t time = imagetool_get_source_date(itl->cmdname, sbuf.st_mtime); ret = fit_set_timestamp(ptr, 0, time); } if (CONFIG_IS_ENABLED(FIT_SIGNATURE) && !ret) - ret = fit_pre_load_data(params->keydir, dest_blob, ptr); + ret = fit_pre_load_data(itl->keydir, dest_blob, ptr); if (!ret) { - ret = fit_cipher_data(params->keydir, dest_blob, ptr, - params->comment, - params->require_keys, - params->engine_id, - params->cmdname); + ret = fit_cipher_data(itl->keydir, dest_blob, ptr, + itl->comment, + itl->require_keys, + itl->engine_id, + itl->cmdname); } if (!ret) { - ret = fit_add_verification_data(params->keydir, - params->keyfile, dest_blob, ptr, - params->comment, - params->require_keys, - params->engine_id, - params->cmdname, - params->algo_name, - ¶ms->summary); + ret = fit_add_verification_data(itl->keydir, + itl->keyfile, dest_blob, ptr, + itl->comment, + itl->require_keys, + itl->engine_id, + itl->cmdname, + itl->algo_name, + &itl->summary); } if (dest_blob) { @@ -97,25 +97,25 @@ err_keydest: /** * fit_calc_size() - Calculate the approximate size of the FIT we will generate */ -static int fit_calc_size(struct imgtool *params) +static int fit_calc_size(struct imgtool *itl) { struct content_info *cont; int size, total_size; - size = imagetool_get_filesize(params, params->datafile); + size = imagetool_get_filesize(itl, itl->datafile); if (size < 0) return -1; total_size = size; - if (params->fit_ramdisk) { - size = imagetool_get_filesize(params, params->fit_ramdisk); + if (itl->fit_ramdisk) { + size = imagetool_get_filesize(itl, itl->fit_ramdisk); if (size < 0) return -1; total_size += size; } - for (cont = params->content_head; cont; cont = cont->next) { - size = imagetool_get_filesize(params, cont->fname); + for (cont = itl->content_head; cont; cont = cont->next) { + size = imagetool_get_filesize(itl, cont->fname); if (size < 0) return -1; @@ -129,8 +129,8 @@ static int fit_calc_size(struct imgtool *params) return total_size; } -static int fdt_property_file(struct imgtool *params, - void *fdt, const char *name, const char *fname) +static int fdt_property_file(struct imgtool *itl, void *fdt, const char *name, + const char *fname) { struct stat sbuf; void *ptr; @@ -140,13 +140,13 @@ static int fdt_property_file(struct imgtool *params, fd = open(fname, O_RDONLY | O_BINARY); if (fd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - params->cmdname, fname, strerror(errno)); + itl->cmdname, fname, strerror(errno)); return -1; } if (fstat(fd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", - params->cmdname, fname, strerror(errno)); + itl->cmdname, fname, strerror(errno)); goto err; } @@ -156,7 +156,7 @@ static int fdt_property_file(struct imgtool *params, ret = read(fd, ptr, sbuf.st_size); if (ret != sbuf.st_size) { fprintf(stderr, "%s: Can't read %s: %s\n", - params->cmdname, fname, strerror(errno)); + itl->cmdname, fname, strerror(errno)); goto err; } close(fd); @@ -203,7 +203,7 @@ static void get_basename(char *str, int size, const char *fname) /** * fit_add_hash_or_sign() - Add a hash or signature node * - * @params: Image parameters + * @itl: Image-tool info * @fdt: Device tree to add to (in sequential-write mode) * @is_images_subnode: true to add hash even if key name hint is provided * @@ -211,14 +211,14 @@ static void get_basename(char *str, int size, const char *fname) * a sign node to parent. Otherwise, just add a CRC. Rationale: if conf have * to be signed, image/dt have to be hashed even if there is a key name hint. */ -static void fit_add_hash_or_sign(struct imgtool *params, void *fdt, +static void fit_add_hash_or_sign(struct imgtool *itl, void *fdt, bool is_images_subnode) { const char *hash_algo = "crc32"; bool do_hash = false; bool do_sign = false; - switch (params->auto_fit) { + switch (itl->auto_fit) { case AF_OFF: break; case AF_HASHED_IMG: @@ -238,7 +238,7 @@ static void fit_add_hash_or_sign(struct imgtool *params, void *fdt, default: fprintf(stderr, "%s: Unsupported auto FIT mode %u\n", - params->cmdname, params->auto_fit); + itl->cmdname, itl->auto_fit); break; } @@ -250,8 +250,8 @@ static void fit_add_hash_or_sign(struct imgtool *params, void *fdt, if (do_sign) { fdt_begin_node(fdt, FIT_SIG_NODENAME); - fdt_property_string(fdt, FIT_ALGO_PROP, params->algo_name); - fdt_property_string(fdt, FIT_KEY_HINT, params->keyname); + fdt_property_string(fdt, FIT_ALGO_PROP, itl->algo_name); + fdt_property_string(fdt, FIT_KEY_HINT, itl->keyname); fdt_end_node(fdt); } } @@ -259,10 +259,10 @@ static void fit_add_hash_or_sign(struct imgtool *params, void *fdt, /** * fit_write_images() - Write out a list of images to the FIT * - * We always include the main image (params->datafile). If there are device + * We always include the main image (itl->datafile). If there are device * tree files, we include an fdt- node for each of those too. */ -static int fit_write_images(struct imgtool *params, char *fdt) +static int fit_write_images(struct imgtool *itl, char *fdt) { struct content_info *cont; const char *typename; @@ -273,33 +273,33 @@ static int fit_write_images(struct imgtool *params, char *fdt) fdt_begin_node(fdt, "images"); /* First the main image */ - typename = genimg_get_type_short_name(params->fit_image_type); + typename = genimg_get_type_short_name(itl->fit_image_type); snprintf(str, sizeof(str), "%s-1", typename); fdt_begin_node(fdt, str); - fdt_property_string(fdt, FIT_DESC_PROP, params->imagename); + fdt_property_string(fdt, FIT_DESC_PROP, itl->imagename); fdt_property_string(fdt, FIT_TYPE_PROP, typename); fdt_property_string(fdt, FIT_ARCH_PROP, - genimg_get_arch_short_name(params->arch)); + genimg_get_arch_short_name(itl->arch)); fdt_property_string(fdt, FIT_OS_PROP, - genimg_get_os_short_name(params->os)); + genimg_get_os_short_name(itl->os)); fdt_property_string(fdt, FIT_COMP_PROP, - genimg_get_comp_short_name(params->comp)); - fdt_property_u32(fdt, FIT_LOAD_PROP, params->addr); - fdt_property_u32(fdt, FIT_ENTRY_PROP, params->ep); + genimg_get_comp_short_name(itl->comp)); + fdt_property_u32(fdt, FIT_LOAD_PROP, itl->addr); + fdt_property_u32(fdt, FIT_ENTRY_PROP, itl->ep); /* * Put data last since it is large. SPL may only load the first part * of the DT, so this way it can access all the above fields. */ - ret = fdt_property_file(params, fdt, FIT_DATA_PROP, params->datafile); + ret = fdt_property_file(itl, fdt, FIT_DATA_PROP, itl->datafile); if (ret) return ret; - fit_add_hash_or_sign(params, fdt, true); + fit_add_hash_or_sign(itl, fdt, true); fdt_end_node(fdt); /* Now the device tree files if available */ upto = 0; - for (cont = params->content_head; cont; cont = cont->next) { + for (cont = itl->content_head; cont; cont = cont->next) { if (cont->type != IH_TYPE_FLATDT) continue; typename = genimg_get_type_short_name(cont->type); @@ -308,36 +308,36 @@ static int fit_write_images(struct imgtool *params, char *fdt) get_basename(str, sizeof(str), cont->fname); fdt_property_string(fdt, FIT_DESC_PROP, str); - ret = fdt_property_file(params, fdt, FIT_DATA_PROP, + ret = fdt_property_file(itl, fdt, FIT_DATA_PROP, cont->fname); if (ret) return ret; fdt_property_string(fdt, FIT_TYPE_PROP, typename); fdt_property_string(fdt, FIT_ARCH_PROP, - genimg_get_arch_short_name(params->arch)); + genimg_get_arch_short_name(itl->arch)); fdt_property_string(fdt, FIT_COMP_PROP, genimg_get_comp_short_name(IH_COMP_NONE)); - fit_add_hash_or_sign(params, fdt, true); + fit_add_hash_or_sign(itl, fdt, true); if (ret) return ret; fdt_end_node(fdt); } /* And a ramdisk file if available */ - if (params->fit_ramdisk) { + if (itl->fit_ramdisk) { fdt_begin_node(fdt, FIT_RAMDISK_PROP "-1"); fdt_property_string(fdt, FIT_TYPE_PROP, FIT_RAMDISK_PROP); fdt_property_string(fdt, FIT_OS_PROP, - genimg_get_os_short_name(params->os)); + genimg_get_os_short_name(itl->os)); fdt_property_string(fdt, FIT_ARCH_PROP, - genimg_get_arch_short_name(params->arch)); + genimg_get_arch_short_name(itl->arch)); - ret = fdt_property_file(params, fdt, FIT_DATA_PROP, - params->fit_ramdisk); + ret = fdt_property_file(itl, fdt, FIT_DATA_PROP, + itl->fit_ramdisk); if (ret) return ret; - fit_add_hash_or_sign(params, fdt, true); + fit_add_hash_or_sign(itl, fdt, true); if (ret) return ret; fdt_end_node(fdt); @@ -357,7 +357,7 @@ static int fit_write_images(struct imgtool *params, char *fdt) * * Otherwise we just create a configuration with the main image in it. */ -static void fit_write_configs(struct imgtool *params, char *fdt) +static void fit_write_configs(struct imgtool *itl, char *fdt) { struct content_info *cont; const char *typename; @@ -368,7 +368,7 @@ static void fit_write_configs(struct imgtool *params, char *fdt) fdt_property_string(fdt, FIT_DEFAULT_PROP, "conf-1"); upto = 0; - for (cont = params->content_head; cont; cont = cont->next) { + for (cont = itl->content_head; cont; cont = cont->next) { if (cont->type != IH_TYPE_FLATDT) continue; typename = genimg_get_type_short_name(cont->type); @@ -378,31 +378,31 @@ static void fit_write_configs(struct imgtool *params, char *fdt) get_basename(str, sizeof(str), cont->fname); fdt_property_string(fdt, FIT_DESC_PROP, str); - typename = genimg_get_type_short_name(params->fit_image_type); + typename = genimg_get_type_short_name(itl->fit_image_type); snprintf(str, sizeof(str), "%s-1", typename); fdt_property_string(fdt, typename, str); fdt_property_string(fdt, FIT_LOADABLE_PROP, str); - if (params->fit_ramdisk) + if (itl->fit_ramdisk) fdt_property_string(fdt, FIT_RAMDISK_PROP, FIT_RAMDISK_PROP "-1"); snprintf(str, sizeof(str), FIT_FDT_PROP "-%d", upto); fdt_property_string(fdt, FIT_FDT_PROP, str); - fit_add_hash_or_sign(params, fdt, false); + fit_add_hash_or_sign(itl, fdt, false); fdt_end_node(fdt); } if (!upto) { fdt_begin_node(fdt, "conf-1"); - typename = genimg_get_type_short_name(params->fit_image_type); + typename = genimg_get_type_short_name(itl->fit_image_type); snprintf(str, sizeof(str), "%s-1", typename); fdt_property_string(fdt, typename, str); - if (params->fit_ramdisk) + if (itl->fit_ramdisk) fdt_property_string(fdt, FIT_RAMDISK_PROP, FIT_RAMDISK_PROP "-1"); - fit_add_hash_or_sign(params, fdt, false); + fit_add_hash_or_sign(itl, fdt, false); fdt_end_node(fdt); } @@ -410,7 +410,7 @@ static void fit_write_configs(struct imgtool *params, char *fdt) fdt_end_node(fdt); } -static int fit_build_fdt(struct imgtool *params, char *fdt, int size) +static int fit_build_fdt(struct imgtool *itl, char *fdt, int size) { int ret; @@ -421,13 +421,13 @@ static int fit_build_fdt(struct imgtool *params, char *fdt, int size) fdt_begin_node(fdt, ""); fdt_property_strf(fdt, FIT_DESC_PROP, "%s image with one or more FDT blobs", - genimg_get_type_name(params->fit_image_type)); + genimg_get_type_name(itl->fit_image_type)); fdt_property_strf(fdt, "creator", "U-Boot mkimage %s", PLAIN_VERSION); fdt_property_u32(fdt, "#address-cells", 1); - ret = fit_write_images(params, fdt); + ret = fit_write_images(itl, fdt); if (ret) return ret; - fit_write_configs(params, fdt); + fit_write_configs(itl, fdt); fdt_end_node(fdt); ret = fdt_finish(fdt); if (ret) @@ -436,39 +436,39 @@ static int fit_build_fdt(struct imgtool *params, char *fdt, int size) return fdt_totalsize(fdt); } -static int fit_build(struct imgtool *params, const char *fname) +static int fit_build(struct imgtool *itl, const char *fname) { char *buf; int size; int ret; int fd; - size = fit_calc_size(params); + size = fit_calc_size(itl); if (size < 0) return -1; buf = calloc(1, size); if (!buf) { fprintf(stderr, "%s: Out of memory (%d bytes)\n", - params->cmdname, size); + itl->cmdname, size); return -1; } - ret = fit_build_fdt(params, buf, size); + ret = fit_build_fdt(itl, buf, size); if (ret < 0) { fprintf(stderr, "%s: Failed to build FIT image\n", - params->cmdname); + itl->cmdname); goto err_buf; } size = ret; fd = open(fname, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666); if (fd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - params->cmdname, fname, strerror(errno)); + itl->cmdname, fname, strerror(errno)); goto err_buf; } ret = write(fd, buf, size); if (ret != size) { fprintf(stderr, "%s: Can't write %s: %s\n", - params->cmdname, fname, strerror(errno)); + itl->cmdname, fname, strerror(errno)); goto err; } close(fd); @@ -493,7 +493,7 @@ err_buf: * This function cannot cope with FITs with 'data-offset' properties. All * data must be in 'data' properties on entry. */ -static int fit_extract_data(struct imgtool *params, const char *fname) +static int fit_extract_data(struct imgtool *itl, const char *fname) { void *buf = NULL; int buf_ptr; @@ -507,8 +507,8 @@ static int fit_extract_data(struct imgtool *params, const char *fname) int image_number; int align_size; - align_size = params->bl_len ? params->bl_len : 4; - fd = mmap_fdt(params->cmdname, fname, 0, &fdt, &sbuf, false, false); + align_size = itl->bl_len ? itl->bl_len : 4; + fd = mmap_fdt(itl->cmdname, fname, 0, &fdt, &sbuf, false, false); if (fd < 0) return -EIO; fit_size = fdt_totalsize(fdt); @@ -549,10 +549,10 @@ static int fit_extract_data(struct imgtool *params, const char *fname) ret = -EPERM; goto err_munmap; } - if (params->external_offset > 0) { + if (itl->external_offset > 0) { /* An external offset positions the data absolutely. */ fdt_setprop_u32(fdt, node, FIT_DATA_POSITION_PROP, - params->external_offset + buf_ptr); + itl->external_offset + buf_ptr); } else { fdt_setprop_u32(fdt, node, FIT_DATA_OFFSET_PROP, buf_ptr); @@ -583,15 +583,15 @@ static int fit_extract_data(struct imgtool *params, const char *fname) } /* Check if an offset for the external data was set. */ - if (params->external_offset > 0) { - if (params->external_offset < new_size) { + if (itl->external_offset > 0) { + if (itl->external_offset < new_size) { fprintf(stderr, "External offset %x overlaps FIT length %x\n", - params->external_offset, new_size); + itl->external_offset, new_size); ret = -EINVAL; goto err; } - new_size = params->external_offset; + new_size = itl->external_offset; } if (lseek(fd, new_size, SEEK_SET) < 0) { debug("%s: Failed to seek to end of file: %s\n", __func__, @@ -617,7 +617,7 @@ err: return ret; } -static int fit_import_data(struct imgtool *params, const char *fname) +static int fit_import_data(struct imgtool *itl, const char *fname) { void *fdt, *old_fdt; void *data = NULL; @@ -629,7 +629,7 @@ static int fit_import_data(struct imgtool *params, const char *fname) int images; int node; - fd = mmap_fdt(params->cmdname, fname, 0, &old_fdt, &sbuf, false, false); + fd = mmap_fdt(itl->cmdname, fname, 0, &old_fdt, &sbuf, false, false); if (fd < 0) return -EIO; fit_size = fdt_totalsize(old_fdt); @@ -709,7 +709,7 @@ static int fit_import_data(struct imgtool *params, const char *fname) fd = open(fname, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666); if (fd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - params->cmdname, fname, strerror(errno)); + itl->cmdname, fname, strerror(errno)); ret = -EIO; goto err; } @@ -744,7 +744,7 @@ err: * returns: * only on success, otherwise calls exit (EXIT_FAILURE); */ -static int fit_handle_file(struct imgtool *params) +static int fit_handle_file(struct imgtool *itl) { char tmpfile[MKIMAGE_MAX_TMPFILE_LEN]; char bakfile[MKIMAGE_MAX_TMPFILE_LEN + 4] = {0}; @@ -756,31 +756,31 @@ static int fit_handle_file(struct imgtool *params) debug ("FIT format handling\n"); /* call dtc to include binary properties into the tmp file */ - if (strlen (params->imagefile) + + if (strlen(itl->imagefile) + strlen (MKIMAGE_TMPFILE_SUFFIX) + 1 > sizeof (tmpfile)) { fprintf (stderr, "%s: Image file name (%s) too long, " "can't create tmpfile.\n", - params->imagefile, params->cmdname); + itl->imagefile, itl->cmdname); return (EXIT_FAILURE); } - sprintf (tmpfile, "%s%s", params->imagefile, MKIMAGE_TMPFILE_SUFFIX); + sprintf(tmpfile, "%s%s", itl->imagefile, MKIMAGE_TMPFILE_SUFFIX); /* We either compile the source file, or use the existing FIT image */ - if (params->auto_fit) { - if (fit_build(params, tmpfile)) { + if (itl->auto_fit) { + if (fit_build(itl, tmpfile)) { fprintf(stderr, "%s: failed to build FIT\n", - params->cmdname); + itl->cmdname); return EXIT_FAILURE; } *cmd = '\0'; - } else if (params->datafile) { + } else if (itl->datafile) { /* dtc -I dts -O dtb -p 500 -o tmpfile datafile */ snprintf(cmd, sizeof(cmd), "%s %s -o \"%s\" \"%s\"", - MKIMAGE_DTC, params->dtc, tmpfile, params->datafile); + MKIMAGE_DTC, itl->dtc, tmpfile, itl->datafile); debug("Trying to execute \"%s\"\n", cmd); } else { snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"", - params->imagefile, tmpfile); + itl->imagefile, tmpfile); } if (strlen(cmd) >= MKIMAGE_MAX_DTC_CMDLINE_LEN - 1) { fprintf(stderr, "WARNING: command-line for FIT creation might be truncated and will probably fail.\n"); @@ -788,12 +788,12 @@ static int fit_handle_file(struct imgtool *params) if (*cmd && system(cmd) == -1) { fprintf (stderr, "%s: system(%s) failed: %s\n", - params->cmdname, cmd, strerror(errno)); + itl->cmdname, cmd, strerror(errno)); goto err_system; } /* Move the data so it is internal to the FIT, if needed */ - ret = fit_import_data(params, tmpfile); + ret = fit_import_data(itl, tmpfile); if (ret) goto err_system; @@ -821,31 +821,31 @@ static int fit_handle_file(struct imgtool *params) ret = -EIO; break; } - ret = fit_add_file_data(params, size_inc, tmpfile); + ret = fit_add_file_data(itl, size_inc, tmpfile); if (!ret || ret != -ENOSPC) break; } if (ret) { fprintf(stderr, "%s Can't add hashes to FIT blob: %d\n", - params->cmdname, ret); + itl->cmdname, ret); goto err_system; } /* Move the data so it is external to the FIT, if requested */ - if (params->external_data) { - ret = fit_extract_data(params, tmpfile); + if (itl->external_data) { + ret = fit_extract_data(itl, tmpfile); if (ret) goto err_system; } - if (rename (tmpfile, params->imagefile) == -1) { + if (rename(tmpfile, itl->imagefile) == -1) { fprintf (stderr, "%s: Can't rename %s to %s: %s\n", - params->cmdname, tmpfile, params->imagefile, + itl->cmdname, tmpfile, itl->imagefile, strerror (errno)); unlink (tmpfile); unlink(bakfile); - unlink (params->imagefile); + unlink(itl->imagefile); return EXIT_FAILURE; } unlink(bakfile); @@ -889,12 +889,12 @@ static int fit_image_extract( /** * fit_extract_contents - retrieve a sub-image component from the FIT image * @ptr: pointer to the FIT format image header - * @params: command line parameters + * @itl: command line parameters * * returns: * zero in case of success or a negative value if fail. */ -static int fit_extract_contents(void *ptr, struct imgtool *params) +static int fit_extract_contents(void *ptr, struct imgtool *itl) { int images_noffset; int noffset; @@ -916,8 +916,8 @@ static int fit_extract_contents(void *ptr, struct imgtool *params) /* Avoid any overrun */ count = fit_get_subimage_count(fit, images_noffset); - if ((params->pflag < 0) || (count <= params->pflag)) { - printf("No such component at '%d'\n", params->pflag); + if (itl->pflag < 0 || count <= itl->pflag) { + printf("No such component at '%d'\n", itl->pflag); return -1; } @@ -931,14 +931,14 @@ static int fit_extract_contents(void *ptr, struct imgtool *params) * Direct child node of the images parent node, * i.e. component image node. */ - if (params->pflag == count) { + if (itl->pflag == count) { printf("Extracted:\n%s Image %u (%s)\n", p, count, fit_get_name(fit, noffset, NULL)); fit_image_print(fit, noffset, p); return fit_image_extract(fit, noffset, - params->outfile); + itl->outfile); } count++; @@ -948,13 +948,13 @@ static int fit_extract_contents(void *ptr, struct imgtool *params) return 0; } -static int fit_check_params(struct imgtool *params) +static int fit_check_params(struct imgtool *itl) { - if (params->auto_fit) + if (itl->auto_fit) return 0; - return ((params->dflag && params->fflag) || - (params->fflag && params->lflag) || - (params->lflag && params->dflag)); + return ((itl->dflag && itl->fflag) || + (itl->fflag && itl->lflag) || + (itl->lflag && itl->dflag)); } U_BOOT_IMAGE_TYPE( diff --git a/tools/gpheader.h b/tools/gpheader.h index 7f71a1db3f9..193f55f56cc 100644 --- a/tools/gpheader.h +++ b/tools/gpheader.h @@ -35,5 +35,5 @@ int gph_verify_header(struct gp_header *gph, int be); void gph_print_header(const struct gp_header *gph, int be); void gph_set_header(struct gp_header *gph, uint32_t size, uint32_t load_addr, int be); -int gpimage_check_params(struct imgtool *params); +int gpimage_check_params(struct imgtool *itl); #endif diff --git a/tools/gpimage-common.c b/tools/gpimage-common.c index 3486819f4ca..50ca74df90b 100644 --- a/tools/gpimage-common.c +++ b/tools/gpimage-common.c @@ -72,9 +72,9 @@ void gph_set_header(struct gp_header *gph, uint32_t size, uint32_t load_addr, to_be32(&gph->size, &gph->load_addr); } -int gpimage_check_params(struct imgtool *params) +int gpimage_check_params(struct imgtool *itl) { - return (params->dflag && (params->fflag || params->lflag)) || - (params->fflag && (params->dflag || params->lflag)) || - (params->lflag && (params->dflag || params->fflag)); + return (itl->dflag && (itl->fflag || itl->lflag)) || + (itl->fflag && (itl->dflag || itl->lflag)) || + (itl->lflag && (itl->dflag || itl->fflag)); } diff --git a/tools/gpimage.c b/tools/gpimage.c index ac138ac9a6b..118fbff714e 100644 --- a/tools/gpimage.c +++ b/tools/gpimage.c @@ -34,14 +34,14 @@ static int gpimage_check_image_types(uint8_t type) } static int gpimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct gp_header *gph = (struct gp_header *)ptr; return gph_verify_header(gph, 1); } -static void gpimage_print_header(const void *ptr, struct imgtool *params) +static void gpimage_print_header(const void *ptr, struct imgtool *itl) { const struct gp_header *gph = (struct gp_header *)ptr; @@ -49,11 +49,11 @@ static void gpimage_print_header(const void *ptr, struct imgtool *params) } static void gpimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { struct gp_header *gph = (struct gp_header *)ptr; - gph_set_header(gph, sbuf->st_size - GPIMAGE_HDR_SIZE, params->addr, 1); + gph_set_header(gph, sbuf->st_size - GPIMAGE_HDR_SIZE, itl->addr, 1); } /* diff --git a/tools/imagetool.c b/tools/imagetool.c index 726c3ceb2b2..67061592cde 100644 --- a/tools/imagetool.c +++ b/tools/imagetool.c @@ -30,13 +30,13 @@ static int imagetool_verify_print_header_by_type( void *ptr, struct stat *sbuf, struct imgtool_funcs *tparams, - struct imgtool *params); + struct imgtool *itl); int imagetool_verify_print_header( void *ptr, struct stat *sbuf, struct imgtool_funcs *tparams, - struct imgtool *params) + struct imgtool *itl) { int retval = -1; struct imgtool_funcs **curr; @@ -46,7 +46,7 @@ int imagetool_verify_print_header( struct imgtool_funcs **end = __stop_image_type; if (tparams) - return imagetool_verify_print_header_by_type(ptr, sbuf, tparams, params); + return imagetool_verify_print_header_by_type(ptr, sbuf, tparams, itl); for (curr = start; curr != end; curr++) { /* @@ -57,7 +57,7 @@ int imagetool_verify_print_header( continue; if ((*curr)->verify_header) { retval = (*curr)->verify_header((unsigned char *)ptr, - sbuf->st_size, params); + sbuf->st_size, itl); if (retval == 0) { /* @@ -65,12 +65,12 @@ int imagetool_verify_print_header( * successful */ if ((*curr)->print_header) { - if (!params->quiet) - (*curr)->print_header(ptr, params); + if (!itl->quiet) + (*curr)->print_header(ptr, itl); } else { fprintf(stderr, "%s: print_header undefined for %s\n", - params->cmdname, (*curr)->name); + itl->cmdname, (*curr)->name); } break; } @@ -79,7 +79,7 @@ int imagetool_verify_print_header( if (retval != 0) { fprintf(stderr, "%s: cannot detect image type\n", - params->cmdname); + itl->cmdname); } return retval; @@ -89,35 +89,35 @@ static int imagetool_verify_print_header_by_type( void *ptr, struct stat *sbuf, struct imgtool_funcs *tparams, - struct imgtool *params) + struct imgtool *itl) { int retval = -1; if (tparams->verify_header) { retval = tparams->verify_header((unsigned char *)ptr, - sbuf->st_size, params); + sbuf->st_size, itl); if (retval == 0) { /* * Print the image information if verify is successful */ if (tparams->print_header) { - if (!params->quiet) - tparams->print_header(ptr, params); + if (!itl->quiet) + tparams->print_header(ptr, itl); } else { fprintf(stderr, "%s: print_header undefined for %s\n", - params->cmdname, tparams->name); + itl->cmdname, tparams->name); } } else { fprintf(stderr, "%s: verify_header failed for %s with exit code %d\n", - params->cmdname, tparams->name, retval); + itl->cmdname, tparams->name, retval); } } else { fprintf(stderr, "%s: verify_header undefined for %s\n", - params->cmdname, tparams->name); + itl->cmdname, tparams->name); } return retval; @@ -150,7 +150,7 @@ int imagetool_save_subimage( return 0; } -int imagetool_get_filesize(struct imgtool *params, const char *fname) +int imagetool_get_filesize(struct imgtool *itl, const char *fname) { struct stat sbuf; int fd; @@ -158,13 +158,13 @@ int imagetool_get_filesize(struct imgtool *params, const char *fname) fd = open(fname, O_RDONLY | O_BINARY); if (fd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - params->cmdname, fname, strerror(errno)); + itl->cmdname, fname, strerror(errno)); return -1; } if (fstat(fd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", - params->cmdname, fname, strerror(errno)); + itl->cmdname, fname, strerror(errno)); close(fd); return -1; } diff --git a/tools/imagetool.h b/tools/imagetool.h index 42c8d8c8742..c877d52c19a 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -194,7 +194,7 @@ struct imgtool_funcs *imagetool_get_type(int type); * @ptr: pointer the the image header * @sbuf: stat information about the file pointed to by ptr * @tparams: image type parameters or NULL - * @params: mkimage parameters + * @itl: mkimage parameters * * Return: 0 on success, negative if input image format does not match with * the given image type @@ -203,7 +203,7 @@ int imagetool_verify_print_header( void *ptr, struct stat *sbuf, struct imgtool_funcs *tparams, - struct imgtool *params); + struct imgtool *itl); /** * imagetool_save_subimage - store data into a file @@ -228,11 +228,11 @@ int imagetool_save_subimage( * This function prints a message if an error occurs, showing the error that * was obtained. * - * @params: mkimage parameters + * @itl: mkimage parameters * @fname: filename to check * Return: size of file, or -ve value on error */ -int imagetool_get_filesize(struct imgtool *params, const char *fname); +int imagetool_get_filesize(struct imgtool *itl, const char *fname); /** * imagetool_get_source_date() - Get timestamp for build output. diff --git a/tools/imx8image.c b/tools/imx8image.c index bb15f078541..16de4154d94 100644 --- a/tools/imx8image.c +++ b/tools/imx8image.c @@ -22,17 +22,17 @@ static uint16_t sw_version; static uint32_t custom_partition; static uint32_t scfw_flags; -int imx8image_check_params(struct imgtool *params) +int imx8image_check_params(struct imgtool *itl) { return 0; } static void imx8image_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { } -static void imx8image_print_header(const void *ptr, struct imgtool *params) +static void imx8image_print_header(const void *ptr, struct imgtool *itl) { } @@ -1133,8 +1133,8 @@ int imx8image_copy_image(int outfd, struct imgtool *itl) * SECO FW is a container image, this is to calculate the * 2nd container offset. */ - fprintf(stdout, "parsing %s\n", mparams->imagename); - parse_cfg_file(img_sp, mparams->imagename); + fprintf(stdout, "parsing %s\n", itl->imagename); + parse_cfg_file(img_sp, itl->imagename); if (sector_size == 0) { fprintf(stderr, "Wrong sector size\n"); diff --git a/tools/imx8mimage.c b/tools/imx8mimage.c index ecff9aff04d..16f40e40eff 100644 --- a/tools/imx8mimage.c +++ b/tools/imx8mimage.c @@ -49,17 +49,17 @@ static uint32_t get_cfg_value(char *token, char *name, int linenr) return value; } -int imx8mimage_check_params(struct imgtool *params) +int imx8mimage_check_params(struct imgtool *itl) { return 0; } static void imx8mimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { } -static void imx8mimage_print_header(const void *ptr, struct imgtool *params) +static void imx8mimage_print_header(const void *ptr, struct imgtool *itl) { } diff --git a/tools/imximage.c b/tools/imximage.c index 9dd962e144f..cdfc3aa434d 100644 --- a/tools/imximage.c +++ b/tools/imximage.c @@ -803,7 +803,7 @@ static int imximage_check_image_types(uint8_t type) } static int imximage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct imx_header *imx_hdr = (struct imx_header *) ptr; @@ -813,7 +813,7 @@ static int imximage_verify_header(unsigned char *ptr, int image_size, return 0; } -static void imximage_print_header(const void *ptr, struct imgtool *params) +static void imximage_print_header(const void *ptr, struct imgtool *itl) { struct imx_header *imx_hdr = (struct imx_header *) ptr; uint32_t version = detect_imximage_version(imx_hdr); @@ -832,7 +832,7 @@ static void imximage_print_header(const void *ptr, struct imgtool *params) } static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { struct imx_header *imxhdr = (struct imx_header *)ptr; uint32_t dcd_len; @@ -850,7 +850,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd, set_hdr_func(); /* Parse dcd configuration file */ - dcd_len = parse_cfg_file(imxhdr, params->imagename); + dcd_len = parse_cfg_file(imxhdr, itl->imagename); if (imximage_version == IMXIMAGE_V1) header_size = sizeof(flash_header_v1_t); @@ -866,7 +866,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd, imximage_init_loadsize = imximage_ivt_offset + header_size; /* Set the imx header */ - (*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset); + (*set_imx_hdr)(imxhdr, dcd_len, itl->ep, imximage_ivt_offset); /* * ROM bug alert @@ -880,20 +880,20 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd, *header_size_ptr = ROUND((sbuf->st_size + imximage_ivt_offset), 4096); if (csf_ptr && imximage_csf_size) { - *csf_ptr = params->ep - imximage_init_loadsize + + *csf_ptr = itl->ep - imximage_init_loadsize + *header_size_ptr; *header_size_ptr += imximage_csf_size; } } -int imximage_check_params(struct imgtool *params) +int imximage_check_params(struct imgtool *itl) { - if (!params) + if (!itl) return CFG_INVALID; - if (!strlen(params->imagename)) { + if (!strlen(itl->imagename)) { fprintf(stderr, "Error: %s - Configuration file not specified, " "it is needed for imximage generation\n", - params->cmdname); + itl->cmdname); return CFG_INVALID; } /* @@ -902,10 +902,10 @@ int imximage_check_params(struct imgtool *params) * parameters are not sent at the same time * For example, if list is required a data image must not be provided */ - return (params->dflag && (params->fflag || params->lflag)) || - (params->fflag && (params->dflag || params->lflag)) || - (params->lflag && (params->dflag || params->fflag)) || - (params->xflag) || !(strlen(params->imagename)); + return (itl->dflag && (itl->fflag || itl->lflag)) || + (itl->fflag && (itl->dflag || itl->lflag)) || + (itl->lflag && (itl->dflag || itl->fflag)) || + (itl->xflag) || !(strlen(itl->imagename)); } #ifdef CONFIG_FSPI_CONF_HEADER @@ -966,13 +966,12 @@ static void generate_fspi_header(int ifd) } #endif -static int imximage_generate(struct imgtool *params, - struct imgtool_funcs *tparams) +static int imximage_generate(struct imgtool *itl, struct imgtool_funcs *tparams) { struct imx_header *imxhdr; size_t alloc_len; struct stat sbuf; - char *datafile = params->datafile; + char *datafile = itl->datafile; uint32_t pad_len, header_size; #ifdef CONFIG_FSPI_CONF_HEADER @@ -994,7 +993,7 @@ static int imximage_generate(struct imgtool *params, set_hdr_func(); /* Parse dcd configuration file */ - parse_cfg_file(&imximage_header, params->imagename); + parse_cfg_file(&imximage_header, itl->imagename); if (imximage_version == IMXIMAGE_V1) header_size = sizeof(imx_header_v1_t); @@ -1013,7 +1012,7 @@ static int imximage_generate(struct imgtool *params, if (alloc_len < header_size) { fprintf(stderr, "%s: header error\n", - params->cmdname); + itl->cmdname); exit(EXIT_FAILURE); } @@ -1021,7 +1020,7 @@ static int imximage_generate(struct imgtool *params, if (!imxhdr) { fprintf(stderr, "%s: malloc return failure: %s\n", - params->cmdname, strerror(errno)); + itl->cmdname, strerror(errno)); exit(EXIT_FAILURE); } @@ -1034,7 +1033,7 @@ static int imximage_generate(struct imgtool *params, if (stat(datafile, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", - params->cmdname, datafile, strerror(errno)); + itl->cmdname, datafile, strerror(errno)); exit(EXIT_FAILURE); } diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 03c818221c2..d482fe9f324 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -486,7 +486,7 @@ static int kwb_load_rsa_key(const char *keydir, const char *name, RSA **p_rsa) return 0; } -static int kwb_load_cfg_key(struct imgtool *params, +static int kwb_load_cfg_key(struct imgtool *itl, unsigned int cfg_option, const char *key_name, RSA **p_key) { @@ -502,7 +502,7 @@ static int kwb_load_cfg_key(struct imgtool *params, return -ENOENT; } - res = kwb_load_rsa_key(params->keydir, e_key->key_name, &key); + res = kwb_load_rsa_key(itl->keydir, e_key->key_name, &key); if (res < 0) { fprintf(stderr, "Failed to load %s\n", key_name); return -ENOENT; @@ -513,14 +513,14 @@ static int kwb_load_cfg_key(struct imgtool *params, return 0; } -static int kwb_load_kak(struct imgtool *params, RSA **p_kak) +static int kwb_load_kak(struct imgtool *itl, RSA **p_kak) { - return kwb_load_cfg_key(params, IMAGE_CFG_KAK, "KAK", p_kak); + return kwb_load_cfg_key(itl, IMAGE_CFG_KAK, "KAK", p_kak); } -static int kwb_load_csk(struct imgtool *params, RSA **p_csk) +static int kwb_load_csk(struct imgtool *itl, RSA **p_csk) { - return kwb_load_cfg_key(params, IMAGE_CFG_CSK, "CSK", p_csk); + return kwb_load_cfg_key(itl, IMAGE_CFG_CSK, "CSK", p_csk); } static int kwb_compute_pubkey_hash(struct pubkey_der_v1 *pk, @@ -929,7 +929,7 @@ done: return ret; } -static int image_fill_xip_header(void *image, struct imgtool *params) +static int image_fill_xip_header(void *image, struct imgtool *itl) { struct main_hdr_v1 *main_hdr = image; /* kwbimage v0 and v1 have same XIP members */ int version = kwbimage_version(image); @@ -942,21 +942,21 @@ static int image_fill_xip_header(void *image, struct imgtool *params) } if (version == 0 && - params->addr >= 0xE8000000 && params->addr < 0xEFFFFFFF && - params->ep >= 0xE8000000 && params->ep < 0xEFFFFFFF) { + itl->addr >= 0xe8000000 && itl->addr < 0xefffffff && + itl->ep >= 0xe8000000 && itl->ep < 0xefffffff) { /* Load and Execute address is in SPI address space (kwbimage v0) */ - startaddr = 0xE8000000; + startaddr = 0xe8000000; } else if (version != 0 && - params->addr >= 0xD4000000 && params->addr < 0xD7FFFFFF && - params->ep >= 0xD4000000 && params->ep < 0xD7FFFFFF) { + itl->addr >= 0xd4000000 && itl->addr < 0xd7ffffff && + itl->ep >= 0xd4000000 && itl->ep < 0xd7ffffff) { /* Load and Execute address is in SPI address space (kwbimage v1) */ - startaddr = 0xD4000000; + startaddr = 0xd4000000; } else if (version != 0 && - params->addr >= 0xD8000000 && params->addr < 0xDFFFFFFF && - params->ep >= 0xD8000000 && params->ep < 0xDFFFFFFF) { + itl->addr >= 0xd8000000 && itl->addr < 0xdfffffff && + itl->ep >= 0xd8000000 && itl->ep < 0xdfffffff) { /* Load and Execute address is in Device bus space (kwbimage v1) */ - startaddr = 0xD8000000; - } else if (params->addr != 0x0) { + startaddr = 0xd8000000; + } else if (itl->addr != 0x0) { /* Load address is non-zero */ if (version == 0) fprintf(stderr, "XIP Load Address or XIP Entry Point is not in SPI address space\n"); @@ -977,18 +977,18 @@ static int image_fill_xip_header(void *image, struct imgtool *params) * Independent and in this case mkimage's --entry-point address * is relative offset from beginning of the data part of image. */ - main_hdr->execaddr = cpu_to_le32(srcaddr + params->ep); + main_hdr->execaddr = cpu_to_le32(srcaddr + itl->ep); } else { /* The lowest possible load address is after the header at srcaddr. */ - if (params->addr - startaddr < srcaddr) { + if (itl->addr - startaddr < srcaddr) { fprintf(stderr, "Invalid XIP Load Address 0x%08x.\n" "The lowest address for this configuration is 0x%08x.\n", - params->addr, (unsigned)(startaddr + srcaddr)); + itl->addr, (unsigned int)(startaddr + srcaddr)); return 0; } - main_hdr->srcaddr = cpu_to_le32(params->addr - startaddr); - main_hdr->execaddr = cpu_to_le32(params->ep - startaddr); + main_hdr->srcaddr = cpu_to_le32(itl->addr - startaddr); + main_hdr->execaddr = cpu_to_le32(itl->ep - startaddr); } return 1; @@ -1039,7 +1039,7 @@ static size_t image_headersz_v0(int *hasext) return headersz; } -static void *image_create_v0(size_t *dataoff, struct imgtool *params, +static void *image_create_v0(size_t *dataoff, struct imgtool *itl, int payloadsz) { struct image_cfg_element *e; @@ -1071,8 +1071,8 @@ static void *image_create_v0(size_t *dataoff, struct imgtool *params, main_hdr->srcaddr = cpu_to_le32(*dataoff); main_hdr->ext = has_ext; main_hdr->version = 0; - main_hdr->destaddr = cpu_to_le32(params->addr); - main_hdr->execaddr = cpu_to_le32(params->ep); + main_hdr->destaddr = cpu_to_le32(itl->addr); + main_hdr->execaddr = cpu_to_le32(itl->ep); main_hdr->blockid = image_get_bootfrom(); e = image_find_option(IMAGE_CFG_NAND_ECC_MODE); @@ -1090,16 +1090,16 @@ static void *image_create_v0(size_t *dataoff, struct imgtool *params, /* For SATA srcaddr is specified in number of sectors. */ if (main_hdr->blockid == IBR_HDR_SATA_ID) { - params->bl_len = image_get_satablksz(); - main_hdr->srcaddr = cpu_to_le32(le32_to_cpu(main_hdr->srcaddr) / params->bl_len); + itl->bl_len = image_get_satablksz(); + main_hdr->srcaddr = cpu_to_le32(le32_to_cpu(main_hdr->srcaddr) / itl->bl_len); } /* For PCIe srcaddr is not used and must be set to 0xFFFFFFFF. */ if (main_hdr->blockid == IBR_HDR_PEX_ID) main_hdr->srcaddr = cpu_to_le32(0xFFFFFFFF); - if (params->xflag) { - if (!image_fill_xip_header(main_hdr, params)) { + if (itl->xflag) { + if (!image_fill_xip_header(main_hdr, itl)) { free(image); return NULL; } @@ -1369,7 +1369,7 @@ static int export_pub_kak_hash(RSA *kak, struct secure_hdr_v1 *secure_hdr) return res < 0 ? 1 : 0; } -static int kwb_sign_csk_with_kak(struct imgtool *params, +static int kwb_sign_csk_with_kak(struct imgtool *itl, struct secure_hdr_v1 *secure_hdr, RSA *csk) { RSA *kak = NULL; @@ -1382,7 +1382,7 @@ static int kwb_sign_csk_with_kak(struct imgtool *params, return 1; } - if (kwb_load_kak(params, &kak) < 0) + if (kwb_load_kak(itl, &kak) < 0) return 1; if (export_pub_kak_hash(kak, secure_hdr)) @@ -1411,7 +1411,7 @@ static int kwb_sign_csk_with_kak(struct imgtool *params, return 0; } -static int add_secure_header_v1(struct imgtool *params, uint8_t *image_ptr, +static int add_secure_header_v1(struct imgtool *itl, uint8_t *image_ptr, size_t image_size, uint8_t *header_ptr, size_t headersz, struct secure_hdr_v1 *secure_hdr) { @@ -1428,7 +1428,7 @@ static int add_secure_header_v1(struct imgtool *params, uint8_t *image_ptr, e_boxid = image_find_option(IMAGE_CFG_BOX_ID); e_flashid = image_find_option(IMAGE_CFG_FLASH_ID); - if (kwb_load_csk(params, &csk) < 0) + if (kwb_load_csk(itl, &csk) < 0) return 1; secure_hdr->headertype = OPT_HDR_V1_SECURE_TYPE; @@ -1441,7 +1441,7 @@ static int add_secure_header_v1(struct imgtool *params, uint8_t *image_ptr, if (e_flashid && specialized_img) secure_hdr->flashid = cpu_to_le32(e_flashid->flashid); - if (kwb_sign_csk_with_kak(params, secure_hdr, csk)) + if (kwb_sign_csk_with_kak(itl, secure_hdr, csk)) return 1; if (kwb_sign_and_verify(csk, image_ptr, image_size - 4, @@ -1474,7 +1474,7 @@ static void finish_register_set_header_v1(uint8_t **cur, uint8_t **next_ext, *datai = 0; } -static void *image_create_v1(size_t *dataoff, struct imgtool *params, +static void *image_create_v1(size_t *dataoff, struct imgtool *itl, uint8_t *ptr, int payloadsz) { struct image_cfg_element *e; @@ -1515,8 +1515,8 @@ static void *image_create_v1(size_t *dataoff, struct imgtool *params, cpu_to_le32(payloadsz); main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF); main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16; - main_hdr->destaddr = cpu_to_le32(params->addr); - main_hdr->execaddr = cpu_to_le32(params->ep); + main_hdr->destaddr = cpu_to_le32(itl->addr); + main_hdr->execaddr = cpu_to_le32(itl->ep); main_hdr->srcaddr = cpu_to_le32(*dataoff); main_hdr->ext = hasext; main_hdr->version = 1; @@ -1546,16 +1546,16 @@ static void *image_create_v1(size_t *dataoff, struct imgtool *params, /* For SATA srcaddr is specified in number of sectors. */ if (main_hdr->blockid == IBR_HDR_SATA_ID) { - params->bl_len = image_get_satablksz(); - main_hdr->srcaddr = cpu_to_le32(le32_to_cpu(main_hdr->srcaddr) / params->bl_len); + itl->bl_len = image_get_satablksz(); + main_hdr->srcaddr = cpu_to_le32(le32_to_cpu(main_hdr->srcaddr) / itl->bl_len); } /* For PCIe srcaddr is not used and must be set to 0xFFFFFFFF. */ if (main_hdr->blockid == IBR_HDR_PEX_ID) main_hdr->srcaddr = cpu_to_le32(0xFFFFFFFF); - if (params->xflag) { - if (!image_fill_xip_header(main_hdr, params)) { + if (itl->xflag) { + if (!image_fill_xip_header(main_hdr, itl)) { free(image); return NULL; } @@ -1623,7 +1623,7 @@ static void *image_create_v1(size_t *dataoff, struct imgtool *params, &datai, delay); } - if (secure_hdr && add_secure_header_v1(params, ptr + *dataoff, payloadsz, + if (secure_hdr && add_secure_header_v1(itl, ptr + *dataoff, payloadsz, image, headersz, secure_hdr)) return NULL; @@ -1905,7 +1905,7 @@ static int image_get_version(void) } static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { FILE *fcfg; void *image = NULL; @@ -1916,25 +1916,25 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, struct stat s; int ret; - params->bl_len = 1; + itl->bl_len = 1; /* * Do not use sbuf->st_size as it contains size with padding. * We need original image data size, so stat original file. */ - if (params->skipcpy) { + if (itl->skipcpy) { s.st_size = 0; - } else if (stat(params->datafile, &s)) { + } else if (stat(itl->datafile, &s)) { fprintf(stderr, "Could not stat data file %s: %s\n", - params->datafile, strerror(errno)); + itl->datafile, strerror(errno)); exit(EXIT_FAILURE); } datasz = ALIGN(s.st_size, 4); - fcfg = fopen(params->imagename, "r"); + fcfg = fopen(itl->imagename, "r"); if (!fcfg) { fprintf(stderr, "Could not open input file %s\n", - params->imagename); + itl->imagename); exit(EXIT_FAILURE); } @@ -1965,11 +1965,11 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, */ case -1: case 0: - image = image_create_v0(&dataoff, params, datasz + 4); + image = image_create_v0(&dataoff, itl, datasz + 4); break; case 1: - image = image_create_v1(&dataoff, params, ptr, datasz + 4); + image = image_create_v1(&dataoff, itl, ptr, datasz + 4); break; default: @@ -1997,7 +1997,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, free(image); } -static void kwbimage_print_header(const void *ptr, struct imgtool *params) +static void kwbimage_print_header(const void *ptr, struct imgtool *itl) { struct main_hdr_v0 *mhdr = (struct main_hdr_v0 *)ptr; struct bin_hdr_v0 *bhdr; @@ -2031,9 +2031,9 @@ static void kwbimage_print_header(const void *ptr, struct imgtool *params) if (mhdr->blockid == IBR_HDR_SATA_ID) printf("%u Sector%s (LBA) = ", le32_to_cpu(mhdr->srcaddr), le32_to_cpu(mhdr->srcaddr) != 1 ? "s" : ""); - genimg_print_size(le32_to_cpu(mhdr->srcaddr) * params->bl_len); + genimg_print_size(le32_to_cpu(mhdr->srcaddr) * itl->bl_len); if (mhdr->blockid == IBR_HDR_SATA_ID) - printf("Sector Size: %u Bytes\n", params->bl_len); + printf("Sector Size: %u Bytes\n", itl->bl_len); if (mhdr->blockid == IBR_HDR_SPI_ID && le32_to_cpu(mhdr->destaddr) == 0xFFFFFFFF) { printf("Load Address: XIP\n"); printf("Execute Offs: %08x\n", le32_to_cpu(mhdr->execaddr)); @@ -2052,7 +2052,7 @@ static int kwbimage_check_image_types(uint8_t type) } static int kwbimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { size_t header_size = kwbheader_size(ptr); uint8_t blockid; @@ -2133,7 +2133,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, if (image_checksum32(ptr + offset * blksz, size - 4) == *(uint32_t *)(ptr + offset * blksz + size - 4)) { - params->bl_len = blksz; + itl->bl_len = blksz; return 0; } } @@ -2155,12 +2155,11 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, *(uint32_t *)(ptr + offset + size - 4)) return -FDT_ERR_BADSTRUCTURE; - params->bl_len = 1; + itl->bl_len = 1; return 0; } -static int kwbimage_generate(struct imgtool *params, - struct imgtool_funcs *tparams) +static int kwbimage_generate(struct imgtool *itl, struct imgtool_funcs *tparams) { FILE *fcfg; struct stat s; @@ -2172,18 +2171,18 @@ static int kwbimage_generate(struct imgtool *params, int align, size; unsigned int satablksz; - fcfg = fopen(params->imagename, "r"); + fcfg = fopen(itl->imagename, "r"); if (!fcfg) { fprintf(stderr, "Could not open input file %s\n", - params->imagename); + itl->imagename); exit(EXIT_FAILURE); } - if (params->skipcpy) { + if (itl->skipcpy) { s.st_size = 0; - } else if (stat(params->datafile, &s)) { + } else if (stat(itl->datafile, &s)) { fprintf(stderr, "Could not stat data file %s: %s\n", - params->datafile, strerror(errno)); + itl->datafile, strerror(errno)); exit(EXIT_FAILURE); } @@ -2245,7 +2244,7 @@ static int kwbimage_generate(struct imgtool *params, hdr = malloc(alloc_len); if (!hdr) { fprintf(stderr, "%s: malloc return failure: %s\n", - params->cmdname, strerror(errno)); + itl->cmdname, strerror(errno)); exit(EXIT_FAILURE); } @@ -2283,7 +2282,7 @@ static int kwbimage_generate(struct imgtool *params, * function is ignored, so we have to put required kwbimage aligning * into the preallocated header size. */ - if (params->skipcpy) { + if (itl->skipcpy) { tparams->header_size += size; return 0; } else { @@ -2291,7 +2290,7 @@ static int kwbimage_generate(struct imgtool *params, } } -static int kwbimage_generate_config(void *ptr, struct imgtool *params) +static int kwbimage_generate_config(void *ptr, struct imgtool *itl) { struct main_hdr_v0 *mhdr0 = (struct main_hdr_v0 *)ptr; struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr; @@ -2310,9 +2309,10 @@ static int kwbimage_generate_config(void *ptr, struct imgtool *params) FILE *f; int i; - f = fopen(params->outfile, "w"); + f = fopen(itl->outfile, "w"); if (!f) { - fprintf(stderr, "Can't open \"%s\": %s\n", params->outfile, strerror(errno)); + fprintf(stderr, "Can't open \"%s\": %s\n", itl->outfile, + strerror(errno)); return -1; } @@ -2353,7 +2353,7 @@ static int kwbimage_generate_config(void *ptr, struct imgtool *params) fprintf(f, "SATA_PIO_MODE %u\n", (unsigned)mhdr0->satapiomode); if (mhdr->blockid == IBR_HDR_SATA_ID) - fprintf(f, "SATA_BLKSZ %u\n", params->bl_len); + fprintf(f, "SATA_BLKSZ %u\n", itl->bl_len); /* * Addresses and sizes which are specified by mkimage command line @@ -2511,13 +2511,13 @@ static int kwbimage_generate_config(void *ptr, struct imgtool *params) return 0; } -static int kwbimage_extract_subimage(void *ptr, struct imgtool *params) +static int kwbimage_extract_subimage(void *ptr, struct imgtool *itl) { struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr; size_t header_size = kwbheader_size(ptr); struct bin_hdr_v0 *bhdr; struct opt_hdr_v1 *ohdr; - int idx = params->pflag; + int idx = itl->pflag; int cur_idx; uint32_t offset; ulong image; @@ -2525,7 +2525,7 @@ static int kwbimage_extract_subimage(void *ptr, struct imgtool *params) /* Generate kwbimage config file when '-p -1' is specified */ if (idx == -1) - return kwbimage_generate_config(ptr, params); + return kwbimage_generate_config(ptr, itl); image = 0; size = 0; @@ -2535,7 +2535,7 @@ static int kwbimage_extract_subimage(void *ptr, struct imgtool *params) offset = le32_to_cpu(mhdr->srcaddr); if (mhdr->blockid == IBR_HDR_SATA_ID) - offset *= params->bl_len; + offset *= itl->bl_len; if (mhdr->blockid == IBR_HDR_PEX_ID && offset == 0xFFFFFFFF) offset = header_size; @@ -2578,22 +2578,22 @@ static int kwbimage_extract_subimage(void *ptr, struct imgtool *params) } } - return imagetool_save_subimage(params->outfile, image, size); + return imagetool_save_subimage(itl->outfile, image, size); } -static int kwbimage_check_params(struct imgtool *params) +static int kwbimage_check_params(struct imgtool *itl) { - if (!params->lflag && !params->iflag && !params->pflag && - (!params->imagename || !strlen(params->imagename))) { + if (!itl->lflag && !itl->iflag && !itl->pflag && + (!itl->imagename || !strlen(itl->imagename))) { char *msg = "Configuration file for kwbimage creation omitted"; - fprintf(stderr, "Error:%s - %s\n", params->cmdname, msg); + fprintf(stderr, "Error:%s - %s\n", itl->cmdname, msg); return 1; } - return (params->dflag && (params->fflag || params->lflag || params->skipcpy)) || - (params->fflag) || - (params->lflag && (params->dflag || params->fflag)); + return (itl->dflag && (itl->fflag || itl->lflag || itl->skipcpy)) || + (itl->fflag) || + (itl->lflag && (itl->dflag || itl->fflag)); } /* diff --git a/tools/lpc32xximage.c b/tools/lpc32xximage.c index d1e5efea44c..c336b4d10ab 100644 --- a/tools/lpc32xximage.c +++ b/tools/lpc32xximage.c @@ -80,7 +80,7 @@ static int lpc32xximage_check_image_types(uint8_t type) } static int lpc32xximage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; @@ -125,7 +125,7 @@ static void print_hdr_byte(struct nand_page_0_boot_header *hdr, int ofs) printf("header[%d] = %02x\n", ofs, hdr->data[ofs]); } -static void lpc32xximage_print_header(const void *ptr, struct imgtool *params) +static void lpc32xximage_print_header(const void *ptr, struct imgtool *itl) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; @@ -137,7 +137,7 @@ static void lpc32xximage_print_header(const void *ptr, struct imgtool *params) } static void lpc32xximage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; diff --git a/tools/mtk_image.c b/tools/mtk_image.c index deaa2ed930f..12e8a937a64 100644 --- a/tools/mtk_image.c +++ b/tools/mtk_image.c @@ -228,22 +228,22 @@ static int mtk_brom_parse_imagename(const char *imagename) return 0; } -static int mtk_image_check_params(struct imgtool *params) +static int mtk_image_check_params(struct imgtool *itl) { - if (!params->addr) { + if (!itl->addr) { fprintf(stderr, "Error: Load Address must be set.\n"); return -EINVAL; } - if (!params->imagename) { + if (!itl->imagename) { fprintf(stderr, "Error: Image Name must be set.\n"); return -EINVAL; } - return mtk_brom_parse_imagename(params->imagename); + return mtk_brom_parse_imagename(itl->imagename); } -static int mtk_image_vrec_header(struct imgtool *params, +static int mtk_image_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams) { if (use_lk_hdr) { @@ -488,7 +488,7 @@ static int mtk_image_verify_mt7621_header(const uint8_t *ptr, int print) } static int mtk_image_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct legacy_img_hdr *hdr = (struct legacy_img_hdr *)ptr; union lk_hdr *lk = (union lk_hdr *)ptr; @@ -510,7 +510,7 @@ static int mtk_image_verify_header(unsigned char *ptr, int image_size, return -1; } -static void mtk_image_print_header(const void *ptr, struct imgtool *params) +static void mtk_image_print_header(const void *ptr, struct imgtool *itl) { struct legacy_img_hdr *hdr = (struct legacy_img_hdr *)ptr; union lk_hdr *lk = (union lk_hdr *)ptr; @@ -730,14 +730,14 @@ static void mtk_image_set_mt7621_header(void *ptr, off_t filesize, } static void mtk_image_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { union lk_hdr *lk = (union lk_hdr *)ptr; if (use_lk_hdr) { lk->magic = cpu_to_le32(LK_PART_MAGIC); lk->size = cpu_to_le32(sbuf->st_size - sizeof(union lk_hdr)); - lk->loadaddr = cpu_to_le32(params->addr); + lk->loadaddr = cpu_to_le32(itl->addr); lk->mode = 0xffffffff; /* must be non-zero */ memset(lk->name, 0, sizeof(lk->name)); strncpy(lk->name, lk_name, sizeof(lk->name)); @@ -748,14 +748,14 @@ static void mtk_image_set_header(void *ptr, struct stat *sbuf, int ifd, img_size = sbuf->st_size; if (use_mt7621_hdr) { - mtk_image_set_mt7621_header(ptr, sbuf->st_size, params->addr); + mtk_image_set_mt7621_header(ptr, sbuf->st_size, itl->addr); return; } if (hdr_media == BRLYT_TYPE_NAND || hdr_media == BRLYT_TYPE_SNAND) - mtk_image_set_nand_header(ptr, sbuf->st_size, params->addr); + mtk_image_set_nand_header(ptr, sbuf->st_size, itl->addr); else - mtk_image_set_gen_header(ptr, sbuf->st_size, params->addr); + mtk_image_set_gen_header(ptr, sbuf->st_size, itl->addr); } U_BOOT_IMAGE_TYPE( diff --git a/tools/mxsimage.c b/tools/mxsimage.c index 1e483a74c9d..2df2e32e2cd 100644 --- a/tools/mxsimage.c +++ b/tools/mxsimage.c @@ -2171,18 +2171,18 @@ static int mxsimage_check_image_types(uint8_t type) } static void mxsimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { } -int mxsimage_check_params(struct imgtool *params) +int mxsimage_check_params(struct imgtool *itl) { - if (!params) + if (!itl) return -1; - if (!strlen(params->imagename)) { + if (!strlen(itl->imagename)) { fprintf(stderr, "Error: %s - Configuration file not specified, it is needed for mxsimage generation\n", - params->cmdname); + itl->cmdname); return -1; } @@ -2192,10 +2192,10 @@ int mxsimage_check_params(struct imgtool *params) * parameters are not sent at the same time * For example, if list is required a data image must not be provided */ - return (params->dflag && (params->fflag || params->lflag)) || - (params->fflag && (params->dflag || params->lflag)) || - (params->lflag && (params->dflag || params->fflag)) || - (params->xflag) || !(strlen(params->imagename)); + return (itl->dflag && (itl->fflag || itl->lflag)) || + (itl->fflag && (itl->dflag || itl->lflag)) || + (itl->lflag && (itl->dflag || itl->fflag)) || + (itl->xflag) || !(strlen(itl->imagename)); } static int mxsimage_verify_print_header(char *file, int silent) @@ -2216,7 +2216,7 @@ static int mxsimage_verify_print_header(char *file, int silent) char *imagefile; static int mxsimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct sb_boot_image_header *hdr; @@ -2233,12 +2233,12 @@ static int mxsimage_verify_header(unsigned char *ptr, int image_size, memcmp(hdr->signature2, "sgtl", 4)) return -EINVAL; - imagefile = params->imagefile; + imagefile = itl->imagefile; - return mxsimage_verify_print_header(params->imagefile, 1); + return mxsimage_verify_print_header(itl->imagefile, 1); } -static void mxsimage_print_header(const void *hdr, struct imgtool *params) +static void mxsimage_print_header(const void *hdr, struct imgtool *itl) { if (imagefile) mxsimage_verify_print_header(imagefile, 0); @@ -2314,19 +2314,18 @@ static int sb_build_image(struct sb_image_ctx *ictx, return 0; } -static int mxsimage_generate(struct imgtool *params, - struct imgtool_funcs *tparams) +static int mxsimage_generate(struct imgtool *itl, struct imgtool_funcs *tparams) { int ret; struct sb_image_ctx ctx; /* Do not copy the U-Boot image! */ - params->skipcpy = 1; + itl->skipcpy = 1; memset(&ctx, 0, sizeof(ctx)); - ctx.cfg_filename = params->imagename; - ctx.output_filename = params->imagefile; + ctx.cfg_filename = itl->imagename; + ctx.output_filename = itl->imagefile; ret = sb_build_tree_from_cfg(&ctx); if (ret) diff --git a/tools/omapimage.c b/tools/omapimage.c index 428dc782f9b..23be1652b0f 100644 --- a/tools/omapimage.c +++ b/tools/omapimage.c @@ -37,7 +37,7 @@ static int omapimage_check_image_types(uint8_t type) } static int omapimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct ch_toc *toc = (struct ch_toc *)ptr; struct gp_header *gph = (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE); @@ -85,7 +85,7 @@ static void omapimage_print_section(struct ch_settings *chs) chs->flags); } -static void omapimage_print_header(const void *ptr, struct imgtool *params) +static void omapimage_print_header(const void *ptr, struct imgtool *itl) { const struct ch_toc *toc = (struct ch_toc *)ptr; const struct gp_header *gph = @@ -124,7 +124,7 @@ static int toc_offset(void *hdr, void *member) } static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { struct ch_toc *toc = (struct ch_toc *)ptr; struct ch_settings *chs = (struct ch_settings *) @@ -144,10 +144,9 @@ static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd, toc++; memset(toc, 0xff, sizeof(*toc)); - gph_set_header(gph, sbuf->st_size - OMAP_CH_HDR_SIZE, - params->addr, 0); + gph_set_header(gph, sbuf->st_size - OMAP_CH_HDR_SIZE, itl->addr, 0); - if (strncmp(params->imagename, "byteswap", 8) == 0) { + if (strncmp(itl->imagename, "byteswap", 8) == 0) { do_swap32 = 1; int swapped = 0; uint32_t *data = (uint32_t *)ptr; diff --git a/tools/pblimage.c b/tools/pblimage.c index 17dff95c46d..a1f3be6b181 100644 --- a/tools/pblimage.c +++ b/tools/pblimage.c @@ -185,22 +185,22 @@ static void add_end_cmd(void) pbl_size += 4; } -void pbl_load_uboot(int ifd, struct imgtool *params) +void pbl_load_uboot(int ifd, struct imgtool *itl) { FILE *fp_uboot; int size, ret; /* parse the rcw.cfg file. */ - pbl_parser(params->imagename); + pbl_parser(itl->imagename); /* parse the pbi.cfg file. */ - if (params->imagename2[0] != '\0') - pbl_parser(params->imagename2); + if (itl->imagename2[0] != '\0') + pbl_parser(itl->imagename2); - if (params->datafile) { - fp_uboot = fopen(params->datafile, "r"); + if (itl->datafile) { + fp_uboot = fopen(itl->datafile, "r"); if (fp_uboot == NULL) { - printf("Error: %s open failed\n", params->datafile); + printf("Error: %s open failed\n", itl->datafile); exit(EXIT_FAILURE); } @@ -218,7 +218,7 @@ void pbl_load_uboot(int ifd, struct imgtool *params) size = pbl_size; if (write(ifd, (const void *)&mem_buf, size) != size) { fprintf(stderr, "Write error on %s: %s\n", - params->imagefile, strerror(errno)); + itl->imagefile, strerror(errno)); exit(EXIT_FAILURE); } } @@ -232,12 +232,12 @@ static int pblimage_check_image_types(uint8_t type) } static int pblimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct pbl_header *pbl_hdr = (struct pbl_header *) ptr; uint32_t rcwheader; - if (params->arch == IH_ARCH_ARM) + if (itl->arch == IH_ARCH_ARM) rcwheader = RCW_ARM_HEADER; else rcwheader = RCW_PPC_HEADER; @@ -259,30 +259,30 @@ static int pblimage_verify_header(unsigned char *ptr, int image_size, return 0; } -static void pblimage_print_header(const void *ptr, struct imgtool *params) +static void pblimage_print_header(const void *ptr, struct imgtool *itl) { printf("Image Type: Freescale PBL Boot Image\n"); } static void pblimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { /*nothing need to do, pbl_load_uboot takes care of whole file. */ } -int pblimage_check_params(struct imgtool *params) +int pblimage_check_params(struct imgtool *itl) { FILE *fp_uboot; int fd; struct stat st; - if (!params) + if (!itl) return EXIT_FAILURE; - if (params->datafile) { - fp_uboot = fopen(params->datafile, "r"); + if (itl->datafile) { + fp_uboot = fopen(itl->datafile, "r"); if (fp_uboot == NULL) { - printf("Error: %s open failed\n", params->datafile); + printf("Error: %s open failed\n", itl->datafile); exit(EXIT_FAILURE); } fd = fileno(fp_uboot); @@ -298,18 +298,18 @@ int pblimage_check_params(struct imgtool *params) fclose(fp_uboot); } - if (params->arch == IH_ARCH_ARM) { + if (itl->arch == IH_ARCH_ARM) { arch_flag = IH_ARCH_ARM; pbi_crc_cmd1 = 0x61; pbi_crc_cmd2 = 0; - pbl_cmd_initaddr = params->addr & PBL_ADDR_24BIT_MASK; + pbl_cmd_initaddr = itl->addr & PBL_ADDR_24BIT_MASK; pbl_cmd_initaddr |= PBL_ACS_CONT_CMD; pbl_cmd_initaddr += uboot_size; pbl_end_cmd[0] = 0x09610000; pbl_end_cmd[1] = 0x00000000; pbl_end_cmd[2] = 0x096100c0; pbl_end_cmd[3] = 0x00000000; - } else if (params->arch == IH_ARCH_PPC) { + } else if (itl->arch == IH_ARCH_PPC) { arch_flag = IH_ARCH_PPC; pbi_crc_cmd1 = 0x13; pbi_crc_cmd2 = 0x80; diff --git a/tools/renesas_spkgimage.c b/tools/renesas_spkgimage.c index 8cc3a62081a..5a87d029755 100644 --- a/tools/renesas_spkgimage.c +++ b/tools/renesas_spkgimage.c @@ -115,19 +115,19 @@ static int spkgimage_parse_config_file(char *filename) return 0; } -static int spkgimage_check_params(struct imgtool *params) +static int spkgimage_check_params(struct imgtool *itl) { - if (!params->addr) { + if (!itl->addr) { fprintf(stderr, "Error: Load Address must be set.\n"); return -EINVAL; } - if (!params->imagename || !params->imagename[0]) { + if (!itl->imagename || !itl->imagename[0]) { fprintf(stderr, "Error: Image name must be set.\n"); return -EINVAL; } - if (!params->datafile) { + if (!itl->datafile) { fprintf(stderr, "Error: Data filename must be set.\n"); return -EINVAL; } @@ -215,25 +215,25 @@ static inline uint32_t roundup(uint32_t x, uint32_t y) return ((x + y - 1) / y) * y; } -static int spkgimage_vrec_header(struct imgtool *params, +static int spkgimage_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams) { struct stat s; struct spkg_file *out_buf; /* Parse the config file */ - if (spkgimage_parse_config_file(params->imagename)) { + if (spkgimage_parse_config_file(itl->imagename)) { fprintf(stderr, "Error parsing config file\n"); exit(EXIT_FAILURE); } /* Get size of input data file */ - if (stat(params->datafile, &s)) { + if (stat(itl->datafile, &s)) { fprintf(stderr, "Could not stat data file: %s: %s\n", - params->datafile, strerror(errno)); + itl->datafile, strerror(errno)); exit(EXIT_FAILURE); } - params->orig_file_size = s.st_size; + itl->orig_file_size = s.st_size; /* Determine size of resulting SPKG file */ uint32_t header_len = SPKG_HEADER_SIZE * SPKG_HEADER_COUNT; @@ -257,8 +257,8 @@ static int spkgimage_vrec_header(struct imgtool *params, .ecc_scheme = conf.ecc_scheme, .ecc_bytes = conf.ecc_bytes, .payload_length = cpu_to_le32(payload_len << 8), - .load_address = cpu_to_le32(params->addr), - .execution_offset = cpu_to_le32(params->ep - params->addr), + .load_address = cpu_to_le32(itl->addr), + .execution_offset = cpu_to_le32(itl->ep - itl->addr), }; header.crc = crc32(0, (uint8_t *)&header, sizeof(header) - SPKG_CRC_SIZE); @@ -281,15 +281,15 @@ static int spkgimage_vrec_header(struct imgtool *params, } static void spkgimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { uint8_t *payload = ptr + SPKG_HEADER_SIZE * SPKG_HEADER_COUNT; - uint8_t *file_end = payload + conf.blp_len + params->orig_file_size; + uint8_t *file_end = payload + conf.blp_len + itl->orig_file_size; uint8_t *crc_buf = file_end + conf.padding; uint32_t crc; /* Make room for the Dummy BLp header */ - memmove(payload + conf.blp_len, payload, params->orig_file_size); + memmove(payload + conf.blp_len, payload, itl->orig_file_size); /* Fill the SPKG with the Dummy BLp */ memset(payload, 0x88, conf.blp_len); diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 860008d4c81..5872e4c005f 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -177,12 +177,12 @@ static struct spl_info *rkcommon_get_spl_info(char *imagename) return NULL; } -static int rkcommon_get_aligned_size(struct imgtool *params, +static int rkcommon_get_aligned_size(struct imgtool *itl, const char *fname) { int size; - size = imagetool_get_filesize(params, fname); + size = imagetool_get_filesize(itl, fname); if (size < 0) return -1; @@ -193,7 +193,7 @@ static int rkcommon_get_aligned_size(struct imgtool *params, return ROUND(size, RK_SIZE_ALIGN); } -int rkcommon_check_params(struct imgtool *params) +int rkcommon_check_params(struct imgtool *itl) { int i, size; @@ -201,13 +201,13 @@ int rkcommon_check_params(struct imgtool *params) * If this is a operation (list or extract), the don't require * imagename to be set. */ - if (params->lflag || params->iflag) + if (itl->lflag || itl->iflag) return EXIT_SUCCESS; - if (!rkcommon_get_spl_info(params->imagename)) + if (!rkcommon_get_spl_info(itl->imagename)) goto err_spl_info; - spl_params.init_file = params->datafile; + spl_params.init_file = itl->datafile; spl_params.boot_file = strchr(spl_params.init_file, ':'); if (spl_params.boot_file) { @@ -215,23 +215,23 @@ int rkcommon_check_params(struct imgtool *params) spl_params.boot_file += 1; } - size = rkcommon_get_aligned_size(params, spl_params.init_file); + size = rkcommon_get_aligned_size(itl, spl_params.init_file); if (size < 0) return EXIT_FAILURE; spl_params.init_size = size; /* Boot file is optional, and only for back-to-bootrom functionality. */ if (spl_params.boot_file) { - size = rkcommon_get_aligned_size(params, spl_params.boot_file); + size = rkcommon_get_aligned_size(itl, spl_params.boot_file); if (size < 0) return EXIT_FAILURE; spl_params.boot_size = size; } - if (spl_params.init_size > rkcommon_get_spl_size(params)) { + if (spl_params.init_size > rkcommon_get_spl_size(itl)) { fprintf(stderr, "Error: SPL image is too large (size %#x than %#x)\n", - spl_params.init_size, rkcommon_get_spl_size(params)); + spl_params.init_size, rkcommon_get_spl_size(itl)); return EXIT_FAILURE; } @@ -239,7 +239,7 @@ int rkcommon_check_params(struct imgtool *params) err_spl_info: fprintf(stderr, "ERROR: imagename (%s) is not supported!\n", - params->imagename ? params->imagename : "NULL"); + itl->imagename ? itl->imagename : "NULL"); fprintf(stderr, "Available imagename:"); for (i = 0; i < ARRAY_SIZE(spl_infos); i++) @@ -249,9 +249,9 @@ err_spl_info: return EXIT_FAILURE; } -const char *rkcommon_get_spl_hdr(struct imgtool *params) +const char *rkcommon_get_spl_hdr(struct imgtool *itl) { - struct spl_info *info = rkcommon_get_spl_info(params->imagename); + struct spl_info *info = rkcommon_get_spl_info(itl->imagename); /* * info would not be NULL, because of we checked params before. @@ -259,9 +259,9 @@ const char *rkcommon_get_spl_hdr(struct imgtool *params) return info->spl_hdr; } -int rkcommon_get_spl_size(struct imgtool *params) +int rkcommon_get_spl_size(struct imgtool *itl) { - struct spl_info *info = rkcommon_get_spl_info(params->imagename); + struct spl_info *info = rkcommon_get_spl_info(itl->imagename); /* * info would not be NULL, because of we checked params before. @@ -269,9 +269,9 @@ int rkcommon_get_spl_size(struct imgtool *params) return info->spl_size; } -bool rkcommon_need_rc4_spl(struct imgtool *params) +bool rkcommon_need_rc4_spl(struct imgtool *itl) { - struct spl_info *info = rkcommon_get_spl_info(params->imagename); + struct spl_info *info = rkcommon_get_spl_info(itl->imagename); /* * info would not be NULL, because of we checked params before. @@ -279,9 +279,9 @@ bool rkcommon_need_rc4_spl(struct imgtool *params) return info->spl_rc4; } -bool rkcommon_is_header_v2(struct imgtool *params) +bool rkcommon_is_header_v2(struct imgtool *itl) { - struct spl_info *info = rkcommon_get_spl_info(params->imagename); + struct spl_info *info = rkcommon_get_spl_info(itl->imagename); return (info->header_ver == RK_HEADER_V2); } @@ -295,14 +295,14 @@ static void do_sha256_hash(uint8_t *buf, uint32_t size, uint8_t *out) sha256_finish(&ctx, out); } -static void rkcommon_set_header0(void *buf, struct imgtool *params) +static void rkcommon_set_header0(void *buf, struct imgtool *itl) { struct header0_info *hdr = buf; uint32_t init_boot_size; memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); hdr->magic = cpu_to_le32(RK_MAGIC); - hdr->disable_rc4 = cpu_to_le32(!rkcommon_need_rc4_spl(params)); + hdr->disable_rc4 = cpu_to_le32(!rkcommon_need_rc4_spl(itl)); hdr->init_offset = cpu_to_le16(RK_INIT_OFFSET); hdr->init_size = cpu_to_le16(spl_params.init_size / RK_BLK_SIZE); @@ -323,7 +323,7 @@ static void rkcommon_set_header0(void *buf, struct imgtool *params) rc4_encode(buf, RK_BLK_SIZE, rc4_key); } -static void rkcommon_set_header0_v2(void *buf, struct imgtool *params) +static void rkcommon_set_header0_v2(void *buf, struct imgtool *itl) { struct header0_info_v2 *hdr = buf; uint32_t sector_offset, image_sector_count; @@ -332,7 +332,7 @@ static void rkcommon_set_header0_v2(void *buf, struct imgtool *params) int i; printf("Image Type: Rockchip %s boot image\n", - rkcommon_get_spl_hdr(params)); + rkcommon_get_spl_hdr(itl)); memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); hdr->magic = cpu_to_le32(RK_MAGIC_V2); hdr->size_and_nimage = cpu_to_le32((2 << 16) + 384); @@ -357,25 +357,25 @@ static void rkcommon_set_header0_v2(void *buf, struct imgtool *params) } void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { struct header1_info *hdr = buf + RK_SPL_HDR_START; - if (rkcommon_is_header_v2(params)) { - rkcommon_set_header0_v2(buf, params); + if (rkcommon_is_header_v2(itl)) { + rkcommon_set_header0_v2(buf, itl); } else { - rkcommon_set_header0(buf, params); + rkcommon_set_header0(buf, itl); /* Set up the SPL name (i.e. copy spl_hdr over) */ if (memcmp(&hdr->magic, "RSAK", 4)) - memcpy(&hdr->magic, rkcommon_get_spl_hdr(params), RK_SPL_HDR_SIZE); + memcpy(&hdr->magic, rkcommon_get_spl_hdr(itl), RK_SPL_HDR_SIZE); - if (rkcommon_need_rc4_spl(params)) + if (rkcommon_need_rc4_spl(itl)) rkcommon_rc4_encode_spl(buf, RK_SPL_HDR_START, spl_params.init_size); if (spl_params.boot_file) { - if (rkcommon_need_rc4_spl(params)) + if (rkcommon_need_rc4_spl(itl)) rkcommon_rc4_encode_spl(buf + RK_SPL_HDR_START, spl_params.init_size, spl_params.boot_size); @@ -449,7 +449,7 @@ static int rkcommon_parse_header_v2(const void *buf, struct header0_info_v2 *hea } int rkcommon_verify_header(unsigned char *buf, int size, - struct imgtool *params) + struct imgtool *itl) { struct header0_info header0; struct spl_info *img_spl_info, *spl_info; @@ -472,18 +472,18 @@ int rkcommon_verify_header(unsigned char *buf, int size, * If no 'imagename' is specified via the commandline (e.g. if this is * 'dumpimage -l' w/o any further constraints), we accept any spl_info. */ - if (params->imagename == NULL || !strlen(params->imagename)) + if (!itl->imagename || !strlen(itl->imagename)) return 0; /* Match the 'imagename' against the 'spl_hdr' found */ - spl_info = rkcommon_get_spl_info(params->imagename); + spl_info = rkcommon_get_spl_info(itl->imagename); if (spl_info && img_spl_info) return strcmp(spl_info->spl_hdr, img_spl_info->spl_hdr); return -ENOENT; } -void rkcommon_print_header(const void *buf, struct imgtool *params) +void rkcommon_print_header(const void *buf, struct imgtool *itl) { struct header0_info header0; struct header0_info_v2 header0_v2; @@ -543,8 +543,7 @@ void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size) } } -int rkcommon_vrec_header(struct imgtool *params, - struct imgtool_funcs *tparams) +int rkcommon_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams) { /* * The SPL image looks as follows: @@ -573,7 +572,7 @@ int rkcommon_vrec_header(struct imgtool *params, tparams->hdr = malloc(tparams->header_size); if (!tparams->hdr) { fprintf(stderr, "%s: Can't alloc header: %s\n", - params->cmdname, strerror(errno)); + itl->cmdname, strerror(errno)); exit(EXIT_FAILURE); } memset(tparams->hdr, 0, tparams->header_size); @@ -582,16 +581,16 @@ int rkcommon_vrec_header(struct imgtool *params, * We need to store the original file-size (i.e. before padding), as * imagetool does not set this during its adjustment of file_size. */ - params->orig_file_size = tparams->header_size + + itl->orig_file_size = tparams->header_size + spl_params.init_size + spl_params.boot_size; - params->file_size = ROUND(params->orig_file_size, RK_SIZE_ALIGN); + itl->file_size = ROUND(itl->orig_file_size, RK_SIZE_ALIGN); /* Ignoring pad len, since we are using our own copy_image() */ return 0; } -static int pad_file(struct imgtool *params, int ifd, int pad) +static int pad_file(struct imgtool *itl, int ifd, int pad) { uint8_t zeros[4096]; @@ -604,7 +603,7 @@ static int pad_file(struct imgtool *params, int ifd, int pad) todo = pad; if (write(ifd, (char *)&zeros, todo) != todo) { fprintf(stderr, "%s: Write error on %s: %s\n", - params->cmdname, params->imagefile, + itl->cmdname, itl->imagefile, strerror(errno)); return -1; } @@ -614,51 +613,51 @@ static int pad_file(struct imgtool *params, int ifd, int pad) return 0; } -static int copy_file(struct imgtool *params, int ifd, - const char *file, int padded_size) +static int copy_file(struct imgtool *itl, int ifd, const char *file, + int padded_size) { int dfd; struct stat sbuf; unsigned char *ptr; int size; - if (params->vflag) + if (itl->vflag) fprintf(stderr, "Adding Image %s\n", file); dfd = open(file, O_RDONLY | O_BINARY); if (dfd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - params->cmdname, file, strerror(errno)); + itl->cmdname, file, strerror(errno)); return -1; } if (fstat(dfd, &sbuf) < 0) { fprintf(stderr, "%s: Can't stat %s: %s\n", - params->cmdname, file, strerror(errno)); + itl->cmdname, file, strerror(errno)); goto err_close; } - if (params->vflag) + if (itl->vflag) fprintf(stderr, "Size %u(pad to %u)\n", (int)sbuf.st_size, padded_size); ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0); if (ptr == MAP_FAILED) { fprintf(stderr, "%s: Can't read %s: %s\n", - params->cmdname, file, strerror(errno)); + itl->cmdname, file, strerror(errno)); goto err_munmap; } size = sbuf.st_size; if (write(ifd, ptr, size) != size) { fprintf(stderr, "%s: Write error on %s: %s\n", - params->cmdname, params->imagefile, strerror(errno)); + itl->cmdname, itl->imagefile, strerror(errno)); goto err_munmap; } munmap((void *)ptr, sbuf.st_size); close(dfd); - return pad_file(params, ifd, padded_size - size); + return pad_file(itl, ifd, padded_size - size); err_munmap: munmap((void *)ptr, sbuf.st_size); @@ -667,22 +666,22 @@ err_close: return -1; } -int rockchip_copy_image(int ifd, struct imgtool *params) +int rockchip_copy_image(int ifd, struct imgtool *itl) { int ret; - ret = copy_file(params, ifd, spl_params.init_file, + ret = copy_file(itl, ifd, spl_params.init_file, spl_params.init_size); if (ret) return ret; if (spl_params.boot_file) { - ret = copy_file(params, ifd, spl_params.boot_file, + ret = copy_file(itl, ifd, spl_params.boot_file, spl_params.boot_size); if (ret) return ret; } - return pad_file(params, ifd, - params->file_size - params->orig_file_size); + return pad_file(itl, ifd, + itl->file_size - itl->orig_file_size); } diff --git a/tools/rkcommon.h b/tools/rkcommon.h index 50db6d3799c..038ffa958b6 100644 --- a/tools/rkcommon.h +++ b/tools/rkcommon.h @@ -21,7 +21,7 @@ enum { * * Return: 0 if OK, -1 if ERROR. */ -int rkcommon_check_params(struct imgtool *params); +int rkcommon_check_params(struct imgtool *itl); /** * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image @@ -29,7 +29,7 @@ int rkcommon_check_params(struct imgtool *params); * Rockchip's bootrom requires the spl loader to start with a 4-bytes * header. The content of this header depends on the chip type. */ -const char *rkcommon_get_spl_hdr(struct imgtool *params); +const char *rkcommon_get_spl_hdr(struct imgtool *itl); /** * rkcommon_get_spl_size() - get spl size for a Rockchip boot image @@ -39,7 +39,7 @@ const char *rkcommon_get_spl_hdr(struct imgtool *params); * for the bootrom. * The spl loader size should be sram size minus reserved size(if needed) */ -int rkcommon_get_spl_size(struct imgtool *params); +int rkcommon_get_spl_size(struct imgtool *itl); /** * rkcommon_set_header() - set up the header for a Rockchip boot image @@ -49,7 +49,7 @@ int rkcommon_get_spl_size(struct imgtool *params); * @buf: Pointer to header place (must be at least 2KB in size) */ void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd, - struct imgtool *params); + struct imgtool *itl); /** * rkcommon_verify_header() - verify the header for a Rockchip boot image @@ -58,8 +58,7 @@ void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd, * @file_size: Size of entire bootable image file (incl. all padding) * Return: 0 if OK */ -int rkcommon_verify_header(unsigned char *buf, int size, - struct imgtool *params); +int rkcommon_verify_header(unsigned char *buf, int size, struct imgtool *itl); /** * rkcommon_print_header() - print the header for a Rockchip boot image @@ -68,7 +67,7 @@ int rkcommon_verify_header(unsigned char *buf, int size, * * @buf: Pointer to the image (can be a read-only file-mapping) */ -void rkcommon_print_header(const void *buf, struct imgtool *params); +void rkcommon_print_header(const void *buf, struct imgtool *itl); /** * rkcommon_need_rc4_spl() - check if rc4 encoded spl is required @@ -78,7 +77,7 @@ void rkcommon_print_header(const void *buf, struct imgtool *params); * handle unencrypted binaries. * Return: true or false depending on rc4 being required. */ -bool rkcommon_need_rc4_spl(struct imgtool *params); +bool rkcommon_need_rc4_spl(struct imgtool *itl); /** * rkcommon_rc4_encode_spl() - encode the spl binary @@ -95,13 +94,12 @@ void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size); /** * rkcommon_vrec_header() - allocate memory for the header * - * @params: Pointer to the tool params structure + * @itl: Pointer to the tool params structure * @tparams: Pointer tot the image type structure (for setting * the header and header_size) * * Return: 0 (always) */ -int rkcommon_vrec_header(struct imgtool *params, - struct imgtool_funcs *tparams); +int rkcommon_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams); #endif diff --git a/tools/rkimage.c b/tools/rkimage.c index 0fcf75f1b90..2b2a8694e0f 100644 --- a/tools/rkimage.c +++ b/tools/rkimage.c @@ -13,12 +13,12 @@ static uint32_t header; static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { - memcpy(buf, rkcommon_get_spl_hdr(params), RK_SPL_HDR_SIZE); + memcpy(buf, rkcommon_get_spl_hdr(itl), RK_SPL_HDR_SIZE); - if (rkcommon_need_rc4_spl(params)) - rkcommon_rc4_encode_spl(buf, 0, params->file_size); + if (rkcommon_need_rc4_spl(itl)) + rkcommon_rc4_encode_spl(buf, 0, itl->file_size); } static int rkimage_check_image_type(uint8_t type) diff --git a/tools/rkspi.c b/tools/rkspi.c index 4409b96dc10..db18d8eb523 100644 --- a/tools/rkspi.c +++ b/tools/rkspi.c @@ -17,23 +17,23 @@ enum { }; static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { int sector; unsigned int size; - size = params->orig_file_size; + size = itl->orig_file_size; - rkcommon_set_header(buf, sbuf, ifd, params); + rkcommon_set_header(buf, sbuf, ifd, itl); /* * Spread the image out so we only use the first 2KB of each 4KB * region. This is a feature of the SPI format required by the Rockchip * boot ROM. Its rationale is unknown. */ - if (params->vflag) + if (itl->vflag) fprintf(stderr, "Spreading spi image from %u to %u\n", - size, params->file_size); + size, itl->file_size); for (sector = size / RKSPI_SECT_LEN - 1; sector >= 0; sector--) { debug("sector %u\n", sector); @@ -57,17 +57,16 @@ static int rkspi_check_image_type(uint8_t type) * The SPI payload needs to make space for odd half-sector layout used in flash * (i.e. only the first 2K of each 4K sector is used). */ -static int rkspi_vrec_header(struct imgtool *params, - struct imgtool_funcs *tparams) +static int rkspi_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams) { - rkcommon_vrec_header(params, tparams); + rkcommon_vrec_header(itl, tparams); /* * Converting to the SPI format (i.e. splitting each 4K page into two * 2K subpages and then padding these 2K pages up to take a complete * 4K sector again) which will double the image size. */ - params->file_size = ROUND(params->file_size, RKSPI_SECT_LEN) << 1; + itl->file_size = ROUND(itl->file_size, RKSPI_SECT_LEN) << 1; /* Ignoring pad len, since we are using our own copy_image() */ return 0; diff --git a/tools/sfspl.c b/tools/sfspl.c index 996f9009c52..9d798d9f97f 100644 --- a/tools/sfspl.c +++ b/tools/sfspl.c @@ -46,17 +46,17 @@ struct spl_hdr { unsigned int zero2[91]; }; -static int sfspl_check_params(struct imgtool *params) +static int sfspl_check_params(struct imgtool *itl) { /* Only the RISC-V architecture is supported */ - if (params->Aflag && params->arch != IH_ARCH_RISCV) + if (itl->Aflag && itl->arch != IH_ARCH_RISCV) return EXIT_FAILURE; return EXIT_SUCCESS; } static int sfspl_verify_header(unsigned char *buf, int size, - struct imgtool *params) + struct imgtool *itl) { struct spl_hdr *hdr = (void *)buf; unsigned int hdr_size = le32_to_cpu(hdr->hdr_size); @@ -86,8 +86,7 @@ static int sfspl_verify_header(unsigned char *buf, int size, return EXIT_SUCCESS; } -static void sfspl_print_header(const void *buf, - struct imgtool *params) +static void sfspl_print_header(const void *buf, struct imgtool *itl) { struct spl_hdr *hdr = (void *)buf; unsigned int hdr_size = le32_to_cpu(hdr->hdr_size); @@ -97,8 +96,7 @@ static void sfspl_print_header(const void *buf, printf("Payload size: %u\n", file_size); } -static int sfspl_image_extract_subimage(void *ptr, - struct imgtool *params) +static int sfspl_image_extract_subimage(void *ptr, struct imgtool *itl) { struct spl_hdr *hdr = (void *)ptr; unsigned char *buf = ptr; @@ -106,12 +104,12 @@ static int sfspl_image_extract_subimage(void *ptr, unsigned int hdr_size = le32_to_cpu(hdr->hdr_size); unsigned int file_size = le32_to_cpu(hdr->file_size); - if (params->pflag) { - printf("Invalid image index %d\n", params->pflag); + if (itl->pflag) { + printf("Invalid image index %d\n", itl->pflag); return EXIT_FAILURE; } - fd = open(params->outfile, O_WRONLY | O_CREAT | O_TRUNC, 0644); + fd = open(itl->outfile, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd == -1) { perror("Cannot open file"); return EXIT_FAILURE; @@ -134,13 +132,13 @@ static int sfspl_check_image_type(uint8_t type) } static void sfspl_set_header(void *buf, struct stat *sbuf, int infd, - struct imgtool *params) + struct imgtool *itl) { struct spl_hdr *hdr = buf; unsigned int file_size; unsigned int crc; - file_size = params->file_size - sizeof(struct spl_hdr); + file_size = itl->file_size - sizeof(struct spl_hdr); crc = crc32(0, &((unsigned char *)buf)[sizeof(struct spl_hdr)], file_size); @@ -152,8 +150,7 @@ static void sfspl_set_header(void *buf, struct stat *sbuf, int infd, hdr->crc32 = cpu_to_le32(crc); } -static int sfspl_vrec_header(struct imgtool *params, - struct imgtool_funcs *tparams) +static int sfspl_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams) { tparams->hdr = calloc(sizeof(struct spl_hdr), 1); diff --git a/tools/socfpgaimage.c b/tools/socfpgaimage.c index 9f3b459a243..2b1d63ab542 100644 --- a/tools/socfpgaimage.c +++ b/tools/socfpgaimage.c @@ -130,10 +130,9 @@ static uint16_t sfp_hdr_checksum(uint8_t *buf, unsigned char ver) } static void sfp_build_header(uint8_t *buf, uint8_t ver, uint8_t flags, - uint32_t length_bytes, - struct imgtool *params) + uint32_t length_bytes, struct imgtool *itl) { - uint32_t entry_offset = params->eflag ? params->ep : ENTRY_POINT_OFFSET; + uint32_t entry_offset = itl->eflag ? itl->ep : ENTRY_POINT_OFFSET; struct socfpga_header_v0 header_v0 = { .validation = cpu_to_le32(VALIDATION_WORD), .version = 0, @@ -211,8 +210,7 @@ static int sfp_verify_header(const uint8_t *buf, uint8_t *ver) /* Sign the buffer and return the signed buffer size */ static int sfp_sign_buffer(uint8_t *buf, uint8_t ver, uint8_t flags, - int len, int pad_64k, - struct imgtool *params) + int len, int pad_64k, struct imgtool *itl) { uint32_t calc_crc; uint32_t crc_off; @@ -221,7 +219,7 @@ static int sfp_sign_buffer(uint8_t *buf, uint8_t ver, uint8_t flags, len = sfp_aligned_len(len); /* Build header */ - sfp_build_header(buf + HEADER_OFFSET, ver, flags, len, params); + sfp_build_header(buf + HEADER_OFFSET, ver, flags, len, itl); /* Calculate and apply the CRC */ crc_off = len - sizeof(uint32_t); /* at last 4 bytes of image */ @@ -275,7 +273,7 @@ static int sfp_verify_buffer(const uint8_t *buf) /* mkimage glue functions */ static int socfpgaimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { if (image_size < 0x80) return -1; @@ -313,7 +311,7 @@ static void socfpgaimage_print_header_v1(struct socfpga_header_v1 *header) le16_to_cpu(header->checksum)); } -static void socfpgaimage_print_header(const void *ptr, struct imgtool *params) +static void socfpgaimage_print_header(const void *ptr, struct imgtool *itl) { const void *header = ptr + HEADER_OFFSET; struct socfpga_header_v0 *header_v0; @@ -330,22 +328,21 @@ static void socfpgaimage_print_header(const void *ptr, struct imgtool *params) } } -static int socfpgaimage_check_params_v0(struct imgtool *params) +static int socfpgaimage_check_params_v0(struct imgtool *itl) { /* Not sure if we should be accepting fflags */ - return (params->dflag && (params->fflag || params->lflag)) || - (params->fflag && (params->dflag || params->lflag)) || - (params->lflag && (params->dflag || params->fflag)); + return (itl->dflag && (itl->fflag || itl->lflag)) || + (itl->fflag && (itl->dflag || itl->lflag)) || + (itl->lflag && (itl->dflag || itl->fflag)); } -static int socfpgaimage_check_params_v1(struct imgtool *params) +static int socfpgaimage_check_params_v1(struct imgtool *itl) { /* * If the entry point is specified, ensure it is >= ENTRY_POINT_OFFSET * and it is 4 bytes aligned. */ - if (params->eflag && (params->ep < ENTRY_POINT_OFFSET || - params->ep % 4 != 0)) { + if (itl->eflag && (itl->ep < ENTRY_POINT_OFFSET || itl->ep % 4 != 0)) { fprintf(stderr, "Error: Entry point must be greater than 0x%x.\n", ENTRY_POINT_OFFSET); @@ -353,9 +350,9 @@ static int socfpgaimage_check_params_v1(struct imgtool *params) } /* Not sure if we should be accepting fflags */ - return (params->dflag && (params->fflag || params->lflag)) || - (params->fflag && (params->dflag || params->lflag)) || - (params->lflag && (params->dflag || params->fflag)); + return (itl->dflag && (itl->fflag || itl->lflag)) || + (itl->fflag && (itl->dflag || itl->lflag)) || + (itl->lflag && (itl->dflag || itl->fflag)); } static int socfpgaimage_check_image_types_v0(uint8_t type) @@ -397,13 +394,13 @@ static int sfp_fake_header_size(unsigned int size, uint8_t ver) return align_size - size; } -static int sfp_vrec_header(struct imgtool *params, +static int sfp_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams, uint8_t ver) { struct stat sbuf; - if (params->datafile && - stat(params->datafile, &sbuf) == 0 && + if (itl->datafile && + stat(itl->datafile, &sbuf) == 0 && sbuf.st_size <= (sfp_max_size(ver) - sizeof(uint32_t))) { data_size = sbuf.st_size; tparams->header_size = sfp_fake_header_size(data_size, ver); @@ -412,20 +409,19 @@ static int sfp_vrec_header(struct imgtool *params, } -static int socfpgaimage_vrec_header_v0(struct imgtool *params, +static int socfpgaimage_vrec_header_v0(struct imgtool *itl, struct imgtool_funcs *tparams) { - return sfp_vrec_header(params, tparams, 0); + return sfp_vrec_header(itl, tparams, 0); } -static int socfpgaimage_vrec_header_v1(struct imgtool *params, +static int socfpgaimage_vrec_header_v1(struct imgtool *itl, struct imgtool_funcs *tparams) { - return sfp_vrec_header(params, tparams, 1); + return sfp_vrec_header(itl, tparams, 1); } -static void sfp_set_header(void *ptr, unsigned char ver, - struct imgtool *params) +static void sfp_set_header(void *ptr, unsigned char ver, struct imgtool *itl) { uint8_t *buf = (uint8_t *)ptr; @@ -439,19 +435,19 @@ static void sfp_set_header(void *ptr, unsigned char ver, memmove(buf, buf + sfp_fake_header_size(data_size, ver), data_size); memset(buf + data_size, 0, sfp_fake_header_size(data_size, ver)); - sfp_sign_buffer(buf, ver, 0, data_size, 0, params); + sfp_sign_buffer(buf, ver, 0, data_size, 0, itl); } static void socfpgaimage_set_header_v0(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { - sfp_set_header(ptr, 0, params); + sfp_set_header(ptr, 0, itl); } static void socfpgaimage_set_header_v1(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { - sfp_set_header(ptr, 1, params); + sfp_set_header(ptr, 1, itl); } U_BOOT_IMAGE_TYPE( diff --git a/tools/stm32image.c b/tools/stm32image.c index 52511af51e8..37b9cf96e44 100644 --- a/tools/stm32image.c +++ b/tools/stm32image.c @@ -78,7 +78,7 @@ static int stm32image_check_image_types(uint8_t type) } static int stm32image_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct stm32_header *stm32hdr = (struct stm32_header *)ptr; int i; @@ -99,7 +99,7 @@ static int stm32image_verify_header(unsigned char *ptr, int image_size, return 0; } -static void stm32image_print_header(const void *ptr, struct imgtool *params) +static void stm32image_print_header(const void *ptr, struct imgtool *itl) { struct stm32_header *stm32hdr = (struct stm32_header *)ptr; @@ -121,14 +121,14 @@ static void stm32image_print_header(const void *ptr, struct imgtool *params) } static void stm32image_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { struct stm32_header *stm32hdr = (struct stm32_header *)ptr; stm32image_default_header(stm32hdr); - stm32hdr->load_address = cpu_to_le32(params->addr); - stm32hdr->image_entry_point = cpu_to_le32(params->ep); + stm32hdr->load_address = cpu_to_le32(itl->addr); + stm32hdr->image_entry_point = cpu_to_le32(itl->ep); stm32hdr->image_length = cpu_to_le32((uint32_t)sbuf->st_size - sizeof(struct stm32_header)); stm32hdr->image_checksum = diff --git a/tools/sunxi_egon.c b/tools/sunxi_egon.c index 26031497257..a082035cac2 100644 --- a/tools/sunxi_egon.c +++ b/tools/sunxi_egon.c @@ -15,21 +15,21 @@ #define PAD_SIZE 8192 #define PAD_SIZE_MIN 512 -static int egon_get_arch(struct imgtool *params) +static int egon_get_arch(struct imgtool *itl) { - if (params->Aflag) - return params->arch; + if (itl->Aflag) + return itl->arch; /* For compatibility, assume ARM when no architecture specified */ return IH_ARCH_ARM; } -static int egon_check_params(struct imgtool *params) +static int egon_check_params(struct imgtool *itl) { /* * Check whether the architecture is supported. */ - switch (egon_get_arch(params)) { + switch (egon_get_arch(itl)) { case IH_ARCH_ARM: case IH_ARCH_RISCV: break; @@ -38,11 +38,11 @@ static int egon_check_params(struct imgtool *params) } /* We need a binary image file. */ - return !params->dflag; + return !itl->dflag; } static int egon_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { const struct boot_file_head *header = (void *)ptr; uint32_t length; @@ -51,7 +51,7 @@ static int egon_verify_header(unsigned char *ptr, int image_size, * First 4 bytes must be a branch instruction of the corresponding * architecture. */ - switch (egon_get_arch(params)) { + switch (egon_get_arch(itl)) { case IH_ARCH_ARM: if ((le32_to_cpu(header->b_instruction) & 0xff000000) != 0xea000000) return EXIT_FAILURE; @@ -82,7 +82,7 @@ static int egon_verify_header(unsigned char *ptr, int image_size, return EXIT_SUCCESS; } -static void egon_print_header(const void *buf, struct imgtool *params) +static void egon_print_header(const void *buf, struct imgtool *itl) { const struct boot_file_head *header = buf; @@ -104,7 +104,7 @@ static void egon_print_header(const void *buf, struct imgtool *params) } static void egon_set_header(void *buf, struct stat *sbuf, int infd, - struct imgtool *params) + struct imgtool *itl) { struct boot_file_head *header = buf; uint32_t *buf32 = buf; @@ -115,7 +115,7 @@ static void egon_set_header(void *buf, struct stat *sbuf, int infd, * Different architectures need different first instruction to * branch to the body. */ - switch (egon_get_arch(params)) { + switch (egon_get_arch(itl)) { case IH_ARCH_ARM: /* Generate an ARM branch instruction to jump over the header. */ value = 0xea000000 | (sizeof(struct boot_file_head) / 4 - 2); @@ -143,17 +143,17 @@ static void egon_set_header(void *buf, struct stat *sbuf, int infd, memcpy(header->magic, BOOT0_MAGIC, sizeof(header->magic)); header->check_sum = cpu_to_le32(BROM_STAMP_VALUE); - header->length = cpu_to_le32(params->file_size); + header->length = cpu_to_le32(itl->file_size); memcpy(header->spl_signature, SPL_SIGNATURE, 3); header->spl_signature[3] = SPL_ENV_HEADER_VERSION; /* If an image name has been provided, use it as the DT name. */ - if (params->imagename && params->imagename[0]) { - if (strlen(params->imagename) > sizeof(header->string_pool) - 1) + if (itl->imagename && itl->imagename[0]) { + if (strlen(itl->imagename) > sizeof(header->string_pool) - 1) printf("WARNING: DT name too long for SPL header!\n"); else { - strcpy((char *)header->string_pool, params->imagename); + strcpy((char *)header->string_pool, itl->imagename); value = offsetof(struct boot_file_head, string_pool); header->dt_name_offset = cpu_to_le32(value); header->spl_signature[3] = SPL_DT_HEADER_VERSION; @@ -171,15 +171,14 @@ static int egon_check_image_type(uint8_t type) return type == IH_TYPE_SUNXI_EGON ? 0 : 1; } -static int egon_vrec_header(struct imgtool *params, - struct imgtool_funcs *tparams) +static int egon_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams) { - int pad_size = ALIGN(params->bl_len ?: PAD_SIZE, PAD_SIZE_MIN); + int pad_size = ALIGN(itl->bl_len ?: PAD_SIZE, PAD_SIZE_MIN); tparams->hdr = calloc(sizeof(struct boot_file_head), 1); /* Return padding to complete blocks. */ - return ALIGN(params->file_size, pad_size) - params->file_size; + return ALIGN(itl->file_size, pad_size) - itl->file_size; } U_BOOT_IMAGE_TYPE( diff --git a/tools/sunxi_toc0.c b/tools/sunxi_toc0.c index 478c1abcbb4..c92dec7d707 100644 --- a/tools/sunxi_toc0.c +++ b/tools/sunxi_toc0.c @@ -667,9 +667,9 @@ err: return ret; } -static int toc0_check_params(struct imgtool *params) +static int toc0_check_params(struct imgtool *itl) { - if (!params->dflag) + if (!itl->dflag) return -EINVAL; /* @@ -704,12 +704,12 @@ static int toc0_check_params(struct imgtool *params) * Note that until the ROTPK_HASH eFuse is programmed, any "root key" * will be accepted by the BROM. */ - if (params->keydir) { - if (asprintf(&fw_key_file, "%s/%s", params->keydir, fw_key_file) < 0) + if (itl->keydir) { + if (asprintf(&fw_key_file, "%s/%s", itl->keydir, fw_key_file) < 0) return -ENOMEM; - if (asprintf(&key_item_file, "%s/%s", params->keydir, key_item_file) < 0) + if (asprintf(&key_item_file, "%s/%s", itl->keydir, key_item_file) < 0) return -ENOMEM; - if (asprintf(&root_key_file, "%s/%s", params->keydir, root_key_file) < 0) + if (asprintf(&root_key_file, "%s/%s", itl->keydir, root_key_file) < 0) return -ENOMEM; } @@ -717,7 +717,7 @@ static int toc0_check_params(struct imgtool *params) } static int toc0_verify_header(unsigned char *buf, int image_size, - struct imgtool *params) + struct imgtool *itl) { int ret = EXIT_FAILURE; RSA *root_key = NULL; @@ -757,7 +757,7 @@ static const char *toc0_item_name(uint32_t name) return "(unknown)"; } -static void toc0_print_header(const void *buf, struct imgtool *params) +static void toc0_print_header(const void *buf, struct imgtool *itl) { const struct toc0_main_info *main_info = buf; const struct toc0_item_info *item_info = (void *)(main_info + 1); @@ -802,7 +802,7 @@ static void toc0_print_header(const void *buf, struct imgtool *params) } static void toc0_set_header(void *buf, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { uint32_t key_item_len = 0; uint8_t *key_item = NULL; @@ -866,10 +866,10 @@ static void toc0_set_header(void *buf, struct stat *sbuf, int ifd, if (key_item || fw_key != root_key) pr_warn("Only H6 supports separate root and firmware keys\n"); - ret = toc0_create(buf, params->file_size, root_key, fw_key, + ret = toc0_create(buf, itl->file_size, root_key, fw_key, key_item, key_item_len, buf + TOC0_DEFAULT_HEADER_LEN, - params->orig_file_size, params->addr); + itl->orig_file_size, itl->addr); err: OPENSSL_free(key_item); @@ -888,16 +888,15 @@ static int toc0_check_image_type(uint8_t type) return type == IH_TYPE_SUNXI_TOC0 ? 0 : 1; } -static int toc0_vrec_header(struct imgtool *params, - struct imgtool_funcs *tparams) +static int toc0_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams) { tparams->hdr = calloc(tparams->header_size, 1); /* Save off the unpadded data size for SHA256 calculation. */ - params->orig_file_size = params->file_size - TOC0_DEFAULT_HEADER_LEN; + itl->orig_file_size = itl->file_size - TOC0_DEFAULT_HEADER_LEN; /* Return padding to 8K blocks. */ - return ALIGN(params->file_size, PAD_SIZE) - params->file_size; + return ALIGN(itl->file_size, PAD_SIZE) - itl->file_size; } U_BOOT_IMAGE_TYPE( diff --git a/tools/ublimage.c b/tools/ublimage.c index 70514285111..714fbd62b44 100644 --- a/tools/ublimage.c +++ b/tools/ublimage.c @@ -193,7 +193,7 @@ static int ublimage_check_image_types(uint8_t type) } static int ublimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct ubl_header *ubl_hdr = (struct ubl_header *)ptr; @@ -203,7 +203,7 @@ static int ublimage_verify_header(unsigned char *ptr, int image_size, return 0; } -static void ublimage_print_header(const void *ptr, struct imgtool *params) +static void ublimage_print_header(const void *ptr, struct imgtool *itl) { struct ubl_header *ubl_hdr = (struct ubl_header *) ptr; @@ -211,22 +211,22 @@ static void ublimage_print_header(const void *ptr, struct imgtool *params) } static void ublimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { struct ubl_header *ublhdr = (struct ubl_header *)ptr; /* Parse configuration file */ - parse_cfg_file(ublhdr, params->imagename); + parse_cfg_file(ublhdr, itl->imagename); } -int ublimage_check_params(struct imgtool *params) +int ublimage_check_params(struct imgtool *itl) { - if (!params) + if (!itl) return CFG_INVALID; - if (!strlen(params->imagename)) { + if (!strlen(itl->imagename)) { fprintf(stderr, "Error: %s - Configuration file not" "specified, it is needed for ublimage generation\n", - params->cmdname); + itl->cmdname); return CFG_INVALID; } /* @@ -235,10 +235,10 @@ int ublimage_check_params(struct imgtool *params) * parameters are not sent at the same time * For example, if list is required a data image must not be provided */ - return (params->dflag && (params->fflag || params->lflag)) || - (params->fflag && (params->dflag || params->lflag)) || - (params->lflag && (params->dflag || params->fflag)) || - (params->xflag) || !(strlen(params->imagename)); + return (itl->dflag && (itl->fflag || itl->lflag)) || + (itl->fflag && (itl->dflag || itl->lflag)) || + (itl->lflag && (itl->dflag || itl->fflag)) || + (itl->xflag) || !(strlen(itl->imagename)); } /* diff --git a/tools/vybridimage.c b/tools/vybridimage.c index 31119d04554..4b375099519 100644 --- a/tools/vybridimage.c +++ b/tools/vybridimage.c @@ -59,7 +59,7 @@ static uint8_t vybridimage_sw_ecc(uint8_t byte) } static int vybridimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; @@ -93,7 +93,7 @@ static int vybridimage_verify_header(unsigned char *ptr, int image_size, } static void vybridimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; @@ -134,7 +134,7 @@ static void vybridimage_print_hdr_field(struct nand_page_0_boot_header *hdr, printf("header.fcb[%d] = %08x\n", idx, hdr->fcb[idx]); } -static void vybridimage_print_header(const void *ptr, struct imgtool *params) +static void vybridimage_print_header(const void *ptr, struct imgtool *itl) { struct nand_page_0_boot_header *hdr = (struct nand_page_0_boot_header *)ptr; diff --git a/tools/zynqimage.c b/tools/zynqimage.c index af7b6f65629..26260e935a9 100644 --- a/tools/zynqimage.c +++ b/tools/zynqimage.c @@ -139,7 +139,7 @@ static void zynqimage_default_header(struct zynq_header *ptr) /* mkimage glue functions */ static int zynqimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct zynq_header *zynqhdr = (struct zynq_header *)ptr; @@ -163,7 +163,7 @@ static int zynqimage_verify_header(unsigned char *ptr, int image_size, return 0; } -static void zynqimage_print_header(const void *ptr, struct imgtool *params) +static void zynqimage_print_header(const void *ptr, struct imgtool *itl) { struct zynq_header *zynqhdr = (struct zynq_header *)ptr; int i; @@ -198,12 +198,12 @@ static void zynqimage_print_header(const void *ptr, struct imgtool *params) } } -static int zynqimage_check_params(struct imgtool *params) +static int zynqimage_check_params(struct imgtool *itl) { - if (!params) + if (!itl) return 0; - if (params->addr != 0x0) { + if (itl->addr != 0x0) { fprintf(stderr, "Error: Load Address cannot be specified.\n"); return -1; } @@ -211,13 +211,13 @@ static int zynqimage_check_params(struct imgtool *params) /* * If the entry point is specified ensure it is 64 byte aligned. */ - if (params->eflag && (params->ep % 64 != 0)) { + if (itl->eflag && (itl->ep % 64 != 0)) { fprintf(stderr, "Error: Entry Point must be aligned to a 64-byte boundary.\n"); return -1; } - return !(params->lflag || params->dflag); + return !(itl->lflag || itl->dflag); } static int zynqimage_check_image_types(uint8_t type) @@ -266,7 +266,7 @@ static void zynqimage_parse_initparams(struct zynq_header *zynqhdr, } static void zynqimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { struct zynq_header *zynqhdr = (struct zynq_header *)ptr; zynqimage_default_header(zynqhdr); @@ -277,12 +277,12 @@ static void zynqimage_set_header(void *ptr, struct stat *sbuf, int ifd, zynqhdr->image_size = cpu_to_le32((uint32_t)sbuf->st_size); zynqhdr->image_stored_size = zynqhdr->image_size; zynqhdr->image_load = 0x0; - if (params->eflag) - zynqhdr->image_load = cpu_to_le32((uint32_t)params->ep); + if (itl->eflag) + zynqhdr->image_load = cpu_to_le32((uint32_t)itl->ep); /* User can pass in text file with init list */ - if (strlen(params->imagename2)) - zynqimage_parse_initparams(zynqhdr, params->imagename2); + if (strlen(itl->imagename2)) + zynqimage_parse_initparams(zynqhdr, itl->imagename2); zynqhdr->checksum = zynqimage_checksum(zynqhdr); } diff --git a/tools/zynqmpbif.c b/tools/zynqmpbif.c index f8acc07244f..7dc553ee6ef 100644 --- a/tools/zynqmpbif.c +++ b/tools/zynqmpbif.c @@ -84,22 +84,22 @@ static uint32_t zynqmp_csum(void *start, void *end) return ~checksum; } -static int zynqmpbif_check_params(struct imgtool *params) +static int zynqmpbif_check_params(struct imgtool *itl) { - if (!params) + if (!itl) return 0; - if (params->addr != 0x0) { + if (itl->addr != 0x0) { fprintf(stderr, "Error: Load Address can not be specified.\n"); return -1; } - if (params->eflag) { + if (itl->eflag) { fprintf(stderr, "Error: Entry Point can not be specified.\n"); return -1; } - return !(params->lflag || params->dflag); + return !(itl->lflag || itl->dflag); } static int zynqmpbif_check_image_types(uint8_t type) @@ -995,7 +995,7 @@ err: /* Needs to be stubbed out so we can print after creation */ static void zynqmpbif_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { } diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c index 5bef2a935bb..28729898c9b 100644 --- a/tools/zynqmpimage.c +++ b/tools/zynqmpimage.c @@ -117,7 +117,7 @@ void zynqmpimage_default_header(struct zynqmp_header *ptr) /* mkimage glue functions */ static int zynqmpimage_verify_header(unsigned char *ptr, int image_size, - struct imgtool *params) + struct imgtool *itl) { struct zynqmp_header *zynqhdr = (struct zynqmp_header *)ptr; @@ -263,7 +263,7 @@ static void print_partition(const void *ptr, const struct partition_header *ph) printf(" Checksum : 0x%08x\n", le32_to_cpu(ph->checksum)); } -void zynqmpimage_print_header(const void *ptr, struct imgtool *params) +void zynqmpimage_print_header(const void *ptr, struct imgtool *itl) { struct zynqmp_header *zynqhdr = (struct zynqmp_header *)ptr; struct partition_header *ph; @@ -311,12 +311,12 @@ void zynqmpimage_print_header(const void *ptr, struct imgtool *params) free(dynamic_header); } -static int zynqmpimage_check_params(struct imgtool *params) +static int zynqmpimage_check_params(struct imgtool *itl) { - if (!params) + if (!itl) return 0; - if (params->addr != 0x0) { + if (itl->addr != 0x0) { fprintf(stderr, "Error: Load Address cannot be specified.\n"); return -1; } @@ -324,13 +324,13 @@ static int zynqmpimage_check_params(struct imgtool *params) /* * If the entry point is specified ensure it is 64 byte aligned. */ - if (params->eflag && (params->ep % 64 != 0)) { + if (itl->eflag && (itl->ep % 64 != 0)) { fprintf(stderr, "Error: Entry Point must be aligned to a 64-byte boundary.\n"); return -1; } - return !(params->lflag || params->dflag || params->outfile); + return !(itl->lflag || itl->dflag || itl->outfile); } static int zynqmpimage_check_image_types(uint8_t type) @@ -439,7 +439,7 @@ static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr, } static void zynqmpimage_set_header(void *ptr, struct stat *sbuf, int ifd, - struct imgtool *params) + struct imgtool *itl) { struct zynqmp_header *zynqhdr = (struct zynqmp_header *)ptr; zynqmpimage_default_header(zynqhdr); @@ -447,20 +447,20 @@ static void zynqmpimage_set_header(void *ptr, struct stat *sbuf, int ifd, /* place image directly after header */ zynqhdr->image_offset = cpu_to_le32((uint32_t)sizeof(struct zynqmp_header)); - zynqhdr->image_size = cpu_to_le32(params->file_size - + zynqhdr->image_size = cpu_to_le32(itl->file_size - sizeof(struct zynqmp_header)); zynqhdr->image_stored_size = zynqhdr->image_size; zynqhdr->image_load = 0xfffc0000; - if (params->eflag) - zynqhdr->image_load = cpu_to_le32((uint32_t)params->ep); + if (itl->eflag) + zynqhdr->image_load = cpu_to_le32((uint32_t)itl->ep); /* PMUFW */ if (fpmu) - zynqmpimage_pmufw(zynqhdr, params->imagename); + zynqmpimage_pmufw(zynqhdr, itl->imagename); /* User can pass in text file with init list */ - if (strlen(params->imagename2)) - zynqmpimage_parse_initparams(zynqhdr, params->imagename2); + if (strlen(itl->imagename2)) + zynqmpimage_parse_initparams(zynqhdr, itl->imagename2); zynqhdr->checksum = zynqmpimage_checksum(zynqhdr); } @@ -478,31 +478,31 @@ static int zynqmpimage_partition_extract(struct zynqmp_header *zynqhdr, /** * zynqmpimage_extract_contents - retrieve a sub-image component from the image * @ptr: pointer to the image header - * @params: command line parameters + * @itl: image-tool info * * returns: * zero in case of success or a negative value if fail. */ -static int zynqmpimage_extract_contents(void *ptr, struct imgtool *params) +static int zynqmpimage_extract_contents(void *ptr, struct imgtool *itl) { struct zynqmp_header *zynqhdr = (struct zynqmp_header *)ptr; struct partition_header *ph; int i; for_each_zynqmp_part(zynqhdr, i, ph) { - if (i == params->pflag) - return zynqmpimage_partition_extract(ptr, ph, params->outfile); + if (i == itl->pflag) + return zynqmpimage_partition_extract(ptr, ph, itl->outfile); } printf("No partition found\n"); return -1; } -static int zynqmpimage_vrec_header(struct imgtool *params, +static int zynqmpimage_vrec_header(struct imgtool *itl, struct imgtool_funcs *tparams) { struct stat path_stat; - char *filename = params->imagename; + char *filename = itl->imagename; int err; /* Handle static case without PMUFW */ diff --git a/tools/zynqmpimage.h b/tools/zynqmpimage.h index a79d4773d2c..1ab1439e665 100644 --- a/tools/zynqmpimage.h +++ b/tools/zynqmpimage.h @@ -141,7 +141,7 @@ struct zynqmp_header { }; void zynqmpimage_default_header(struct zynqmp_header *ptr); -void zynqmpimage_print_header(const void *ptr, struct imgtool *params); +void zynqmpimage_print_header(const void *ptr, struct imgtool *itl); static inline struct image_header_table * zynqmp_get_iht(const struct zynqmp_header *zynqhdr) -- 2.43.0
participants (1)
-
Simon Glass