2012-01-31 12:03:57 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000-2004
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* (C) Copyright 2011
|
|
|
|
* Texas Instruments, <www.ti.com>
|
|
|
|
*
|
|
|
|
* Matt Porter <mporter@ti.com>
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2012-01-31 12:03:57 +00:00
|
|
|
*/
|
|
|
|
#include <common.h>
|
2012-08-13 19:03:19 +00:00
|
|
|
#include <spl.h>
|
2012-01-31 12:03:57 +00:00
|
|
|
#include <xyzModem.h>
|
|
|
|
#include <asm/u-boot.h>
|
|
|
|
#include <asm/utils.h>
|
|
|
|
|
|
|
|
#define BUF_SIZE 1024
|
|
|
|
|
|
|
|
static int getcymodem(void) {
|
|
|
|
if (tstc())
|
|
|
|
return (getc());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-11-08 15:11:49 +00:00
|
|
|
int spl_ymodem_load_image(void)
|
2012-01-31 12:03:57 +00:00
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
int err;
|
|
|
|
int res;
|
|
|
|
int ret;
|
|
|
|
connection_info_t info;
|
|
|
|
char buf[BUF_SIZE];
|
|
|
|
ulong store_addr = ~0;
|
|
|
|
ulong addr = 0;
|
|
|
|
|
|
|
|
info.mode = xyzModem_ymodem;
|
|
|
|
ret = xyzModem_stream_open(&info, &err);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
while ((res =
|
|
|
|
xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) {
|
2016-04-28 22:44:54 +00:00
|
|
|
if (addr == 0) {
|
|
|
|
ret = spl_parse_image_header((struct image_header *)buf);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2012-01-31 12:03:57 +00:00
|
|
|
store_addr = addr + spl_image.load_addr;
|
|
|
|
size += res;
|
|
|
|
addr += res;
|
|
|
|
memcpy((char *)(store_addr), buf, res);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("spl: ymodem err - %s\n", xyzModem_error(err));
|
2015-11-08 15:11:49 +00:00
|
|
|
return ret;
|
2012-01-31 12:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xyzModem_stream_close(&err);
|
|
|
|
xyzModem_stream_terminate(false, &getcymodem);
|
|
|
|
|
|
|
|
printf("Loaded %d bytes\n", size);
|
2015-11-08 15:11:49 +00:00
|
|
|
return 0;
|
2012-01-31 12:03:57 +00:00
|
|
|
}
|