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