wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Memory Functions |
| 10 | * |
| 11 | * Copied from FADS ROM, Dan Malek (dmalek@jlc.net) |
| 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 15 | #include <console.h> |
Simon Glass | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 16 | #include <bootretry.h> |
Simon Glass | dec3c01 | 2014-04-10 20:01:25 -0600 | [diff] [blame] | 17 | #include <cli.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 18 | #include <command.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 19 | #include <console.h> |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 20 | #ifdef CONFIG_HAS_DATAFLASH |
| 21 | #include <dataflash.h> |
| 22 | #endif |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 23 | #include <hash.h> |
Simon Glass | e9f343f | 2014-11-11 12:47:07 -0700 | [diff] [blame] | 24 | #include <inttypes.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 25 | #include <mapmem.h> |
Sergei Poselenov | 474dbb8 | 2008-04-09 16:09:41 +0200 | [diff] [blame] | 26 | #include <watchdog.h> |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 27 | #include <asm/io.h> |
Simon Glass | eacd14f | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 28 | #include <linux/compiler.h> |
| 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 31 | |
Simon Glass | 1c6c725 | 2013-02-24 17:33:29 +0000 | [diff] [blame] | 32 | #ifndef CONFIG_SYS_MEMTEST_SCRATCH |
| 33 | #define CONFIG_SYS_MEMTEST_SCRATCH 0 |
| 34 | #endif |
| 35 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 36 | static int mod_mem(cmd_tbl_t *, int, int, int, char * const []); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 37 | |
| 38 | /* Display values from last command. |
| 39 | * Memory modify remembered values are different from display memory. |
| 40 | */ |
Scott Wood | 3ec0288 | 2015-03-19 09:43:12 -0700 | [diff] [blame] | 41 | static ulong dp_last_addr, dp_last_size; |
| 42 | static ulong dp_last_length = 0x40; |
| 43 | static ulong mm_last_addr, mm_last_size; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 44 | |
| 45 | static ulong base_address = 0; |
| 46 | |
| 47 | /* Memory Display |
| 48 | * |
| 49 | * Syntax: |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 50 | * md{.b, .w, .l, .q} {addr} {len} |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 51 | */ |
| 52 | #define DISP_LINE_LEN 16 |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 53 | static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 54 | { |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 55 | ulong addr, length; |
Grant Likely | 02a0078 | 2007-02-20 09:05:00 +0100 | [diff] [blame] | 56 | #if defined(CONFIG_HAS_DATAFLASH) |
| 57 | ulong nbytes, linebytes; |
| 58 | #endif |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 59 | int size; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 60 | int rc = 0; |
| 61 | |
| 62 | /* We use the last specified parameters, unless new ones are |
| 63 | * entered. |
| 64 | */ |
| 65 | addr = dp_last_addr; |
| 66 | size = dp_last_size; |
| 67 | length = dp_last_length; |
| 68 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 69 | if (argc < 2) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 70 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 71 | |
| 72 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 73 | /* New command specified. Check for a size specification. |
| 74 | * Defaults to long if no or incorrect specification. |
| 75 | */ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 76 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 77 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 78 | |
| 79 | /* Address is specified since argc > 1 |
| 80 | */ |
| 81 | addr = simple_strtoul(argv[1], NULL, 16); |
| 82 | addr += base_address; |
| 83 | |
| 84 | /* If another parameter, it is the length to display. |
| 85 | * Length is the number of objects, not number of bytes. |
| 86 | */ |
| 87 | if (argc > 2) |
| 88 | length = simple_strtoul(argv[2], NULL, 16); |
| 89 | } |
| 90 | |
Grant Likely | 02a0078 | 2007-02-20 09:05:00 +0100 | [diff] [blame] | 91 | #if defined(CONFIG_HAS_DATAFLASH) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 92 | /* Print the lines. |
| 93 | * |
| 94 | * We buffer all read data, so we can make sure data is read only |
| 95 | * once, and all accesses are with the specified bus width. |
| 96 | */ |
| 97 | nbytes = length * size; |
| 98 | do { |
| 99 | char linebuf[DISP_LINE_LEN]; |
Grant Likely | 02a0078 | 2007-02-20 09:05:00 +0100 | [diff] [blame] | 100 | void* p; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 101 | linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes; |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 102 | |
Grant Likely | 02a0078 | 2007-02-20 09:05:00 +0100 | [diff] [blame] | 103 | rc = read_dataflash(addr, (linebytes/size)*size, linebuf); |
| 104 | p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr; |
| 105 | print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 106 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 107 | nbytes -= linebytes; |
Grant Likely | 02a0078 | 2007-02-20 09:05:00 +0100 | [diff] [blame] | 108 | addr += linebytes; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 109 | if (ctrlc()) { |
| 110 | rc = 1; |
| 111 | break; |
| 112 | } |
| 113 | } while (nbytes > 0); |
Grant Likely | 02a0078 | 2007-02-20 09:05:00 +0100 | [diff] [blame] | 114 | #else |
Mike Frysinger | e578d68 | 2008-02-04 19:26:56 -0500 | [diff] [blame] | 115 | { |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 116 | ulong bytes = size * length; |
| 117 | const void *buf = map_sysmem(addr, bytes); |
| 118 | |
Mike Frysinger | e578d68 | 2008-02-04 19:26:56 -0500 | [diff] [blame] | 119 | /* Print the lines. */ |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 120 | print_buffer(addr, buf, size, length, DISP_LINE_LEN / size); |
| 121 | addr += bytes; |
| 122 | unmap_sysmem(buf); |
Mike Frysinger | e578d68 | 2008-02-04 19:26:56 -0500 | [diff] [blame] | 123 | } |
Grant Likely | 02a0078 | 2007-02-20 09:05:00 +0100 | [diff] [blame] | 124 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 125 | |
| 126 | dp_last_addr = addr; |
| 127 | dp_last_length = length; |
| 128 | dp_last_size = size; |
| 129 | return (rc); |
| 130 | } |
| 131 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 132 | static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 133 | { |
| 134 | return mod_mem (cmdtp, 1, flag, argc, argv); |
| 135 | } |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 136 | static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 137 | { |
| 138 | return mod_mem (cmdtp, 0, flag, argc, argv); |
| 139 | } |
| 140 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 141 | static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 142 | { |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 143 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 144 | u64 writeval; |
| 145 | #else |
| 146 | ulong writeval; |
| 147 | #endif |
| 148 | ulong addr, count; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 149 | int size; |
Simon Glass | 3c4a287 | 2015-03-05 12:25:18 -0700 | [diff] [blame] | 150 | void *buf, *start; |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 151 | ulong bytes; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 152 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 153 | if ((argc < 3) || (argc > 4)) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 154 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 155 | |
| 156 | /* Check for size specification. |
| 157 | */ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 158 | if ((size = cmd_get_data_size(argv[0], 4)) < 1) |
| 159 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 160 | |
| 161 | /* Address is specified since argc > 1 |
| 162 | */ |
| 163 | addr = simple_strtoul(argv[1], NULL, 16); |
| 164 | addr += base_address; |
| 165 | |
| 166 | /* Get the value to write. |
| 167 | */ |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 168 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 169 | writeval = simple_strtoull(argv[2], NULL, 16); |
| 170 | #else |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 171 | writeval = simple_strtoul(argv[2], NULL, 16); |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 172 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 173 | |
| 174 | /* Count ? */ |
| 175 | if (argc == 4) { |
| 176 | count = simple_strtoul(argv[3], NULL, 16); |
| 177 | } else { |
| 178 | count = 1; |
| 179 | } |
| 180 | |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 181 | bytes = size * count; |
Simon Glass | 3c4a287 | 2015-03-05 12:25:18 -0700 | [diff] [blame] | 182 | start = map_sysmem(addr, bytes); |
| 183 | buf = start; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 184 | while (count-- > 0) { |
| 185 | if (size == 4) |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 186 | *((u32 *)buf) = (u32)writeval; |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 187 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 188 | else if (size == 8) |
| 189 | *((u64 *)buf) = (u64)writeval; |
| 190 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 191 | else if (size == 2) |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 192 | *((u16 *)buf) = (u16)writeval; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 193 | else |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 194 | *((u8 *)buf) = (u8)writeval; |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 195 | buf += size; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 196 | } |
Simon Glass | 3c4a287 | 2015-03-05 12:25:18 -0700 | [diff] [blame] | 197 | unmap_sysmem(start); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
stroese | fb5e0ac | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 201 | #ifdef CONFIG_MX_CYCLIC |
Masahiro Yamada | 0b2f331 | 2014-09-04 00:38:26 +0900 | [diff] [blame] | 202 | static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
stroese | fb5e0ac | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 203 | { |
| 204 | int i; |
| 205 | ulong count; |
| 206 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 207 | if (argc < 4) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 208 | return CMD_RET_USAGE; |
stroese | fb5e0ac | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 209 | |
| 210 | count = simple_strtoul(argv[3], NULL, 10); |
| 211 | |
| 212 | for (;;) { |
| 213 | do_mem_md (NULL, 0, 3, argv); |
| 214 | |
| 215 | /* delay for <count> ms... */ |
| 216 | for (i=0; i<count; i++) |
| 217 | udelay (1000); |
| 218 | |
| 219 | /* check for ctrl-c to abort... */ |
| 220 | if (ctrlc()) { |
| 221 | puts("Abort\n"); |
| 222 | return 0; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
Masahiro Yamada | 0b2f331 | 2014-09-04 00:38:26 +0900 | [diff] [blame] | 229 | static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
stroese | fb5e0ac | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 230 | { |
| 231 | int i; |
| 232 | ulong count; |
| 233 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 234 | if (argc < 4) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 235 | return CMD_RET_USAGE; |
stroese | fb5e0ac | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 236 | |
| 237 | count = simple_strtoul(argv[3], NULL, 10); |
| 238 | |
| 239 | for (;;) { |
| 240 | do_mem_mw (NULL, 0, 3, argv); |
| 241 | |
| 242 | /* delay for <count> ms... */ |
| 243 | for (i=0; i<count; i++) |
| 244 | udelay (1000); |
| 245 | |
| 246 | /* check for ctrl-c to abort... */ |
| 247 | if (ctrlc()) { |
| 248 | puts("Abort\n"); |
| 249 | return 0; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | #endif /* CONFIG_MX_CYCLIC */ |
| 256 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 257 | static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 258 | { |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 259 | ulong addr1, addr2, count, ngood, bytes; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 260 | int size; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 261 | int rcode = 0; |
Mike Frysinger | 62a7ea7 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 262 | const char *type; |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 263 | const void *buf1, *buf2, *base; |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 264 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 265 | u64 word1, word2; |
| 266 | #else |
| 267 | ulong word1, word2; |
| 268 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 269 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 270 | if (argc != 4) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 271 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 272 | |
| 273 | /* Check for size specification. |
| 274 | */ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 275 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 276 | return 1; |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 277 | type = size == 8 ? "double word" : |
| 278 | size == 4 ? "word" : |
| 279 | size == 2 ? "halfword" : "byte"; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 280 | |
| 281 | addr1 = simple_strtoul(argv[1], NULL, 16); |
| 282 | addr1 += base_address; |
| 283 | |
| 284 | addr2 = simple_strtoul(argv[2], NULL, 16); |
| 285 | addr2 += base_address; |
| 286 | |
| 287 | count = simple_strtoul(argv[3], NULL, 16); |
| 288 | |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 289 | #ifdef CONFIG_HAS_DATAFLASH |
| 290 | if (addr_dataflash(addr1) | addr_dataflash(addr2)){ |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 291 | puts ("Comparison with DataFlash space not supported.\n\r"); |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | #endif |
| 295 | |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 296 | bytes = size * count; |
| 297 | base = buf1 = map_sysmem(addr1, bytes); |
| 298 | buf2 = map_sysmem(addr2, bytes); |
Mike Frysinger | a66afbd | 2012-01-20 09:07:22 +0000 | [diff] [blame] | 299 | for (ngood = 0; ngood < count; ++ngood) { |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 300 | if (size == 4) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 301 | word1 = *(u32 *)buf1; |
| 302 | word2 = *(u32 *)buf2; |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 303 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 304 | } else if (size == 8) { |
| 305 | word1 = *(u64 *)buf1; |
| 306 | word2 = *(u64 *)buf2; |
| 307 | #endif |
Mike Frysinger | 62a7ea7 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 308 | } else if (size == 2) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 309 | word1 = *(u16 *)buf1; |
| 310 | word2 = *(u16 *)buf2; |
Mike Frysinger | 62a7ea7 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 311 | } else { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 312 | word1 = *(u8 *)buf1; |
| 313 | word2 = *(u8 *)buf2; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 314 | } |
Mike Frysinger | 62a7ea7 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 315 | if (word1 != word2) { |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 316 | ulong offset = buf1 - base; |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 317 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
Simon Glass | e9f343f | 2014-11-11 12:47:07 -0700 | [diff] [blame] | 318 | printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*" |
| 319 | PRIx64 ")\n", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 320 | type, (void *)(addr1 + offset), size, word1, |
| 321 | type, (void *)(addr2 + offset), size, word2); |
| 322 | #else |
Mike Frysinger | 62a7ea7 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 323 | printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n", |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 324 | type, (ulong)(addr1 + offset), size, word1, |
| 325 | type, (ulong)(addr2 + offset), size, word2); |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 326 | #endif |
Mike Frysinger | 62a7ea7 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 327 | rcode = 1; |
| 328 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 329 | } |
Mike Frysinger | 62a7ea7 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 330 | |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 331 | buf1 += size; |
| 332 | buf2 += size; |
Stefan Roese | d4ef82b | 2010-09-13 11:10:34 +0200 | [diff] [blame] | 333 | |
| 334 | /* reset watchdog from time to time */ |
Mike Frysinger | a66afbd | 2012-01-20 09:07:22 +0000 | [diff] [blame] | 335 | if ((ngood % (64 << 10)) == 0) |
Stefan Roese | d4ef82b | 2010-09-13 11:10:34 +0200 | [diff] [blame] | 336 | WATCHDOG_RESET(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 337 | } |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 338 | unmap_sysmem(buf1); |
| 339 | unmap_sysmem(buf2); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 340 | |
Mike Frysinger | 62a7ea7 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 341 | printf("Total of %ld %s(s) were the same\n", ngood, type); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 342 | return rcode; |
| 343 | } |
| 344 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 345 | static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 346 | { |
Fabio Estevam | b03b0c8 | 2016-12-15 16:00:13 -0200 | [diff] [blame] | 347 | ulong addr, dest, count; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 348 | int size; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 349 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 350 | if (argc != 4) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 351 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 352 | |
| 353 | /* Check for size specification. |
| 354 | */ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 355 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 356 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 357 | |
| 358 | addr = simple_strtoul(argv[1], NULL, 16); |
| 359 | addr += base_address; |
| 360 | |
| 361 | dest = simple_strtoul(argv[2], NULL, 16); |
| 362 | dest += base_address; |
| 363 | |
| 364 | count = simple_strtoul(argv[3], NULL, 16); |
| 365 | |
| 366 | if (count == 0) { |
| 367 | puts ("Zero length ???\n"); |
| 368 | return 1; |
| 369 | } |
| 370 | |
Masahiro Yamada | 8cea9b5 | 2017-02-11 22:43:54 +0900 | [diff] [blame] | 371 | #ifdef CONFIG_MTD_NOR_FLASH |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 372 | /* check if we are copying to Flash */ |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 373 | if ( (addr2info(dest) != NULL) |
| 374 | #ifdef CONFIG_HAS_DATAFLASH |
Kim B. Heino | 1eb0fd5 | 2008-03-03 10:39:13 +0200 | [diff] [blame] | 375 | && (!addr_dataflash(dest)) |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 376 | #endif |
| 377 | ) { |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 378 | int rc; |
| 379 | |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 380 | puts ("Copy to Flash... "); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 381 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 382 | rc = flash_write ((char *)addr, dest, count*size); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 383 | if (rc != 0) { |
| 384 | flash_perror (rc); |
| 385 | return (1); |
| 386 | } |
| 387 | puts ("done\n"); |
| 388 | return 0; |
| 389 | } |
| 390 | #endif |
| 391 | |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 392 | #ifdef CONFIG_HAS_DATAFLASH |
| 393 | /* Check if we are copying from RAM or Flash to DataFlash */ |
| 394 | if (addr_dataflash(dest) && !addr_dataflash(addr)){ |
| 395 | int rc; |
| 396 | |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 397 | puts ("Copy to DataFlash... "); |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 398 | |
| 399 | rc = write_dataflash (dest, addr, count*size); |
| 400 | |
| 401 | if (rc != 1) { |
| 402 | dataflash_perror (rc); |
| 403 | return (1); |
| 404 | } |
| 405 | puts ("done\n"); |
| 406 | return 0; |
| 407 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 408 | |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 409 | /* Check if we are copying from DataFlash to RAM */ |
Stelian Pop | a63d2eb | 2008-03-26 22:52:35 +0100 | [diff] [blame] | 410 | if (addr_dataflash(addr) && !addr_dataflash(dest) |
Masahiro Yamada | 8cea9b5 | 2017-02-11 22:43:54 +0900 | [diff] [blame] | 411 | #ifdef CONFIG_MTD_NOR_FLASH |
Stelian Pop | a63d2eb | 2008-03-26 22:52:35 +0100 | [diff] [blame] | 412 | && (addr2info(dest) == NULL) |
| 413 | #endif |
| 414 | ){ |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 415 | int rc; |
| 416 | rc = read_dataflash(addr, count * size, (char *) dest); |
| 417 | if (rc != 1) { |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 418 | dataflash_perror (rc); |
| 419 | return (1); |
| 420 | } |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | if (addr_dataflash(addr) && addr_dataflash(dest)){ |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 425 | puts ("Unsupported combination of source/destination.\n\r"); |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 426 | return 1; |
| 427 | } |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 428 | #endif |
| 429 | |
Fabio Estevam | b03b0c8 | 2016-12-15 16:00:13 -0200 | [diff] [blame] | 430 | memcpy((void *)dest, (void *)addr, count * size); |
Masahiro Yamada | 787b0c5 | 2014-10-23 17:46:24 +0900 | [diff] [blame] | 431 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 432 | return 0; |
| 433 | } |
| 434 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 435 | static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc, |
| 436 | char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 437 | { |
| 438 | if (argc > 1) { |
| 439 | /* Set new base address. |
| 440 | */ |
| 441 | base_address = simple_strtoul(argv[1], NULL, 16); |
| 442 | } |
| 443 | /* Print the current base address. |
| 444 | */ |
| 445 | printf("Base Address: 0x%08lx\n", base_address); |
| 446 | return 0; |
| 447 | } |
| 448 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 449 | static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc, |
| 450 | char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 451 | { |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 452 | ulong addr, length, i, bytes; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 453 | int size; |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 454 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 455 | volatile u64 *llp; |
| 456 | #endif |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 457 | volatile u32 *longp; |
| 458 | volatile u16 *shortp; |
| 459 | volatile u8 *cp; |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 460 | const void *buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 461 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 462 | if (argc < 3) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 463 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 464 | |
Robert P. J. Day | 21c9b78 | 2013-02-03 02:29:54 +0000 | [diff] [blame] | 465 | /* |
| 466 | * Check for a size specification. |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 467 | * Defaults to long if no or incorrect specification. |
| 468 | */ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 469 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 470 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 471 | |
| 472 | /* Address is always specified. |
| 473 | */ |
| 474 | addr = simple_strtoul(argv[1], NULL, 16); |
| 475 | |
| 476 | /* Length is the number of objects, not number of bytes. |
| 477 | */ |
| 478 | length = simple_strtoul(argv[2], NULL, 16); |
| 479 | |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 480 | bytes = size * length; |
| 481 | buf = map_sysmem(addr, bytes); |
| 482 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 483 | /* We want to optimize the loops to run as fast as possible. |
| 484 | * If we have only one object, just run infinite loops. |
| 485 | */ |
| 486 | if (length == 1) { |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 487 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 488 | if (size == 8) { |
| 489 | llp = (u64 *)buf; |
| 490 | for (;;) |
| 491 | i = *llp; |
| 492 | } |
| 493 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 494 | if (size == 4) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 495 | longp = (u32 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 496 | for (;;) |
| 497 | i = *longp; |
| 498 | } |
| 499 | if (size == 2) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 500 | shortp = (u16 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 501 | for (;;) |
| 502 | i = *shortp; |
| 503 | } |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 504 | cp = (u8 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 505 | for (;;) |
| 506 | i = *cp; |
| 507 | } |
| 508 | |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 509 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 510 | if (size == 8) { |
| 511 | for (;;) { |
| 512 | llp = (u64 *)buf; |
| 513 | i = length; |
| 514 | while (i-- > 0) |
| 515 | *llp++; |
| 516 | } |
| 517 | } |
| 518 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 519 | if (size == 4) { |
| 520 | for (;;) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 521 | longp = (u32 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 522 | i = length; |
| 523 | while (i-- > 0) |
Marek Vasut | 7d33582 | 2011-09-26 02:26:06 +0200 | [diff] [blame] | 524 | *longp++; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | if (size == 2) { |
| 528 | for (;;) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 529 | shortp = (u16 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 530 | i = length; |
| 531 | while (i-- > 0) |
Marek Vasut | 7d33582 | 2011-09-26 02:26:06 +0200 | [diff] [blame] | 532 | *shortp++; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | for (;;) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 536 | cp = (u8 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 537 | i = length; |
| 538 | while (i-- > 0) |
Marek Vasut | 7d33582 | 2011-09-26 02:26:06 +0200 | [diff] [blame] | 539 | *cp++; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 540 | } |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 541 | unmap_sysmem(buf); |
Simon Glass | 50d9eb9 | 2013-06-11 11:14:35 -0700 | [diff] [blame] | 542 | |
| 543 | return 0; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 544 | } |
| 545 | |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 546 | #ifdef CONFIG_LOOPW |
Masahiro Yamada | 0b2f331 | 2014-09-04 00:38:26 +0900 | [diff] [blame] | 547 | static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc, |
| 548 | char * const argv[]) |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 549 | { |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 550 | ulong addr, length, i, bytes; |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 551 | int size; |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 552 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 553 | volatile u64 *llp; |
| 554 | u64 data; |
| 555 | #else |
| 556 | ulong data; |
| 557 | #endif |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 558 | volatile u32 *longp; |
| 559 | volatile u16 *shortp; |
| 560 | volatile u8 *cp; |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 561 | void *buf; |
wdenk | 7dd1329 | 2004-07-11 20:04:51 +0000 | [diff] [blame] | 562 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 563 | if (argc < 4) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 564 | return CMD_RET_USAGE; |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 565 | |
Robert P. J. Day | 21c9b78 | 2013-02-03 02:29:54 +0000 | [diff] [blame] | 566 | /* |
| 567 | * Check for a size specification. |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 568 | * Defaults to long if no or incorrect specification. |
| 569 | */ |
| 570 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 571 | return 1; |
| 572 | |
| 573 | /* Address is always specified. |
| 574 | */ |
| 575 | addr = simple_strtoul(argv[1], NULL, 16); |
| 576 | |
| 577 | /* Length is the number of objects, not number of bytes. |
| 578 | */ |
| 579 | length = simple_strtoul(argv[2], NULL, 16); |
| 580 | |
| 581 | /* data to write */ |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 582 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 583 | data = simple_strtoull(argv[3], NULL, 16); |
| 584 | #else |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 585 | data = simple_strtoul(argv[3], NULL, 16); |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 586 | #endif |
wdenk | 7dd1329 | 2004-07-11 20:04:51 +0000 | [diff] [blame] | 587 | |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 588 | bytes = size * length; |
| 589 | buf = map_sysmem(addr, bytes); |
| 590 | |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 591 | /* We want to optimize the loops to run as fast as possible. |
| 592 | * If we have only one object, just run infinite loops. |
| 593 | */ |
| 594 | if (length == 1) { |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 595 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 596 | if (size == 8) { |
| 597 | llp = (u64 *)buf; |
| 598 | for (;;) |
| 599 | *llp = data; |
| 600 | } |
| 601 | #endif |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 602 | if (size == 4) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 603 | longp = (u32 *)buf; |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 604 | for (;;) |
| 605 | *longp = data; |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 606 | } |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 607 | if (size == 2) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 608 | shortp = (u16 *)buf; |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 609 | for (;;) |
| 610 | *shortp = data; |
| 611 | } |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 612 | cp = (u8 *)buf; |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 613 | for (;;) |
| 614 | *cp = data; |
| 615 | } |
| 616 | |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 617 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 618 | if (size == 8) { |
| 619 | for (;;) { |
| 620 | llp = (u64 *)buf; |
| 621 | i = length; |
| 622 | while (i-- > 0) |
| 623 | *llp++ = data; |
| 624 | } |
| 625 | } |
| 626 | #endif |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 627 | if (size == 4) { |
| 628 | for (;;) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 629 | longp = (u32 *)buf; |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 630 | i = length; |
| 631 | while (i-- > 0) |
| 632 | *longp++ = data; |
| 633 | } |
| 634 | } |
| 635 | if (size == 2) { |
| 636 | for (;;) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 637 | shortp = (u16 *)buf; |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 638 | i = length; |
| 639 | while (i-- > 0) |
| 640 | *shortp++ = data; |
| 641 | } |
| 642 | } |
| 643 | for (;;) { |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 644 | cp = (u8 *)buf; |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 645 | i = length; |
| 646 | while (i-- > 0) |
| 647 | *cp++ = data; |
| 648 | } |
| 649 | } |
| 650 | #endif /* CONFIG_LOOPW */ |
| 651 | |
Tom Rini | a5f0270 | 2013-03-12 10:07:19 -0400 | [diff] [blame] | 652 | #ifdef CONFIG_CMD_MEMTEST |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 653 | static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, |
| 654 | vu_long *dummy) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 655 | { |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 656 | vu_long *addr; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 657 | ulong errs = 0; |
| 658 | ulong val, readback; |
| 659 | int j; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 660 | vu_long offset; |
| 661 | vu_long test_offset; |
| 662 | vu_long pattern; |
| 663 | vu_long temp; |
| 664 | vu_long anti_pattern; |
| 665 | vu_long num_words; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 666 | static const ulong bitpattern[] = { |
| 667 | 0x00000001, /* single bit */ |
| 668 | 0x00000003, /* two adjacent bits */ |
| 669 | 0x00000007, /* three adjacent bits */ |
| 670 | 0x0000000F, /* four adjacent bits */ |
| 671 | 0x00000005, /* two non-adjacent bits */ |
| 672 | 0x00000015, /* three non-adjacent bits */ |
| 673 | 0x00000055, /* four non-adjacent bits */ |
| 674 | 0xaaaaaaaa, /* alternating 1/0 */ |
| 675 | }; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 676 | |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 677 | num_words = (end_addr - start_addr) / sizeof(vu_long); |
Simon Glass | 5107525 | 2013-02-24 17:33:20 +0000 | [diff] [blame] | 678 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 679 | /* |
| 680 | * Data line test: write a pattern to the first |
| 681 | * location, write the 1's complement to a 'parking' |
| 682 | * address (changes the state of the data bus so a |
| 683 | * floating bus doesn't give a false OK), and then |
| 684 | * read the value back. Note that we read it back |
| 685 | * into a variable because the next time we read it, |
| 686 | * it might be right (been there, tough to explain to |
| 687 | * the quality guys why it prints a failure when the |
| 688 | * "is" and "should be" are obviously the same in the |
| 689 | * error message). |
| 690 | * |
| 691 | * Rather than exhaustively testing, we test some |
| 692 | * patterns by shifting '1' bits through a field of |
| 693 | * '0's and '0' bits through a field of '1's (i.e. |
| 694 | * pattern and ~pattern). |
| 695 | */ |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 696 | addr = buf; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 697 | for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) { |
| 698 | val = bitpattern[j]; |
| 699 | for (; val != 0; val <<= 1) { |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 700 | *addr = val; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 701 | *dummy = ~val; /* clear the test data off the bus */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 702 | readback = *addr; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 703 | if (readback != val) { |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 704 | printf("FAILURE (data line): " |
| 705 | "expected %08lx, actual %08lx\n", |
| 706 | val, readback); |
| 707 | errs++; |
Simon Glass | eb4598b | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 708 | if (ctrlc()) |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 709 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 710 | } |
| 711 | *addr = ~val; |
| 712 | *dummy = val; |
| 713 | readback = *addr; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 714 | if (readback != ~val) { |
| 715 | printf("FAILURE (data line): " |
| 716 | "Is %08lx, should be %08lx\n", |
| 717 | readback, ~val); |
| 718 | errs++; |
Simon Glass | eb4598b | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 719 | if (ctrlc()) |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 720 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 721 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 722 | } |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 723 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 724 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 725 | /* |
| 726 | * Based on code whose Original Author and Copyright |
| 727 | * information follows: Copyright (c) 1998 by Michael |
| 728 | * Barr. This software is placed into the public |
| 729 | * domain and may be used for any purpose. However, |
| 730 | * this notice must not be changed or removed and no |
| 731 | * warranty is either expressed or implied by its |
| 732 | * publication or distribution. |
| 733 | */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 734 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 735 | /* |
| 736 | * Address line test |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 737 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 738 | * Description: Test the address bus wiring in a |
| 739 | * memory region by performing a walking |
| 740 | * 1's test on the relevant bits of the |
| 741 | * address and checking for aliasing. |
| 742 | * This test will find single-bit |
| 743 | * address failures such as stuck-high, |
| 744 | * stuck-low, and shorted pins. The base |
| 745 | * address and size of the region are |
| 746 | * selected by the caller. |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 747 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 748 | * Notes: For best results, the selected base |
| 749 | * address should have enough LSB 0's to |
| 750 | * guarantee single address bit changes. |
| 751 | * For example, to test a 64-Kbyte |
| 752 | * region, select a base address on a |
| 753 | * 64-Kbyte boundary. Also, select the |
| 754 | * region size as a power-of-two if at |
| 755 | * all possible. |
| 756 | * |
| 757 | * Returns: 0 if the test succeeds, 1 if the test fails. |
| 758 | */ |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 759 | pattern = (vu_long) 0xaaaaaaaa; |
| 760 | anti_pattern = (vu_long) 0x55555555; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 761 | |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 762 | debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words); |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 763 | /* |
| 764 | * Write the default pattern at each of the |
| 765 | * power-of-two offsets. |
| 766 | */ |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 767 | for (offset = 1; offset < num_words; offset <<= 1) |
| 768 | addr[offset] = pattern; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 769 | |
| 770 | /* |
| 771 | * Check for address bits stuck high. |
| 772 | */ |
| 773 | test_offset = 0; |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 774 | addr[test_offset] = anti_pattern; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 775 | |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 776 | for (offset = 1; offset < num_words; offset <<= 1) { |
| 777 | temp = addr[offset]; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 778 | if (temp != pattern) { |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 779 | printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:" |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 780 | " expected 0x%.8lx, actual 0x%.8lx\n", |
David Feng | f40b221 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 781 | start_addr + offset*sizeof(vu_long), |
| 782 | pattern, temp); |
Paul Gortmaker | cb47b4f | 2009-10-02 18:18:33 -0400 | [diff] [blame] | 783 | errs++; |
Simon Glass | eb4598b | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 784 | if (ctrlc()) |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 785 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 786 | } |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 787 | } |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 788 | addr[test_offset] = pattern; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 789 | WATCHDOG_RESET(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 790 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 791 | /* |
| 792 | * Check for addr bits stuck low or shorted. |
| 793 | */ |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 794 | for (test_offset = 1; test_offset < num_words; test_offset <<= 1) { |
| 795 | addr[test_offset] = anti_pattern; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 796 | |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 797 | for (offset = 1; offset < num_words; offset <<= 1) { |
| 798 | temp = addr[offset]; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 799 | if ((temp != pattern) && (offset != test_offset)) { |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 800 | printf("\nFAILURE: Address bit stuck low or" |
| 801 | " shorted @ 0x%.8lx: expected 0x%.8lx," |
| 802 | " actual 0x%.8lx\n", |
David Feng | f40b221 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 803 | start_addr + offset*sizeof(vu_long), |
| 804 | pattern, temp); |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 805 | errs++; |
Simon Glass | eb4598b | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 806 | if (ctrlc()) |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 807 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 808 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 809 | } |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 810 | addr[test_offset] = pattern; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 811 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 812 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 813 | /* |
| 814 | * Description: Test the integrity of a physical |
| 815 | * memory device by performing an |
| 816 | * increment/decrement test over the |
| 817 | * entire region. In the process every |
| 818 | * storage bit in the device is tested |
| 819 | * as a zero and a one. The base address |
| 820 | * and the size of the region are |
| 821 | * selected by the caller. |
| 822 | * |
| 823 | * Returns: 0 if the test succeeds, 1 if the test fails. |
| 824 | */ |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 825 | num_words++; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 826 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 827 | /* |
| 828 | * Fill memory with a known pattern. |
| 829 | */ |
| 830 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { |
| 831 | WATCHDOG_RESET(); |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 832 | addr[offset] = pattern; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 833 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 834 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 835 | /* |
| 836 | * Check each location and invert it for the second pass. |
| 837 | */ |
| 838 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { |
| 839 | WATCHDOG_RESET(); |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 840 | temp = addr[offset]; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 841 | if (temp != pattern) { |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 842 | printf("\nFAILURE (read/write) @ 0x%.8lx:" |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 843 | " expected 0x%.8lx, actual 0x%.8lx)\n", |
David Feng | f40b221 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 844 | start_addr + offset*sizeof(vu_long), |
| 845 | pattern, temp); |
Paul Gortmaker | cb47b4f | 2009-10-02 18:18:33 -0400 | [diff] [blame] | 846 | errs++; |
Simon Glass | eb4598b | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 847 | if (ctrlc()) |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 848 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 851 | anti_pattern = ~pattern; |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 852 | addr[offset] = anti_pattern; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | /* |
| 856 | * Check each location for the inverted pattern and zero it. |
| 857 | */ |
| 858 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { |
| 859 | WATCHDOG_RESET(); |
| 860 | anti_pattern = ~pattern; |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 861 | temp = addr[offset]; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 862 | if (temp != anti_pattern) { |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 863 | printf("\nFAILURE (read/write): @ 0x%.8lx:" |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 864 | " expected 0x%.8lx, actual 0x%.8lx)\n", |
David Feng | f40b221 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 865 | start_addr + offset*sizeof(vu_long), |
| 866 | anti_pattern, temp); |
Paul Gortmaker | cb47b4f | 2009-10-02 18:18:33 -0400 | [diff] [blame] | 867 | errs++; |
Simon Glass | eb4598b | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 868 | if (ctrlc()) |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 869 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 870 | } |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 871 | addr[offset] = 0; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 872 | } |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 873 | |
Rasmus Villemoes | abd06c9 | 2016-01-07 11:36:04 +0100 | [diff] [blame] | 874 | return errs; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 877 | static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, |
| 878 | vu_long pattern, int iteration) |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 879 | { |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 880 | vu_long *end; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 881 | vu_long *addr; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 882 | ulong errs = 0; |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 883 | ulong incr, length; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 884 | ulong val, readback; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 885 | |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 886 | /* Alternate the pattern */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 887 | incr = 1; |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 888 | if (iteration & 1) { |
| 889 | incr = -incr; |
| 890 | /* |
| 891 | * Flip the pattern each time to make lots of zeros and |
| 892 | * then, the next time, lots of ones. We decrement |
| 893 | * the "negative" patterns and increment the "positive" |
| 894 | * patterns to preserve this feature. |
| 895 | */ |
| 896 | if (pattern & 0x80000000) |
| 897 | pattern = -pattern; /* complement & increment */ |
| 898 | else |
| 899 | pattern = ~pattern; |
| 900 | } |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 901 | length = (end_addr - start_addr) / sizeof(ulong); |
| 902 | end = buf + length; |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 903 | printf("\rPattern %08lX Writing..." |
| 904 | "%12s" |
| 905 | "\b\b\b\b\b\b\b\b\b\b", |
| 906 | pattern, ""); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 907 | |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 908 | for (addr = buf, val = pattern; addr < end; addr++) { |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 909 | WATCHDOG_RESET(); |
| 910 | *addr = val; |
| 911 | val += incr; |
| 912 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 913 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 914 | puts("Reading..."); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 915 | |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 916 | for (addr = buf, val = pattern; addr < end; addr++) { |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 917 | WATCHDOG_RESET(); |
| 918 | readback = *addr; |
| 919 | if (readback != val) { |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 920 | ulong offset = addr - buf; |
| 921 | |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 922 | printf("\nMem error @ 0x%08X: " |
| 923 | "found %08lX, expected %08lX\n", |
David Feng | f40b221 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 924 | (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)), |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 925 | readback, val); |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 926 | errs++; |
Simon Glass | eb4598b | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 927 | if (ctrlc()) |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 928 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 929 | } |
Simon Glass | 130103e | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 930 | val += incr; |
| 931 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 932 | |
Rasmus Villemoes | abd06c9 | 2016-01-07 11:36:04 +0100 | [diff] [blame] | 933 | return errs; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | /* |
| 937 | * Perform a memory test. A more complete alternative test can be |
| 938 | * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until |
| 939 | * interrupted by ctrl-c or by a failure of one of the sub-tests. |
| 940 | */ |
| 941 | static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, |
| 942 | char * const argv[]) |
| 943 | { |
Simon Glass | 5107525 | 2013-02-24 17:33:20 +0000 | [diff] [blame] | 944 | ulong start, end; |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 945 | vu_long *buf, *dummy; |
Tom Rini | b918088 | 2015-04-07 09:38:54 -0400 | [diff] [blame] | 946 | ulong iteration_limit = 0; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 947 | int ret; |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 948 | ulong errs = 0; /* number of errors, or -1 if interrupted */ |
Pavel Machek | d319f59 | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 949 | ulong pattern = 0; |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 950 | int iteration; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 951 | #if defined(CONFIG_SYS_ALT_MEMTEST) |
| 952 | const int alt_test = 1; |
| 953 | #else |
| 954 | const int alt_test = 0; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 955 | #endif |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 956 | |
Pavel Machek | d319f59 | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 957 | start = CONFIG_SYS_MEMTEST_START; |
| 958 | end = CONFIG_SYS_MEMTEST_END; |
| 959 | |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 960 | if (argc > 1) |
Pavel Machek | d319f59 | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 961 | if (strict_strtoul(argv[1], 16, &start) < 0) |
| 962 | return CMD_RET_USAGE; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 963 | |
| 964 | if (argc > 2) |
Pavel Machek | d319f59 | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 965 | if (strict_strtoul(argv[2], 16, &end) < 0) |
| 966 | return CMD_RET_USAGE; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 967 | |
| 968 | if (argc > 3) |
Pavel Machek | d319f59 | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 969 | if (strict_strtoul(argv[3], 16, &pattern) < 0) |
| 970 | return CMD_RET_USAGE; |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 971 | |
| 972 | if (argc > 4) |
Pavel Machek | d319f59 | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 973 | if (strict_strtoul(argv[4], 16, &iteration_limit) < 0) |
| 974 | return CMD_RET_USAGE; |
| 975 | |
| 976 | if (end < start) { |
| 977 | printf("Refusing to do empty test\n"); |
| 978 | return -1; |
| 979 | } |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 980 | |
Michal Simek | 45f8e33 | 2016-02-24 08:36:02 +0100 | [diff] [blame] | 981 | printf("Testing %08lx ... %08lx:\n", start, end); |
Simon Glass | 5107525 | 2013-02-24 17:33:20 +0000 | [diff] [blame] | 982 | debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__, |
| 983 | start, end); |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 984 | |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 985 | buf = map_sysmem(start, end - start); |
| 986 | dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long)); |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 987 | for (iteration = 0; |
| 988 | !iteration_limit || iteration < iteration_limit; |
| 989 | iteration++) { |
| 990 | if (ctrlc()) { |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 991 | errs = -1UL; |
| 992 | break; |
| 993 | } |
| 994 | |
| 995 | printf("Iteration: %6d\r", iteration + 1); |
| 996 | debug("\n"); |
Simon Glass | ad02a01 | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 997 | if (alt_test) { |
| 998 | errs = mem_test_alt(buf, start, end, dummy); |
| 999 | } else { |
| 1000 | errs = mem_test_quick(buf, start, end, pattern, |
| 1001 | iteration); |
| 1002 | } |
| 1003 | if (errs == -1UL) |
| 1004 | break; |
| 1005 | } |
| 1006 | |
| 1007 | /* |
| 1008 | * Work-around for eldk-4.2 which gives this warning if we try to |
| 1009 | * case in the unmap_sysmem() call: |
| 1010 | * warning: initialization discards qualifiers from pointer target type |
| 1011 | */ |
| 1012 | { |
| 1013 | void *vbuf = (void *)buf; |
| 1014 | void *vdummy = (void *)dummy; |
| 1015 | |
| 1016 | unmap_sysmem(vbuf); |
| 1017 | unmap_sysmem(vdummy); |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | if (errs == -1UL) { |
Simon Glass | eb4598b | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 1021 | /* Memory test was aborted - write a newline to finish off */ |
| 1022 | putc('\n'); |
Simon Glass | 57ee443 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 1023 | ret = 1; |
| 1024 | } else { |
| 1025 | printf("Tested %d iteration(s) with %lu errors.\n", |
| 1026 | iteration, errs); |
| 1027 | ret = errs != 0; |
| 1028 | } |
Simon Glass | 8f2c758 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 1029 | |
Pavel Machek | d319f59 | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 1030 | return ret; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1031 | } |
Wolfgang Denk | 9d00928 | 2013-03-08 10:51:32 +0000 | [diff] [blame] | 1032 | #endif /* CONFIG_CMD_MEMTEST */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1033 | |
| 1034 | /* Modify memory. |
| 1035 | * |
| 1036 | * Syntax: |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1037 | * mm{.b, .w, .l, .q} {addr} |
| 1038 | * nm{.b, .w, .l, .q} {addr} |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1039 | */ |
| 1040 | static int |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 1041 | mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1042 | { |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1043 | ulong addr; |
| 1044 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1045 | u64 i; |
| 1046 | #else |
| 1047 | ulong i; |
| 1048 | #endif |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1049 | int nbytes, size; |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 1050 | void *ptr = NULL; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1051 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 1052 | if (argc != 2) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1053 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1054 | |
Simon Glass | 09007c4 | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 1055 | bootretry_reset_cmd_timeout(); /* got a good command to get here */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1056 | /* We use the last specified parameters, unless new ones are |
| 1057 | * entered. |
| 1058 | */ |
| 1059 | addr = mm_last_addr; |
| 1060 | size = mm_last_size; |
| 1061 | |
| 1062 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 1063 | /* New command specified. Check for a size specification. |
| 1064 | * Defaults to long if no or incorrect specification. |
| 1065 | */ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1066 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 1067 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1068 | |
| 1069 | /* Address is specified since argc > 1 |
| 1070 | */ |
| 1071 | addr = simple_strtoul(argv[1], NULL, 16); |
| 1072 | addr += base_address; |
| 1073 | } |
| 1074 | |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 1075 | #ifdef CONFIG_HAS_DATAFLASH |
| 1076 | if (addr_dataflash(addr)){ |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1077 | puts ("Can't modify DataFlash in place. Use cp instead.\n\r"); |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 1078 | return 0; |
| 1079 | } |
| 1080 | #endif |
| 1081 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1082 | /* Print the address, followed by value. Then accept input for |
| 1083 | * the next value. A non-converted value exits. |
| 1084 | */ |
| 1085 | do { |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 1086 | ptr = map_sysmem(addr, size); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1087 | printf("%08lx:", addr); |
| 1088 | if (size == 4) |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1089 | printf(" %08x", *((u32 *)ptr)); |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1090 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1091 | else if (size == 8) |
Simon Glass | e9f343f | 2014-11-11 12:47:07 -0700 | [diff] [blame] | 1092 | printf(" %016" PRIx64, *((u64 *)ptr)); |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1093 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1094 | else if (size == 2) |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1095 | printf(" %04x", *((u16 *)ptr)); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1096 | else |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1097 | printf(" %02x", *((u8 *)ptr)); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1098 | |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 1099 | nbytes = cli_readline(" ? "); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1100 | if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { |
| 1101 | /* <CR> pressed as only input, don't modify current |
| 1102 | * location and move to next. "-" pressed will go back. |
| 1103 | */ |
| 1104 | if (incrflag) |
| 1105 | addr += nbytes ? -size : size; |
| 1106 | nbytes = 1; |
Simon Glass | 09007c4 | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 1107 | /* good enough to not time out */ |
| 1108 | bootretry_reset_cmd_timeout(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1109 | } |
| 1110 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 1111 | else if (nbytes == -2) { |
| 1112 | break; /* timed out, exit the command */ |
| 1113 | } |
| 1114 | #endif |
| 1115 | else { |
| 1116 | char *endp; |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1117 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1118 | i = simple_strtoull(console_buffer, &endp, 16); |
| 1119 | #else |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1120 | i = simple_strtoul(console_buffer, &endp, 16); |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1121 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1122 | nbytes = endp - console_buffer; |
| 1123 | if (nbytes) { |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1124 | /* good enough to not time out |
| 1125 | */ |
Simon Glass | 09007c4 | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 1126 | bootretry_reset_cmd_timeout(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1127 | if (size == 4) |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1128 | *((u32 *)ptr) = i; |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1129 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1130 | else if (size == 8) |
| 1131 | *((u64 *)ptr) = i; |
| 1132 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1133 | else if (size == 2) |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1134 | *((u16 *)ptr) = i; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1135 | else |
York Sun | d8a405d | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1136 | *((u8 *)ptr) = i; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1137 | if (incrflag) |
| 1138 | addr += size; |
| 1139 | } |
| 1140 | } |
| 1141 | } while (nbytes); |
Simon Glass | e6d0ca2 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 1142 | if (ptr) |
| 1143 | unmap_sysmem(ptr); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1144 | |
| 1145 | mm_last_addr = addr; |
| 1146 | mm_last_size = size; |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
Mike Frysinger | 321ab9e | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1150 | #ifdef CONFIG_CMD_CRC32 |
| 1151 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1152 | static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1153 | { |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 1154 | int flags = 0; |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1155 | int ac; |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 1156 | char * const *av; |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1157 | |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 1158 | if (argc < 3) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1159 | return CMD_RET_USAGE; |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1160 | |
| 1161 | av = argv + 1; |
| 1162 | ac = argc - 1; |
Daniel Thompson | a9e2c67 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1163 | #ifdef CONFIG_CRC32_VERIFY |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1164 | if (strcmp(*av, "-v") == 0) { |
Joe Hershberger | 5fcee9a | 2015-05-05 12:23:53 -0500 | [diff] [blame] | 1165 | flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV; |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1166 | av++; |
| 1167 | ac--; |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1168 | } |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 1169 | #endif |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1170 | |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 1171 | return hash_command("crc32", flags, cmdtp, flag, ac, av); |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1172 | } |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1173 | |
Robin Getz | 93d6cb0 | 2009-07-27 00:07:59 -0400 | [diff] [blame] | 1174 | #endif |
| 1175 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1176 | /**************************************************/ |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1177 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1178 | md, 3, 1, do_mem_md, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1179 | "memory display", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1180 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1181 | "[.b, .w, .l, .q] address [# of objects]" |
| 1182 | #else |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1183 | "[.b, .w, .l] address [# of objects]" |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1184 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1185 | ); |
| 1186 | |
| 1187 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1188 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1189 | mm, 2, 1, do_mem_mm, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1190 | "memory modify (auto-incrementing address)", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1191 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1192 | "[.b, .w, .l, .q] address" |
| 1193 | #else |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1194 | "[.b, .w, .l] address" |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1195 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1196 | ); |
| 1197 | |
| 1198 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1199 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1200 | nm, 2, 1, do_mem_nm, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1201 | "memory modify (constant address)", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1202 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1203 | "[.b, .w, .l, .q] address" |
| 1204 | #else |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1205 | "[.b, .w, .l] address" |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1206 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1207 | ); |
| 1208 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1209 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1210 | mw, 4, 1, do_mem_mw, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1211 | "memory write (fill)", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1212 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1213 | "[.b, .w, .l, .q] address value [count]" |
| 1214 | #else |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1215 | "[.b, .w, .l] address value [count]" |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1216 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1217 | ); |
| 1218 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1219 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1220 | cp, 4, 1, do_mem_cp, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1221 | "memory copy", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1222 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1223 | "[.b, .w, .l, .q] source target count" |
| 1224 | #else |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1225 | "[.b, .w, .l] source target count" |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1226 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1227 | ); |
| 1228 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1229 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1230 | cmp, 4, 1, do_mem_cmp, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1231 | "memory compare", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1232 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1233 | "[.b, .w, .l, .q] addr1 addr2 count" |
| 1234 | #else |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1235 | "[.b, .w, .l] addr1 addr2 count" |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1236 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1237 | ); |
| 1238 | |
Mike Frysinger | 321ab9e | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1239 | #ifdef CONFIG_CMD_CRC32 |
| 1240 | |
Daniel Thompson | a9e2c67 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1241 | #ifndef CONFIG_CRC32_VERIFY |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1242 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1243 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1244 | crc32, 4, 1, do_mem_crc, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1245 | "checksum calculation", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1246 | "address count [addr]\n - compute CRC32 checksum [save at addr]" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1247 | ); |
| 1248 | |
Daniel Thompson | a9e2c67 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1249 | #else /* CONFIG_CRC32_VERIFY */ |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1250 | |
| 1251 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1252 | crc32, 5, 1, do_mem_crc, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1253 | "checksum calculation", |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1254 | "address count [addr]\n - compute CRC32 checksum [save at addr]\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1255 | "-v address count crc\n - verify crc of memory area" |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1256 | ); |
| 1257 | |
Daniel Thompson | a9e2c67 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1258 | #endif /* CONFIG_CRC32_VERIFY */ |
wdenk | 6203e40 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1259 | |
Mike Frysinger | 321ab9e | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1260 | #endif |
| 1261 | |
Simon Glass | eacd14f | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 1262 | #ifdef CONFIG_CMD_MEMINFO |
Andrew Bradford | ec9dbc9 | 2015-05-22 08:30:14 -0400 | [diff] [blame] | 1263 | __weak void board_show_dram(phys_size_t size) |
Simon Glass | eacd14f | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 1264 | { |
| 1265 | puts("DRAM: "); |
| 1266 | print_size(size, "\n"); |
| 1267 | } |
| 1268 | |
| 1269 | static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc, |
| 1270 | char * const argv[]) |
| 1271 | { |
| 1272 | board_show_dram(gd->ram_size); |
| 1273 | |
| 1274 | return 0; |
| 1275 | } |
| 1276 | #endif |
| 1277 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1278 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1279 | base, 2, 1, do_mem_base, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1280 | "print or set address offset", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1281 | "\n - print address offset for memory commands\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1282 | "base off\n - set address offset for memory commands to 'off'" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1283 | ); |
| 1284 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1285 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1286 | loop, 3, 1, do_mem_loop, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1287 | "infinite loop on address range", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1288 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1289 | "[.b, .w, .l, .q] address number_of_objects" |
| 1290 | #else |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1291 | "[.b, .w, .l] address number_of_objects" |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1292 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1293 | ); |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 1294 | |
| 1295 | #ifdef CONFIG_LOOPW |
| 1296 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1297 | loopw, 4, 1, do_mem_loopw, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1298 | "infinite write loop on address range", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1299 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1300 | "[.b, .w, .l, .q] address number_of_objects data_to_write" |
| 1301 | #else |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1302 | "[.b, .w, .l] address number_of_objects data_to_write" |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1303 | #endif |
wdenk | 6451936 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 1304 | ); |
| 1305 | #endif /* CONFIG_LOOPW */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1306 | |
Wolfgang Denk | 9d00928 | 2013-03-08 10:51:32 +0000 | [diff] [blame] | 1307 | #ifdef CONFIG_CMD_MEMTEST |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1308 | U_BOOT_CMD( |
Dirk Eibach | b265989 | 2008-12-16 14:51:56 +0100 | [diff] [blame] | 1309 | mtest, 5, 1, do_mem_mtest, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1310 | "simple RAM read/write test", |
| 1311 | "[start [end [pattern [iterations]]]]" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1312 | ); |
Wolfgang Denk | 9d00928 | 2013-03-08 10:51:32 +0000 | [diff] [blame] | 1313 | #endif /* CONFIG_CMD_MEMTEST */ |
stroese | fb5e0ac | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 1314 | |
| 1315 | #ifdef CONFIG_MX_CYCLIC |
| 1316 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1317 | mdc, 4, 1, do_mem_mdc, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1318 | "memory display cyclic", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1319 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1320 | "[.b, .w, .l, .q] address count delay(ms)" |
| 1321 | #else |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1322 | "[.b, .w, .l] address count delay(ms)" |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1323 | #endif |
stroese | fb5e0ac | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 1324 | ); |
| 1325 | |
| 1326 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1327 | mwc, 4, 1, do_mem_mwc, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1328 | "memory write cyclic", |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1329 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1330 | "[.b, .w, .l, .q] address value delay(ms)" |
| 1331 | #else |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1332 | "[.b, .w, .l] address value delay(ms)" |
York Sun | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1333 | #endif |
stroese | fb5e0ac | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 1334 | ); |
| 1335 | #endif /* CONFIG_MX_CYCLIC */ |
Simon Glass | eacd14f | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 1336 | |
| 1337 | #ifdef CONFIG_CMD_MEMINFO |
| 1338 | U_BOOT_CMD( |
| 1339 | meminfo, 3, 1, do_mem_info, |
| 1340 | "display memory information", |
| 1341 | "" |
| 1342 | ); |
| 1343 | #endif |