summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile2
-rw-r--r--tools/aisimage.c30
-rw-r--r--tools/atmelimage.c30
-rw-r--r--tools/default_image.c77
-rw-r--r--tools/dumpimage.c170
-rw-r--r--tools/fit_image.c121
-rw-r--r--tools/gpimage-common.c3
-rw-r--r--tools/gpimage.c29
-rw-r--r--tools/imagetool.c124
-rw-r--r--tools/imagetool.h115
-rw-r--r--tools/imagetool.lds24
-rw-r--r--tools/imximage.c30
-rw-r--r--tools/kwbimage.c30
-rw-r--r--tools/mkimage.c113
-rw-r--r--tools/mxsimage.c35
-rw-r--r--tools/omapimage.c29
-rw-r--r--tools/pblimage.c30
-rw-r--r--tools/socfpgaimage.c36
-rw-r--r--tools/ublimage.c29
19 files changed, 502 insertions, 555 deletions
diff --git a/tools/Makefile b/tools/Makefile
index ea76a3e7d9..6e1ce79f2f 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -124,6 +124,8 @@ HOSTLOADLIBES_dumpimage := $(HOSTLOADLIBES_mkimage)
HOSTLOADLIBES_fit_info := $(HOSTLOADLIBES_mkimage)
HOSTLOADLIBES_fit_check_sign := $(HOSTLOADLIBES_mkimage)
+HOSTLDFLAGS += -T $(srctree)/tools/imagetool.lds
+
hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
HOSTCFLAGS_mkexynosspl.o := -pedantic
diff --git a/tools/aisimage.c b/tools/aisimage.c
index 8de370a2e0..9338342cb3 100644
--- a/tools/aisimage.c
+++ b/tools/aisimage.c
@@ -413,19 +413,17 @@ int aisimage_check_params(struct image_tool_params *params)
/*
* aisimage parameters
*/
-static struct image_type_params aisimage_params = {
- .name = "TI Davinci AIS Boot Image support",
- .header_size = 0,
- .hdr = NULL,
- .check_image_type = aisimage_check_image_types,
- .verify_header = aisimage_verify_header,
- .print_header = aisimage_print_header,
- .set_header = aisimage_set_header,
- .check_params = aisimage_check_params,
- .vrec_header = aisimage_generate,
-};
-
-void init_ais_image_type(void)
-{
- register_image_type(&aisimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ aisimage,
+ "TI Davinci AIS Boot Image support",
+ 0,
+ NULL,
+ aisimage_check_params,
+ aisimage_verify_header,
+ aisimage_print_header,
+ aisimage_set_header,
+ NULL,
+ aisimage_check_image_types,
+ NULL,
+ aisimage_generate
+);
diff --git a/tools/atmelimage.c b/tools/atmelimage.c
index c8101d2ddc..5b72ac54a6 100644
--- a/tools/atmelimage.c
+++ b/tools/atmelimage.c
@@ -324,19 +324,17 @@ static int atmel_vrec_header(struct image_tool_params *params,
return EXIT_SUCCESS;
}
-static struct image_type_params atmelimage_params = {
- .name = "ATMEL ROM-Boot Image support",
- .header_size = 0,
- .hdr = NULL,
- .check_image_type = atmel_check_image_type,
- .verify_header = atmel_verify_header,
- .print_header = atmel_print_header,
- .set_header = atmel_set_header,
- .check_params = atmel_check_params,
- .vrec_header = atmel_vrec_header,
-};
-
-void init_atmel_image_type(void)
-{
- register_image_type(&atmelimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ atmelimage,
+ "ATMEL ROM-Boot Image support",
+ 0,
+ NULL,
+ atmel_check_params,
+ atmel_verify_header,
+ atmel_print_header,
+ atmel_set_header,
+ NULL,
+ atmel_check_image_type,
+ NULL,
+ atmel_vrec_header
+);
diff --git a/tools/default_image.c b/tools/default_image.c
index 0a0792e503..cf5c0d4393 100644
--- a/tools/default_image.c
+++ b/tools/default_image.c
@@ -15,6 +15,8 @@
*/
#include "imagetool.h"
+#include "mkimage.h"
+
#include <image.h>
#include <u-boot/crc.h>
@@ -53,9 +55,8 @@ static int image_verify_header(unsigned char *ptr, int image_size,
memcpy(hdr, ptr, sizeof(image_header_t));
if (be32_to_cpu(hdr->ih_magic) != IH_MAGIC) {
- fprintf(stderr,
- "%s: Bad Magic Number: \"%s\" is no valid image\n",
- params->cmdname, params->imagefile);
+ debug("%s: Bad Magic Number: \"%s\" is no valid image\n",
+ params->cmdname, params->imagefile);
return -FDT_ERR_BADMAGIC;
}
@@ -66,9 +67,8 @@ static int image_verify_header(unsigned char *ptr, int image_size,
hdr->ih_hcrc = cpu_to_be32(0); /* clear for re-calculation */
if (crc32(0, data, len) != checksum) {
- fprintf(stderr,
- "%s: ERROR: \"%s\" has bad header checksum!\n",
- params->cmdname, params->imagefile);
+ debug("%s: ERROR: \"%s\" has bad header checksum!\n",
+ params->cmdname, params->imagefile);
return -FDT_ERR_BADSTATE;
}
@@ -77,9 +77,8 @@ static int image_verify_header(unsigned char *ptr, int image_size,
checksum = be32_to_cpu(hdr->ih_dcrc);
if (crc32(0, data, len) != checksum) {
- fprintf(stderr,
- "%s: ERROR: \"%s\" has corrupted data!\n",
- params->cmdname, params->imagefile);
+ debug("%s: ERROR: \"%s\" has corrupted data!\n",
+ params->cmdname, params->imagefile);
return -FDT_ERR_BADSTRUCTURE;
}
return 0;
@@ -117,33 +116,7 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd,
image_set_hcrc(hdr, checksum);
}
-static int image_save_datafile(struct image_tool_params *params,
- ulong file_data, ulong file_len)
-{
- int dfd;
- const char *datafile = params->outfile;
-
- dfd = open(datafile, O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
- S_IRUSR | S_IWUSR);
- if (dfd < 0) {
- fprintf(stderr, "%s: Can't open \"%s\": %s\n",
- params->cmdname, datafile, strerror(errno));
- return -1;
- }
-
- if (write(dfd, (void *)file_data, file_len) != (ssize_t)file_len) {
- fprintf(stderr, "%s: Write error on \"%s\": %s\n",
- params->cmdname, datafile, strerror(errno));
- close(dfd);
- return -1;
- }
-
- close(dfd);
-
- return 0;
-}
-
-static int image_extract_datafile(void *ptr, struct image_tool_params *params)
+static int image_extract_subimage(void *ptr, struct image_tool_params *params)
{
const image_header_t *hdr = (const image_header_t *)ptr;
ulong file_data;
@@ -170,25 +143,23 @@ static int image_extract_datafile(void *ptr, struct image_tool_params *params)
}
/* save the "data file" into the file system */
- return image_save_datafile(params, file_data, file_len);
+ return imagetool_save_subimage(params->outfile, file_data, file_len);
}
/*
* Default image type parameters definition
*/
-static struct image_type_params defimage_params = {
- .name = "Default Image support",
- .header_size = sizeof(image_header_t),
- .hdr = (void*)&header,
- .check_image_type = image_check_image_types,
- .verify_header = image_verify_header,
- .print_header = image_print_contents,
- .set_header = image_set_header,
- .extract_datafile = image_extract_datafile,
- .check_params = image_check_params,
-};
-
-void init_default_image_type(void)
-{
- register_image_type(&defimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ defimage,
+ "Default Image support",
+ sizeof(image_header_t),
+ (void *)&header,
+ image_check_params,
+ image_verify_header,
+ image_print_contents,
+ image_set_header,
+ image_extract_subimage,
+ image_check_image_types,
+ NULL,
+ NULL
+);
diff --git a/tools/dumpimage.c b/tools/dumpimage.c
index 542ee28210..75a5d4762c 100644
--- a/tools/dumpimage.c
+++ b/tools/dumpimage.c
@@ -12,112 +12,13 @@
static void usage(void);
-/* image_type_params linked list to maintain registered image types supports */
-static struct image_type_params *dumpimage_tparams;
-
/* parameters initialized by core will be used by the image type code */
static struct image_tool_params params = {
.type = IH_TYPE_KERNEL,
};
-/**
- * dumpimage_register() - register respective image generation/list support
- *
- * the input struct image_type_params is checked and appended to the link
- * list, if the input structure is already registered, issue an error
- *
- * @tparams: Image type parameters
- */
-static void dumpimage_register(struct image_type_params *tparams)
-{
- struct image_type_params **tp;
-
- if (!tparams) {
- fprintf(stderr, "%s: %s: Null input\n", params.cmdname,
- __func__);
- exit(EXIT_FAILURE);
- }
-
- /* scan the linked list, check for registry and point the last one */
- for (tp = &dumpimage_tparams; *tp != NULL; tp = &(*tp)->next) {
- if (!strcmp((*tp)->name, tparams->name)) {
- fprintf(stderr, "%s: %s already registered\n",
- params.cmdname, tparams->name);
- return;
- }
- }
-
- /* add input struct entry at the end of link list */
- *tp = tparams;
- /* mark input entry as last entry in the link list */
- tparams->next = NULL;
-
- debug("Registered %s\n", tparams->name);
-}
-
-/**
- * dumpimage_get_type() - find the image type params for a given image type
- *
- * Scan all registered image types and check the input type_id for each
- * supported image type
- *
- * @return respective image_type_params pointer. If the input type is not
- * supported by any of registered image types, returns NULL
- */
-static struct image_type_params *dumpimage_get_type(int type)
-{
- struct image_type_params *curr;
-
- for (curr = dumpimage_tparams; curr != NULL; curr = curr->next) {
- if (curr->check_image_type) {
- if (!curr->check_image_type(type))
- return curr;
- }
- }
- return NULL;
-}
-
/*
- * dumpimage_verify_print_header() - verifies the image header
- *
- * Scan registered image types and verify the image_header for each
- * supported image type. If verification is successful, this prints
- * the respective header.
- *
- * @return 0 on success, negative if input image format does not match with
- * any of supported image types
- */
-static int dumpimage_verify_print_header(void *ptr, struct stat *sbuf)
-{
- int retval = -1;
- struct image_type_params *curr;
-
- for (curr = dumpimage_tparams; curr != NULL; curr = curr->next) {
- if (curr->verify_header) {
- retval = curr->verify_header((unsigned char *)ptr,
- sbuf->st_size, &params);
- if (retval != 0)
- continue;
- /*
- * Print the image information if verify is
- * successful
- */
- if (curr->print_header) {
- curr->print_header(ptr);
- } else {
- fprintf(stderr,
- "%s: print_header undefined for %s\n",
- params.cmdname, curr->name);
- }
- break;
- }
- }
-
- return retval;
-}
-
-/*
- * dumpimage_extract_datafile -
+ * dumpimage_extract_subimage -
*
* It scans all registered image types,
* verifies image_header for each supported image type
@@ -127,29 +28,27 @@ static int dumpimage_verify_print_header(void *ptr, struct stat *sbuf)
* returns negative if input image format does not match with any of
* supported image types
*/
-static int dumpimage_extract_datafile(void *ptr, struct stat *sbuf)
+static int dumpimage_extract_subimage(struct image_type_params *tparams,
+ void *ptr, struct stat *sbuf)
{
int retval = -1;
- struct image_type_params *curr;
- for (curr = dumpimage_tparams; curr != NULL; curr = curr->next) {
- if (curr->verify_header) {
- retval = curr->verify_header((unsigned char *)ptr,
- sbuf->st_size, &params);
- if (retval != 0)
- continue;
- /*
- * Extract the file from the image
- * if verify is successful
- */
- if (curr->extract_datafile) {
- curr->extract_datafile(ptr, &params);
- } else {
- fprintf(stderr,
- "%s: extract_datafile undefined for %s\n",
- params.cmdname, curr->name);
- break;
- }
+ if (tparams->verify_header) {
+ retval = tparams->verify_header((unsigned char *)ptr,
+ sbuf->st_size, &params);
+ if (retval != 0)
+ return -1;
+ /*
+ * Extract the file from the image
+ * if verify is successful
+ */
+ if (tparams->extract_subimage) {
+ retval = tparams->extract_subimage(ptr, &params);
+ } else {
+ fprintf(stderr,
+ "%s: extract_subimage undefined for %s\n",
+ params.cmdname, tparams->name);
+ return -2;
}
}
@@ -165,12 +64,9 @@ int main(int argc, char **argv)
int retval = 0;
struct image_type_params *tparams = NULL;
- /* Init all image generation/list support */
- register_image_tool(dumpimage_register);
-
params.cmdname = *argv;
- while ((opt = getopt(argc, argv, "li:o:p:V")) != -1) {
+ while ((opt = getopt(argc, argv, "li:o:T:p:V")) != -1) {
switch (opt) {
case 'l':
params.lflag = 1;
@@ -182,6 +78,12 @@ int main(int argc, char **argv)
case 'o':
params.outfile = optarg;
break;
+ case 'T':
+ params.type = genimg_get_type_id(optarg);
+ if (params.type < 0) {
+ usage();
+ }
+ break;
case 'p':
params.pflag = strtoul(optarg, &ptr, 10);
if (*ptr) {
@@ -196,6 +98,7 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
default:
usage();
+ break;
}
}
@@ -203,9 +106,9 @@ int main(int argc, char **argv)
usage();
/* set tparams as per input type_id */
- tparams = dumpimage_get_type(params.type);
+ tparams = imagetool_get_type(params.type);
if (tparams == NULL) {
- fprintf(stderr, "%s: unsupported type %s\n",
+ fprintf(stderr, "%s: unsupported type: %s\n",
params.cmdname, genimg_get_type_name(params.type));
exit(EXIT_FAILURE);
}
@@ -242,7 +145,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
- if ((unsigned)sbuf.st_size < tparams->header_size) {
+ if ((uint32_t)sbuf.st_size < tparams->header_size) {
fprintf(stderr,
"%s: Bad size: \"%s\" is not valid image\n",
params.cmdname, params.imagefile);
@@ -267,13 +170,15 @@ int main(int argc, char **argv)
* Extract the data files from within the matched
* image type. Returns the error code if not matched
*/
- retval = dumpimage_extract_datafile(ptr, &sbuf);
+ retval = dumpimage_extract_subimage(tparams, ptr,
+ &sbuf);
} else {
/*
* Print the image information for matched image type
* Returns the error code if not matched
*/
- retval = dumpimage_verify_print_header(ptr, &sbuf);
+ retval = imagetool_verify_print_header(ptr, &sbuf,
+ tparams, &params);
}
(void)munmap((void *)ptr, sbuf.st_size);
@@ -293,9 +198,10 @@ static void usage(void)
" -l ==> list image header information\n",
params.cmdname);
fprintf(stderr,
- " %s -i image [-p position] [-o outfile] data_file\n"
- " -i ==> extract from the 'image' a specific 'data_file'"
- ", indexed by 'position' (starting at 0)\n",
+ " %s -i image -T type [-p position] [-o outfile] data_file\n"
+ " -i ==> extract from the 'image' a specific 'data_file'\n"
+ " -T ==> set image type to 'type'\n"
+ " -p ==> 'position' (starting at 0) of the 'data_file' inside the 'image'\n",
params.cmdname);
fprintf(stderr,
" %s -V ==> print version information and exit\n",
diff --git a/tools/fit_image.c b/tools/fit_image.c
index 3ececf913f..eb2a25eeac 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -155,6 +155,97 @@ err_system:
return -1;
}
+/**
+ * fit_image_extract - extract a FIT component image
+ * @fit: pointer to the FIT format image header
+ * @image_noffset: offset of the component image node
+ * @file_name: name of the file to store the FIT sub-image
+ *
+ * returns:
+ * zero in case of success or a negative value if fail.
+ */
+static int fit_image_extract(
+ const void *fit,
+ int image_noffset,
+ const char *file_name)
+{
+ const void *file_data;
+ size_t file_size = 0;
+
+ /* get the "data" property of component at offset "image_noffset" */
+ fit_image_get_data(fit, image_noffset, &file_data, &file_size);
+
+ /* save the "file_data" into the file specified by "file_name" */
+ return imagetool_save_subimage(file_name, (ulong) file_data, file_size);
+}
+
+/**
+ * fit_extract_contents - retrieve a sub-image component from the FIT image
+ * @ptr: pointer to the FIT format image header
+ * @params: command line parameters
+ *
+ * returns:
+ * zero in case of success or a negative value if fail.
+ */
+static int fit_extract_contents(void *ptr, struct image_tool_params *params)
+{
+ int images_noffset;
+ int noffset;
+ int ndepth;
+ const void *fit = ptr;
+ int count = 0;
+ const char *p;
+
+ /* Indent string is defined in header image.h */
+ p = IMAGE_INDENT_STRING;
+
+ if (!fit_check_format(fit)) {
+ printf("Bad FIT image format\n");
+ return -1;
+ }
+
+ /* Find images parent node offset */
+ images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
+ if (images_noffset < 0) {
+ printf("Can't find images parent node '%s' (%s)\n",
+ FIT_IMAGES_PATH, fdt_strerror(images_noffset));
+ return -1;
+ }
+
+ /* 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);
+ return -1;
+ }
+
+ /* Process its subnodes, extract the desired component from image */
+ for (ndepth = 0, count = 0,
+ noffset = fdt_next_node(fit, images_noffset, &ndepth);
+ (noffset >= 0) && (ndepth > 0);
+ noffset = fdt_next_node(fit, noffset, &ndepth)) {
+ if (ndepth == 1) {
+ /*
+ * Direct child node of the images parent node,
+ * i.e. component image node.
+ */
+ if (params->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);
+ }
+
+ count++;
+ }
+ }
+
+ return 0;
+}
+
static int fit_check_params(struct image_tool_params *params)
{
return ((params->dflag && (params->fflag || params->lflag)) ||
@@ -162,19 +253,17 @@ static int fit_check_params(struct image_tool_params *params)
(params->lflag && (params->dflag || params->fflag)));
}
-static struct image_type_params fitimage_params = {
- .name = "FIT Image support",
- .header_size = sizeof(image_header_t),
- .hdr = (void*)&header,
- .verify_header = fit_verify_header,
- .print_header = fit_print_contents,
- .check_image_type = fit_check_image_types,
- .fflag_handle = fit_handle_file,
- .set_header = NULL, /* FIT images use DTB header */
- .check_params = fit_check_params,
-};
-
-void init_fit_image_type (void)
-{
- register_image_type(&fitimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ fitimage,
+ "FIT Image support",
+ sizeof(image_header_t),
+ (void *)&header,
+ fit_check_params,
+ fit_verify_header,
+ fit_print_contents,
+ NULL,
+ fit_extract_contents,
+ fit_check_image_types,
+ fit_handle_file,
+ NULL /* FIT images use DTB header */
+);
diff --git a/tools/gpimage-common.c b/tools/gpimage-common.c
index b343a3aa8b..5ad52be437 100644
--- a/tools/gpimage-common.c
+++ b/tools/gpimage-common.c
@@ -32,7 +32,8 @@ void to_be32(uint32_t *gph_size, uint32_t *gph_load_addr)
int gph_verify_header(struct gp_header *gph, int be)
{
- uint32_t gph_size = gph->size, gph_load_addr = gph->load_addr;
+ uint32_t gph_size = gph->size;
+ uint32_t gph_load_addr = gph->load_addr;
if (be)
to_be32(&gph_size, &gph_load_addr);
diff --git a/tools/gpimage.c b/tools/gpimage.c
index 1cabb5b612..1adc55c5fc 100644
--- a/tools/gpimage.c
+++ b/tools/gpimage.c
@@ -60,18 +60,17 @@ static void gpimage_set_header(void *ptr, struct stat *sbuf, int ifd,
/*
* gpimage parameters
*/
-static struct image_type_params gpimage_params = {
- .name = "TI KeyStone GP Image support",
- .header_size = GPIMAGE_HDR_SIZE,
- .hdr = (void *)&gpimage_header,
- .check_image_type = gpimage_check_image_types,
- .verify_header = gpimage_verify_header,
- .print_header = gpimage_print_header,
- .set_header = gpimage_set_header,
- .check_params = gpimage_check_params,
-};
-
-void init_gpimage_type(void)
-{
- register_image_type(&gpimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ gpimage,
+ "TI KeyStone GP Image support",
+ GPIMAGE_HDR_SIZE,
+ (void *)&gpimage_header,
+ gpimage_check_params,
+ gpimage_verify_header,
+ gpimage_print_header,
+ gpimage_set_header,
+ NULL,
+ gpimage_check_image_types,
+ NULL,
+ NULL
+);
diff --git a/tools/imagetool.c b/tools/imagetool.c
index 98717bdedd..148e4662b7 100644
--- a/tools/imagetool.c
+++ b/tools/imagetool.c
@@ -8,57 +8,87 @@
#include "imagetool.h"
-/*
- * Callback function to register a image type within a tool
- */
-static imagetool_register_t register_func;
+#include <image.h>
-/*
- * register_image_tool -
- *
- * The tool provides its own registration function in order to all image
- * types initialize themselves.
- */
-void register_image_tool(imagetool_register_t image_register)
+struct image_type_params *imagetool_get_type(int type)
{
- /*
- * Save the image tool callback function. It will be used to register
- * image types within that tool
- */
- register_func = image_register;
+ struct image_type_params *curr;
+ struct image_type_params *start = ll_entry_start(
+ struct image_type_params, image_type);
+ struct image_type_params *end = ll_entry_end(
+ struct image_type_params, image_type);
- /* Init ATMEL ROM Boot Image generation/list support */
- init_atmel_image_type();
- /* Init Freescale PBL Boot image generation/list support */
- init_pbl_image_type();
- /* Init Kirkwood Boot image generation/list support */
- init_kwb_image_type();
- /* Init Freescale imx Boot image generation/list support */
- init_imx_image_type();
- /* Init Freescale mxs Boot image generation/list support */
- init_mxs_image_type();
- /* Init FIT image generation/list support */
- init_fit_image_type();
- /* Init TI OMAP Boot image generation/list support */
- init_omap_image_type();
- /* Init Default image generation/list support */
- init_default_image_type();
- /* Init Davinci UBL support */
- init_ubl_image_type();
- /* Init Davinci AIS support */
- init_ais_image_type();
- /* Init Altera SOCFPGA support */
- init_socfpga_image_type();
- /* Init TI Keystone boot image generation/list support */
- init_gpimage_type();
+ for (curr = start; curr != end; curr++) {
+ if (curr->check_image_type) {
+ if (!curr->check_image_type(type))
+ return curr;
+ }
+ }
+ return NULL;
}
-/*
- * register_image_type -
- *
- * Register a image type within a tool
- */
-void register_image_type(struct image_type_params *tparams)
+int imagetool_verify_print_header(
+ void *ptr,
+ struct stat *sbuf,
+ struct image_type_params *tparams,
+ struct image_tool_params *params)
{
- register_func(tparams);
+ int retval = -1;
+ struct image_type_params *curr;
+
+ struct image_type_params *start = ll_entry_start(
+ struct image_type_params, image_type);
+ struct image_type_params *end = ll_entry_end(
+ struct image_type_params, image_type);
+
+ for (curr = start; curr != end; curr++) {
+ if (curr->verify_header) {
+ retval = curr->verify_header((unsigned char *)ptr,
+ sbuf->st_size, params);
+
+ if (retval == 0) {
+ /*
+ * Print the image information if verify is
+ * successful
+ */
+ if (curr->print_header) {
+ curr->print_header(ptr);
+ } else {
+ fprintf(stderr,
+ "%s: print_header undefined for %s\n",
+ params->cmdname, curr->name);
+ }
+ break;
+ }
+ }
+ }
+
+ return retval;
+}
+
+int imagetool_save_subimage(
+ const char *file_name,
+ ulong file_data,
+ ulong file_len)
+{
+ int dfd;
+
+ dfd = open(file_name, O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
+ S_IRUSR | S_IWUSR);
+ if (dfd < 0) {
+ fprintf(stderr, "Can't open \"%s\": %s\n",
+ file_name, strerror(errno));
+ return -1;
+ }
+
+ if (write(dfd, (void *)file_data, file_len) != (ssize_t)file_len) {
+ fprintf(stderr, "Write error on \"%s\": %s\n",
+ file_name, strerror(errno));
+ close(dfd);
+ return -1;
+ }
+
+ close(dfd);
+
+ return 0;
}
diff --git a/tools/imagetool.h b/tools/imagetool.h
index 8bce059482..f35dec71c7 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -19,6 +19,16 @@
#include <time.h>
#include <unistd.h>
#include <u-boot/sha1.h>
+
+/* define __KERNEL__ in order to get the definitions
+ * required by the linker list. This is probably not
+ * the best way to do this */
+#ifndef __KERNEL__
+#define __KERNEL__
+#include <linker_lists.h>
+#undef __KERNEL__
+#endif /* __KERNEL__ */
+
#include "fdt_host.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
@@ -100,14 +110,15 @@ struct image_type_params {
void (*set_header) (void *, struct stat *, int,
struct image_tool_params *);
/*
- * This function is used by the command to retrieve a data file from
- * the image (i.e. dumpimage -i <image> -p <position> <data_file>).
+ * This function is used by the command to retrieve a component
+ * (sub-image) from the image (i.e. dumpimage -i <image> -p <position>
+ * <sub-image-name>).
* Thus the code to extract a file from an image must be put here.
*
* Returns 0 if the file was successfully retrieved from the image,
* or a negative value on error.
*/
- int (*extract_datafile) (void *, struct image_tool_params *);
+ int (*extract_subimage)(void *, struct image_tool_params *);
/*
* Some image generation support for ex (default image type) supports
* more than one type_ids, this callback function is used to check
@@ -127,50 +138,88 @@ struct image_type_params {
*/
int (*vrec_header) (struct image_tool_params *,
struct image_type_params *);
- /* pointer to the next registered entry in linked list */
- struct image_type_params *next;
};
-/*
- * Tool registration function.
+/**
+ * imagetool_get_type() - find the image type params for a given image type
+ *
+ * It scans all registers image type supports
+ * checks the input type for each supported image type
+ *
+ * if successful,
+ * returns respective image_type_params pointer if success
+ * if input type_id is not supported by any of image_type_support
+ * returns NULL
*/
-typedef void (*imagetool_register_t)(struct image_type_params *);
+struct image_type_params *imagetool_get_type(int type);
/*
- * Initializes all image types with the given registration callback
- * function.
- * An image tool uses this function to initialize all image types.
+ * imagetool_verify_print_header() - verifies the image header
+ *
+ * Scan registered image types and verify the image_header for each
+ * supported image type. If verification is successful, this prints
+ * the respective header.
+ *
+ * @return 0 on success, negative if input image format does not match with
+ * any of supported image types
*/
-void register_image_tool(imagetool_register_t image_register);
+int imagetool_verify_print_header(
+ void *ptr,
+ struct stat *sbuf,
+ struct image_type_params *tparams,
+ struct image_tool_params *params);
-/*
- * Register a image type within a tool.
- * An image type uses this function to register itself within
- * all tools.
+/**
+ * imagetool_save_subimage - store data into a file
+ * @file_name: name of the destination file
+ * @file_data: data to be written
+ * @file_len: the amount of data to store
+ *
+ * imagetool_save_subimage() store file_len bytes of data pointed by file_data
+ * into the file name by file_name.
+ *
+ * returns:
+ * zero in case of success or a negative value if fail.
*/
-void register_image_type(struct image_type_params *tparams);
+int imagetool_save_subimage(
+ const char *file_name,
+ ulong file_data,
+ ulong file_len);
/*
* There is a c file associated with supported image type low level code
* for ex. default_image.c, fit_image.c
- * init_xxx_type() is the only function referred by image tool core to avoid
- * a single lined header file, you can define them here
- *
- * Supported image types init functions
*/
-void init_default_image_type(void);
-void init_atmel_image_type(void);
-void init_pbl_image_type(void);
-void init_ais_image_type(void);
-void init_kwb_image_type(void);
-void init_imx_image_type(void);
-void init_mxs_image_type(void);
-void init_fit_image_type(void);
-void init_ubl_image_type(void);
-void init_omap_image_type(void);
-void init_socfpga_image_type(void);
-void init_gpimage_type(void);
+
void pbl_load_uboot(int fd, struct image_tool_params *mparams);
+#define U_BOOT_IMAGE_TYPE( \
+ _id, \
+ _name, \
+ _header_size, \
+ _header, \
+ _check_params, \
+ _verify_header, \
+ _print_header, \
+ _set_header, \
+ _extract_subimage, \
+ _check_image_type, \
+ _fflag_handle, \
+ _vrec_header \
+ ) \
+ ll_entry_declare(struct image_type_params, _id, image_type) = { \
+ .name = _name, \
+ .header_size = _header_size, \
+ .hdr = _header, \
+ .check_params = _check_params, \
+ .verify_header = _verify_header, \
+ .print_header = _print_header, \
+ .set_header = _set_header, \
+ .extract_subimage = _extract_subimage, \
+ .check_image_type = _check_image_type, \
+ .fflag_handle = _fflag_handle, \
+ .vrec_header = _vrec_header \
+ }
+
#endif /* _IMAGETOOL_H_ */
diff --git a/tools/imagetool.lds b/tools/imagetool.lds
new file mode 100644
index 0000000000..7e92b4ac66
--- /dev/null
+++ b/tools/imagetool.lds
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2011-2012 The Chromium OS Authors.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+SECTIONS
+{
+
+ . = ALIGN(4);
+ .u_boot_list : {
+ KEEP(*(SORT(.u_boot_list*)));
+ }
+
+ __u_boot_sandbox_option_start = .;
+ _u_boot_sandbox_getopt : { *(.u_boot_sandbox_getopt) }
+ __u_boot_sandbox_option_end = .;
+
+ __bss_start = .;
+}
+
+INSERT BEFORE .data;
diff --git a/tools/imximage.c b/tools/imximage.c
index 526b7d490d..3d37591886 100644
--- a/tools/imximage.c
+++ b/tools/imximage.c
@@ -694,19 +694,17 @@ static int imximage_generate(struct image_tool_params *params,
/*
* imximage parameters
*/
-static struct image_type_params imximage_params = {
- .name = "Freescale i.MX Boot Image support",
- .header_size = 0,
- .hdr = NULL,
- .check_image_type = imximage_check_image_types,
- .verify_header = imximage_verify_header,
- .print_header = imximage_print_header,
- .set_header = imximage_set_header,
- .check_params = imximage_check_params,
- .vrec_header = imximage_generate,
-};
-
-void init_imx_image_type(void)
-{
- register_image_type(&imximage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ imximage,
+ "Freescale i.MX Boot Image support",
+ 0,
+ NULL,
+ imximage_check_params,
+ imximage_verify_header,
+ imximage_print_header,
+ imximage_set_header,
+ NULL,
+ imximage_check_image_types,
+ NULL,
+ imximage_generate
+);
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 807d46668b..66f459ad6b 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -905,19 +905,17 @@ static int kwbimage_check_params(struct image_tool_params *params)
/*
* kwbimage type parameters definition
*/
-static struct image_type_params kwbimage_params = {
- .name = "Marvell MVEBU Boot Image support",
- .header_size = 0, /* no fixed header size */
- .hdr = NULL,
- .vrec_header = kwbimage_generate,
- .check_image_type = kwbimage_check_image_types,
- .verify_header = kwbimage_verify_header,
- .print_header = kwbimage_print_header,
- .set_header = kwbimage_set_header,
- .check_params = kwbimage_check_params,
-};
-
-void init_kwb_image_type (void)
-{
- register_image_type(&kwbimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ kwbimage,
+ "Marvell MVEBU Boot Image support",
+ 0,
+ NULL,
+ kwbimage_check_params,
+ kwbimage_verify_header,
+ kwbimage_print_header,
+ kwbimage_set_header,
+ NULL,
+ kwbimage_check_image_types,
+ NULL,
+ kwbimage_generate
+);
diff --git a/tools/mkimage.c b/tools/mkimage.c
index c70408c9ba..5ccd951048 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -15,9 +15,6 @@
static void copy_file(int, const char *, int);
static void usage(void);
-/* image_type_params link list to maintain registered image type supports */
-struct image_type_params *mkimage_tparams = NULL;
-
/* parameters initialized by core will be used by the image type code */
struct image_tool_params params = {
.os = IH_OS_LINUX,
@@ -29,106 +26,6 @@ struct image_tool_params params = {
.imagename2 = "",
};
-/*
- * mkimage_register -
- *
- * It is used to register respective image generation/list support to the
- * mkimage core
- *
- * the input struct image_type_params is checked and appended to the link
- * list, if the input structure is already registered, error
- */
-void mkimage_register (struct image_type_params *tparams)
-{
- struct image_type_params **tp;
-
- if (!tparams) {
- fprintf (stderr, "%s: %s: Null input\n",
- params.cmdname, __FUNCTION__);
- exit (EXIT_FAILURE);
- }
-
- /* scan the linked list, check for registry and point the last one */
- for (tp = &mkimage_tparams; *tp != NULL; tp = &(*tp)->next) {
- if (!strcmp((*tp)->name, tparams->name)) {
- fprintf (stderr, "%s: %s already registered\n",
- params.cmdname, tparams->name);
- return;
- }
- }
-
- /* add input struct entry at the end of link list */
- *tp = tparams;
- /* mark input entry as last entry in the link list */
- tparams->next = NULL;
-
- debug ("Registered %s\n", tparams->name);
-}
-
-/*
- * mkimage_get_type -
- *
- * It scans all registers image type supports
- * checks the input type_id for each supported image type
- *
- * if successful,
- * returns respective image_type_params pointer if success
- * if input type_id is not supported by any of image_type_support
- * returns NULL
- */
-struct image_type_params *mkimage_get_type(int type)
-{
- struct image_type_params *curr;
-
- for (curr = mkimage_tparams; curr != NULL; curr = curr->next) {
- if (curr->check_image_type) {
- if (!curr->check_image_type (type))
- return curr;
- }
- }
- return NULL;
-}
-
-/*
- * mkimage_verify_print_header -
- *
- * It scans mkimage_tparams link list,
- * verifies image_header for each supported image type
- * if verification is successful, prints respective header
- *
- * returns negative if input image format does not match with any of
- * supported image types
- */
-int mkimage_verify_print_header (void *ptr, struct stat *sbuf)
-{
- int retval = -1;
- struct image_type_params *curr;
-
- for (curr = mkimage_tparams; curr != NULL; curr = curr->next ) {
- if (curr->verify_header) {
- retval = curr->verify_header (
- (unsigned char *)ptr, sbuf->st_size,
- &params);
-
- if (retval == 0) {
- /*
- * Print the image information
- * if verify is successful
- */
- if (curr->print_header)
- curr->print_header (ptr);
- else {
- fprintf (stderr,
- "%s: print_header undefined for %s\n",
- params.cmdname, curr->name);
- }
- break;
- }
- }
- }
- return retval;
-}
-
int
main (int argc, char **argv)
{
@@ -139,9 +36,6 @@ main (int argc, char **argv)
struct image_type_params *tparams = NULL;
int pad_len = 0;
- /* Init all image generation/list support */
- register_image_tool(mkimage_register);
-
params.cmdname = *argv;
params.addr = params.ep = 0;
@@ -279,7 +173,7 @@ NXTARG: ;
usage ();
/* set tparams as per input type_id */
- tparams = mkimage_get_type(params.type);
+ tparams = imagetool_get_type(params.type);
if (tparams == NULL) {
fprintf (stderr, "%s: unsupported type %s\n",
params.cmdname, genimg_get_type_name(params.type));
@@ -363,7 +257,8 @@ NXTARG: ;
* Print the image information for matched image type
* Returns the error code if not matched
*/
- retval = mkimage_verify_print_header (ptr, &sbuf);
+ retval = imagetool_verify_print_header(ptr, &sbuf,
+ tparams, &params);
(void) munmap((void *)ptr, sbuf.st_size);
(void) close (ifd);
@@ -529,7 +424,7 @@ copy_file (int ifd, const char *datafile, int pad)
uint8_t zeros[4096];
int offset = 0;
int size;
- struct image_type_params *tparams = mkimage_get_type (params.type);
+ struct image_type_params *tparams = imagetool_get_type(params.type);
if (pad >= sizeof(zeros)) {
fprintf(stderr, "%s: Can't pad to %d\n",
diff --git a/tools/mxsimage.c b/tools/mxsimage.c
index 04beefe05c..98fc64491c 100644
--- a/tools/mxsimage.c
+++ b/tools/mxsimage.c
@@ -2312,25 +2312,18 @@ fail:
/*
* mxsimage parameters
*/
-static struct image_type_params mxsimage_params = {
- .name = "Freescale MXS Boot Image support",
- .header_size = 0,
- .hdr = NULL,
- .check_image_type = mxsimage_check_image_types,
- .verify_header = mxsimage_verify_header,
- .print_header = mxsimage_print_header,
- .set_header = mxsimage_set_header,
- .check_params = mxsimage_check_params,
- .vrec_header = mxsimage_generate,
-};
-
-void init_mxs_image_type(void)
-{
- register_image_type(&mxsimage_params);
-}
-
-#else
-void init_mxs_image_type(void)
-{
-}
+U_BOOT_IMAGE_TYPE(
+ mxsimage,
+ "Freescale MXS Boot Image support",
+ 0,
+ NULL,
+ mxsimage_check_params,
+ mxsimage_verify_header,
+ mxsimage_print_header,
+ mxsimage_set_header,
+ NULL,
+ mxsimage_check_image_types,
+ NULL,
+ mxsimage_generate
+);
#endif
diff --git a/tools/omapimage.c b/tools/omapimage.c
index 1e0c164796..7198b3330d 100644
--- a/tools/omapimage.c
+++ b/tools/omapimage.c
@@ -162,18 +162,17 @@ static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd,
/*
* omapimage parameters
*/
-static struct image_type_params omapimage_params = {
- .name = "TI OMAP CH/GP Boot Image support",
- .header_size = OMAP_FILE_HDR_SIZE,
- .hdr = (void *)&omapimage_header,
- .check_image_type = omapimage_check_image_types,
- .verify_header = omapimage_verify_header,
- .print_header = omapimage_print_header,
- .set_header = omapimage_set_header,
- .check_params = gpimage_check_params,
-};
-
-void init_omap_image_type(void)
-{
- register_image_type(&omapimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ omapimage,
+ "TI OMAP CH/GP Boot Image support",
+ OMAP_FILE_HDR_SIZE,
+ (void *)&omapimage_header,
+ gpimage_check_params,
+ omapimage_verify_header,
+ omapimage_print_header,
+ omapimage_set_header,
+ NULL,
+ omapimage_check_image_types,
+ NULL,
+ NULL
+);
diff --git a/tools/pblimage.c b/tools/pblimage.c
index 2a799ab4b6..d74fde9a44 100644
--- a/tools/pblimage.c
+++ b/tools/pblimage.c
@@ -308,19 +308,17 @@ int pblimage_check_params(struct image_tool_params *params)
};
/* pblimage parameters */
-static struct image_type_params pblimage_params = {
- .name = "Freescale PBL Boot Image support",
- .header_size = sizeof(struct pbl_header),
- .hdr = (void *)&pblimage_header,
- .check_image_type = pblimage_check_image_types,
- .check_params = pblimage_check_params,
- .verify_header = pblimage_verify_header,
- .print_header = pblimage_print_header,
- .set_header = pblimage_set_header,
-};
-
-void init_pbl_image_type(void)
-{
- pbl_size = 0;
- register_image_type(&pblimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ pblimage,
+ "Freescale PBL Boot Image support",
+ sizeof(struct pbl_header),
+ (void *)&pblimage_header,
+ pblimage_check_params,
+ pblimage_verify_header,
+ pblimage_print_header,
+ pblimage_set_header,
+ NULL,
+ pblimage_check_image_types,
+ NULL,
+ NULL
+);
diff --git a/tools/socfpgaimage.c b/tools/socfpgaimage.c
index 917873e7b3..8fe91fe80e 100644
--- a/tools/socfpgaimage.c
+++ b/tools/socfpgaimage.c
@@ -33,6 +33,8 @@
#include "pbl_crc32.h"
#include "imagetool.h"
+#include "mkimage.h"
+
#include <image.h>
#define HEADER_OFFSET 0x40
@@ -133,12 +135,12 @@ static int verify_buffer(const uint8_t *buf)
len = verify_header(buf + HEADER_OFFSET);
if (len < 0) {
- fprintf(stderr, "Invalid header\n");
+ debug("Invalid header\n");
return -1;
}
if (len < HEADER_OFFSET || len > PADDED_SIZE) {
- fprintf(stderr, "Invalid header length (%i)\n", len);
+ debug("Invalid header length (%i)\n", len);
return -1;
}
@@ -241,19 +243,17 @@ static void socfpgaimage_set_header(void *ptr, struct stat *sbuf, int ifd,
sign_buffer(buf, 0, 0, data_size, 0);
}
-static struct image_type_params socfpgaimage_params = {
- .name = "Altera SOCFPGA preloader support",
- .vrec_header = socfpgaimage_vrec_header,
- .header_size = 0, /* This will be modified by vrec_header() */
- .hdr = (void *)buffer,
- .check_image_type = socfpgaimage_check_image_types,
- .verify_header = socfpgaimage_verify_header,
- .print_header = socfpgaimage_print_header,
- .set_header = socfpgaimage_set_header,
- .check_params = socfpgaimage_check_params,
-};
-
-void init_socfpga_image_type(void)
-{
- register_image_type(&socfpgaimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ socfpgaimage,
+ "Altera SOCFPGA preloader support",
+ 0, /* This will be modified by vrec_header() */
+ (void *)buffer,
+ socfpgaimage_check_params,
+ socfpgaimage_verify_header,
+ socfpgaimage_print_header,
+ socfpgaimage_set_header,
+ NULL,
+ socfpgaimage_check_image_types,
+ NULL,
+ socfpgaimage_vrec_header
+);
diff --git a/tools/ublimage.c b/tools/ublimage.c
index cbbbe205da..6ed1eef29c 100644
--- a/tools/ublimage.c
+++ b/tools/ublimage.c
@@ -244,18 +244,17 @@ int ublimage_check_params(struct image_tool_params *params)
/*
* ublimage parameters
*/
-static struct image_type_params ublimage_params = {
- .name = "Davinci UBL boot support",
- .header_size = sizeof(struct ubl_header),
- .hdr = (void *)&ublimage_header,
- .check_image_type = ublimage_check_image_types,
- .verify_header = ublimage_verify_header,
- .print_header = ublimage_print_header,
- .set_header = ublimage_set_header,
- .check_params = ublimage_check_params,
-};
-
-void init_ubl_image_type(void)
-{
- register_image_type(&ublimage_params);
-}
+U_BOOT_IMAGE_TYPE(
+ ublimage,
+ "Davinci UBL boot support",
+ sizeof(struct ubl_header),
+ (void *)&ublimage_header,
+ ublimage_check_params,
+ ublimage_verify_header,
+ ublimage_print_header,
+ ublimage_set_header,
+ NULL,
+ ublimage_check_image_types,
+ NULL,
+ NULL
+);
OpenPOWER on IntegriCloud