[PATCH 11/23] scripts: imx-image: move write_mem to context data
Sascha Hauer
s.hauer at pengutronix.de
Fri Jan 29 02:43:51 PST 2016
Move the config parsers write_mem 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 | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index 707852b..56c6464 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 (*write_mem)(struct config_data *data, uint32_t addr, uint32_t val, int width);
};
static uint32_t dcdtable[MAX_DCD];
@@ -394,14 +395,7 @@ static int do_cmd_write_mem(struct config_data *data, int argc, char *argv[])
return -EINVAL;
};
- switch (data->header_version) {
- case 1:
- return write_mem_v1(addr, val, width);
- case 2:
- return write_mem_v2(addr, val, width);
- default:
- return -EINVAL;
- }
+ return data->write_mem(data, addr, val, width);
}
static int do_loadaddr(struct config_data *data, int argc, char *argv[])
@@ -618,6 +612,18 @@ static int write_dcd(const char *outfile)
return 0;
}
+static int write_mem(struct config_data *data, uint32_t addr, uint32_t val, int width)
+{
+ switch (data->header_version) {
+ case 1:
+ return write_mem_v1(addr, val, width);
+ case 2:
+ return write_mem_v2(addr, val, width);
+ default:
+ return -EINVAL;
+ }
+}
+
int main(int argc, char *argv[])
{
int opt, ret;
@@ -633,6 +639,7 @@ int main(int argc, char *argv[])
int now = 0;
struct config_data data = {
.image_dcd_offset = 0xffffffff,
+ .write_mem = write_mem,
};
while ((opt = getopt(argc, argv, "c:hf:o:bdp")) != -1) {
--
2.7.0.rc3
More information about the barebox
mailing list