Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2 | /* |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 3 | * (C) Copyright 2000-2004 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Serial up- and download support |
| 9 | */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 10 | #include <command.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 11 | #include <console.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 12 | #include <cpu_func.h> |
Heinrich Schuchardt | a89adb0 | 2021-03-19 02:50:57 +0000 | [diff] [blame] | 13 | #include <efi_loader.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 14 | #include <env.h> |
Heinrich Schuchardt | a89adb0 | 2021-03-19 02:50:57 +0000 | [diff] [blame] | 15 | #include <exports.h> |
Tom Rini | 063c938 | 2022-07-23 13:05:03 -0400 | [diff] [blame] | 16 | #ifdef CONFIG_MTD_NOR_FLASH |
Simon Glass | a606ffc | 2019-12-28 10:44:40 -0700 | [diff] [blame] | 17 | #include <flash.h> |
Tom Rini | 063c938 | 2022-07-23 13:05:03 -0400 | [diff] [blame] | 18 | #endif |
Simon Glass | 85f1378 | 2019-12-28 10:45:03 -0700 | [diff] [blame] | 19 | #include <image.h> |
Marek Vasut | 4d2be38 | 2021-10-10 23:52:41 +0200 | [diff] [blame] | 20 | #include <lmb.h> |
Heinrich Schuchardt | a89adb0 | 2021-03-19 02:50:57 +0000 | [diff] [blame] | 21 | #include <mapmem.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 22 | #include <net.h> |
Heinrich Schuchardt | a89adb0 | 2021-03-19 02:50:57 +0000 | [diff] [blame] | 23 | #include <s_record.h> |
Simon Glass | 3673618 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 24 | #include <serial.h> |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 25 | #include <xyzModem.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 26 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 27 | #include <asm/global_data.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 28 | #include <linux/delay.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 29 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 31 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 32 | #if defined(CONFIG_CMD_LOADB) |
Angus Ainslie | f283bd0 | 2013-06-26 16:54:24 -0600 | [diff] [blame] | 33 | static ulong load_serial_ymodem(ulong offset, int mode); |
Wolfgang Denk | da91693 | 2006-05-02 00:11:25 +0200 | [diff] [blame] | 34 | #endif |
| 35 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 36 | #if defined(CONFIG_CMD_LOADS) |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 37 | static ulong load_serial(long offset); |
| 38 | static int read_record(char *buf, ulong len); |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 39 | # if defined(CONFIG_CMD_SAVES) |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 40 | static int save_serial(ulong offset, ulong size); |
| 41 | static int write_record(char *buf); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 42 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 43 | |
| 44 | static int do_echo = 1; |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 45 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 46 | |
| 47 | /* -------------------------------------------------------------------- */ |
| 48 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 49 | #if defined(CONFIG_CMD_LOADS) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 50 | static int do_load_serial(struct cmd_tbl *cmdtp, int flag, int argc, |
| 51 | char *const argv[]) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 52 | { |
Ricardo Ribalda Delgado | 9cde830 | 2008-07-30 12:39:29 +0200 | [diff] [blame] | 53 | long offset = 0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 54 | ulong addr; |
| 55 | int i; |
| 56 | char *env_echo; |
| 57 | int rcode = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 58 | #ifdef CONFIG_SYS_LOADS_BAUD_CHANGE |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 59 | int load_baudrate, current_baudrate; |
| 60 | |
| 61 | load_baudrate = current_baudrate = gd->baudrate; |
| 62 | #endif |
| 63 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 64 | env_echo = env_get("loads_echo"); |
| 65 | if (env_echo && *env_echo == '1') |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 66 | do_echo = 1; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 67 | else |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 68 | do_echo = 0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 69 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 70 | #ifdef CONFIG_SYS_LOADS_BAUD_CHANGE |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 71 | if (argc >= 2) { |
Ricardo Ribalda Delgado | 9cde830 | 2008-07-30 12:39:29 +0200 | [diff] [blame] | 72 | offset = simple_strtol(argv[1], NULL, 16); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 73 | } |
| 74 | if (argc == 3) { |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 75 | load_baudrate = (int)dectoul(argv[2], NULL); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 76 | |
| 77 | /* default to current baudrate */ |
| 78 | if (load_baudrate == 0) |
| 79 | load_baudrate = current_baudrate; |
| 80 | } |
| 81 | if (load_baudrate != current_baudrate) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 82 | printf("## Switch baudrate to %d bps and press ENTER ...\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 83 | load_baudrate); |
| 84 | udelay(50000); |
Pali Rohár | 8e67a8a | 2022-09-05 11:31:20 +0200 | [diff] [blame] | 85 | flush(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | gd->baudrate = load_baudrate; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 87 | serial_setbrg(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 88 | udelay(50000); |
| 89 | for (;;) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 90 | if (getchar() == '\r') |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 91 | break; |
| 92 | } |
| 93 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 94 | #else /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 95 | if (argc == 2) { |
Ricardo Ribalda Delgado | 9cde830 | 2008-07-30 12:39:29 +0200 | [diff] [blame] | 96 | offset = simple_strtol(argv[1], NULL, 16); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 97 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 98 | #endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 99 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 100 | printf("## Ready for S-Record download ...\n"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 101 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 102 | addr = load_serial(offset); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | * Gather any trailing characters (for instance, the ^D which |
| 106 | * is sent by 'cu' after sending a file), and give the |
| 107 | * box some time (100 * 1 ms) |
| 108 | */ |
| 109 | for (i=0; i<100; ++i) { |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 110 | if (tstc()) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 111 | getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 112 | } |
| 113 | udelay(1000); |
| 114 | } |
| 115 | |
| 116 | if (addr == ~0) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 117 | printf("## S-Record download aborted\n"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 118 | rcode = 1; |
| 119 | } else { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 120 | printf("## Start Addr = 0x%08lX\n", addr); |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 121 | image_load_addr = addr; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 124 | #ifdef CONFIG_SYS_LOADS_BAUD_CHANGE |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 125 | if (load_baudrate != current_baudrate) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 126 | printf("## Switch baudrate to %d bps and press ESC ...\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 127 | current_baudrate); |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 128 | udelay(50000); |
Pali Rohár | 8e67a8a | 2022-09-05 11:31:20 +0200 | [diff] [blame] | 129 | flush(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 130 | gd->baudrate = current_baudrate; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 131 | serial_setbrg(); |
| 132 | udelay(50000); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 133 | for (;;) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 134 | if (getchar() == 0x1B) /* ESC */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | break; |
| 136 | } |
| 137 | } |
| 138 | #endif |
| 139 | return rcode; |
| 140 | } |
| 141 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 142 | static ulong load_serial(long offset) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 143 | { |
| 144 | char record[SREC_MAXRECLEN + 1]; /* buffer for one S-Record */ |
| 145 | char binbuf[SREC_MAXBINLEN]; /* buffer for binary data */ |
| 146 | int binlen; /* no. of data bytes in S-Rec. */ |
| 147 | int type; /* return code for record type */ |
| 148 | ulong addr; /* load address from S-Record */ |
| 149 | ulong size; /* number of bytes transferred */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 150 | ulong store_addr; |
| 151 | ulong start_addr = ~0; |
| 152 | ulong end_addr = 0; |
| 153 | int line_count = 0; |
Marek Vasut | 4d2be38 | 2021-10-10 23:52:41 +0200 | [diff] [blame] | 154 | long ret; |
| 155 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 156 | lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 157 | |
| 158 | while (read_record(record, SREC_MAXRECLEN + 1) >= 0) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 159 | type = srec_decode(record, &binlen, &addr, binbuf); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 160 | |
| 161 | if (type < 0) { |
| 162 | return (~0); /* Invalid S-Record */ |
| 163 | } |
| 164 | |
| 165 | switch (type) { |
| 166 | case SREC_DATA2: |
| 167 | case SREC_DATA3: |
| 168 | case SREC_DATA4: |
| 169 | store_addr = addr + offset; |
Masahiro Yamada | 8cea9b5 | 2017-02-11 22:43:54 +0900 | [diff] [blame] | 170 | #ifdef CONFIG_MTD_NOR_FLASH |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 171 | if (addr2info(store_addr)) { |
| 172 | int rc; |
| 173 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 174 | rc = flash_write((char *)binbuf,store_addr,binlen); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 175 | if (rc != 0) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 176 | flash_perror(rc); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 177 | return (~0); |
| 178 | } |
| 179 | } else |
| 180 | #endif |
| 181 | { |
Heinrich Schuchardt | 604404b | 2023-06-25 11:54:23 +0200 | [diff] [blame] | 182 | void *dst; |
| 183 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 184 | ret = lmb_reserve(store_addr, binlen); |
Marek Vasut | 4d2be38 | 2021-10-10 23:52:41 +0200 | [diff] [blame] | 185 | if (ret) { |
| 186 | printf("\nCannot overwrite reserved area (%08lx..%08lx)\n", |
| 187 | store_addr, store_addr + binlen); |
| 188 | return ret; |
| 189 | } |
Heinrich Schuchardt | 604404b | 2023-06-25 11:54:23 +0200 | [diff] [blame] | 190 | dst = map_sysmem(store_addr, binlen); |
| 191 | memcpy(dst, binbuf, binlen); |
| 192 | unmap_sysmem(dst); |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 193 | lmb_free(store_addr, binlen); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 194 | } |
| 195 | if ((store_addr) < start_addr) |
| 196 | start_addr = store_addr; |
| 197 | if ((store_addr + binlen - 1) > end_addr) |
| 198 | end_addr = store_addr + binlen - 1; |
| 199 | break; |
| 200 | case SREC_END2: |
| 201 | case SREC_END3: |
| 202 | case SREC_END4: |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 203 | udelay(10000); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 204 | size = end_addr - start_addr + 1; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 205 | printf("\n" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 206 | "## First Load Addr = 0x%08lX\n" |
| 207 | "## Last Load Addr = 0x%08lX\n" |
| 208 | "## Total Size = 0x%08lX = %ld Bytes\n", |
| 209 | start_addr, end_addr, size, size |
| 210 | ); |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 211 | flush_cache(start_addr, size); |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 212 | env_set_hex("filesize", size); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 213 | return (addr); |
| 214 | case SREC_START: |
| 215 | break; |
| 216 | default: |
| 217 | break; |
| 218 | } |
| 219 | if (!do_echo) { /* print a '.' every 100 lines */ |
| 220 | if ((++line_count % 100) == 0) |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 221 | putc('.'); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | return (~0); /* Download aborted */ |
| 226 | } |
| 227 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 228 | static int read_record(char *buf, ulong len) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 229 | { |
| 230 | char *p; |
Tom Rini | 479f54a | 2024-01-09 17:57:16 -0500 | [diff] [blame] | 231 | int c; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 232 | |
| 233 | --len; /* always leave room for terminating '\0' byte */ |
| 234 | |
| 235 | for (p=buf; p < buf+len; ++p) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 236 | c = getchar(); /* read character */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 237 | if (do_echo) |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 238 | putc(c); /* ... and echo it */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 239 | |
| 240 | switch (c) { |
| 241 | case '\r': |
| 242 | case '\n': |
| 243 | *p = '\0'; |
| 244 | return (p - buf); |
| 245 | case '\0': |
| 246 | case 0x03: /* ^C - Control C */ |
| 247 | return (-1); |
| 248 | default: |
| 249 | *p = c; |
| 250 | } |
| 251 | |
Michal Simek | b6e8ba1 | 2020-12-01 13:58:28 +0100 | [diff] [blame] | 252 | /* Check for the console hangup (if any different from serial) */ |
| 253 | if (gd->jt->getc != getchar) { |
| 254 | if (ctrlc()) |
| 255 | return (-1); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 256 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /* line too long - truncate */ |
| 260 | *p = '\0'; |
| 261 | return (p - buf); |
| 262 | } |
| 263 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 264 | #if defined(CONFIG_CMD_SAVES) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 265 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 266 | int do_save_serial(struct cmd_tbl *cmdtp, int flag, int argc, |
| 267 | char *const argv[]) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 268 | { |
| 269 | ulong offset = 0; |
| 270 | ulong size = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 271 | #ifdef CONFIG_SYS_LOADS_BAUD_CHANGE |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 272 | int save_baudrate, current_baudrate; |
| 273 | |
| 274 | save_baudrate = current_baudrate = gd->baudrate; |
| 275 | #endif |
| 276 | |
| 277 | if (argc >= 2) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 278 | offset = hextoul(argv[1], NULL); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 279 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 280 | #ifdef CONFIG_SYS_LOADS_BAUD_CHANGE |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 281 | if (argc >= 3) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 282 | size = hextoul(argv[2], NULL); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 283 | } |
| 284 | if (argc == 4) { |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 285 | save_baudrate = (int)dectoul(argv[3], NULL); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 286 | |
| 287 | /* default to current baudrate */ |
| 288 | if (save_baudrate == 0) |
| 289 | save_baudrate = current_baudrate; |
| 290 | } |
| 291 | if (save_baudrate != current_baudrate) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 292 | printf("## Switch baudrate to %d bps and press ENTER ...\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 293 | save_baudrate); |
| 294 | udelay(50000); |
| 295 | gd->baudrate = save_baudrate; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 296 | serial_setbrg(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 297 | udelay(50000); |
| 298 | for (;;) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 299 | if (getchar() == '\r') |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 300 | break; |
| 301 | } |
| 302 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 303 | #else /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 304 | if (argc == 3) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 305 | size = hextoul(argv[2], NULL); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 306 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 307 | #endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 308 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 309 | printf("## Ready for S-Record upload, press ENTER to proceed ...\n"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 310 | for (;;) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 311 | if (getchar() == '\r') |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 312 | break; |
| 313 | } |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 314 | if (save_serial(offset, size)) { |
| 315 | printf("## S-Record upload aborted\n"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 316 | } else { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 317 | printf("## S-Record upload complete\n"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 318 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 319 | #ifdef CONFIG_SYS_LOADS_BAUD_CHANGE |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 320 | if (save_baudrate != current_baudrate) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 321 | printf("## Switch baudrate to %d bps and press ESC ...\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 322 | (int)current_baudrate); |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 323 | udelay(50000); |
Pali Rohár | 8e67a8a | 2022-09-05 11:31:20 +0200 | [diff] [blame] | 324 | flush(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 325 | gd->baudrate = current_baudrate; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 326 | serial_setbrg(); |
| 327 | udelay(50000); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 328 | for (;;) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 329 | if (getchar() == 0x1B) /* ESC */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 330 | break; |
| 331 | } |
| 332 | } |
| 333 | #endif |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | #define SREC3_START "S0030000FC\n" |
| 338 | #define SREC3_FORMAT "S3%02X%08lX%s%02X\n" |
| 339 | #define SREC3_END "S70500000000FA\n" |
| 340 | #define SREC_BYTES_PER_RECORD 16 |
| 341 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 342 | static int save_serial(ulong address, ulong count) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 343 | { |
| 344 | int i, c, reclen, checksum, length; |
| 345 | char *hex = "0123456789ABCDEF"; |
| 346 | char record[2*SREC_BYTES_PER_RECORD+16]; /* buffer for one S-Record */ |
| 347 | char data[2*SREC_BYTES_PER_RECORD+1]; /* buffer for hex data */ |
| 348 | |
| 349 | reclen = 0; |
| 350 | checksum = 0; |
| 351 | |
| 352 | if(write_record(SREC3_START)) /* write the header */ |
| 353 | return (-1); |
| 354 | do { |
Heinrich Schuchardt | 604404b | 2023-06-25 11:54:23 +0200 | [diff] [blame] | 355 | volatile uchar *src; |
| 356 | |
| 357 | src = map_sysmem(address, count); |
| 358 | if (count) { /* collect hex data in the buffer */ |
| 359 | c = src[reclen]; /* get one byte */ |
| 360 | checksum += c; /* accumulate checksum */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 361 | data[2*reclen] = hex[(c>>4)&0x0f]; |
| 362 | data[2*reclen+1] = hex[c & 0x0f]; |
| 363 | data[2*reclen+2] = '\0'; |
| 364 | ++reclen; |
| 365 | --count; |
| 366 | } |
Heinrich Schuchardt | 604404b | 2023-06-25 11:54:23 +0200 | [diff] [blame] | 367 | unmap_sysmem((void *)src); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 368 | if(reclen == SREC_BYTES_PER_RECORD || count == 0) { |
| 369 | /* enough data collected for one record: dump it */ |
| 370 | if(reclen) { /* build & write a data record: */ |
| 371 | /* address + data + checksum */ |
| 372 | length = 4 + reclen + 1; |
| 373 | |
| 374 | /* accumulate length bytes into checksum */ |
| 375 | for(i = 0; i < 2; i++) |
| 376 | checksum += (length >> (8*i)) & 0xff; |
| 377 | |
| 378 | /* accumulate address bytes into checksum: */ |
| 379 | for(i = 0; i < 4; i++) |
| 380 | checksum += (address >> (8*i)) & 0xff; |
| 381 | |
| 382 | /* make proper checksum byte: */ |
| 383 | checksum = ~checksum & 0xff; |
| 384 | |
| 385 | /* output one record: */ |
| 386 | sprintf(record, SREC3_FORMAT, length, address, data, checksum); |
| 387 | if(write_record(record)) |
| 388 | return (-1); |
| 389 | } |
| 390 | address += reclen; /* increment address */ |
| 391 | checksum = 0; |
| 392 | reclen = 0; |
| 393 | } |
| 394 | } |
| 395 | while(count); |
| 396 | if(write_record(SREC3_END)) /* write the final record */ |
| 397 | return (-1); |
| 398 | return(0); |
| 399 | } |
| 400 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 401 | static int write_record(char *buf) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 402 | { |
| 403 | char c; |
| 404 | |
| 405 | while((c = *buf++)) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 406 | putc(c); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 407 | |
| 408 | /* Check for the console hangup (if any different from serial) */ |
| 409 | |
| 410 | if (ctrlc()) { |
| 411 | return (-1); |
| 412 | } |
| 413 | return (0); |
| 414 | } |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 415 | # endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 416 | |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 417 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 418 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 419 | #if defined(CONFIG_CMD_LOADB) |
Jon Loeliger | 3de8b24 | 2007-06-11 19:01:54 -0500 | [diff] [blame] | 420 | /* |
| 421 | * loadb command (load binary) included |
| 422 | */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 423 | #define XON_CHAR 17 |
| 424 | #define XOFF_CHAR 19 |
| 425 | #define START_CHAR 0x01 |
| 426 | #define ETX_CHAR 0x03 |
| 427 | #define END_CHAR 0x0D |
| 428 | #define SPACE 0x20 |
| 429 | #define K_ESCAPE 0x23 |
| 430 | #define SEND_TYPE 'S' |
| 431 | #define DATA_TYPE 'D' |
| 432 | #define ACK_TYPE 'Y' |
| 433 | #define NACK_TYPE 'N' |
| 434 | #define BREAK_TYPE 'B' |
| 435 | #define tochar(x) ((char) (((x) + SPACE) & 0xff)) |
| 436 | #define untochar(x) ((int) (((x) - SPACE) & 0xff)) |
| 437 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 438 | static void set_kerm_bin_mode(unsigned long *); |
| 439 | static int k_recv(void); |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 440 | static ulong load_serial_bin(ulong offset); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 441 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 442 | static char his_eol; /* character he needs at end of packet */ |
| 443 | static int his_pad_count; /* number of pad chars he needs */ |
| 444 | static char his_pad_char; /* pad chars he needs */ |
| 445 | static char his_quote; /* quote chars he'll use */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 446 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 447 | static int do_load_serial_bin(struct cmd_tbl *cmdtp, int flag, int argc, |
| 448 | char *const argv[]) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 449 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 450 | ulong offset = 0; |
| 451 | ulong addr; |
| 452 | int load_baudrate, current_baudrate; |
| 453 | int rcode = 0; |
| 454 | char *s; |
| 455 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 456 | /* pre-set offset from CONFIG_SYS_LOAD_ADDR */ |
| 457 | offset = CONFIG_SYS_LOAD_ADDR; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 458 | |
| 459 | /* pre-set offset from $loadaddr */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 460 | s = env_get("loadaddr"); |
| 461 | if (s) |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 462 | offset = hextoul(s, NULL); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 463 | |
| 464 | load_baudrate = current_baudrate = gd->baudrate; |
| 465 | |
| 466 | if (argc >= 2) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 467 | offset = hextoul(argv[1], NULL); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 468 | } |
| 469 | if (argc == 3) { |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 470 | load_baudrate = (int)dectoul(argv[2], NULL); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 471 | |
| 472 | /* default to current baudrate */ |
| 473 | if (load_baudrate == 0) |
| 474 | load_baudrate = current_baudrate; |
| 475 | } |
| 476 | |
| 477 | if (load_baudrate != current_baudrate) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 478 | printf("## Switch baudrate to %d bps and press ENTER ...\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 479 | load_baudrate); |
| 480 | udelay(50000); |
Pali Rohár | 8e67a8a | 2022-09-05 11:31:20 +0200 | [diff] [blame] | 481 | flush(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 482 | gd->baudrate = load_baudrate; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 483 | serial_setbrg(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 484 | udelay(50000); |
| 485 | for (;;) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 486 | if (getchar() == '\r') |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 487 | break; |
| 488 | } |
| 489 | } |
| 490 | |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 491 | if (strcmp(argv[0],"loady")==0) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 492 | printf("## Ready for binary (ymodem) download " |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 493 | "to 0x%08lX at %d bps...\n", |
| 494 | offset, |
| 495 | load_baudrate); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 496 | |
Angus Ainslie | f283bd0 | 2013-06-26 16:54:24 -0600 | [diff] [blame] | 497 | addr = load_serial_ymodem(offset, xyzModem_ymodem); |
| 498 | |
Pali Rohár | e37155f | 2021-08-03 16:28:43 +0200 | [diff] [blame] | 499 | if (addr == ~0) { |
| 500 | image_load_addr = 0; |
| 501 | printf("## Binary (ymodem) download aborted\n"); |
| 502 | rcode = 1; |
| 503 | } else { |
| 504 | printf("## Start Addr = 0x%08lX\n", addr); |
| 505 | image_load_addr = addr; |
| 506 | } |
Angus Ainslie | f283bd0 | 2013-06-26 16:54:24 -0600 | [diff] [blame] | 507 | } else if (strcmp(argv[0],"loadx")==0) { |
| 508 | printf("## Ready for binary (xmodem) download " |
| 509 | "to 0x%08lX at %d bps...\n", |
| 510 | offset, |
| 511 | load_baudrate); |
| 512 | |
| 513 | addr = load_serial_ymodem(offset, xyzModem_xmodem); |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 514 | |
Pali Rohár | e37155f | 2021-08-03 16:28:43 +0200 | [diff] [blame] | 515 | if (addr == ~0) { |
| 516 | image_load_addr = 0; |
| 517 | printf("## Binary (xmodem) download aborted\n"); |
| 518 | rcode = 1; |
| 519 | } else { |
| 520 | printf("## Start Addr = 0x%08lX\n", addr); |
| 521 | image_load_addr = addr; |
| 522 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 523 | } else { |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 524 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 525 | printf("## Ready for binary (kermit) download " |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 526 | "to 0x%08lX at %d bps...\n", |
| 527 | offset, |
| 528 | load_baudrate); |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 529 | addr = load_serial_bin(offset); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 530 | |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 531 | if (addr == ~0) { |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 532 | image_load_addr = 0; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 533 | printf("## Binary (kermit) download aborted\n"); |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 534 | rcode = 1; |
| 535 | } else { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 536 | printf("## Start Addr = 0x%08lX\n", addr); |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 537 | image_load_addr = addr; |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 538 | } |
| 539 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 540 | if (load_baudrate != current_baudrate) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 541 | printf("## Switch baudrate to %d bps and press ESC ...\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 542 | current_baudrate); |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 543 | udelay(50000); |
Pali Rohár | 8e67a8a | 2022-09-05 11:31:20 +0200 | [diff] [blame] | 544 | flush(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 545 | gd->baudrate = current_baudrate; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 546 | serial_setbrg(); |
| 547 | udelay(50000); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 548 | for (;;) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 549 | if (getchar() == 0x1B) /* ESC */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 550 | break; |
| 551 | } |
| 552 | } |
| 553 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 554 | return rcode; |
| 555 | } |
| 556 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 557 | static ulong load_serial_bin(ulong offset) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 558 | { |
| 559 | int size, i; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 560 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 561 | set_kerm_bin_mode((ulong *) offset); |
| 562 | size = k_recv(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 563 | |
| 564 | /* |
| 565 | * Gather any trailing characters (for instance, the ^D which |
| 566 | * is sent by 'cu' after sending a file), and give the |
| 567 | * box some time (100 * 1 ms) |
| 568 | */ |
| 569 | for (i=0; i<100; ++i) { |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 570 | if (tstc()) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 571 | getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 572 | } |
| 573 | udelay(1000); |
| 574 | } |
| 575 | |
Pali Rohár | 8398dd3 | 2021-08-06 18:07:39 +0200 | [diff] [blame] | 576 | if (size == 0) |
| 577 | return ~0; /* Download aborted */ |
| 578 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 579 | flush_cache(offset, size); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 580 | |
| 581 | printf("## Total Size = 0x%08x = %d Bytes\n", size, size); |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 582 | env_set_hex("filesize", size); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 583 | |
| 584 | return offset; |
| 585 | } |
| 586 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 587 | static void send_pad(void) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 588 | { |
| 589 | int count = his_pad_count; |
| 590 | |
| 591 | while (count-- > 0) |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 592 | putc(his_pad_char); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | /* converts escaped kermit char to binary char */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 596 | static char ktrans(char in) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 597 | { |
| 598 | if ((in & 0x60) == 0x40) { |
| 599 | return (char) (in & ~0x40); |
| 600 | } else if ((in & 0x7f) == 0x3f) { |
| 601 | return (char) (in | 0x40); |
| 602 | } else |
| 603 | return in; |
| 604 | } |
| 605 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 606 | static int chk1(char *buffer) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 607 | { |
| 608 | int total = 0; |
| 609 | |
| 610 | while (*buffer) { |
| 611 | total += *buffer++; |
| 612 | } |
| 613 | return (int) ((total + ((total >> 6) & 0x03)) & 0x3f); |
| 614 | } |
| 615 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 616 | static void s1_sendpacket(char *packet) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 617 | { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 618 | send_pad(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 619 | while (*packet) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 620 | putc(*packet++); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
| 624 | static char a_b[24]; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 625 | static void send_ack(int n) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 626 | { |
| 627 | a_b[0] = START_CHAR; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 628 | a_b[1] = tochar(3); |
| 629 | a_b[2] = tochar(n); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 630 | a_b[3] = ACK_TYPE; |
| 631 | a_b[4] = '\0'; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 632 | a_b[4] = tochar(chk1(&a_b[1])); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 633 | a_b[5] = his_eol; |
| 634 | a_b[6] = '\0'; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 635 | s1_sendpacket(a_b); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 638 | static void send_nack(int n) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 639 | { |
| 640 | a_b[0] = START_CHAR; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 641 | a_b[1] = tochar(3); |
| 642 | a_b[2] = tochar(n); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 643 | a_b[3] = NACK_TYPE; |
| 644 | a_b[4] = '\0'; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 645 | a_b[4] = tochar(chk1(&a_b[1])); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 646 | a_b[5] = his_eol; |
| 647 | a_b[6] = '\0'; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 648 | s1_sendpacket(a_b); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 651 | static void (*os_data_init)(void); |
| 652 | static void (*os_data_char)(char new_char); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 653 | static int os_data_state, os_data_state_saved; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 654 | static char *os_data_addr, *os_data_addr_saved; |
| 655 | static char *bin_start_address; |
Gururaja Hebbar K R | b4d7eb2 | 2008-08-07 13:13:27 +0530 | [diff] [blame] | 656 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 657 | static void bin_data_init(void) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 658 | { |
| 659 | os_data_state = 0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 660 | os_data_addr = bin_start_address; |
| 661 | } |
Gururaja Hebbar K R | b4d7eb2 | 2008-08-07 13:13:27 +0530 | [diff] [blame] | 662 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 663 | static void os_data_save(void) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 664 | { |
| 665 | os_data_state_saved = os_data_state; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 666 | os_data_addr_saved = os_data_addr; |
| 667 | } |
Gururaja Hebbar K R | b4d7eb2 | 2008-08-07 13:13:27 +0530 | [diff] [blame] | 668 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 669 | static void os_data_restore(void) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 670 | { |
| 671 | os_data_state = os_data_state_saved; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 672 | os_data_addr = os_data_addr_saved; |
| 673 | } |
Gururaja Hebbar K R | b4d7eb2 | 2008-08-07 13:13:27 +0530 | [diff] [blame] | 674 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 675 | static void bin_data_char(char new_char) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 676 | { |
| 677 | switch (os_data_state) { |
| 678 | case 0: /* data */ |
| 679 | *os_data_addr++ = new_char; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 680 | break; |
| 681 | } |
| 682 | } |
Gururaja Hebbar K R | b4d7eb2 | 2008-08-07 13:13:27 +0530 | [diff] [blame] | 683 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 684 | static void set_kerm_bin_mode(unsigned long *addr) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 685 | { |
| 686 | bin_start_address = (char *) addr; |
| 687 | os_data_init = bin_data_init; |
| 688 | os_data_char = bin_data_char; |
| 689 | } |
| 690 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 691 | /* k_data_* simply handles the kermit escape translations */ |
| 692 | static int k_data_escape, k_data_escape_saved; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 693 | static void k_data_init(void) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 694 | { |
| 695 | k_data_escape = 0; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 696 | os_data_init(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 697 | } |
Gururaja Hebbar K R | b4d7eb2 | 2008-08-07 13:13:27 +0530 | [diff] [blame] | 698 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 699 | static void k_data_save(void) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 700 | { |
| 701 | k_data_escape_saved = k_data_escape; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 702 | os_data_save(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 703 | } |
Gururaja Hebbar K R | b4d7eb2 | 2008-08-07 13:13:27 +0530 | [diff] [blame] | 704 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 705 | static void k_data_restore(void) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 706 | { |
| 707 | k_data_escape = k_data_escape_saved; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 708 | os_data_restore(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 709 | } |
Gururaja Hebbar K R | b4d7eb2 | 2008-08-07 13:13:27 +0530 | [diff] [blame] | 710 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 711 | static void k_data_char(char new_char) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 712 | { |
| 713 | if (k_data_escape) { |
| 714 | /* last char was escape - translate this character */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 715 | os_data_char(ktrans(new_char)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 716 | k_data_escape = 0; |
| 717 | } else { |
| 718 | if (new_char == his_quote) { |
| 719 | /* this char is escape - remember */ |
| 720 | k_data_escape = 1; |
| 721 | } else { |
| 722 | /* otherwise send this char as-is */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 723 | os_data_char(new_char); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 724 | } |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | #define SEND_DATA_SIZE 20 |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 729 | static char send_parms[SEND_DATA_SIZE]; |
| 730 | static char *send_ptr; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 731 | |
| 732 | /* handle_send_packet interprits the protocol info and builds and |
| 733 | sends an appropriate ack for what we can do */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 734 | static void handle_send_packet(int n) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 735 | { |
| 736 | int length = 3; |
| 737 | int bytes; |
| 738 | |
| 739 | /* initialize some protocol parameters */ |
| 740 | his_eol = END_CHAR; /* default end of line character */ |
| 741 | his_pad_count = 0; |
| 742 | his_pad_char = '\0'; |
| 743 | his_quote = K_ESCAPE; |
| 744 | |
| 745 | /* ignore last character if it filled the buffer */ |
| 746 | if (send_ptr == &send_parms[SEND_DATA_SIZE - 1]) |
| 747 | --send_ptr; |
| 748 | bytes = send_ptr - send_parms; /* how many bytes we'll process */ |
| 749 | do { |
| 750 | if (bytes-- <= 0) |
| 751 | break; |
| 752 | /* handle MAXL - max length */ |
| 753 | /* ignore what he says - most I'll take (here) is 94 */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 754 | a_b[++length] = tochar(94); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 755 | if (bytes-- <= 0) |
| 756 | break; |
| 757 | /* handle TIME - time you should wait for my packets */ |
| 758 | /* ignore what he says - don't wait for my ack longer than 1 second */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 759 | a_b[++length] = tochar(1); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 760 | if (bytes-- <= 0) |
| 761 | break; |
| 762 | /* handle NPAD - number of pad chars I need */ |
| 763 | /* remember what he says - I need none */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 764 | his_pad_count = untochar(send_parms[2]); |
| 765 | a_b[++length] = tochar(0); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 766 | if (bytes-- <= 0) |
| 767 | break; |
| 768 | /* handle PADC - pad chars I need */ |
| 769 | /* remember what he says - I need none */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 770 | his_pad_char = ktrans(send_parms[3]); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 771 | a_b[++length] = 0x40; /* He should ignore this */ |
| 772 | if (bytes-- <= 0) |
| 773 | break; |
| 774 | /* handle EOL - end of line he needs */ |
| 775 | /* remember what he says - I need CR */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 776 | his_eol = untochar(send_parms[4]); |
| 777 | a_b[++length] = tochar(END_CHAR); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 778 | if (bytes-- <= 0) |
| 779 | break; |
| 780 | /* handle QCTL - quote control char he'll use */ |
| 781 | /* remember what he says - I'll use '#' */ |
| 782 | his_quote = send_parms[5]; |
| 783 | a_b[++length] = '#'; |
| 784 | if (bytes-- <= 0) |
| 785 | break; |
| 786 | /* handle QBIN - 8-th bit prefixing */ |
| 787 | /* ignore what he says - I refuse */ |
| 788 | a_b[++length] = 'N'; |
| 789 | if (bytes-- <= 0) |
| 790 | break; |
| 791 | /* handle CHKT - the clock check type */ |
| 792 | /* ignore what he says - I do type 1 (for now) */ |
| 793 | a_b[++length] = '1'; |
| 794 | if (bytes-- <= 0) |
| 795 | break; |
| 796 | /* handle REPT - the repeat prefix */ |
| 797 | /* ignore what he says - I refuse (for now) */ |
| 798 | a_b[++length] = 'N'; |
| 799 | if (bytes-- <= 0) |
| 800 | break; |
| 801 | /* handle CAPAS - the capabilities mask */ |
| 802 | /* ignore what he says - I only do long packets - I don't do windows */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 803 | a_b[++length] = tochar(2); /* only long packets */ |
| 804 | a_b[++length] = tochar(0); /* no windows */ |
| 805 | a_b[++length] = tochar(94); /* large packet msb */ |
| 806 | a_b[++length] = tochar(94); /* large packet lsb */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 807 | } while (0); |
| 808 | |
| 809 | a_b[0] = START_CHAR; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 810 | a_b[1] = tochar(length); |
| 811 | a_b[2] = tochar(n); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 812 | a_b[3] = ACK_TYPE; |
| 813 | a_b[++length] = '\0'; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 814 | a_b[length] = tochar(chk1(&a_b[1])); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 815 | a_b[++length] = his_eol; |
| 816 | a_b[++length] = '\0'; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 817 | s1_sendpacket(a_b); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /* k_recv receives a OS Open image file over kermit line */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 821 | static int k_recv(void) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 822 | { |
Tom Rini | 479f54a | 2024-01-09 17:57:16 -0500 | [diff] [blame] | 823 | int new_char; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 824 | char k_state, k_state_saved; |
| 825 | int sum; |
| 826 | int done; |
| 827 | int length; |
| 828 | int n, last_n; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 829 | int len_lo, len_hi; |
| 830 | |
| 831 | /* initialize some protocol parameters */ |
| 832 | his_eol = END_CHAR; /* default end of line character */ |
| 833 | his_pad_count = 0; |
| 834 | his_pad_char = '\0'; |
| 835 | his_quote = K_ESCAPE; |
| 836 | |
| 837 | /* initialize the k_recv and k_data state machine */ |
| 838 | done = 0; |
| 839 | k_state = 0; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 840 | k_data_init(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 841 | k_state_saved = k_state; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 842 | k_data_save(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 843 | n = 0; /* just to get rid of a warning */ |
| 844 | last_n = -1; |
| 845 | |
| 846 | /* expect this "type" sequence (but don't check): |
| 847 | S: send initiate |
| 848 | F: file header |
| 849 | D: data (multiple) |
| 850 | Z: end of file |
| 851 | B: break transmission |
| 852 | */ |
| 853 | |
| 854 | /* enter main loop */ |
| 855 | while (!done) { |
| 856 | /* set the send packet pointer to begining of send packet parms */ |
| 857 | send_ptr = send_parms; |
| 858 | |
| 859 | /* With each packet, start summing the bytes starting with the length. |
| 860 | Save the current sequence number. |
| 861 | Note the type of the packet. |
| 862 | If a character less than SPACE (0x20) is received - error. |
| 863 | */ |
| 864 | |
| 865 | #if 0 |
| 866 | /* OLD CODE, Prior to checking sequence numbers */ |
| 867 | /* first have all state machines save current states */ |
| 868 | k_state_saved = k_state; |
| 869 | k_data_save (); |
| 870 | #endif |
| 871 | |
| 872 | /* get a packet */ |
| 873 | /* wait for the starting character or ^C */ |
| 874 | for (;;) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 875 | switch (getchar()) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 876 | case START_CHAR: /* start packet */ |
| 877 | goto START; |
| 878 | case ETX_CHAR: /* ^C waiting for packet */ |
| 879 | return (0); |
| 880 | default: |
| 881 | ; |
| 882 | } |
| 883 | } |
| 884 | START: |
| 885 | /* get length of packet */ |
| 886 | sum = 0; |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 887 | new_char = getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 888 | if ((new_char & 0xE0) == 0) |
| 889 | goto packet_error; |
| 890 | sum += new_char & 0xff; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 891 | length = untochar(new_char); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 892 | /* get sequence number */ |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 893 | new_char = getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 894 | if ((new_char & 0xE0) == 0) |
| 895 | goto packet_error; |
| 896 | sum += new_char & 0xff; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 897 | n = untochar(new_char); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 898 | --length; |
| 899 | |
| 900 | /* NEW CODE - check sequence numbers for retried packets */ |
| 901 | /* Note - this new code assumes that the sequence number is correctly |
| 902 | * received. Handling an invalid sequence number adds another layer |
| 903 | * of complexity that may not be needed - yet! At this time, I'm hoping |
| 904 | * that I don't need to buffer the incoming data packets and can write |
| 905 | * the data into memory in real time. |
| 906 | */ |
| 907 | if (n == last_n) { |
| 908 | /* same sequence number, restore the previous state */ |
| 909 | k_state = k_state_saved; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 910 | k_data_restore(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 911 | } else { |
| 912 | /* new sequence number, checkpoint the download */ |
| 913 | last_n = n; |
| 914 | k_state_saved = k_state; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 915 | k_data_save(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 916 | } |
| 917 | /* END NEW CODE */ |
| 918 | |
| 919 | /* get packet type */ |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 920 | new_char = getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 921 | if ((new_char & 0xE0) == 0) |
| 922 | goto packet_error; |
| 923 | sum += new_char & 0xff; |
| 924 | k_state = new_char; |
| 925 | --length; |
| 926 | /* check for extended length */ |
| 927 | if (length == -2) { |
| 928 | /* (length byte was 0, decremented twice) */ |
| 929 | /* get the two length bytes */ |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 930 | new_char = getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 931 | if ((new_char & 0xE0) == 0) |
| 932 | goto packet_error; |
| 933 | sum += new_char & 0xff; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 934 | len_hi = untochar(new_char); |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 935 | new_char = getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 936 | if ((new_char & 0xE0) == 0) |
| 937 | goto packet_error; |
| 938 | sum += new_char & 0xff; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 939 | len_lo = untochar(new_char); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 940 | length = len_hi * 95 + len_lo; |
| 941 | /* check header checksum */ |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 942 | new_char = getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 943 | if ((new_char & 0xE0) == 0) |
| 944 | goto packet_error; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 945 | if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f)) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 946 | goto packet_error; |
| 947 | sum += new_char & 0xff; |
| 948 | /* --length; */ /* new length includes only data and block check to come */ |
| 949 | } |
| 950 | /* bring in rest of packet */ |
| 951 | while (length > 1) { |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 952 | new_char = getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 953 | if ((new_char & 0xE0) == 0) |
| 954 | goto packet_error; |
| 955 | sum += new_char & 0xff; |
| 956 | --length; |
| 957 | if (k_state == DATA_TYPE) { |
| 958 | /* pass on the data if this is a data packet */ |
| 959 | k_data_char (new_char); |
| 960 | } else if (k_state == SEND_TYPE) { |
| 961 | /* save send pack in buffer as is */ |
| 962 | *send_ptr++ = new_char; |
| 963 | /* if too much data, back off the pointer */ |
| 964 | if (send_ptr >= &send_parms[SEND_DATA_SIZE]) |
| 965 | --send_ptr; |
| 966 | } |
| 967 | } |
| 968 | /* get and validate checksum character */ |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 969 | new_char = getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 970 | if ((new_char & 0xE0) == 0) |
| 971 | goto packet_error; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 972 | if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f)) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 973 | goto packet_error; |
| 974 | /* get END_CHAR */ |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 975 | new_char = getchar(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 976 | if (new_char != END_CHAR) { |
| 977 | packet_error: |
| 978 | /* restore state machines */ |
| 979 | k_state = k_state_saved; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 980 | k_data_restore(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 981 | /* send a negative acknowledge packet in */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 982 | send_nack(n); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 983 | } else if (k_state == SEND_TYPE) { |
| 984 | /* crack the protocol parms, build an appropriate ack packet */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 985 | handle_send_packet(n); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 986 | } else { |
| 987 | /* send simple acknowledge packet in */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 988 | send_ack(n); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 989 | /* quit if end of transmission */ |
| 990 | if (k_state == BREAK_TYPE) |
| 991 | done = 1; |
| 992 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 993 | } |
| 994 | return ((ulong) os_data_addr - (ulong) bin_start_address); |
| 995 | } |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 996 | |
| 997 | static int getcxmodem(void) { |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 998 | if (tstc()) |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 999 | return (getchar()); |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1000 | return -1; |
| 1001 | } |
Angus Ainslie | f283bd0 | 2013-06-26 16:54:24 -0600 | [diff] [blame] | 1002 | static ulong load_serial_ymodem(ulong offset, int mode) |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1003 | { |
| 1004 | int size; |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1005 | int err; |
| 1006 | int res; |
| 1007 | connection_info_t info; |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1008 | char ymodemBuf[1024]; |
| 1009 | ulong store_addr = ~0; |
| 1010 | ulong addr = 0; |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1011 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1012 | size = 0; |
Angus Ainslie | f283bd0 | 2013-06-26 16:54:24 -0600 | [diff] [blame] | 1013 | info.mode = mode; |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1014 | res = xyzModem_stream_open(&info, &err); |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1015 | if (!res) { |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1016 | |
Pali Rohár | b6f177b | 2021-08-03 16:28:42 +0200 | [diff] [blame] | 1017 | err = 0; |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1018 | while ((res = |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1019 | xyzModem_stream_read(ymodemBuf, 1024, &err)) > 0) { |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1020 | store_addr = addr + offset; |
| 1021 | size += res; |
| 1022 | addr += res; |
Masahiro Yamada | 8cea9b5 | 2017-02-11 22:43:54 +0900 | [diff] [blame] | 1023 | #ifdef CONFIG_MTD_NOR_FLASH |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1024 | if (addr2info(store_addr)) { |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1025 | int rc; |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1026 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1027 | rc = flash_write((char *) ymodemBuf, |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1028 | store_addr, res); |
| 1029 | if (rc != 0) { |
Pali Rohár | b6f177b | 2021-08-03 16:28:42 +0200 | [diff] [blame] | 1030 | xyzModem_stream_terminate(true, &getcxmodem); |
| 1031 | xyzModem_stream_close(&err); |
| 1032 | printf("\n"); |
Simon Glass | a606ffc | 2019-12-28 10:44:40 -0700 | [diff] [blame] | 1033 | flash_perror(rc); |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1034 | return (~0); |
| 1035 | } |
| 1036 | } else |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1037 | #endif |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1038 | { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1039 | memcpy((char *)(store_addr), ymodemBuf, |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1040 | res); |
| 1041 | } |
| 1042 | |
| 1043 | } |
Pali Rohár | b6f177b | 2021-08-03 16:28:42 +0200 | [diff] [blame] | 1044 | if (err) { |
| 1045 | xyzModem_stream_terminate((err == xyzModem_cancel) ? false : true, &getcxmodem); |
| 1046 | xyzModem_stream_close(&err); |
| 1047 | printf("\n%s\n", xyzModem_error(err)); |
| 1048 | return (~0); /* Download aborted */ |
| 1049 | } |
| 1050 | |
Heinrich Schuchardt | a89adb0 | 2021-03-19 02:50:57 +0000 | [diff] [blame] | 1051 | if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) |
| 1052 | efi_set_bootdev("Uart", "", "", |
| 1053 | map_sysmem(offset, 0), size); |
| 1054 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1055 | } else { |
Pali Rohár | b6f177b | 2021-08-03 16:28:42 +0200 | [diff] [blame] | 1056 | printf("\n%s\n", xyzModem_error(err)); |
| 1057 | return (~0); /* Download aborted */ |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1058 | } |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1059 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1060 | xyzModem_stream_terminate(false, &getcxmodem); |
Pali Rohár | d9c805e | 2021-08-03 16:28:41 +0200 | [diff] [blame] | 1061 | xyzModem_stream_close(&err); |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 1062 | |
Chris Packham | bbaf424 | 2016-10-25 20:22:48 +1300 | [diff] [blame] | 1063 | flush_cache(offset, ALIGN(size, ARCH_DMA_MINALIGN)); |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1064 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1065 | printf("## Total Size = 0x%08x = %d Bytes\n", size, size); |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 1066 | env_set_hex("filesize", size); |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1067 | |
| 1068 | return offset; |
| 1069 | } |
| 1070 | |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 1071 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1072 | |
Rui Miguel Silva | 433f15a | 2022-05-11 10:55:40 +0100 | [diff] [blame] | 1073 | #if defined(CONFIG_CMD_LOADM) |
| 1074 | static int do_load_memory_bin(struct cmd_tbl *cmdtp, int flag, int argc, |
| 1075 | char *const argv[]) |
| 1076 | { |
| 1077 | ulong addr, dest, size; |
| 1078 | void *src, *dst; |
| 1079 | |
| 1080 | if (argc != 4) |
| 1081 | return CMD_RET_USAGE; |
| 1082 | |
| 1083 | addr = simple_strtoul(argv[1], NULL, 16); |
| 1084 | |
| 1085 | dest = simple_strtoul(argv[2], NULL, 16); |
| 1086 | |
| 1087 | size = simple_strtoul(argv[3], NULL, 16); |
| 1088 | |
| 1089 | if (!size) { |
| 1090 | printf("loadm: can not load zero bytes\n"); |
| 1091 | return 1; |
| 1092 | } |
| 1093 | |
| 1094 | src = map_sysmem(addr, size); |
| 1095 | dst = map_sysmem(dest, size); |
| 1096 | |
| 1097 | memcpy(dst, src, size); |
| 1098 | |
| 1099 | unmap_sysmem(src); |
| 1100 | unmap_sysmem(dst); |
| 1101 | |
| 1102 | if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) |
| 1103 | efi_set_bootdev("Mem", "", "", map_sysmem(dest, 0), size); |
| 1104 | |
| 1105 | printf("loaded bin to memory: size: %lu\n", size); |
| 1106 | |
| 1107 | return 0; |
| 1108 | } |
| 1109 | #endif |
| 1110 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1111 | /* -------------------------------------------------------------------- */ |
| 1112 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 1113 | #if defined(CONFIG_CMD_LOADS) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1114 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1115 | #ifdef CONFIG_SYS_LOADS_BAUD_CHANGE |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1116 | U_BOOT_CMD( |
| 1117 | loads, 3, 0, do_load_serial, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1118 | "load S-Record file over serial line", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1119 | "[ off ] [ baud ]\n" |
| 1120 | " - load S-Record file over serial line" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1121 | " with offset 'off' and baudrate 'baud'" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1122 | ); |
| 1123 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1124 | #else /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */ |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1125 | U_BOOT_CMD( |
| 1126 | loads, 2, 0, do_load_serial, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1127 | "load S-Record file over serial line", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1128 | "[ off ]\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1129 | " - load S-Record file over serial line with offset 'off'" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1130 | ); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1131 | #endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1132 | |
| 1133 | /* |
| 1134 | * SAVES always requires LOADS support, but not vice versa |
| 1135 | */ |
| 1136 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 1137 | #if defined(CONFIG_CMD_SAVES) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1138 | #ifdef CONFIG_SYS_LOADS_BAUD_CHANGE |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1139 | U_BOOT_CMD( |
| 1140 | saves, 4, 0, do_save_serial, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1141 | "save S-Record file over serial line", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1142 | "[ off ] [size] [ baud ]\n" |
| 1143 | " - save S-Record file over serial line" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1144 | " with offset 'off', size 'size' and baudrate 'baud'" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1145 | ); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1146 | #else /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */ |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1147 | U_BOOT_CMD( |
| 1148 | saves, 3, 0, do_save_serial, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1149 | "save S-Record file over serial line", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1150 | "[ off ] [size]\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1151 | " - save S-Record file over serial line with offset 'off' and size 'size'" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1152 | ); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1153 | #endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */ |
Robert P. J. Day | aec64f0 | 2013-02-03 05:46:13 +0000 | [diff] [blame] | 1154 | #endif /* CONFIG_CMD_SAVES */ |
| 1155 | #endif /* CONFIG_CMD_LOADS */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1156 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 1157 | #if defined(CONFIG_CMD_LOADB) |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1158 | U_BOOT_CMD( |
| 1159 | loadb, 3, 0, do_load_serial_bin, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1160 | "load binary file over serial line (kermit mode)", |
Heinrich Schuchardt | cd373b5 | 2021-01-22 13:16:04 +0100 | [diff] [blame] | 1161 | "[ addr [ baud ] ]\n" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1162 | " - load binary file over serial line" |
Heinrich Schuchardt | cd373b5 | 2021-01-22 13:16:04 +0100 | [diff] [blame] | 1163 | " at address 'addr' with baudrate 'baud'" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1164 | ); |
| 1165 | |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1166 | U_BOOT_CMD( |
Angus Ainslie | f283bd0 | 2013-06-26 16:54:24 -0600 | [diff] [blame] | 1167 | loadx, 3, 0, do_load_serial_bin, |
| 1168 | "load binary file over serial line (xmodem mode)", |
Heinrich Schuchardt | cd373b5 | 2021-01-22 13:16:04 +0100 | [diff] [blame] | 1169 | "[ addr [ baud ] ]\n" |
Angus Ainslie | f283bd0 | 2013-06-26 16:54:24 -0600 | [diff] [blame] | 1170 | " - load binary file over serial line" |
Heinrich Schuchardt | cd373b5 | 2021-01-22 13:16:04 +0100 | [diff] [blame] | 1171 | " at address 'addr' with baudrate 'baud'" |
Angus Ainslie | f283bd0 | 2013-06-26 16:54:24 -0600 | [diff] [blame] | 1172 | ); |
| 1173 | |
| 1174 | U_BOOT_CMD( |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1175 | loady, 3, 0, do_load_serial_bin, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1176 | "load binary file over serial line (ymodem mode)", |
Heinrich Schuchardt | cd373b5 | 2021-01-22 13:16:04 +0100 | [diff] [blame] | 1177 | "[ addr [ baud ] ]\n" |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1178 | " - load binary file over serial line" |
Heinrich Schuchardt | cd373b5 | 2021-01-22 13:16:04 +0100 | [diff] [blame] | 1179 | " at address 'addr' with baudrate 'baud'" |
Markus Klotzbuecher | 387f541 | 2006-03-30 13:40:55 +0200 | [diff] [blame] | 1180 | ); |
| 1181 | |
Robert P. J. Day | aec64f0 | 2013-02-03 05:46:13 +0000 | [diff] [blame] | 1182 | #endif /* CONFIG_CMD_LOADB */ |
Rui Miguel Silva | 433f15a | 2022-05-11 10:55:40 +0100 | [diff] [blame] | 1183 | |
| 1184 | #if defined(CONFIG_CMD_LOADM) |
| 1185 | U_BOOT_CMD( |
| 1186 | loadm, 4, 0, do_load_memory_bin, |
| 1187 | "load binary blob from source address to destination address", |
| 1188 | "[src_addr] [dst_addr] [size]\n" |
| 1189 | " - load a binary blob from one memory location to other" |
| 1190 | " from src_addr to dst_addr by size bytes" |
| 1191 | ); |
| 1192 | #endif /* CONFIG_CMD_LOADM */ |