*
*/
-#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
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);
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) {
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;
}
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;
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;
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;
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;
#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;
#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,