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