[RESEND v3 50/52] scripts: imx-image: Share the code to write barebox header

Andrey Smirnov andrew.smirnov at gmail.com
Thu Jun 7 06:01:06 PDT 2018


Signed-off-by: Andrey Smirnov <andrew.smirnov at gmail.com>
---
 scripts/imx/imx-image.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index 294f51a90..09686f69c 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -216,9 +216,6 @@ static int add_header_v1(struct config_data *data, void *buf)
 	uint32_t loadaddr = data->image_load_addr;
 	uint32_t imagesize = data->load_size;
 
-	if (add_barebox_header)
-		memcpy(buf, bb_header, sizeof(bb_header));
-
 	buf += offset;
 	hdr = buf;
 
@@ -292,9 +289,6 @@ static int add_header_v2(const struct config_data *data, void *buf)
 	uint32_t loadaddr = data->image_load_addr;
 	uint32_t imagesize = data->load_size;
 
-	if (add_barebox_header)
-		memcpy(buf, bb_header, sizeof(bb_header));
-
 	buf += offset;
 	hdr = buf;
 
@@ -824,7 +818,15 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	ret = xwrite(outfd, buf, HEADER_LEN);
+	ret = xwrite(outfd, add_barebox_header ? bb_header : buf,
+		     sizeof(bb_header));
+	if (ret < 0) {
+		perror("write");
+		exit(1);
+	}
+
+	ret = xwrite(outfd, buf + sizeof(bb_header),
+		     HEADER_LEN - sizeof(bb_header));
 	if (ret < 0) {
 		perror("write");
 		exit(1);
-- 
2.17.0




More information about the barebox mailing list