mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
To: barebox@lists.infradead.org
Cc: Lior Amsalem <alior@marvell.com>,
	Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Subject: [PATCHv2 03/10] scripts/kwbimage: make the v0 image creation more flexible
Date: Wed, 15 May 2013 09:36:29 +0200	[thread overview]
Message-ID: <1368603396-27887-4-git-send-email-thomas.petazzoni@free-electrons.com> (raw)
In-Reply-To: <1368603396-27887-1-git-send-email-thomas.petazzoni@free-electrons.com>

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>
---
 scripts/kwbimage.c |   48 ++++++++++++++++++++----------------------------
 1 file changed, 20 insertions(+), 28 deletions(-)

diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index cca20ab..d4f65a8 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,
-- 
1.7.9.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2013-05-15  7:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-15  7:36 [PATCHv2 00/10] kwbimage improvements, Kirkwood support Thomas Petazzoni
2013-05-15  7:36 ` [PATCHv2 01/10] scripts/kwbimage: add a new function image_count_options() Thomas Petazzoni
2013-05-15  7:36 ` [PATCHv2 02/10] scripts/kwbimage: add a few sanity checks Thomas Petazzoni
2013-05-15  7:36 ` Thomas Petazzoni [this message]
2013-05-15  7:36 ` [PATCHv2 04/10] scripts/kwbimage: simplify the v1 image creation Thomas Petazzoni
2013-05-15  7:36 ` [PATCHv2 05/10] scripts/kwbimage: make image_boot_mode_id() return -1 on failure Thomas Petazzoni
2013-05-15  7:36 ` [PATCHv2 06/10] scripts/kwbimage: add support for NAND ECC and page size header fields Thomas Petazzoni
2013-05-15  7:36 ` [PATCHv2 07/10] arm: mvebu: add Feroceon CPU type Thomas Petazzoni
2013-05-15  7:36 ` [PATCHv2 08/10] arm: mvebu: initial support for Marvell Kirkwood SoCs Thomas Petazzoni
2013-05-15  7:36 ` [PATCHv2 09/10] arm: mvebu: add basic support for Globalscale Guruplug board Thomas Petazzoni
2013-05-15  7:36 ` [PATCHv2 10/10] arm: mvebu: remove useless lines in kwbimage.cfg for CuBox Thomas Petazzoni
2013-05-15 20:07 ` [PATCHv2 00/10] kwbimage improvements, Kirkwood support Sebastian Hesselbarth
2013-05-17  5:41   ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1368603396-27887-4-git-send-email-thomas.petazzoni@free-electrons.com \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=alior@marvell.com \
    --cc=barebox@lists.infradead.org \
    --cc=ezequiel.garcia@free-electrons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox