summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-10-15 10:04:09 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2015-10-19 08:39:25 +0200
commitfe89df4ed968430320a09f2ced726f401260468f (patch)
tree22aae2b0516519c4ec589a1ceec8f67b6e535c37
parent119f75f23a92b5171978a6691fd10e12247628ea (diff)
downloadbarebox-fe89df4ed968430320a09f2ced726f401260468f.tar.gz
scripts/kwbimage: Make BINARY files relative to config file
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>
-rw-r--r--arch/arm/boards/globalscale-mirabox/kwbimage.cfg2
-rw-r--r--arch/arm/boards/lenovo-ix4-300d/kwbimage.cfg2
-rw-r--r--arch/arm/boards/marvell-armada-xp-gp/kwbimage.cfg2
-rw-r--r--arch/arm/boards/plathome-openblocks-ax3/kwbimage.cfg2
-rw-r--r--scripts/kwbimage.c17
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..fa8e5a6 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..a9b035e 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..eb8a2e7 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..eb8a2e7 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;
}