Skip to contentSkip to conversation

spl: ymodem: Fix loading of fit image

PATCH New Lokesh Vutla 2 participants 2 messages Nov 14, 2019 – Dec 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spl: ymodem: Fix loading of fit image

spl ymodem driver always assumes that 1 BUF_SIZE is read in one stream. This might not be true when image is not padded to BUF_SIZE and the last sector that gets loaded will be < BUF_SIZE. Drop this assumption and use the actual size that is loaded.

---
 common/spl/spl_ymodem.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
common/spl/spl_ymodem.c +6 -2
index c02c05624d..8500ee8ba5 100644
@@ -37,7 +37,7 @@ static int getcymodem(void) {
 static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset,
 			     ulong size, void *addr)
 {
-	int res, err;
+	int res, err, buf_offset;
 	struct ymodem_fit_info *info = load->priv;
 	char *buf = info->buf;
 
@@ -51,7 +51,11 @@ static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset,
 
 	if (info->image_read > offset) {
 		res = info->image_read - offset;
-		memcpy(addr, &buf[BUF_SIZE - res], res);
+		if (info->image_read % BUF_SIZE)
+			buf_offset = (info->image_read % BUF_SIZE);
+		else
+			buf_offset = BUF_SIZE;
+		memcpy(addr, &buf[buf_offset - res], res);
 		addr = addr + res;
 	}
 
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/1 spl: ymodem: Fix loading of fit image

Quoted 6 lines · Lokesh Vutla

spl ymodem driver always assumes that 1 BUF_SIZE is read in one stream. This might not be true when image is not padded to BUF_SIZE and the last sector that gets loaded will be < BUF_SIZE. Drop this assumption and use the actual size that is loaded.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191203/d3eebb6f/attachment-0001.sig>