Matt Porter | 24de357 | 2012-01-31 12:03:57 +0000 | [diff] [blame] | 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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
Matt Porter | 24de357 | 2012-01-31 12:03:57 +0000 | [diff] [blame] | 11 | */ |
| 12 | #include <common.h> |
Tom Rini | 47f7bca | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 13 | #include <spl.h> |
Matt Porter | 24de357 | 2012-01-31 12:03:57 +0000 | [diff] [blame] | 14 | #include <xyzModem.h> |
| 15 | #include <asm/u-boot.h> |
| 16 | #include <asm/utils.h> |
Matt Porter | 24de357 | 2012-01-31 12:03:57 +0000 | [diff] [blame] | 17 | |
| 18 | #define BUF_SIZE 1024 |
| 19 | |
| 20 | static int getcymodem(void) { |
| 21 | if (tstc()) |
| 22 | return (getc()); |
| 23 | return -1; |
| 24 | } |
| 25 | |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 26 | int spl_ymodem_load_image(void) |
Matt Porter | 24de357 | 2012-01-31 12:03:57 +0000 | [diff] [blame] | 27 | { |
| 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) { |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 43 | if (addr == 0) { |
| 44 | ret = spl_parse_image_header((struct image_header *)buf); |
| 45 | if (ret) |
| 46 | return ret; |
| 47 | } |
Matt Porter | 24de357 | 2012-01-31 12:03:57 +0000 | [diff] [blame] | 48 | store_addr = addr + spl_image.load_addr; |
| 49 | size += res; |
| 50 | addr += res; |
| 51 | memcpy((char *)(store_addr), buf, res); |
| 52 | } |
| 53 | } else { |
| 54 | printf("spl: ymodem err - %s\n", xyzModem_error(err)); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 55 | return ret; |
Matt Porter | 24de357 | 2012-01-31 12:03:57 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | xyzModem_stream_close(&err); |
| 59 | xyzModem_stream_terminate(false, &getcymodem); |
| 60 | |
| 61 | printf("Loaded %d bytes\n", size); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 62 | return 0; |
Matt Porter | 24de357 | 2012-01-31 12:03:57 +0000 | [diff] [blame] | 63 | } |