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