blob: 0bfb6081e7e13e99fd1a1632928e1221c6dd1d1c [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
Stefan Roese8e434cb2020-03-05 07:21:32 +0100804static int compare_regions(volatile unsigned long *bufa,
805 volatile unsigned long *bufb, size_t count)
806{
807 volatile unsigned long *p1 = bufa;
808 volatile unsigned long *p2 = bufb;
809 int errs = 0;
810 size_t i;
811
812 for (i = 0; i < count; i++, p1++, p2++) {
813 if (*p1 != *p2) {
814 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
815 (unsigned long)*p1, (unsigned long)*p2,
816 *p1 ^ *p2, __ffs(*p1 ^ *p2),
817 (unsigned long)(i * sizeof(unsigned long)));
818 errs++;
819 }
820 }
821
822 return errs;
823}
824
825static ulong test_bitflip_comparison(volatile unsigned long *bufa,
826 volatile unsigned long *bufb, size_t count)
827{
828 volatile unsigned long *p1 = bufa;
829 volatile unsigned long *p2 = bufb;
830 unsigned int j, k;
831 unsigned long q;
832 size_t i;
833 int max;
834 int errs = 0;
835
836 max = sizeof(unsigned long) * 8;
837 for (k = 0; k < max; k++) {
838 q = 0x00000001L << k;
839 for (j = 0; j < 8; j++) {
840 WATCHDOG_RESET();
841 q = ~q;
842 p1 = (volatile unsigned long *)bufa;
843 p2 = (volatile unsigned long *)bufb;
844 for (i = 0; i < count; i++)
845 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
846
847 errs += compare_regions(bufa, bufb, count);
848 }
849
850 if (ctrlc())
851 return -1UL;
852 }
853
854 return errs;
855}
856
Simon Glass5512d5b2013-02-28 17:47:14 +0000857static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
858 vu_long pattern, int iteration)
Simon Glassc9638f52013-02-24 17:33:16 +0000859{
Simon Glass5512d5b2013-02-28 17:47:14 +0000860 vu_long *end;
Simon Glassc9638f52013-02-24 17:33:16 +0000861 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000862 ulong errs = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000863 ulong incr, length;
Simon Glassc9638f52013-02-24 17:33:16 +0000864 ulong val, readback;
865
Simon Glass51209b12013-02-24 17:33:17 +0000866 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000867 incr = 1;
Simon Glass51209b12013-02-24 17:33:17 +0000868 if (iteration & 1) {
869 incr = -incr;
870 /*
871 * Flip the pattern each time to make lots of zeros and
872 * then, the next time, lots of ones. We decrement
873 * the "negative" patterns and increment the "positive"
874 * patterns to preserve this feature.
875 */
876 if (pattern & 0x80000000)
877 pattern = -pattern; /* complement & increment */
878 else
879 pattern = ~pattern;
880 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000881 length = (end_addr - start_addr) / sizeof(ulong);
882 end = buf + length;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000883 printf("\rPattern %08lX Writing..."
884 "%12s"
885 "\b\b\b\b\b\b\b\b\b\b",
886 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000887
Simon Glass5512d5b2013-02-28 17:47:14 +0000888 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000889 WATCHDOG_RESET();
890 *addr = val;
891 val += incr;
892 }
wdenk38635852002-08-27 05:55:31 +0000893
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000894 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000895
Simon Glass5512d5b2013-02-28 17:47:14 +0000896 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000897 WATCHDOG_RESET();
898 readback = *addr;
899 if (readback != val) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000900 ulong offset = addr - buf;
901
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000902 printf("\nMem error @ 0x%08X: "
903 "found %08lX, expected %08lX\n",
David Feng102c0512014-02-12 16:10:08 +0800904 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glass5512d5b2013-02-28 17:47:14 +0000905 readback, val);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000906 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000907 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000908 return -1;
wdenk38635852002-08-27 05:55:31 +0000909 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000910 val += incr;
911 }
wdenk38635852002-08-27 05:55:31 +0000912
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100913 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000914}
915
916/*
917 * Perform a memory test. A more complete alternative test can be
918 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
919 * interrupted by ctrl-c or by a failure of one of the sub-tests.
920 */
921static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
922 char * const argv[])
923{
Simon Glass8c86bbe2013-02-24 17:33:20 +0000924 ulong start, end;
Simon Glass5512d5b2013-02-28 17:47:14 +0000925 vu_long *buf, *dummy;
Tom Riniadcc5702015-04-07 09:38:54 -0400926 ulong iteration_limit = 0;
Stefan Roesea8c708e2020-03-05 07:21:29 +0100927 ulong count = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000928 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200929 ulong pattern = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000930 int iteration;
Simon Glassc9638f52013-02-24 17:33:16 +0000931
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200932 start = CONFIG_SYS_MEMTEST_START;
933 end = CONFIG_SYS_MEMTEST_END;
934
Simon Glassc9638f52013-02-24 17:33:16 +0000935 if (argc > 1)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200936 if (strict_strtoul(argv[1], 16, &start) < 0)
937 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000938
939 if (argc > 2)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200940 if (strict_strtoul(argv[2], 16, &end) < 0)
941 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000942
943 if (argc > 3)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200944 if (strict_strtoul(argv[3], 16, &pattern) < 0)
945 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000946
947 if (argc > 4)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200948 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
949 return CMD_RET_USAGE;
950
951 if (end < start) {
952 printf("Refusing to do empty test\n");
953 return -1;
954 }
Simon Glassc9638f52013-02-24 17:33:16 +0000955
Michal Simekdfe461d2016-02-24 08:36:02 +0100956 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000957 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
958 start, end);
Simon Glass51209b12013-02-24 17:33:17 +0000959
Simon Glass5512d5b2013-02-28 17:47:14 +0000960 buf = map_sysmem(start, end - start);
961 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass51209b12013-02-24 17:33:17 +0000962 for (iteration = 0;
963 !iteration_limit || iteration < iteration_limit;
964 iteration++) {
965 if (ctrlc()) {
Simon Glass51209b12013-02-24 17:33:17 +0000966 errs = -1UL;
967 break;
968 }
969
970 printf("Iteration: %6d\r", iteration + 1);
971 debug("\n");
Stefan Roesef14bfa72020-03-05 07:21:31 +0100972 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000973 errs = mem_test_alt(buf, start, end, dummy);
Stefan Roese8e434cb2020-03-05 07:21:32 +0100974 if (errs == -1UL)
975 break;
976 count += errs;
977 errs = test_bitflip_comparison(buf,
978 buf + (end - start) / 2,
979 (end - start) /
980 sizeof(unsigned long));
Simon Glass5512d5b2013-02-28 17:47:14 +0000981 } else {
982 errs = mem_test_quick(buf, start, end, pattern,
983 iteration);
984 }
985 if (errs == -1UL)
986 break;
Stefan Roesea8c708e2020-03-05 07:21:29 +0100987 count += errs;
Simon Glass5512d5b2013-02-28 17:47:14 +0000988 }
989
Stefan Roese54de2442020-03-05 07:21:30 +0100990 unmap_sysmem((void *)buf);
991 unmap_sysmem((void *)dummy);
Simon Glass51209b12013-02-24 17:33:17 +0000992
993 if (errs == -1UL) {
Simon Glassc44d4382013-02-24 17:33:19 +0000994 /* Memory test was aborted - write a newline to finish off */
995 putc('\n');
Simon Glass51209b12013-02-24 17:33:17 +0000996 }
Stefan Roesea8c708e2020-03-05 07:21:29 +0100997 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
Simon Glassc9638f52013-02-24 17:33:16 +0000998
Stefan Roesea8c708e2020-03-05 07:21:29 +0100999 return errs != 0;
wdenk38635852002-08-27 05:55:31 +00001000}
Wolfgang Denka2681702013-03-08 10:51:32 +00001001#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001002
1003/* Modify memory.
1004 *
1005 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -08001006 * mm{.b, .w, .l, .q} {addr}
1007 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001008 */
1009static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001010mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001011{
York Sun4d1fd7f2014-02-26 17:03:19 -08001012 ulong addr;
Simon Glass4d979bf2019-12-28 10:45:10 -07001013#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001014 u64 i;
1015#else
1016 ulong i;
1017#endif
wdenk27b207f2003-07-24 23:38:38 +00001018 int nbytes, size;
Simon Glass0628ab82013-02-24 17:33:15 +00001019 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001020
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001021 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001022 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001023
Simon Glassb26440f2014-04-10 20:01:31 -06001024 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001025 /* We use the last specified parameters, unless new ones are
1026 * entered.
1027 */
1028 addr = mm_last_addr;
1029 size = mm_last_size;
1030
1031 if ((flag & CMD_FLAG_REPEAT) == 0) {
1032 /* New command specified. Check for a size specification.
1033 * Defaults to long if no or incorrect specification.
1034 */
wdenk27b207f2003-07-24 23:38:38 +00001035 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1036 return 1;
wdenk38635852002-08-27 05:55:31 +00001037
1038 /* Address is specified since argc > 1
1039 */
1040 addr = simple_strtoul(argv[1], NULL, 16);
1041 addr += base_address;
1042 }
1043
1044 /* Print the address, followed by value. Then accept input for
1045 * the next value. A non-converted value exits.
1046 */
1047 do {
Simon Glass0628ab82013-02-24 17:33:15 +00001048 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001049 printf("%08lx:", addr);
1050 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001051 printf(" %08x", *((u32 *)ptr));
Simon Glass4d979bf2019-12-28 10:45:10 -07001052#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001053 else if (size == 8)
Masahiro Yamadadee37fc2018-08-06 20:47:40 +09001054 printf(" %016llx", *((u64 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001055#endif
wdenk38635852002-08-27 05:55:31 +00001056 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001057 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001058 else
York Sun76698b42014-02-12 15:55:35 -08001059 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001060
Simon Glasse1bf8242014-04-10 20:01:27 -06001061 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001062 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1063 /* <CR> pressed as only input, don't modify current
1064 * location and move to next. "-" pressed will go back.
1065 */
1066 if (incrflag)
1067 addr += nbytes ? -size : size;
1068 nbytes = 1;
Simon Glassb26440f2014-04-10 20:01:31 -06001069 /* good enough to not time out */
1070 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001071 }
1072#ifdef CONFIG_BOOT_RETRY_TIME
1073 else if (nbytes == -2) {
1074 break; /* timed out, exit the command */
1075 }
1076#endif
1077 else {
1078 char *endp;
Simon Glass4d979bf2019-12-28 10:45:10 -07001079#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001080 i = simple_strtoull(console_buffer, &endp, 16);
1081#else
wdenk38635852002-08-27 05:55:31 +00001082 i = simple_strtoul(console_buffer, &endp, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -08001083#endif
wdenk38635852002-08-27 05:55:31 +00001084 nbytes = endp - console_buffer;
1085 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001086 /* good enough to not time out
1087 */
Simon Glassb26440f2014-04-10 20:01:31 -06001088 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001089 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001090 *((u32 *)ptr) = i;
Simon Glass4d979bf2019-12-28 10:45:10 -07001091#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001092 else if (size == 8)
1093 *((u64 *)ptr) = i;
1094#endif
wdenk38635852002-08-27 05:55:31 +00001095 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001096 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001097 else
York Sun76698b42014-02-12 15:55:35 -08001098 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001099 if (incrflag)
1100 addr += size;
1101 }
1102 }
1103 } while (nbytes);
Simon Glass0628ab82013-02-24 17:33:15 +00001104 if (ptr)
1105 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001106
1107 mm_last_addr = addr;
1108 mm_last_size = size;
1109 return 0;
1110}
1111
Mike Frysinger710b9932010-12-21 14:19:51 -05001112#ifdef CONFIG_CMD_CRC32
1113
Kim Phillips088f1b12012-10-29 13:34:31 +00001114static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001115{
Simon Glassd20a40d2013-02-24 20:30:22 +00001116 int flags = 0;
1117 int ac;
1118 char * const *av;
wdenk38635852002-08-27 05:55:31 +00001119
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001120 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001121 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001122
wdenkc26e4542004-04-18 10:13:26 +00001123 av = argv + 1;
1124 ac = argc - 1;
Daniel Thompson221a9492017-05-19 17:26:58 +01001125#ifdef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001126 if (strcmp(*av, "-v") == 0) {
Joe Hershbergera69bdba2015-05-05 12:23:53 -05001127 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenkc26e4542004-04-18 10:13:26 +00001128 av++;
1129 ac--;
wdenkc26e4542004-04-18 10:13:26 +00001130 }
Simon Glassd20a40d2013-02-24 20:30:22 +00001131#endif
wdenkc26e4542004-04-18 10:13:26 +00001132
Simon Glassd20a40d2013-02-24 20:30:22 +00001133 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenkc26e4542004-04-18 10:13:26 +00001134}
wdenkc26e4542004-04-18 10:13:26 +00001135
Mike Frysinger710b9932010-12-21 14:19:51 -05001136#endif
1137
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001138#ifdef CONFIG_CMD_RANDOM
1139static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1140{
1141 unsigned long addr, len;
1142 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1143 unsigned int *buf, *start;
1144 unsigned char *buf8;
1145 unsigned int i;
1146
1147 if (argc < 3 || argc > 4) {
1148 printf("usage: %s <addr> <len> [<seed>]\n", argv[0]);
1149 return 0;
1150 }
1151
1152 len = simple_strtoul(argv[2], NULL, 16);
1153 addr = simple_strtoul(argv[1], NULL, 16);
1154
1155 if (argc == 4) {
1156 seed = simple_strtoul(argv[3], NULL, 16);
1157 if (seed == 0) {
1158 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1159 seed = 0xDEADBEEF;
1160 }
1161 } else {
1162 seed = get_timer(0) ^ rand();
1163 }
1164
1165 srand(seed);
1166 start = map_sysmem(addr, len);
1167 buf = start;
1168 for (i = 0; i < (len / 4); i++)
1169 *buf++ = rand();
1170
1171 buf8 = (unsigned char *)buf;
1172 for (i = 0; i < (len % 4); i++)
1173 *buf8++ = rand() & 0xFF;
1174
1175 unmap_sysmem(start);
1176 printf("%lu bytes filled with random data\n", len);
1177 return 1;
1178}
1179#endif
1180
wdenk8bde7f72003-06-27 21:31:46 +00001181/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001182U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001183 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001184 "memory display",
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] address [# of objects]"
1187#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001188 "[.b, .w, .l] address [# of objects]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001189#endif
wdenk8bde7f72003-06-27 21:31:46 +00001190);
1191
1192
wdenk0d498392003-07-01 21:06:45 +00001193U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001194 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001195 "memory modify (auto-incrementing address)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001196#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001197 "[.b, .w, .l, .q] address"
1198#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001199 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001200#endif
wdenk8bde7f72003-06-27 21:31:46 +00001201);
1202
1203
wdenk0d498392003-07-01 21:06:45 +00001204U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001205 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001206 "memory modify (constant address)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001207#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001208 "[.b, .w, .l, .q] address"
1209#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001210 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001211#endif
wdenk8bde7f72003-06-27 21:31:46 +00001212);
1213
wdenk0d498392003-07-01 21:06:45 +00001214U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001215 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001216 "memory write (fill)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001217#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001218 "[.b, .w, .l, .q] address value [count]"
1219#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001220 "[.b, .w, .l] address value [count]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001221#endif
wdenk8bde7f72003-06-27 21:31:46 +00001222);
1223
wdenk0d498392003-07-01 21:06:45 +00001224U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001225 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001226 "memory copy",
Simon Glass4d979bf2019-12-28 10:45:10 -07001227#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001228 "[.b, .w, .l, .q] source target count"
1229#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001230 "[.b, .w, .l] source target count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001231#endif
wdenk8bde7f72003-06-27 21:31:46 +00001232);
1233
wdenk0d498392003-07-01 21:06:45 +00001234U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001235 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001236 "memory compare",
Simon Glass4d979bf2019-12-28 10:45:10 -07001237#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001238 "[.b, .w, .l, .q] addr1 addr2 count"
1239#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001240 "[.b, .w, .l] addr1 addr2 count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001241#endif
wdenk8bde7f72003-06-27 21:31:46 +00001242);
1243
Mike Frysinger710b9932010-12-21 14:19:51 -05001244#ifdef CONFIG_CMD_CRC32
1245
Daniel Thompson221a9492017-05-19 17:26:58 +01001246#ifndef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001247
wdenk0d498392003-07-01 21:06:45 +00001248U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001249 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001250 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001251 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001252);
1253
Daniel Thompson221a9492017-05-19 17:26:58 +01001254#else /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001255
1256U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001257 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001258 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001259 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001260 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001261);
1262
Daniel Thompson221a9492017-05-19 17:26:58 +01001263#endif /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001264
Mike Frysinger710b9932010-12-21 14:19:51 -05001265#endif
1266
Simon Glass15a33e42012-11-30 13:01:20 +00001267#ifdef CONFIG_CMD_MEMINFO
Simon Glass15a33e42012-11-30 13:01:20 +00001268static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1269 char * const argv[])
1270{
Simon Glass428a6a12019-11-14 12:57:44 -07001271 puts("DRAM: ");
1272 print_size(gd->ram_size, "\n");
Simon Glass15a33e42012-11-30 13:01:20 +00001273
1274 return 0;
1275}
1276#endif
1277
wdenk0d498392003-07-01 21:06:45 +00001278U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001279 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001280 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001281 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001282 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001283);
1284
wdenk0d498392003-07-01 21:06:45 +00001285U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001286 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001287 "infinite loop on address range",
Simon Glass4d979bf2019-12-28 10:45:10 -07001288#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001289 "[.b, .w, .l, .q] address number_of_objects"
1290#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001291 "[.b, .w, .l] address number_of_objects"
York Sun4d1fd7f2014-02-26 17:03:19 -08001292#endif
wdenk8bde7f72003-06-27 21:31:46 +00001293);
1294
wdenk56523f12004-07-11 17:40:54 +00001295#ifdef CONFIG_LOOPW
1296U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001297 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001298 "infinite write loop on address range",
Simon Glass4d979bf2019-12-28 10:45:10 -07001299#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001300 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1301#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001302 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun4d1fd7f2014-02-26 17:03:19 -08001303#endif
wdenk56523f12004-07-11 17:40:54 +00001304);
1305#endif /* CONFIG_LOOPW */
1306
Wolfgang Denka2681702013-03-08 10:51:32 +00001307#ifdef CONFIG_CMD_MEMTEST
wdenk0d498392003-07-01 21:06:45 +00001308U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001309 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001310 "simple RAM read/write test",
1311 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001312);
Wolfgang Denka2681702013-03-08 10:51:32 +00001313#endif /* CONFIG_CMD_MEMTEST */
wdenk8bde7f72003-06-27 21:31:46 +00001314
Joel Johnson72732312020-01-29 09:17:18 -07001315#ifdef CONFIG_CMD_MX_CYCLIC
stroese4aaf29b2004-12-16 17:42:39 +00001316U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001317 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001318 "memory display cyclic",
Simon Glass4d979bf2019-12-28 10:45:10 -07001319#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001320 "[.b, .w, .l, .q] address count delay(ms)"
1321#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001322 "[.b, .w, .l] address count delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001323#endif
stroese4aaf29b2004-12-16 17:42:39 +00001324);
1325
1326U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001327 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001328 "memory write cyclic",
Simon Glass4d979bf2019-12-28 10:45:10 -07001329#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001330 "[.b, .w, .l, .q] address value delay(ms)"
1331#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001332 "[.b, .w, .l] address value delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001333#endif
stroese4aaf29b2004-12-16 17:42:39 +00001334);
Joel Johnson72732312020-01-29 09:17:18 -07001335#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glass15a33e42012-11-30 13:01:20 +00001336
1337#ifdef CONFIG_CMD_MEMINFO
1338U_BOOT_CMD(
1339 meminfo, 3, 1, do_mem_info,
1340 "display memory information",
1341 ""
1342);
1343#endif
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001344
1345#ifdef CONFIG_CMD_RANDOM
1346U_BOOT_CMD(
1347 random, 4, 0, do_random,
1348 "fill memory with random pattern",
1349 "<addr> <len> [<seed>]\n"
1350 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1351);
1352#endif