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