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