summaryrefslogtreecommitdiffstats
path: root/scripts/kwbimage.c
diff options
context:
space:
mode:
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>2013-05-15 09:36:29 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-05-17 07:39:56 +0200
commite91abe2ec433d665a692c3095517f7ac0bbe1d5a (patch)
treec7195ef1522237d94d7f3d46007aea954d88c33b /scripts/kwbimage.c
parentd60819c62691a40c23b97d1bdf2da428af40544d (diff)
downloadbarebox-e91abe2ec433d665a692c3095517f7ac0bbe1d5a.tar.gz
barebox-e91abe2ec433d665a692c3095517f7ac0bbe1d5a.tar.xz
scripts/kwbimage: make the v0 image creation more flexible
Until now, the v0 image creation function was expecting the configuration parameters to be ordered with first the configuration parameters affecting the main header, then the DATA configuration parameters that affect the extended header, then the payload. However, with the recently added ability to override the destination address or execution address, the configuration options corresponding to those values may now appear at the end of the configuration options. This commit allows to handle that by making the image creation more flexible: - The configuration options for the main header are just searched amongst all options, the first match is used. - When building the extension header with the DATA options, all DATA options from the configuration file are used, in the order in which they appear in the kwbimage.cfg file. This will for example allow a kwbimage.cfg for a v0 image to not specify any destination or execution address, and simply override it from the command line. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Tested-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts/kwbimage.c')
-rw-r--r--scripts/kwbimage.c48
1 files changed, 20 insertions, 28 deletions
diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index cca20abdcd..d4f65a8b4c 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -705,7 +705,7 @@ static void *image_create_v0(struct image_cfg_element *image_cfg,
struct ext_hdr_v0 *ext_hdr;
void *image;
int has_ext = 0;
- int cfgi, ret;
+ int ret;
/* Calculate the size of the header and the size of the
* payload */
@@ -754,42 +754,34 @@ static void *image_create_v0(struct image_cfg_element *image_cfg,
main_hdr->blocksize = payloadsz + sizeof(uint32_t);
main_hdr->srcaddr = headersz;
main_hdr->ext = has_ext;
- for (cfgi = 0; cfgi < cfgn; cfgi++) {
- struct image_cfg_element *el = &image_cfg[cfgi];
- if (el->type == IMAGE_CFG_BOOT_FROM)
- main_hdr->blockid = el->bootfrom;
- else if (el->type == IMAGE_CFG_DEST_ADDR)
- main_hdr->destaddr = el->dstaddr;
- else if (el->type == IMAGE_CFG_EXEC_ADDR)
- main_hdr->execaddr = el->execaddr;
- else if (el->type != IMAGE_CFG_VERSION)
- break;
- }
-
+ e = image_find_option(image_cfg, cfgn, IMAGE_CFG_BOOT_FROM);
+ if (e)
+ main_hdr->blockid = e->bootfrom;
+ e = image_find_option(image_cfg, cfgn, IMAGE_CFG_DEST_ADDR);
+ if (e)
+ main_hdr->destaddr = e->dstaddr;
+ e = image_find_option(image_cfg, cfgn, IMAGE_CFG_EXEC_ADDR);
+ if (e)
+ main_hdr->execaddr = e->execaddr;
main_hdr->checksum = image_checksum8(image,
sizeof(struct main_hdr_v0));
/* Generate the ext header */
if (has_ext) {
- int datai = 0;
+ int cfgi, datai;
ext_hdr = image + sizeof(struct main_hdr_v0);
ext_hdr->offset = 0x40;
- for (; cfgi < cfgn; cfgi++) {
- struct image_cfg_element *el = &image_cfg[cfgi];
- if (el->type == IMAGE_CFG_DATA) {
- ext_hdr->rcfg[datai].raddr = el->regdata.raddr;
- ext_hdr->rcfg[datai].rdata = el->regdata.rdata;
- datai++;
- }
- else if (el->type == IMAGE_CFG_PAYLOAD)
- break;
- else {
- fprintf(stderr, "Invalid element of type %d\n",
- el->type);
- return NULL;
- }
+ for (cfgi = 0, datai = 0; cfgi < cfgn; cfgi++) {
+ e = &image_cfg[cfgi];
+
+ if (e->type != IMAGE_CFG_DATA)
+ continue;
+
+ ext_hdr->rcfg[datai].raddr = e->regdata.raddr;
+ ext_hdr->rcfg[datai].rdata = e->regdata.rdata;
+ datai++;
}
ext_hdr->checksum = image_checksum8(ext_hdr,