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