2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Texas Instruments, <www.ti.com>
8 * Matt Porter <mporter@ti.com>
10 * SPDX-License-Identifier: GPL-2.0+
15 #include <asm/u-boot.h>
16 #include <asm/utils.h>
22 * Information required to load image using ymodem.
24 * @image_read: Now of bytes read from the image.
25 * @buf: pointer to the previous read block.
27 struct ymodem_fit_info {
32 static int getcymodem(void) {
38 static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset,
39 ulong size, void *addr)
42 struct ymodem_fit_info *info = load->priv;
43 char *buf = info->buf;
45 while (info->image_read < offset) {
46 res = xyzModem_stream_read(buf, BUF_SIZE, &err);
49 info->image_read += res;
52 if (info->image_read > offset) {
53 res = info->image_read - offset;
54 memcpy(addr, &buf[BUF_SIZE - res], res);
58 while (info->image_read < offset + size) {
59 res = xyzModem_stream_read(buf, BUF_SIZE, &err);
63 memcpy(addr, buf, res);
64 info->image_read += res;
71 static int spl_ymodem_load_image(struct spl_image_info *spl_image,
72 struct spl_boot_device *bootdev)
78 connection_info_t info;
82 info.mode = xyzModem_ymodem;
83 ret = xyzModem_stream_open(&info, &err);
85 printf("spl: ymodem err - %s\n", xyzModem_error(err));
89 res = xyzModem_stream_read(buf, BUF_SIZE, &err);
93 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
94 image_get_magic((struct image_header *)buf) == FDT_MAGIC) {
95 struct spl_load_info load;
96 struct ymodem_fit_info info;
100 load.priv = (void *)&info;
101 load.filename = NULL;
104 info.image_read = BUF_SIZE;
105 load.read = ymodem_read_fit;
106 ret = spl_load_simple_fit(spl_image, &load, 0, (void *)buf);
107 size = info.image_read;
109 while ((res = xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0)
112 ret = spl_parse_image_header(spl_image,
113 (struct image_header *)buf);
116 addr = spl_image->load_addr;
117 memcpy((void *)addr, buf, res);
121 while ((res = xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) {
122 memcpy((void *)addr, buf, res);
129 xyzModem_stream_close(&err);
130 xyzModem_stream_terminate(false, &getcymodem);
132 printf("Loaded %d bytes\n", size);
135 SPL_LOAD_IMAGE_METHOD("UART", 0, BOOT_DEVICE_UART, spl_ymodem_load_image);