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