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