diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-01-29 20:39:14 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-01-30 08:39:29 +0100 |
commit | d1050c021634fadd80bbc80c18bdfba0a0f4d6a3 (patch) | |
tree | 5082ea03db0063d074c67fd7da5b8b5325d88b88 /arch | |
parent | b5526c403c41ffa70a917df3841cd5e77b23d1f3 (diff) | |
download | barebox-d1050c021634fadd80bbc80c18bdfba0a0f4d6a3.tar.gz barebox-d1050c021634fadd80bbc80c18bdfba0a0f4d6a3.tar.xz |
bbu: imx-bbu-internal: Do not modify image
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@pengutronix.de>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/mach-imx/imx-bbu-internal.c | 19 |
1 files 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; |