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