diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c index cca20abdc..d4f65a8b4 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,