[PATCH v2 4/4] scripts/kwbimage: allow to overwrite binary

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Wed Nov 16 01:52:44 PST 2016


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

Signed-off-by: Uwe Kleine-König <u.kleine-koenig at 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




More information about the barebox mailing list