fa539ecd7af4f4f3989c2704084c8bfb1bcb13fc
1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2004
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * Texas Instruments, <www.ti.com>
9 * Matt Porter <mporter@ti.com>
14 #include <asm/u-boot.h>
15 #include <linux/libfdt.h>
20 * Information required to load image using ymodem.
22 * @image_read: Now of bytes read from the image.
23 * @buf: pointer to the previous read block.
25 struct ymodem_fit_info
{
30 static int getcymodem(void) {
36 static ulong
ymodem_read_fit(struct spl_load_info
*load
, ulong offset
,
37 ulong size
, void *addr
)
40 struct ymodem_fit_info
*info
= load
->priv
;
41 char *buf
= info
->buf
;
43 while (info
->image_read
< offset
) {
44 res
= xyzModem_stream_read(buf
, BUF_SIZE
, &err
);
47 info
->image_read
+= res
;
50 if (info
->image_read
> offset
) {
51 res
= info
->image_read
- offset
;
52 memcpy(addr
, &buf
[BUF_SIZE
- res
], res
);
56 while (info
->image_read
< offset
+ size
) {
57 res
= xyzModem_stream_read(buf
, BUF_SIZE
, &err
);
61 memcpy(addr
, buf
, res
);
62 info
->image_read
+= res
;
69 static int spl_ymodem_load_image(struct spl_image_info
*spl_image
,
70 struct spl_boot_device
*bootdev
)
76 connection_info_t info
;
78 struct image_header
*ih
= NULL
;
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_FULL
) &&
93 image_get_magic((struct image_header
*)buf
) == FDT_MAGIC
) {
94 addr
= CONFIG_SYS_LOAD_ADDR
;
95 ih
= (struct image_header
*)addr
;
97 memcpy((void *)addr
, buf
, res
);
101 while ((res
= xyzModem_stream_read(buf
, BUF_SIZE
, &err
)) > 0) {
102 memcpy((void *)addr
, buf
, res
);
107 ret
= spl_parse_image_header(spl_image
, ih
);
110 } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT
) &&
111 image_get_magic((struct image_header
*)buf
) == FDT_MAGIC
) {
112 struct spl_load_info load
;
113 struct ymodem_fit_info info
;
115 debug("Found FIT\n");
117 load
.priv
= (void *)&info
;
118 load
.filename
= NULL
;
121 info
.image_read
= BUF_SIZE
;
122 load
.read
= ymodem_read_fit
;
123 ret
= spl_load_simple_fit(spl_image
, &load
, 0, (void *)buf
);
124 size
= info
.image_read
;
126 while ((res
= xyzModem_stream_read(buf
, BUF_SIZE
, &err
)) > 0)
129 ih
= (struct image_header
*)buf
;
130 ret
= spl_parse_image_header(spl_image
, ih
);
133 #ifdef CONFIG_SPL_GZIP
134 if (ih
->ih_comp
== IH_COMP_GZIP
)
135 addr
= CONFIG_SYS_LOAD_ADDR
;
138 addr
= spl_image
->load_addr
;
139 memcpy((void *)addr
, buf
, res
);
140 ih
= (struct image_header
*)addr
;
144 while ((res
= xyzModem_stream_read(buf
, BUF_SIZE
, &err
)) > 0) {
145 memcpy((void *)addr
, buf
, res
);
152 xyzModem_stream_close(&err
);
153 xyzModem_stream_terminate(false, &getcymodem
);
155 printf("Loaded %lu bytes\n", size
);
157 #ifdef CONFIG_SPL_GZIP
158 if (!(IS_ENABLED(CONFIG_SPL_LOAD_FIT
) &&
159 image_get_magic((struct image_header
*)buf
) == FDT_MAGIC
) &&
160 (ih
->ih_comp
== IH_COMP_GZIP
)) {
161 if (gunzip((void *)(spl_image
->load_addr
+ sizeof(*ih
)),
162 CONFIG_SYS_BOOTM_LEN
,
163 (void *)(CONFIG_SYS_LOAD_ADDR
+ sizeof(*ih
)),
165 puts("Uncompressing error\n");
173 SPL_LOAD_IMAGE_METHOD("UART", 0, BOOT_DEVICE_UART
, spl_ymodem_load_image
);