blob: 009b7b58f32887dea97c78fbecb6f239289cc0d4 [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>
Sergei Poselenov474dbb82008-04-09 16:09:41 +020022#include <watchdog.h>
Simon Glasse6d0ca22013-02-24 17:33:15 +000023#include <asm/io.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000024#include <linux/compiler.h>
25
26DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000027
Simon Glass1c6c7252013-02-24 17:33:29 +000028#ifndef CONFIG_SYS_MEMTEST_SCRATCH
29#define CONFIG_SYS_MEMTEST_SCRATCH 0
30#endif
31
Wolfgang Denk6262d0212010-06-28 22:00:46 +020032static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000033
34/* Display values from last command.
35 * Memory modify remembered values are different from display memory.
36 */
Scott Wood3ec02882015-03-19 09:43:12 -070037static ulong dp_last_addr, dp_last_size;
38static ulong dp_last_length = 0x40;
39static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000040
41static ulong base_address = 0;
42
43/* Memory Display
44 *
45 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080046 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000047 */
48#define DISP_LINE_LEN 16
Kim Phillipsdc00a682012-10-29 13:34:31 +000049static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000050{
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030051 ulong addr, length, bytes;
52 const void *buf;
wdenk874ac262003-07-24 23:38:38 +000053 int size;
wdenk38635852002-08-27 05:55:31 +000054 int rc = 0;
55
56 /* We use the last specified parameters, unless new ones are
57 * entered.
58 */
59 addr = dp_last_addr;
60 size = dp_last_size;
61 length = dp_last_length;
62
Wolfgang Denk3b683112010-07-17 01:06:04 +020063 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000064 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000065
66 if ((flag & CMD_FLAG_REPEAT) == 0) {
67 /* New command specified. Check for a size specification.
68 * Defaults to long if no or incorrect specification.
69 */
wdenk874ac262003-07-24 23:38:38 +000070 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
71 return 1;
wdenk38635852002-08-27 05:55:31 +000072
73 /* Address is specified since argc > 1
74 */
75 addr = simple_strtoul(argv[1], NULL, 16);
76 addr += base_address;
77
78 /* If another parameter, it is the length to display.
79 * Length is the number of objects, not number of bytes.
80 */
81 if (argc > 2)
82 length = simple_strtoul(argv[2], NULL, 16);
83 }
84
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030085 bytes = size * length;
86 buf = map_sysmem(addr, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +000087
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030088 /* Print the lines. */
89 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
90 addr += bytes;
91 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +000092
93 dp_last_addr = addr;
94 dp_last_length = length;
95 dp_last_size = size;
96 return (rc);
97}
98
Kim Phillipsdc00a682012-10-29 13:34:31 +000099static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000100{
101 return mod_mem (cmdtp, 1, flag, argc, argv);
102}
Kim Phillipsdc00a682012-10-29 13:34:31 +0000103static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000104{
105 return mod_mem (cmdtp, 0, flag, argc, argv);
106}
107
Kim Phillipsdc00a682012-10-29 13:34:31 +0000108static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000109{
Simon Glass8927bf22019-12-28 10:45:10 -0700110#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800111 u64 writeval;
112#else
113 ulong writeval;
114#endif
115 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000116 int size;
Simon Glass3c4a2872015-03-05 12:25:18 -0700117 void *buf, *start;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000118 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000119
Wolfgang Denk3b683112010-07-17 01:06:04 +0200120 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000121 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000122
123 /* Check for size specification.
124 */
wdenk874ac262003-07-24 23:38:38 +0000125 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
126 return 1;
wdenk38635852002-08-27 05:55:31 +0000127
128 /* Address is specified since argc > 1
129 */
130 addr = simple_strtoul(argv[1], NULL, 16);
131 addr += base_address;
132
133 /* Get the value to write.
134 */
Simon Glass8927bf22019-12-28 10:45:10 -0700135#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800136 writeval = simple_strtoull(argv[2], NULL, 16);
137#else
wdenk38635852002-08-27 05:55:31 +0000138 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800139#endif
wdenk38635852002-08-27 05:55:31 +0000140
141 /* Count ? */
142 if (argc == 4) {
143 count = simple_strtoul(argv[3], NULL, 16);
144 } else {
145 count = 1;
146 }
147
Simon Glasse6d0ca22013-02-24 17:33:15 +0000148 bytes = size * count;
Simon Glass3c4a2872015-03-05 12:25:18 -0700149 start = map_sysmem(addr, bytes);
150 buf = start;
wdenk38635852002-08-27 05:55:31 +0000151 while (count-- > 0) {
152 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800153 *((u32 *)buf) = (u32)writeval;
Simon Glass8927bf22019-12-28 10:45:10 -0700154#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800155 else if (size == 8)
156 *((u64 *)buf) = (u64)writeval;
157#endif
wdenk38635852002-08-27 05:55:31 +0000158 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800159 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000160 else
York Sund8a405d2014-02-12 15:55:35 -0800161 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000162 buf += size;
wdenk38635852002-08-27 05:55:31 +0000163 }
Simon Glass3c4a2872015-03-05 12:25:18 -0700164 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000165 return 0;
166}
167
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700168#ifdef CONFIG_CMD_MX_CYCLIC
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900169static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000170{
171 int i;
172 ulong count;
173
Wolfgang Denk3b683112010-07-17 01:06:04 +0200174 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000175 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000176
177 count = simple_strtoul(argv[3], NULL, 10);
178
179 for (;;) {
180 do_mem_md (NULL, 0, 3, argv);
181
182 /* delay for <count> ms... */
183 for (i=0; i<count; i++)
184 udelay (1000);
185
186 /* check for ctrl-c to abort... */
187 if (ctrlc()) {
188 puts("Abort\n");
189 return 0;
190 }
191 }
192
193 return 0;
194}
195
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900196static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000197{
198 int i;
199 ulong count;
200
Wolfgang Denk3b683112010-07-17 01:06:04 +0200201 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000202 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000203
204 count = simple_strtoul(argv[3], NULL, 10);
205
206 for (;;) {
207 do_mem_mw (NULL, 0, 3, argv);
208
209 /* delay for <count> ms... */
210 for (i=0; i<count; i++)
211 udelay (1000);
212
213 /* check for ctrl-c to abort... */
214 if (ctrlc()) {
215 puts("Abort\n");
216 return 0;
217 }
218 }
219
220 return 0;
221}
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700222#endif /* CONFIG_CMD_MX_CYCLIC */
stroesefb5e0ac2004-12-16 17:42:39 +0000223
Kim Phillipsdc00a682012-10-29 13:34:31 +0000224static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000225{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000226 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000227 int size;
wdenk38635852002-08-27 05:55:31 +0000228 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000229 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000230 const void *buf1, *buf2, *base;
Simon Glass8927bf22019-12-28 10:45:10 -0700231#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800232 u64 word1, word2;
233#else
234 ulong word1, word2;
235#endif
wdenk38635852002-08-27 05:55:31 +0000236
Wolfgang Denk3b683112010-07-17 01:06:04 +0200237 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000238 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000239
240 /* Check for size specification.
241 */
wdenk874ac262003-07-24 23:38:38 +0000242 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
243 return 1;
York Sun6c480012014-02-26 17:03:19 -0800244 type = size == 8 ? "double word" :
245 size == 4 ? "word" :
246 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000247
248 addr1 = simple_strtoul(argv[1], NULL, 16);
249 addr1 += base_address;
250
251 addr2 = simple_strtoul(argv[2], NULL, 16);
252 addr2 += base_address;
253
254 count = simple_strtoul(argv[3], NULL, 16);
255
Simon Glasse6d0ca22013-02-24 17:33:15 +0000256 bytes = size * count;
257 base = buf1 = map_sysmem(addr1, bytes);
258 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000259 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000260 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800261 word1 = *(u32 *)buf1;
262 word2 = *(u32 *)buf2;
Simon Glass8927bf22019-12-28 10:45:10 -0700263#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800264 } else if (size == 8) {
265 word1 = *(u64 *)buf1;
266 word2 = *(u64 *)buf2;
267#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000268 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800269 word1 = *(u16 *)buf1;
270 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000271 } else {
York Sund8a405d2014-02-12 15:55:35 -0800272 word1 = *(u8 *)buf1;
273 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000274 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000275 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000276 ulong offset = buf1 - base;
Simon Glass8927bf22019-12-28 10:45:10 -0700277#ifdef MEM_SUPPORT_64BIT_DATA
Masahiro Yamadac7570a32018-08-06 20:47:40 +0900278 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
York Sun6c480012014-02-26 17:03:19 -0800279 type, (void *)(addr1 + offset), size, word1,
280 type, (void *)(addr2 + offset), size, word2);
281#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000282 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000283 type, (ulong)(addr1 + offset), size, word1,
284 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800285#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000286 rcode = 1;
287 break;
wdenk38635852002-08-27 05:55:31 +0000288 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000289
Simon Glasse6d0ca22013-02-24 17:33:15 +0000290 buf1 += size;
291 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200292
293 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000294 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200295 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000296 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000297 unmap_sysmem(buf1);
298 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000299
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000300 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000301 return rcode;
302}
303
Kim Phillipsdc00a682012-10-29 13:34:31 +0000304static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000305{
Fabio Estevamb03b0c82016-12-15 16:00:13 -0200306 ulong addr, dest, count;
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100307 void *src, *dst;
wdenk874ac262003-07-24 23:38:38 +0000308 int size;
wdenk38635852002-08-27 05:55:31 +0000309
Wolfgang Denk3b683112010-07-17 01:06:04 +0200310 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000311 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000312
313 /* Check for size specification.
314 */
wdenk874ac262003-07-24 23:38:38 +0000315 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
316 return 1;
wdenk38635852002-08-27 05:55:31 +0000317
318 addr = simple_strtoul(argv[1], NULL, 16);
319 addr += base_address;
320
321 dest = simple_strtoul(argv[2], NULL, 16);
322 dest += base_address;
323
324 count = simple_strtoul(argv[3], NULL, 16);
325
326 if (count == 0) {
327 puts ("Zero length ???\n");
328 return 1;
329 }
330
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100331 src = map_sysmem(addr, count * size);
332 dst = map_sysmem(dest, count * size);
333
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900334#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000335 /* check if we are copying to Flash */
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100336 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000337 int rc;
338
wdenk42c05472004-03-23 22:14:11 +0000339 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000340
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100341 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000342 if (rc != 0) {
Simon Glassa606ffc2019-12-28 10:44:40 -0700343 flash_perror(rc);
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100344 unmap_sysmem(src);
345 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000346 return (1);
347 }
348 puts ("done\n");
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100349 unmap_sysmem(src);
350 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000351 return 0;
352 }
wdenk7a428cc2003-06-15 22:40:42 +0000353#endif
354
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100355 memcpy(dst, src, count * size);
Masahiro Yamada787b0c52014-10-23 17:46:24 +0900356
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100357 unmap_sysmem(src);
358 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000359 return 0;
360}
361
Kim Phillipsdc00a682012-10-29 13:34:31 +0000362static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
363 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000364{
365 if (argc > 1) {
366 /* Set new base address.
367 */
368 base_address = simple_strtoul(argv[1], NULL, 16);
369 }
370 /* Print the current base address.
371 */
372 printf("Base Address: 0x%08lx\n", base_address);
373 return 0;
374}
375
Kim Phillipsdc00a682012-10-29 13:34:31 +0000376static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
377 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000378{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000379 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000380 int size;
Simon Glass8927bf22019-12-28 10:45:10 -0700381#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800382 volatile u64 *llp;
383#endif
York Sund8a405d2014-02-12 15:55:35 -0800384 volatile u32 *longp;
385 volatile u16 *shortp;
386 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000387 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000388
Wolfgang Denk3b683112010-07-17 01:06:04 +0200389 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000390 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000391
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000392 /*
393 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000394 * Defaults to long if no or incorrect specification.
395 */
wdenk874ac262003-07-24 23:38:38 +0000396 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
397 return 1;
wdenk38635852002-08-27 05:55:31 +0000398
399 /* Address is always specified.
400 */
401 addr = simple_strtoul(argv[1], NULL, 16);
402
403 /* Length is the number of objects, not number of bytes.
404 */
405 length = simple_strtoul(argv[2], NULL, 16);
406
Simon Glasse6d0ca22013-02-24 17:33:15 +0000407 bytes = size * length;
408 buf = map_sysmem(addr, bytes);
409
wdenk38635852002-08-27 05:55:31 +0000410 /* We want to optimize the loops to run as fast as possible.
411 * If we have only one object, just run infinite loops.
412 */
413 if (length == 1) {
Simon Glass8927bf22019-12-28 10:45:10 -0700414#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800415 if (size == 8) {
416 llp = (u64 *)buf;
417 for (;;)
418 i = *llp;
419 }
420#endif
wdenk38635852002-08-27 05:55:31 +0000421 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800422 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000423 for (;;)
424 i = *longp;
425 }
426 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800427 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000428 for (;;)
429 i = *shortp;
430 }
York Sund8a405d2014-02-12 15:55:35 -0800431 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000432 for (;;)
433 i = *cp;
434 }
435
Simon Glass8927bf22019-12-28 10:45:10 -0700436#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800437 if (size == 8) {
438 for (;;) {
439 llp = (u64 *)buf;
440 i = length;
441 while (i-- > 0)
442 *llp++;
443 }
444 }
445#endif
wdenk38635852002-08-27 05:55:31 +0000446 if (size == 4) {
447 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800448 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000449 i = length;
450 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200451 *longp++;
wdenk38635852002-08-27 05:55:31 +0000452 }
453 }
454 if (size == 2) {
455 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800456 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000457 i = length;
458 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200459 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000460 }
461 }
462 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800463 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000464 i = length;
465 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200466 *cp++;
wdenk38635852002-08-27 05:55:31 +0000467 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000468 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700469
470 return 0;
wdenk38635852002-08-27 05:55:31 +0000471}
472
wdenk64519362004-07-11 17:40:54 +0000473#ifdef CONFIG_LOOPW
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900474static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
475 char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000476{
York Sun6c480012014-02-26 17:03:19 -0800477 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000478 int size;
Simon Glass8927bf22019-12-28 10:45:10 -0700479#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800480 volatile u64 *llp;
481 u64 data;
482#else
483 ulong data;
484#endif
York Sund8a405d2014-02-12 15:55:35 -0800485 volatile u32 *longp;
486 volatile u16 *shortp;
487 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000488 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000489
Wolfgang Denk3b683112010-07-17 01:06:04 +0200490 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000491 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000492
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000493 /*
494 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000495 * Defaults to long if no or incorrect specification.
496 */
497 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
498 return 1;
499
500 /* Address is always specified.
501 */
502 addr = simple_strtoul(argv[1], NULL, 16);
503
504 /* Length is the number of objects, not number of bytes.
505 */
506 length = simple_strtoul(argv[2], NULL, 16);
507
508 /* data to write */
Simon Glass8927bf22019-12-28 10:45:10 -0700509#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800510 data = simple_strtoull(argv[3], NULL, 16);
511#else
wdenk64519362004-07-11 17:40:54 +0000512 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800513#endif
wdenk7dd13292004-07-11 20:04:51 +0000514
Simon Glasse6d0ca22013-02-24 17:33:15 +0000515 bytes = size * length;
516 buf = map_sysmem(addr, bytes);
517
wdenk64519362004-07-11 17:40:54 +0000518 /* We want to optimize the loops to run as fast as possible.
519 * If we have only one object, just run infinite loops.
520 */
521 if (length == 1) {
Simon Glass8927bf22019-12-28 10:45:10 -0700522#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800523 if (size == 8) {
524 llp = (u64 *)buf;
525 for (;;)
526 *llp = data;
527 }
528#endif
wdenk64519362004-07-11 17:40:54 +0000529 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800530 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000531 for (;;)
532 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800533 }
wdenk64519362004-07-11 17:40:54 +0000534 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800535 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000536 for (;;)
537 *shortp = data;
538 }
York Sund8a405d2014-02-12 15:55:35 -0800539 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000540 for (;;)
541 *cp = data;
542 }
543
Simon Glass8927bf22019-12-28 10:45:10 -0700544#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800545 if (size == 8) {
546 for (;;) {
547 llp = (u64 *)buf;
548 i = length;
549 while (i-- > 0)
550 *llp++ = data;
551 }
552 }
553#endif
wdenk64519362004-07-11 17:40:54 +0000554 if (size == 4) {
555 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800556 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000557 i = length;
558 while (i-- > 0)
559 *longp++ = data;
560 }
561 }
562 if (size == 2) {
563 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800564 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000565 i = length;
566 while (i-- > 0)
567 *shortp++ = data;
568 }
569 }
570 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800571 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000572 i = length;
573 while (i-- > 0)
574 *cp++ = data;
575 }
576}
577#endif /* CONFIG_LOOPW */
578
Tom Rinia5f02702013-03-12 10:07:19 -0400579#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000580static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
581 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000582{
Simon Glass8f2c7582013-02-24 17:33:16 +0000583 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000584 ulong errs = 0;
585 ulong val, readback;
586 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000587 vu_long offset;
588 vu_long test_offset;
589 vu_long pattern;
590 vu_long temp;
591 vu_long anti_pattern;
592 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000593 static const ulong bitpattern[] = {
594 0x00000001, /* single bit */
595 0x00000003, /* two adjacent bits */
596 0x00000007, /* three adjacent bits */
597 0x0000000F, /* four adjacent bits */
598 0x00000005, /* two non-adjacent bits */
599 0x00000015, /* three non-adjacent bits */
600 0x00000055, /* four non-adjacent bits */
601 0xaaaaaaaa, /* alternating 1/0 */
602 };
wdenk38635852002-08-27 05:55:31 +0000603
Simon Glassad02a012013-02-28 17:47:14 +0000604 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000605
Simon Glass130103e2013-02-24 17:33:18 +0000606 /*
607 * Data line test: write a pattern to the first
608 * location, write the 1's complement to a 'parking'
609 * address (changes the state of the data bus so a
610 * floating bus doesn't give a false OK), and then
611 * read the value back. Note that we read it back
612 * into a variable because the next time we read it,
613 * it might be right (been there, tough to explain to
614 * the quality guys why it prints a failure when the
615 * "is" and "should be" are obviously the same in the
616 * error message).
617 *
618 * Rather than exhaustively testing, we test some
619 * patterns by shifting '1' bits through a field of
620 * '0's and '0' bits through a field of '1's (i.e.
621 * pattern and ~pattern).
622 */
Simon Glassad02a012013-02-28 17:47:14 +0000623 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000624 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
625 val = bitpattern[j];
626 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000627 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000628 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000629 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000630 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000631 printf("FAILURE (data line): "
632 "expected %08lx, actual %08lx\n",
633 val, readback);
634 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000635 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000636 return -1;
wdenk38635852002-08-27 05:55:31 +0000637 }
638 *addr = ~val;
639 *dummy = val;
640 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000641 if (readback != ~val) {
642 printf("FAILURE (data line): "
643 "Is %08lx, should be %08lx\n",
644 readback, ~val);
645 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000646 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000647 return -1;
wdenk38635852002-08-27 05:55:31 +0000648 }
wdenk38635852002-08-27 05:55:31 +0000649 }
Simon Glass130103e2013-02-24 17:33:18 +0000650 }
wdenk38635852002-08-27 05:55:31 +0000651
Simon Glass130103e2013-02-24 17:33:18 +0000652 /*
653 * Based on code whose Original Author and Copyright
654 * information follows: Copyright (c) 1998 by Michael
655 * Barr. This software is placed into the public
656 * domain and may be used for any purpose. However,
657 * this notice must not be changed or removed and no
658 * warranty is either expressed or implied by its
659 * publication or distribution.
660 */
wdenk38635852002-08-27 05:55:31 +0000661
Simon Glass130103e2013-02-24 17:33:18 +0000662 /*
663 * Address line test
wdenk38635852002-08-27 05:55:31 +0000664
Simon Glass130103e2013-02-24 17:33:18 +0000665 * Description: Test the address bus wiring in a
666 * memory region by performing a walking
667 * 1's test on the relevant bits of the
668 * address and checking for aliasing.
669 * This test will find single-bit
670 * address failures such as stuck-high,
671 * stuck-low, and shorted pins. The base
672 * address and size of the region are
673 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000674
Simon Glass130103e2013-02-24 17:33:18 +0000675 * Notes: For best results, the selected base
676 * address should have enough LSB 0's to
677 * guarantee single address bit changes.
678 * For example, to test a 64-Kbyte
679 * region, select a base address on a
680 * 64-Kbyte boundary. Also, select the
681 * region size as a power-of-two if at
682 * all possible.
683 *
684 * Returns: 0 if the test succeeds, 1 if the test fails.
685 */
Simon Glass130103e2013-02-24 17:33:18 +0000686 pattern = (vu_long) 0xaaaaaaaa;
687 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000688
Simon Glassad02a012013-02-28 17:47:14 +0000689 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000690 /*
691 * Write the default pattern at each of the
692 * power-of-two offsets.
693 */
Simon Glassad02a012013-02-28 17:47:14 +0000694 for (offset = 1; offset < num_words; offset <<= 1)
695 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000696
697 /*
698 * Check for address bits stuck high.
699 */
700 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000701 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000702
Simon Glassad02a012013-02-28 17:47:14 +0000703 for (offset = 1; offset < num_words; offset <<= 1) {
704 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000705 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000706 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000707 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800708 start_addr + offset*sizeof(vu_long),
709 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400710 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000711 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000712 return -1;
wdenk38635852002-08-27 05:55:31 +0000713 }
Simon Glass130103e2013-02-24 17:33:18 +0000714 }
Simon Glassad02a012013-02-28 17:47:14 +0000715 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000716 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000717
Simon Glass130103e2013-02-24 17:33:18 +0000718 /*
719 * Check for addr bits stuck low or shorted.
720 */
Simon Glassad02a012013-02-28 17:47:14 +0000721 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
722 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000723
Simon Glassad02a012013-02-28 17:47:14 +0000724 for (offset = 1; offset < num_words; offset <<= 1) {
725 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000726 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000727 printf("\nFAILURE: Address bit stuck low or"
728 " shorted @ 0x%.8lx: expected 0x%.8lx,"
729 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800730 start_addr + offset*sizeof(vu_long),
731 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000732 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000733 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000734 return -1;
wdenk38635852002-08-27 05:55:31 +0000735 }
wdenk38635852002-08-27 05:55:31 +0000736 }
Simon Glassad02a012013-02-28 17:47:14 +0000737 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000738 }
wdenk38635852002-08-27 05:55:31 +0000739
Simon Glass130103e2013-02-24 17:33:18 +0000740 /*
741 * Description: Test the integrity of a physical
742 * memory device by performing an
743 * increment/decrement test over the
744 * entire region. In the process every
745 * storage bit in the device is tested
746 * as a zero and a one. The base address
747 * and the size of the region are
748 * selected by the caller.
749 *
750 * Returns: 0 if the test succeeds, 1 if the test fails.
751 */
Simon Glassad02a012013-02-28 17:47:14 +0000752 num_words++;
wdenk38635852002-08-27 05:55:31 +0000753
Simon Glass130103e2013-02-24 17:33:18 +0000754 /*
755 * Fill memory with a known pattern.
756 */
757 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
758 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000759 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000760 }
wdenk38635852002-08-27 05:55:31 +0000761
Simon Glass130103e2013-02-24 17:33:18 +0000762 /*
763 * Check each location and invert it for the second pass.
764 */
765 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
766 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000767 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000768 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000769 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000770 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800771 start_addr + offset*sizeof(vu_long),
772 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400773 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000774 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000775 return -1;
wdenk38635852002-08-27 05:55:31 +0000776 }
777
Simon Glass130103e2013-02-24 17:33:18 +0000778 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000779 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000780 }
781
782 /*
783 * Check each location for the inverted pattern and zero it.
784 */
785 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
786 WATCHDOG_RESET();
787 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000788 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000789 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000790 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000791 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800792 start_addr + offset*sizeof(vu_long),
793 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400794 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000795 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000796 return -1;
wdenk38635852002-08-27 05:55:31 +0000797 }
Simon Glassad02a012013-02-28 17:47:14 +0000798 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000799 }
Simon Glass57ee4432013-02-24 17:33:17 +0000800
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100801 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000802}
803
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100804static int compare_regions(volatile unsigned long *bufa,
805 volatile unsigned long *bufb, size_t count)
806{
807 volatile unsigned long *p1 = bufa;
808 volatile unsigned long *p2 = bufb;
809 int errs = 0;
810 size_t i;
811
812 for (i = 0; i < count; i++, p1++, p2++) {
813 if (*p1 != *p2) {
814 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
815 (unsigned long)*p1, (unsigned long)*p2,
816 *p1 ^ *p2, __ffs(*p1 ^ *p2),
817 (unsigned long)(i * sizeof(unsigned long)));
818 errs++;
819 }
820 }
821
822 return errs;
823}
824
825static ulong test_bitflip_comparison(volatile unsigned long *bufa,
826 volatile unsigned long *bufb, size_t count)
827{
828 volatile unsigned long *p1 = bufa;
829 volatile unsigned long *p2 = bufb;
830 unsigned int j, k;
831 unsigned long q;
832 size_t i;
833 int max;
834 int errs = 0;
835
836 max = sizeof(unsigned long) * 8;
837 for (k = 0; k < max; k++) {
838 q = 0x00000001L << k;
839 for (j = 0; j < 8; j++) {
840 WATCHDOG_RESET();
841 q = ~q;
842 p1 = (volatile unsigned long *)bufa;
843 p2 = (volatile unsigned long *)bufb;
844 for (i = 0; i < count; i++)
845 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
846
847 errs += compare_regions(bufa, bufb, count);
848 }
849
850 if (ctrlc())
851 return -1UL;
852 }
853
854 return errs;
855}
856
Simon Glassad02a012013-02-28 17:47:14 +0000857static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
858 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000859{
Simon Glassad02a012013-02-28 17:47:14 +0000860 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000861 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000862 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000863 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000864 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000865
Simon Glass57ee4432013-02-24 17:33:17 +0000866 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000867 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000868 if (iteration & 1) {
869 incr = -incr;
870 /*
871 * Flip the pattern each time to make lots of zeros and
872 * then, the next time, lots of ones. We decrement
873 * the "negative" patterns and increment the "positive"
874 * patterns to preserve this feature.
875 */
876 if (pattern & 0x80000000)
877 pattern = -pattern; /* complement & increment */
878 else
879 pattern = ~pattern;
880 }
Simon Glassad02a012013-02-28 17:47:14 +0000881 length = (end_addr - start_addr) / sizeof(ulong);
882 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000883 printf("\rPattern %08lX Writing..."
884 "%12s"
885 "\b\b\b\b\b\b\b\b\b\b",
886 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000887
Simon Glassad02a012013-02-28 17:47:14 +0000888 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000889 WATCHDOG_RESET();
890 *addr = val;
891 val += incr;
892 }
wdenk38635852002-08-27 05:55:31 +0000893
Simon Glass130103e2013-02-24 17:33:18 +0000894 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000895
Simon Glassad02a012013-02-28 17:47:14 +0000896 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000897 WATCHDOG_RESET();
898 readback = *addr;
899 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000900 ulong offset = addr - buf;
901
Simon Glass130103e2013-02-24 17:33:18 +0000902 printf("\nMem error @ 0x%08X: "
903 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800904 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000905 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000906 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000907 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000908 return -1;
wdenk38635852002-08-27 05:55:31 +0000909 }
Simon Glass130103e2013-02-24 17:33:18 +0000910 val += incr;
911 }
wdenk38635852002-08-27 05:55:31 +0000912
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100913 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000914}
915
916/*
917 * Perform a memory test. A more complete alternative test can be
918 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
919 * interrupted by ctrl-c or by a failure of one of the sub-tests.
920 */
921static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
922 char * const argv[])
923{
Simon Glass51075252013-02-24 17:33:20 +0000924 ulong start, end;
Simon Glassad02a012013-02-28 17:47:14 +0000925 vu_long *buf, *dummy;
Tom Rinib9180882015-04-07 09:38:54 -0400926 ulong iteration_limit = 0;
Stefan Roese32265fc2020-03-05 07:21:29 +0100927 ulong count = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000928 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Machekd319f592015-04-01 13:50:41 +0200929 ulong pattern = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000930 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +0000931
Pavel Machekd319f592015-04-01 13:50:41 +0200932 start = CONFIG_SYS_MEMTEST_START;
933 end = CONFIG_SYS_MEMTEST_END;
934
Simon Glass8f2c7582013-02-24 17:33:16 +0000935 if (argc > 1)
Pavel Machekd319f592015-04-01 13:50:41 +0200936 if (strict_strtoul(argv[1], 16, &start) < 0)
937 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000938
939 if (argc > 2)
Pavel Machekd319f592015-04-01 13:50:41 +0200940 if (strict_strtoul(argv[2], 16, &end) < 0)
941 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000942
943 if (argc > 3)
Pavel Machekd319f592015-04-01 13:50:41 +0200944 if (strict_strtoul(argv[3], 16, &pattern) < 0)
945 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000946
947 if (argc > 4)
Pavel Machekd319f592015-04-01 13:50:41 +0200948 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
949 return CMD_RET_USAGE;
950
951 if (end < start) {
952 printf("Refusing to do empty test\n");
953 return -1;
954 }
Simon Glass8f2c7582013-02-24 17:33:16 +0000955
Michal Simek45f8e332016-02-24 08:36:02 +0100956 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass51075252013-02-24 17:33:20 +0000957 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
958 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +0000959
Simon Glassad02a012013-02-28 17:47:14 +0000960 buf = map_sysmem(start, end - start);
961 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass57ee4432013-02-24 17:33:17 +0000962 for (iteration = 0;
963 !iteration_limit || iteration < iteration_limit;
964 iteration++) {
965 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +0000966 errs = -1UL;
967 break;
968 }
969
970 printf("Iteration: %6d\r", iteration + 1);
971 debug("\n");
Stefan Roese1eb8b1e2020-03-05 07:21:31 +0100972 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
Simon Glassad02a012013-02-28 17:47:14 +0000973 errs = mem_test_alt(buf, start, end, dummy);
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100974 if (errs == -1UL)
975 break;
976 count += errs;
977 errs = test_bitflip_comparison(buf,
978 buf + (end - start) / 2,
979 (end - start) /
980 sizeof(unsigned long));
Simon Glassad02a012013-02-28 17:47:14 +0000981 } else {
982 errs = mem_test_quick(buf, start, end, pattern,
983 iteration);
984 }
985 if (errs == -1UL)
986 break;
Stefan Roese32265fc2020-03-05 07:21:29 +0100987 count += errs;
Simon Glassad02a012013-02-28 17:47:14 +0000988 }
989
Stefan Roesec1d47db2020-03-05 07:21:30 +0100990 unmap_sysmem((void *)buf);
991 unmap_sysmem((void *)dummy);
Simon Glass57ee4432013-02-24 17:33:17 +0000992
993 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +0000994 /* Memory test was aborted - write a newline to finish off */
995 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +0000996 }
Stefan Roese32265fc2020-03-05 07:21:29 +0100997 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
Simon Glass8f2c7582013-02-24 17:33:16 +0000998
Stefan Roese32265fc2020-03-05 07:21:29 +0100999 return errs != 0;
wdenk38635852002-08-27 05:55:31 +00001000}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001001#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001002
1003/* Modify memory.
1004 *
1005 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001006 * mm{.b, .w, .l, .q} {addr}
1007 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001008 */
1009static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001010mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001011{
York Sun6c480012014-02-26 17:03:19 -08001012 ulong addr;
Simon Glass8927bf22019-12-28 10:45:10 -07001013#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001014 u64 i;
1015#else
1016 ulong i;
1017#endif
wdenk874ac262003-07-24 23:38:38 +00001018 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001019 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001020
Wolfgang Denk3b683112010-07-17 01:06:04 +02001021 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001022 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001023
Simon Glass09007c42014-04-10 20:01:31 -06001024 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001025 /* We use the last specified parameters, unless new ones are
1026 * entered.
1027 */
1028 addr = mm_last_addr;
1029 size = mm_last_size;
1030
1031 if ((flag & CMD_FLAG_REPEAT) == 0) {
1032 /* New command specified. Check for a size specification.
1033 * Defaults to long if no or incorrect specification.
1034 */
wdenk874ac262003-07-24 23:38:38 +00001035 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1036 return 1;
wdenk38635852002-08-27 05:55:31 +00001037
1038 /* Address is specified since argc > 1
1039 */
1040 addr = simple_strtoul(argv[1], NULL, 16);
1041 addr += base_address;
1042 }
wdenk381669a2003-06-16 23:50:08 +00001043
wdenk38635852002-08-27 05:55:31 +00001044 /* Print the address, followed by value. Then accept input for
1045 * the next value. A non-converted value exits.
1046 */
1047 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001048 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001049 printf("%08lx:", addr);
1050 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001051 printf(" %08x", *((u32 *)ptr));
Simon Glass8927bf22019-12-28 10:45:10 -07001052#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001053 else if (size == 8)
Masahiro Yamadac7570a32018-08-06 20:47:40 +09001054 printf(" %016llx", *((u64 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001055#endif
wdenk38635852002-08-27 05:55:31 +00001056 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001057 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001058 else
York Sund8a405d2014-02-12 15:55:35 -08001059 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001060
Simon Glassbe6aafc2014-04-10 20:01:27 -06001061 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001062 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1063 /* <CR> pressed as only input, don't modify current
1064 * location and move to next. "-" pressed will go back.
1065 */
1066 if (incrflag)
1067 addr += nbytes ? -size : size;
1068 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001069 /* good enough to not time out */
1070 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001071 }
1072#ifdef CONFIG_BOOT_RETRY_TIME
1073 else if (nbytes == -2) {
1074 break; /* timed out, exit the command */
1075 }
1076#endif
1077 else {
1078 char *endp;
Simon Glass8927bf22019-12-28 10:45:10 -07001079#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001080 i = simple_strtoull(console_buffer, &endp, 16);
1081#else
wdenk38635852002-08-27 05:55:31 +00001082 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001083#endif
wdenk38635852002-08-27 05:55:31 +00001084 nbytes = endp - console_buffer;
1085 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001086 /* good enough to not time out
1087 */
Simon Glass09007c42014-04-10 20:01:31 -06001088 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001089 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001090 *((u32 *)ptr) = i;
Simon Glass8927bf22019-12-28 10:45:10 -07001091#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001092 else if (size == 8)
1093 *((u64 *)ptr) = i;
1094#endif
wdenk38635852002-08-27 05:55:31 +00001095 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001096 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001097 else
York Sund8a405d2014-02-12 15:55:35 -08001098 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001099 if (incrflag)
1100 addr += size;
1101 }
1102 }
1103 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001104 if (ptr)
1105 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001106
1107 mm_last_addr = addr;
1108 mm_last_size = size;
1109 return 0;
1110}
1111
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001112#ifdef CONFIG_CMD_CRC32
1113
Kim Phillipsdc00a682012-10-29 13:34:31 +00001114static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001115{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001116 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001117 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001118 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001119
Simon Glass0bbd76f2013-02-24 20:30:22 +00001120 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001121 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001122
1123 av = argv + 1;
1124 ac = argc - 1;
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001125#ifdef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001126 if (strcmp(*av, "-v") == 0) {
Joe Hershberger5fcee9a2015-05-05 12:23:53 -05001127 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenk6203e402004-04-18 10:13:26 +00001128 av++;
1129 ac--;
wdenk6203e402004-04-18 10:13:26 +00001130 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001131#endif
wdenk6203e402004-04-18 10:13:26 +00001132
Simon Glass0bbd76f2013-02-24 20:30:22 +00001133 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001134}
wdenk6203e402004-04-18 10:13:26 +00001135
Robin Getz93d6cb02009-07-27 00:07:59 -04001136#endif
1137
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001138#ifdef CONFIG_CMD_RANDOM
1139static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1140{
1141 unsigned long addr, len;
1142 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1143 unsigned int *buf, *start;
1144 unsigned char *buf8;
1145 unsigned int i;
1146
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001147 if (argc < 3 || argc > 4)
1148 return CMD_RET_USAGE;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001149
1150 len = simple_strtoul(argv[2], NULL, 16);
1151 addr = simple_strtoul(argv[1], NULL, 16);
1152
1153 if (argc == 4) {
1154 seed = simple_strtoul(argv[3], NULL, 16);
1155 if (seed == 0) {
1156 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1157 seed = 0xDEADBEEF;
1158 }
1159 } else {
1160 seed = get_timer(0) ^ rand();
1161 }
1162
1163 srand(seed);
1164 start = map_sysmem(addr, len);
1165 buf = start;
1166 for (i = 0; i < (len / 4); i++)
1167 *buf++ = rand();
1168
1169 buf8 = (unsigned char *)buf;
1170 for (i = 0; i < (len % 4); i++)
1171 *buf8++ = rand() & 0xFF;
1172
1173 unmap_sysmem(start);
1174 printf("%lu bytes filled with random data\n", len);
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001175
1176 return CMD_RET_SUCCESS;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001177}
1178#endif
1179
wdenk57b2d802003-06-27 21:31:46 +00001180/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001181U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001182 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001183 "memory display",
Simon Glass8927bf22019-12-28 10:45:10 -07001184#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001185 "[.b, .w, .l, .q] address [# of objects]"
1186#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001187 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001188#endif
wdenk57b2d802003-06-27 21:31:46 +00001189);
1190
1191
wdenkf287a242003-07-01 21:06:45 +00001192U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001193 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001194 "memory modify (auto-incrementing address)",
Simon Glass8927bf22019-12-28 10:45:10 -07001195#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001196 "[.b, .w, .l, .q] address"
1197#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001198 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001199#endif
wdenk57b2d802003-06-27 21:31:46 +00001200);
1201
1202
wdenkf287a242003-07-01 21:06:45 +00001203U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001204 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001205 "memory modify (constant address)",
Simon Glass8927bf22019-12-28 10:45:10 -07001206#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001207 "[.b, .w, .l, .q] address"
1208#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001209 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001210#endif
wdenk57b2d802003-06-27 21:31:46 +00001211);
1212
wdenkf287a242003-07-01 21:06:45 +00001213U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001214 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001215 "memory write (fill)",
Simon Glass8927bf22019-12-28 10:45:10 -07001216#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001217 "[.b, .w, .l, .q] address value [count]"
1218#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001219 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001220#endif
wdenk57b2d802003-06-27 21:31:46 +00001221);
1222
wdenkf287a242003-07-01 21:06:45 +00001223U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001224 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001225 "memory copy",
Simon Glass8927bf22019-12-28 10:45:10 -07001226#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001227 "[.b, .w, .l, .q] source target count"
1228#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001229 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001230#endif
wdenk57b2d802003-06-27 21:31:46 +00001231);
1232
wdenkf287a242003-07-01 21:06:45 +00001233U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001234 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001235 "memory compare",
Simon Glass8927bf22019-12-28 10:45:10 -07001236#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001237 "[.b, .w, .l, .q] addr1 addr2 count"
1238#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001239 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001240#endif
wdenk57b2d802003-06-27 21:31:46 +00001241);
1242
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001243#ifdef CONFIG_CMD_CRC32
1244
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001245#ifndef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001246
wdenkf287a242003-07-01 21:06:45 +00001247U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001248 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001249 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001250 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001251);
1252
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001253#else /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001254
1255U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001256 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001257 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001258 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001259 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001260);
1261
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001262#endif /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001263
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001264#endif
1265
Simon Glasseacd14f2012-11-30 13:01:20 +00001266#ifdef CONFIG_CMD_MEMINFO
Simon Glasseacd14f2012-11-30 13:01:20 +00001267static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1268 char * const argv[])
1269{
Simon Glass320a5d42019-11-14 12:57:44 -07001270 puts("DRAM: ");
1271 print_size(gd->ram_size, "\n");
Simon Glasseacd14f2012-11-30 13:01:20 +00001272
1273 return 0;
1274}
1275#endif
1276
wdenkf287a242003-07-01 21:06:45 +00001277U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001278 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001279 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001280 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001281 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001282);
1283
wdenkf287a242003-07-01 21:06:45 +00001284U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001285 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001286 "infinite loop on address range",
Simon Glass8927bf22019-12-28 10:45:10 -07001287#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001288 "[.b, .w, .l, .q] address number_of_objects"
1289#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001290 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001291#endif
wdenk57b2d802003-06-27 21:31:46 +00001292);
wdenk64519362004-07-11 17:40:54 +00001293
1294#ifdef CONFIG_LOOPW
1295U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001296 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001297 "infinite write loop on address range",
Simon Glass8927bf22019-12-28 10:45:10 -07001298#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001299 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1300#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001301 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001302#endif
wdenk64519362004-07-11 17:40:54 +00001303);
1304#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001305
Wolfgang Denk9d009282013-03-08 10:51:32 +00001306#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001307U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001308 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001309 "simple RAM read/write test",
1310 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001311);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001312#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001313
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001314#ifdef CONFIG_CMD_MX_CYCLIC
stroesefb5e0ac2004-12-16 17:42:39 +00001315U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001316 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001317 "memory display cyclic",
Simon Glass8927bf22019-12-28 10:45:10 -07001318#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001319 "[.b, .w, .l, .q] address count delay(ms)"
1320#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001321 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001322#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001323);
1324
1325U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001326 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001327 "memory write cyclic",
Simon Glass8927bf22019-12-28 10:45:10 -07001328#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001329 "[.b, .w, .l, .q] address value delay(ms)"
1330#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001331 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001332#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001333);
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001334#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001335
1336#ifdef CONFIG_CMD_MEMINFO
1337U_BOOT_CMD(
1338 meminfo, 3, 1, do_mem_info,
1339 "display memory information",
1340 ""
1341);
1342#endif
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001343
1344#ifdef CONFIG_CMD_RANDOM
1345U_BOOT_CMD(
1346 random, 4, 0, do_random,
1347 "fill memory with random pattern",
1348 "<addr> <len> [<seed>]\n"
1349 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1350);
1351#endif