blob: 380d8ddf52831a0b175a10838fcc2274d6190e48 [file] [log] [blame]
Matt Porter24de3572012-01-31 12:03:57 +00001/*
2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2011
6 * Texas Instruments, <www.ti.com>
7 *
8 * Matt Porter <mporter@ti.com>
9 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Matt Porter24de3572012-01-31 12:03:57 +000011 */
12#include <common.h>
Tom Rini47f7bca2012-08-13 12:03:19 -070013#include <spl.h>
Matt Porter24de3572012-01-31 12:03:57 +000014#include <xyzModem.h>
15#include <asm/u-boot.h>
16#include <asm/utils.h>
Matt Porter24de3572012-01-31 12:03:57 +000017
18#define BUF_SIZE 1024
19
20static int getcymodem(void) {
21 if (tstc())
22 return (getc());
23 return -1;
24}
25
Nikita Kiryanov36afd452015-11-08 17:11:49 +020026int spl_ymodem_load_image(void)
Matt Porter24de3572012-01-31 12:03:57 +000027{
28 int size = 0;
29 int err;
30 int res;
31 int ret;
32 connection_info_t info;
33 char buf[BUF_SIZE];
34 ulong store_addr = ~0;
35 ulong addr = 0;
36
37 info.mode = xyzModem_ymodem;
38 ret = xyzModem_stream_open(&info, &err);
39
40 if (!ret) {
41 while ((res =
42 xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) {
43 if (addr == 0)
44 spl_parse_image_header((struct image_header *)buf);
45 store_addr = addr + spl_image.load_addr;
46 size += res;
47 addr += res;
48 memcpy((char *)(store_addr), buf, res);
49 }
50 } else {
51 printf("spl: ymodem err - %s\n", xyzModem_error(err));
Nikita Kiryanov36afd452015-11-08 17:11:49 +020052 return ret;
Matt Porter24de3572012-01-31 12:03:57 +000053 }
54
55 xyzModem_stream_close(&err);
56 xyzModem_stream_terminate(false, &getcymodem);
57
58 printf("Loaded %d bytes\n", size);
Nikita Kiryanov36afd452015-11-08 17:11:49 +020059 return 0;
Matt Porter24de3572012-01-31 12:03:57 +000060}