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