mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 4/4] scripts/kwbimage: allow to overwrite binary
Date: Wed, 16 Nov 2016 10:52:44 +0100	[thread overview]
Message-ID: <20161116095244.14288-4-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20161116095244.14288-1-u.kleine-koenig@pengutronix.de>

This is a preparation to let barebox provide the binary.0.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
This is new in this series and a left over from my efforts to let
barebox implement the functionality of binary.0. For now that failed,
but this patch should be fine anyhow.

Best regards
Uwe

 scripts/kwbimage.c | 40 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 2af96f055c7e..5b84db3f7a23 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -347,6 +347,7 @@ static void usage(const char *prog)
 	printf("   -h: this help text\n");
 	printf(" Options specific to image creation:\n");
 	printf("   -p: path to payload image. Overrides the PAYLOAD line from kwbimage.cfg\n");
+	printf("   -b: path to binary image. Overrides the BINARY line from kwbimage.cfg\n");
 	printf("   -m: boot media. Overrides the BOOT_FROM line from kwbimage.cfg\n");
 	printf("   -d: load address. Overrides the DEST_ADDR line from kwbimage.cfg\n");
 	printf("   -e: exec address. Overrides the EXEC_ADDR line from kwbimage.cfg\n");
@@ -1186,6 +1187,30 @@ static int image_override_payload(struct image_cfg_element *image_cfg,
 	return 0;
 }
 
+static int image_override_binary(struct image_cfg_element *image_cfg,
+				 int *cfgn, char *binary)
+{
+	struct image_cfg_element *e;
+	int cfgi = *cfgn;
+
+	if (!binary)
+		return 0;
+
+	e = image_find_option(image_cfg, *cfgn, IMAGE_CFG_BINARY);
+	if (e) {
+		e->binary.file = binary;
+		return 0;
+	}
+
+	image_cfg[cfgi].type = IMAGE_CFG_BINARY;
+	image_cfg[cfgi].binary.file = binary;
+	image_cfg[cfgi].binary.nargs = 0;
+	cfgi++;
+
+	*cfgn = cfgi;
+	return 0;
+}
+
 static int image_override_bootmedia(struct image_cfg_element *image_cfg,
 				    int *cfgn, const char *bootmedia)
 {
@@ -1332,9 +1357,9 @@ static void image_dump_config(struct image_cfg_element *image_cfg,
 }
 
 static int image_create(const char *input, const char *output,
-			const char *payload, const char *bootmedia,
-			uint32_t dstaddr, uint32_t execaddr,
-			int verbose)
+			const char *payload, char *binary,
+			const char *bootmedia, uint32_t dstaddr,
+			uint32_t execaddr, int verbose)
 {
 	struct image_cfg_element *image_cfg;
 	FILE *outputimg;
@@ -1361,6 +1386,7 @@ static int image_create(const char *input, const char *output,
 	}
 
 	image_override_payload(image_cfg, &cfgn, payload);
+	image_override_binary(image_cfg, &cfgn, binary);
 	image_override_bootmedia(image_cfg, &cfgn, bootmedia);
 	image_override_dstaddr(image_cfg, &cfgn, dstaddr);
 	image_override_execaddr(image_cfg, &cfgn, execaddr);
@@ -1433,9 +1459,10 @@ int main(int argc, char *argv[])
 	int action = -1, opt, verbose = 0;
 	const char *input = NULL, *output = NULL,
 		*payload = NULL, *bootmedia = NULL;
+	char *binary = NULL;
 	uint32_t execaddr = ADDR_INVALID, dstaddr = ADDR_INVALID;
 
-	while ((opt = getopt(argc, argv, "hxci:o:p:m:e:d:v")) != -1) {
+	while ((opt = getopt(argc, argv, "hxci:o:p:b:m:e:d:v")) != -1) {
 		switch (opt) {
 		case 'x':
 			action = ACTION_EXTRACT;
@@ -1452,6 +1479,9 @@ int main(int argc, char *argv[])
 		case 'p':
 			payload = optarg;
 			break;
+		case 'b':
+			binary = optarg;
+			break;
 		case 'm':
 			bootmedia = optarg;
 			break;
@@ -1502,7 +1532,7 @@ int main(int argc, char *argv[])
 	case ACTION_EXTRACT:
 		return image_extract(input, output);
 	case ACTION_CREATE:
-		return image_create(input, output, payload,
+		return image_create(input, output, payload, binary,
 				    bootmedia, dstaddr, execaddr,
 				    verbose);
 	case ACTION_HELP:
-- 
2.10.2


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

  parent reply	other threads:[~2016-11-16  9:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-16  9:52 [PATCH v2 1/4] scripts/kwbimage: fix handling of binary header Uwe Kleine-König
2016-11-16  9:52 ` [PATCH v2 2/4] scripts/kwbimage: fix typo Uwe Kleine-König
2016-11-16  9:52 ` [PATCH v2 3/4] scripts/kwbimage: use ALIGN_SUP instead of open-coding it Uwe Kleine-König
2016-11-16  9:52 ` Uwe Kleine-König [this message]
2016-11-17  6:58 ` [PATCH v2 1/4] scripts/kwbimage: fix handling of binary header 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=20161116095244.14288-4-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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