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