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