blob: ab67a01446057d5416700c3edeaaabe6ea2e27ed [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk38635852002-08-27 05:55:31 +00005 */
6
7/*
8 * Memory Functions
9 *
10 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
11 */
12
13#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -070014#include <console.h>
Simon Glass399ed9a2014-04-10 20:01:30 -060015#include <bootretry.h>
Simon Glassdec3c012014-04-10 20:01:25 -060016#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000017#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070018#include <console.h>
Simon Glassa606ffc2019-12-28 10:44:40 -070019#include <flash.h>
Simon Glass0bbd76f2013-02-24 20:30:22 +000020#include <hash.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050021#include <mapmem.h>
Simon Glass274e0b02020-05-10 11:39:56 -060022#include <rand.h>
Sergei Poselenov474dbb82008-04-09 16:09:41 +020023#include <watchdog.h>
Simon Glasse6d0ca22013-02-24 17:33:15 +000024#include <asm/io.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000025#include <linux/compiler.h>
26
27DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000028
Simon Glassed38aef2020-05-10 11:40:03 -060029#ifndef CONFIG_SYS_MEMTEST_SCRATCH
30#define CONFIG_SYS_MEMTEST_SCRATCH 0
31#endif
32
33static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000034
35/* Display values from last command.
36 * Memory modify remembered values are different from display memory.
37 */
Scott Wood3ec02882015-03-19 09:43:12 -070038static ulong dp_last_addr, dp_last_size;
39static ulong dp_last_length = 0x40;
40static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000041
42static ulong base_address = 0;
43
44/* Memory Display
45 *
46 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080047 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000048 */
49#define DISP_LINE_LEN 16
Simon Glassed38aef2020-05-10 11:40:03 -060050static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
51 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000052{
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030053 ulong addr, length, bytes;
54 const void *buf;
wdenk874ac262003-07-24 23:38:38 +000055 int size;
wdenk38635852002-08-27 05:55:31 +000056 int rc = 0;
57
58 /* We use the last specified parameters, unless new ones are
59 * entered.
60 */
61 addr = dp_last_addr;
62 size = dp_last_size;
63 length = dp_last_length;
64
Wolfgang Denk3b683112010-07-17 01:06:04 +020065 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000066 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000067
68 if ((flag & CMD_FLAG_REPEAT) == 0) {
69 /* New command specified. Check for a size specification.
70 * Defaults to long if no or incorrect specification.
71 */
wdenk874ac262003-07-24 23:38:38 +000072 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
73 return 1;
wdenk38635852002-08-27 05:55:31 +000074
75 /* Address is specified since argc > 1
76 */
77 addr = simple_strtoul(argv[1], NULL, 16);
78 addr += base_address;
79
80 /* If another parameter, it is the length to display.
81 * Length is the number of objects, not number of bytes.
82 */
83 if (argc > 2)
84 length = simple_strtoul(argv[2], NULL, 16);
85 }
86
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030087 bytes = size * length;
88 buf = map_sysmem(addr, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +000089
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030090 /* Print the lines. */
91 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
92 addr += bytes;
93 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +000094
95 dp_last_addr = addr;
96 dp_last_length = length;
97 dp_last_size = size;
98 return (rc);
99}
100
Simon Glassed38aef2020-05-10 11:40:03 -0600101static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
102 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000103{
104 return mod_mem (cmdtp, 1, flag, argc, argv);
105}
Simon Glassed38aef2020-05-10 11:40:03 -0600106
107static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
108 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000109{
110 return mod_mem (cmdtp, 0, flag, argc, argv);
111}
112
Simon Glassed38aef2020-05-10 11:40:03 -0600113static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
114 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000115{
Simon Glass8927bf22019-12-28 10:45:10 -0700116#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800117 u64 writeval;
118#else
119 ulong writeval;
120#endif
121 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000122 int size;
Simon Glass3c4a2872015-03-05 12:25:18 -0700123 void *buf, *start;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000124 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000125
Wolfgang Denk3b683112010-07-17 01:06:04 +0200126 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000127 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000128
129 /* Check for size specification.
130 */
wdenk874ac262003-07-24 23:38:38 +0000131 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
132 return 1;
wdenk38635852002-08-27 05:55:31 +0000133
134 /* Address is specified since argc > 1
135 */
136 addr = simple_strtoul(argv[1], NULL, 16);
137 addr += base_address;
138
139 /* Get the value to write.
140 */
Simon Glass8927bf22019-12-28 10:45:10 -0700141#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800142 writeval = simple_strtoull(argv[2], NULL, 16);
143#else
wdenk38635852002-08-27 05:55:31 +0000144 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800145#endif
wdenk38635852002-08-27 05:55:31 +0000146
147 /* Count ? */
148 if (argc == 4) {
149 count = simple_strtoul(argv[3], NULL, 16);
150 } else {
151 count = 1;
152 }
153
Simon Glasse6d0ca22013-02-24 17:33:15 +0000154 bytes = size * count;
Simon Glass3c4a2872015-03-05 12:25:18 -0700155 start = map_sysmem(addr, bytes);
156 buf = start;
wdenk38635852002-08-27 05:55:31 +0000157 while (count-- > 0) {
158 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800159 *((u32 *)buf) = (u32)writeval;
Simon Glass8927bf22019-12-28 10:45:10 -0700160#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800161 else if (size == 8)
162 *((u64 *)buf) = (u64)writeval;
163#endif
wdenk38635852002-08-27 05:55:31 +0000164 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800165 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000166 else
York Sund8a405d2014-02-12 15:55:35 -0800167 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000168 buf += size;
wdenk38635852002-08-27 05:55:31 +0000169 }
Simon Glass3c4a2872015-03-05 12:25:18 -0700170 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000171 return 0;
172}
173
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700174#ifdef CONFIG_CMD_MX_CYCLIC
Simon Glassed38aef2020-05-10 11:40:03 -0600175static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
176 char *const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000177{
178 int i;
179 ulong count;
180
Wolfgang Denk3b683112010-07-17 01:06:04 +0200181 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000182 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000183
184 count = simple_strtoul(argv[3], NULL, 10);
185
186 for (;;) {
187 do_mem_md (NULL, 0, 3, argv);
188
189 /* delay for <count> ms... */
190 for (i=0; i<count; i++)
191 udelay (1000);
192
193 /* check for ctrl-c to abort... */
194 if (ctrlc()) {
195 puts("Abort\n");
196 return 0;
197 }
198 }
199
200 return 0;
201}
202
Simon Glassed38aef2020-05-10 11:40:03 -0600203static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
204 char *const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000205{
206 int i;
207 ulong count;
208
Wolfgang Denk3b683112010-07-17 01:06:04 +0200209 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000210 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000211
212 count = simple_strtoul(argv[3], NULL, 10);
213
214 for (;;) {
215 do_mem_mw (NULL, 0, 3, argv);
216
217 /* delay for <count> ms... */
218 for (i=0; i<count; i++)
219 udelay (1000);
220
221 /* check for ctrl-c to abort... */
222 if (ctrlc()) {
223 puts("Abort\n");
224 return 0;
225 }
226 }
227
228 return 0;
229}
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700230#endif /* CONFIG_CMD_MX_CYCLIC */
stroesefb5e0ac2004-12-16 17:42:39 +0000231
Simon Glassed38aef2020-05-10 11:40:03 -0600232static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
233 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000234{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000235 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000236 int size;
wdenk38635852002-08-27 05:55:31 +0000237 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000238 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000239 const void *buf1, *buf2, *base;
Simon Glass8927bf22019-12-28 10:45:10 -0700240#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800241 u64 word1, word2;
242#else
243 ulong word1, word2;
244#endif
wdenk38635852002-08-27 05:55:31 +0000245
Wolfgang Denk3b683112010-07-17 01:06:04 +0200246 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000247 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000248
249 /* Check for size specification.
250 */
wdenk874ac262003-07-24 23:38:38 +0000251 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
252 return 1;
York Sun6c480012014-02-26 17:03:19 -0800253 type = size == 8 ? "double word" :
254 size == 4 ? "word" :
255 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000256
257 addr1 = simple_strtoul(argv[1], NULL, 16);
258 addr1 += base_address;
259
260 addr2 = simple_strtoul(argv[2], NULL, 16);
261 addr2 += base_address;
262
263 count = simple_strtoul(argv[3], NULL, 16);
264
Simon Glasse6d0ca22013-02-24 17:33:15 +0000265 bytes = size * count;
266 base = buf1 = map_sysmem(addr1, bytes);
267 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000268 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000269 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800270 word1 = *(u32 *)buf1;
271 word2 = *(u32 *)buf2;
Simon Glass8927bf22019-12-28 10:45:10 -0700272#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800273 } else if (size == 8) {
274 word1 = *(u64 *)buf1;
275 word2 = *(u64 *)buf2;
276#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000277 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800278 word1 = *(u16 *)buf1;
279 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000280 } else {
York Sund8a405d2014-02-12 15:55:35 -0800281 word1 = *(u8 *)buf1;
282 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000283 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000284 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000285 ulong offset = buf1 - base;
Simon Glass8927bf22019-12-28 10:45:10 -0700286#ifdef MEM_SUPPORT_64BIT_DATA
Masahiro Yamadac7570a32018-08-06 20:47:40 +0900287 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
York Sun6c480012014-02-26 17:03:19 -0800288 type, (void *)(addr1 + offset), size, word1,
289 type, (void *)(addr2 + offset), size, word2);
290#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000291 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000292 type, (ulong)(addr1 + offset), size, word1,
293 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800294#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000295 rcode = 1;
296 break;
wdenk38635852002-08-27 05:55:31 +0000297 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000298
Simon Glasse6d0ca22013-02-24 17:33:15 +0000299 buf1 += size;
300 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200301
302 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000303 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200304 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000305 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000306 unmap_sysmem(buf1);
307 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000308
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000309 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000310 return rcode;
311}
312
Simon Glassed38aef2020-05-10 11:40:03 -0600313static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
314 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000315{
Fabio Estevamb03b0c82016-12-15 16:00:13 -0200316 ulong addr, dest, count;
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100317 void *src, *dst;
wdenk874ac262003-07-24 23:38:38 +0000318 int size;
wdenk38635852002-08-27 05:55:31 +0000319
Wolfgang Denk3b683112010-07-17 01:06:04 +0200320 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000321 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000322
323 /* Check for size specification.
324 */
wdenk874ac262003-07-24 23:38:38 +0000325 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
326 return 1;
wdenk38635852002-08-27 05:55:31 +0000327
328 addr = simple_strtoul(argv[1], NULL, 16);
329 addr += base_address;
330
331 dest = simple_strtoul(argv[2], NULL, 16);
332 dest += base_address;
333
334 count = simple_strtoul(argv[3], NULL, 16);
335
336 if (count == 0) {
337 puts ("Zero length ???\n");
338 return 1;
339 }
340
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100341 src = map_sysmem(addr, count * size);
342 dst = map_sysmem(dest, count * size);
343
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900344#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000345 /* check if we are copying to Flash */
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100346 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000347 int rc;
348
wdenk42c05472004-03-23 22:14:11 +0000349 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000350
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100351 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000352 if (rc != 0) {
Simon Glassa606ffc2019-12-28 10:44:40 -0700353 flash_perror(rc);
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100354 unmap_sysmem(src);
355 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000356 return (1);
357 }
358 puts ("done\n");
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100359 unmap_sysmem(src);
360 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000361 return 0;
362 }
wdenk7a428cc2003-06-15 22:40:42 +0000363#endif
364
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100365 memcpy(dst, src, count * size);
Masahiro Yamada787b0c52014-10-23 17:46:24 +0900366
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100367 unmap_sysmem(src);
368 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000369 return 0;
370}
371
Simon Glassed38aef2020-05-10 11:40:03 -0600372static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
373 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000374{
375 if (argc > 1) {
376 /* Set new base address.
377 */
378 base_address = simple_strtoul(argv[1], NULL, 16);
379 }
380 /* Print the current base address.
381 */
382 printf("Base Address: 0x%08lx\n", base_address);
383 return 0;
384}
385
Simon Glassed38aef2020-05-10 11:40:03 -0600386static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
387 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000388{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000389 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000390 int size;
Simon Glass8927bf22019-12-28 10:45:10 -0700391#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800392 volatile u64 *llp;
393#endif
York Sund8a405d2014-02-12 15:55:35 -0800394 volatile u32 *longp;
395 volatile u16 *shortp;
396 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000397 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000398
Wolfgang Denk3b683112010-07-17 01:06:04 +0200399 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000400 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000401
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000402 /*
403 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000404 * Defaults to long if no or incorrect specification.
405 */
wdenk874ac262003-07-24 23:38:38 +0000406 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
407 return 1;
wdenk38635852002-08-27 05:55:31 +0000408
409 /* Address is always specified.
410 */
411 addr = simple_strtoul(argv[1], NULL, 16);
412
413 /* Length is the number of objects, not number of bytes.
414 */
415 length = simple_strtoul(argv[2], NULL, 16);
416
Simon Glasse6d0ca22013-02-24 17:33:15 +0000417 bytes = size * length;
418 buf = map_sysmem(addr, bytes);
419
wdenk38635852002-08-27 05:55:31 +0000420 /* We want to optimize the loops to run as fast as possible.
421 * If we have only one object, just run infinite loops.
422 */
423 if (length == 1) {
Simon Glass8927bf22019-12-28 10:45:10 -0700424#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800425 if (size == 8) {
426 llp = (u64 *)buf;
427 for (;;)
428 i = *llp;
429 }
430#endif
wdenk38635852002-08-27 05:55:31 +0000431 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800432 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000433 for (;;)
434 i = *longp;
435 }
436 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800437 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000438 for (;;)
439 i = *shortp;
440 }
York Sund8a405d2014-02-12 15:55:35 -0800441 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000442 for (;;)
443 i = *cp;
444 }
445
Simon Glass8927bf22019-12-28 10:45:10 -0700446#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800447 if (size == 8) {
448 for (;;) {
449 llp = (u64 *)buf;
450 i = length;
451 while (i-- > 0)
452 *llp++;
453 }
454 }
455#endif
wdenk38635852002-08-27 05:55:31 +0000456 if (size == 4) {
457 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800458 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000459 i = length;
460 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200461 *longp++;
wdenk38635852002-08-27 05:55:31 +0000462 }
463 }
464 if (size == 2) {
465 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800466 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000467 i = length;
468 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200469 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000470 }
471 }
472 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800473 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000474 i = length;
475 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200476 *cp++;
wdenk38635852002-08-27 05:55:31 +0000477 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000478 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700479
480 return 0;
wdenk38635852002-08-27 05:55:31 +0000481}
482
wdenk64519362004-07-11 17:40:54 +0000483#ifdef CONFIG_LOOPW
Simon Glassed38aef2020-05-10 11:40:03 -0600484static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
485 char *const argv[])
wdenk64519362004-07-11 17:40:54 +0000486{
York Sun6c480012014-02-26 17:03:19 -0800487 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000488 int size;
Simon Glass8927bf22019-12-28 10:45:10 -0700489#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800490 volatile u64 *llp;
491 u64 data;
492#else
493 ulong data;
494#endif
York Sund8a405d2014-02-12 15:55:35 -0800495 volatile u32 *longp;
496 volatile u16 *shortp;
497 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000498 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000499
Wolfgang Denk3b683112010-07-17 01:06:04 +0200500 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000501 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000502
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000503 /*
504 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000505 * Defaults to long if no or incorrect specification.
506 */
507 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
508 return 1;
509
510 /* Address is always specified.
511 */
512 addr = simple_strtoul(argv[1], NULL, 16);
513
514 /* Length is the number of objects, not number of bytes.
515 */
516 length = simple_strtoul(argv[2], NULL, 16);
517
518 /* data to write */
Simon Glass8927bf22019-12-28 10:45:10 -0700519#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800520 data = simple_strtoull(argv[3], NULL, 16);
521#else
wdenk64519362004-07-11 17:40:54 +0000522 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800523#endif
wdenk7dd13292004-07-11 20:04:51 +0000524
Simon Glasse6d0ca22013-02-24 17:33:15 +0000525 bytes = size * length;
526 buf = map_sysmem(addr, bytes);
527
wdenk64519362004-07-11 17:40:54 +0000528 /* We want to optimize the loops to run as fast as possible.
529 * If we have only one object, just run infinite loops.
530 */
531 if (length == 1) {
Simon Glass8927bf22019-12-28 10:45:10 -0700532#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800533 if (size == 8) {
534 llp = (u64 *)buf;
535 for (;;)
536 *llp = data;
537 }
538#endif
wdenk64519362004-07-11 17:40:54 +0000539 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800540 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000541 for (;;)
542 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800543 }
wdenk64519362004-07-11 17:40:54 +0000544 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800545 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000546 for (;;)
547 *shortp = data;
548 }
York Sund8a405d2014-02-12 15:55:35 -0800549 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000550 for (;;)
551 *cp = data;
552 }
553
Simon Glass8927bf22019-12-28 10:45:10 -0700554#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800555 if (size == 8) {
556 for (;;) {
557 llp = (u64 *)buf;
558 i = length;
559 while (i-- > 0)
560 *llp++ = data;
561 }
562 }
563#endif
wdenk64519362004-07-11 17:40:54 +0000564 if (size == 4) {
565 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800566 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000567 i = length;
568 while (i-- > 0)
569 *longp++ = data;
570 }
571 }
572 if (size == 2) {
573 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800574 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000575 i = length;
576 while (i-- > 0)
577 *shortp++ = data;
578 }
579 }
580 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800581 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000582 i = length;
583 while (i-- > 0)
584 *cp++ = data;
585 }
586}
587#endif /* CONFIG_LOOPW */
588
Tom Rinia5f02702013-03-12 10:07:19 -0400589#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000590static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
591 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000592{
Simon Glass8f2c7582013-02-24 17:33:16 +0000593 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000594 ulong errs = 0;
595 ulong val, readback;
596 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000597 vu_long offset;
598 vu_long test_offset;
599 vu_long pattern;
600 vu_long temp;
601 vu_long anti_pattern;
602 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000603 static const ulong bitpattern[] = {
604 0x00000001, /* single bit */
605 0x00000003, /* two adjacent bits */
606 0x00000007, /* three adjacent bits */
607 0x0000000F, /* four adjacent bits */
608 0x00000005, /* two non-adjacent bits */
609 0x00000015, /* three non-adjacent bits */
610 0x00000055, /* four non-adjacent bits */
611 0xaaaaaaaa, /* alternating 1/0 */
612 };
wdenk38635852002-08-27 05:55:31 +0000613
Simon Glassad02a012013-02-28 17:47:14 +0000614 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000615
Simon Glass130103e2013-02-24 17:33:18 +0000616 /*
617 * Data line test: write a pattern to the first
618 * location, write the 1's complement to a 'parking'
619 * address (changes the state of the data bus so a
620 * floating bus doesn't give a false OK), and then
621 * read the value back. Note that we read it back
622 * into a variable because the next time we read it,
623 * it might be right (been there, tough to explain to
624 * the quality guys why it prints a failure when the
625 * "is" and "should be" are obviously the same in the
626 * error message).
627 *
628 * Rather than exhaustively testing, we test some
629 * patterns by shifting '1' bits through a field of
630 * '0's and '0' bits through a field of '1's (i.e.
631 * pattern and ~pattern).
632 */
Simon Glassad02a012013-02-28 17:47:14 +0000633 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000634 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
635 val = bitpattern[j];
636 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000637 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000638 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000639 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000640 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000641 printf("FAILURE (data line): "
642 "expected %08lx, actual %08lx\n",
643 val, readback);
644 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000645 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000646 return -1;
wdenk38635852002-08-27 05:55:31 +0000647 }
648 *addr = ~val;
649 *dummy = val;
650 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000651 if (readback != ~val) {
652 printf("FAILURE (data line): "
653 "Is %08lx, should be %08lx\n",
654 readback, ~val);
655 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000656 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000657 return -1;
wdenk38635852002-08-27 05:55:31 +0000658 }
wdenk38635852002-08-27 05:55:31 +0000659 }
Simon Glass130103e2013-02-24 17:33:18 +0000660 }
wdenk38635852002-08-27 05:55:31 +0000661
Simon Glass130103e2013-02-24 17:33:18 +0000662 /*
663 * Based on code whose Original Author and Copyright
664 * information follows: Copyright (c) 1998 by Michael
665 * Barr. This software is placed into the public
666 * domain and may be used for any purpose. However,
667 * this notice must not be changed or removed and no
668 * warranty is either expressed or implied by its
669 * publication or distribution.
670 */
wdenk38635852002-08-27 05:55:31 +0000671
Simon Glass130103e2013-02-24 17:33:18 +0000672 /*
673 * Address line test
wdenk38635852002-08-27 05:55:31 +0000674
Simon Glass130103e2013-02-24 17:33:18 +0000675 * Description: Test the address bus wiring in a
676 * memory region by performing a walking
677 * 1's test on the relevant bits of the
678 * address and checking for aliasing.
679 * This test will find single-bit
680 * address failures such as stuck-high,
681 * stuck-low, and shorted pins. The base
682 * address and size of the region are
683 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000684
Simon Glass130103e2013-02-24 17:33:18 +0000685 * Notes: For best results, the selected base
686 * address should have enough LSB 0's to
687 * guarantee single address bit changes.
688 * For example, to test a 64-Kbyte
689 * region, select a base address on a
690 * 64-Kbyte boundary. Also, select the
691 * region size as a power-of-two if at
692 * all possible.
693 *
694 * Returns: 0 if the test succeeds, 1 if the test fails.
695 */
Simon Glass130103e2013-02-24 17:33:18 +0000696 pattern = (vu_long) 0xaaaaaaaa;
697 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000698
Simon Glassad02a012013-02-28 17:47:14 +0000699 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000700 /*
701 * Write the default pattern at each of the
702 * power-of-two offsets.
703 */
Simon Glassad02a012013-02-28 17:47:14 +0000704 for (offset = 1; offset < num_words; offset <<= 1)
705 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000706
707 /*
708 * Check for address bits stuck high.
709 */
710 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000711 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000712
Simon Glassad02a012013-02-28 17:47:14 +0000713 for (offset = 1; offset < num_words; offset <<= 1) {
714 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000715 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000716 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000717 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800718 start_addr + offset*sizeof(vu_long),
719 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400720 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000721 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000722 return -1;
wdenk38635852002-08-27 05:55:31 +0000723 }
Simon Glass130103e2013-02-24 17:33:18 +0000724 }
Simon Glassad02a012013-02-28 17:47:14 +0000725 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000726 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000727
Simon Glass130103e2013-02-24 17:33:18 +0000728 /*
729 * Check for addr bits stuck low or shorted.
730 */
Simon Glassad02a012013-02-28 17:47:14 +0000731 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
732 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000733
Simon Glassad02a012013-02-28 17:47:14 +0000734 for (offset = 1; offset < num_words; offset <<= 1) {
735 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000736 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000737 printf("\nFAILURE: Address bit stuck low or"
738 " shorted @ 0x%.8lx: expected 0x%.8lx,"
739 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800740 start_addr + offset*sizeof(vu_long),
741 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000742 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000743 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000744 return -1;
wdenk38635852002-08-27 05:55:31 +0000745 }
wdenk38635852002-08-27 05:55:31 +0000746 }
Simon Glassad02a012013-02-28 17:47:14 +0000747 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000748 }
wdenk38635852002-08-27 05:55:31 +0000749
Simon Glass130103e2013-02-24 17:33:18 +0000750 /*
751 * Description: Test the integrity of a physical
752 * memory device by performing an
753 * increment/decrement test over the
754 * entire region. In the process every
755 * storage bit in the device is tested
756 * as a zero and a one. The base address
757 * and the size of the region are
758 * selected by the caller.
759 *
760 * Returns: 0 if the test succeeds, 1 if the test fails.
761 */
Simon Glassad02a012013-02-28 17:47:14 +0000762 num_words++;
wdenk38635852002-08-27 05:55:31 +0000763
Simon Glass130103e2013-02-24 17:33:18 +0000764 /*
765 * Fill memory with a known pattern.
766 */
767 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
768 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000769 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000770 }
wdenk38635852002-08-27 05:55:31 +0000771
Simon Glass130103e2013-02-24 17:33:18 +0000772 /*
773 * Check each location and invert it for the second pass.
774 */
775 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
776 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000777 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000778 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000779 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000780 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800781 start_addr + offset*sizeof(vu_long),
782 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400783 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000784 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000785 return -1;
wdenk38635852002-08-27 05:55:31 +0000786 }
787
Simon Glass130103e2013-02-24 17:33:18 +0000788 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000789 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000790 }
791
792 /*
793 * Check each location for the inverted pattern and zero it.
794 */
795 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
796 WATCHDOG_RESET();
797 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000798 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000799 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000800 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000801 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800802 start_addr + offset*sizeof(vu_long),
803 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400804 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000805 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000806 return -1;
wdenk38635852002-08-27 05:55:31 +0000807 }
Simon Glassad02a012013-02-28 17:47:14 +0000808 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000809 }
Simon Glass57ee4432013-02-24 17:33:17 +0000810
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100811 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000812}
813
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100814static int compare_regions(volatile unsigned long *bufa,
815 volatile unsigned long *bufb, size_t count)
816{
817 volatile unsigned long *p1 = bufa;
818 volatile unsigned long *p2 = bufb;
819 int errs = 0;
820 size_t i;
821
822 for (i = 0; i < count; i++, p1++, p2++) {
823 if (*p1 != *p2) {
824 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
825 (unsigned long)*p1, (unsigned long)*p2,
826 *p1 ^ *p2, __ffs(*p1 ^ *p2),
827 (unsigned long)(i * sizeof(unsigned long)));
828 errs++;
829 }
830 }
831
832 return errs;
833}
834
835static ulong test_bitflip_comparison(volatile unsigned long *bufa,
836 volatile unsigned long *bufb, size_t count)
837{
838 volatile unsigned long *p1 = bufa;
839 volatile unsigned long *p2 = bufb;
840 unsigned int j, k;
841 unsigned long q;
842 size_t i;
843 int max;
844 int errs = 0;
845
846 max = sizeof(unsigned long) * 8;
847 for (k = 0; k < max; k++) {
848 q = 0x00000001L << k;
849 for (j = 0; j < 8; j++) {
850 WATCHDOG_RESET();
851 q = ~q;
852 p1 = (volatile unsigned long *)bufa;
853 p2 = (volatile unsigned long *)bufb;
854 for (i = 0; i < count; i++)
855 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
856
857 errs += compare_regions(bufa, bufb, count);
858 }
859
860 if (ctrlc())
861 return -1UL;
862 }
863
864 return errs;
865}
866
Simon Glassad02a012013-02-28 17:47:14 +0000867static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
868 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000869{
Simon Glassad02a012013-02-28 17:47:14 +0000870 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000871 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000872 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000873 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000874 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000875
Simon Glass57ee4432013-02-24 17:33:17 +0000876 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000877 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000878 if (iteration & 1) {
879 incr = -incr;
880 /*
881 * Flip the pattern each time to make lots of zeros and
882 * then, the next time, lots of ones. We decrement
883 * the "negative" patterns and increment the "positive"
884 * patterns to preserve this feature.
885 */
886 if (pattern & 0x80000000)
887 pattern = -pattern; /* complement & increment */
888 else
889 pattern = ~pattern;
890 }
Simon Glassad02a012013-02-28 17:47:14 +0000891 length = (end_addr - start_addr) / sizeof(ulong);
892 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000893 printf("\rPattern %08lX Writing..."
894 "%12s"
895 "\b\b\b\b\b\b\b\b\b\b",
896 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000897
Simon Glassad02a012013-02-28 17:47:14 +0000898 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000899 WATCHDOG_RESET();
900 *addr = val;
901 val += incr;
902 }
wdenk38635852002-08-27 05:55:31 +0000903
Simon Glass130103e2013-02-24 17:33:18 +0000904 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000905
Simon Glassad02a012013-02-28 17:47:14 +0000906 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000907 WATCHDOG_RESET();
908 readback = *addr;
909 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000910 ulong offset = addr - buf;
911
Simon Glass130103e2013-02-24 17:33:18 +0000912 printf("\nMem error @ 0x%08X: "
913 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800914 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000915 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000916 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000917 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000918 return -1;
wdenk38635852002-08-27 05:55:31 +0000919 }
Simon Glass130103e2013-02-24 17:33:18 +0000920 val += incr;
921 }
wdenk38635852002-08-27 05:55:31 +0000922
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100923 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000924}
925
926/*
927 * Perform a memory test. A more complete alternative test can be
928 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
929 * interrupted by ctrl-c or by a failure of one of the sub-tests.
930 */
Simon Glassed38aef2020-05-10 11:40:03 -0600931static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
932 char *const argv[])
Simon Glass8f2c7582013-02-24 17:33:16 +0000933{
Simon Glass51075252013-02-24 17:33:20 +0000934 ulong start, end;
Michal Simek9eaf6442020-05-04 13:54:40 +0200935 vu_long scratch_space;
936 vu_long *buf, *dummy = &scratch_space;
Tom Rinib9180882015-04-07 09:38:54 -0400937 ulong iteration_limit = 0;
Stefan Roese32265fc2020-03-05 07:21:29 +0100938 ulong count = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000939 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Machekd319f592015-04-01 13:50:41 +0200940 ulong pattern = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000941 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +0000942
Pavel Machekd319f592015-04-01 13:50:41 +0200943 start = CONFIG_SYS_MEMTEST_START;
944 end = CONFIG_SYS_MEMTEST_END;
945
Simon Glass8f2c7582013-02-24 17:33:16 +0000946 if (argc > 1)
Pavel Machekd319f592015-04-01 13:50:41 +0200947 if (strict_strtoul(argv[1], 16, &start) < 0)
948 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000949
950 if (argc > 2)
Pavel Machekd319f592015-04-01 13:50:41 +0200951 if (strict_strtoul(argv[2], 16, &end) < 0)
952 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000953
954 if (argc > 3)
Pavel Machekd319f592015-04-01 13:50:41 +0200955 if (strict_strtoul(argv[3], 16, &pattern) < 0)
956 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000957
958 if (argc > 4)
Pavel Machekd319f592015-04-01 13:50:41 +0200959 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
960 return CMD_RET_USAGE;
961
962 if (end < start) {
963 printf("Refusing to do empty test\n");
964 return -1;
965 }
Simon Glass8f2c7582013-02-24 17:33:16 +0000966
Michal Simek45f8e332016-02-24 08:36:02 +0100967 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass51075252013-02-24 17:33:20 +0000968 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
969 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +0000970
Simon Glassad02a012013-02-28 17:47:14 +0000971 buf = map_sysmem(start, end - start);
Simon Glass57ee4432013-02-24 17:33:17 +0000972 for (iteration = 0;
973 !iteration_limit || iteration < iteration_limit;
974 iteration++) {
975 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +0000976 errs = -1UL;
977 break;
978 }
979
980 printf("Iteration: %6d\r", iteration + 1);
981 debug("\n");
Stefan Roese1eb8b1e2020-03-05 07:21:31 +0100982 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
Simon Glassad02a012013-02-28 17:47:14 +0000983 errs = mem_test_alt(buf, start, end, dummy);
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100984 if (errs == -1UL)
985 break;
986 count += errs;
987 errs = test_bitflip_comparison(buf,
988 buf + (end - start) / 2,
989 (end - start) /
990 sizeof(unsigned long));
Simon Glassad02a012013-02-28 17:47:14 +0000991 } else {
992 errs = mem_test_quick(buf, start, end, pattern,
993 iteration);
994 }
995 if (errs == -1UL)
996 break;
Stefan Roese32265fc2020-03-05 07:21:29 +0100997 count += errs;
Simon Glassad02a012013-02-28 17:47:14 +0000998 }
999
Stefan Roesec1d47db2020-03-05 07:21:30 +01001000 unmap_sysmem((void *)buf);
Simon Glass57ee4432013-02-24 17:33:17 +00001001
1002 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001003 /* Memory test was aborted - write a newline to finish off */
1004 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001005 }
Stefan Roese32265fc2020-03-05 07:21:29 +01001006 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
Simon Glass8f2c7582013-02-24 17:33:16 +00001007
Stefan Roese32265fc2020-03-05 07:21:29 +01001008 return errs != 0;
wdenk38635852002-08-27 05:55:31 +00001009}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001010#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001011
1012/* Modify memory.
1013 *
1014 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001015 * mm{.b, .w, .l, .q} {addr}
1016 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001017 */
1018static int
Simon Glassed38aef2020-05-10 11:40:03 -06001019mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1020 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001021{
York Sun6c480012014-02-26 17:03:19 -08001022 ulong addr;
Simon Glass8927bf22019-12-28 10:45:10 -07001023#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001024 u64 i;
1025#else
1026 ulong i;
1027#endif
wdenk874ac262003-07-24 23:38:38 +00001028 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001029 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001030
Wolfgang Denk3b683112010-07-17 01:06:04 +02001031 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001032 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001033
Simon Glass09007c42014-04-10 20:01:31 -06001034 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001035 /* We use the last specified parameters, unless new ones are
1036 * entered.
1037 */
1038 addr = mm_last_addr;
1039 size = mm_last_size;
1040
1041 if ((flag & CMD_FLAG_REPEAT) == 0) {
1042 /* New command specified. Check for a size specification.
1043 * Defaults to long if no or incorrect specification.
1044 */
wdenk874ac262003-07-24 23:38:38 +00001045 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1046 return 1;
wdenk38635852002-08-27 05:55:31 +00001047
1048 /* Address is specified since argc > 1
1049 */
1050 addr = simple_strtoul(argv[1], NULL, 16);
1051 addr += base_address;
1052 }
wdenk381669a2003-06-16 23:50:08 +00001053
wdenk38635852002-08-27 05:55:31 +00001054 /* Print the address, followed by value. Then accept input for
1055 * the next value. A non-converted value exits.
1056 */
1057 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001058 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001059 printf("%08lx:", addr);
1060 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001061 printf(" %08x", *((u32 *)ptr));
Simon Glass8927bf22019-12-28 10:45:10 -07001062#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001063 else if (size == 8)
Masahiro Yamadac7570a32018-08-06 20:47:40 +09001064 printf(" %016llx", *((u64 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001065#endif
wdenk38635852002-08-27 05:55:31 +00001066 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001067 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001068 else
York Sund8a405d2014-02-12 15:55:35 -08001069 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001070
Simon Glassbe6aafc2014-04-10 20:01:27 -06001071 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001072 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1073 /* <CR> pressed as only input, don't modify current
1074 * location and move to next. "-" pressed will go back.
1075 */
1076 if (incrflag)
1077 addr += nbytes ? -size : size;
1078 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001079 /* good enough to not time out */
1080 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001081 }
1082#ifdef CONFIG_BOOT_RETRY_TIME
1083 else if (nbytes == -2) {
1084 break; /* timed out, exit the command */
1085 }
1086#endif
1087 else {
1088 char *endp;
Simon Glass8927bf22019-12-28 10:45:10 -07001089#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001090 i = simple_strtoull(console_buffer, &endp, 16);
1091#else
wdenk38635852002-08-27 05:55:31 +00001092 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001093#endif
wdenk38635852002-08-27 05:55:31 +00001094 nbytes = endp - console_buffer;
1095 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001096 /* good enough to not time out
1097 */
Simon Glass09007c42014-04-10 20:01:31 -06001098 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001099 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001100 *((u32 *)ptr) = i;
Simon Glass8927bf22019-12-28 10:45:10 -07001101#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001102 else if (size == 8)
1103 *((u64 *)ptr) = i;
1104#endif
wdenk38635852002-08-27 05:55:31 +00001105 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001106 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001107 else
York Sund8a405d2014-02-12 15:55:35 -08001108 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001109 if (incrflag)
1110 addr += size;
1111 }
1112 }
1113 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001114 if (ptr)
1115 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001116
1117 mm_last_addr = addr;
1118 mm_last_size = size;
1119 return 0;
1120}
1121
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001122#ifdef CONFIG_CMD_CRC32
1123
Simon Glassed38aef2020-05-10 11:40:03 -06001124static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1125 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001126{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001127 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001128 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001129 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001130
Simon Glass0bbd76f2013-02-24 20:30:22 +00001131 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001132 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001133
1134 av = argv + 1;
1135 ac = argc - 1;
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001136#ifdef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001137 if (strcmp(*av, "-v") == 0) {
Joe Hershberger5fcee9a2015-05-05 12:23:53 -05001138 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenk6203e402004-04-18 10:13:26 +00001139 av++;
1140 ac--;
wdenk6203e402004-04-18 10:13:26 +00001141 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001142#endif
wdenk6203e402004-04-18 10:13:26 +00001143
Simon Glass0bbd76f2013-02-24 20:30:22 +00001144 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001145}
wdenk6203e402004-04-18 10:13:26 +00001146
Robin Getz93d6cb02009-07-27 00:07:59 -04001147#endif
1148
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001149#ifdef CONFIG_CMD_RANDOM
Simon Glassed38aef2020-05-10 11:40:03 -06001150static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1151 char *const argv[])
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001152{
1153 unsigned long addr, len;
1154 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1155 unsigned int *buf, *start;
1156 unsigned char *buf8;
1157 unsigned int i;
1158
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001159 if (argc < 3 || argc > 4)
1160 return CMD_RET_USAGE;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001161
1162 len = simple_strtoul(argv[2], NULL, 16);
1163 addr = simple_strtoul(argv[1], NULL, 16);
1164
1165 if (argc == 4) {
1166 seed = simple_strtoul(argv[3], NULL, 16);
1167 if (seed == 0) {
1168 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1169 seed = 0xDEADBEEF;
1170 }
1171 } else {
1172 seed = get_timer(0) ^ rand();
1173 }
1174
1175 srand(seed);
1176 start = map_sysmem(addr, len);
1177 buf = start;
1178 for (i = 0; i < (len / 4); i++)
1179 *buf++ = rand();
1180
1181 buf8 = (unsigned char *)buf;
1182 for (i = 0; i < (len % 4); i++)
1183 *buf8++ = rand() & 0xFF;
1184
1185 unmap_sysmem(start);
1186 printf("%lu bytes filled with random data\n", len);
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001187
1188 return CMD_RET_SUCCESS;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001189}
1190#endif
1191
wdenk57b2d802003-06-27 21:31:46 +00001192/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001193U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001194 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001195 "memory display",
Simon Glass8927bf22019-12-28 10:45:10 -07001196#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001197 "[.b, .w, .l, .q] address [# of objects]"
1198#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001199 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001200#endif
wdenk57b2d802003-06-27 21:31:46 +00001201);
1202
1203
wdenkf287a242003-07-01 21:06:45 +00001204U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001205 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001206 "memory modify (auto-incrementing address)",
Simon Glass8927bf22019-12-28 10:45:10 -07001207#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001208 "[.b, .w, .l, .q] address"
1209#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001210 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001211#endif
wdenk57b2d802003-06-27 21:31:46 +00001212);
1213
1214
wdenkf287a242003-07-01 21:06:45 +00001215U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001216 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001217 "memory modify (constant address)",
Simon Glass8927bf22019-12-28 10:45:10 -07001218#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001219 "[.b, .w, .l, .q] address"
1220#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001221 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001222#endif
wdenk57b2d802003-06-27 21:31:46 +00001223);
1224
wdenkf287a242003-07-01 21:06:45 +00001225U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001226 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001227 "memory write (fill)",
Simon Glass8927bf22019-12-28 10:45:10 -07001228#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001229 "[.b, .w, .l, .q] address value [count]"
1230#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001231 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001232#endif
wdenk57b2d802003-06-27 21:31:46 +00001233);
1234
wdenkf287a242003-07-01 21:06:45 +00001235U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001236 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001237 "memory copy",
Simon Glass8927bf22019-12-28 10:45:10 -07001238#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001239 "[.b, .w, .l, .q] source target count"
1240#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001241 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001242#endif
wdenk57b2d802003-06-27 21:31:46 +00001243);
1244
wdenkf287a242003-07-01 21:06:45 +00001245U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001246 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001247 "memory compare",
Simon Glass8927bf22019-12-28 10:45:10 -07001248#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001249 "[.b, .w, .l, .q] addr1 addr2 count"
1250#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001251 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001252#endif
wdenk57b2d802003-06-27 21:31:46 +00001253);
1254
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001255#ifdef CONFIG_CMD_CRC32
1256
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001257#ifndef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001258
wdenkf287a242003-07-01 21:06:45 +00001259U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001260 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001261 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001262 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001263);
1264
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001265#else /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001266
1267U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001268 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001269 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001270 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001271 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001272);
1273
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001274#endif /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001275
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001276#endif
1277
Simon Glasseacd14f2012-11-30 13:01:20 +00001278#ifdef CONFIG_CMD_MEMINFO
Simon Glassed38aef2020-05-10 11:40:03 -06001279static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1280 char *const argv[])
Simon Glasseacd14f2012-11-30 13:01:20 +00001281{
Simon Glass320a5d42019-11-14 12:57:44 -07001282 puts("DRAM: ");
1283 print_size(gd->ram_size, "\n");
Simon Glasseacd14f2012-11-30 13:01:20 +00001284
1285 return 0;
1286}
1287#endif
1288
wdenkf287a242003-07-01 21:06:45 +00001289U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001290 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001291 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001292 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001293 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001294);
1295
wdenkf287a242003-07-01 21:06:45 +00001296U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001297 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001298 "infinite loop on address range",
Simon Glass8927bf22019-12-28 10:45:10 -07001299#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001300 "[.b, .w, .l, .q] address number_of_objects"
1301#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001302 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001303#endif
wdenk57b2d802003-06-27 21:31:46 +00001304);
wdenk64519362004-07-11 17:40:54 +00001305
1306#ifdef CONFIG_LOOPW
1307U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001308 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001309 "infinite write loop on address range",
Simon Glass8927bf22019-12-28 10:45:10 -07001310#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001311 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1312#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001313 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001314#endif
wdenk64519362004-07-11 17:40:54 +00001315);
1316#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001317
Wolfgang Denk9d009282013-03-08 10:51:32 +00001318#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001319U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001320 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001321 "simple RAM read/write test",
1322 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001323);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001324#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001325
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001326#ifdef CONFIG_CMD_MX_CYCLIC
stroesefb5e0ac2004-12-16 17:42:39 +00001327U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001328 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001329 "memory display cyclic",
Simon Glass8927bf22019-12-28 10:45:10 -07001330#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001331 "[.b, .w, .l, .q] address count delay(ms)"
1332#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001333 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001334#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001335);
1336
1337U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001338 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001339 "memory write cyclic",
Simon Glass8927bf22019-12-28 10:45:10 -07001340#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001341 "[.b, .w, .l, .q] address value delay(ms)"
1342#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001343 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001344#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001345);
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001346#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001347
1348#ifdef CONFIG_CMD_MEMINFO
1349U_BOOT_CMD(
1350 meminfo, 3, 1, do_mem_info,
1351 "display memory information",
1352 ""
1353);
1354#endif
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001355
1356#ifdef CONFIG_CMD_RANDOM
1357U_BOOT_CMD(
1358 random, 4, 0, do_random,
1359 "fill memory with random pattern",
1360 "<addr> <len> [<seed>]\n"
1361 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1362);
1363#endif