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