Tom Rini | 83d290c | 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 | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 14 | #include <console.h> |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 15 | #include <bootretry.h> |
Simon Glass | 18d6653 | 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 | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 18 | #include <console.h> |
Simon Glass | 0ee48252 | 2019-12-28 10:44:40 -0700 | [diff] [blame] | 19 | #include <flash.h> |
Simon Glass | d20a40d | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 20 | #include <hash.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 21 | #include <mapmem.h> |
Sergei Poselenov | a6e6fc6 | 2008-04-09 16:09:41 +0200 | [diff] [blame] | 22 | #include <watchdog.h> |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 23 | #include <asm/io.h> |
Simon Glass | 15a33e4 | 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 | 8e169cc | 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 | 54841ab | 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 | 581508b | 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 | 4d1fd7f | 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 | 088f1b1 | 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 | c68c03f | 2017-10-10 21:59:42 +0300 | [diff] [blame] | 51 | ulong addr, length, bytes; |
| 52 | const void *buf; |
wdenk | 27b207f | 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 | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 63 | if (argc < 2) |
Simon Glass | 4c12eeb | 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 | 27b207f | 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 | c68c03f | 2017-10-10 21:59:42 +0300 | [diff] [blame] | 85 | bytes = size * length; |
| 86 | buf = map_sysmem(addr, bytes); |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 87 | |
Tuomas Tynkkynen | c68c03f | 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 | 088f1b1 | 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 | 088f1b1 | 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 | 088f1b1 | 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 | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 110 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 111 | u64 writeval; |
| 112 | #else |
| 113 | ulong writeval; |
| 114 | #endif |
| 115 | ulong addr, count; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 116 | int size; |
Simon Glass | cc5e196 | 2015-03-05 12:25:18 -0700 | [diff] [blame] | 117 | void *buf, *start; |
Simon Glass | 0628ab8 | 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 | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 120 | if ((argc < 3) || (argc > 4)) |
Simon Glass | 4c12eeb | 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 | 27b207f | 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 | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 135 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 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 | 4d1fd7f | 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 | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 148 | bytes = size * count; |
Simon Glass | cc5e196 | 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 | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 153 | *((u32 *)buf) = (u32)writeval; |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 154 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 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 | 76698b4 | 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 | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 161 | *((u8 *)buf) = (u8)writeval; |
Simon Glass | 0628ab8 | 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 | cc5e196 | 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 | 7273231 | 2020-01-29 09:17:18 -0700 | [diff] [blame] | 168 | #ifdef CONFIG_CMD_MX_CYCLIC |
Masahiro Yamada | 5a8608e | 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 | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 170 | { |
| 171 | int i; |
| 172 | ulong count; |
| 173 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 174 | if (argc < 4) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 175 | return CMD_RET_USAGE; |
stroese | 4aaf29b | 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 | 5a8608e | 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 | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 197 | { |
| 198 | int i; |
| 199 | ulong count; |
| 200 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 201 | if (argc < 4) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 202 | return CMD_RET_USAGE; |
stroese | 4aaf29b | 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 | 7273231 | 2020-01-29 09:17:18 -0700 | [diff] [blame] | 222 | #endif /* CONFIG_CMD_MX_CYCLIC */ |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 223 | |
Kim Phillips | 088f1b1 | 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 | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 226 | ulong addr1, addr2, count, ngood, bytes; |
wdenk | 27b207f | 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 | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 229 | const char *type; |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 230 | const void *buf1, *buf2, *base; |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 231 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 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 | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 237 | if (argc != 4) |
Simon Glass | 4c12eeb | 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 | 27b207f | 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 | 4d1fd7f | 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 | 0628ab8 | 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 | feb12a1 | 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 | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 261 | word1 = *(u32 *)buf1; |
| 262 | word2 = *(u32 *)buf2; |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 263 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 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 | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 268 | } else if (size == 2) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 269 | word1 = *(u16 *)buf1; |
| 270 | word2 = *(u16 *)buf2; |
Mike Frysinger | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 271 | } else { |
York Sun | 76698b4 | 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 | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 275 | if (word1 != word2) { |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 276 | ulong offset = buf1 - base; |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 277 | #ifdef MEM_SUPPORT_64BIT_DATA |
Masahiro Yamada | dee37fc | 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 | 4d1fd7f | 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 | 054ea17 | 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 | 0628ab8 | 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 | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 285 | #endif |
Mike Frysinger | 054ea17 | 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 | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 289 | |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 290 | buf1 += size; |
| 291 | buf2 += size; |
Stefan Roese | eaadb44 | 2010-09-13 11:10:34 +0200 | [diff] [blame] | 292 | |
| 293 | /* reset watchdog from time to time */ |
Mike Frysinger | feb12a1 | 2012-01-20 09:07:22 +0000 | [diff] [blame] | 294 | if ((ngood % (64 << 10)) == 0) |
Stefan Roese | eaadb44 | 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 | 0628ab8 | 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 | 054ea17 | 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 | 088f1b1 | 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 | c253842 | 2016-12-15 16:00:13 -0200 | [diff] [blame] | 306 | ulong addr, dest, count; |
Philippe Reynes | 787f10a | 2019-12-02 17:33:22 +0100 | [diff] [blame] | 307 | void *src, *dst; |
wdenk | 27b207f | 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 | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 310 | if (argc != 4) |
Simon Glass | 4c12eeb | 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 | 27b207f | 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 | 787f10a | 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 | e856bdc | 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 | 787f10a | 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 | 4b9206e | 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 | 787f10a | 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 | 0ee48252 | 2019-12-28 10:44:40 -0700 | [diff] [blame] | 343 | flash_perror(rc); |
Philippe Reynes | 787f10a | 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 | 787f10a | 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 | } |
| 353 | #endif |
| 354 | |
Philippe Reynes | 787f10a | 2019-12-02 17:33:22 +0100 | [diff] [blame] | 355 | memcpy(dst, src, count * size); |
Masahiro Yamada | a3a4749 | 2014-10-23 17:46:24 +0900 | [diff] [blame] | 356 | |
Philippe Reynes | 787f10a | 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 | 088f1b1 | 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 | 088f1b1 | 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 | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 379 | ulong addr, length, i, bytes; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 380 | int size; |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 381 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 382 | volatile u64 *llp; |
| 383 | #endif |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 384 | volatile u32 *longp; |
| 385 | volatile u16 *shortp; |
| 386 | volatile u8 *cp; |
Simon Glass | 0628ab8 | 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 | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 389 | if (argc < 3) |
Simon Glass | 4c12eeb | 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 | 85de63e | 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 | 27b207f | 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 | 0628ab8 | 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 | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 414 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 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 | 76698b4 | 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 | 76698b4 | 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 | 76698b4 | 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 | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 436 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 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 | 76698b4 | 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 | f3b3c3d | 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 | 76698b4 | 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 | f3b3c3d | 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 | 76698b4 | 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 | f3b3c3d | 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 | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 468 | unmap_sysmem(buf); |
Simon Glass | 92765f42 | 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 | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 473 | #ifdef CONFIG_LOOPW |
Masahiro Yamada | 5a8608e | 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 | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 476 | { |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 477 | ulong addr, length, i, bytes; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 478 | int size; |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 479 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 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 | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 485 | volatile u32 *longp; |
| 486 | volatile u16 *shortp; |
| 487 | volatile u8 *cp; |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 488 | void *buf; |
wdenk | 8105092 | 2004-07-11 20:04:51 +0000 | [diff] [blame] | 489 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 490 | if (argc < 4) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 491 | return CMD_RET_USAGE; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 492 | |
Robert P. J. Day | 85de63e | 2013-02-03 02:29:54 +0000 | [diff] [blame] | 493 | /* |
| 494 | * Check for a size specification. |
wdenk | 56523f1 | 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 | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 509 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 510 | data = simple_strtoull(argv[3], NULL, 16); |
| 511 | #else |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 512 | data = simple_strtoul(argv[3], NULL, 16); |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 513 | #endif |
wdenk | 8105092 | 2004-07-11 20:04:51 +0000 | [diff] [blame] | 514 | |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 515 | bytes = size * length; |
| 516 | buf = map_sysmem(addr, bytes); |
| 517 | |
wdenk | 56523f1 | 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 | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 522 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 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 | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 529 | if (size == 4) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 530 | longp = (u32 *)buf; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 531 | for (;;) |
| 532 | *longp = data; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 533 | } |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 534 | if (size == 2) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 535 | shortp = (u16 *)buf; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 536 | for (;;) |
| 537 | *shortp = data; |
| 538 | } |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 539 | cp = (u8 *)buf; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 540 | for (;;) |
| 541 | *cp = data; |
| 542 | } |
| 543 | |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 544 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 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 | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 554 | if (size == 4) { |
| 555 | for (;;) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 556 | longp = (u32 *)buf; |
wdenk | 56523f1 | 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 | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 564 | shortp = (u16 *)buf; |
wdenk | 56523f1 | 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 | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 571 | cp = (u8 *)buf; |
wdenk | 56523f1 | 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 | 68149e9 | 2013-03-12 10:07:19 -0400 | [diff] [blame] | 579 | #ifdef CONFIG_CMD_MEMTEST |
Simon Glass | 5512d5b | 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 | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 583 | vu_long *addr; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 584 | ulong errs = 0; |
| 585 | ulong val, readback; |
| 586 | int j; |
Simon Glass | c9638f5 | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 604 | num_words = (end_addr - start_addr) / sizeof(vu_long); |
Simon Glass | 8c86bbe | 2013-02-24 17:33:20 +0000 | [diff] [blame] | 605 | |
Simon Glass | 7ecbd4d | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 623 | addr = buf; |
Simon Glass | 7ecbd4d | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 627 | *addr = val; |
Simon Glass | c9638f5 | 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 | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 630 | if (readback != val) { |
Simon Glass | c9638f5 | 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 | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 635 | if (ctrlc()) |
Simon Glass | 51209b1 | 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 | c9638f5 | 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 | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 646 | if (ctrlc()) |
Simon Glass | 51209b1 | 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 | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 650 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 651 | |
Simon Glass | 7ecbd4d | 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 | 7ecbd4d | 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 | 7ecbd4d | 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 | 7ecbd4d | 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 | 7ecbd4d | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 689 | debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words); |
Simon Glass | 7ecbd4d | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 694 | for (offset = 1; offset < num_words; offset <<= 1) |
| 695 | addr[offset] = pattern; |
Simon Glass | 7ecbd4d | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 701 | addr[test_offset] = anti_pattern; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 702 | |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 703 | for (offset = 1; offset < num_words; offset <<= 1) { |
| 704 | temp = addr[offset]; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 705 | if (temp != pattern) { |
Simon Glass | c9638f5 | 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 | 102c051 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 708 | start_addr + offset*sizeof(vu_long), |
| 709 | pattern, temp); |
Paul Gortmaker | 87b22b7 | 2009-10-02 18:18:33 -0400 | [diff] [blame] | 710 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 711 | if (ctrlc()) |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 712 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 713 | } |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 714 | } |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 715 | addr[test_offset] = pattern; |
Simon Glass | 7ecbd4d | 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 | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 718 | /* |
| 719 | * Check for addr bits stuck low or shorted. |
| 720 | */ |
Simon Glass | 5512d5b | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 724 | for (offset = 1; offset < num_words; offset <<= 1) { |
| 725 | temp = addr[offset]; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 726 | if ((temp != pattern) && (offset != test_offset)) { |
| 727 | printf("\nFAILURE: Address bit stuck low or" |
| 728 | " shorted @ 0x%.8lx: expected 0x%.8lx," |
| 729 | " actual 0x%.8lx\n", |
David Feng | 102c051 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 730 | start_addr + offset*sizeof(vu_long), |
| 731 | pattern, temp); |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 732 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 733 | if (ctrlc()) |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 734 | return -1; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 735 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 736 | } |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 737 | addr[test_offset] = pattern; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 738 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 739 | |
Simon Glass | 7ecbd4d | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 752 | num_words++; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 753 | |
| 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 759 | addr[offset] = pattern; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 767 | temp = addr[offset]; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 768 | if (temp != pattern) { |
Simon Glass | c9638f5 | 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 | 102c051 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 771 | start_addr + offset*sizeof(vu_long), |
| 772 | pattern, temp); |
Paul Gortmaker | 87b22b7 | 2009-10-02 18:18:33 -0400 | [diff] [blame] | 773 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 774 | if (ctrlc()) |
Simon Glass | 51209b1 | 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 | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 778 | anti_pattern = ~pattern; |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 779 | addr[offset] = anti_pattern; |
Simon Glass | 7ecbd4d | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 788 | temp = addr[offset]; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 789 | if (temp != anti_pattern) { |
Simon Glass | c9638f5 | 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 | 102c051 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 792 | start_addr + offset*sizeof(vu_long), |
| 793 | anti_pattern, temp); |
Paul Gortmaker | 87b22b7 | 2009-10-02 18:18:33 -0400 | [diff] [blame] | 794 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 795 | if (ctrlc()) |
Simon Glass | 51209b1 | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 798 | addr[offset] = 0; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 799 | } |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 800 | |
Rasmus Villemoes | fea6730 | 2016-01-07 11:36:04 +0100 | [diff] [blame] | 801 | return errs; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 802 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 803 | |
Simon Glass | 5512d5b | 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 | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 806 | { |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 807 | vu_long *end; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 808 | vu_long *addr; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 809 | ulong errs = 0; |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 810 | ulong incr, length; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 811 | ulong val, readback; |
| 812 | |
Simon Glass | 51209b1 | 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 | 51209b1 | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 828 | length = (end_addr - start_addr) / sizeof(ulong); |
| 829 | end = buf + length; |
Simon Glass | 7ecbd4d | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 835 | for (addr = buf, val = pattern; addr < end; addr++) { |
Simon Glass | 7ecbd4d | 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 | 7ecbd4d | 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 | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 843 | for (addr = buf, val = pattern; addr < end; addr++) { |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 844 | WATCHDOG_RESET(); |
| 845 | readback = *addr; |
| 846 | if (readback != val) { |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 847 | ulong offset = addr - buf; |
| 848 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 849 | printf("\nMem error @ 0x%08X: " |
| 850 | "found %08lX, expected %08lX\n", |
David Feng | 102c051 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 851 | (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)), |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 852 | readback, val); |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 853 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 854 | if (ctrlc()) |
Simon Glass | 7ecbd4d | 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 | 7ecbd4d | 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 | fea6730 | 2016-01-07 11:36:04 +0100 | [diff] [blame] | 860 | return errs; |
Simon Glass | c9638f5 | 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 | 8c86bbe | 2013-02-24 17:33:20 +0000 | [diff] [blame] | 871 | ulong start, end; |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 872 | vu_long *buf, *dummy; |
Tom Rini | adcc570 | 2015-04-07 09:38:54 -0400 | [diff] [blame] | 873 | ulong iteration_limit = 0; |
Stefan Roese | a8c708e | 2020-03-05 07:21:29 +0100 | [diff] [blame] | 874 | ulong count = 0; |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 875 | ulong errs = 0; /* number of errors, or -1 if interrupted */ |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 876 | ulong pattern = 0; |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 877 | int iteration; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 878 | |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 879 | start = CONFIG_SYS_MEMTEST_START; |
| 880 | end = CONFIG_SYS_MEMTEST_END; |
| 881 | |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 882 | if (argc > 1) |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 883 | if (strict_strtoul(argv[1], 16, &start) < 0) |
| 884 | return CMD_RET_USAGE; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 885 | |
| 886 | if (argc > 2) |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 887 | if (strict_strtoul(argv[2], 16, &end) < 0) |
| 888 | return CMD_RET_USAGE; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 889 | |
| 890 | if (argc > 3) |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 891 | if (strict_strtoul(argv[3], 16, &pattern) < 0) |
| 892 | return CMD_RET_USAGE; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 893 | |
| 894 | if (argc > 4) |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 895 | if (strict_strtoul(argv[4], 16, &iteration_limit) < 0) |
| 896 | return CMD_RET_USAGE; |
| 897 | |
| 898 | if (end < start) { |
| 899 | printf("Refusing to do empty test\n"); |
| 900 | return -1; |
| 901 | } |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 902 | |
Michal Simek | dfe461d | 2016-02-24 08:36:02 +0100 | [diff] [blame] | 903 | printf("Testing %08lx ... %08lx:\n", start, end); |
Simon Glass | 8c86bbe | 2013-02-24 17:33:20 +0000 | [diff] [blame] | 904 | debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__, |
| 905 | start, end); |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 906 | |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 907 | buf = map_sysmem(start, end - start); |
| 908 | dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long)); |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 909 | for (iteration = 0; |
| 910 | !iteration_limit || iteration < iteration_limit; |
| 911 | iteration++) { |
| 912 | if (ctrlc()) { |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 913 | errs = -1UL; |
| 914 | break; |
| 915 | } |
| 916 | |
| 917 | printf("Iteration: %6d\r", iteration + 1); |
| 918 | debug("\n"); |
Stefan Roese | f14bfa7 | 2020-03-05 07:21:31 +0100 | [diff] [blame^] | 919 | if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) { |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 920 | errs = mem_test_alt(buf, start, end, dummy); |
| 921 | } else { |
| 922 | errs = mem_test_quick(buf, start, end, pattern, |
| 923 | iteration); |
| 924 | } |
| 925 | if (errs == -1UL) |
| 926 | break; |
Stefan Roese | a8c708e | 2020-03-05 07:21:29 +0100 | [diff] [blame] | 927 | count += errs; |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Stefan Roese | 54de244 | 2020-03-05 07:21:30 +0100 | [diff] [blame] | 930 | unmap_sysmem((void *)buf); |
| 931 | unmap_sysmem((void *)dummy); |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 932 | |
| 933 | if (errs == -1UL) { |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 934 | /* Memory test was aborted - write a newline to finish off */ |
| 935 | putc('\n'); |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 936 | } |
Stefan Roese | a8c708e | 2020-03-05 07:21:29 +0100 | [diff] [blame] | 937 | printf("Tested %d iteration(s) with %lu errors.\n", iteration, count); |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 938 | |
Stefan Roese | a8c708e | 2020-03-05 07:21:29 +0100 | [diff] [blame] | 939 | return errs != 0; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 940 | } |
Wolfgang Denk | a268170 | 2013-03-08 10:51:32 +0000 | [diff] [blame] | 941 | #endif /* CONFIG_CMD_MEMTEST */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 942 | |
| 943 | /* Modify memory. |
| 944 | * |
| 945 | * Syntax: |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 946 | * mm{.b, .w, .l, .q} {addr} |
| 947 | * nm{.b, .w, .l, .q} {addr} |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 948 | */ |
| 949 | static int |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 950 | 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] | 951 | { |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 952 | ulong addr; |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 953 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 954 | u64 i; |
| 955 | #else |
| 956 | ulong i; |
| 957 | #endif |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 958 | int nbytes, size; |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 959 | void *ptr = NULL; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 960 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 961 | if (argc != 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 962 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 963 | |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 964 | bootretry_reset_cmd_timeout(); /* got a good command to get here */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 965 | /* We use the last specified parameters, unless new ones are |
| 966 | * entered. |
| 967 | */ |
| 968 | addr = mm_last_addr; |
| 969 | size = mm_last_size; |
| 970 | |
| 971 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 972 | /* New command specified. Check for a size specification. |
| 973 | * Defaults to long if no or incorrect specification. |
| 974 | */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 975 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 976 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 977 | |
| 978 | /* Address is specified since argc > 1 |
| 979 | */ |
| 980 | addr = simple_strtoul(argv[1], NULL, 16); |
| 981 | addr += base_address; |
| 982 | } |
| 983 | |
| 984 | /* Print the address, followed by value. Then accept input for |
| 985 | * the next value. A non-converted value exits. |
| 986 | */ |
| 987 | do { |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 988 | ptr = map_sysmem(addr, size); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 989 | printf("%08lx:", addr); |
| 990 | if (size == 4) |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 991 | printf(" %08x", *((u32 *)ptr)); |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 992 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 993 | else if (size == 8) |
Masahiro Yamada | dee37fc | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 994 | printf(" %016llx", *((u64 *)ptr)); |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 995 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 996 | else if (size == 2) |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 997 | printf(" %04x", *((u16 *)ptr)); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 998 | else |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 999 | printf(" %02x", *((u8 *)ptr)); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1000 | |
Simon Glass | e1bf824 | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 1001 | nbytes = cli_readline(" ? "); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1002 | if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { |
| 1003 | /* <CR> pressed as only input, don't modify current |
| 1004 | * location and move to next. "-" pressed will go back. |
| 1005 | */ |
| 1006 | if (incrflag) |
| 1007 | addr += nbytes ? -size : size; |
| 1008 | nbytes = 1; |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 1009 | /* good enough to not time out */ |
| 1010 | bootretry_reset_cmd_timeout(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1011 | } |
| 1012 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 1013 | else if (nbytes == -2) { |
| 1014 | break; /* timed out, exit the command */ |
| 1015 | } |
| 1016 | #endif |
| 1017 | else { |
| 1018 | char *endp; |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1019 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1020 | i = simple_strtoull(console_buffer, &endp, 16); |
| 1021 | #else |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1022 | i = simple_strtoul(console_buffer, &endp, 16); |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1023 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1024 | nbytes = endp - console_buffer; |
| 1025 | if (nbytes) { |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1026 | /* good enough to not time out |
| 1027 | */ |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 1028 | bootretry_reset_cmd_timeout(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1029 | if (size == 4) |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1030 | *((u32 *)ptr) = i; |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1031 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1032 | else if (size == 8) |
| 1033 | *((u64 *)ptr) = i; |
| 1034 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1035 | else if (size == 2) |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1036 | *((u16 *)ptr) = i; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1037 | else |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1038 | *((u8 *)ptr) = i; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1039 | if (incrflag) |
| 1040 | addr += size; |
| 1041 | } |
| 1042 | } |
| 1043 | } while (nbytes); |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 1044 | if (ptr) |
| 1045 | unmap_sysmem(ptr); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1046 | |
| 1047 | mm_last_addr = addr; |
| 1048 | mm_last_size = size; |
| 1049 | return 0; |
| 1050 | } |
| 1051 | |
Mike Frysinger | 710b993 | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1052 | #ifdef CONFIG_CMD_CRC32 |
| 1053 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1054 | 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] | 1055 | { |
Simon Glass | d20a40d | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 1056 | int flags = 0; |
| 1057 | int ac; |
| 1058 | char * const *av; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1059 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 1060 | if (argc < 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1061 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1062 | |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1063 | av = argv + 1; |
| 1064 | ac = argc - 1; |
Daniel Thompson | 221a949 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1065 | #ifdef CONFIG_CRC32_VERIFY |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1066 | if (strcmp(*av, "-v") == 0) { |
Joe Hershberger | a69bdba | 2015-05-05 12:23:53 -0500 | [diff] [blame] | 1067 | flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV; |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1068 | av++; |
| 1069 | ac--; |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1070 | } |
Simon Glass | d20a40d | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 1071 | #endif |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1072 | |
Simon Glass | d20a40d | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 1073 | return hash_command("crc32", flags, cmdtp, flag, ac, av); |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1074 | } |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1075 | |
Mike Frysinger | 710b993 | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1076 | #endif |
| 1077 | |
Jean-Jacques Hiblot | 803e1a3 | 2019-07-02 14:23:26 +0200 | [diff] [blame] | 1078 | #ifdef CONFIG_CMD_RANDOM |
| 1079 | static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 1080 | { |
| 1081 | unsigned long addr, len; |
| 1082 | unsigned long seed; // NOT INITIALIZED ON PURPOSE |
| 1083 | unsigned int *buf, *start; |
| 1084 | unsigned char *buf8; |
| 1085 | unsigned int i; |
| 1086 | |
| 1087 | if (argc < 3 || argc > 4) { |
| 1088 | printf("usage: %s <addr> <len> [<seed>]\n", argv[0]); |
| 1089 | return 0; |
| 1090 | } |
| 1091 | |
| 1092 | len = simple_strtoul(argv[2], NULL, 16); |
| 1093 | addr = simple_strtoul(argv[1], NULL, 16); |
| 1094 | |
| 1095 | if (argc == 4) { |
| 1096 | seed = simple_strtoul(argv[3], NULL, 16); |
| 1097 | if (seed == 0) { |
| 1098 | printf("The seed cannot be 0. Using 0xDEADBEEF.\n"); |
| 1099 | seed = 0xDEADBEEF; |
| 1100 | } |
| 1101 | } else { |
| 1102 | seed = get_timer(0) ^ rand(); |
| 1103 | } |
| 1104 | |
| 1105 | srand(seed); |
| 1106 | start = map_sysmem(addr, len); |
| 1107 | buf = start; |
| 1108 | for (i = 0; i < (len / 4); i++) |
| 1109 | *buf++ = rand(); |
| 1110 | |
| 1111 | buf8 = (unsigned char *)buf; |
| 1112 | for (i = 0; i < (len % 4); i++) |
| 1113 | *buf8++ = rand() & 0xFF; |
| 1114 | |
| 1115 | unmap_sysmem(start); |
| 1116 | printf("%lu bytes filled with random data\n", len); |
| 1117 | return 1; |
| 1118 | } |
| 1119 | #endif |
| 1120 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1121 | /**************************************************/ |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1122 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1123 | md, 3, 1, do_mem_md, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1124 | "memory display", |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1125 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1126 | "[.b, .w, .l, .q] address [# of objects]" |
| 1127 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1128 | "[.b, .w, .l] address [# of objects]" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1129 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1130 | ); |
| 1131 | |
| 1132 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1133 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1134 | mm, 2, 1, do_mem_mm, |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1135 | "memory modify (auto-incrementing address)", |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1136 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1137 | "[.b, .w, .l, .q] address" |
| 1138 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1139 | "[.b, .w, .l] address" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1140 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1141 | ); |
| 1142 | |
| 1143 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1144 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1145 | nm, 2, 1, do_mem_nm, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1146 | "memory modify (constant address)", |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1147 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1148 | "[.b, .w, .l, .q] address" |
| 1149 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1150 | "[.b, .w, .l] address" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1151 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1152 | ); |
| 1153 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1154 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1155 | mw, 4, 1, do_mem_mw, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1156 | "memory write (fill)", |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1157 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1158 | "[.b, .w, .l, .q] address value [count]" |
| 1159 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1160 | "[.b, .w, .l] address value [count]" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1161 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1162 | ); |
| 1163 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1164 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1165 | cp, 4, 1, do_mem_cp, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1166 | "memory copy", |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1167 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1168 | "[.b, .w, .l, .q] source target count" |
| 1169 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1170 | "[.b, .w, .l] source target count" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1171 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1172 | ); |
| 1173 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1174 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1175 | cmp, 4, 1, do_mem_cmp, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1176 | "memory compare", |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1177 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1178 | "[.b, .w, .l, .q] addr1 addr2 count" |
| 1179 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1180 | "[.b, .w, .l] addr1 addr2 count" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1181 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1182 | ); |
| 1183 | |
Mike Frysinger | 710b993 | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1184 | #ifdef CONFIG_CMD_CRC32 |
| 1185 | |
Daniel Thompson | 221a949 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1186 | #ifndef CONFIG_CRC32_VERIFY |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1187 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1188 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1189 | crc32, 4, 1, do_mem_crc, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1190 | "checksum calculation", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1191 | "address count [addr]\n - compute CRC32 checksum [save at addr]" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1192 | ); |
| 1193 | |
Daniel Thompson | 221a949 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1194 | #else /* CONFIG_CRC32_VERIFY */ |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1195 | |
| 1196 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1197 | crc32, 5, 1, do_mem_crc, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1198 | "checksum calculation", |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1199 | "address count [addr]\n - compute CRC32 checksum [save at addr]\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1200 | "-v address count crc\n - verify crc of memory area" |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1201 | ); |
| 1202 | |
Daniel Thompson | 221a949 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1203 | #endif /* CONFIG_CRC32_VERIFY */ |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1204 | |
Mike Frysinger | 710b993 | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1205 | #endif |
| 1206 | |
Simon Glass | 15a33e4 | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 1207 | #ifdef CONFIG_CMD_MEMINFO |
Simon Glass | 15a33e4 | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 1208 | static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc, |
| 1209 | char * const argv[]) |
| 1210 | { |
Simon Glass | 428a6a1 | 2019-11-14 12:57:44 -0700 | [diff] [blame] | 1211 | puts("DRAM: "); |
| 1212 | print_size(gd->ram_size, "\n"); |
Simon Glass | 15a33e4 | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 1213 | |
| 1214 | return 0; |
| 1215 | } |
| 1216 | #endif |
| 1217 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1218 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1219 | base, 2, 1, do_mem_base, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1220 | "print or set address offset", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1221 | "\n - print address offset for memory commands\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1222 | "base off\n - set address offset for memory commands to 'off'" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1223 | ); |
| 1224 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1225 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1226 | loop, 3, 1, do_mem_loop, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1227 | "infinite loop on address range", |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1228 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1229 | "[.b, .w, .l, .q] address number_of_objects" |
| 1230 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1231 | "[.b, .w, .l] address number_of_objects" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1232 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1233 | ); |
| 1234 | |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 1235 | #ifdef CONFIG_LOOPW |
| 1236 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1237 | loopw, 4, 1, do_mem_loopw, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1238 | "infinite write loop on address range", |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1239 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1240 | "[.b, .w, .l, .q] address number_of_objects data_to_write" |
| 1241 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1242 | "[.b, .w, .l] address number_of_objects data_to_write" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1243 | #endif |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 1244 | ); |
| 1245 | #endif /* CONFIG_LOOPW */ |
| 1246 | |
Wolfgang Denk | a268170 | 2013-03-08 10:51:32 +0000 | [diff] [blame] | 1247 | #ifdef CONFIG_CMD_MEMTEST |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1248 | U_BOOT_CMD( |
Dirk Eibach | b6fc6fd | 2008-12-16 14:51:56 +0100 | [diff] [blame] | 1249 | mtest, 5, 1, do_mem_mtest, |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1250 | "simple RAM read/write test", |
| 1251 | "[start [end [pattern [iterations]]]]" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1252 | ); |
Wolfgang Denk | a268170 | 2013-03-08 10:51:32 +0000 | [diff] [blame] | 1253 | #endif /* CONFIG_CMD_MEMTEST */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1254 | |
Joel Johnson | 7273231 | 2020-01-29 09:17:18 -0700 | [diff] [blame] | 1255 | #ifdef CONFIG_CMD_MX_CYCLIC |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 1256 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1257 | mdc, 4, 1, do_mem_mdc, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1258 | "memory display cyclic", |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1259 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1260 | "[.b, .w, .l, .q] address count delay(ms)" |
| 1261 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1262 | "[.b, .w, .l] address count delay(ms)" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1263 | #endif |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 1264 | ); |
| 1265 | |
| 1266 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1267 | mwc, 4, 1, do_mem_mwc, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1268 | "memory write cyclic", |
Simon Glass | 4d979bf | 2019-12-28 10:45:10 -0700 | [diff] [blame] | 1269 | #ifdef MEM_SUPPORT_64BIT_DATA |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1270 | "[.b, .w, .l, .q] address value delay(ms)" |
| 1271 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1272 | "[.b, .w, .l] address value delay(ms)" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1273 | #endif |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 1274 | ); |
Joel Johnson | 7273231 | 2020-01-29 09:17:18 -0700 | [diff] [blame] | 1275 | #endif /* CONFIG_CMD_MX_CYCLIC */ |
Simon Glass | 15a33e4 | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 1276 | |
| 1277 | #ifdef CONFIG_CMD_MEMINFO |
| 1278 | U_BOOT_CMD( |
| 1279 | meminfo, 3, 1, do_mem_info, |
| 1280 | "display memory information", |
| 1281 | "" |
| 1282 | ); |
| 1283 | #endif |
Jean-Jacques Hiblot | 803e1a3 | 2019-07-02 14:23:26 +0200 | [diff] [blame] | 1284 | |
| 1285 | #ifdef CONFIG_CMD_RANDOM |
| 1286 | U_BOOT_CMD( |
| 1287 | random, 4, 0, do_random, |
| 1288 | "fill memory with random pattern", |
| 1289 | "<addr> <len> [<seed>]\n" |
| 1290 | " - Fill 'len' bytes of memory starting at 'addr' with random data\n" |
| 1291 | ); |
| 1292 | #endif |