blob: 6d54f1952727e2cefcfacf06e8b52b3b8091c7c6 [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 Glass0ee482522019-12-28 10:44:40 -070019#include <flash.h>
Simon Glassd20a40d2013-02-24 20:30:22 +000020#include <hash.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050021#include <mapmem.h>
Sergei Poselenova6e6fc62008-04-09 16:09:41 +020022#include <watchdog.h>
Simon Glass0628ab82013-02-24 17:33:15 +000023#include <asm/io.h>
Simon Glass15a33e42012-11-30 13:01:20 +000024#include <linux/compiler.h>
25
26DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000027
Simon Glass8e169cc2013-02-24 17:33:29 +000028#ifndef CONFIG_SYS_MEMTEST_SCRATCH
29#define CONFIG_SYS_MEMTEST_SCRATCH 0
30#endif
31
Wolfgang Denk54841ab2010-06-28 22:00:46 +020032static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000033
34/* Display values from last command.
35 * Memory modify remembered values are different from display memory.
36 */
Scott Wood581508b2015-03-19 09:43:12 -070037static ulong dp_last_addr, dp_last_size;
38static ulong dp_last_length = 0x40;
39static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000040
41static ulong base_address = 0;
42
43/* Memory Display
44 *
45 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -080046 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000047 */
48#define DISP_LINE_LEN 16
Kim Phillips088f1b12012-10-29 13:34:31 +000049static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000050{
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030051 ulong addr, length, bytes;
52 const void *buf;
wdenk27b207f2003-07-24 23:38:38 +000053 int size;
wdenk38635852002-08-27 05:55:31 +000054 int rc = 0;
55
56 /* We use the last specified parameters, unless new ones are
57 * entered.
58 */
59 addr = dp_last_addr;
60 size = dp_last_size;
61 length = dp_last_length;
62
Wolfgang Denk47e26b12010-07-17 01:06:04 +020063 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000064 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000065
66 if ((flag & CMD_FLAG_REPEAT) == 0) {
67 /* New command specified. Check for a size specification.
68 * Defaults to long if no or incorrect specification.
69 */
wdenk27b207f2003-07-24 23:38:38 +000070 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
71 return 1;
wdenk38635852002-08-27 05:55:31 +000072
73 /* Address is specified since argc > 1
74 */
75 addr = simple_strtoul(argv[1], NULL, 16);
76 addr += base_address;
77
78 /* If another parameter, it is the length to display.
79 * Length is the number of objects, not number of bytes.
80 */
81 if (argc > 2)
82 length = simple_strtoul(argv[2], NULL, 16);
83 }
84
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030085 bytes = size * length;
86 buf = map_sysmem(addr, bytes);
wdenk2abbe072003-06-16 23:50:08 +000087
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030088 /* Print the lines. */
89 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
90 addr += bytes;
91 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +000092
93 dp_last_addr = addr;
94 dp_last_length = length;
95 dp_last_size = size;
96 return (rc);
97}
98
Kim Phillips088f1b12012-10-29 13:34:31 +000099static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000100{
101 return mod_mem (cmdtp, 1, flag, argc, argv);
102}
Kim Phillips088f1b12012-10-29 13:34:31 +0000103static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000104{
105 return mod_mem (cmdtp, 0, flag, argc, argv);
106}
107
Kim Phillips088f1b12012-10-29 13:34:31 +0000108static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000109{
Simon Glass4d979bf2019-12-28 10:45:10 -0700110#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800111 u64 writeval;
112#else
113 ulong writeval;
114#endif
115 ulong addr, count;
wdenk27b207f2003-07-24 23:38:38 +0000116 int size;
Simon Glasscc5e1962015-03-05 12:25:18 -0700117 void *buf, *start;
Simon Glass0628ab82013-02-24 17:33:15 +0000118 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000119
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200120 if ((argc < 3) || (argc > 4))
Simon Glass4c12eeb2011-12-10 08:44:01 +0000121 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000122
123 /* Check for size specification.
124 */
wdenk27b207f2003-07-24 23:38:38 +0000125 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
126 return 1;
wdenk38635852002-08-27 05:55:31 +0000127
128 /* Address is specified since argc > 1
129 */
130 addr = simple_strtoul(argv[1], NULL, 16);
131 addr += base_address;
132
133 /* Get the value to write.
134 */
Simon Glass4d979bf2019-12-28 10:45:10 -0700135#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800136 writeval = simple_strtoull(argv[2], NULL, 16);
137#else
wdenk38635852002-08-27 05:55:31 +0000138 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800139#endif
wdenk38635852002-08-27 05:55:31 +0000140
141 /* Count ? */
142 if (argc == 4) {
143 count = simple_strtoul(argv[3], NULL, 16);
144 } else {
145 count = 1;
146 }
147
Simon Glass0628ab82013-02-24 17:33:15 +0000148 bytes = size * count;
Simon Glasscc5e1962015-03-05 12:25:18 -0700149 start = map_sysmem(addr, bytes);
150 buf = start;
wdenk38635852002-08-27 05:55:31 +0000151 while (count-- > 0) {
152 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -0800153 *((u32 *)buf) = (u32)writeval;
Simon Glass4d979bf2019-12-28 10:45:10 -0700154#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800155 else if (size == 8)
156 *((u64 *)buf) = (u64)writeval;
157#endif
wdenk38635852002-08-27 05:55:31 +0000158 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -0800159 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000160 else
York Sun76698b42014-02-12 15:55:35 -0800161 *((u8 *)buf) = (u8)writeval;
Simon Glass0628ab82013-02-24 17:33:15 +0000162 buf += size;
wdenk38635852002-08-27 05:55:31 +0000163 }
Simon Glasscc5e1962015-03-05 12:25:18 -0700164 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000165 return 0;
166}
167
Joel Johnson72732312020-01-29 09:17:18 -0700168#ifdef CONFIG_CMD_MX_CYCLIC
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900169static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000170{
171 int i;
172 ulong count;
173
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200174 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000175 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000176
177 count = simple_strtoul(argv[3], NULL, 10);
178
179 for (;;) {
180 do_mem_md (NULL, 0, 3, argv);
181
182 /* delay for <count> ms... */
183 for (i=0; i<count; i++)
184 udelay (1000);
185
186 /* check for ctrl-c to abort... */
187 if (ctrlc()) {
188 puts("Abort\n");
189 return 0;
190 }
191 }
192
193 return 0;
194}
195
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900196static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000197{
198 int i;
199 ulong count;
200
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200201 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000202 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000203
204 count = simple_strtoul(argv[3], NULL, 10);
205
206 for (;;) {
207 do_mem_mw (NULL, 0, 3, argv);
208
209 /* delay for <count> ms... */
210 for (i=0; i<count; i++)
211 udelay (1000);
212
213 /* check for ctrl-c to abort... */
214 if (ctrlc()) {
215 puts("Abort\n");
216 return 0;
217 }
218 }
219
220 return 0;
221}
Joel Johnson72732312020-01-29 09:17:18 -0700222#endif /* CONFIG_CMD_MX_CYCLIC */
stroese4aaf29b2004-12-16 17:42:39 +0000223
Kim Phillips088f1b12012-10-29 13:34:31 +0000224static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000225{
Simon Glass0628ab82013-02-24 17:33:15 +0000226 ulong addr1, addr2, count, ngood, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000227 int size;
wdenk38635852002-08-27 05:55:31 +0000228 int rcode = 0;
Mike Frysinger054ea172012-01-20 09:07:21 +0000229 const char *type;
Simon Glass0628ab82013-02-24 17:33:15 +0000230 const void *buf1, *buf2, *base;
Simon Glass4d979bf2019-12-28 10:45:10 -0700231#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800232 u64 word1, word2;
233#else
234 ulong word1, word2;
235#endif
wdenk38635852002-08-27 05:55:31 +0000236
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200237 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000238 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000239
240 /* Check for size specification.
241 */
wdenk27b207f2003-07-24 23:38:38 +0000242 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
243 return 1;
York Sun4d1fd7f2014-02-26 17:03:19 -0800244 type = size == 8 ? "double word" :
245 size == 4 ? "word" :
246 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000247
248 addr1 = simple_strtoul(argv[1], NULL, 16);
249 addr1 += base_address;
250
251 addr2 = simple_strtoul(argv[2], NULL, 16);
252 addr2 += base_address;
253
254 count = simple_strtoul(argv[3], NULL, 16);
255
Simon Glass0628ab82013-02-24 17:33:15 +0000256 bytes = size * count;
257 base = buf1 = map_sysmem(addr1, bytes);
258 buf2 = map_sysmem(addr2, bytes);
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000259 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000260 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800261 word1 = *(u32 *)buf1;
262 word2 = *(u32 *)buf2;
Simon Glass4d979bf2019-12-28 10:45:10 -0700263#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800264 } else if (size == 8) {
265 word1 = *(u64 *)buf1;
266 word2 = *(u64 *)buf2;
267#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000268 } else if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800269 word1 = *(u16 *)buf1;
270 word2 = *(u16 *)buf2;
Mike Frysinger054ea172012-01-20 09:07:21 +0000271 } else {
York Sun76698b42014-02-12 15:55:35 -0800272 word1 = *(u8 *)buf1;
273 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000274 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000275 if (word1 != word2) {
Simon Glass0628ab82013-02-24 17:33:15 +0000276 ulong offset = buf1 - base;
Simon Glass4d979bf2019-12-28 10:45:10 -0700277#ifdef MEM_SUPPORT_64BIT_DATA
Masahiro Yamadadee37fc2018-08-06 20:47:40 +0900278 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
York Sun4d1fd7f2014-02-26 17:03:19 -0800279 type, (void *)(addr1 + offset), size, word1,
280 type, (void *)(addr2 + offset), size, word2);
281#else
Mike Frysinger054ea172012-01-20 09:07:21 +0000282 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glass0628ab82013-02-24 17:33:15 +0000283 type, (ulong)(addr1 + offset), size, word1,
284 type, (ulong)(addr2 + offset), size, word2);
York Sun4d1fd7f2014-02-26 17:03:19 -0800285#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000286 rcode = 1;
287 break;
wdenk38635852002-08-27 05:55:31 +0000288 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000289
Simon Glass0628ab82013-02-24 17:33:15 +0000290 buf1 += size;
291 buf2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200292
293 /* reset watchdog from time to time */
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000294 if ((ngood % (64 << 10)) == 0)
Stefan Roeseeaadb442010-09-13 11:10:34 +0200295 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000296 }
Simon Glass0628ab82013-02-24 17:33:15 +0000297 unmap_sysmem(buf1);
298 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000299
Mike Frysinger054ea172012-01-20 09:07:21 +0000300 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000301 return rcode;
302}
303
Kim Phillips088f1b12012-10-29 13:34:31 +0000304static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000305{
Fabio Estevamc2538422016-12-15 16:00:13 -0200306 ulong addr, dest, count;
Philippe Reynes787f10a2019-12-02 17:33:22 +0100307 void *src, *dst;
wdenk27b207f2003-07-24 23:38:38 +0000308 int size;
wdenk38635852002-08-27 05:55:31 +0000309
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200310 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000311 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000312
313 /* Check for size specification.
314 */
wdenk27b207f2003-07-24 23:38:38 +0000315 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
316 return 1;
wdenk38635852002-08-27 05:55:31 +0000317
318 addr = simple_strtoul(argv[1], NULL, 16);
319 addr += base_address;
320
321 dest = simple_strtoul(argv[2], NULL, 16);
322 dest += base_address;
323
324 count = simple_strtoul(argv[3], NULL, 16);
325
326 if (count == 0) {
327 puts ("Zero length ???\n");
328 return 1;
329 }
330
Philippe Reynes787f10a2019-12-02 17:33:22 +0100331 src = map_sysmem(addr, count * size);
332 dst = map_sysmem(dest, count * size);
333
Masahiro Yamadae856bdc2017-02-11 22:43:54 +0900334#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000335 /* check if we are copying to Flash */
Philippe Reynes787f10a2019-12-02 17:33:22 +0100336 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000337 int rc;
338
wdenk4b9206e2004-03-23 22:14:11 +0000339 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000340
Philippe Reynes787f10a2019-12-02 17:33:22 +0100341 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000342 if (rc != 0) {
Simon Glass0ee482522019-12-28 10:44:40 -0700343 flash_perror(rc);
Philippe Reynes787f10a2019-12-02 17:33:22 +0100344 unmap_sysmem(src);
345 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000346 return (1);
347 }
348 puts ("done\n");
Philippe Reynes787f10a2019-12-02 17:33:22 +0100349 unmap_sysmem(src);
350 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000351 return 0;
352 }
353#endif
354
Philippe Reynes787f10a2019-12-02 17:33:22 +0100355 memcpy(dst, src, count * size);
Masahiro Yamadaa3a47492014-10-23 17:46:24 +0900356
Philippe Reynes787f10a2019-12-02 17:33:22 +0100357 unmap_sysmem(src);
358 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000359 return 0;
360}
361
Kim Phillips088f1b12012-10-29 13:34:31 +0000362static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
363 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000364{
365 if (argc > 1) {
366 /* Set new base address.
367 */
368 base_address = simple_strtoul(argv[1], NULL, 16);
369 }
370 /* Print the current base address.
371 */
372 printf("Base Address: 0x%08lx\n", base_address);
373 return 0;
374}
375
Kim Phillips088f1b12012-10-29 13:34:31 +0000376static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
377 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000378{
Simon Glass0628ab82013-02-24 17:33:15 +0000379 ulong addr, length, i, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000380 int size;
Simon Glass4d979bf2019-12-28 10:45:10 -0700381#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800382 volatile u64 *llp;
383#endif
York Sun76698b42014-02-12 15:55:35 -0800384 volatile u32 *longp;
385 volatile u16 *shortp;
386 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000387 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000388
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200389 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000390 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000391
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000392 /*
393 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000394 * Defaults to long if no or incorrect specification.
395 */
wdenk27b207f2003-07-24 23:38:38 +0000396 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
397 return 1;
wdenk38635852002-08-27 05:55:31 +0000398
399 /* Address is always specified.
400 */
401 addr = simple_strtoul(argv[1], NULL, 16);
402
403 /* Length is the number of objects, not number of bytes.
404 */
405 length = simple_strtoul(argv[2], NULL, 16);
406
Simon Glass0628ab82013-02-24 17:33:15 +0000407 bytes = size * length;
408 buf = map_sysmem(addr, bytes);
409
wdenk38635852002-08-27 05:55:31 +0000410 /* We want to optimize the loops to run as fast as possible.
411 * If we have only one object, just run infinite loops.
412 */
413 if (length == 1) {
Simon Glass4d979bf2019-12-28 10:45:10 -0700414#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800415 if (size == 8) {
416 llp = (u64 *)buf;
417 for (;;)
418 i = *llp;
419 }
420#endif
wdenk38635852002-08-27 05:55:31 +0000421 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800422 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000423 for (;;)
424 i = *longp;
425 }
426 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800427 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000428 for (;;)
429 i = *shortp;
430 }
York Sun76698b42014-02-12 15:55:35 -0800431 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000432 for (;;)
433 i = *cp;
434 }
435
Simon Glass4d979bf2019-12-28 10:45:10 -0700436#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800437 if (size == 8) {
438 for (;;) {
439 llp = (u64 *)buf;
440 i = length;
441 while (i-- > 0)
442 *llp++;
443 }
444 }
445#endif
wdenk38635852002-08-27 05:55:31 +0000446 if (size == 4) {
447 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800448 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000449 i = length;
450 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200451 *longp++;
wdenk38635852002-08-27 05:55:31 +0000452 }
453 }
454 if (size == 2) {
455 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800456 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000457 i = length;
458 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200459 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000460 }
461 }
462 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800463 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000464 i = length;
465 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200466 *cp++;
wdenk38635852002-08-27 05:55:31 +0000467 }
Simon Glass0628ab82013-02-24 17:33:15 +0000468 unmap_sysmem(buf);
Simon Glass92765f422013-06-11 11:14:35 -0700469
470 return 0;
wdenk38635852002-08-27 05:55:31 +0000471}
472
wdenk56523f12004-07-11 17:40:54 +0000473#ifdef CONFIG_LOOPW
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900474static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
475 char * const argv[])
wdenk56523f12004-07-11 17:40:54 +0000476{
York Sun4d1fd7f2014-02-26 17:03:19 -0800477 ulong addr, length, i, bytes;
wdenk56523f12004-07-11 17:40:54 +0000478 int size;
Simon Glass4d979bf2019-12-28 10:45:10 -0700479#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800480 volatile u64 *llp;
481 u64 data;
482#else
483 ulong data;
484#endif
York Sun76698b42014-02-12 15:55:35 -0800485 volatile u32 *longp;
486 volatile u16 *shortp;
487 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000488 void *buf;
wdenk81050922004-07-11 20:04:51 +0000489
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200490 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000491 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000492
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000493 /*
494 * Check for a size specification.
wdenk56523f12004-07-11 17:40:54 +0000495 * Defaults to long if no or incorrect specification.
496 */
497 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
498 return 1;
499
500 /* Address is always specified.
501 */
502 addr = simple_strtoul(argv[1], NULL, 16);
503
504 /* Length is the number of objects, not number of bytes.
505 */
506 length = simple_strtoul(argv[2], NULL, 16);
507
508 /* data to write */
Simon Glass4d979bf2019-12-28 10:45:10 -0700509#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800510 data = simple_strtoull(argv[3], NULL, 16);
511#else
wdenk56523f12004-07-11 17:40:54 +0000512 data = simple_strtoul(argv[3], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800513#endif
wdenk81050922004-07-11 20:04:51 +0000514
Simon Glass0628ab82013-02-24 17:33:15 +0000515 bytes = size * length;
516 buf = map_sysmem(addr, bytes);
517
wdenk56523f12004-07-11 17:40:54 +0000518 /* We want to optimize the loops to run as fast as possible.
519 * If we have only one object, just run infinite loops.
520 */
521 if (length == 1) {
Simon Glass4d979bf2019-12-28 10:45:10 -0700522#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800523 if (size == 8) {
524 llp = (u64 *)buf;
525 for (;;)
526 *llp = data;
527 }
528#endif
wdenk56523f12004-07-11 17:40:54 +0000529 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800530 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000531 for (;;)
532 *longp = data;
York Sun4d1fd7f2014-02-26 17:03:19 -0800533 }
wdenk56523f12004-07-11 17:40:54 +0000534 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800535 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000536 for (;;)
537 *shortp = data;
538 }
York Sun76698b42014-02-12 15:55:35 -0800539 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000540 for (;;)
541 *cp = data;
542 }
543
Simon Glass4d979bf2019-12-28 10:45:10 -0700544#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800545 if (size == 8) {
546 for (;;) {
547 llp = (u64 *)buf;
548 i = length;
549 while (i-- > 0)
550 *llp++ = data;
551 }
552 }
553#endif
wdenk56523f12004-07-11 17:40:54 +0000554 if (size == 4) {
555 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800556 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000557 i = length;
558 while (i-- > 0)
559 *longp++ = data;
560 }
561 }
562 if (size == 2) {
563 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800564 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000565 i = length;
566 while (i-- > 0)
567 *shortp++ = data;
568 }
569 }
570 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800571 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000572 i = length;
573 while (i-- > 0)
574 *cp++ = data;
575 }
576}
577#endif /* CONFIG_LOOPW */
578
Tom Rini68149e92013-03-12 10:07:19 -0400579#ifdef CONFIG_CMD_MEMTEST
Simon Glass5512d5b2013-02-28 17:47:14 +0000580static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
581 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000582{
Simon Glassc9638f52013-02-24 17:33:16 +0000583 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000584 ulong errs = 0;
585 ulong val, readback;
586 int j;
Simon Glassc9638f52013-02-24 17:33:16 +0000587 vu_long offset;
588 vu_long test_offset;
589 vu_long pattern;
590 vu_long temp;
591 vu_long anti_pattern;
592 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000593 static const ulong bitpattern[] = {
594 0x00000001, /* single bit */
595 0x00000003, /* two adjacent bits */
596 0x00000007, /* three adjacent bits */
597 0x0000000F, /* four adjacent bits */
598 0x00000005, /* two non-adjacent bits */
599 0x00000015, /* three non-adjacent bits */
600 0x00000055, /* four non-adjacent bits */
601 0xaaaaaaaa, /* alternating 1/0 */
602 };
wdenk38635852002-08-27 05:55:31 +0000603
Simon Glass5512d5b2013-02-28 17:47:14 +0000604 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000605
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000606 /*
607 * Data line test: write a pattern to the first
608 * location, write the 1's complement to a 'parking'
609 * address (changes the state of the data bus so a
610 * floating bus doesn't give a false OK), and then
611 * read the value back. Note that we read it back
612 * into a variable because the next time we read it,
613 * it might be right (been there, tough to explain to
614 * the quality guys why it prints a failure when the
615 * "is" and "should be" are obviously the same in the
616 * error message).
617 *
618 * Rather than exhaustively testing, we test some
619 * patterns by shifting '1' bits through a field of
620 * '0's and '0' bits through a field of '1's (i.e.
621 * pattern and ~pattern).
622 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000623 addr = buf;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000624 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
625 val = bitpattern[j];
626 for (; val != 0; val <<= 1) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000627 *addr = val;
Simon Glassc9638f52013-02-24 17:33:16 +0000628 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000629 readback = *addr;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000630 if (readback != val) {
Simon Glassc9638f52013-02-24 17:33:16 +0000631 printf("FAILURE (data line): "
632 "expected %08lx, actual %08lx\n",
633 val, readback);
634 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000635 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000636 return -1;
wdenk38635852002-08-27 05:55:31 +0000637 }
638 *addr = ~val;
639 *dummy = val;
640 readback = *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000641 if (readback != ~val) {
642 printf("FAILURE (data line): "
643 "Is %08lx, should be %08lx\n",
644 readback, ~val);
645 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000646 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000647 return -1;
wdenk38635852002-08-27 05:55:31 +0000648 }
wdenk38635852002-08-27 05:55:31 +0000649 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000650 }
wdenk38635852002-08-27 05:55:31 +0000651
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000652 /*
653 * Based on code whose Original Author and Copyright
654 * information follows: Copyright (c) 1998 by Michael
655 * Barr. This software is placed into the public
656 * domain and may be used for any purpose. However,
657 * this notice must not be changed or removed and no
658 * warranty is either expressed or implied by its
659 * publication or distribution.
660 */
wdenk38635852002-08-27 05:55:31 +0000661
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000662 /*
663 * Address line test
wdenk38635852002-08-27 05:55:31 +0000664
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000665 * Description: Test the address bus wiring in a
666 * memory region by performing a walking
667 * 1's test on the relevant bits of the
668 * address and checking for aliasing.
669 * This test will find single-bit
670 * address failures such as stuck-high,
671 * stuck-low, and shorted pins. The base
672 * address and size of the region are
673 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000674
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000675 * Notes: For best results, the selected base
676 * address should have enough LSB 0's to
677 * guarantee single address bit changes.
678 * For example, to test a 64-Kbyte
679 * region, select a base address on a
680 * 64-Kbyte boundary. Also, select the
681 * region size as a power-of-two if at
682 * all possible.
683 *
684 * Returns: 0 if the test succeeds, 1 if the test fails.
685 */
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000686 pattern = (vu_long) 0xaaaaaaaa;
687 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000688
Simon Glass5512d5b2013-02-28 17:47:14 +0000689 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000690 /*
691 * Write the default pattern at each of the
692 * power-of-two offsets.
693 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000694 for (offset = 1; offset < num_words; offset <<= 1)
695 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000696
697 /*
698 * Check for address bits stuck high.
699 */
700 test_offset = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000701 addr[test_offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000702
Simon Glass5512d5b2013-02-28 17:47:14 +0000703 for (offset = 1; offset < num_words; offset <<= 1) {
704 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000705 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000706 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000707 " expected 0x%.8lx, actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800708 start_addr + offset*sizeof(vu_long),
709 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400710 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000711 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000712 return -1;
wdenk38635852002-08-27 05:55:31 +0000713 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000714 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000715 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000716 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000717
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000718 /*
719 * Check for addr bits stuck low or shorted.
720 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000721 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
722 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000723
Simon Glass5512d5b2013-02-28 17:47:14 +0000724 for (offset = 1; offset < num_words; offset <<= 1) {
725 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000726 if ((temp != pattern) && (offset != test_offset)) {
727 printf("\nFAILURE: Address bit stuck low or"
728 " shorted @ 0x%.8lx: expected 0x%.8lx,"
729 " actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800730 start_addr + offset*sizeof(vu_long),
731 pattern, temp);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000732 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000733 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000734 return -1;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000735 }
wdenk38635852002-08-27 05:55:31 +0000736 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000737 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000738 }
wdenk38635852002-08-27 05:55:31 +0000739
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000740 /*
741 * Description: Test the integrity of a physical
742 * memory device by performing an
743 * increment/decrement test over the
744 * entire region. In the process every
745 * storage bit in the device is tested
746 * as a zero and a one. The base address
747 * and the size of the region are
748 * selected by the caller.
749 *
750 * Returns: 0 if the test succeeds, 1 if the test fails.
751 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000752 num_words++;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000753
754 /*
755 * Fill memory with a known pattern.
756 */
757 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
758 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000759 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000760 }
761
762 /*
763 * Check each location and invert it for the second pass.
764 */
765 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
766 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000767 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000768 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000769 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000770 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800771 start_addr + offset*sizeof(vu_long),
772 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400773 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000774 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000775 return -1;
wdenk38635852002-08-27 05:55:31 +0000776 }
777
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000778 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000779 addr[offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000780 }
781
782 /*
783 * Check each location for the inverted pattern and zero it.
784 */
785 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
786 WATCHDOG_RESET();
787 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000788 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000789 if (temp != anti_pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000790 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000791 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800792 start_addr + offset*sizeof(vu_long),
793 anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400794 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000795 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000796 return -1;
wdenk38635852002-08-27 05:55:31 +0000797 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000798 addr[offset] = 0;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000799 }
Simon Glass51209b12013-02-24 17:33:17 +0000800
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100801 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000802}
wdenk38635852002-08-27 05:55:31 +0000803
Simon Glass5512d5b2013-02-28 17:47:14 +0000804static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
805 vu_long pattern, int iteration)
Simon Glassc9638f52013-02-24 17:33:16 +0000806{
Simon Glass5512d5b2013-02-28 17:47:14 +0000807 vu_long *end;
Simon Glassc9638f52013-02-24 17:33:16 +0000808 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000809 ulong errs = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000810 ulong incr, length;
Simon Glassc9638f52013-02-24 17:33:16 +0000811 ulong val, readback;
812
Simon Glass51209b12013-02-24 17:33:17 +0000813 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000814 incr = 1;
Simon Glass51209b12013-02-24 17:33:17 +0000815 if (iteration & 1) {
816 incr = -incr;
817 /*
818 * Flip the pattern each time to make lots of zeros and
819 * then, the next time, lots of ones. We decrement
820 * the "negative" patterns and increment the "positive"
821 * patterns to preserve this feature.
822 */
823 if (pattern & 0x80000000)
824 pattern = -pattern; /* complement & increment */
825 else
826 pattern = ~pattern;
827 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000828 length = (end_addr - start_addr) / sizeof(ulong);
829 end = buf + length;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000830 printf("\rPattern %08lX Writing..."
831 "%12s"
832 "\b\b\b\b\b\b\b\b\b\b",
833 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000834
Simon Glass5512d5b2013-02-28 17:47:14 +0000835 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000836 WATCHDOG_RESET();
837 *addr = val;
838 val += incr;
839 }
wdenk38635852002-08-27 05:55:31 +0000840
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000841 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000842
Simon Glass5512d5b2013-02-28 17:47:14 +0000843 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000844 WATCHDOG_RESET();
845 readback = *addr;
846 if (readback != val) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000847 ulong offset = addr - buf;
848
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000849 printf("\nMem error @ 0x%08X: "
850 "found %08lX, expected %08lX\n",
David Feng102c0512014-02-12 16:10:08 +0800851 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glass5512d5b2013-02-28 17:47:14 +0000852 readback, val);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000853 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000854 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000855 return -1;
wdenk38635852002-08-27 05:55:31 +0000856 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000857 val += incr;
858 }
wdenk38635852002-08-27 05:55:31 +0000859
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100860 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000861}
862
863/*
864 * Perform a memory test. A more complete alternative test can be
865 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
866 * interrupted by ctrl-c or by a failure of one of the sub-tests.
867 */
868static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
869 char * const argv[])
870{
Simon Glass8c86bbe2013-02-24 17:33:20 +0000871 ulong start, end;
Simon Glass5512d5b2013-02-28 17:47:14 +0000872 vu_long *buf, *dummy;
Tom Riniadcc5702015-04-07 09:38:54 -0400873 ulong iteration_limit = 0;
Simon Glassc9638f52013-02-24 17:33:16 +0000874 int ret;
Simon Glass51209b12013-02-24 17:33:17 +0000875 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200876 ulong pattern = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000877 int iteration;
Simon Glassc9638f52013-02-24 17:33:16 +0000878#if defined(CONFIG_SYS_ALT_MEMTEST)
879 const int alt_test = 1;
880#else
881 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +0000882#endif
Simon Glassc9638f52013-02-24 17:33:16 +0000883
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200884 start = CONFIG_SYS_MEMTEST_START;
885 end = CONFIG_SYS_MEMTEST_END;
886
Simon Glassc9638f52013-02-24 17:33:16 +0000887 if (argc > 1)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200888 if (strict_strtoul(argv[1], 16, &start) < 0)
889 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000890
891 if (argc > 2)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200892 if (strict_strtoul(argv[2], 16, &end) < 0)
893 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000894
895 if (argc > 3)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200896 if (strict_strtoul(argv[3], 16, &pattern) < 0)
897 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000898
899 if (argc > 4)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200900 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
901 return CMD_RET_USAGE;
902
903 if (end < start) {
904 printf("Refusing to do empty test\n");
905 return -1;
906 }
Simon Glassc9638f52013-02-24 17:33:16 +0000907
Michal Simekdfe461d2016-02-24 08:36:02 +0100908 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000909 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
910 start, end);
Simon Glass51209b12013-02-24 17:33:17 +0000911
Simon Glass5512d5b2013-02-28 17:47:14 +0000912 buf = map_sysmem(start, end - start);
913 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass51209b12013-02-24 17:33:17 +0000914 for (iteration = 0;
915 !iteration_limit || iteration < iteration_limit;
916 iteration++) {
917 if (ctrlc()) {
Simon Glass51209b12013-02-24 17:33:17 +0000918 errs = -1UL;
919 break;
920 }
921
922 printf("Iteration: %6d\r", iteration + 1);
923 debug("\n");
Simon Glass5512d5b2013-02-28 17:47:14 +0000924 if (alt_test) {
925 errs = mem_test_alt(buf, start, end, dummy);
926 } else {
927 errs = mem_test_quick(buf, start, end, pattern,
928 iteration);
929 }
930 if (errs == -1UL)
931 break;
932 }
933
934 /*
935 * Work-around for eldk-4.2 which gives this warning if we try to
936 * case in the unmap_sysmem() call:
937 * warning: initialization discards qualifiers from pointer target type
938 */
939 {
940 void *vbuf = (void *)buf;
941 void *vdummy = (void *)dummy;
942
943 unmap_sysmem(vbuf);
944 unmap_sysmem(vdummy);
Simon Glass51209b12013-02-24 17:33:17 +0000945 }
946
947 if (errs == -1UL) {
Simon Glassc44d4382013-02-24 17:33:19 +0000948 /* Memory test was aborted - write a newline to finish off */
949 putc('\n');
Simon Glass51209b12013-02-24 17:33:17 +0000950 ret = 1;
951 } else {
952 printf("Tested %d iteration(s) with %lu errors.\n",
953 iteration, errs);
954 ret = errs != 0;
955 }
Simon Glassc9638f52013-02-24 17:33:16 +0000956
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200957 return ret;
wdenk38635852002-08-27 05:55:31 +0000958}
Wolfgang Denka2681702013-03-08 10:51:32 +0000959#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +0000960
961/* Modify memory.
962 *
963 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -0800964 * mm{.b, .w, .l, .q} {addr}
965 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +0000966 */
967static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200968mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000969{
York Sun4d1fd7f2014-02-26 17:03:19 -0800970 ulong addr;
Simon Glass4d979bf2019-12-28 10:45:10 -0700971#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800972 u64 i;
973#else
974 ulong i;
975#endif
wdenk27b207f2003-07-24 23:38:38 +0000976 int nbytes, size;
Simon Glass0628ab82013-02-24 17:33:15 +0000977 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +0000978
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200979 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000980 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000981
Simon Glassb26440f2014-04-10 20:01:31 -0600982 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +0000983 /* We use the last specified parameters, unless new ones are
984 * entered.
985 */
986 addr = mm_last_addr;
987 size = mm_last_size;
988
989 if ((flag & CMD_FLAG_REPEAT) == 0) {
990 /* New command specified. Check for a size specification.
991 * Defaults to long if no or incorrect specification.
992 */
wdenk27b207f2003-07-24 23:38:38 +0000993 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
994 return 1;
wdenk38635852002-08-27 05:55:31 +0000995
996 /* Address is specified since argc > 1
997 */
998 addr = simple_strtoul(argv[1], NULL, 16);
999 addr += base_address;
1000 }
1001
1002 /* Print the address, followed by value. Then accept input for
1003 * the next value. A non-converted value exits.
1004 */
1005 do {
Simon Glass0628ab82013-02-24 17:33:15 +00001006 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001007 printf("%08lx:", addr);
1008 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001009 printf(" %08x", *((u32 *)ptr));
Simon Glass4d979bf2019-12-28 10:45:10 -07001010#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001011 else if (size == 8)
Masahiro Yamadadee37fc2018-08-06 20:47:40 +09001012 printf(" %016llx", *((u64 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001013#endif
wdenk38635852002-08-27 05:55:31 +00001014 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001015 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001016 else
York Sun76698b42014-02-12 15:55:35 -08001017 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001018
Simon Glasse1bf8242014-04-10 20:01:27 -06001019 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001020 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1021 /* <CR> pressed as only input, don't modify current
1022 * location and move to next. "-" pressed will go back.
1023 */
1024 if (incrflag)
1025 addr += nbytes ? -size : size;
1026 nbytes = 1;
Simon Glassb26440f2014-04-10 20:01:31 -06001027 /* good enough to not time out */
1028 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001029 }
1030#ifdef CONFIG_BOOT_RETRY_TIME
1031 else if (nbytes == -2) {
1032 break; /* timed out, exit the command */
1033 }
1034#endif
1035 else {
1036 char *endp;
Simon Glass4d979bf2019-12-28 10:45:10 -07001037#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001038 i = simple_strtoull(console_buffer, &endp, 16);
1039#else
wdenk38635852002-08-27 05:55:31 +00001040 i = simple_strtoul(console_buffer, &endp, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -08001041#endif
wdenk38635852002-08-27 05:55:31 +00001042 nbytes = endp - console_buffer;
1043 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001044 /* good enough to not time out
1045 */
Simon Glassb26440f2014-04-10 20:01:31 -06001046 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001047 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001048 *((u32 *)ptr) = i;
Simon Glass4d979bf2019-12-28 10:45:10 -07001049#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001050 else if (size == 8)
1051 *((u64 *)ptr) = i;
1052#endif
wdenk38635852002-08-27 05:55:31 +00001053 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001054 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001055 else
York Sun76698b42014-02-12 15:55:35 -08001056 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001057 if (incrflag)
1058 addr += size;
1059 }
1060 }
1061 } while (nbytes);
Simon Glass0628ab82013-02-24 17:33:15 +00001062 if (ptr)
1063 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001064
1065 mm_last_addr = addr;
1066 mm_last_size = size;
1067 return 0;
1068}
1069
Mike Frysinger710b9932010-12-21 14:19:51 -05001070#ifdef CONFIG_CMD_CRC32
1071
Kim Phillips088f1b12012-10-29 13:34:31 +00001072static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001073{
Simon Glassd20a40d2013-02-24 20:30:22 +00001074 int flags = 0;
1075 int ac;
1076 char * const *av;
wdenk38635852002-08-27 05:55:31 +00001077
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001078 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001079 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001080
wdenkc26e4542004-04-18 10:13:26 +00001081 av = argv + 1;
1082 ac = argc - 1;
Daniel Thompson221a9492017-05-19 17:26:58 +01001083#ifdef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001084 if (strcmp(*av, "-v") == 0) {
Joe Hershbergera69bdba2015-05-05 12:23:53 -05001085 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenkc26e4542004-04-18 10:13:26 +00001086 av++;
1087 ac--;
wdenkc26e4542004-04-18 10:13:26 +00001088 }
Simon Glassd20a40d2013-02-24 20:30:22 +00001089#endif
wdenkc26e4542004-04-18 10:13:26 +00001090
Simon Glassd20a40d2013-02-24 20:30:22 +00001091 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenkc26e4542004-04-18 10:13:26 +00001092}
wdenkc26e4542004-04-18 10:13:26 +00001093
Mike Frysinger710b9932010-12-21 14:19:51 -05001094#endif
1095
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001096#ifdef CONFIG_CMD_RANDOM
1097static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1098{
1099 unsigned long addr, len;
1100 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1101 unsigned int *buf, *start;
1102 unsigned char *buf8;
1103 unsigned int i;
1104
1105 if (argc < 3 || argc > 4) {
1106 printf("usage: %s <addr> <len> [<seed>]\n", argv[0]);
1107 return 0;
1108 }
1109
1110 len = simple_strtoul(argv[2], NULL, 16);
1111 addr = simple_strtoul(argv[1], NULL, 16);
1112
1113 if (argc == 4) {
1114 seed = simple_strtoul(argv[3], NULL, 16);
1115 if (seed == 0) {
1116 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1117 seed = 0xDEADBEEF;
1118 }
1119 } else {
1120 seed = get_timer(0) ^ rand();
1121 }
1122
1123 srand(seed);
1124 start = map_sysmem(addr, len);
1125 buf = start;
1126 for (i = 0; i < (len / 4); i++)
1127 *buf++ = rand();
1128
1129 buf8 = (unsigned char *)buf;
1130 for (i = 0; i < (len % 4); i++)
1131 *buf8++ = rand() & 0xFF;
1132
1133 unmap_sysmem(start);
1134 printf("%lu bytes filled with random data\n", len);
1135 return 1;
1136}
1137#endif
1138
wdenk8bde7f72003-06-27 21:31:46 +00001139/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001140U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001141 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001142 "memory display",
Simon Glass4d979bf2019-12-28 10:45:10 -07001143#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001144 "[.b, .w, .l, .q] address [# of objects]"
1145#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001146 "[.b, .w, .l] address [# of objects]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001147#endif
wdenk8bde7f72003-06-27 21:31:46 +00001148);
1149
1150
wdenk0d498392003-07-01 21:06:45 +00001151U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001152 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001153 "memory modify (auto-incrementing address)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001154#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001155 "[.b, .w, .l, .q] address"
1156#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001157 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001158#endif
wdenk8bde7f72003-06-27 21:31:46 +00001159);
1160
1161
wdenk0d498392003-07-01 21:06:45 +00001162U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001163 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001164 "memory modify (constant address)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001165#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001166 "[.b, .w, .l, .q] address"
1167#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001168 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001169#endif
wdenk8bde7f72003-06-27 21:31:46 +00001170);
1171
wdenk0d498392003-07-01 21:06:45 +00001172U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001173 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001174 "memory write (fill)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001175#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001176 "[.b, .w, .l, .q] address value [count]"
1177#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001178 "[.b, .w, .l] address value [count]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001179#endif
wdenk8bde7f72003-06-27 21:31:46 +00001180);
1181
wdenk0d498392003-07-01 21:06:45 +00001182U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001183 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001184 "memory copy",
Simon Glass4d979bf2019-12-28 10:45:10 -07001185#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001186 "[.b, .w, .l, .q] source target count"
1187#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001188 "[.b, .w, .l] source target count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001189#endif
wdenk8bde7f72003-06-27 21:31:46 +00001190);
1191
wdenk0d498392003-07-01 21:06:45 +00001192U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001193 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001194 "memory compare",
Simon Glass4d979bf2019-12-28 10:45:10 -07001195#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001196 "[.b, .w, .l, .q] addr1 addr2 count"
1197#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001198 "[.b, .w, .l] addr1 addr2 count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001199#endif
wdenk8bde7f72003-06-27 21:31:46 +00001200);
1201
Mike Frysinger710b9932010-12-21 14:19:51 -05001202#ifdef CONFIG_CMD_CRC32
1203
Daniel Thompson221a9492017-05-19 17:26:58 +01001204#ifndef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001205
wdenk0d498392003-07-01 21:06:45 +00001206U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001207 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001208 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001209 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001210);
1211
Daniel Thompson221a9492017-05-19 17:26:58 +01001212#else /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001213
1214U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001215 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001216 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001217 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001218 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001219);
1220
Daniel Thompson221a9492017-05-19 17:26:58 +01001221#endif /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001222
Mike Frysinger710b9932010-12-21 14:19:51 -05001223#endif
1224
Simon Glass15a33e42012-11-30 13:01:20 +00001225#ifdef CONFIG_CMD_MEMINFO
Simon Glass15a33e42012-11-30 13:01:20 +00001226static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1227 char * const argv[])
1228{
Simon Glass428a6a12019-11-14 12:57:44 -07001229 puts("DRAM: ");
1230 print_size(gd->ram_size, "\n");
Simon Glass15a33e42012-11-30 13:01:20 +00001231
1232 return 0;
1233}
1234#endif
1235
wdenk0d498392003-07-01 21:06:45 +00001236U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001237 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001238 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001239 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001240 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001241);
1242
wdenk0d498392003-07-01 21:06:45 +00001243U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001244 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001245 "infinite loop on address range",
Simon Glass4d979bf2019-12-28 10:45:10 -07001246#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001247 "[.b, .w, .l, .q] address number_of_objects"
1248#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001249 "[.b, .w, .l] address number_of_objects"
York Sun4d1fd7f2014-02-26 17:03:19 -08001250#endif
wdenk8bde7f72003-06-27 21:31:46 +00001251);
1252
wdenk56523f12004-07-11 17:40:54 +00001253#ifdef CONFIG_LOOPW
1254U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001255 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001256 "infinite write loop on address range",
Simon Glass4d979bf2019-12-28 10:45:10 -07001257#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001258 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1259#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001260 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun4d1fd7f2014-02-26 17:03:19 -08001261#endif
wdenk56523f12004-07-11 17:40:54 +00001262);
1263#endif /* CONFIG_LOOPW */
1264
Wolfgang Denka2681702013-03-08 10:51:32 +00001265#ifdef CONFIG_CMD_MEMTEST
wdenk0d498392003-07-01 21:06:45 +00001266U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001267 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001268 "simple RAM read/write test",
1269 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001270);
Wolfgang Denka2681702013-03-08 10:51:32 +00001271#endif /* CONFIG_CMD_MEMTEST */
wdenk8bde7f72003-06-27 21:31:46 +00001272
Joel Johnson72732312020-01-29 09:17:18 -07001273#ifdef CONFIG_CMD_MX_CYCLIC
stroese4aaf29b2004-12-16 17:42:39 +00001274U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001275 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001276 "memory display cyclic",
Simon Glass4d979bf2019-12-28 10:45:10 -07001277#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001278 "[.b, .w, .l, .q] address count delay(ms)"
1279#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001280 "[.b, .w, .l] address count delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001281#endif
stroese4aaf29b2004-12-16 17:42:39 +00001282);
1283
1284U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001285 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001286 "memory write cyclic",
Simon Glass4d979bf2019-12-28 10:45:10 -07001287#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001288 "[.b, .w, .l, .q] address value delay(ms)"
1289#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001290 "[.b, .w, .l] address value delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001291#endif
stroese4aaf29b2004-12-16 17:42:39 +00001292);
Joel Johnson72732312020-01-29 09:17:18 -07001293#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glass15a33e42012-11-30 13:01:20 +00001294
1295#ifdef CONFIG_CMD_MEMINFO
1296U_BOOT_CMD(
1297 meminfo, 3, 1, do_mem_info,
1298 "display memory information",
1299 ""
1300);
1301#endif
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001302
1303#ifdef CONFIG_CMD_RANDOM
1304U_BOOT_CMD(
1305 random, 4, 0, do_random,
1306 "fill memory with random pattern",
1307 "<addr> <len> [<seed>]\n"
1308 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1309);
1310#endif