blob: 24a9c7731ccf1b3fe5bdc99a918ccf3cbbace698 [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>
Simon Glass90526e92020-05-10 11:39:56 -060022#include <rand.h>
Sergei Poselenova6e6fc62008-04-09 16:09:41 +020023#include <watchdog.h>
Simon Glass0628ab82013-02-24 17:33:15 +000024#include <asm/io.h>
Simon Glass15a33e42012-11-30 13:01:20 +000025#include <linux/compiler.h>
26
27DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000028
Wolfgang Denk54841ab2010-06-28 22:00:46 +020029static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000030
31/* Display values from last command.
32 * Memory modify remembered values are different from display memory.
33 */
Scott Wood581508b2015-03-19 09:43:12 -070034static ulong dp_last_addr, dp_last_size;
35static ulong dp_last_length = 0x40;
36static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000037
38static ulong base_address = 0;
39
40/* Memory Display
41 *
42 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -080043 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000044 */
45#define DISP_LINE_LEN 16
Kim Phillips088f1b12012-10-29 13:34:31 +000046static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000047{
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030048 ulong addr, length, bytes;
49 const void *buf;
wdenk27b207f2003-07-24 23:38:38 +000050 int size;
wdenk38635852002-08-27 05:55:31 +000051 int rc = 0;
52
53 /* We use the last specified parameters, unless new ones are
54 * entered.
55 */
56 addr = dp_last_addr;
57 size = dp_last_size;
58 length = dp_last_length;
59
Wolfgang Denk47e26b12010-07-17 01:06:04 +020060 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000061 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000062
63 if ((flag & CMD_FLAG_REPEAT) == 0) {
64 /* New command specified. Check for a size specification.
65 * Defaults to long if no or incorrect specification.
66 */
wdenk27b207f2003-07-24 23:38:38 +000067 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
68 return 1;
wdenk38635852002-08-27 05:55:31 +000069
70 /* Address is specified since argc > 1
71 */
72 addr = simple_strtoul(argv[1], NULL, 16);
73 addr += base_address;
74
75 /* If another parameter, it is the length to display.
76 * Length is the number of objects, not number of bytes.
77 */
78 if (argc > 2)
79 length = simple_strtoul(argv[2], NULL, 16);
80 }
81
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030082 bytes = size * length;
83 buf = map_sysmem(addr, bytes);
wdenk2abbe072003-06-16 23:50:08 +000084
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030085 /* Print the lines. */
86 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
87 addr += bytes;
88 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +000089
90 dp_last_addr = addr;
91 dp_last_length = length;
92 dp_last_size = size;
93 return (rc);
94}
95
Kim Phillips088f1b12012-10-29 13:34:31 +000096static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000097{
98 return mod_mem (cmdtp, 1, flag, argc, argv);
99}
Kim Phillips088f1b12012-10-29 13:34:31 +0000100static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000101{
102 return mod_mem (cmdtp, 0, flag, argc, argv);
103}
104
Kim Phillips088f1b12012-10-29 13:34:31 +0000105static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000106{
Simon Glass4d979bf2019-12-28 10:45:10 -0700107#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800108 u64 writeval;
109#else
110 ulong writeval;
111#endif
112 ulong addr, count;
wdenk27b207f2003-07-24 23:38:38 +0000113 int size;
Simon Glasscc5e1962015-03-05 12:25:18 -0700114 void *buf, *start;
Simon Glass0628ab82013-02-24 17:33:15 +0000115 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000116
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200117 if ((argc < 3) || (argc > 4))
Simon Glass4c12eeb2011-12-10 08:44:01 +0000118 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000119
120 /* Check for size specification.
121 */
wdenk27b207f2003-07-24 23:38:38 +0000122 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
123 return 1;
wdenk38635852002-08-27 05:55:31 +0000124
125 /* Address is specified since argc > 1
126 */
127 addr = simple_strtoul(argv[1], NULL, 16);
128 addr += base_address;
129
130 /* Get the value to write.
131 */
Simon Glass4d979bf2019-12-28 10:45:10 -0700132#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800133 writeval = simple_strtoull(argv[2], NULL, 16);
134#else
wdenk38635852002-08-27 05:55:31 +0000135 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800136#endif
wdenk38635852002-08-27 05:55:31 +0000137
138 /* Count ? */
139 if (argc == 4) {
140 count = simple_strtoul(argv[3], NULL, 16);
141 } else {
142 count = 1;
143 }
144
Simon Glass0628ab82013-02-24 17:33:15 +0000145 bytes = size * count;
Simon Glasscc5e1962015-03-05 12:25:18 -0700146 start = map_sysmem(addr, bytes);
147 buf = start;
wdenk38635852002-08-27 05:55:31 +0000148 while (count-- > 0) {
149 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -0800150 *((u32 *)buf) = (u32)writeval;
Simon Glass4d979bf2019-12-28 10:45:10 -0700151#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800152 else if (size == 8)
153 *((u64 *)buf) = (u64)writeval;
154#endif
wdenk38635852002-08-27 05:55:31 +0000155 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -0800156 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000157 else
York Sun76698b42014-02-12 15:55:35 -0800158 *((u8 *)buf) = (u8)writeval;
Simon Glass0628ab82013-02-24 17:33:15 +0000159 buf += size;
wdenk38635852002-08-27 05:55:31 +0000160 }
Simon Glasscc5e1962015-03-05 12:25:18 -0700161 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000162 return 0;
163}
164
Joel Johnson72732312020-01-29 09:17:18 -0700165#ifdef CONFIG_CMD_MX_CYCLIC
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900166static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000167{
168 int i;
169 ulong count;
170
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200171 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000172 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000173
174 count = simple_strtoul(argv[3], NULL, 10);
175
176 for (;;) {
177 do_mem_md (NULL, 0, 3, argv);
178
179 /* delay for <count> ms... */
180 for (i=0; i<count; i++)
181 udelay (1000);
182
183 /* check for ctrl-c to abort... */
184 if (ctrlc()) {
185 puts("Abort\n");
186 return 0;
187 }
188 }
189
190 return 0;
191}
192
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900193static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000194{
195 int i;
196 ulong count;
197
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200198 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000199 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000200
201 count = simple_strtoul(argv[3], NULL, 10);
202
203 for (;;) {
204 do_mem_mw (NULL, 0, 3, argv);
205
206 /* delay for <count> ms... */
207 for (i=0; i<count; i++)
208 udelay (1000);
209
210 /* check for ctrl-c to abort... */
211 if (ctrlc()) {
212 puts("Abort\n");
213 return 0;
214 }
215 }
216
217 return 0;
218}
Joel Johnson72732312020-01-29 09:17:18 -0700219#endif /* CONFIG_CMD_MX_CYCLIC */
stroese4aaf29b2004-12-16 17:42:39 +0000220
Kim Phillips088f1b12012-10-29 13:34:31 +0000221static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000222{
Simon Glass0628ab82013-02-24 17:33:15 +0000223 ulong addr1, addr2, count, ngood, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000224 int size;
wdenk38635852002-08-27 05:55:31 +0000225 int rcode = 0;
Mike Frysinger054ea172012-01-20 09:07:21 +0000226 const char *type;
Simon Glass0628ab82013-02-24 17:33:15 +0000227 const void *buf1, *buf2, *base;
Simon Glass4d979bf2019-12-28 10:45:10 -0700228#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800229 u64 word1, word2;
230#else
231 ulong word1, word2;
232#endif
wdenk38635852002-08-27 05:55:31 +0000233
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200234 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000235 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000236
237 /* Check for size specification.
238 */
wdenk27b207f2003-07-24 23:38:38 +0000239 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
240 return 1;
York Sun4d1fd7f2014-02-26 17:03:19 -0800241 type = size == 8 ? "double word" :
242 size == 4 ? "word" :
243 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000244
245 addr1 = simple_strtoul(argv[1], NULL, 16);
246 addr1 += base_address;
247
248 addr2 = simple_strtoul(argv[2], NULL, 16);
249 addr2 += base_address;
250
251 count = simple_strtoul(argv[3], NULL, 16);
252
Simon Glass0628ab82013-02-24 17:33:15 +0000253 bytes = size * count;
254 base = buf1 = map_sysmem(addr1, bytes);
255 buf2 = map_sysmem(addr2, bytes);
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000256 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000257 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800258 word1 = *(u32 *)buf1;
259 word2 = *(u32 *)buf2;
Simon Glass4d979bf2019-12-28 10:45:10 -0700260#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800261 } else if (size == 8) {
262 word1 = *(u64 *)buf1;
263 word2 = *(u64 *)buf2;
264#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000265 } else if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800266 word1 = *(u16 *)buf1;
267 word2 = *(u16 *)buf2;
Mike Frysinger054ea172012-01-20 09:07:21 +0000268 } else {
York Sun76698b42014-02-12 15:55:35 -0800269 word1 = *(u8 *)buf1;
270 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000271 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000272 if (word1 != word2) {
Simon Glass0628ab82013-02-24 17:33:15 +0000273 ulong offset = buf1 - base;
Simon Glass4d979bf2019-12-28 10:45:10 -0700274#ifdef MEM_SUPPORT_64BIT_DATA
Masahiro Yamadadee37fc2018-08-06 20:47:40 +0900275 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
York Sun4d1fd7f2014-02-26 17:03:19 -0800276 type, (void *)(addr1 + offset), size, word1,
277 type, (void *)(addr2 + offset), size, word2);
278#else
Mike Frysinger054ea172012-01-20 09:07:21 +0000279 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glass0628ab82013-02-24 17:33:15 +0000280 type, (ulong)(addr1 + offset), size, word1,
281 type, (ulong)(addr2 + offset), size, word2);
York Sun4d1fd7f2014-02-26 17:03:19 -0800282#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000283 rcode = 1;
284 break;
wdenk38635852002-08-27 05:55:31 +0000285 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000286
Simon Glass0628ab82013-02-24 17:33:15 +0000287 buf1 += size;
288 buf2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200289
290 /* reset watchdog from time to time */
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000291 if ((ngood % (64 << 10)) == 0)
Stefan Roeseeaadb442010-09-13 11:10:34 +0200292 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000293 }
Simon Glass0628ab82013-02-24 17:33:15 +0000294 unmap_sysmem(buf1);
295 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000296
Mike Frysinger054ea172012-01-20 09:07:21 +0000297 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000298 return rcode;
299}
300
Kim Phillips088f1b12012-10-29 13:34:31 +0000301static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000302{
Fabio Estevamc2538422016-12-15 16:00:13 -0200303 ulong addr, dest, count;
Philippe Reynes787f10a2019-12-02 17:33:22 +0100304 void *src, *dst;
wdenk27b207f2003-07-24 23:38:38 +0000305 int size;
wdenk38635852002-08-27 05:55:31 +0000306
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200307 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000308 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000309
310 /* Check for size specification.
311 */
wdenk27b207f2003-07-24 23:38:38 +0000312 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
313 return 1;
wdenk38635852002-08-27 05:55:31 +0000314
315 addr = simple_strtoul(argv[1], NULL, 16);
316 addr += base_address;
317
318 dest = simple_strtoul(argv[2], NULL, 16);
319 dest += base_address;
320
321 count = simple_strtoul(argv[3], NULL, 16);
322
323 if (count == 0) {
324 puts ("Zero length ???\n");
325 return 1;
326 }
327
Philippe Reynes787f10a2019-12-02 17:33:22 +0100328 src = map_sysmem(addr, count * size);
329 dst = map_sysmem(dest, count * size);
330
Masahiro Yamadae856bdc2017-02-11 22:43:54 +0900331#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000332 /* check if we are copying to Flash */
Philippe Reynes787f10a2019-12-02 17:33:22 +0100333 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000334 int rc;
335
wdenk4b9206e2004-03-23 22:14:11 +0000336 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000337
Philippe Reynes787f10a2019-12-02 17:33:22 +0100338 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000339 if (rc != 0) {
Simon Glass0ee482522019-12-28 10:44:40 -0700340 flash_perror(rc);
Philippe Reynes787f10a2019-12-02 17:33:22 +0100341 unmap_sysmem(src);
342 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000343 return (1);
344 }
345 puts ("done\n");
Philippe Reynes787f10a2019-12-02 17:33:22 +0100346 unmap_sysmem(src);
347 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000348 return 0;
349 }
350#endif
351
Philippe Reynes787f10a2019-12-02 17:33:22 +0100352 memcpy(dst, src, count * size);
Masahiro Yamadaa3a47492014-10-23 17:46:24 +0900353
Philippe Reynes787f10a2019-12-02 17:33:22 +0100354 unmap_sysmem(src);
355 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000356 return 0;
357}
358
Kim Phillips088f1b12012-10-29 13:34:31 +0000359static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
360 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000361{
362 if (argc > 1) {
363 /* Set new base address.
364 */
365 base_address = simple_strtoul(argv[1], NULL, 16);
366 }
367 /* Print the current base address.
368 */
369 printf("Base Address: 0x%08lx\n", base_address);
370 return 0;
371}
372
Kim Phillips088f1b12012-10-29 13:34:31 +0000373static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
374 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000375{
Simon Glass0628ab82013-02-24 17:33:15 +0000376 ulong addr, length, i, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000377 int size;
Simon Glass4d979bf2019-12-28 10:45:10 -0700378#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800379 volatile u64 *llp;
380#endif
York Sun76698b42014-02-12 15:55:35 -0800381 volatile u32 *longp;
382 volatile u16 *shortp;
383 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000384 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000385
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200386 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000387 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000388
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000389 /*
390 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000391 * Defaults to long if no or incorrect specification.
392 */
wdenk27b207f2003-07-24 23:38:38 +0000393 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
394 return 1;
wdenk38635852002-08-27 05:55:31 +0000395
396 /* Address is always specified.
397 */
398 addr = simple_strtoul(argv[1], NULL, 16);
399
400 /* Length is the number of objects, not number of bytes.
401 */
402 length = simple_strtoul(argv[2], NULL, 16);
403
Simon Glass0628ab82013-02-24 17:33:15 +0000404 bytes = size * length;
405 buf = map_sysmem(addr, bytes);
406
wdenk38635852002-08-27 05:55:31 +0000407 /* We want to optimize the loops to run as fast as possible.
408 * If we have only one object, just run infinite loops.
409 */
410 if (length == 1) {
Simon Glass4d979bf2019-12-28 10:45:10 -0700411#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800412 if (size == 8) {
413 llp = (u64 *)buf;
414 for (;;)
415 i = *llp;
416 }
417#endif
wdenk38635852002-08-27 05:55:31 +0000418 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800419 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000420 for (;;)
421 i = *longp;
422 }
423 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800424 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000425 for (;;)
426 i = *shortp;
427 }
York Sun76698b42014-02-12 15:55:35 -0800428 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000429 for (;;)
430 i = *cp;
431 }
432
Simon Glass4d979bf2019-12-28 10:45:10 -0700433#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800434 if (size == 8) {
435 for (;;) {
436 llp = (u64 *)buf;
437 i = length;
438 while (i-- > 0)
439 *llp++;
440 }
441 }
442#endif
wdenk38635852002-08-27 05:55:31 +0000443 if (size == 4) {
444 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800445 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000446 i = length;
447 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200448 *longp++;
wdenk38635852002-08-27 05:55:31 +0000449 }
450 }
451 if (size == 2) {
452 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800453 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000454 i = length;
455 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200456 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000457 }
458 }
459 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800460 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000461 i = length;
462 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200463 *cp++;
wdenk38635852002-08-27 05:55:31 +0000464 }
Simon Glass0628ab82013-02-24 17:33:15 +0000465 unmap_sysmem(buf);
Simon Glass92765f422013-06-11 11:14:35 -0700466
467 return 0;
wdenk38635852002-08-27 05:55:31 +0000468}
469
wdenk56523f12004-07-11 17:40:54 +0000470#ifdef CONFIG_LOOPW
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900471static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
472 char * const argv[])
wdenk56523f12004-07-11 17:40:54 +0000473{
York Sun4d1fd7f2014-02-26 17:03:19 -0800474 ulong addr, length, i, bytes;
wdenk56523f12004-07-11 17:40:54 +0000475 int size;
Simon Glass4d979bf2019-12-28 10:45:10 -0700476#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800477 volatile u64 *llp;
478 u64 data;
479#else
480 ulong data;
481#endif
York Sun76698b42014-02-12 15:55:35 -0800482 volatile u32 *longp;
483 volatile u16 *shortp;
484 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000485 void *buf;
wdenk81050922004-07-11 20:04:51 +0000486
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200487 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000488 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000489
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000490 /*
491 * Check for a size specification.
wdenk56523f12004-07-11 17:40:54 +0000492 * Defaults to long if no or incorrect specification.
493 */
494 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
495 return 1;
496
497 /* Address is always specified.
498 */
499 addr = simple_strtoul(argv[1], NULL, 16);
500
501 /* Length is the number of objects, not number of bytes.
502 */
503 length = simple_strtoul(argv[2], NULL, 16);
504
505 /* data to write */
Simon Glass4d979bf2019-12-28 10:45:10 -0700506#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800507 data = simple_strtoull(argv[3], NULL, 16);
508#else
wdenk56523f12004-07-11 17:40:54 +0000509 data = simple_strtoul(argv[3], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800510#endif
wdenk81050922004-07-11 20:04:51 +0000511
Simon Glass0628ab82013-02-24 17:33:15 +0000512 bytes = size * length;
513 buf = map_sysmem(addr, bytes);
514
wdenk56523f12004-07-11 17:40:54 +0000515 /* We want to optimize the loops to run as fast as possible.
516 * If we have only one object, just run infinite loops.
517 */
518 if (length == 1) {
Simon Glass4d979bf2019-12-28 10:45:10 -0700519#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800520 if (size == 8) {
521 llp = (u64 *)buf;
522 for (;;)
523 *llp = data;
524 }
525#endif
wdenk56523f12004-07-11 17:40:54 +0000526 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800527 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000528 for (;;)
529 *longp = data;
York Sun4d1fd7f2014-02-26 17:03:19 -0800530 }
wdenk56523f12004-07-11 17:40:54 +0000531 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800532 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000533 for (;;)
534 *shortp = data;
535 }
York Sun76698b42014-02-12 15:55:35 -0800536 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000537 for (;;)
538 *cp = data;
539 }
540
Simon Glass4d979bf2019-12-28 10:45:10 -0700541#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800542 if (size == 8) {
543 for (;;) {
544 llp = (u64 *)buf;
545 i = length;
546 while (i-- > 0)
547 *llp++ = data;
548 }
549 }
550#endif
wdenk56523f12004-07-11 17:40:54 +0000551 if (size == 4) {
552 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800553 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000554 i = length;
555 while (i-- > 0)
556 *longp++ = data;
557 }
558 }
559 if (size == 2) {
560 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800561 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000562 i = length;
563 while (i-- > 0)
564 *shortp++ = data;
565 }
566 }
567 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800568 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000569 i = length;
570 while (i-- > 0)
571 *cp++ = data;
572 }
573}
574#endif /* CONFIG_LOOPW */
575
Tom Rini68149e92013-03-12 10:07:19 -0400576#ifdef CONFIG_CMD_MEMTEST
Simon Glass5512d5b2013-02-28 17:47:14 +0000577static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
578 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000579{
Simon Glassc9638f52013-02-24 17:33:16 +0000580 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000581 ulong errs = 0;
582 ulong val, readback;
583 int j;
Simon Glassc9638f52013-02-24 17:33:16 +0000584 vu_long offset;
585 vu_long test_offset;
586 vu_long pattern;
587 vu_long temp;
588 vu_long anti_pattern;
589 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000590 static const ulong bitpattern[] = {
591 0x00000001, /* single bit */
592 0x00000003, /* two adjacent bits */
593 0x00000007, /* three adjacent bits */
594 0x0000000F, /* four adjacent bits */
595 0x00000005, /* two non-adjacent bits */
596 0x00000015, /* three non-adjacent bits */
597 0x00000055, /* four non-adjacent bits */
598 0xaaaaaaaa, /* alternating 1/0 */
599 };
wdenk38635852002-08-27 05:55:31 +0000600
Simon Glass5512d5b2013-02-28 17:47:14 +0000601 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000602
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000603 /*
604 * Data line test: write a pattern to the first
605 * location, write the 1's complement to a 'parking'
606 * address (changes the state of the data bus so a
607 * floating bus doesn't give a false OK), and then
608 * read the value back. Note that we read it back
609 * into a variable because the next time we read it,
610 * it might be right (been there, tough to explain to
611 * the quality guys why it prints a failure when the
612 * "is" and "should be" are obviously the same in the
613 * error message).
614 *
615 * Rather than exhaustively testing, we test some
616 * patterns by shifting '1' bits through a field of
617 * '0's and '0' bits through a field of '1's (i.e.
618 * pattern and ~pattern).
619 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000620 addr = buf;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000621 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
622 val = bitpattern[j];
623 for (; val != 0; val <<= 1) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000624 *addr = val;
Simon Glassc9638f52013-02-24 17:33:16 +0000625 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000626 readback = *addr;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000627 if (readback != val) {
Simon Glassc9638f52013-02-24 17:33:16 +0000628 printf("FAILURE (data line): "
629 "expected %08lx, actual %08lx\n",
630 val, readback);
631 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000632 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000633 return -1;
wdenk38635852002-08-27 05:55:31 +0000634 }
635 *addr = ~val;
636 *dummy = val;
637 readback = *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000638 if (readback != ~val) {
639 printf("FAILURE (data line): "
640 "Is %08lx, should be %08lx\n",
641 readback, ~val);
642 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000643 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000644 return -1;
wdenk38635852002-08-27 05:55:31 +0000645 }
wdenk38635852002-08-27 05:55:31 +0000646 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000647 }
wdenk38635852002-08-27 05:55:31 +0000648
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000649 /*
650 * Based on code whose Original Author and Copyright
651 * information follows: Copyright (c) 1998 by Michael
652 * Barr. This software is placed into the public
653 * domain and may be used for any purpose. However,
654 * this notice must not be changed or removed and no
655 * warranty is either expressed or implied by its
656 * publication or distribution.
657 */
wdenk38635852002-08-27 05:55:31 +0000658
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000659 /*
660 * Address line test
wdenk38635852002-08-27 05:55:31 +0000661
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000662 * Description: Test the address bus wiring in a
663 * memory region by performing a walking
664 * 1's test on the relevant bits of the
665 * address and checking for aliasing.
666 * This test will find single-bit
667 * address failures such as stuck-high,
668 * stuck-low, and shorted pins. The base
669 * address and size of the region are
670 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000671
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000672 * Notes: For best results, the selected base
673 * address should have enough LSB 0's to
674 * guarantee single address bit changes.
675 * For example, to test a 64-Kbyte
676 * region, select a base address on a
677 * 64-Kbyte boundary. Also, select the
678 * region size as a power-of-two if at
679 * all possible.
680 *
681 * Returns: 0 if the test succeeds, 1 if the test fails.
682 */
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000683 pattern = (vu_long) 0xaaaaaaaa;
684 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000685
Simon Glass5512d5b2013-02-28 17:47:14 +0000686 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000687 /*
688 * Write the default pattern at each of the
689 * power-of-two offsets.
690 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000691 for (offset = 1; offset < num_words; offset <<= 1)
692 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000693
694 /*
695 * Check for address bits stuck high.
696 */
697 test_offset = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000698 addr[test_offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000699
Simon Glass5512d5b2013-02-28 17:47:14 +0000700 for (offset = 1; offset < num_words; offset <<= 1) {
701 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000702 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000703 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000704 " expected 0x%.8lx, actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800705 start_addr + offset*sizeof(vu_long),
706 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400707 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000708 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000709 return -1;
wdenk38635852002-08-27 05:55:31 +0000710 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000711 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000712 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000713 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000714
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000715 /*
716 * Check for addr bits stuck low or shorted.
717 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000718 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
719 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000720
Simon Glass5512d5b2013-02-28 17:47:14 +0000721 for (offset = 1; offset < num_words; offset <<= 1) {
722 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000723 if ((temp != pattern) && (offset != test_offset)) {
724 printf("\nFAILURE: Address bit stuck low or"
725 " shorted @ 0x%.8lx: expected 0x%.8lx,"
726 " actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800727 start_addr + offset*sizeof(vu_long),
728 pattern, temp);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000729 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000730 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000731 return -1;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000732 }
wdenk38635852002-08-27 05:55:31 +0000733 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000734 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000735 }
wdenk38635852002-08-27 05:55:31 +0000736
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000737 /*
738 * Description: Test the integrity of a physical
739 * memory device by performing an
740 * increment/decrement test over the
741 * entire region. In the process every
742 * storage bit in the device is tested
743 * as a zero and a one. The base address
744 * and the size of the region are
745 * selected by the caller.
746 *
747 * Returns: 0 if the test succeeds, 1 if the test fails.
748 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000749 num_words++;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000750
751 /*
752 * Fill memory with a known pattern.
753 */
754 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
755 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000756 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000757 }
758
759 /*
760 * Check each location and invert it for the second pass.
761 */
762 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
763 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000764 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000765 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000766 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000767 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800768 start_addr + offset*sizeof(vu_long),
769 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400770 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000771 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000772 return -1;
wdenk38635852002-08-27 05:55:31 +0000773 }
774
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000775 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000776 addr[offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000777 }
778
779 /*
780 * Check each location for the inverted pattern and zero it.
781 */
782 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
783 WATCHDOG_RESET();
784 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000785 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000786 if (temp != anti_pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000787 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000788 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800789 start_addr + offset*sizeof(vu_long),
790 anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400791 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000792 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000793 return -1;
wdenk38635852002-08-27 05:55:31 +0000794 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000795 addr[offset] = 0;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000796 }
Simon Glass51209b12013-02-24 17:33:17 +0000797
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100798 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000799}
wdenk38635852002-08-27 05:55:31 +0000800
Stefan Roese8e434cb2020-03-05 07:21:32 +0100801static int compare_regions(volatile unsigned long *bufa,
802 volatile unsigned long *bufb, size_t count)
803{
804 volatile unsigned long *p1 = bufa;
805 volatile unsigned long *p2 = bufb;
806 int errs = 0;
807 size_t i;
808
809 for (i = 0; i < count; i++, p1++, p2++) {
810 if (*p1 != *p2) {
811 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
812 (unsigned long)*p1, (unsigned long)*p2,
813 *p1 ^ *p2, __ffs(*p1 ^ *p2),
814 (unsigned long)(i * sizeof(unsigned long)));
815 errs++;
816 }
817 }
818
819 return errs;
820}
821
822static ulong test_bitflip_comparison(volatile unsigned long *bufa,
823 volatile unsigned long *bufb, size_t count)
824{
825 volatile unsigned long *p1 = bufa;
826 volatile unsigned long *p2 = bufb;
827 unsigned int j, k;
828 unsigned long q;
829 size_t i;
830 int max;
831 int errs = 0;
832
833 max = sizeof(unsigned long) * 8;
834 for (k = 0; k < max; k++) {
835 q = 0x00000001L << k;
836 for (j = 0; j < 8; j++) {
837 WATCHDOG_RESET();
838 q = ~q;
839 p1 = (volatile unsigned long *)bufa;
840 p2 = (volatile unsigned long *)bufb;
841 for (i = 0; i < count; i++)
842 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
843
844 errs += compare_regions(bufa, bufb, count);
845 }
846
847 if (ctrlc())
848 return -1UL;
849 }
850
851 return errs;
852}
853
Simon Glass5512d5b2013-02-28 17:47:14 +0000854static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
855 vu_long pattern, int iteration)
Simon Glassc9638f52013-02-24 17:33:16 +0000856{
Simon Glass5512d5b2013-02-28 17:47:14 +0000857 vu_long *end;
Simon Glassc9638f52013-02-24 17:33:16 +0000858 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000859 ulong errs = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000860 ulong incr, length;
Simon Glassc9638f52013-02-24 17:33:16 +0000861 ulong val, readback;
862
Simon Glass51209b12013-02-24 17:33:17 +0000863 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000864 incr = 1;
Simon Glass51209b12013-02-24 17:33:17 +0000865 if (iteration & 1) {
866 incr = -incr;
867 /*
868 * Flip the pattern each time to make lots of zeros and
869 * then, the next time, lots of ones. We decrement
870 * the "negative" patterns and increment the "positive"
871 * patterns to preserve this feature.
872 */
873 if (pattern & 0x80000000)
874 pattern = -pattern; /* complement & increment */
875 else
876 pattern = ~pattern;
877 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000878 length = (end_addr - start_addr) / sizeof(ulong);
879 end = buf + length;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000880 printf("\rPattern %08lX Writing..."
881 "%12s"
882 "\b\b\b\b\b\b\b\b\b\b",
883 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000884
Simon Glass5512d5b2013-02-28 17:47:14 +0000885 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000886 WATCHDOG_RESET();
887 *addr = val;
888 val += incr;
889 }
wdenk38635852002-08-27 05:55:31 +0000890
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000891 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000892
Simon Glass5512d5b2013-02-28 17:47:14 +0000893 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000894 WATCHDOG_RESET();
895 readback = *addr;
896 if (readback != val) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000897 ulong offset = addr - buf;
898
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000899 printf("\nMem error @ 0x%08X: "
900 "found %08lX, expected %08lX\n",
David Feng102c0512014-02-12 16:10:08 +0800901 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glass5512d5b2013-02-28 17:47:14 +0000902 readback, val);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000903 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000904 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000905 return -1;
wdenk38635852002-08-27 05:55:31 +0000906 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000907 val += incr;
908 }
wdenk38635852002-08-27 05:55:31 +0000909
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100910 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000911}
912
913/*
914 * Perform a memory test. A more complete alternative test can be
915 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
916 * interrupted by ctrl-c or by a failure of one of the sub-tests.
917 */
918static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
919 char * const argv[])
920{
Simon Glass8c86bbe2013-02-24 17:33:20 +0000921 ulong start, end;
Michal Simeke519f032020-05-04 13:54:40 +0200922 vu_long scratch_space;
923 vu_long *buf, *dummy = &scratch_space;
Tom Riniadcc5702015-04-07 09:38:54 -0400924 ulong iteration_limit = 0;
Stefan Roesea8c708e2020-03-05 07:21:29 +0100925 ulong count = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000926 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200927 ulong pattern = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000928 int iteration;
Simon Glassc9638f52013-02-24 17:33:16 +0000929
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200930 start = CONFIG_SYS_MEMTEST_START;
931 end = CONFIG_SYS_MEMTEST_END;
932
Simon Glassc9638f52013-02-24 17:33:16 +0000933 if (argc > 1)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200934 if (strict_strtoul(argv[1], 16, &start) < 0)
935 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000936
937 if (argc > 2)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200938 if (strict_strtoul(argv[2], 16, &end) < 0)
939 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000940
941 if (argc > 3)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200942 if (strict_strtoul(argv[3], 16, &pattern) < 0)
943 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000944
945 if (argc > 4)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200946 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
947 return CMD_RET_USAGE;
948
949 if (end < start) {
950 printf("Refusing to do empty test\n");
951 return -1;
952 }
Simon Glassc9638f52013-02-24 17:33:16 +0000953
Michal Simekdfe461d2016-02-24 08:36:02 +0100954 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000955 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
956 start, end);
Simon Glass51209b12013-02-24 17:33:17 +0000957
Simon Glass5512d5b2013-02-28 17:47:14 +0000958 buf = map_sysmem(start, end - start);
Simon Glass51209b12013-02-24 17:33:17 +0000959 for (iteration = 0;
960 !iteration_limit || iteration < iteration_limit;
961 iteration++) {
962 if (ctrlc()) {
Simon Glass51209b12013-02-24 17:33:17 +0000963 errs = -1UL;
964 break;
965 }
966
967 printf("Iteration: %6d\r", iteration + 1);
968 debug("\n");
Stefan Roesef14bfa72020-03-05 07:21:31 +0100969 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000970 errs = mem_test_alt(buf, start, end, dummy);
Stefan Roese8e434cb2020-03-05 07:21:32 +0100971 if (errs == -1UL)
972 break;
973 count += errs;
974 errs = test_bitflip_comparison(buf,
975 buf + (end - start) / 2,
976 (end - start) /
977 sizeof(unsigned long));
Simon Glass5512d5b2013-02-28 17:47:14 +0000978 } else {
979 errs = mem_test_quick(buf, start, end, pattern,
980 iteration);
981 }
982 if (errs == -1UL)
983 break;
Stefan Roesea8c708e2020-03-05 07:21:29 +0100984 count += errs;
Simon Glass5512d5b2013-02-28 17:47:14 +0000985 }
986
Stefan Roese54de2442020-03-05 07:21:30 +0100987 unmap_sysmem((void *)buf);
Simon Glass51209b12013-02-24 17:33:17 +0000988
989 if (errs == -1UL) {
Simon Glassc44d4382013-02-24 17:33:19 +0000990 /* Memory test was aborted - write a newline to finish off */
991 putc('\n');
Simon Glass51209b12013-02-24 17:33:17 +0000992 }
Stefan Roesea8c708e2020-03-05 07:21:29 +0100993 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
Simon Glassc9638f52013-02-24 17:33:16 +0000994
Stefan Roesea8c708e2020-03-05 07:21:29 +0100995 return errs != 0;
wdenk38635852002-08-27 05:55:31 +0000996}
Wolfgang Denka2681702013-03-08 10:51:32 +0000997#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +0000998
999/* Modify memory.
1000 *
1001 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -08001002 * mm{.b, .w, .l, .q} {addr}
1003 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001004 */
1005static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001006mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001007{
York Sun4d1fd7f2014-02-26 17:03:19 -08001008 ulong addr;
Simon Glass4d979bf2019-12-28 10:45:10 -07001009#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001010 u64 i;
1011#else
1012 ulong i;
1013#endif
wdenk27b207f2003-07-24 23:38:38 +00001014 int nbytes, size;
Simon Glass0628ab82013-02-24 17:33:15 +00001015 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001016
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001017 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001018 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001019
Simon Glassb26440f2014-04-10 20:01:31 -06001020 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001021 /* We use the last specified parameters, unless new ones are
1022 * entered.
1023 */
1024 addr = mm_last_addr;
1025 size = mm_last_size;
1026
1027 if ((flag & CMD_FLAG_REPEAT) == 0) {
1028 /* New command specified. Check for a size specification.
1029 * Defaults to long if no or incorrect specification.
1030 */
wdenk27b207f2003-07-24 23:38:38 +00001031 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1032 return 1;
wdenk38635852002-08-27 05:55:31 +00001033
1034 /* Address is specified since argc > 1
1035 */
1036 addr = simple_strtoul(argv[1], NULL, 16);
1037 addr += base_address;
1038 }
1039
1040 /* Print the address, followed by value. Then accept input for
1041 * the next value. A non-converted value exits.
1042 */
1043 do {
Simon Glass0628ab82013-02-24 17:33:15 +00001044 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001045 printf("%08lx:", addr);
1046 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001047 printf(" %08x", *((u32 *)ptr));
Simon Glass4d979bf2019-12-28 10:45:10 -07001048#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001049 else if (size == 8)
Masahiro Yamadadee37fc2018-08-06 20:47:40 +09001050 printf(" %016llx", *((u64 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001051#endif
wdenk38635852002-08-27 05:55:31 +00001052 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001053 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001054 else
York Sun76698b42014-02-12 15:55:35 -08001055 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001056
Simon Glasse1bf8242014-04-10 20:01:27 -06001057 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001058 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1059 /* <CR> pressed as only input, don't modify current
1060 * location and move to next. "-" pressed will go back.
1061 */
1062 if (incrflag)
1063 addr += nbytes ? -size : size;
1064 nbytes = 1;
Simon Glassb26440f2014-04-10 20:01:31 -06001065 /* good enough to not time out */
1066 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001067 }
1068#ifdef CONFIG_BOOT_RETRY_TIME
1069 else if (nbytes == -2) {
1070 break; /* timed out, exit the command */
1071 }
1072#endif
1073 else {
1074 char *endp;
Simon Glass4d979bf2019-12-28 10:45:10 -07001075#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001076 i = simple_strtoull(console_buffer, &endp, 16);
1077#else
wdenk38635852002-08-27 05:55:31 +00001078 i = simple_strtoul(console_buffer, &endp, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -08001079#endif
wdenk38635852002-08-27 05:55:31 +00001080 nbytes = endp - console_buffer;
1081 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001082 /* good enough to not time out
1083 */
Simon Glassb26440f2014-04-10 20:01:31 -06001084 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001085 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001086 *((u32 *)ptr) = i;
Simon Glass4d979bf2019-12-28 10:45:10 -07001087#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001088 else if (size == 8)
1089 *((u64 *)ptr) = i;
1090#endif
wdenk38635852002-08-27 05:55:31 +00001091 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001092 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001093 else
York Sun76698b42014-02-12 15:55:35 -08001094 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001095 if (incrflag)
1096 addr += size;
1097 }
1098 }
1099 } while (nbytes);
Simon Glass0628ab82013-02-24 17:33:15 +00001100 if (ptr)
1101 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001102
1103 mm_last_addr = addr;
1104 mm_last_size = size;
1105 return 0;
1106}
1107
Mike Frysinger710b9932010-12-21 14:19:51 -05001108#ifdef CONFIG_CMD_CRC32
1109
Kim Phillips088f1b12012-10-29 13:34:31 +00001110static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001111{
Simon Glassd20a40d2013-02-24 20:30:22 +00001112 int flags = 0;
1113 int ac;
1114 char * const *av;
wdenk38635852002-08-27 05:55:31 +00001115
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001116 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001117 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001118
wdenkc26e4542004-04-18 10:13:26 +00001119 av = argv + 1;
1120 ac = argc - 1;
Daniel Thompson221a9492017-05-19 17:26:58 +01001121#ifdef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001122 if (strcmp(*av, "-v") == 0) {
Joe Hershbergera69bdba2015-05-05 12:23:53 -05001123 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenkc26e4542004-04-18 10:13:26 +00001124 av++;
1125 ac--;
wdenkc26e4542004-04-18 10:13:26 +00001126 }
Simon Glassd20a40d2013-02-24 20:30:22 +00001127#endif
wdenkc26e4542004-04-18 10:13:26 +00001128
Simon Glassd20a40d2013-02-24 20:30:22 +00001129 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenkc26e4542004-04-18 10:13:26 +00001130}
wdenkc26e4542004-04-18 10:13:26 +00001131
Mike Frysinger710b9932010-12-21 14:19:51 -05001132#endif
1133
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001134#ifdef CONFIG_CMD_RANDOM
1135static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1136{
1137 unsigned long addr, len;
1138 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1139 unsigned int *buf, *start;
1140 unsigned char *buf8;
1141 unsigned int i;
1142
Eugeniy Paltsev5f2c4e02020-03-20 19:38:17 +03001143 if (argc < 3 || argc > 4)
1144 return CMD_RET_USAGE;
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001145
1146 len = simple_strtoul(argv[2], NULL, 16);
1147 addr = simple_strtoul(argv[1], NULL, 16);
1148
1149 if (argc == 4) {
1150 seed = simple_strtoul(argv[3], NULL, 16);
1151 if (seed == 0) {
1152 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1153 seed = 0xDEADBEEF;
1154 }
1155 } else {
1156 seed = get_timer(0) ^ rand();
1157 }
1158
1159 srand(seed);
1160 start = map_sysmem(addr, len);
1161 buf = start;
1162 for (i = 0; i < (len / 4); i++)
1163 *buf++ = rand();
1164
1165 buf8 = (unsigned char *)buf;
1166 for (i = 0; i < (len % 4); i++)
1167 *buf8++ = rand() & 0xFF;
1168
1169 unmap_sysmem(start);
1170 printf("%lu bytes filled with random data\n", len);
Eugeniy Paltsev5f2c4e02020-03-20 19:38:17 +03001171
1172 return CMD_RET_SUCCESS;
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001173}
1174#endif
1175
wdenk8bde7f72003-06-27 21:31:46 +00001176/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001177U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001178 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001179 "memory display",
Simon Glass4d979bf2019-12-28 10:45:10 -07001180#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001181 "[.b, .w, .l, .q] address [# of objects]"
1182#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001183 "[.b, .w, .l] address [# of objects]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001184#endif
wdenk8bde7f72003-06-27 21:31:46 +00001185);
1186
1187
wdenk0d498392003-07-01 21:06:45 +00001188U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001189 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001190 "memory modify (auto-incrementing address)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001191#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001192 "[.b, .w, .l, .q] address"
1193#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001194 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001195#endif
wdenk8bde7f72003-06-27 21:31:46 +00001196);
1197
1198
wdenk0d498392003-07-01 21:06:45 +00001199U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001200 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001201 "memory modify (constant address)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001202#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001203 "[.b, .w, .l, .q] address"
1204#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001205 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001206#endif
wdenk8bde7f72003-06-27 21:31:46 +00001207);
1208
wdenk0d498392003-07-01 21:06:45 +00001209U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001210 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001211 "memory write (fill)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001212#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001213 "[.b, .w, .l, .q] address value [count]"
1214#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001215 "[.b, .w, .l] address value [count]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001216#endif
wdenk8bde7f72003-06-27 21:31:46 +00001217);
1218
wdenk0d498392003-07-01 21:06:45 +00001219U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001220 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001221 "memory copy",
Simon Glass4d979bf2019-12-28 10:45:10 -07001222#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001223 "[.b, .w, .l, .q] source target count"
1224#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001225 "[.b, .w, .l] source target count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001226#endif
wdenk8bde7f72003-06-27 21:31:46 +00001227);
1228
wdenk0d498392003-07-01 21:06:45 +00001229U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001230 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001231 "memory compare",
Simon Glass4d979bf2019-12-28 10:45:10 -07001232#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001233 "[.b, .w, .l, .q] addr1 addr2 count"
1234#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001235 "[.b, .w, .l] addr1 addr2 count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001236#endif
wdenk8bde7f72003-06-27 21:31:46 +00001237);
1238
Mike Frysinger710b9932010-12-21 14:19:51 -05001239#ifdef CONFIG_CMD_CRC32
1240
Daniel Thompson221a9492017-05-19 17:26:58 +01001241#ifndef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001242
wdenk0d498392003-07-01 21:06:45 +00001243U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001244 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001245 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001246 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001247);
1248
Daniel Thompson221a9492017-05-19 17:26:58 +01001249#else /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001250
1251U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001252 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001253 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001254 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001255 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001256);
1257
Daniel Thompson221a9492017-05-19 17:26:58 +01001258#endif /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001259
Mike Frysinger710b9932010-12-21 14:19:51 -05001260#endif
1261
Simon Glass15a33e42012-11-30 13:01:20 +00001262#ifdef CONFIG_CMD_MEMINFO
Simon Glass15a33e42012-11-30 13:01:20 +00001263static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1264 char * const argv[])
1265{
Simon Glass428a6a12019-11-14 12:57:44 -07001266 puts("DRAM: ");
1267 print_size(gd->ram_size, "\n");
Simon Glass15a33e42012-11-30 13:01:20 +00001268
1269 return 0;
1270}
1271#endif
1272
wdenk0d498392003-07-01 21:06:45 +00001273U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001274 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001275 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001276 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001277 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001278);
1279
wdenk0d498392003-07-01 21:06:45 +00001280U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001281 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001282 "infinite loop on address range",
Simon Glass4d979bf2019-12-28 10:45:10 -07001283#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001284 "[.b, .w, .l, .q] address number_of_objects"
1285#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001286 "[.b, .w, .l] address number_of_objects"
York Sun4d1fd7f2014-02-26 17:03:19 -08001287#endif
wdenk8bde7f72003-06-27 21:31:46 +00001288);
1289
wdenk56523f12004-07-11 17:40:54 +00001290#ifdef CONFIG_LOOPW
1291U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001292 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001293 "infinite write loop on address range",
Simon Glass4d979bf2019-12-28 10:45:10 -07001294#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001295 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1296#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001297 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun4d1fd7f2014-02-26 17:03:19 -08001298#endif
wdenk56523f12004-07-11 17:40:54 +00001299);
1300#endif /* CONFIG_LOOPW */
1301
Wolfgang Denka2681702013-03-08 10:51:32 +00001302#ifdef CONFIG_CMD_MEMTEST
wdenk0d498392003-07-01 21:06:45 +00001303U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001304 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001305 "simple RAM read/write test",
1306 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001307);
Wolfgang Denka2681702013-03-08 10:51:32 +00001308#endif /* CONFIG_CMD_MEMTEST */
wdenk8bde7f72003-06-27 21:31:46 +00001309
Joel Johnson72732312020-01-29 09:17:18 -07001310#ifdef CONFIG_CMD_MX_CYCLIC
stroese4aaf29b2004-12-16 17:42:39 +00001311U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001312 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001313 "memory display cyclic",
Simon Glass4d979bf2019-12-28 10:45:10 -07001314#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001315 "[.b, .w, .l, .q] address count delay(ms)"
1316#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001317 "[.b, .w, .l] address count delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001318#endif
stroese4aaf29b2004-12-16 17:42:39 +00001319);
1320
1321U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001322 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001323 "memory write cyclic",
Simon Glass4d979bf2019-12-28 10:45:10 -07001324#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001325 "[.b, .w, .l, .q] address value delay(ms)"
1326#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001327 "[.b, .w, .l] address value delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001328#endif
stroese4aaf29b2004-12-16 17:42:39 +00001329);
Joel Johnson72732312020-01-29 09:17:18 -07001330#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glass15a33e42012-11-30 13:01:20 +00001331
1332#ifdef CONFIG_CMD_MEMINFO
1333U_BOOT_CMD(
1334 meminfo, 3, 1, do_mem_info,
1335 "display memory information",
1336 ""
1337);
1338#endif
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001339
1340#ifdef CONFIG_CMD_RANDOM
1341U_BOOT_CMD(
1342 random, 4, 0, do_random,
1343 "fill memory with random pattern",
1344 "<addr> <len> [<seed>]\n"
1345 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1346);
1347#endif