]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/spl/spl_ymodem.c
merged tx6dl-devel into denx master branch
[karo-tx-uboot.git] / common / spl / spl_ymodem.c
1 /*
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  *
10  * SPDX-License-Identifier:     GPL-2.0+
11  */
12 #include <common.h>
13 #include <spl.h>
14 #include <xyzModem.h>
15 #include <watchdog.h>
16 #include <asm/u-boot.h>
17 #include <asm/utils.h>
18
19 #define BUF_SIZE 1024
20
21 static int getcymodem(void) {
22         if (tstc())
23                 return (getc());
24         return -1;
25 }
26
27 void spl_ymodem_load_image(void)
28 {
29         int size = 0;
30         int err;
31         int res;
32         int ret;
33         connection_info_t info;
34         char buf[BUF_SIZE];
35         ulong store_addr = ~0;
36         ulong addr = 0;
37
38 loop:
39         info.mode = xyzModem_ymodem;
40         ret = xyzModem_stream_open(&info, &err);
41         if (ret == 0) {
42                 while ((res = xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) {
43                         WATCHDOG_RESET();
44                         if (addr == 0)
45                                 spl_parse_image_header((struct image_header *)buf);
46                         store_addr = addr + spl_image.load_addr;
47                         size += res;
48                         addr += res;
49                         memcpy((char *)store_addr, buf, res);
50                 }
51         } else {
52                 WATCHDOG_RESET();
53                 printf("Retrying...\n");
54                 goto loop;
55         }
56
57         xyzModem_stream_close(&err);
58         xyzModem_stream_terminate(false, &getcymodem);
59
60         printf("Loaded %d bytes\n", size);
61 }