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_boot_device *bootdev)
77 connection_info_t info;
81 info.mode = xyzModem_ymodem;
82 ret = xyzModem_stream_open(&info, &err);
84 printf("spl: ymodem err - %s\n", xyzModem_error(err));
88 res = xyzModem_stream_read(buf, BUF_SIZE, &err);
92 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
93 image_get_magic((struct image_header *)buf) == FDT_MAGIC) {
94 struct spl_load_info load;
95 struct ymodem_fit_info info;
99 load.priv = (void *)&info;
100 load.filename = NULL;
103 info.image_read = BUF_SIZE;
104 load.read = ymodem_read_fit;
105 ret = spl_load_simple_fit(&load, 0, (void *)buf);
106 size = info.image_read;
108 while ((res = xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0)
111 spl_parse_image_header(&spl_image, (struct image_header *)buf);
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(0, BOOT_DEVICE_UART, spl_ymodem_load_image);