[PATCH 12/23] scripts: imx-image: move check to context data

Sascha Hauer s.hauer at pengutronix.de
Fri Jan 29 02:43:52 PST 2016


Move the config parsers check function to context data to make
it possible to pass in a different version of this function later.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 scripts/imx/imx-image.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index 56c6464..04b650e 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -44,6 +44,7 @@ struct config_data {
 	uint32_t image_dcd_offset;
 	int header_version;
 	int cpu_type;
+	int (*check)(struct config_data *data, uint32_t cmd, uint32_t addr, uint32_t mask);
 	int (*write_mem)(struct config_data *data, uint32_t addr, uint32_t val, int width);
 };
 
@@ -314,6 +315,9 @@ static int do_cmd_check(struct config_data *data, int argc, char *argv[])
 		return -EINVAL;
 	}
 
+	if (!data->check)
+		return -ENOSYS;
+
 	width = strtoul(argv[1], NULL, 0) >> 3;
 	scmd = argv[2];
 	addr = strtoul(argv[3], NULL, 0);
@@ -346,13 +350,7 @@ static int do_cmd_check(struct config_data *data, int argc, char *argv[])
 
 	cmd = (TAG_CHECK << 24) | (i << 3) | width | ((sizeof(uint32_t) * 3) << 8);
 
-	check_last_dcd(cmd);
-
-	dcdtable[curdcd++] = htobe32(cmd);
-	dcdtable[curdcd++] = htobe32(addr);
-	dcdtable[curdcd++] = htobe32(mask);
-
-	return 0;
+	return data->check(data, cmd, addr, mask);
 }
 
 static int do_cmd_write_mem(struct config_data *data, int argc, char *argv[])
@@ -612,6 +610,22 @@ static int write_dcd(const char *outfile)
 	return 0;
 }
 
+static int check(struct config_data *data, uint32_t cmd, uint32_t addr, uint32_t mask)
+{
+	if (curdcd > MAX_DCD - 3) {
+		fprintf(stderr, "At maximum %d dcd entried are allowed\n", MAX_DCD);
+		return -ENOMEM;
+	}
+
+	check_last_dcd(cmd);
+
+	dcdtable[curdcd++] = htobe32(cmd);
+	dcdtable[curdcd++] = htobe32(addr);
+	dcdtable[curdcd++] = htobe32(mask);
+
+	return 0;
+}
+
 static int write_mem(struct config_data *data, uint32_t addr, uint32_t val, int width)
 {
 	switch (data->header_version) {
@@ -640,6 +654,7 @@ int main(int argc, char *argv[])
 	struct config_data data = {
 		.image_dcd_offset = 0xffffffff,
 		.write_mem = write_mem,
+		.check = check,
 	};
 
 	while ((opt = getopt(argc, argv, "c:hf:o:bdp")) != -1) {
-- 
2.7.0.rc3




More information about the barebox mailing list