[PATCH 1/6] bbu: imx-bbu-internal: Do not modify image

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of copying the existing partition table into the image
to be flashed, modify the temporary buffer and write from this
one. This makes it unnecessary to modify the input image which
can be made const then in a later step.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 arch/arm/mach-imx/imx-bbu-internal.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index 5783da6102..d40bde5339 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -54,6 +54,7 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
 		void *buf, int image_len)
 {
 	int fd, ret;
+	int written = 0;
 
 	fd = open(devicefile, O_RDWR | O_CREAT);
 	if (fd < 0)
@@ -90,15 +91,25 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
 			goto err_close;
 		}
 
-		memcpy(buf + 0x1b8, mbr + 0x1b8, 0x48);
-		free(mbr);
+		memcpy(mbr, buf, 0x1b8);
 
 		ret = lseek(fd, 0, SEEK_SET);
-		if (ret)
+		if (ret) {
+			free(mbr);
+			goto err_close;
+		}
+
+		ret = write(fd, mbr, 512);
+
+		free(mbr);
+
+		if (ret < 0)
 			goto err_close;
+
+		written = 512;
 	}
 
-	ret = write(fd, buf, image_len);
+	ret = write(fd, buf + written, image_len - written);
 	if (ret < 0)
 		goto err_close;
 
-- 
2.15.1


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



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux