Merge tag 'efi-2020-07-rc6' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
[oweals/u-boot.git] / common / spl / spl_ymodem.c
index c02c05624d48b1997efb227ea1680af3cb326b9b..284512478f1be52cf9119b18cf2fe0f73ed64043 100644 (file)
@@ -10,6 +10,8 @@
  */
 #include <common.h>
 #include <gzip.h>
+#include <image.h>
+#include <log.h>
 #include <spl.h>
 #include <xyzModem.h>
 #include <asm/u-boot.h>
@@ -37,7 +39,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 +53,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;
        }