Skip to content

Commit

Permalink
imagetool: replace image registration function by linker_lists feature
Browse files Browse the repository at this point in the history
The registration was introduced in commit f86ed6a

This commit also removes all registration functions, and the member "next"
from image_type_params struct

Signed-off-by: Guilherme Maciel Ferreira <[email protected]>
  • Loading branch information
guilhermeferreira authored and trini committed Jan 29, 2015
1 parent 067d156 commit a93648d
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 376 deletions.
2 changes: 2 additions & 0 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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
Expand Down
30 changes: 14 additions & 16 deletions tools/aisimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
30 changes: 14 additions & 16 deletions tools/atmelimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
30 changes: 14 additions & 16 deletions tools/default_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,17 @@ static int image_extract_datafile(void *ptr, struct image_tool_params *params)
/*
* 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_datafile,
image_check_image_types,
NULL,
NULL
);
46 changes: 6 additions & 40 deletions tools/dumpimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,6 @@ 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_extract_datafile -
*
Expand All @@ -70,8 +35,12 @@ static int dumpimage_extract_datafile(void *ptr, struct stat *sbuf)
{
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 = dumpimage_tparams; curr != NULL; curr = curr->next) {
for (curr = start; curr != end; curr++) {
if (curr->verify_header) {
retval = curr->verify_header((unsigned char *)ptr,
sbuf->st_size, &params);
Expand Down Expand Up @@ -104,9 +73,6 @@ 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) {
Expand Down Expand Up @@ -142,7 +108,7 @@ int main(int argc, char **argv)
usage();

/* set tparams as per input type_id */
tparams = imagetool_get_type(params.type, dumpimage_tparams);
tparams = imagetool_get_type(params.type);
if (tparams == NULL) {
fprintf(stderr, "%s: unsupported type %s\n",
params.cmdname, genimg_get_type_name(params.type));
Expand Down
30 changes: 14 additions & 16 deletions tools/fit_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,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,
NULL,
fit_check_image_types,
fit_handle_file,
NULL /* FIT images use DTB header */
);
29 changes: 14 additions & 15 deletions tools/gpimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
72 changes: 12 additions & 60 deletions tools/imagetool.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,15 @@

#include <image.h>

/*
* Callback function to register a image type within a tool
*/
static imagetool_register_t register_func;

/*
* 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)
{
/*
* Save the image tool callback function. It will be used to register
* image types within that tool
*/
register_func = image_register;

/* 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();
}

/*
* register_image_type -
*
* Register a image type within a tool
*/
void register_image_type(struct image_type_params *tparams)
{
register_func(tparams);
}

struct image_type_params *imagetool_get_type(
int type,
struct image_type_params *tparams)
struct image_type_params *imagetool_get_type(int type)
{
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 = tparams; curr != NULL; curr = curr->next) {
for (curr = start; curr != end; curr++) {
if (curr->check_image_type) {
if (!curr->check_image_type(type))
return curr;
Expand All @@ -89,7 +36,12 @@ int imagetool_verify_print_header(
int retval = -1;
struct image_type_params *curr;

for (curr = tparams; curr != NULL; curr = curr->next) {
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);
Expand Down
Loading

0 comments on commit a93648d

Please sign in to comment.