]> Git Repo - u-boot.git/blobdiff - common/spl/spl_ymodem.c
global: Make <asm/global_data.h> include <asm/u-boot.h>
[u-boot.git] / common / spl / spl_ymodem.c
index 047df74856b6e9991b75f37527d06144c6c75cf7..4c7222af612dc92d59d85899c46d524923f3182f 100644 (file)
@@ -8,13 +8,11 @@
  *
  * Matt Porter <[email protected]>
  */
-#include <common.h>
 #include <gzip.h>
 #include <image.h>
 #include <log.h>
 #include <spl.h>
 #include <xyzModem.h>
-#include <asm/u-boot.h>
 #include <linux/libfdt.h>
 
 #define BUF_SIZE 1024
@@ -42,6 +40,7 @@ static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset,
        int res, err, buf_offset;
        struct ymodem_fit_info *info = load->priv;
        char *buf = info->buf;
+       ulong copy_size = size;
 
        while (info->image_read < offset) {
                res = xyzModem_stream_read(buf, BUF_SIZE, &err);
@@ -57,8 +56,14 @@ static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset,
                        buf_offset = (info->image_read % BUF_SIZE);
                else
                        buf_offset = BUF_SIZE;
+
+               if (res > copy_size) {
+                       memcpy(addr, &buf[buf_offset - res], copy_size);
+                       goto done;
+               }
                memcpy(addr, &buf[buf_offset - res], res);
                addr = addr + res;
+               copy_size -= res;
        }
 
        while (info->image_read < offset + size) {
@@ -66,11 +71,17 @@ static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset,
                if (res <= 0)
                        break;
 
-               memcpy(addr, buf, res);
                info->image_read += res;
+               if (res > copy_size) {
+                       memcpy(addr, buf, copy_size);
+                       goto done;
+               }
+               memcpy(addr, buf, res);
                addr += res;
+               copy_size -= res;
        }
 
+done:
        return size;
 }
 
@@ -83,7 +94,7 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image,
        int ret;
        connection_info_t info;
        char buf[BUF_SIZE];
-       struct image_header *ih = NULL;
+       struct legacy_img_hdr *ih = NULL;
        ulong addr = 0;
 
        info.mode = xyzModem_ymodem;
@@ -98,9 +109,9 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image,
                goto end_stream;
 
        if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
-           image_get_magic((struct image_header *)buf) == FDT_MAGIC) {
+           image_get_magic((struct legacy_img_hdr *)buf) == FDT_MAGIC) {
                addr = CONFIG_SYS_LOAD_ADDR;
-               ih = (struct image_header *)addr;
+               ih = (struct legacy_img_hdr *)addr;
 
                memcpy((void *)addr, buf, res);
                size += res;
@@ -116,15 +127,13 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image,
                if (ret)
                        return ret;
        } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-           image_get_magic((struct image_header *)buf) == FDT_MAGIC) {
+           image_get_magic((struct legacy_img_hdr *)buf) == FDT_MAGIC) {
                struct spl_load_info load;
                struct ymodem_fit_info info;
 
                debug("Found FIT\n");
-               load.dev = NULL;
                load.priv = (void *)&info;
-               load.filename = NULL;
-               load.bl_len = 1;
+               spl_set_bl_len(&load, 1);
                info.buf = buf;
                info.image_read = BUF_SIZE;
                load.read = ymodem_read_fit;
@@ -134,7 +143,7 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image,
                while ((res = xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0)
                        size += res;
        } else {
-               ih = (struct image_header *)buf;
+               ih = (struct legacy_img_hdr *)buf;
                ret = spl_parse_image_header(spl_image, bootdev, ih);
                if (ret)
                        goto end_stream;
@@ -145,7 +154,7 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image,
 #endif
                        addr = spl_image->load_addr;
                memcpy((void *)addr, buf, res);
-               ih = (struct image_header *)addr;
+               ih = (struct legacy_img_hdr *)addr;
                size += res;
                addr += res;
 
@@ -164,7 +173,7 @@ end_stream:
 
 #ifdef CONFIG_SPL_GZIP
        if (!(IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-             image_get_magic((struct image_header *)buf) == FDT_MAGIC) &&
+             image_get_magic((struct legacy_img_hdr *)buf) == FDT_MAGIC) &&
            (ih->ih_comp == IH_COMP_GZIP)) {
                if (gunzip((void *)(spl_image->load_addr + sizeof(*ih)),
                           CONFIG_SYS_BOOTM_LEN,
This page took 0.030008 seconds and 4 git commands to generate.