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