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