blob: da02bbce95fa68ca171b56f337a74014641e9a34 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk38635852002-08-27 05:55:31 +00005 */
6
7/*
8 * Memory Functions
9 *
10 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
11 */
12
13#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -070014#include <console.h>
Simon Glass399ed9a2014-04-10 20:01:30 -060015#include <bootretry.h>
Simon Glassdec3c012014-04-10 20:01:25 -060016#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000017#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070018#include <console.h>
Simon Glassa606ffc2019-12-28 10:44:40 -070019#include <flash.h>
Simon Glass0bbd76f2013-02-24 20:30:22 +000020#include <hash.h>
Simon Glass0f2af882020-05-10 11:40:05 -060021#include <log.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050022#include <mapmem.h>
Simon Glass274e0b02020-05-10 11:39:56 -060023#include <rand.h>
Sergei Poselenov474dbb82008-04-09 16:09:41 +020024#include <watchdog.h>
Simon Glasse6d0ca22013-02-24 17:33:15 +000025#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060026#include <linux/bitops.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000027#include <linux/compiler.h>
Simon Glassdbd79542020-05-10 11:40:11 -060028#include <linux/delay.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000029
30DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000031
Simon Glassed38aef2020-05-10 11:40:03 -060032#ifndef CONFIG_SYS_MEMTEST_SCRATCH
33#define CONFIG_SYS_MEMTEST_SCRATCH 0
34#endif
35
Simon Glass683e39e2020-06-02 19:26:45 -060036/* Create a compile-time value */
37#if MEM_SUPPORT_64BIT_DATA
38#define HELP_Q ", .q"
39#else
40#define HELP_Q ""
41#endif
42
Simon Glassed38aef2020-05-10 11:40:03 -060043static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000044
45/* Display values from last command.
46 * Memory modify remembered values are different from display memory.
47 */
Scott Wood3ec02882015-03-19 09:43:12 -070048static ulong dp_last_addr, dp_last_size;
49static ulong dp_last_length = 0x40;
50static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000051
52static ulong base_address = 0;
53
54/* Memory Display
55 *
56 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080057 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000058 */
59#define DISP_LINE_LEN 16
Simon Glassed38aef2020-05-10 11:40:03 -060060static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
61 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000062{
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030063 ulong addr, length, bytes;
64 const void *buf;
wdenk874ac262003-07-24 23:38:38 +000065 int size;
wdenk38635852002-08-27 05:55:31 +000066 int rc = 0;
67
68 /* We use the last specified parameters, unless new ones are
69 * entered.
70 */
71 addr = dp_last_addr;
72 size = dp_last_size;
73 length = dp_last_length;
74
Wolfgang Denk3b683112010-07-17 01:06:04 +020075 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000076 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000077
78 if ((flag & CMD_FLAG_REPEAT) == 0) {
79 /* New command specified. Check for a size specification.
80 * Defaults to long if no or incorrect specification.
81 */
wdenk874ac262003-07-24 23:38:38 +000082 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
83 return 1;
wdenk38635852002-08-27 05:55:31 +000084
85 /* Address is specified since argc > 1
86 */
87 addr = simple_strtoul(argv[1], NULL, 16);
88 addr += base_address;
89
90 /* If another parameter, it is the length to display.
91 * Length is the number of objects, not number of bytes.
92 */
93 if (argc > 2)
94 length = simple_strtoul(argv[2], NULL, 16);
95 }
96
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030097 bytes = size * length;
98 buf = map_sysmem(addr, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +000099
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +0300100 /* Print the lines. */
101 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
102 addr += bytes;
103 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +0000104
105 dp_last_addr = addr;
106 dp_last_length = length;
107 dp_last_size = size;
108 return (rc);
109}
110
Simon Glassed38aef2020-05-10 11:40:03 -0600111static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
112 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000113{
114 return mod_mem (cmdtp, 1, flag, argc, argv);
115}
Simon Glassed38aef2020-05-10 11:40:03 -0600116
117static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
118 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000119{
120 return mod_mem (cmdtp, 0, flag, argc, argv);
121}
122
Simon Glassed38aef2020-05-10 11:40:03 -0600123static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
124 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000125{
Simon Glass3a6bca12020-06-02 19:26:44 -0600126#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800127 u64 writeval;
128#else
129 ulong writeval;
130#endif
131 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000132 int size;
Simon Glass3c4a2872015-03-05 12:25:18 -0700133 void *buf, *start;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000134 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000135
Wolfgang Denk3b683112010-07-17 01:06:04 +0200136 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000137 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000138
139 /* Check for size specification.
140 */
wdenk874ac262003-07-24 23:38:38 +0000141 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
142 return 1;
wdenk38635852002-08-27 05:55:31 +0000143
144 /* Address is specified since argc > 1
145 */
146 addr = simple_strtoul(argv[1], NULL, 16);
147 addr += base_address;
148
149 /* Get the value to write.
150 */
Simon Glass3a6bca12020-06-02 19:26:44 -0600151#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800152 writeval = simple_strtoull(argv[2], NULL, 16);
153#else
wdenk38635852002-08-27 05:55:31 +0000154 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800155#endif
wdenk38635852002-08-27 05:55:31 +0000156
157 /* Count ? */
158 if (argc == 4) {
159 count = simple_strtoul(argv[3], NULL, 16);
160 } else {
161 count = 1;
162 }
163
Simon Glasse6d0ca22013-02-24 17:33:15 +0000164 bytes = size * count;
Simon Glass3c4a2872015-03-05 12:25:18 -0700165 start = map_sysmem(addr, bytes);
166 buf = start;
wdenk38635852002-08-27 05:55:31 +0000167 while (count-- > 0) {
168 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800169 *((u32 *)buf) = (u32)writeval;
Simon Glass3a6bca12020-06-02 19:26:44 -0600170#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800171 else if (size == 8)
172 *((u64 *)buf) = (u64)writeval;
173#endif
wdenk38635852002-08-27 05:55:31 +0000174 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800175 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000176 else
York Sund8a405d2014-02-12 15:55:35 -0800177 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000178 buf += size;
wdenk38635852002-08-27 05:55:31 +0000179 }
Simon Glass3c4a2872015-03-05 12:25:18 -0700180 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000181 return 0;
182}
183
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700184#ifdef CONFIG_CMD_MX_CYCLIC
Simon Glassed38aef2020-05-10 11:40:03 -0600185static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
186 char *const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000187{
188 int i;
189 ulong count;
190
Wolfgang Denk3b683112010-07-17 01:06:04 +0200191 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000192 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000193
194 count = simple_strtoul(argv[3], NULL, 10);
195
196 for (;;) {
197 do_mem_md (NULL, 0, 3, argv);
198
199 /* delay for <count> ms... */
200 for (i=0; i<count; i++)
Simon Glass0db4b942020-05-10 11:40:10 -0600201 udelay(1000);
stroesefb5e0ac2004-12-16 17:42:39 +0000202
203 /* check for ctrl-c to abort... */
204 if (ctrlc()) {
205 puts("Abort\n");
206 return 0;
207 }
208 }
209
210 return 0;
211}
212
Simon Glassed38aef2020-05-10 11:40:03 -0600213static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
214 char *const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000215{
216 int i;
217 ulong count;
218
Wolfgang Denk3b683112010-07-17 01:06:04 +0200219 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000220 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000221
222 count = simple_strtoul(argv[3], NULL, 10);
223
224 for (;;) {
225 do_mem_mw (NULL, 0, 3, argv);
226
227 /* delay for <count> ms... */
228 for (i=0; i<count; i++)
Simon Glass0db4b942020-05-10 11:40:10 -0600229 udelay(1000);
stroesefb5e0ac2004-12-16 17:42:39 +0000230
231 /* check for ctrl-c to abort... */
232 if (ctrlc()) {
233 puts("Abort\n");
234 return 0;
235 }
236 }
237
238 return 0;
239}
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700240#endif /* CONFIG_CMD_MX_CYCLIC */
stroesefb5e0ac2004-12-16 17:42:39 +0000241
Simon Glassed38aef2020-05-10 11:40:03 -0600242static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
243 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000244{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000245 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000246 int size;
wdenk38635852002-08-27 05:55:31 +0000247 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000248 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000249 const void *buf1, *buf2, *base;
Simon Glass3a6bca12020-06-02 19:26:44 -0600250#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800251 u64 word1, word2;
252#else
253 ulong word1, word2;
254#endif
wdenk38635852002-08-27 05:55:31 +0000255
Wolfgang Denk3b683112010-07-17 01:06:04 +0200256 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000257 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000258
259 /* Check for size specification.
260 */
wdenk874ac262003-07-24 23:38:38 +0000261 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
262 return 1;
York Sun6c480012014-02-26 17:03:19 -0800263 type = size == 8 ? "double word" :
264 size == 4 ? "word" :
265 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000266
267 addr1 = simple_strtoul(argv[1], NULL, 16);
268 addr1 += base_address;
269
270 addr2 = simple_strtoul(argv[2], NULL, 16);
271 addr2 += base_address;
272
273 count = simple_strtoul(argv[3], NULL, 16);
274
Simon Glasse6d0ca22013-02-24 17:33:15 +0000275 bytes = size * count;
276 base = buf1 = map_sysmem(addr1, bytes);
277 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000278 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000279 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800280 word1 = *(u32 *)buf1;
281 word2 = *(u32 *)buf2;
Simon Glass3a6bca12020-06-02 19:26:44 -0600282#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800283 } else if (size == 8) {
284 word1 = *(u64 *)buf1;
285 word2 = *(u64 *)buf2;
286#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000287 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800288 word1 = *(u16 *)buf1;
289 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000290 } else {
York Sund8a405d2014-02-12 15:55:35 -0800291 word1 = *(u8 *)buf1;
292 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000293 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000294 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000295 ulong offset = buf1 - base;
Simon Glass3a6bca12020-06-02 19:26:44 -0600296#if MEM_SUPPORT_64BIT_DATA
Masahiro Yamadac7570a32018-08-06 20:47:40 +0900297 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
York Sun6c480012014-02-26 17:03:19 -0800298 type, (void *)(addr1 + offset), size, word1,
299 type, (void *)(addr2 + offset), size, word2);
300#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000301 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000302 type, (ulong)(addr1 + offset), size, word1,
303 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800304#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000305 rcode = 1;
306 break;
wdenk38635852002-08-27 05:55:31 +0000307 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000308
Simon Glasse6d0ca22013-02-24 17:33:15 +0000309 buf1 += size;
310 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200311
312 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000313 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200314 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000315 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000316 unmap_sysmem(buf1);
317 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000318
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000319 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000320 return rcode;
321}
322
Simon Glassed38aef2020-05-10 11:40:03 -0600323static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
324 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000325{
Fabio Estevamb03b0c82016-12-15 16:00:13 -0200326 ulong addr, dest, count;
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100327 void *src, *dst;
wdenk874ac262003-07-24 23:38:38 +0000328 int size;
wdenk38635852002-08-27 05:55:31 +0000329
Wolfgang Denk3b683112010-07-17 01:06:04 +0200330 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000331 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000332
333 /* Check for size specification.
334 */
wdenk874ac262003-07-24 23:38:38 +0000335 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
336 return 1;
wdenk38635852002-08-27 05:55:31 +0000337
338 addr = simple_strtoul(argv[1], NULL, 16);
339 addr += base_address;
340
341 dest = simple_strtoul(argv[2], NULL, 16);
342 dest += base_address;
343
344 count = simple_strtoul(argv[3], NULL, 16);
345
346 if (count == 0) {
347 puts ("Zero length ???\n");
348 return 1;
349 }
350
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100351 src = map_sysmem(addr, count * size);
352 dst = map_sysmem(dest, count * size);
353
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900354#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000355 /* check if we are copying to Flash */
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100356 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000357 int rc;
358
wdenk42c05472004-03-23 22:14:11 +0000359 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000360
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100361 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000362 if (rc != 0) {
Simon Glassa606ffc2019-12-28 10:44:40 -0700363 flash_perror(rc);
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100364 unmap_sysmem(src);
365 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000366 return (1);
367 }
368 puts ("done\n");
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100369 unmap_sysmem(src);
370 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000371 return 0;
372 }
wdenk7a428cc2003-06-15 22:40:42 +0000373#endif
374
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100375 memcpy(dst, src, count * size);
Masahiro Yamada787b0c52014-10-23 17:46:24 +0900376
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100377 unmap_sysmem(src);
378 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000379 return 0;
380}
381
Simon Glassed38aef2020-05-10 11:40:03 -0600382static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
383 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000384{
385 if (argc > 1) {
386 /* Set new base address.
387 */
388 base_address = simple_strtoul(argv[1], NULL, 16);
389 }
390 /* Print the current base address.
391 */
392 printf("Base Address: 0x%08lx\n", base_address);
393 return 0;
394}
395
Simon Glassed38aef2020-05-10 11:40:03 -0600396static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
397 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000398{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000399 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000400 int size;
Simon Glass3a6bca12020-06-02 19:26:44 -0600401#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800402 volatile u64 *llp;
403#endif
York Sund8a405d2014-02-12 15:55:35 -0800404 volatile u32 *longp;
405 volatile u16 *shortp;
406 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000407 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000408
Wolfgang Denk3b683112010-07-17 01:06:04 +0200409 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000410 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000411
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000412 /*
413 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000414 * Defaults to long if no or incorrect specification.
415 */
wdenk874ac262003-07-24 23:38:38 +0000416 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
417 return 1;
wdenk38635852002-08-27 05:55:31 +0000418
419 /* Address is always specified.
420 */
421 addr = simple_strtoul(argv[1], NULL, 16);
422
423 /* Length is the number of objects, not number of bytes.
424 */
425 length = simple_strtoul(argv[2], NULL, 16);
426
Simon Glasse6d0ca22013-02-24 17:33:15 +0000427 bytes = size * length;
428 buf = map_sysmem(addr, bytes);
429
wdenk38635852002-08-27 05:55:31 +0000430 /* We want to optimize the loops to run as fast as possible.
431 * If we have only one object, just run infinite loops.
432 */
433 if (length == 1) {
Simon Glass3a6bca12020-06-02 19:26:44 -0600434#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800435 if (size == 8) {
436 llp = (u64 *)buf;
437 for (;;)
438 i = *llp;
439 }
440#endif
wdenk38635852002-08-27 05:55:31 +0000441 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800442 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000443 for (;;)
444 i = *longp;
445 }
446 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800447 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000448 for (;;)
449 i = *shortp;
450 }
York Sund8a405d2014-02-12 15:55:35 -0800451 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000452 for (;;)
453 i = *cp;
454 }
455
Simon Glass3a6bca12020-06-02 19:26:44 -0600456#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800457 if (size == 8) {
458 for (;;) {
459 llp = (u64 *)buf;
460 i = length;
461 while (i-- > 0)
462 *llp++;
463 }
464 }
465#endif
wdenk38635852002-08-27 05:55:31 +0000466 if (size == 4) {
467 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800468 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000469 i = length;
470 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200471 *longp++;
wdenk38635852002-08-27 05:55:31 +0000472 }
473 }
474 if (size == 2) {
475 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800476 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000477 i = length;
478 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200479 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000480 }
481 }
482 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800483 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000484 i = length;
485 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200486 *cp++;
wdenk38635852002-08-27 05:55:31 +0000487 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000488 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700489
490 return 0;
wdenk38635852002-08-27 05:55:31 +0000491}
492
wdenk64519362004-07-11 17:40:54 +0000493#ifdef CONFIG_LOOPW
Simon Glassed38aef2020-05-10 11:40:03 -0600494static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
495 char *const argv[])
wdenk64519362004-07-11 17:40:54 +0000496{
York Sun6c480012014-02-26 17:03:19 -0800497 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000498 int size;
Simon Glass3a6bca12020-06-02 19:26:44 -0600499#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800500 volatile u64 *llp;
501 u64 data;
502#else
503 ulong data;
504#endif
York Sund8a405d2014-02-12 15:55:35 -0800505 volatile u32 *longp;
506 volatile u16 *shortp;
507 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000508 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000509
Wolfgang Denk3b683112010-07-17 01:06:04 +0200510 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000511 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000512
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000513 /*
514 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000515 * Defaults to long if no or incorrect specification.
516 */
517 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
518 return 1;
519
520 /* Address is always specified.
521 */
522 addr = simple_strtoul(argv[1], NULL, 16);
523
524 /* Length is the number of objects, not number of bytes.
525 */
526 length = simple_strtoul(argv[2], NULL, 16);
527
528 /* data to write */
Simon Glass3a6bca12020-06-02 19:26:44 -0600529#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800530 data = simple_strtoull(argv[3], NULL, 16);
531#else
wdenk64519362004-07-11 17:40:54 +0000532 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800533#endif
wdenk7dd13292004-07-11 20:04:51 +0000534
Simon Glasse6d0ca22013-02-24 17:33:15 +0000535 bytes = size * length;
536 buf = map_sysmem(addr, bytes);
537
wdenk64519362004-07-11 17:40:54 +0000538 /* We want to optimize the loops to run as fast as possible.
539 * If we have only one object, just run infinite loops.
540 */
541 if (length == 1) {
Simon Glass3a6bca12020-06-02 19:26:44 -0600542#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800543 if (size == 8) {
544 llp = (u64 *)buf;
545 for (;;)
546 *llp = data;
547 }
548#endif
wdenk64519362004-07-11 17:40:54 +0000549 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800550 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000551 for (;;)
552 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800553 }
wdenk64519362004-07-11 17:40:54 +0000554 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800555 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000556 for (;;)
557 *shortp = data;
558 }
York Sund8a405d2014-02-12 15:55:35 -0800559 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000560 for (;;)
561 *cp = data;
562 }
563
Simon Glass3a6bca12020-06-02 19:26:44 -0600564#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800565 if (size == 8) {
566 for (;;) {
567 llp = (u64 *)buf;
568 i = length;
569 while (i-- > 0)
570 *llp++ = data;
571 }
572 }
573#endif
wdenk64519362004-07-11 17:40:54 +0000574 if (size == 4) {
575 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800576 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000577 i = length;
578 while (i-- > 0)
579 *longp++ = data;
580 }
581 }
582 if (size == 2) {
583 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800584 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000585 i = length;
586 while (i-- > 0)
587 *shortp++ = data;
588 }
589 }
590 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800591 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000592 i = length;
593 while (i-- > 0)
594 *cp++ = data;
595 }
596}
597#endif /* CONFIG_LOOPW */
598
Tom Rinia5f02702013-03-12 10:07:19 -0400599#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000600static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
601 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000602{
Simon Glass8f2c7582013-02-24 17:33:16 +0000603 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000604 ulong errs = 0;
605 ulong val, readback;
606 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000607 vu_long offset;
608 vu_long test_offset;
609 vu_long pattern;
610 vu_long temp;
611 vu_long anti_pattern;
612 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000613 static const ulong bitpattern[] = {
614 0x00000001, /* single bit */
615 0x00000003, /* two adjacent bits */
616 0x00000007, /* three adjacent bits */
617 0x0000000F, /* four adjacent bits */
618 0x00000005, /* two non-adjacent bits */
619 0x00000015, /* three non-adjacent bits */
620 0x00000055, /* four non-adjacent bits */
621 0xaaaaaaaa, /* alternating 1/0 */
622 };
wdenk38635852002-08-27 05:55:31 +0000623
Simon Glassad02a012013-02-28 17:47:14 +0000624 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000625
Simon Glass130103e2013-02-24 17:33:18 +0000626 /*
627 * Data line test: write a pattern to the first
628 * location, write the 1's complement to a 'parking'
629 * address (changes the state of the data bus so a
630 * floating bus doesn't give a false OK), and then
631 * read the value back. Note that we read it back
632 * into a variable because the next time we read it,
633 * it might be right (been there, tough to explain to
634 * the quality guys why it prints a failure when the
635 * "is" and "should be" are obviously the same in the
636 * error message).
637 *
638 * Rather than exhaustively testing, we test some
639 * patterns by shifting '1' bits through a field of
640 * '0's and '0' bits through a field of '1's (i.e.
641 * pattern and ~pattern).
642 */
Simon Glassad02a012013-02-28 17:47:14 +0000643 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000644 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
645 val = bitpattern[j];
646 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000647 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000648 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000649 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000650 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000651 printf("FAILURE (data line): "
652 "expected %08lx, actual %08lx\n",
653 val, readback);
654 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000655 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000656 return -1;
wdenk38635852002-08-27 05:55:31 +0000657 }
658 *addr = ~val;
659 *dummy = val;
660 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000661 if (readback != ~val) {
662 printf("FAILURE (data line): "
663 "Is %08lx, should be %08lx\n",
664 readback, ~val);
665 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000666 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000667 return -1;
wdenk38635852002-08-27 05:55:31 +0000668 }
wdenk38635852002-08-27 05:55:31 +0000669 }
Simon Glass130103e2013-02-24 17:33:18 +0000670 }
wdenk38635852002-08-27 05:55:31 +0000671
Simon Glass130103e2013-02-24 17:33:18 +0000672 /*
673 * Based on code whose Original Author and Copyright
674 * information follows: Copyright (c) 1998 by Michael
675 * Barr. This software is placed into the public
676 * domain and may be used for any purpose. However,
677 * this notice must not be changed or removed and no
678 * warranty is either expressed or implied by its
679 * publication or distribution.
680 */
wdenk38635852002-08-27 05:55:31 +0000681
Simon Glass130103e2013-02-24 17:33:18 +0000682 /*
683 * Address line test
wdenk38635852002-08-27 05:55:31 +0000684
Simon Glass130103e2013-02-24 17:33:18 +0000685 * Description: Test the address bus wiring in a
686 * memory region by performing a walking
687 * 1's test on the relevant bits of the
688 * address and checking for aliasing.
689 * This test will find single-bit
690 * address failures such as stuck-high,
691 * stuck-low, and shorted pins. The base
692 * address and size of the region are
693 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000694
Simon Glass130103e2013-02-24 17:33:18 +0000695 * Notes: For best results, the selected base
696 * address should have enough LSB 0's to
697 * guarantee single address bit changes.
698 * For example, to test a 64-Kbyte
699 * region, select a base address on a
700 * 64-Kbyte boundary. Also, select the
701 * region size as a power-of-two if at
702 * all possible.
703 *
704 * Returns: 0 if the test succeeds, 1 if the test fails.
705 */
Simon Glass130103e2013-02-24 17:33:18 +0000706 pattern = (vu_long) 0xaaaaaaaa;
707 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000708
Simon Glassad02a012013-02-28 17:47:14 +0000709 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000710 /*
711 * Write the default pattern at each of the
712 * power-of-two offsets.
713 */
Simon Glassad02a012013-02-28 17:47:14 +0000714 for (offset = 1; offset < num_words; offset <<= 1)
715 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000716
717 /*
718 * Check for address bits stuck high.
719 */
720 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000721 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000722
Simon Glassad02a012013-02-28 17:47:14 +0000723 for (offset = 1; offset < num_words; offset <<= 1) {
724 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000725 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000726 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000727 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800728 start_addr + offset*sizeof(vu_long),
729 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400730 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000731 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000732 return -1;
wdenk38635852002-08-27 05:55:31 +0000733 }
Simon Glass130103e2013-02-24 17:33:18 +0000734 }
Simon Glassad02a012013-02-28 17:47:14 +0000735 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000736 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000737
Simon Glass130103e2013-02-24 17:33:18 +0000738 /*
739 * Check for addr bits stuck low or shorted.
740 */
Simon Glassad02a012013-02-28 17:47:14 +0000741 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
742 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000743
Simon Glassad02a012013-02-28 17:47:14 +0000744 for (offset = 1; offset < num_words; offset <<= 1) {
745 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000746 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000747 printf("\nFAILURE: Address bit stuck low or"
748 " shorted @ 0x%.8lx: expected 0x%.8lx,"
749 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800750 start_addr + offset*sizeof(vu_long),
751 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000752 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000753 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000754 return -1;
wdenk38635852002-08-27 05:55:31 +0000755 }
wdenk38635852002-08-27 05:55:31 +0000756 }
Simon Glassad02a012013-02-28 17:47:14 +0000757 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000758 }
wdenk38635852002-08-27 05:55:31 +0000759
Simon Glass130103e2013-02-24 17:33:18 +0000760 /*
761 * Description: Test the integrity of a physical
762 * memory device by performing an
763 * increment/decrement test over the
764 * entire region. In the process every
765 * storage bit in the device is tested
766 * as a zero and a one. The base address
767 * and the size of the region are
768 * selected by the caller.
769 *
770 * Returns: 0 if the test succeeds, 1 if the test fails.
771 */
Simon Glassad02a012013-02-28 17:47:14 +0000772 num_words++;
wdenk38635852002-08-27 05:55:31 +0000773
Simon Glass130103e2013-02-24 17:33:18 +0000774 /*
775 * Fill memory with a known pattern.
776 */
777 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
778 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000779 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000780 }
wdenk38635852002-08-27 05:55:31 +0000781
Simon Glass130103e2013-02-24 17:33:18 +0000782 /*
783 * Check each location and invert it for the second pass.
784 */
785 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
786 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000787 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000788 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000789 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000790 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800791 start_addr + offset*sizeof(vu_long),
792 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400793 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000794 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000795 return -1;
wdenk38635852002-08-27 05:55:31 +0000796 }
797
Simon Glass130103e2013-02-24 17:33:18 +0000798 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000799 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000800 }
801
802 /*
803 * Check each location for the inverted pattern and zero it.
804 */
805 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
806 WATCHDOG_RESET();
807 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000808 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000809 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000810 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000811 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800812 start_addr + offset*sizeof(vu_long),
813 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400814 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000815 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000816 return -1;
wdenk38635852002-08-27 05:55:31 +0000817 }
Simon Glassad02a012013-02-28 17:47:14 +0000818 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000819 }
Simon Glass57ee4432013-02-24 17:33:17 +0000820
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100821 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000822}
823
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100824static int compare_regions(volatile unsigned long *bufa,
825 volatile unsigned long *bufb, size_t count)
826{
827 volatile unsigned long *p1 = bufa;
828 volatile unsigned long *p2 = bufb;
829 int errs = 0;
830 size_t i;
831
832 for (i = 0; i < count; i++, p1++, p2++) {
833 if (*p1 != *p2) {
834 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
835 (unsigned long)*p1, (unsigned long)*p2,
836 *p1 ^ *p2, __ffs(*p1 ^ *p2),
837 (unsigned long)(i * sizeof(unsigned long)));
838 errs++;
839 }
840 }
841
842 return errs;
843}
844
845static ulong test_bitflip_comparison(volatile unsigned long *bufa,
846 volatile unsigned long *bufb, size_t count)
847{
848 volatile unsigned long *p1 = bufa;
849 volatile unsigned long *p2 = bufb;
850 unsigned int j, k;
851 unsigned long q;
852 size_t i;
853 int max;
854 int errs = 0;
855
856 max = sizeof(unsigned long) * 8;
857 for (k = 0; k < max; k++) {
858 q = 0x00000001L << k;
859 for (j = 0; j < 8; j++) {
860 WATCHDOG_RESET();
861 q = ~q;
862 p1 = (volatile unsigned long *)bufa;
863 p2 = (volatile unsigned long *)bufb;
864 for (i = 0; i < count; i++)
865 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
866
867 errs += compare_regions(bufa, bufb, count);
868 }
869
870 if (ctrlc())
871 return -1UL;
872 }
873
874 return errs;
875}
876
Simon Glassad02a012013-02-28 17:47:14 +0000877static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
878 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000879{
Simon Glassad02a012013-02-28 17:47:14 +0000880 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000881 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000882 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000883 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000884 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000885
Simon Glass57ee4432013-02-24 17:33:17 +0000886 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000887 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000888 if (iteration & 1) {
889 incr = -incr;
890 /*
891 * Flip the pattern each time to make lots of zeros and
892 * then, the next time, lots of ones. We decrement
893 * the "negative" patterns and increment the "positive"
894 * patterns to preserve this feature.
895 */
896 if (pattern & 0x80000000)
897 pattern = -pattern; /* complement & increment */
898 else
899 pattern = ~pattern;
900 }
Simon Glassad02a012013-02-28 17:47:14 +0000901 length = (end_addr - start_addr) / sizeof(ulong);
902 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000903 printf("\rPattern %08lX Writing..."
904 "%12s"
905 "\b\b\b\b\b\b\b\b\b\b",
906 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000907
Simon Glassad02a012013-02-28 17:47:14 +0000908 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000909 WATCHDOG_RESET();
910 *addr = val;
911 val += incr;
912 }
wdenk38635852002-08-27 05:55:31 +0000913
Simon Glass130103e2013-02-24 17:33:18 +0000914 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000915
Simon Glassad02a012013-02-28 17:47:14 +0000916 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000917 WATCHDOG_RESET();
918 readback = *addr;
919 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000920 ulong offset = addr - buf;
921
Simon Glass130103e2013-02-24 17:33:18 +0000922 printf("\nMem error @ 0x%08X: "
923 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800924 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000925 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000926 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000927 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000928 return -1;
wdenk38635852002-08-27 05:55:31 +0000929 }
Simon Glass130103e2013-02-24 17:33:18 +0000930 val += incr;
931 }
wdenk38635852002-08-27 05:55:31 +0000932
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100933 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000934}
935
936/*
937 * Perform a memory test. A more complete alternative test can be
938 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
939 * interrupted by ctrl-c or by a failure of one of the sub-tests.
940 */
Simon Glassed38aef2020-05-10 11:40:03 -0600941static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
942 char *const argv[])
Simon Glass8f2c7582013-02-24 17:33:16 +0000943{
Simon Glass51075252013-02-24 17:33:20 +0000944 ulong start, end;
Michal Simek9eaf6442020-05-04 13:54:40 +0200945 vu_long scratch_space;
946 vu_long *buf, *dummy = &scratch_space;
Tom Rinib9180882015-04-07 09:38:54 -0400947 ulong iteration_limit = 0;
Stefan Roese32265fc2020-03-05 07:21:29 +0100948 ulong count = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000949 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Machekd319f592015-04-01 13:50:41 +0200950 ulong pattern = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000951 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +0000952
Pavel Machekd319f592015-04-01 13:50:41 +0200953 start = CONFIG_SYS_MEMTEST_START;
954 end = CONFIG_SYS_MEMTEST_END;
955
Simon Glass8f2c7582013-02-24 17:33:16 +0000956 if (argc > 1)
Pavel Machekd319f592015-04-01 13:50:41 +0200957 if (strict_strtoul(argv[1], 16, &start) < 0)
958 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000959
960 if (argc > 2)
Pavel Machekd319f592015-04-01 13:50:41 +0200961 if (strict_strtoul(argv[2], 16, &end) < 0)
962 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000963
964 if (argc > 3)
Pavel Machekd319f592015-04-01 13:50:41 +0200965 if (strict_strtoul(argv[3], 16, &pattern) < 0)
966 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000967
968 if (argc > 4)
Pavel Machekd319f592015-04-01 13:50:41 +0200969 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
970 return CMD_RET_USAGE;
971
972 if (end < start) {
973 printf("Refusing to do empty test\n");
974 return -1;
975 }
Simon Glass8f2c7582013-02-24 17:33:16 +0000976
Michal Simek45f8e332016-02-24 08:36:02 +0100977 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass51075252013-02-24 17:33:20 +0000978 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
979 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +0000980
Simon Glassad02a012013-02-28 17:47:14 +0000981 buf = map_sysmem(start, end - start);
Simon Glass57ee4432013-02-24 17:33:17 +0000982 for (iteration = 0;
983 !iteration_limit || iteration < iteration_limit;
984 iteration++) {
985 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +0000986 errs = -1UL;
987 break;
988 }
989
990 printf("Iteration: %6d\r", iteration + 1);
991 debug("\n");
Stefan Roese1eb8b1e2020-03-05 07:21:31 +0100992 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
Simon Glassad02a012013-02-28 17:47:14 +0000993 errs = mem_test_alt(buf, start, end, dummy);
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100994 if (errs == -1UL)
995 break;
996 count += errs;
997 errs = test_bitflip_comparison(buf,
998 buf + (end - start) / 2,
999 (end - start) /
1000 sizeof(unsigned long));
Simon Glassad02a012013-02-28 17:47:14 +00001001 } else {
1002 errs = mem_test_quick(buf, start, end, pattern,
1003 iteration);
1004 }
1005 if (errs == -1UL)
1006 break;
Stefan Roese32265fc2020-03-05 07:21:29 +01001007 count += errs;
Simon Glassad02a012013-02-28 17:47:14 +00001008 }
1009
Stefan Roesec1d47db2020-03-05 07:21:30 +01001010 unmap_sysmem((void *)buf);
Simon Glass57ee4432013-02-24 17:33:17 +00001011
1012 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001013 /* Memory test was aborted - write a newline to finish off */
1014 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001015 }
Stefan Roese32265fc2020-03-05 07:21:29 +01001016 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
Simon Glass8f2c7582013-02-24 17:33:16 +00001017
Stefan Roese32265fc2020-03-05 07:21:29 +01001018 return errs != 0;
wdenk38635852002-08-27 05:55:31 +00001019}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001020#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001021
1022/* Modify memory.
1023 *
1024 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001025 * mm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001026 */
1027static int
Simon Glassed38aef2020-05-10 11:40:03 -06001028mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1029 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001030{
York Sun6c480012014-02-26 17:03:19 -08001031 ulong addr;
Simon Glass3a6bca12020-06-02 19:26:44 -06001032#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001033 u64 i;
1034#else
1035 ulong i;
1036#endif
wdenk874ac262003-07-24 23:38:38 +00001037 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001038 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001039
Wolfgang Denk3b683112010-07-17 01:06:04 +02001040 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001041 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001042
Simon Glass09007c42014-04-10 20:01:31 -06001043 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001044 /* We use the last specified parameters, unless new ones are
1045 * entered.
1046 */
1047 addr = mm_last_addr;
1048 size = mm_last_size;
1049
1050 if ((flag & CMD_FLAG_REPEAT) == 0) {
1051 /* New command specified. Check for a size specification.
1052 * Defaults to long if no or incorrect specification.
1053 */
wdenk874ac262003-07-24 23:38:38 +00001054 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1055 return 1;
wdenk38635852002-08-27 05:55:31 +00001056
1057 /* Address is specified since argc > 1
1058 */
1059 addr = simple_strtoul(argv[1], NULL, 16);
1060 addr += base_address;
1061 }
wdenk381669a2003-06-16 23:50:08 +00001062
wdenk38635852002-08-27 05:55:31 +00001063 /* Print the address, followed by value. Then accept input for
1064 * the next value. A non-converted value exits.
1065 */
1066 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001067 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001068 printf("%08lx:", addr);
1069 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001070 printf(" %08x", *((u32 *)ptr));
Simon Glass3a6bca12020-06-02 19:26:44 -06001071#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001072 else if (size == 8)
Masahiro Yamadac7570a32018-08-06 20:47:40 +09001073 printf(" %016llx", *((u64 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001074#endif
wdenk38635852002-08-27 05:55:31 +00001075 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001076 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001077 else
York Sund8a405d2014-02-12 15:55:35 -08001078 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001079
Simon Glassbe6aafc2014-04-10 20:01:27 -06001080 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001081 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1082 /* <CR> pressed as only input, don't modify current
1083 * location and move to next. "-" pressed will go back.
1084 */
1085 if (incrflag)
1086 addr += nbytes ? -size : size;
1087 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001088 /* good enough to not time out */
1089 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001090 }
1091#ifdef CONFIG_BOOT_RETRY_TIME
1092 else if (nbytes == -2) {
1093 break; /* timed out, exit the command */
1094 }
1095#endif
1096 else {
1097 char *endp;
Simon Glass3a6bca12020-06-02 19:26:44 -06001098#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001099 i = simple_strtoull(console_buffer, &endp, 16);
1100#else
wdenk38635852002-08-27 05:55:31 +00001101 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001102#endif
wdenk38635852002-08-27 05:55:31 +00001103 nbytes = endp - console_buffer;
1104 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001105 /* good enough to not time out
1106 */
Simon Glass09007c42014-04-10 20:01:31 -06001107 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001108 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001109 *((u32 *)ptr) = i;
Simon Glass3a6bca12020-06-02 19:26:44 -06001110#if MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001111 else if (size == 8)
1112 *((u64 *)ptr) = i;
1113#endif
wdenk38635852002-08-27 05:55:31 +00001114 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001115 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001116 else
York Sund8a405d2014-02-12 15:55:35 -08001117 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001118 if (incrflag)
1119 addr += size;
1120 }
1121 }
1122 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001123 if (ptr)
1124 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001125
1126 mm_last_addr = addr;
1127 mm_last_size = size;
1128 return 0;
1129}
1130
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001131#ifdef CONFIG_CMD_CRC32
1132
Simon Glassed38aef2020-05-10 11:40:03 -06001133static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1134 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001135{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001136 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001137 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001138 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001139
Simon Glass0bbd76f2013-02-24 20:30:22 +00001140 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001141 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001142
1143 av = argv + 1;
1144 ac = argc - 1;
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001145#ifdef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001146 if (strcmp(*av, "-v") == 0) {
Joe Hershberger5fcee9a2015-05-05 12:23:53 -05001147 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenk6203e402004-04-18 10:13:26 +00001148 av++;
1149 ac--;
wdenk6203e402004-04-18 10:13:26 +00001150 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001151#endif
wdenk6203e402004-04-18 10:13:26 +00001152
Simon Glass0bbd76f2013-02-24 20:30:22 +00001153 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001154}
wdenk6203e402004-04-18 10:13:26 +00001155
Robin Getz93d6cb02009-07-27 00:07:59 -04001156#endif
1157
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001158#ifdef CONFIG_CMD_RANDOM
Simon Glassed38aef2020-05-10 11:40:03 -06001159static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1160 char *const argv[])
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001161{
1162 unsigned long addr, len;
1163 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1164 unsigned int *buf, *start;
1165 unsigned char *buf8;
1166 unsigned int i;
1167
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001168 if (argc < 3 || argc > 4)
1169 return CMD_RET_USAGE;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001170
1171 len = simple_strtoul(argv[2], NULL, 16);
1172 addr = simple_strtoul(argv[1], NULL, 16);
1173
1174 if (argc == 4) {
1175 seed = simple_strtoul(argv[3], NULL, 16);
1176 if (seed == 0) {
1177 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1178 seed = 0xDEADBEEF;
1179 }
1180 } else {
1181 seed = get_timer(0) ^ rand();
1182 }
1183
1184 srand(seed);
1185 start = map_sysmem(addr, len);
1186 buf = start;
1187 for (i = 0; i < (len / 4); i++)
1188 *buf++ = rand();
1189
1190 buf8 = (unsigned char *)buf;
1191 for (i = 0; i < (len % 4); i++)
1192 *buf8++ = rand() & 0xFF;
1193
1194 unmap_sysmem(start);
1195 printf("%lu bytes filled with random data\n", len);
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001196
1197 return CMD_RET_SUCCESS;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001198}
1199#endif
1200
wdenk57b2d802003-06-27 21:31:46 +00001201/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001202U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001203 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001204 "memory display",
Simon Glass683e39e2020-06-02 19:26:45 -06001205 "[.b, .w, .l" HELP_Q "] address [# of objects]"
wdenk57b2d802003-06-27 21:31:46 +00001206);
1207
1208
wdenkf287a242003-07-01 21:06:45 +00001209U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001210 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001211 "memory modify (auto-incrementing address)",
Simon Glass683e39e2020-06-02 19:26:45 -06001212 "[.b, .w, .l" HELP_Q "] address"
wdenk57b2d802003-06-27 21:31:46 +00001213);
1214
1215
wdenkf287a242003-07-01 21:06:45 +00001216U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001217 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001218 "memory modify (constant address)",
Simon Glass683e39e2020-06-02 19:26:45 -06001219 "[.b, .w, .l" HELP_Q "] address"
wdenk57b2d802003-06-27 21:31:46 +00001220);
1221
wdenkf287a242003-07-01 21:06:45 +00001222U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001223 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001224 "memory write (fill)",
Simon Glass683e39e2020-06-02 19:26:45 -06001225 "[.b, .w, .l" HELP_Q "] address value [count]"
wdenk57b2d802003-06-27 21:31:46 +00001226);
1227
wdenkf287a242003-07-01 21:06:45 +00001228U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001229 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001230 "memory copy",
Simon Glass683e39e2020-06-02 19:26:45 -06001231 "[.b, .w, .l" HELP_Q "] source target count"
wdenk57b2d802003-06-27 21:31:46 +00001232);
1233
wdenkf287a242003-07-01 21:06:45 +00001234U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001235 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001236 "memory compare",
Simon Glass683e39e2020-06-02 19:26:45 -06001237 "[.b, .w, .l" HELP_Q "] addr1 addr2 count"
wdenk57b2d802003-06-27 21:31:46 +00001238);
1239
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001240#ifdef CONFIG_CMD_CRC32
1241
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001242#ifndef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001243
wdenkf287a242003-07-01 21:06:45 +00001244U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001245 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001246 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001247 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001248);
1249
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001250#else /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001251
1252U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001253 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001254 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001255 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001256 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001257);
1258
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001259#endif /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001260
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001261#endif
1262
Simon Glasseacd14f2012-11-30 13:01:20 +00001263#ifdef CONFIG_CMD_MEMINFO
Simon Glassed38aef2020-05-10 11:40:03 -06001264static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1265 char *const argv[])
Simon Glasseacd14f2012-11-30 13:01:20 +00001266{
Simon Glass320a5d42019-11-14 12:57:44 -07001267 puts("DRAM: ");
1268 print_size(gd->ram_size, "\n");
Simon Glasseacd14f2012-11-30 13:01:20 +00001269
1270 return 0;
1271}
1272#endif
1273
wdenkf287a242003-07-01 21:06:45 +00001274U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001275 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001276 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001277 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001278 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001279);
1280
wdenkf287a242003-07-01 21:06:45 +00001281U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001282 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001283 "infinite loop on address range",
Simon Glass683e39e2020-06-02 19:26:45 -06001284 "[.b, .w, .l" HELP_Q "] address number_of_objects"
wdenk57b2d802003-06-27 21:31:46 +00001285);
wdenk64519362004-07-11 17:40:54 +00001286
1287#ifdef CONFIG_LOOPW
1288U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001289 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001290 "infinite write loop on address range",
Simon Glass683e39e2020-06-02 19:26:45 -06001291 "[.b, .w, .l" HELP_Q "] address number_of_objects data_to_write"
wdenk64519362004-07-11 17:40:54 +00001292);
1293#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001294
Wolfgang Denk9d009282013-03-08 10:51:32 +00001295#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001296U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001297 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001298 "simple RAM read/write test",
1299 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001300);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001301#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001302
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001303#ifdef CONFIG_CMD_MX_CYCLIC
stroesefb5e0ac2004-12-16 17:42:39 +00001304U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001305 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001306 "memory display cyclic",
Simon Glass683e39e2020-06-02 19:26:45 -06001307 "[.b, .w, .l" HELP_Q "] address count delay(ms)"
stroesefb5e0ac2004-12-16 17:42:39 +00001308);
1309
1310U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001311 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001312 "memory write cyclic",
Simon Glass683e39e2020-06-02 19:26:45 -06001313 "[.b, .w, .l" HELP_Q "] address value delay(ms)"
stroesefb5e0ac2004-12-16 17:42:39 +00001314);
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001315#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001316
1317#ifdef CONFIG_CMD_MEMINFO
1318U_BOOT_CMD(
1319 meminfo, 3, 1, do_mem_info,
1320 "display memory information",
1321 ""
1322);
1323#endif
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001324
1325#ifdef CONFIG_CMD_RANDOM
1326U_BOOT_CMD(
1327 random, 4, 0, do_random,
1328 "fill memory with random pattern",
1329 "<addr> <len> [<seed>]\n"
1330 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1331);
1332#endif