summaryrefslogtreecommitdiff
path: root/common/spl/spl_ymodem.c
diff options
context:
space:
mode:
authorLokesh Vutla <lokeshvutla@ti.com>2019-11-14 16:03:30 +0300
committerTom Rini <trini@konsulko.com>2019-12-03 16:44:14 +0300
commit095764e369ec7e313f6cb45f633b203b4ec622cc (patch)
tree577f874eb3f6f1346442a01fce48e9496dafb6a0 /common/spl/spl_ymodem.c
parent3ef94715cc011e3f0042019359f848f9f129b391 (diff)
downloadu-boot-095764e369ec7e313f6cb45f633b203b4ec622cc.tar.xz
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. Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Diffstat (limited to 'common/spl/spl_ymodem.c')
-rw-r--r--common/spl/spl_ymodem.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c
index c02c05624d..8500ee8ba5 100644
--- a/common/spl/spl_ymodem.c
+++ b/common/spl/spl_ymodem.c
@@ -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;
}