mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Subject: [PATCH 2/3] scripts/kwbimage: Make BINARY files relative to config file
Date: Thu, 15 Oct 2015 10:18:55 +0200	[thread overview]
Message-ID: <1444897136-25028-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1444897136-25028-1-git-send-email-s.hauer@pengutronix.de>

The BINARY files given in the config files are expected to be relative
to the place kwbimage is called from. This is bad since it breaks where
kwbimage is called from the build directory and not the source
directory.
It makes more sense to make the paths in the config files relative
to the config files which works with out of tree builds and is also
more what a user normally expects.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/globalscale-mirabox/kwbimage.cfg     |  2 +-
 arch/arm/boards/lenovo-ix4-300d/kwbimage.cfg         |  2 +-
 arch/arm/boards/marvell-armada-xp-gp/kwbimage.cfg    |  2 +-
 arch/arm/boards/plathome-openblocks-ax3/kwbimage.cfg |  2 +-
 scripts/kwbimage.c                                   | 17 +++++++++++++----
 5 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boards/globalscale-mirabox/kwbimage.cfg b/arch/arm/boards/globalscale-mirabox/kwbimage.cfg
index 16fb77c..3e20502 100644
--- a/arch/arm/boards/globalscale-mirabox/kwbimage.cfg
+++ b/arch/arm/boards/globalscale-mirabox/kwbimage.cfg
@@ -2,4 +2,4 @@ VERSION 1
 BOOT_FROM nand
 NAND_BLKSZ 00020000
 NAND_BADBLK_LOCATION 01
-BINARY arch/arm/boards/globalscale-mirabox/binary.0 0000005b 00000068
+BINARY binary.0 0000005b 00000068
diff --git a/arch/arm/boards/lenovo-ix4-300d/kwbimage.cfg b/arch/arm/boards/lenovo-ix4-300d/kwbimage.cfg
index 713efb0..15b7fdd 100644
--- a/arch/arm/boards/lenovo-ix4-300d/kwbimage.cfg
+++ b/arch/arm/boards/lenovo-ix4-300d/kwbimage.cfg
@@ -2,4 +2,4 @@ VERSION 1
 BOOT_FROM nand
 NAND_BLKSZ 00020000
 NAND_BADBLK_LOCATION 00
-BINARY arch/arm/boards/lenovo-ix4-300d/binary.0 0000005b 00000068
+BINARY binary.0 0000005b 00000068
diff --git a/arch/arm/boards/marvell-armada-xp-gp/kwbimage.cfg b/arch/arm/boards/marvell-armada-xp-gp/kwbimage.cfg
index 3f66aa0..05d398c 100644
--- a/arch/arm/boards/marvell-armada-xp-gp/kwbimage.cfg
+++ b/arch/arm/boards/marvell-armada-xp-gp/kwbimage.cfg
@@ -1,3 +1,3 @@
 VERSION 1
 BOOT_FROM spi
-BINARY arch/arm/boards/marvell-armada-xp-gp/binary.0 0000005b 00000068
+BINARY binary.0 0000005b 00000068
diff --git a/arch/arm/boards/plathome-openblocks-ax3/kwbimage.cfg b/arch/arm/boards/plathome-openblocks-ax3/kwbimage.cfg
index 1d05715..05d398c 100644
--- a/arch/arm/boards/plathome-openblocks-ax3/kwbimage.cfg
+++ b/arch/arm/boards/plathome-openblocks-ax3/kwbimage.cfg
@@ -1,3 +1,3 @@
 VERSION 1
 BOOT_FROM spi
-BINARY arch/arm/boards/plathome-openblocks-ax3/binary.0 0000005b 00000068
+BINARY binary.0 0000005b 00000068
diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 16be2dd..448ac2a 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -51,6 +51,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+#include <libgen.h>
 
 #define ALIGN_SUP(x, a) (((x) + (a - 1)) & ~(a - 1))
 
@@ -187,7 +188,7 @@ struct image_cfg_element {
 		unsigned int version;
 		unsigned int bootfrom;
 		struct {
-			const char *file;
+			char *file;
 			unsigned int args[BINARY_MAX_ARGS];
 			unsigned int nargs;
 		} binary;
@@ -1003,7 +1004,8 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
 }
 
 static int image_create_config_parse_oneline(char *line,
-					     struct image_cfg_element *el)
+					     struct image_cfg_element *el,
+					     char *configpath)
 {
 	char *keyword, *saveptr;
 
@@ -1056,7 +1058,10 @@ static int image_create_config_parse_oneline(char *line,
 		int argi = 0;
 
 		el->type = IMAGE_CFG_BINARY;
-		el->binary.file = strdup(value);
+		if (*value == '/')
+			el->binary.file = strdup(value);
+		else
+			asprintf(&el->binary.file, "%s/%s", configpath, value);
 		while (1) {
 			value = strtok_r(NULL, " ", &saveptr);
 			if (!value)
@@ -1105,11 +1110,13 @@ static int image_create_config_parse(const char *input,
 	int ret;
 	int cfgi = 0;
 	FILE *fcfg;
+	char *configpath = dirname(strdup(input));
 
 	fcfg = fopen(input, "r");
 	if (!fcfg) {
 		fprintf(stderr, "Could not open input file %s\n",
 			input);
+		free(configpath);
 		return -1;
 	}
 
@@ -1134,7 +1141,8 @@ static int image_create_config_parse(const char *input,
 
 		/* Parse the current line */
 		ret = image_create_config_parse_oneline(line,
-							&image_cfg[cfgi]);
+							&image_cfg[cfgi],
+							configpath);
 		if (ret)
 			goto out;
 
@@ -1151,6 +1159,7 @@ static int image_create_config_parse(const char *input,
 	*cfgn = cfgi;
 out:
 	fclose(fcfg);
+	free(configpath);
 	return ret;
 }
 
-- 
2.6.1


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

  parent reply	other threads:[~2015-10-15  8:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-15  8:18 Sascha Hauer
2015-10-15  8:18 ` [PATCH 1/3] scripts/kwbimage: Move configfile opening to the function that reads it Sascha Hauer
2015-10-15  8:18 ` Sascha Hauer [this message]
2015-10-15  9:00   ` [PATCH 2/3] scripts/kwbimage: Make BINARY files relative to config file Thomas Petazzoni
2015-10-15  9:29     ` Sebastian Hesselbarth
2015-10-15  9:44       ` Thomas Petazzoni
2015-10-19  6:40       ` Sascha Hauer
2015-10-15 10:44     ` Sascha Hauer
2015-10-15  8:18 ` [PATCH 3/3] ARM: mvebu: Lenovo IX4 300D: Fix pblb generation 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=1444897136-25028-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=thomas.petazzoni@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