blob: 423e6c1056d1eff7ac3eca479a6839cec7fbea7c [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 Glasseacd14f2012-11-30 13:01:20 +000026#include <linux/compiler.h>
27
28DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000029
Simon Glassed38aef2020-05-10 11:40:03 -060030#ifndef CONFIG_SYS_MEMTEST_SCRATCH
31#define CONFIG_SYS_MEMTEST_SCRATCH 0
32#endif
33
34static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000035
36/* Display values from last command.
37 * Memory modify remembered values are different from display memory.
38 */
Scott Wood3ec02882015-03-19 09:43:12 -070039static ulong dp_last_addr, dp_last_size;
40static ulong dp_last_length = 0x40;
41static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000042
43static ulong base_address = 0;
44
45/* Memory Display
46 *
47 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080048 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000049 */
50#define DISP_LINE_LEN 16
Simon Glassed38aef2020-05-10 11:40:03 -060051static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
52 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000053{
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030054 ulong addr, length, bytes;
55 const void *buf;
wdenk874ac262003-07-24 23:38:38 +000056 int size;
wdenk38635852002-08-27 05:55:31 +000057 int rc = 0;
58
59 /* We use the last specified parameters, unless new ones are
60 * entered.
61 */
62 addr = dp_last_addr;
63 size = dp_last_size;
64 length = dp_last_length;
65
Wolfgang Denk3b683112010-07-17 01:06:04 +020066 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000067 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000068
69 if ((flag & CMD_FLAG_REPEAT) == 0) {
70 /* New command specified. Check for a size specification.
71 * Defaults to long if no or incorrect specification.
72 */
wdenk874ac262003-07-24 23:38:38 +000073 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
74 return 1;
wdenk38635852002-08-27 05:55:31 +000075
76 /* Address is specified since argc > 1
77 */
78 addr = simple_strtoul(argv[1], NULL, 16);
79 addr += base_address;
80
81 /* If another parameter, it is the length to display.
82 * Length is the number of objects, not number of bytes.
83 */
84 if (argc > 2)
85 length = simple_strtoul(argv[2], NULL, 16);
86 }
87
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030088 bytes = size * length;
89 buf = map_sysmem(addr, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +000090
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030091 /* Print the lines. */
92 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
93 addr += bytes;
94 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +000095
96 dp_last_addr = addr;
97 dp_last_length = length;
98 dp_last_size = size;
99 return (rc);
100}
101
Simon Glassed38aef2020-05-10 11:40:03 -0600102static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
103 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000104{
105 return mod_mem (cmdtp, 1, flag, argc, argv);
106}
Simon Glassed38aef2020-05-10 11:40:03 -0600107
108static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
109 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000110{
111 return mod_mem (cmdtp, 0, flag, argc, argv);
112}
113
Simon Glassed38aef2020-05-10 11:40:03 -0600114static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
115 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000116{
Simon Glass8927bf22019-12-28 10:45:10 -0700117#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800118 u64 writeval;
119#else
120 ulong writeval;
121#endif
122 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000123 int size;
Simon Glass3c4a2872015-03-05 12:25:18 -0700124 void *buf, *start;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000125 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000126
Wolfgang Denk3b683112010-07-17 01:06:04 +0200127 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000128 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000129
130 /* Check for size specification.
131 */
wdenk874ac262003-07-24 23:38:38 +0000132 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
133 return 1;
wdenk38635852002-08-27 05:55:31 +0000134
135 /* Address is specified since argc > 1
136 */
137 addr = simple_strtoul(argv[1], NULL, 16);
138 addr += base_address;
139
140 /* Get the value to write.
141 */
Simon Glass8927bf22019-12-28 10:45:10 -0700142#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800143 writeval = simple_strtoull(argv[2], NULL, 16);
144#else
wdenk38635852002-08-27 05:55:31 +0000145 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800146#endif
wdenk38635852002-08-27 05:55:31 +0000147
148 /* Count ? */
149 if (argc == 4) {
150 count = simple_strtoul(argv[3], NULL, 16);
151 } else {
152 count = 1;
153 }
154
Simon Glasse6d0ca22013-02-24 17:33:15 +0000155 bytes = size * count;
Simon Glass3c4a2872015-03-05 12:25:18 -0700156 start = map_sysmem(addr, bytes);
157 buf = start;
wdenk38635852002-08-27 05:55:31 +0000158 while (count-- > 0) {
159 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800160 *((u32 *)buf) = (u32)writeval;
Simon Glass8927bf22019-12-28 10:45:10 -0700161#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800162 else if (size == 8)
163 *((u64 *)buf) = (u64)writeval;
164#endif
wdenk38635852002-08-27 05:55:31 +0000165 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800166 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000167 else
York Sund8a405d2014-02-12 15:55:35 -0800168 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000169 buf += size;
wdenk38635852002-08-27 05:55:31 +0000170 }
Simon Glass3c4a2872015-03-05 12:25:18 -0700171 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000172 return 0;
173}
174
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700175#ifdef CONFIG_CMD_MX_CYCLIC
Simon Glassed38aef2020-05-10 11:40:03 -0600176static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
177 char *const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000178{
179 int i;
180 ulong count;
181
Wolfgang Denk3b683112010-07-17 01:06:04 +0200182 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000183 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000184
185 count = simple_strtoul(argv[3], NULL, 10);
186
187 for (;;) {
188 do_mem_md (NULL, 0, 3, argv);
189
190 /* delay for <count> ms... */
191 for (i=0; i<count; i++)
Simon Glass0db4b942020-05-10 11:40:10 -0600192 udelay(1000);
stroesefb5e0ac2004-12-16 17:42:39 +0000193
194 /* check for ctrl-c to abort... */
195 if (ctrlc()) {
196 puts("Abort\n");
197 return 0;
198 }
199 }
200
201 return 0;
202}
203
Simon Glassed38aef2020-05-10 11:40:03 -0600204static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
205 char *const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000206{
207 int i;
208 ulong count;
209
Wolfgang Denk3b683112010-07-17 01:06:04 +0200210 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000211 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000212
213 count = simple_strtoul(argv[3], NULL, 10);
214
215 for (;;) {
216 do_mem_mw (NULL, 0, 3, argv);
217
218 /* delay for <count> ms... */
219 for (i=0; i<count; i++)
Simon Glass0db4b942020-05-10 11:40:10 -0600220 udelay(1000);
stroesefb5e0ac2004-12-16 17:42:39 +0000221
222 /* check for ctrl-c to abort... */
223 if (ctrlc()) {
224 puts("Abort\n");
225 return 0;
226 }
227 }
228
229 return 0;
230}
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700231#endif /* CONFIG_CMD_MX_CYCLIC */
stroesefb5e0ac2004-12-16 17:42:39 +0000232
Simon Glassed38aef2020-05-10 11:40:03 -0600233static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
234 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000235{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000236 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000237 int size;
wdenk38635852002-08-27 05:55:31 +0000238 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000239 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000240 const void *buf1, *buf2, *base;
Simon Glass8927bf22019-12-28 10:45:10 -0700241#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800242 u64 word1, word2;
243#else
244 ulong word1, word2;
245#endif
wdenk38635852002-08-27 05:55:31 +0000246
Wolfgang Denk3b683112010-07-17 01:06:04 +0200247 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000248 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000249
250 /* Check for size specification.
251 */
wdenk874ac262003-07-24 23:38:38 +0000252 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
253 return 1;
York Sun6c480012014-02-26 17:03:19 -0800254 type = size == 8 ? "double word" :
255 size == 4 ? "word" :
256 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000257
258 addr1 = simple_strtoul(argv[1], NULL, 16);
259 addr1 += base_address;
260
261 addr2 = simple_strtoul(argv[2], NULL, 16);
262 addr2 += base_address;
263
264 count = simple_strtoul(argv[3], NULL, 16);
265
Simon Glasse6d0ca22013-02-24 17:33:15 +0000266 bytes = size * count;
267 base = buf1 = map_sysmem(addr1, bytes);
268 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000269 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000270 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800271 word1 = *(u32 *)buf1;
272 word2 = *(u32 *)buf2;
Simon Glass8927bf22019-12-28 10:45:10 -0700273#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800274 } else if (size == 8) {
275 word1 = *(u64 *)buf1;
276 word2 = *(u64 *)buf2;
277#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000278 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800279 word1 = *(u16 *)buf1;
280 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000281 } else {
York Sund8a405d2014-02-12 15:55:35 -0800282 word1 = *(u8 *)buf1;
283 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000284 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000285 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000286 ulong offset = buf1 - base;
Simon Glass8927bf22019-12-28 10:45:10 -0700287#ifdef MEM_SUPPORT_64BIT_DATA
Masahiro Yamadac7570a32018-08-06 20:47:40 +0900288 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
York Sun6c480012014-02-26 17:03:19 -0800289 type, (void *)(addr1 + offset), size, word1,
290 type, (void *)(addr2 + offset), size, word2);
291#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000292 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000293 type, (ulong)(addr1 + offset), size, word1,
294 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800295#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000296 rcode = 1;
297 break;
wdenk38635852002-08-27 05:55:31 +0000298 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000299
Simon Glasse6d0ca22013-02-24 17:33:15 +0000300 buf1 += size;
301 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200302
303 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000304 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200305 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000306 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000307 unmap_sysmem(buf1);
308 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000309
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000310 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000311 return rcode;
312}
313
Simon Glassed38aef2020-05-10 11:40:03 -0600314static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
315 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000316{
Fabio Estevamb03b0c82016-12-15 16:00:13 -0200317 ulong addr, dest, count;
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100318 void *src, *dst;
wdenk874ac262003-07-24 23:38:38 +0000319 int size;
wdenk38635852002-08-27 05:55:31 +0000320
Wolfgang Denk3b683112010-07-17 01:06:04 +0200321 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000322 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000323
324 /* Check for size specification.
325 */
wdenk874ac262003-07-24 23:38:38 +0000326 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
327 return 1;
wdenk38635852002-08-27 05:55:31 +0000328
329 addr = simple_strtoul(argv[1], NULL, 16);
330 addr += base_address;
331
332 dest = simple_strtoul(argv[2], NULL, 16);
333 dest += base_address;
334
335 count = simple_strtoul(argv[3], NULL, 16);
336
337 if (count == 0) {
338 puts ("Zero length ???\n");
339 return 1;
340 }
341
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100342 src = map_sysmem(addr, count * size);
343 dst = map_sysmem(dest, count * size);
344
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900345#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000346 /* check if we are copying to Flash */
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100347 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000348 int rc;
349
wdenk42c05472004-03-23 22:14:11 +0000350 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000351
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100352 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000353 if (rc != 0) {
Simon Glassa606ffc2019-12-28 10:44:40 -0700354 flash_perror(rc);
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100355 unmap_sysmem(src);
356 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000357 return (1);
358 }
359 puts ("done\n");
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100360 unmap_sysmem(src);
361 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000362 return 0;
363 }
wdenk7a428cc2003-06-15 22:40:42 +0000364#endif
365
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100366 memcpy(dst, src, count * size);
Masahiro Yamada787b0c52014-10-23 17:46:24 +0900367
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100368 unmap_sysmem(src);
369 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000370 return 0;
371}
372
Simon Glassed38aef2020-05-10 11:40:03 -0600373static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
374 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000375{
376 if (argc > 1) {
377 /* Set new base address.
378 */
379 base_address = simple_strtoul(argv[1], NULL, 16);
380 }
381 /* Print the current base address.
382 */
383 printf("Base Address: 0x%08lx\n", base_address);
384 return 0;
385}
386
Simon Glassed38aef2020-05-10 11:40:03 -0600387static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
388 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000389{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000390 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000391 int size;
Simon Glass8927bf22019-12-28 10:45:10 -0700392#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800393 volatile u64 *llp;
394#endif
York Sund8a405d2014-02-12 15:55:35 -0800395 volatile u32 *longp;
396 volatile u16 *shortp;
397 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000398 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000399
Wolfgang Denk3b683112010-07-17 01:06:04 +0200400 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000401 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000402
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000403 /*
404 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000405 * Defaults to long if no or incorrect specification.
406 */
wdenk874ac262003-07-24 23:38:38 +0000407 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
408 return 1;
wdenk38635852002-08-27 05:55:31 +0000409
410 /* Address is always specified.
411 */
412 addr = simple_strtoul(argv[1], NULL, 16);
413
414 /* Length is the number of objects, not number of bytes.
415 */
416 length = simple_strtoul(argv[2], NULL, 16);
417
Simon Glasse6d0ca22013-02-24 17:33:15 +0000418 bytes = size * length;
419 buf = map_sysmem(addr, bytes);
420
wdenk38635852002-08-27 05:55:31 +0000421 /* We want to optimize the loops to run as fast as possible.
422 * If we have only one object, just run infinite loops.
423 */
424 if (length == 1) {
Simon Glass8927bf22019-12-28 10:45:10 -0700425#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800426 if (size == 8) {
427 llp = (u64 *)buf;
428 for (;;)
429 i = *llp;
430 }
431#endif
wdenk38635852002-08-27 05:55:31 +0000432 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800433 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000434 for (;;)
435 i = *longp;
436 }
437 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800438 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000439 for (;;)
440 i = *shortp;
441 }
York Sund8a405d2014-02-12 15:55:35 -0800442 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000443 for (;;)
444 i = *cp;
445 }
446
Simon Glass8927bf22019-12-28 10:45:10 -0700447#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800448 if (size == 8) {
449 for (;;) {
450 llp = (u64 *)buf;
451 i = length;
452 while (i-- > 0)
453 *llp++;
454 }
455 }
456#endif
wdenk38635852002-08-27 05:55:31 +0000457 if (size == 4) {
458 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800459 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000460 i = length;
461 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200462 *longp++;
wdenk38635852002-08-27 05:55:31 +0000463 }
464 }
465 if (size == 2) {
466 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800467 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000468 i = length;
469 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200470 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000471 }
472 }
473 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800474 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000475 i = length;
476 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200477 *cp++;
wdenk38635852002-08-27 05:55:31 +0000478 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000479 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700480
481 return 0;
wdenk38635852002-08-27 05:55:31 +0000482}
483
wdenk64519362004-07-11 17:40:54 +0000484#ifdef CONFIG_LOOPW
Simon Glassed38aef2020-05-10 11:40:03 -0600485static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
486 char *const argv[])
wdenk64519362004-07-11 17:40:54 +0000487{
York Sun6c480012014-02-26 17:03:19 -0800488 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000489 int size;
Simon Glass8927bf22019-12-28 10:45:10 -0700490#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800491 volatile u64 *llp;
492 u64 data;
493#else
494 ulong data;
495#endif
York Sund8a405d2014-02-12 15:55:35 -0800496 volatile u32 *longp;
497 volatile u16 *shortp;
498 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000499 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000500
Wolfgang Denk3b683112010-07-17 01:06:04 +0200501 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000502 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000503
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000504 /*
505 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000506 * Defaults to long if no or incorrect specification.
507 */
508 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
509 return 1;
510
511 /* Address is always specified.
512 */
513 addr = simple_strtoul(argv[1], NULL, 16);
514
515 /* Length is the number of objects, not number of bytes.
516 */
517 length = simple_strtoul(argv[2], NULL, 16);
518
519 /* data to write */
Simon Glass8927bf22019-12-28 10:45:10 -0700520#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800521 data = simple_strtoull(argv[3], NULL, 16);
522#else
wdenk64519362004-07-11 17:40:54 +0000523 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800524#endif
wdenk7dd13292004-07-11 20:04:51 +0000525
Simon Glasse6d0ca22013-02-24 17:33:15 +0000526 bytes = size * length;
527 buf = map_sysmem(addr, bytes);
528
wdenk64519362004-07-11 17:40:54 +0000529 /* We want to optimize the loops to run as fast as possible.
530 * If we have only one object, just run infinite loops.
531 */
532 if (length == 1) {
Simon Glass8927bf22019-12-28 10:45:10 -0700533#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800534 if (size == 8) {
535 llp = (u64 *)buf;
536 for (;;)
537 *llp = data;
538 }
539#endif
wdenk64519362004-07-11 17:40:54 +0000540 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800541 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000542 for (;;)
543 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800544 }
wdenk64519362004-07-11 17:40:54 +0000545 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800546 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000547 for (;;)
548 *shortp = data;
549 }
York Sund8a405d2014-02-12 15:55:35 -0800550 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000551 for (;;)
552 *cp = data;
553 }
554
Simon Glass8927bf22019-12-28 10:45:10 -0700555#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800556 if (size == 8) {
557 for (;;) {
558 llp = (u64 *)buf;
559 i = length;
560 while (i-- > 0)
561 *llp++ = data;
562 }
563 }
564#endif
wdenk64519362004-07-11 17:40:54 +0000565 if (size == 4) {
566 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800567 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000568 i = length;
569 while (i-- > 0)
570 *longp++ = data;
571 }
572 }
573 if (size == 2) {
574 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800575 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000576 i = length;
577 while (i-- > 0)
578 *shortp++ = data;
579 }
580 }
581 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800582 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000583 i = length;
584 while (i-- > 0)
585 *cp++ = data;
586 }
587}
588#endif /* CONFIG_LOOPW */
589
Tom Rinia5f02702013-03-12 10:07:19 -0400590#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000591static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
592 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000593{
Simon Glass8f2c7582013-02-24 17:33:16 +0000594 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000595 ulong errs = 0;
596 ulong val, readback;
597 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000598 vu_long offset;
599 vu_long test_offset;
600 vu_long pattern;
601 vu_long temp;
602 vu_long anti_pattern;
603 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000604 static const ulong bitpattern[] = {
605 0x00000001, /* single bit */
606 0x00000003, /* two adjacent bits */
607 0x00000007, /* three adjacent bits */
608 0x0000000F, /* four adjacent bits */
609 0x00000005, /* two non-adjacent bits */
610 0x00000015, /* three non-adjacent bits */
611 0x00000055, /* four non-adjacent bits */
612 0xaaaaaaaa, /* alternating 1/0 */
613 };
wdenk38635852002-08-27 05:55:31 +0000614
Simon Glassad02a012013-02-28 17:47:14 +0000615 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000616
Simon Glass130103e2013-02-24 17:33:18 +0000617 /*
618 * Data line test: write a pattern to the first
619 * location, write the 1's complement to a 'parking'
620 * address (changes the state of the data bus so a
621 * floating bus doesn't give a false OK), and then
622 * read the value back. Note that we read it back
623 * into a variable because the next time we read it,
624 * it might be right (been there, tough to explain to
625 * the quality guys why it prints a failure when the
626 * "is" and "should be" are obviously the same in the
627 * error message).
628 *
629 * Rather than exhaustively testing, we test some
630 * patterns by shifting '1' bits through a field of
631 * '0's and '0' bits through a field of '1's (i.e.
632 * pattern and ~pattern).
633 */
Simon Glassad02a012013-02-28 17:47:14 +0000634 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000635 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
636 val = bitpattern[j];
637 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000638 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000639 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000640 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000641 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000642 printf("FAILURE (data line): "
643 "expected %08lx, actual %08lx\n",
644 val, readback);
645 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000646 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000647 return -1;
wdenk38635852002-08-27 05:55:31 +0000648 }
649 *addr = ~val;
650 *dummy = val;
651 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000652 if (readback != ~val) {
653 printf("FAILURE (data line): "
654 "Is %08lx, should be %08lx\n",
655 readback, ~val);
656 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000657 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000658 return -1;
wdenk38635852002-08-27 05:55:31 +0000659 }
wdenk38635852002-08-27 05:55:31 +0000660 }
Simon Glass130103e2013-02-24 17:33:18 +0000661 }
wdenk38635852002-08-27 05:55:31 +0000662
Simon Glass130103e2013-02-24 17:33:18 +0000663 /*
664 * Based on code whose Original Author and Copyright
665 * information follows: Copyright (c) 1998 by Michael
666 * Barr. This software is placed into the public
667 * domain and may be used for any purpose. However,
668 * this notice must not be changed or removed and no
669 * warranty is either expressed or implied by its
670 * publication or distribution.
671 */
wdenk38635852002-08-27 05:55:31 +0000672
Simon Glass130103e2013-02-24 17:33:18 +0000673 /*
674 * Address line test
wdenk38635852002-08-27 05:55:31 +0000675
Simon Glass130103e2013-02-24 17:33:18 +0000676 * Description: Test the address bus wiring in a
677 * memory region by performing a walking
678 * 1's test on the relevant bits of the
679 * address and checking for aliasing.
680 * This test will find single-bit
681 * address failures such as stuck-high,
682 * stuck-low, and shorted pins. The base
683 * address and size of the region are
684 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000685
Simon Glass130103e2013-02-24 17:33:18 +0000686 * Notes: For best results, the selected base
687 * address should have enough LSB 0's to
688 * guarantee single address bit changes.
689 * For example, to test a 64-Kbyte
690 * region, select a base address on a
691 * 64-Kbyte boundary. Also, select the
692 * region size as a power-of-two if at
693 * all possible.
694 *
695 * Returns: 0 if the test succeeds, 1 if the test fails.
696 */
Simon Glass130103e2013-02-24 17:33:18 +0000697 pattern = (vu_long) 0xaaaaaaaa;
698 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000699
Simon Glassad02a012013-02-28 17:47:14 +0000700 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000701 /*
702 * Write the default pattern at each of the
703 * power-of-two offsets.
704 */
Simon Glassad02a012013-02-28 17:47:14 +0000705 for (offset = 1; offset < num_words; offset <<= 1)
706 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000707
708 /*
709 * Check for address bits stuck high.
710 */
711 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000712 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000713
Simon Glassad02a012013-02-28 17:47:14 +0000714 for (offset = 1; offset < num_words; offset <<= 1) {
715 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000716 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000717 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000718 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800719 start_addr + offset*sizeof(vu_long),
720 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400721 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000722 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000723 return -1;
wdenk38635852002-08-27 05:55:31 +0000724 }
Simon Glass130103e2013-02-24 17:33:18 +0000725 }
Simon Glassad02a012013-02-28 17:47:14 +0000726 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000727 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000728
Simon Glass130103e2013-02-24 17:33:18 +0000729 /*
730 * Check for addr bits stuck low or shorted.
731 */
Simon Glassad02a012013-02-28 17:47:14 +0000732 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
733 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000734
Simon Glassad02a012013-02-28 17:47:14 +0000735 for (offset = 1; offset < num_words; offset <<= 1) {
736 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000737 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000738 printf("\nFAILURE: Address bit stuck low or"
739 " shorted @ 0x%.8lx: expected 0x%.8lx,"
740 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800741 start_addr + offset*sizeof(vu_long),
742 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000743 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000744 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000745 return -1;
wdenk38635852002-08-27 05:55:31 +0000746 }
wdenk38635852002-08-27 05:55:31 +0000747 }
Simon Glassad02a012013-02-28 17:47:14 +0000748 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000749 }
wdenk38635852002-08-27 05:55:31 +0000750
Simon Glass130103e2013-02-24 17:33:18 +0000751 /*
752 * Description: Test the integrity of a physical
753 * memory device by performing an
754 * increment/decrement test over the
755 * entire region. In the process every
756 * storage bit in the device is tested
757 * as a zero and a one. The base address
758 * and the size of the region are
759 * selected by the caller.
760 *
761 * Returns: 0 if the test succeeds, 1 if the test fails.
762 */
Simon Glassad02a012013-02-28 17:47:14 +0000763 num_words++;
wdenk38635852002-08-27 05:55:31 +0000764
Simon Glass130103e2013-02-24 17:33:18 +0000765 /*
766 * Fill memory with a known pattern.
767 */
768 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
769 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000770 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000771 }
wdenk38635852002-08-27 05:55:31 +0000772
Simon Glass130103e2013-02-24 17:33:18 +0000773 /*
774 * Check each location and invert it for the second pass.
775 */
776 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
777 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000778 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000779 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000780 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000781 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800782 start_addr + offset*sizeof(vu_long),
783 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400784 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000785 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000786 return -1;
wdenk38635852002-08-27 05:55:31 +0000787 }
788
Simon Glass130103e2013-02-24 17:33:18 +0000789 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000790 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000791 }
792
793 /*
794 * Check each location for the inverted pattern and zero it.
795 */
796 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
797 WATCHDOG_RESET();
798 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000799 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000800 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000801 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000802 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800803 start_addr + offset*sizeof(vu_long),
804 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400805 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000806 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000807 return -1;
wdenk38635852002-08-27 05:55:31 +0000808 }
Simon Glassad02a012013-02-28 17:47:14 +0000809 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000810 }
Simon Glass57ee4432013-02-24 17:33:17 +0000811
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100812 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000813}
814
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100815static int compare_regions(volatile unsigned long *bufa,
816 volatile unsigned long *bufb, size_t count)
817{
818 volatile unsigned long *p1 = bufa;
819 volatile unsigned long *p2 = bufb;
820 int errs = 0;
821 size_t i;
822
823 for (i = 0; i < count; i++, p1++, p2++) {
824 if (*p1 != *p2) {
825 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
826 (unsigned long)*p1, (unsigned long)*p2,
827 *p1 ^ *p2, __ffs(*p1 ^ *p2),
828 (unsigned long)(i * sizeof(unsigned long)));
829 errs++;
830 }
831 }
832
833 return errs;
834}
835
836static ulong test_bitflip_comparison(volatile unsigned long *bufa,
837 volatile unsigned long *bufb, size_t count)
838{
839 volatile unsigned long *p1 = bufa;
840 volatile unsigned long *p2 = bufb;
841 unsigned int j, k;
842 unsigned long q;
843 size_t i;
844 int max;
845 int errs = 0;
846
847 max = sizeof(unsigned long) * 8;
848 for (k = 0; k < max; k++) {
849 q = 0x00000001L << k;
850 for (j = 0; j < 8; j++) {
851 WATCHDOG_RESET();
852 q = ~q;
853 p1 = (volatile unsigned long *)bufa;
854 p2 = (volatile unsigned long *)bufb;
855 for (i = 0; i < count; i++)
856 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
857
858 errs += compare_regions(bufa, bufb, count);
859 }
860
861 if (ctrlc())
862 return -1UL;
863 }
864
865 return errs;
866}
867
Simon Glassad02a012013-02-28 17:47:14 +0000868static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
869 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000870{
Simon Glassad02a012013-02-28 17:47:14 +0000871 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000872 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000873 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000874 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000875 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000876
Simon Glass57ee4432013-02-24 17:33:17 +0000877 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000878 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000879 if (iteration & 1) {
880 incr = -incr;
881 /*
882 * Flip the pattern each time to make lots of zeros and
883 * then, the next time, lots of ones. We decrement
884 * the "negative" patterns and increment the "positive"
885 * patterns to preserve this feature.
886 */
887 if (pattern & 0x80000000)
888 pattern = -pattern; /* complement & increment */
889 else
890 pattern = ~pattern;
891 }
Simon Glassad02a012013-02-28 17:47:14 +0000892 length = (end_addr - start_addr) / sizeof(ulong);
893 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000894 printf("\rPattern %08lX Writing..."
895 "%12s"
896 "\b\b\b\b\b\b\b\b\b\b",
897 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000898
Simon Glassad02a012013-02-28 17:47:14 +0000899 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000900 WATCHDOG_RESET();
901 *addr = val;
902 val += incr;
903 }
wdenk38635852002-08-27 05:55:31 +0000904
Simon Glass130103e2013-02-24 17:33:18 +0000905 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000906
Simon Glassad02a012013-02-28 17:47:14 +0000907 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000908 WATCHDOG_RESET();
909 readback = *addr;
910 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000911 ulong offset = addr - buf;
912
Simon Glass130103e2013-02-24 17:33:18 +0000913 printf("\nMem error @ 0x%08X: "
914 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800915 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000916 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000917 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000918 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000919 return -1;
wdenk38635852002-08-27 05:55:31 +0000920 }
Simon Glass130103e2013-02-24 17:33:18 +0000921 val += incr;
922 }
wdenk38635852002-08-27 05:55:31 +0000923
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100924 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000925}
926
927/*
928 * Perform a memory test. A more complete alternative test can be
929 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
930 * interrupted by ctrl-c or by a failure of one of the sub-tests.
931 */
Simon Glassed38aef2020-05-10 11:40:03 -0600932static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
933 char *const argv[])
Simon Glass8f2c7582013-02-24 17:33:16 +0000934{
Simon Glass51075252013-02-24 17:33:20 +0000935 ulong start, end;
Michal Simek9eaf6442020-05-04 13:54:40 +0200936 vu_long scratch_space;
937 vu_long *buf, *dummy = &scratch_space;
Tom Rinib9180882015-04-07 09:38:54 -0400938 ulong iteration_limit = 0;
Stefan Roese32265fc2020-03-05 07:21:29 +0100939 ulong count = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000940 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Machekd319f592015-04-01 13:50:41 +0200941 ulong pattern = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000942 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +0000943
Pavel Machekd319f592015-04-01 13:50:41 +0200944 start = CONFIG_SYS_MEMTEST_START;
945 end = CONFIG_SYS_MEMTEST_END;
946
Simon Glass8f2c7582013-02-24 17:33:16 +0000947 if (argc > 1)
Pavel Machekd319f592015-04-01 13:50:41 +0200948 if (strict_strtoul(argv[1], 16, &start) < 0)
949 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000950
951 if (argc > 2)
Pavel Machekd319f592015-04-01 13:50:41 +0200952 if (strict_strtoul(argv[2], 16, &end) < 0)
953 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000954
955 if (argc > 3)
Pavel Machekd319f592015-04-01 13:50:41 +0200956 if (strict_strtoul(argv[3], 16, &pattern) < 0)
957 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000958
959 if (argc > 4)
Pavel Machekd319f592015-04-01 13:50:41 +0200960 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
961 return CMD_RET_USAGE;
962
963 if (end < start) {
964 printf("Refusing to do empty test\n");
965 return -1;
966 }
Simon Glass8f2c7582013-02-24 17:33:16 +0000967
Michal Simek45f8e332016-02-24 08:36:02 +0100968 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass51075252013-02-24 17:33:20 +0000969 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
970 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +0000971
Simon Glassad02a012013-02-28 17:47:14 +0000972 buf = map_sysmem(start, end - start);
Simon Glass57ee4432013-02-24 17:33:17 +0000973 for (iteration = 0;
974 !iteration_limit || iteration < iteration_limit;
975 iteration++) {
976 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +0000977 errs = -1UL;
978 break;
979 }
980
981 printf("Iteration: %6d\r", iteration + 1);
982 debug("\n");
Stefan Roese1eb8b1e2020-03-05 07:21:31 +0100983 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
Simon Glassad02a012013-02-28 17:47:14 +0000984 errs = mem_test_alt(buf, start, end, dummy);
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100985 if (errs == -1UL)
986 break;
987 count += errs;
988 errs = test_bitflip_comparison(buf,
989 buf + (end - start) / 2,
990 (end - start) /
991 sizeof(unsigned long));
Simon Glassad02a012013-02-28 17:47:14 +0000992 } else {
993 errs = mem_test_quick(buf, start, end, pattern,
994 iteration);
995 }
996 if (errs == -1UL)
997 break;
Stefan Roese32265fc2020-03-05 07:21:29 +0100998 count += errs;
Simon Glassad02a012013-02-28 17:47:14 +0000999 }
1000
Stefan Roesec1d47db2020-03-05 07:21:30 +01001001 unmap_sysmem((void *)buf);
Simon Glass57ee4432013-02-24 17:33:17 +00001002
1003 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001004 /* Memory test was aborted - write a newline to finish off */
1005 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001006 }
Stefan Roese32265fc2020-03-05 07:21:29 +01001007 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
Simon Glass8f2c7582013-02-24 17:33:16 +00001008
Stefan Roese32265fc2020-03-05 07:21:29 +01001009 return errs != 0;
wdenk38635852002-08-27 05:55:31 +00001010}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001011#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001012
1013/* Modify memory.
1014 *
1015 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001016 * mm{.b, .w, .l, .q} {addr}
1017 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001018 */
1019static int
Simon Glassed38aef2020-05-10 11:40:03 -06001020mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1021 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001022{
York Sun6c480012014-02-26 17:03:19 -08001023 ulong addr;
Simon Glass8927bf22019-12-28 10:45:10 -07001024#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001025 u64 i;
1026#else
1027 ulong i;
1028#endif
wdenk874ac262003-07-24 23:38:38 +00001029 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001030 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001031
Wolfgang Denk3b683112010-07-17 01:06:04 +02001032 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001033 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001034
Simon Glass09007c42014-04-10 20:01:31 -06001035 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001036 /* We use the last specified parameters, unless new ones are
1037 * entered.
1038 */
1039 addr = mm_last_addr;
1040 size = mm_last_size;
1041
1042 if ((flag & CMD_FLAG_REPEAT) == 0) {
1043 /* New command specified. Check for a size specification.
1044 * Defaults to long if no or incorrect specification.
1045 */
wdenk874ac262003-07-24 23:38:38 +00001046 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1047 return 1;
wdenk38635852002-08-27 05:55:31 +00001048
1049 /* Address is specified since argc > 1
1050 */
1051 addr = simple_strtoul(argv[1], NULL, 16);
1052 addr += base_address;
1053 }
wdenk381669a2003-06-16 23:50:08 +00001054
wdenk38635852002-08-27 05:55:31 +00001055 /* Print the address, followed by value. Then accept input for
1056 * the next value. A non-converted value exits.
1057 */
1058 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001059 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001060 printf("%08lx:", addr);
1061 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001062 printf(" %08x", *((u32 *)ptr));
Simon Glass8927bf22019-12-28 10:45:10 -07001063#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001064 else if (size == 8)
Masahiro Yamadac7570a32018-08-06 20:47:40 +09001065 printf(" %016llx", *((u64 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001066#endif
wdenk38635852002-08-27 05:55:31 +00001067 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001068 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001069 else
York Sund8a405d2014-02-12 15:55:35 -08001070 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001071
Simon Glassbe6aafc2014-04-10 20:01:27 -06001072 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001073 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1074 /* <CR> pressed as only input, don't modify current
1075 * location and move to next. "-" pressed will go back.
1076 */
1077 if (incrflag)
1078 addr += nbytes ? -size : size;
1079 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001080 /* good enough to not time out */
1081 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001082 }
1083#ifdef CONFIG_BOOT_RETRY_TIME
1084 else if (nbytes == -2) {
1085 break; /* timed out, exit the command */
1086 }
1087#endif
1088 else {
1089 char *endp;
Simon Glass8927bf22019-12-28 10:45:10 -07001090#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001091 i = simple_strtoull(console_buffer, &endp, 16);
1092#else
wdenk38635852002-08-27 05:55:31 +00001093 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001094#endif
wdenk38635852002-08-27 05:55:31 +00001095 nbytes = endp - console_buffer;
1096 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001097 /* good enough to not time out
1098 */
Simon Glass09007c42014-04-10 20:01:31 -06001099 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001100 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001101 *((u32 *)ptr) = i;
Simon Glass8927bf22019-12-28 10:45:10 -07001102#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001103 else if (size == 8)
1104 *((u64 *)ptr) = i;
1105#endif
wdenk38635852002-08-27 05:55:31 +00001106 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001107 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001108 else
York Sund8a405d2014-02-12 15:55:35 -08001109 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001110 if (incrflag)
1111 addr += size;
1112 }
1113 }
1114 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001115 if (ptr)
1116 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001117
1118 mm_last_addr = addr;
1119 mm_last_size = size;
1120 return 0;
1121}
1122
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001123#ifdef CONFIG_CMD_CRC32
1124
Simon Glassed38aef2020-05-10 11:40:03 -06001125static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1126 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001127{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001128 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001129 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001130 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001131
Simon Glass0bbd76f2013-02-24 20:30:22 +00001132 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001133 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001134
1135 av = argv + 1;
1136 ac = argc - 1;
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001137#ifdef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001138 if (strcmp(*av, "-v") == 0) {
Joe Hershberger5fcee9a2015-05-05 12:23:53 -05001139 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenk6203e402004-04-18 10:13:26 +00001140 av++;
1141 ac--;
wdenk6203e402004-04-18 10:13:26 +00001142 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001143#endif
wdenk6203e402004-04-18 10:13:26 +00001144
Simon Glass0bbd76f2013-02-24 20:30:22 +00001145 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001146}
wdenk6203e402004-04-18 10:13:26 +00001147
Robin Getz93d6cb02009-07-27 00:07:59 -04001148#endif
1149
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001150#ifdef CONFIG_CMD_RANDOM
Simon Glassed38aef2020-05-10 11:40:03 -06001151static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1152 char *const argv[])
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001153{
1154 unsigned long addr, len;
1155 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1156 unsigned int *buf, *start;
1157 unsigned char *buf8;
1158 unsigned int i;
1159
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001160 if (argc < 3 || argc > 4)
1161 return CMD_RET_USAGE;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001162
1163 len = simple_strtoul(argv[2], NULL, 16);
1164 addr = simple_strtoul(argv[1], NULL, 16);
1165
1166 if (argc == 4) {
1167 seed = simple_strtoul(argv[3], NULL, 16);
1168 if (seed == 0) {
1169 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1170 seed = 0xDEADBEEF;
1171 }
1172 } else {
1173 seed = get_timer(0) ^ rand();
1174 }
1175
1176 srand(seed);
1177 start = map_sysmem(addr, len);
1178 buf = start;
1179 for (i = 0; i < (len / 4); i++)
1180 *buf++ = rand();
1181
1182 buf8 = (unsigned char *)buf;
1183 for (i = 0; i < (len % 4); i++)
1184 *buf8++ = rand() & 0xFF;
1185
1186 unmap_sysmem(start);
1187 printf("%lu bytes filled with random data\n", len);
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001188
1189 return CMD_RET_SUCCESS;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001190}
1191#endif
1192
wdenk57b2d802003-06-27 21:31:46 +00001193/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001194U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001195 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001196 "memory display",
Simon Glass8927bf22019-12-28 10:45:10 -07001197#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001198 "[.b, .w, .l, .q] address [# of objects]"
1199#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001200 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001201#endif
wdenk57b2d802003-06-27 21:31:46 +00001202);
1203
1204
wdenkf287a242003-07-01 21:06:45 +00001205U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001206 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001207 "memory modify (auto-incrementing address)",
Simon Glass8927bf22019-12-28 10:45:10 -07001208#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001209 "[.b, .w, .l, .q] address"
1210#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001211 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001212#endif
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 Glass8927bf22019-12-28 10:45:10 -07001219#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001220 "[.b, .w, .l, .q] address"
1221#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001222 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001223#endif
wdenk57b2d802003-06-27 21:31:46 +00001224);
1225
wdenkf287a242003-07-01 21:06:45 +00001226U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001227 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001228 "memory write (fill)",
Simon Glass8927bf22019-12-28 10:45:10 -07001229#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001230 "[.b, .w, .l, .q] address value [count]"
1231#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001232 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001233#endif
wdenk57b2d802003-06-27 21:31:46 +00001234);
1235
wdenkf287a242003-07-01 21:06:45 +00001236U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001237 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001238 "memory copy",
Simon Glass8927bf22019-12-28 10:45:10 -07001239#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001240 "[.b, .w, .l, .q] source target count"
1241#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001242 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001243#endif
wdenk57b2d802003-06-27 21:31:46 +00001244);
1245
wdenkf287a242003-07-01 21:06:45 +00001246U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001247 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001248 "memory compare",
Simon Glass8927bf22019-12-28 10:45:10 -07001249#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001250 "[.b, .w, .l, .q] addr1 addr2 count"
1251#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001252 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001253#endif
wdenk57b2d802003-06-27 21:31:46 +00001254);
1255
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001256#ifdef CONFIG_CMD_CRC32
1257
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001258#ifndef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001259
wdenkf287a242003-07-01 21:06:45 +00001260U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001261 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001262 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001263 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001264);
1265
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001266#else /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001267
1268U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001269 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001270 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001271 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001272 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001273);
1274
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001275#endif /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001276
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001277#endif
1278
Simon Glasseacd14f2012-11-30 13:01:20 +00001279#ifdef CONFIG_CMD_MEMINFO
Simon Glassed38aef2020-05-10 11:40:03 -06001280static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1281 char *const argv[])
Simon Glasseacd14f2012-11-30 13:01:20 +00001282{
Simon Glass320a5d42019-11-14 12:57:44 -07001283 puts("DRAM: ");
1284 print_size(gd->ram_size, "\n");
Simon Glasseacd14f2012-11-30 13:01:20 +00001285
1286 return 0;
1287}
1288#endif
1289
wdenkf287a242003-07-01 21:06:45 +00001290U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001291 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001292 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001293 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001294 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001295);
1296
wdenkf287a242003-07-01 21:06:45 +00001297U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001298 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001299 "infinite loop on address range",
Simon Glass8927bf22019-12-28 10:45:10 -07001300#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001301 "[.b, .w, .l, .q] address number_of_objects"
1302#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001303 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001304#endif
wdenk57b2d802003-06-27 21:31:46 +00001305);
wdenk64519362004-07-11 17:40:54 +00001306
1307#ifdef CONFIG_LOOPW
1308U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001309 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001310 "infinite write loop on address range",
Simon Glass8927bf22019-12-28 10:45:10 -07001311#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001312 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1313#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001314 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001315#endif
wdenk64519362004-07-11 17:40:54 +00001316);
1317#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001318
Wolfgang Denk9d009282013-03-08 10:51:32 +00001319#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001320U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001321 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001322 "simple RAM read/write test",
1323 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001324);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001325#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001326
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001327#ifdef CONFIG_CMD_MX_CYCLIC
stroesefb5e0ac2004-12-16 17:42:39 +00001328U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001329 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001330 "memory display cyclic",
Simon Glass8927bf22019-12-28 10:45:10 -07001331#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001332 "[.b, .w, .l, .q] address count delay(ms)"
1333#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001334 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001335#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001336);
1337
1338U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001339 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001340 "memory write cyclic",
Simon Glass8927bf22019-12-28 10:45:10 -07001341#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001342 "[.b, .w, .l, .q] address value delay(ms)"
1343#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001344 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001345#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001346);
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001347#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001348
1349#ifdef CONFIG_CMD_MEMINFO
1350U_BOOT_CMD(
1351 meminfo, 3, 1, do_mem_info,
1352 "display memory information",
1353 ""
1354);
1355#endif
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001356
1357#ifdef CONFIG_CMD_RANDOM
1358U_BOOT_CMD(
1359 random, 4, 0, do_random,
1360 "fill memory with random pattern",
1361 "<addr> <len> [<seed>]\n"
1362 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1363);
1364#endif