blob: 4ec450b050248d14f6c77bfd08c0c8f818e12359 [file] [log] [blame]
Tom Rini83d290c2018-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 Glass24b852a2015-11-08 23:47:45 -070014#include <console.h>
Simon Glass0098e172014-04-10 20:01:30 -060015#include <bootretry.h>
Simon Glass18d66532014-04-10 20:01:25 -060016#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000017#include <command.h>
Simon Glass24b852a2015-11-08 23:47:45 -070018#include <console.h>
Simon Glassd20a40d2013-02-24 20:30:22 +000019#include <hash.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050020#include <mapmem.h>
Sergei Poselenova6e6fc62008-04-09 16:09:41 +020021#include <watchdog.h>
Simon Glass0628ab82013-02-24 17:33:15 +000022#include <asm/io.h>
Simon Glass15a33e42012-11-30 13:01:20 +000023#include <linux/compiler.h>
24
25DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000026
Simon Glass8e169cc2013-02-24 17:33:29 +000027#ifndef CONFIG_SYS_MEMTEST_SCRATCH
28#define CONFIG_SYS_MEMTEST_SCRATCH 0
29#endif
30
Wolfgang Denk54841ab2010-06-28 22:00:46 +020031static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000032
33/* Display values from last command.
34 * Memory modify remembered values are different from display memory.
35 */
Scott Wood581508b2015-03-19 09:43:12 -070036static ulong dp_last_addr, dp_last_size;
37static ulong dp_last_length = 0x40;
38static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000039
40static ulong base_address = 0;
41
42/* Memory Display
43 *
44 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -080045 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000046 */
47#define DISP_LINE_LEN 16
Kim Phillips088f1b12012-10-29 13:34:31 +000048static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000049{
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030050 ulong addr, length, bytes;
51 const void *buf;
wdenk27b207f2003-07-24 23:38:38 +000052 int size;
wdenk38635852002-08-27 05:55:31 +000053 int rc = 0;
54
55 /* We use the last specified parameters, unless new ones are
56 * entered.
57 */
58 addr = dp_last_addr;
59 size = dp_last_size;
60 length = dp_last_length;
61
Wolfgang Denk47e26b12010-07-17 01:06:04 +020062 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000063 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000064
65 if ((flag & CMD_FLAG_REPEAT) == 0) {
66 /* New command specified. Check for a size specification.
67 * Defaults to long if no or incorrect specification.
68 */
wdenk27b207f2003-07-24 23:38:38 +000069 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
70 return 1;
wdenk38635852002-08-27 05:55:31 +000071
72 /* Address is specified since argc > 1
73 */
74 addr = simple_strtoul(argv[1], NULL, 16);
75 addr += base_address;
76
77 /* If another parameter, it is the length to display.
78 * Length is the number of objects, not number of bytes.
79 */
80 if (argc > 2)
81 length = simple_strtoul(argv[2], NULL, 16);
82 }
83
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030084 bytes = size * length;
85 buf = map_sysmem(addr, bytes);
wdenk2abbe072003-06-16 23:50:08 +000086
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030087 /* Print the lines. */
88 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
89 addr += bytes;
90 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +000091
92 dp_last_addr = addr;
93 dp_last_length = length;
94 dp_last_size = size;
95 return (rc);
96}
97
Kim Phillips088f1b12012-10-29 13:34:31 +000098static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000099{
100 return mod_mem (cmdtp, 1, flag, argc, argv);
101}
Kim Phillips088f1b12012-10-29 13:34:31 +0000102static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000103{
104 return mod_mem (cmdtp, 0, flag, argc, argv);
105}
106
Kim Phillips088f1b12012-10-29 13:34:31 +0000107static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000108{
York Sun4d1fd7f2014-02-26 17:03:19 -0800109#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
110 u64 writeval;
111#else
112 ulong writeval;
113#endif
114 ulong addr, count;
wdenk27b207f2003-07-24 23:38:38 +0000115 int size;
Simon Glasscc5e1962015-03-05 12:25:18 -0700116 void *buf, *start;
Simon Glass0628ab82013-02-24 17:33:15 +0000117 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000118
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200119 if ((argc < 3) || (argc > 4))
Simon Glass4c12eeb2011-12-10 08:44:01 +0000120 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000121
122 /* Check for size specification.
123 */
wdenk27b207f2003-07-24 23:38:38 +0000124 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
125 return 1;
wdenk38635852002-08-27 05:55:31 +0000126
127 /* Address is specified since argc > 1
128 */
129 addr = simple_strtoul(argv[1], NULL, 16);
130 addr += base_address;
131
132 /* Get the value to write.
133 */
York Sun4d1fd7f2014-02-26 17:03:19 -0800134#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
135 writeval = simple_strtoull(argv[2], NULL, 16);
136#else
wdenk38635852002-08-27 05:55:31 +0000137 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800138#endif
wdenk38635852002-08-27 05:55:31 +0000139
140 /* Count ? */
141 if (argc == 4) {
142 count = simple_strtoul(argv[3], NULL, 16);
143 } else {
144 count = 1;
145 }
146
Simon Glass0628ab82013-02-24 17:33:15 +0000147 bytes = size * count;
Simon Glasscc5e1962015-03-05 12:25:18 -0700148 start = map_sysmem(addr, bytes);
149 buf = start;
wdenk38635852002-08-27 05:55:31 +0000150 while (count-- > 0) {
151 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -0800152 *((u32 *)buf) = (u32)writeval;
York Sun4d1fd7f2014-02-26 17:03:19 -0800153#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
154 else if (size == 8)
155 *((u64 *)buf) = (u64)writeval;
156#endif
wdenk38635852002-08-27 05:55:31 +0000157 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -0800158 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000159 else
York Sun76698b42014-02-12 15:55:35 -0800160 *((u8 *)buf) = (u8)writeval;
Simon Glass0628ab82013-02-24 17:33:15 +0000161 buf += size;
wdenk38635852002-08-27 05:55:31 +0000162 }
Simon Glasscc5e1962015-03-05 12:25:18 -0700163 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000164 return 0;
165}
166
stroese4aaf29b2004-12-16 17:42:39 +0000167#ifdef CONFIG_MX_CYCLIC
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900168static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000169{
170 int i;
171 ulong count;
172
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200173 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000174 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000175
176 count = simple_strtoul(argv[3], NULL, 10);
177
178 for (;;) {
179 do_mem_md (NULL, 0, 3, argv);
180
181 /* delay for <count> ms... */
182 for (i=0; i<count; i++)
183 udelay (1000);
184
185 /* check for ctrl-c to abort... */
186 if (ctrlc()) {
187 puts("Abort\n");
188 return 0;
189 }
190 }
191
192 return 0;
193}
194
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900195static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000196{
197 int i;
198 ulong count;
199
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200200 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000201 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000202
203 count = simple_strtoul(argv[3], NULL, 10);
204
205 for (;;) {
206 do_mem_mw (NULL, 0, 3, argv);
207
208 /* delay for <count> ms... */
209 for (i=0; i<count; i++)
210 udelay (1000);
211
212 /* check for ctrl-c to abort... */
213 if (ctrlc()) {
214 puts("Abort\n");
215 return 0;
216 }
217 }
218
219 return 0;
220}
221#endif /* CONFIG_MX_CYCLIC */
222
Kim Phillips088f1b12012-10-29 13:34:31 +0000223static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000224{
Simon Glass0628ab82013-02-24 17:33:15 +0000225 ulong addr1, addr2, count, ngood, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000226 int size;
wdenk38635852002-08-27 05:55:31 +0000227 int rcode = 0;
Mike Frysinger054ea172012-01-20 09:07:21 +0000228 const char *type;
Simon Glass0628ab82013-02-24 17:33:15 +0000229 const void *buf1, *buf2, *base;
York Sun4d1fd7f2014-02-26 17:03:19 -0800230#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
231 u64 word1, word2;
232#else
233 ulong word1, word2;
234#endif
wdenk38635852002-08-27 05:55:31 +0000235
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200236 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000237 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000238
239 /* Check for size specification.
240 */
wdenk27b207f2003-07-24 23:38:38 +0000241 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
242 return 1;
York Sun4d1fd7f2014-02-26 17:03:19 -0800243 type = size == 8 ? "double word" :
244 size == 4 ? "word" :
245 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000246
247 addr1 = simple_strtoul(argv[1], NULL, 16);
248 addr1 += base_address;
249
250 addr2 = simple_strtoul(argv[2], NULL, 16);
251 addr2 += base_address;
252
253 count = simple_strtoul(argv[3], NULL, 16);
254
Simon Glass0628ab82013-02-24 17:33:15 +0000255 bytes = size * count;
256 base = buf1 = map_sysmem(addr1, bytes);
257 buf2 = map_sysmem(addr2, bytes);
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000258 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000259 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800260 word1 = *(u32 *)buf1;
261 word2 = *(u32 *)buf2;
York Sun4d1fd7f2014-02-26 17:03:19 -0800262#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
263 } else if (size == 8) {
264 word1 = *(u64 *)buf1;
265 word2 = *(u64 *)buf2;
266#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000267 } else if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800268 word1 = *(u16 *)buf1;
269 word2 = *(u16 *)buf2;
Mike Frysinger054ea172012-01-20 09:07:21 +0000270 } else {
York Sun76698b42014-02-12 15:55:35 -0800271 word1 = *(u8 *)buf1;
272 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000273 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000274 if (word1 != word2) {
Simon Glass0628ab82013-02-24 17:33:15 +0000275 ulong offset = buf1 - base;
York Sun4d1fd7f2014-02-26 17:03:19 -0800276#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
Masahiro Yamadadee37fc2018-08-06 20:47:40 +0900277 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
York Sun4d1fd7f2014-02-26 17:03:19 -0800278 type, (void *)(addr1 + offset), size, word1,
279 type, (void *)(addr2 + offset), size, word2);
280#else
Mike Frysinger054ea172012-01-20 09:07:21 +0000281 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glass0628ab82013-02-24 17:33:15 +0000282 type, (ulong)(addr1 + offset), size, word1,
283 type, (ulong)(addr2 + offset), size, word2);
York Sun4d1fd7f2014-02-26 17:03:19 -0800284#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000285 rcode = 1;
286 break;
wdenk38635852002-08-27 05:55:31 +0000287 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000288
Simon Glass0628ab82013-02-24 17:33:15 +0000289 buf1 += size;
290 buf2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200291
292 /* reset watchdog from time to time */
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000293 if ((ngood % (64 << 10)) == 0)
Stefan Roeseeaadb442010-09-13 11:10:34 +0200294 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000295 }
Simon Glass0628ab82013-02-24 17:33:15 +0000296 unmap_sysmem(buf1);
297 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000298
Mike Frysinger054ea172012-01-20 09:07:21 +0000299 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000300 return rcode;
301}
302
Kim Phillips088f1b12012-10-29 13:34:31 +0000303static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000304{
Fabio Estevamc2538422016-12-15 16:00:13 -0200305 ulong addr, dest, count;
Philippe Reynes787f10a2019-12-02 17:33:22 +0100306 void *src, *dst;
wdenk27b207f2003-07-24 23:38:38 +0000307 int size;
wdenk38635852002-08-27 05:55:31 +0000308
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200309 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000310 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000311
312 /* Check for size specification.
313 */
wdenk27b207f2003-07-24 23:38:38 +0000314 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
315 return 1;
wdenk38635852002-08-27 05:55:31 +0000316
317 addr = simple_strtoul(argv[1], NULL, 16);
318 addr += base_address;
319
320 dest = simple_strtoul(argv[2], NULL, 16);
321 dest += base_address;
322
323 count = simple_strtoul(argv[3], NULL, 16);
324
325 if (count == 0) {
326 puts ("Zero length ???\n");
327 return 1;
328 }
329
Philippe Reynes787f10a2019-12-02 17:33:22 +0100330 src = map_sysmem(addr, count * size);
331 dst = map_sysmem(dest, count * size);
332
Masahiro Yamadae856bdc2017-02-11 22:43:54 +0900333#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000334 /* check if we are copying to Flash */
Philippe Reynes787f10a2019-12-02 17:33:22 +0100335 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000336 int rc;
337
wdenk4b9206e2004-03-23 22:14:11 +0000338 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000339
Philippe Reynes787f10a2019-12-02 17:33:22 +0100340 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000341 if (rc != 0) {
342 flash_perror (rc);
Philippe Reynes787f10a2019-12-02 17:33:22 +0100343 unmap_sysmem(src);
344 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000345 return (1);
346 }
347 puts ("done\n");
Philippe Reynes787f10a2019-12-02 17:33:22 +0100348 unmap_sysmem(src);
349 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000350 return 0;
351 }
352#endif
353
Philippe Reynes787f10a2019-12-02 17:33:22 +0100354 memcpy(dst, src, count * size);
Masahiro Yamadaa3a47492014-10-23 17:46:24 +0900355
Philippe Reynes787f10a2019-12-02 17:33:22 +0100356 unmap_sysmem(src);
357 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000358 return 0;
359}
360
Kim Phillips088f1b12012-10-29 13:34:31 +0000361static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
362 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000363{
364 if (argc > 1) {
365 /* Set new base address.
366 */
367 base_address = simple_strtoul(argv[1], NULL, 16);
368 }
369 /* Print the current base address.
370 */
371 printf("Base Address: 0x%08lx\n", base_address);
372 return 0;
373}
374
Kim Phillips088f1b12012-10-29 13:34:31 +0000375static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
376 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000377{
Simon Glass0628ab82013-02-24 17:33:15 +0000378 ulong addr, length, i, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000379 int size;
York Sun4d1fd7f2014-02-26 17:03:19 -0800380#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
381 volatile u64 *llp;
382#endif
York Sun76698b42014-02-12 15:55:35 -0800383 volatile u32 *longp;
384 volatile u16 *shortp;
385 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000386 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000387
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200388 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000389 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000390
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000391 /*
392 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000393 * Defaults to long if no or incorrect specification.
394 */
wdenk27b207f2003-07-24 23:38:38 +0000395 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
396 return 1;
wdenk38635852002-08-27 05:55:31 +0000397
398 /* Address is always specified.
399 */
400 addr = simple_strtoul(argv[1], NULL, 16);
401
402 /* Length is the number of objects, not number of bytes.
403 */
404 length = simple_strtoul(argv[2], NULL, 16);
405
Simon Glass0628ab82013-02-24 17:33:15 +0000406 bytes = size * length;
407 buf = map_sysmem(addr, bytes);
408
wdenk38635852002-08-27 05:55:31 +0000409 /* We want to optimize the loops to run as fast as possible.
410 * If we have only one object, just run infinite loops.
411 */
412 if (length == 1) {
York Sun4d1fd7f2014-02-26 17:03:19 -0800413#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
414 if (size == 8) {
415 llp = (u64 *)buf;
416 for (;;)
417 i = *llp;
418 }
419#endif
wdenk38635852002-08-27 05:55:31 +0000420 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800421 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000422 for (;;)
423 i = *longp;
424 }
425 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800426 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000427 for (;;)
428 i = *shortp;
429 }
York Sun76698b42014-02-12 15:55:35 -0800430 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000431 for (;;)
432 i = *cp;
433 }
434
York Sun4d1fd7f2014-02-26 17:03:19 -0800435#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
436 if (size == 8) {
437 for (;;) {
438 llp = (u64 *)buf;
439 i = length;
440 while (i-- > 0)
441 *llp++;
442 }
443 }
444#endif
wdenk38635852002-08-27 05:55:31 +0000445 if (size == 4) {
446 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800447 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000448 i = length;
449 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200450 *longp++;
wdenk38635852002-08-27 05:55:31 +0000451 }
452 }
453 if (size == 2) {
454 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800455 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000456 i = length;
457 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200458 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000459 }
460 }
461 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800462 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000463 i = length;
464 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200465 *cp++;
wdenk38635852002-08-27 05:55:31 +0000466 }
Simon Glass0628ab82013-02-24 17:33:15 +0000467 unmap_sysmem(buf);
Simon Glass92765f422013-06-11 11:14:35 -0700468
469 return 0;
wdenk38635852002-08-27 05:55:31 +0000470}
471
wdenk56523f12004-07-11 17:40:54 +0000472#ifdef CONFIG_LOOPW
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900473static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
474 char * const argv[])
wdenk56523f12004-07-11 17:40:54 +0000475{
York Sun4d1fd7f2014-02-26 17:03:19 -0800476 ulong addr, length, i, bytes;
wdenk56523f12004-07-11 17:40:54 +0000477 int size;
York Sun4d1fd7f2014-02-26 17:03:19 -0800478#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
479 volatile u64 *llp;
480 u64 data;
481#else
482 ulong data;
483#endif
York Sun76698b42014-02-12 15:55:35 -0800484 volatile u32 *longp;
485 volatile u16 *shortp;
486 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000487 void *buf;
wdenk81050922004-07-11 20:04:51 +0000488
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200489 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000490 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000491
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000492 /*
493 * Check for a size specification.
wdenk56523f12004-07-11 17:40:54 +0000494 * Defaults to long if no or incorrect specification.
495 */
496 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
497 return 1;
498
499 /* Address is always specified.
500 */
501 addr = simple_strtoul(argv[1], NULL, 16);
502
503 /* Length is the number of objects, not number of bytes.
504 */
505 length = simple_strtoul(argv[2], NULL, 16);
506
507 /* data to write */
York Sun4d1fd7f2014-02-26 17:03:19 -0800508#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
509 data = simple_strtoull(argv[3], NULL, 16);
510#else
wdenk56523f12004-07-11 17:40:54 +0000511 data = simple_strtoul(argv[3], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800512#endif
wdenk81050922004-07-11 20:04:51 +0000513
Simon Glass0628ab82013-02-24 17:33:15 +0000514 bytes = size * length;
515 buf = map_sysmem(addr, bytes);
516
wdenk56523f12004-07-11 17:40:54 +0000517 /* We want to optimize the loops to run as fast as possible.
518 * If we have only one object, just run infinite loops.
519 */
520 if (length == 1) {
York Sun4d1fd7f2014-02-26 17:03:19 -0800521#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
522 if (size == 8) {
523 llp = (u64 *)buf;
524 for (;;)
525 *llp = data;
526 }
527#endif
wdenk56523f12004-07-11 17:40:54 +0000528 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800529 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000530 for (;;)
531 *longp = data;
York Sun4d1fd7f2014-02-26 17:03:19 -0800532 }
wdenk56523f12004-07-11 17:40:54 +0000533 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800534 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000535 for (;;)
536 *shortp = data;
537 }
York Sun76698b42014-02-12 15:55:35 -0800538 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000539 for (;;)
540 *cp = data;
541 }
542
York Sun4d1fd7f2014-02-26 17:03:19 -0800543#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
544 if (size == 8) {
545 for (;;) {
546 llp = (u64 *)buf;
547 i = length;
548 while (i-- > 0)
549 *llp++ = data;
550 }
551 }
552#endif
wdenk56523f12004-07-11 17:40:54 +0000553 if (size == 4) {
554 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800555 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000556 i = length;
557 while (i-- > 0)
558 *longp++ = data;
559 }
560 }
561 if (size == 2) {
562 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800563 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000564 i = length;
565 while (i-- > 0)
566 *shortp++ = data;
567 }
568 }
569 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800570 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000571 i = length;
572 while (i-- > 0)
573 *cp++ = data;
574 }
575}
576#endif /* CONFIG_LOOPW */
577
Tom Rini68149e92013-03-12 10:07:19 -0400578#ifdef CONFIG_CMD_MEMTEST
Simon Glass5512d5b2013-02-28 17:47:14 +0000579static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
580 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000581{
Simon Glassc9638f52013-02-24 17:33:16 +0000582 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000583 ulong errs = 0;
584 ulong val, readback;
585 int j;
Simon Glassc9638f52013-02-24 17:33:16 +0000586 vu_long offset;
587 vu_long test_offset;
588 vu_long pattern;
589 vu_long temp;
590 vu_long anti_pattern;
591 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000592 static const ulong bitpattern[] = {
593 0x00000001, /* single bit */
594 0x00000003, /* two adjacent bits */
595 0x00000007, /* three adjacent bits */
596 0x0000000F, /* four adjacent bits */
597 0x00000005, /* two non-adjacent bits */
598 0x00000015, /* three non-adjacent bits */
599 0x00000055, /* four non-adjacent bits */
600 0xaaaaaaaa, /* alternating 1/0 */
601 };
wdenk38635852002-08-27 05:55:31 +0000602
Simon Glass5512d5b2013-02-28 17:47:14 +0000603 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000604
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000605 /*
606 * Data line test: write a pattern to the first
607 * location, write the 1's complement to a 'parking'
608 * address (changes the state of the data bus so a
609 * floating bus doesn't give a false OK), and then
610 * read the value back. Note that we read it back
611 * into a variable because the next time we read it,
612 * it might be right (been there, tough to explain to
613 * the quality guys why it prints a failure when the
614 * "is" and "should be" are obviously the same in the
615 * error message).
616 *
617 * Rather than exhaustively testing, we test some
618 * patterns by shifting '1' bits through a field of
619 * '0's and '0' bits through a field of '1's (i.e.
620 * pattern and ~pattern).
621 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000622 addr = buf;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000623 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
624 val = bitpattern[j];
625 for (; val != 0; val <<= 1) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000626 *addr = val;
Simon Glassc9638f52013-02-24 17:33:16 +0000627 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000628 readback = *addr;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000629 if (readback != val) {
Simon Glassc9638f52013-02-24 17:33:16 +0000630 printf("FAILURE (data line): "
631 "expected %08lx, actual %08lx\n",
632 val, readback);
633 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000634 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000635 return -1;
wdenk38635852002-08-27 05:55:31 +0000636 }
637 *addr = ~val;
638 *dummy = val;
639 readback = *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000640 if (readback != ~val) {
641 printf("FAILURE (data line): "
642 "Is %08lx, should be %08lx\n",
643 readback, ~val);
644 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000645 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000646 return -1;
wdenk38635852002-08-27 05:55:31 +0000647 }
wdenk38635852002-08-27 05:55:31 +0000648 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000649 }
wdenk38635852002-08-27 05:55:31 +0000650
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000651 /*
652 * Based on code whose Original Author and Copyright
653 * information follows: Copyright (c) 1998 by Michael
654 * Barr. This software is placed into the public
655 * domain and may be used for any purpose. However,
656 * this notice must not be changed or removed and no
657 * warranty is either expressed or implied by its
658 * publication or distribution.
659 */
wdenk38635852002-08-27 05:55:31 +0000660
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000661 /*
662 * Address line test
wdenk38635852002-08-27 05:55:31 +0000663
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000664 * Description: Test the address bus wiring in a
665 * memory region by performing a walking
666 * 1's test on the relevant bits of the
667 * address and checking for aliasing.
668 * This test will find single-bit
669 * address failures such as stuck-high,
670 * stuck-low, and shorted pins. The base
671 * address and size of the region are
672 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000673
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000674 * Notes: For best results, the selected base
675 * address should have enough LSB 0's to
676 * guarantee single address bit changes.
677 * For example, to test a 64-Kbyte
678 * region, select a base address on a
679 * 64-Kbyte boundary. Also, select the
680 * region size as a power-of-two if at
681 * all possible.
682 *
683 * Returns: 0 if the test succeeds, 1 if the test fails.
684 */
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000685 pattern = (vu_long) 0xaaaaaaaa;
686 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000687
Simon Glass5512d5b2013-02-28 17:47:14 +0000688 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000689 /*
690 * Write the default pattern at each of the
691 * power-of-two offsets.
692 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000693 for (offset = 1; offset < num_words; offset <<= 1)
694 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000695
696 /*
697 * Check for address bits stuck high.
698 */
699 test_offset = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000700 addr[test_offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000701
Simon Glass5512d5b2013-02-28 17:47:14 +0000702 for (offset = 1; offset < num_words; offset <<= 1) {
703 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000704 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000705 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000706 " expected 0x%.8lx, actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800707 start_addr + offset*sizeof(vu_long),
708 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400709 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000710 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000711 return -1;
wdenk38635852002-08-27 05:55:31 +0000712 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000713 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000714 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000715 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000716
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000717 /*
718 * Check for addr bits stuck low or shorted.
719 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000720 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
721 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000722
Simon Glass5512d5b2013-02-28 17:47:14 +0000723 for (offset = 1; offset < num_words; offset <<= 1) {
724 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000725 if ((temp != pattern) && (offset != test_offset)) {
726 printf("\nFAILURE: Address bit stuck low or"
727 " shorted @ 0x%.8lx: expected 0x%.8lx,"
728 " actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800729 start_addr + offset*sizeof(vu_long),
730 pattern, temp);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000731 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000732 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000733 return -1;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000734 }
wdenk38635852002-08-27 05:55:31 +0000735 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000736 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000737 }
wdenk38635852002-08-27 05:55:31 +0000738
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000739 /*
740 * Description: Test the integrity of a physical
741 * memory device by performing an
742 * increment/decrement test over the
743 * entire region. In the process every
744 * storage bit in the device is tested
745 * as a zero and a one. The base address
746 * and the size of the region are
747 * selected by the caller.
748 *
749 * Returns: 0 if the test succeeds, 1 if the test fails.
750 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000751 num_words++;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000752
753 /*
754 * Fill memory with a known pattern.
755 */
756 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
757 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000758 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000759 }
760
761 /*
762 * Check each location and invert it for the second pass.
763 */
764 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
765 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000766 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000767 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000768 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000769 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800770 start_addr + offset*sizeof(vu_long),
771 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400772 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000773 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000774 return -1;
wdenk38635852002-08-27 05:55:31 +0000775 }
776
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000777 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000778 addr[offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000779 }
780
781 /*
782 * Check each location for the inverted pattern and zero it.
783 */
784 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
785 WATCHDOG_RESET();
786 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000787 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000788 if (temp != anti_pattern) {
Simon Glassc9638f52013-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 Feng102c0512014-02-12 16:10:08 +0800791 start_addr + offset*sizeof(vu_long),
792 anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400793 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000794 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000795 return -1;
wdenk38635852002-08-27 05:55:31 +0000796 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000797 addr[offset] = 0;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000798 }
Simon Glass51209b12013-02-24 17:33:17 +0000799
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100800 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000801}
wdenk38635852002-08-27 05:55:31 +0000802
Simon Glass5512d5b2013-02-28 17:47:14 +0000803static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
804 vu_long pattern, int iteration)
Simon Glassc9638f52013-02-24 17:33:16 +0000805{
Simon Glass5512d5b2013-02-28 17:47:14 +0000806 vu_long *end;
Simon Glassc9638f52013-02-24 17:33:16 +0000807 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000808 ulong errs = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000809 ulong incr, length;
Simon Glassc9638f52013-02-24 17:33:16 +0000810 ulong val, readback;
811
Simon Glass51209b12013-02-24 17:33:17 +0000812 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000813 incr = 1;
Simon Glass51209b12013-02-24 17:33:17 +0000814 if (iteration & 1) {
815 incr = -incr;
816 /*
817 * Flip the pattern each time to make lots of zeros and
818 * then, the next time, lots of ones. We decrement
819 * the "negative" patterns and increment the "positive"
820 * patterns to preserve this feature.
821 */
822 if (pattern & 0x80000000)
823 pattern = -pattern; /* complement & increment */
824 else
825 pattern = ~pattern;
826 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000827 length = (end_addr - start_addr) / sizeof(ulong);
828 end = buf + length;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000829 printf("\rPattern %08lX Writing..."
830 "%12s"
831 "\b\b\b\b\b\b\b\b\b\b",
832 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000833
Simon Glass5512d5b2013-02-28 17:47:14 +0000834 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000835 WATCHDOG_RESET();
836 *addr = val;
837 val += incr;
838 }
wdenk38635852002-08-27 05:55:31 +0000839
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000840 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000841
Simon Glass5512d5b2013-02-28 17:47:14 +0000842 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000843 WATCHDOG_RESET();
844 readback = *addr;
845 if (readback != val) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000846 ulong offset = addr - buf;
847
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000848 printf("\nMem error @ 0x%08X: "
849 "found %08lX, expected %08lX\n",
David Feng102c0512014-02-12 16:10:08 +0800850 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glass5512d5b2013-02-28 17:47:14 +0000851 readback, val);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000852 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000853 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000854 return -1;
wdenk38635852002-08-27 05:55:31 +0000855 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000856 val += incr;
857 }
wdenk38635852002-08-27 05:55:31 +0000858
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100859 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000860}
861
862/*
863 * Perform a memory test. A more complete alternative test can be
864 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
865 * interrupted by ctrl-c or by a failure of one of the sub-tests.
866 */
867static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
868 char * const argv[])
869{
Simon Glass8c86bbe2013-02-24 17:33:20 +0000870 ulong start, end;
Simon Glass5512d5b2013-02-28 17:47:14 +0000871 vu_long *buf, *dummy;
Tom Riniadcc5702015-04-07 09:38:54 -0400872 ulong iteration_limit = 0;
Simon Glassc9638f52013-02-24 17:33:16 +0000873 int ret;
Simon Glass51209b12013-02-24 17:33:17 +0000874 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200875 ulong pattern = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000876 int iteration;
Simon Glassc9638f52013-02-24 17:33:16 +0000877#if defined(CONFIG_SYS_ALT_MEMTEST)
878 const int alt_test = 1;
879#else
880 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +0000881#endif
Simon Glassc9638f52013-02-24 17:33:16 +0000882
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200883 start = CONFIG_SYS_MEMTEST_START;
884 end = CONFIG_SYS_MEMTEST_END;
885
Simon Glassc9638f52013-02-24 17:33:16 +0000886 if (argc > 1)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200887 if (strict_strtoul(argv[1], 16, &start) < 0)
888 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000889
890 if (argc > 2)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200891 if (strict_strtoul(argv[2], 16, &end) < 0)
892 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000893
894 if (argc > 3)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200895 if (strict_strtoul(argv[3], 16, &pattern) < 0)
896 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000897
898 if (argc > 4)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200899 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
900 return CMD_RET_USAGE;
901
902 if (end < start) {
903 printf("Refusing to do empty test\n");
904 return -1;
905 }
Simon Glassc9638f52013-02-24 17:33:16 +0000906
Michal Simekdfe461d2016-02-24 08:36:02 +0100907 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000908 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
909 start, end);
Simon Glass51209b12013-02-24 17:33:17 +0000910
Simon Glass5512d5b2013-02-28 17:47:14 +0000911 buf = map_sysmem(start, end - start);
912 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass51209b12013-02-24 17:33:17 +0000913 for (iteration = 0;
914 !iteration_limit || iteration < iteration_limit;
915 iteration++) {
916 if (ctrlc()) {
Simon Glass51209b12013-02-24 17:33:17 +0000917 errs = -1UL;
918 break;
919 }
920
921 printf("Iteration: %6d\r", iteration + 1);
922 debug("\n");
Simon Glass5512d5b2013-02-28 17:47:14 +0000923 if (alt_test) {
924 errs = mem_test_alt(buf, start, end, dummy);
925 } else {
926 errs = mem_test_quick(buf, start, end, pattern,
927 iteration);
928 }
929 if (errs == -1UL)
930 break;
931 }
932
933 /*
934 * Work-around for eldk-4.2 which gives this warning if we try to
935 * case in the unmap_sysmem() call:
936 * warning: initialization discards qualifiers from pointer target type
937 */
938 {
939 void *vbuf = (void *)buf;
940 void *vdummy = (void *)dummy;
941
942 unmap_sysmem(vbuf);
943 unmap_sysmem(vdummy);
Simon Glass51209b12013-02-24 17:33:17 +0000944 }
945
946 if (errs == -1UL) {
Simon Glassc44d4382013-02-24 17:33:19 +0000947 /* Memory test was aborted - write a newline to finish off */
948 putc('\n');
Simon Glass51209b12013-02-24 17:33:17 +0000949 ret = 1;
950 } else {
951 printf("Tested %d iteration(s) with %lu errors.\n",
952 iteration, errs);
953 ret = errs != 0;
954 }
Simon Glassc9638f52013-02-24 17:33:16 +0000955
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200956 return ret;
wdenk38635852002-08-27 05:55:31 +0000957}
Wolfgang Denka2681702013-03-08 10:51:32 +0000958#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +0000959
960/* Modify memory.
961 *
962 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -0800963 * mm{.b, .w, .l, .q} {addr}
964 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +0000965 */
966static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200967mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000968{
York Sun4d1fd7f2014-02-26 17:03:19 -0800969 ulong addr;
970#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
971 u64 i;
972#else
973 ulong i;
974#endif
wdenk27b207f2003-07-24 23:38:38 +0000975 int nbytes, size;
Simon Glass0628ab82013-02-24 17:33:15 +0000976 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +0000977
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200978 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000979 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000980
Simon Glassb26440f2014-04-10 20:01:31 -0600981 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +0000982 /* We use the last specified parameters, unless new ones are
983 * entered.
984 */
985 addr = mm_last_addr;
986 size = mm_last_size;
987
988 if ((flag & CMD_FLAG_REPEAT) == 0) {
989 /* New command specified. Check for a size specification.
990 * Defaults to long if no or incorrect specification.
991 */
wdenk27b207f2003-07-24 23:38:38 +0000992 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
993 return 1;
wdenk38635852002-08-27 05:55:31 +0000994
995 /* Address is specified since argc > 1
996 */
997 addr = simple_strtoul(argv[1], NULL, 16);
998 addr += base_address;
999 }
1000
1001 /* Print the address, followed by value. Then accept input for
1002 * the next value. A non-converted value exits.
1003 */
1004 do {
Simon Glass0628ab82013-02-24 17:33:15 +00001005 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001006 printf("%08lx:", addr);
1007 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001008 printf(" %08x", *((u32 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001009#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1010 else if (size == 8)
Masahiro Yamadadee37fc2018-08-06 20:47:40 +09001011 printf(" %016llx", *((u64 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001012#endif
wdenk38635852002-08-27 05:55:31 +00001013 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001014 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001015 else
York Sun76698b42014-02-12 15:55:35 -08001016 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001017
Simon Glasse1bf8242014-04-10 20:01:27 -06001018 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001019 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1020 /* <CR> pressed as only input, don't modify current
1021 * location and move to next. "-" pressed will go back.
1022 */
1023 if (incrflag)
1024 addr += nbytes ? -size : size;
1025 nbytes = 1;
Simon Glassb26440f2014-04-10 20:01:31 -06001026 /* good enough to not time out */
1027 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001028 }
1029#ifdef CONFIG_BOOT_RETRY_TIME
1030 else if (nbytes == -2) {
1031 break; /* timed out, exit the command */
1032 }
1033#endif
1034 else {
1035 char *endp;
York Sun4d1fd7f2014-02-26 17:03:19 -08001036#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1037 i = simple_strtoull(console_buffer, &endp, 16);
1038#else
wdenk38635852002-08-27 05:55:31 +00001039 i = simple_strtoul(console_buffer, &endp, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -08001040#endif
wdenk38635852002-08-27 05:55:31 +00001041 nbytes = endp - console_buffer;
1042 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001043 /* good enough to not time out
1044 */
Simon Glassb26440f2014-04-10 20:01:31 -06001045 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001046 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001047 *((u32 *)ptr) = i;
York Sun4d1fd7f2014-02-26 17:03:19 -08001048#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1049 else if (size == 8)
1050 *((u64 *)ptr) = i;
1051#endif
wdenk38635852002-08-27 05:55:31 +00001052 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001053 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001054 else
York Sun76698b42014-02-12 15:55:35 -08001055 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001056 if (incrflag)
1057 addr += size;
1058 }
1059 }
1060 } while (nbytes);
Simon Glass0628ab82013-02-24 17:33:15 +00001061 if (ptr)
1062 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001063
1064 mm_last_addr = addr;
1065 mm_last_size = size;
1066 return 0;
1067}
1068
Mike Frysinger710b9932010-12-21 14:19:51 -05001069#ifdef CONFIG_CMD_CRC32
1070
Kim Phillips088f1b12012-10-29 13:34:31 +00001071static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001072{
Simon Glassd20a40d2013-02-24 20:30:22 +00001073 int flags = 0;
1074 int ac;
1075 char * const *av;
wdenk38635852002-08-27 05:55:31 +00001076
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001077 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001078 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001079
wdenkc26e4542004-04-18 10:13:26 +00001080 av = argv + 1;
1081 ac = argc - 1;
Daniel Thompson221a9492017-05-19 17:26:58 +01001082#ifdef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001083 if (strcmp(*av, "-v") == 0) {
Joe Hershbergera69bdba2015-05-05 12:23:53 -05001084 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenkc26e4542004-04-18 10:13:26 +00001085 av++;
1086 ac--;
wdenkc26e4542004-04-18 10:13:26 +00001087 }
Simon Glassd20a40d2013-02-24 20:30:22 +00001088#endif
wdenkc26e4542004-04-18 10:13:26 +00001089
Simon Glassd20a40d2013-02-24 20:30:22 +00001090 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenkc26e4542004-04-18 10:13:26 +00001091}
wdenkc26e4542004-04-18 10:13:26 +00001092
Mike Frysinger710b9932010-12-21 14:19:51 -05001093#endif
1094
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001095#ifdef CONFIG_CMD_RANDOM
1096static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1097{
1098 unsigned long addr, len;
1099 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1100 unsigned int *buf, *start;
1101 unsigned char *buf8;
1102 unsigned int i;
1103
1104 if (argc < 3 || argc > 4) {
1105 printf("usage: %s <addr> <len> [<seed>]\n", argv[0]);
1106 return 0;
1107 }
1108
1109 len = simple_strtoul(argv[2], NULL, 16);
1110 addr = simple_strtoul(argv[1], NULL, 16);
1111
1112 if (argc == 4) {
1113 seed = simple_strtoul(argv[3], NULL, 16);
1114 if (seed == 0) {
1115 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1116 seed = 0xDEADBEEF;
1117 }
1118 } else {
1119 seed = get_timer(0) ^ rand();
1120 }
1121
1122 srand(seed);
1123 start = map_sysmem(addr, len);
1124 buf = start;
1125 for (i = 0; i < (len / 4); i++)
1126 *buf++ = rand();
1127
1128 buf8 = (unsigned char *)buf;
1129 for (i = 0; i < (len % 4); i++)
1130 *buf8++ = rand() & 0xFF;
1131
1132 unmap_sysmem(start);
1133 printf("%lu bytes filled with random data\n", len);
1134 return 1;
1135}
1136#endif
1137
wdenk8bde7f72003-06-27 21:31:46 +00001138/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001139U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001140 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001141 "memory display",
York Sun4d1fd7f2014-02-26 17:03:19 -08001142#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1143 "[.b, .w, .l, .q] address [# of objects]"
1144#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001145 "[.b, .w, .l] address [# of objects]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001146#endif
wdenk8bde7f72003-06-27 21:31:46 +00001147);
1148
1149
wdenk0d498392003-07-01 21:06:45 +00001150U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001151 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001152 "memory modify (auto-incrementing address)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001153#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1154 "[.b, .w, .l, .q] address"
1155#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001156 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001157#endif
wdenk8bde7f72003-06-27 21:31:46 +00001158);
1159
1160
wdenk0d498392003-07-01 21:06:45 +00001161U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001162 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001163 "memory modify (constant address)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001164#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1165 "[.b, .w, .l, .q] address"
1166#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001167 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001168#endif
wdenk8bde7f72003-06-27 21:31:46 +00001169);
1170
wdenk0d498392003-07-01 21:06:45 +00001171U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001172 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001173 "memory write (fill)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001174#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1175 "[.b, .w, .l, .q] address value [count]"
1176#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001177 "[.b, .w, .l] address value [count]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001178#endif
wdenk8bde7f72003-06-27 21:31:46 +00001179);
1180
wdenk0d498392003-07-01 21:06:45 +00001181U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001182 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001183 "memory copy",
York Sun4d1fd7f2014-02-26 17:03:19 -08001184#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1185 "[.b, .w, .l, .q] source target count"
1186#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001187 "[.b, .w, .l] source target count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001188#endif
wdenk8bde7f72003-06-27 21:31:46 +00001189);
1190
wdenk0d498392003-07-01 21:06:45 +00001191U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001192 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001193 "memory compare",
York Sun4d1fd7f2014-02-26 17:03:19 -08001194#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1195 "[.b, .w, .l, .q] addr1 addr2 count"
1196#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001197 "[.b, .w, .l] addr1 addr2 count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001198#endif
wdenk8bde7f72003-06-27 21:31:46 +00001199);
1200
Mike Frysinger710b9932010-12-21 14:19:51 -05001201#ifdef CONFIG_CMD_CRC32
1202
Daniel Thompson221a9492017-05-19 17:26:58 +01001203#ifndef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001204
wdenk0d498392003-07-01 21:06:45 +00001205U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001206 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001207 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001208 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001209);
1210
Daniel Thompson221a9492017-05-19 17:26:58 +01001211#else /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001212
1213U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001214 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001215 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001216 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001217 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001218);
1219
Daniel Thompson221a9492017-05-19 17:26:58 +01001220#endif /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001221
Mike Frysinger710b9932010-12-21 14:19:51 -05001222#endif
1223
Simon Glass15a33e42012-11-30 13:01:20 +00001224#ifdef CONFIG_CMD_MEMINFO
Simon Glass15a33e42012-11-30 13:01:20 +00001225static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1226 char * const argv[])
1227{
Simon Glass428a6a12019-11-14 12:57:44 -07001228 puts("DRAM: ");
1229 print_size(gd->ram_size, "\n");
Simon Glass15a33e42012-11-30 13:01:20 +00001230
1231 return 0;
1232}
1233#endif
1234
wdenk0d498392003-07-01 21:06:45 +00001235U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001236 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001237 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001238 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001239 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001240);
1241
wdenk0d498392003-07-01 21:06:45 +00001242U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001243 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001244 "infinite loop on address range",
York Sun4d1fd7f2014-02-26 17:03:19 -08001245#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1246 "[.b, .w, .l, .q] address number_of_objects"
1247#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001248 "[.b, .w, .l] address number_of_objects"
York Sun4d1fd7f2014-02-26 17:03:19 -08001249#endif
wdenk8bde7f72003-06-27 21:31:46 +00001250);
1251
wdenk56523f12004-07-11 17:40:54 +00001252#ifdef CONFIG_LOOPW
1253U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001254 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001255 "infinite write loop on address range",
York Sun4d1fd7f2014-02-26 17:03:19 -08001256#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1257 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1258#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001259 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun4d1fd7f2014-02-26 17:03:19 -08001260#endif
wdenk56523f12004-07-11 17:40:54 +00001261);
1262#endif /* CONFIG_LOOPW */
1263
Wolfgang Denka2681702013-03-08 10:51:32 +00001264#ifdef CONFIG_CMD_MEMTEST
wdenk0d498392003-07-01 21:06:45 +00001265U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001266 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001267 "simple RAM read/write test",
1268 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001269);
Wolfgang Denka2681702013-03-08 10:51:32 +00001270#endif /* CONFIG_CMD_MEMTEST */
wdenk8bde7f72003-06-27 21:31:46 +00001271
stroese4aaf29b2004-12-16 17:42:39 +00001272#ifdef CONFIG_MX_CYCLIC
1273U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001274 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001275 "memory display cyclic",
York Sun4d1fd7f2014-02-26 17:03:19 -08001276#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1277 "[.b, .w, .l, .q] address count delay(ms)"
1278#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001279 "[.b, .w, .l] address count delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001280#endif
stroese4aaf29b2004-12-16 17:42:39 +00001281);
1282
1283U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001284 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001285 "memory write cyclic",
York Sun4d1fd7f2014-02-26 17:03:19 -08001286#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1287 "[.b, .w, .l, .q] address value delay(ms)"
1288#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001289 "[.b, .w, .l] address value delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001290#endif
stroese4aaf29b2004-12-16 17:42:39 +00001291);
1292#endif /* CONFIG_MX_CYCLIC */
Simon Glass15a33e42012-11-30 13:01:20 +00001293
1294#ifdef CONFIG_CMD_MEMINFO
1295U_BOOT_CMD(
1296 meminfo, 3, 1, do_mem_info,
1297 "display memory information",
1298 ""
1299);
1300#endif
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001301
1302#ifdef CONFIG_CMD_RANDOM
1303U_BOOT_CMD(
1304 random, 4, 0, do_random,
1305 "fill memory with random pattern",
1306 "<addr> <len> [<seed>]\n"
1307 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1308);
1309#endif