blob: 18f0510098be60355b4252815fd3401a87a2cb3c [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
Wolfgang Denk6262d0212010-06-28 22:00:46 +020028static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000029
30/* Display values from last command.
31 * Memory modify remembered values are different from display memory.
32 */
Scott Wood3ec02882015-03-19 09:43:12 -070033static ulong dp_last_addr, dp_last_size;
34static ulong dp_last_length = 0x40;
35static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000036
37static ulong base_address = 0;
38
39/* Memory Display
40 *
41 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080042 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000043 */
44#define DISP_LINE_LEN 16
Kim Phillipsdc00a682012-10-29 13:34:31 +000045static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000046{
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030047 ulong addr, length, bytes;
48 const void *buf;
wdenk874ac262003-07-24 23:38:38 +000049 int size;
wdenk38635852002-08-27 05:55:31 +000050 int rc = 0;
51
52 /* We use the last specified parameters, unless new ones are
53 * entered.
54 */
55 addr = dp_last_addr;
56 size = dp_last_size;
57 length = dp_last_length;
58
Wolfgang Denk3b683112010-07-17 01:06:04 +020059 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000060 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000061
62 if ((flag & CMD_FLAG_REPEAT) == 0) {
63 /* New command specified. Check for a size specification.
64 * Defaults to long if no or incorrect specification.
65 */
wdenk874ac262003-07-24 23:38:38 +000066 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
67 return 1;
wdenk38635852002-08-27 05:55:31 +000068
69 /* Address is specified since argc > 1
70 */
71 addr = simple_strtoul(argv[1], NULL, 16);
72 addr += base_address;
73
74 /* If another parameter, it is the length to display.
75 * Length is the number of objects, not number of bytes.
76 */
77 if (argc > 2)
78 length = simple_strtoul(argv[2], NULL, 16);
79 }
80
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030081 bytes = size * length;
82 buf = map_sysmem(addr, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +000083
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030084 /* Print the lines. */
85 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
86 addr += bytes;
87 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +000088
89 dp_last_addr = addr;
90 dp_last_length = length;
91 dp_last_size = size;
92 return (rc);
93}
94
Kim Phillipsdc00a682012-10-29 13:34:31 +000095static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000096{
97 return mod_mem (cmdtp, 1, flag, argc, argv);
98}
Kim Phillipsdc00a682012-10-29 13:34:31 +000099static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000100{
101 return mod_mem (cmdtp, 0, flag, argc, argv);
102}
103
Kim Phillipsdc00a682012-10-29 13:34:31 +0000104static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000105{
Simon Glass8927bf22019-12-28 10:45:10 -0700106#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800107 u64 writeval;
108#else
109 ulong writeval;
110#endif
111 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000112 int size;
Simon Glass3c4a2872015-03-05 12:25:18 -0700113 void *buf, *start;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000114 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000115
Wolfgang Denk3b683112010-07-17 01:06:04 +0200116 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000117 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000118
119 /* Check for size specification.
120 */
wdenk874ac262003-07-24 23:38:38 +0000121 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
122 return 1;
wdenk38635852002-08-27 05:55:31 +0000123
124 /* Address is specified since argc > 1
125 */
126 addr = simple_strtoul(argv[1], NULL, 16);
127 addr += base_address;
128
129 /* Get the value to write.
130 */
Simon Glass8927bf22019-12-28 10:45:10 -0700131#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800132 writeval = simple_strtoull(argv[2], NULL, 16);
133#else
wdenk38635852002-08-27 05:55:31 +0000134 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800135#endif
wdenk38635852002-08-27 05:55:31 +0000136
137 /* Count ? */
138 if (argc == 4) {
139 count = simple_strtoul(argv[3], NULL, 16);
140 } else {
141 count = 1;
142 }
143
Simon Glasse6d0ca22013-02-24 17:33:15 +0000144 bytes = size * count;
Simon Glass3c4a2872015-03-05 12:25:18 -0700145 start = map_sysmem(addr, bytes);
146 buf = start;
wdenk38635852002-08-27 05:55:31 +0000147 while (count-- > 0) {
148 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800149 *((u32 *)buf) = (u32)writeval;
Simon Glass8927bf22019-12-28 10:45:10 -0700150#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800151 else if (size == 8)
152 *((u64 *)buf) = (u64)writeval;
153#endif
wdenk38635852002-08-27 05:55:31 +0000154 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800155 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000156 else
York Sund8a405d2014-02-12 15:55:35 -0800157 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000158 buf += size;
wdenk38635852002-08-27 05:55:31 +0000159 }
Simon Glass3c4a2872015-03-05 12:25:18 -0700160 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000161 return 0;
162}
163
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700164#ifdef CONFIG_CMD_MX_CYCLIC
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900165static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000166{
167 int i;
168 ulong count;
169
Wolfgang Denk3b683112010-07-17 01:06:04 +0200170 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000171 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000172
173 count = simple_strtoul(argv[3], NULL, 10);
174
175 for (;;) {
176 do_mem_md (NULL, 0, 3, argv);
177
178 /* delay for <count> ms... */
179 for (i=0; i<count; i++)
180 udelay (1000);
181
182 /* check for ctrl-c to abort... */
183 if (ctrlc()) {
184 puts("Abort\n");
185 return 0;
186 }
187 }
188
189 return 0;
190}
191
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900192static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000193{
194 int i;
195 ulong count;
196
Wolfgang Denk3b683112010-07-17 01:06:04 +0200197 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000198 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000199
200 count = simple_strtoul(argv[3], NULL, 10);
201
202 for (;;) {
203 do_mem_mw (NULL, 0, 3, argv);
204
205 /* delay for <count> ms... */
206 for (i=0; i<count; i++)
207 udelay (1000);
208
209 /* check for ctrl-c to abort... */
210 if (ctrlc()) {
211 puts("Abort\n");
212 return 0;
213 }
214 }
215
216 return 0;
217}
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700218#endif /* CONFIG_CMD_MX_CYCLIC */
stroesefb5e0ac2004-12-16 17:42:39 +0000219
Kim Phillipsdc00a682012-10-29 13:34:31 +0000220static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000221{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000222 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000223 int size;
wdenk38635852002-08-27 05:55:31 +0000224 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000225 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000226 const void *buf1, *buf2, *base;
Simon Glass8927bf22019-12-28 10:45:10 -0700227#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800228 u64 word1, word2;
229#else
230 ulong word1, word2;
231#endif
wdenk38635852002-08-27 05:55:31 +0000232
Wolfgang Denk3b683112010-07-17 01:06:04 +0200233 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000234 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000235
236 /* Check for size specification.
237 */
wdenk874ac262003-07-24 23:38:38 +0000238 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
239 return 1;
York Sun6c480012014-02-26 17:03:19 -0800240 type = size == 8 ? "double word" :
241 size == 4 ? "word" :
242 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000243
244 addr1 = simple_strtoul(argv[1], NULL, 16);
245 addr1 += base_address;
246
247 addr2 = simple_strtoul(argv[2], NULL, 16);
248 addr2 += base_address;
249
250 count = simple_strtoul(argv[3], NULL, 16);
251
Simon Glasse6d0ca22013-02-24 17:33:15 +0000252 bytes = size * count;
253 base = buf1 = map_sysmem(addr1, bytes);
254 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000255 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000256 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800257 word1 = *(u32 *)buf1;
258 word2 = *(u32 *)buf2;
Simon Glass8927bf22019-12-28 10:45:10 -0700259#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800260 } else if (size == 8) {
261 word1 = *(u64 *)buf1;
262 word2 = *(u64 *)buf2;
263#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000264 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800265 word1 = *(u16 *)buf1;
266 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000267 } else {
York Sund8a405d2014-02-12 15:55:35 -0800268 word1 = *(u8 *)buf1;
269 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000270 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000271 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000272 ulong offset = buf1 - base;
Simon Glass8927bf22019-12-28 10:45:10 -0700273#ifdef MEM_SUPPORT_64BIT_DATA
Masahiro Yamadac7570a32018-08-06 20:47:40 +0900274 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
York Sun6c480012014-02-26 17:03:19 -0800275 type, (void *)(addr1 + offset), size, word1,
276 type, (void *)(addr2 + offset), size, word2);
277#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000278 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000279 type, (ulong)(addr1 + offset), size, word1,
280 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800281#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000282 rcode = 1;
283 break;
wdenk38635852002-08-27 05:55:31 +0000284 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000285
Simon Glasse6d0ca22013-02-24 17:33:15 +0000286 buf1 += size;
287 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200288
289 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000290 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200291 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000292 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000293 unmap_sysmem(buf1);
294 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000295
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000296 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000297 return rcode;
298}
299
Kim Phillipsdc00a682012-10-29 13:34:31 +0000300static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000301{
Fabio Estevamb03b0c82016-12-15 16:00:13 -0200302 ulong addr, dest, count;
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100303 void *src, *dst;
wdenk874ac262003-07-24 23:38:38 +0000304 int size;
wdenk38635852002-08-27 05:55:31 +0000305
Wolfgang Denk3b683112010-07-17 01:06:04 +0200306 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000307 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000308
309 /* Check for size specification.
310 */
wdenk874ac262003-07-24 23:38:38 +0000311 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
312 return 1;
wdenk38635852002-08-27 05:55:31 +0000313
314 addr = simple_strtoul(argv[1], NULL, 16);
315 addr += base_address;
316
317 dest = simple_strtoul(argv[2], NULL, 16);
318 dest += base_address;
319
320 count = simple_strtoul(argv[3], NULL, 16);
321
322 if (count == 0) {
323 puts ("Zero length ???\n");
324 return 1;
325 }
326
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100327 src = map_sysmem(addr, count * size);
328 dst = map_sysmem(dest, count * size);
329
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900330#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000331 /* check if we are copying to Flash */
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100332 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000333 int rc;
334
wdenk42c05472004-03-23 22:14:11 +0000335 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000336
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100337 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000338 if (rc != 0) {
Simon Glassa606ffc2019-12-28 10:44:40 -0700339 flash_perror(rc);
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100340 unmap_sysmem(src);
341 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000342 return (1);
343 }
344 puts ("done\n");
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100345 unmap_sysmem(src);
346 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000347 return 0;
348 }
wdenk7a428cc2003-06-15 22:40:42 +0000349#endif
350
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100351 memcpy(dst, src, count * size);
Masahiro Yamada787b0c52014-10-23 17:46:24 +0900352
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100353 unmap_sysmem(src);
354 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000355 return 0;
356}
357
Kim Phillipsdc00a682012-10-29 13:34:31 +0000358static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
359 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000360{
361 if (argc > 1) {
362 /* Set new base address.
363 */
364 base_address = simple_strtoul(argv[1], NULL, 16);
365 }
366 /* Print the current base address.
367 */
368 printf("Base Address: 0x%08lx\n", base_address);
369 return 0;
370}
371
Kim Phillipsdc00a682012-10-29 13:34:31 +0000372static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
373 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000374{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000375 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000376 int size;
Simon Glass8927bf22019-12-28 10:45:10 -0700377#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800378 volatile u64 *llp;
379#endif
York Sund8a405d2014-02-12 15:55:35 -0800380 volatile u32 *longp;
381 volatile u16 *shortp;
382 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000383 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000384
Wolfgang Denk3b683112010-07-17 01:06:04 +0200385 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000386 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000387
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000388 /*
389 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000390 * Defaults to long if no or incorrect specification.
391 */
wdenk874ac262003-07-24 23:38:38 +0000392 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
393 return 1;
wdenk38635852002-08-27 05:55:31 +0000394
395 /* Address is always specified.
396 */
397 addr = simple_strtoul(argv[1], NULL, 16);
398
399 /* Length is the number of objects, not number of bytes.
400 */
401 length = simple_strtoul(argv[2], NULL, 16);
402
Simon Glasse6d0ca22013-02-24 17:33:15 +0000403 bytes = size * length;
404 buf = map_sysmem(addr, bytes);
405
wdenk38635852002-08-27 05:55:31 +0000406 /* We want to optimize the loops to run as fast as possible.
407 * If we have only one object, just run infinite loops.
408 */
409 if (length == 1) {
Simon Glass8927bf22019-12-28 10:45:10 -0700410#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800411 if (size == 8) {
412 llp = (u64 *)buf;
413 for (;;)
414 i = *llp;
415 }
416#endif
wdenk38635852002-08-27 05:55:31 +0000417 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800418 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000419 for (;;)
420 i = *longp;
421 }
422 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800423 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000424 for (;;)
425 i = *shortp;
426 }
York Sund8a405d2014-02-12 15:55:35 -0800427 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000428 for (;;)
429 i = *cp;
430 }
431
Simon Glass8927bf22019-12-28 10:45:10 -0700432#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800433 if (size == 8) {
434 for (;;) {
435 llp = (u64 *)buf;
436 i = length;
437 while (i-- > 0)
438 *llp++;
439 }
440 }
441#endif
wdenk38635852002-08-27 05:55:31 +0000442 if (size == 4) {
443 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800444 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000445 i = length;
446 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200447 *longp++;
wdenk38635852002-08-27 05:55:31 +0000448 }
449 }
450 if (size == 2) {
451 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800452 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000453 i = length;
454 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200455 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000456 }
457 }
458 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800459 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000460 i = length;
461 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200462 *cp++;
wdenk38635852002-08-27 05:55:31 +0000463 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000464 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700465
466 return 0;
wdenk38635852002-08-27 05:55:31 +0000467}
468
wdenk64519362004-07-11 17:40:54 +0000469#ifdef CONFIG_LOOPW
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900470static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
471 char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000472{
York Sun6c480012014-02-26 17:03:19 -0800473 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000474 int size;
Simon Glass8927bf22019-12-28 10:45:10 -0700475#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800476 volatile u64 *llp;
477 u64 data;
478#else
479 ulong data;
480#endif
York Sund8a405d2014-02-12 15:55:35 -0800481 volatile u32 *longp;
482 volatile u16 *shortp;
483 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000484 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000485
Wolfgang Denk3b683112010-07-17 01:06:04 +0200486 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000487 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000488
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000489 /*
490 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000491 * Defaults to long if no or incorrect specification.
492 */
493 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
494 return 1;
495
496 /* Address is always specified.
497 */
498 addr = simple_strtoul(argv[1], NULL, 16);
499
500 /* Length is the number of objects, not number of bytes.
501 */
502 length = simple_strtoul(argv[2], NULL, 16);
503
504 /* data to write */
Simon Glass8927bf22019-12-28 10:45:10 -0700505#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800506 data = simple_strtoull(argv[3], NULL, 16);
507#else
wdenk64519362004-07-11 17:40:54 +0000508 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800509#endif
wdenk7dd13292004-07-11 20:04:51 +0000510
Simon Glasse6d0ca22013-02-24 17:33:15 +0000511 bytes = size * length;
512 buf = map_sysmem(addr, bytes);
513
wdenk64519362004-07-11 17:40:54 +0000514 /* We want to optimize the loops to run as fast as possible.
515 * If we have only one object, just run infinite loops.
516 */
517 if (length == 1) {
Simon Glass8927bf22019-12-28 10:45:10 -0700518#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800519 if (size == 8) {
520 llp = (u64 *)buf;
521 for (;;)
522 *llp = data;
523 }
524#endif
wdenk64519362004-07-11 17:40:54 +0000525 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800526 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000527 for (;;)
528 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800529 }
wdenk64519362004-07-11 17:40:54 +0000530 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800531 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000532 for (;;)
533 *shortp = data;
534 }
York Sund8a405d2014-02-12 15:55:35 -0800535 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000536 for (;;)
537 *cp = data;
538 }
539
Simon Glass8927bf22019-12-28 10:45:10 -0700540#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800541 if (size == 8) {
542 for (;;) {
543 llp = (u64 *)buf;
544 i = length;
545 while (i-- > 0)
546 *llp++ = data;
547 }
548 }
549#endif
wdenk64519362004-07-11 17:40:54 +0000550 if (size == 4) {
551 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800552 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000553 i = length;
554 while (i-- > 0)
555 *longp++ = data;
556 }
557 }
558 if (size == 2) {
559 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800560 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000561 i = length;
562 while (i-- > 0)
563 *shortp++ = data;
564 }
565 }
566 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800567 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000568 i = length;
569 while (i-- > 0)
570 *cp++ = data;
571 }
572}
573#endif /* CONFIG_LOOPW */
574
Tom Rinia5f02702013-03-12 10:07:19 -0400575#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000576static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
577 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000578{
Simon Glass8f2c7582013-02-24 17:33:16 +0000579 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000580 ulong errs = 0;
581 ulong val, readback;
582 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000583 vu_long offset;
584 vu_long test_offset;
585 vu_long pattern;
586 vu_long temp;
587 vu_long anti_pattern;
588 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000589 static const ulong bitpattern[] = {
590 0x00000001, /* single bit */
591 0x00000003, /* two adjacent bits */
592 0x00000007, /* three adjacent bits */
593 0x0000000F, /* four adjacent bits */
594 0x00000005, /* two non-adjacent bits */
595 0x00000015, /* three non-adjacent bits */
596 0x00000055, /* four non-adjacent bits */
597 0xaaaaaaaa, /* alternating 1/0 */
598 };
wdenk38635852002-08-27 05:55:31 +0000599
Simon Glassad02a012013-02-28 17:47:14 +0000600 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000601
Simon Glass130103e2013-02-24 17:33:18 +0000602 /*
603 * Data line test: write a pattern to the first
604 * location, write the 1's complement to a 'parking'
605 * address (changes the state of the data bus so a
606 * floating bus doesn't give a false OK), and then
607 * read the value back. Note that we read it back
608 * into a variable because the next time we read it,
609 * it might be right (been there, tough to explain to
610 * the quality guys why it prints a failure when the
611 * "is" and "should be" are obviously the same in the
612 * error message).
613 *
614 * Rather than exhaustively testing, we test some
615 * patterns by shifting '1' bits through a field of
616 * '0's and '0' bits through a field of '1's (i.e.
617 * pattern and ~pattern).
618 */
Simon Glassad02a012013-02-28 17:47:14 +0000619 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000620 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
621 val = bitpattern[j];
622 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000623 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000624 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000625 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000626 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000627 printf("FAILURE (data line): "
628 "expected %08lx, actual %08lx\n",
629 val, readback);
630 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000631 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000632 return -1;
wdenk38635852002-08-27 05:55:31 +0000633 }
634 *addr = ~val;
635 *dummy = val;
636 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000637 if (readback != ~val) {
638 printf("FAILURE (data line): "
639 "Is %08lx, should be %08lx\n",
640 readback, ~val);
641 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000642 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000643 return -1;
wdenk38635852002-08-27 05:55:31 +0000644 }
wdenk38635852002-08-27 05:55:31 +0000645 }
Simon Glass130103e2013-02-24 17:33:18 +0000646 }
wdenk38635852002-08-27 05:55:31 +0000647
Simon Glass130103e2013-02-24 17:33:18 +0000648 /*
649 * Based on code whose Original Author and Copyright
650 * information follows: Copyright (c) 1998 by Michael
651 * Barr. This software is placed into the public
652 * domain and may be used for any purpose. However,
653 * this notice must not be changed or removed and no
654 * warranty is either expressed or implied by its
655 * publication or distribution.
656 */
wdenk38635852002-08-27 05:55:31 +0000657
Simon Glass130103e2013-02-24 17:33:18 +0000658 /*
659 * Address line test
wdenk38635852002-08-27 05:55:31 +0000660
Simon Glass130103e2013-02-24 17:33:18 +0000661 * Description: Test the address bus wiring in a
662 * memory region by performing a walking
663 * 1's test on the relevant bits of the
664 * address and checking for aliasing.
665 * This test will find single-bit
666 * address failures such as stuck-high,
667 * stuck-low, and shorted pins. The base
668 * address and size of the region are
669 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000670
Simon Glass130103e2013-02-24 17:33:18 +0000671 * Notes: For best results, the selected base
672 * address should have enough LSB 0's to
673 * guarantee single address bit changes.
674 * For example, to test a 64-Kbyte
675 * region, select a base address on a
676 * 64-Kbyte boundary. Also, select the
677 * region size as a power-of-two if at
678 * all possible.
679 *
680 * Returns: 0 if the test succeeds, 1 if the test fails.
681 */
Simon Glass130103e2013-02-24 17:33:18 +0000682 pattern = (vu_long) 0xaaaaaaaa;
683 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000684
Simon Glassad02a012013-02-28 17:47:14 +0000685 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000686 /*
687 * Write the default pattern at each of the
688 * power-of-two offsets.
689 */
Simon Glassad02a012013-02-28 17:47:14 +0000690 for (offset = 1; offset < num_words; offset <<= 1)
691 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000692
693 /*
694 * Check for address bits stuck high.
695 */
696 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000697 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000698
Simon Glassad02a012013-02-28 17:47:14 +0000699 for (offset = 1; offset < num_words; offset <<= 1) {
700 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000701 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000702 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000703 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800704 start_addr + offset*sizeof(vu_long),
705 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400706 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000707 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000708 return -1;
wdenk38635852002-08-27 05:55:31 +0000709 }
Simon Glass130103e2013-02-24 17:33:18 +0000710 }
Simon Glassad02a012013-02-28 17:47:14 +0000711 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000712 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000713
Simon Glass130103e2013-02-24 17:33:18 +0000714 /*
715 * Check for addr bits stuck low or shorted.
716 */
Simon Glassad02a012013-02-28 17:47:14 +0000717 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
718 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000719
Simon Glassad02a012013-02-28 17:47:14 +0000720 for (offset = 1; offset < num_words; offset <<= 1) {
721 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000722 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000723 printf("\nFAILURE: Address bit stuck low or"
724 " shorted @ 0x%.8lx: expected 0x%.8lx,"
725 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800726 start_addr + offset*sizeof(vu_long),
727 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000728 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000729 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000730 return -1;
wdenk38635852002-08-27 05:55:31 +0000731 }
wdenk38635852002-08-27 05:55:31 +0000732 }
Simon Glassad02a012013-02-28 17:47:14 +0000733 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000734 }
wdenk38635852002-08-27 05:55:31 +0000735
Simon Glass130103e2013-02-24 17:33:18 +0000736 /*
737 * Description: Test the integrity of a physical
738 * memory device by performing an
739 * increment/decrement test over the
740 * entire region. In the process every
741 * storage bit in the device is tested
742 * as a zero and a one. The base address
743 * and the size of the region are
744 * selected by the caller.
745 *
746 * Returns: 0 if the test succeeds, 1 if the test fails.
747 */
Simon Glassad02a012013-02-28 17:47:14 +0000748 num_words++;
wdenk38635852002-08-27 05:55:31 +0000749
Simon Glass130103e2013-02-24 17:33:18 +0000750 /*
751 * Fill memory with a known pattern.
752 */
753 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
754 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000755 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000756 }
wdenk38635852002-08-27 05:55:31 +0000757
Simon Glass130103e2013-02-24 17:33:18 +0000758 /*
759 * Check each location and invert it for the second pass.
760 */
761 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
762 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000763 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000764 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000765 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000766 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800767 start_addr + offset*sizeof(vu_long),
768 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400769 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000770 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000771 return -1;
wdenk38635852002-08-27 05:55:31 +0000772 }
773
Simon Glass130103e2013-02-24 17:33:18 +0000774 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000775 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000776 }
777
778 /*
779 * Check each location for the inverted pattern and zero it.
780 */
781 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
782 WATCHDOG_RESET();
783 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000784 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000785 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000786 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000787 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800788 start_addr + offset*sizeof(vu_long),
789 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400790 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000791 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000792 return -1;
wdenk38635852002-08-27 05:55:31 +0000793 }
Simon Glassad02a012013-02-28 17:47:14 +0000794 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000795 }
Simon Glass57ee4432013-02-24 17:33:17 +0000796
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100797 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000798}
799
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100800static int compare_regions(volatile unsigned long *bufa,
801 volatile unsigned long *bufb, size_t count)
802{
803 volatile unsigned long *p1 = bufa;
804 volatile unsigned long *p2 = bufb;
805 int errs = 0;
806 size_t i;
807
808 for (i = 0; i < count; i++, p1++, p2++) {
809 if (*p1 != *p2) {
810 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
811 (unsigned long)*p1, (unsigned long)*p2,
812 *p1 ^ *p2, __ffs(*p1 ^ *p2),
813 (unsigned long)(i * sizeof(unsigned long)));
814 errs++;
815 }
816 }
817
818 return errs;
819}
820
821static ulong test_bitflip_comparison(volatile unsigned long *bufa,
822 volatile unsigned long *bufb, size_t count)
823{
824 volatile unsigned long *p1 = bufa;
825 volatile unsigned long *p2 = bufb;
826 unsigned int j, k;
827 unsigned long q;
828 size_t i;
829 int max;
830 int errs = 0;
831
832 max = sizeof(unsigned long) * 8;
833 for (k = 0; k < max; k++) {
834 q = 0x00000001L << k;
835 for (j = 0; j < 8; j++) {
836 WATCHDOG_RESET();
837 q = ~q;
838 p1 = (volatile unsigned long *)bufa;
839 p2 = (volatile unsigned long *)bufb;
840 for (i = 0; i < count; i++)
841 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
842
843 errs += compare_regions(bufa, bufb, count);
844 }
845
846 if (ctrlc())
847 return -1UL;
848 }
849
850 return errs;
851}
852
Simon Glassad02a012013-02-28 17:47:14 +0000853static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
854 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000855{
Simon Glassad02a012013-02-28 17:47:14 +0000856 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000857 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000858 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000859 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000860 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000861
Simon Glass57ee4432013-02-24 17:33:17 +0000862 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000863 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000864 if (iteration & 1) {
865 incr = -incr;
866 /*
867 * Flip the pattern each time to make lots of zeros and
868 * then, the next time, lots of ones. We decrement
869 * the "negative" patterns and increment the "positive"
870 * patterns to preserve this feature.
871 */
872 if (pattern & 0x80000000)
873 pattern = -pattern; /* complement & increment */
874 else
875 pattern = ~pattern;
876 }
Simon Glassad02a012013-02-28 17:47:14 +0000877 length = (end_addr - start_addr) / sizeof(ulong);
878 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000879 printf("\rPattern %08lX Writing..."
880 "%12s"
881 "\b\b\b\b\b\b\b\b\b\b",
882 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000883
Simon Glassad02a012013-02-28 17:47:14 +0000884 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000885 WATCHDOG_RESET();
886 *addr = val;
887 val += incr;
888 }
wdenk38635852002-08-27 05:55:31 +0000889
Simon Glass130103e2013-02-24 17:33:18 +0000890 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000891
Simon Glassad02a012013-02-28 17:47:14 +0000892 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000893 WATCHDOG_RESET();
894 readback = *addr;
895 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000896 ulong offset = addr - buf;
897
Simon Glass130103e2013-02-24 17:33:18 +0000898 printf("\nMem error @ 0x%08X: "
899 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800900 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000901 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000902 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000903 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000904 return -1;
wdenk38635852002-08-27 05:55:31 +0000905 }
Simon Glass130103e2013-02-24 17:33:18 +0000906 val += incr;
907 }
wdenk38635852002-08-27 05:55:31 +0000908
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100909 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000910}
911
912/*
913 * Perform a memory test. A more complete alternative test can be
914 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
915 * interrupted by ctrl-c or by a failure of one of the sub-tests.
916 */
917static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
918 char * const argv[])
919{
Simon Glass51075252013-02-24 17:33:20 +0000920 ulong start, end;
Michal Simek9eaf6442020-05-04 13:54:40 +0200921 vu_long scratch_space;
922 vu_long *buf, *dummy = &scratch_space;
Tom Rinib9180882015-04-07 09:38:54 -0400923 ulong iteration_limit = 0;
Stefan Roese32265fc2020-03-05 07:21:29 +0100924 ulong count = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000925 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Machekd319f592015-04-01 13:50:41 +0200926 ulong pattern = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000927 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +0000928
Pavel Machekd319f592015-04-01 13:50:41 +0200929 start = CONFIG_SYS_MEMTEST_START;
930 end = CONFIG_SYS_MEMTEST_END;
931
Simon Glass8f2c7582013-02-24 17:33:16 +0000932 if (argc > 1)
Pavel Machekd319f592015-04-01 13:50:41 +0200933 if (strict_strtoul(argv[1], 16, &start) < 0)
934 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000935
936 if (argc > 2)
Pavel Machekd319f592015-04-01 13:50:41 +0200937 if (strict_strtoul(argv[2], 16, &end) < 0)
938 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000939
940 if (argc > 3)
Pavel Machekd319f592015-04-01 13:50:41 +0200941 if (strict_strtoul(argv[3], 16, &pattern) < 0)
942 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000943
944 if (argc > 4)
Pavel Machekd319f592015-04-01 13:50:41 +0200945 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
946 return CMD_RET_USAGE;
947
948 if (end < start) {
949 printf("Refusing to do empty test\n");
950 return -1;
951 }
Simon Glass8f2c7582013-02-24 17:33:16 +0000952
Michal Simek45f8e332016-02-24 08:36:02 +0100953 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass51075252013-02-24 17:33:20 +0000954 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
955 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +0000956
Simon Glassad02a012013-02-28 17:47:14 +0000957 buf = map_sysmem(start, end - start);
Simon Glass57ee4432013-02-24 17:33:17 +0000958 for (iteration = 0;
959 !iteration_limit || iteration < iteration_limit;
960 iteration++) {
961 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +0000962 errs = -1UL;
963 break;
964 }
965
966 printf("Iteration: %6d\r", iteration + 1);
967 debug("\n");
Stefan Roese1eb8b1e2020-03-05 07:21:31 +0100968 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
Simon Glassad02a012013-02-28 17:47:14 +0000969 errs = mem_test_alt(buf, start, end, dummy);
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100970 if (errs == -1UL)
971 break;
972 count += errs;
973 errs = test_bitflip_comparison(buf,
974 buf + (end - start) / 2,
975 (end - start) /
976 sizeof(unsigned long));
Simon Glassad02a012013-02-28 17:47:14 +0000977 } else {
978 errs = mem_test_quick(buf, start, end, pattern,
979 iteration);
980 }
981 if (errs == -1UL)
982 break;
Stefan Roese32265fc2020-03-05 07:21:29 +0100983 count += errs;
Simon Glassad02a012013-02-28 17:47:14 +0000984 }
985
Stefan Roesec1d47db2020-03-05 07:21:30 +0100986 unmap_sysmem((void *)buf);
Simon Glass57ee4432013-02-24 17:33:17 +0000987
988 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +0000989 /* Memory test was aborted - write a newline to finish off */
990 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +0000991 }
Stefan Roese32265fc2020-03-05 07:21:29 +0100992 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
Simon Glass8f2c7582013-02-24 17:33:16 +0000993
Stefan Roese32265fc2020-03-05 07:21:29 +0100994 return errs != 0;
wdenk38635852002-08-27 05:55:31 +0000995}
Wolfgang Denk9d009282013-03-08 10:51:32 +0000996#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +0000997
998/* Modify memory.
999 *
1000 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001001 * mm{.b, .w, .l, .q} {addr}
1002 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001003 */
1004static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001005mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001006{
York Sun6c480012014-02-26 17:03:19 -08001007 ulong addr;
Simon Glass8927bf22019-12-28 10:45:10 -07001008#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001009 u64 i;
1010#else
1011 ulong i;
1012#endif
wdenk874ac262003-07-24 23:38:38 +00001013 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001014 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001015
Wolfgang Denk3b683112010-07-17 01:06:04 +02001016 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001017 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001018
Simon Glass09007c42014-04-10 20:01:31 -06001019 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001020 /* We use the last specified parameters, unless new ones are
1021 * entered.
1022 */
1023 addr = mm_last_addr;
1024 size = mm_last_size;
1025
1026 if ((flag & CMD_FLAG_REPEAT) == 0) {
1027 /* New command specified. Check for a size specification.
1028 * Defaults to long if no or incorrect specification.
1029 */
wdenk874ac262003-07-24 23:38:38 +00001030 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1031 return 1;
wdenk38635852002-08-27 05:55:31 +00001032
1033 /* Address is specified since argc > 1
1034 */
1035 addr = simple_strtoul(argv[1], NULL, 16);
1036 addr += base_address;
1037 }
wdenk381669a2003-06-16 23:50:08 +00001038
wdenk38635852002-08-27 05:55:31 +00001039 /* Print the address, followed by value. Then accept input for
1040 * the next value. A non-converted value exits.
1041 */
1042 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001043 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001044 printf("%08lx:", addr);
1045 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001046 printf(" %08x", *((u32 *)ptr));
Simon Glass8927bf22019-12-28 10:45:10 -07001047#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001048 else if (size == 8)
Masahiro Yamadac7570a32018-08-06 20:47:40 +09001049 printf(" %016llx", *((u64 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001050#endif
wdenk38635852002-08-27 05:55:31 +00001051 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001052 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001053 else
York Sund8a405d2014-02-12 15:55:35 -08001054 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001055
Simon Glassbe6aafc2014-04-10 20:01:27 -06001056 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001057 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1058 /* <CR> pressed as only input, don't modify current
1059 * location and move to next. "-" pressed will go back.
1060 */
1061 if (incrflag)
1062 addr += nbytes ? -size : size;
1063 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001064 /* good enough to not time out */
1065 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001066 }
1067#ifdef CONFIG_BOOT_RETRY_TIME
1068 else if (nbytes == -2) {
1069 break; /* timed out, exit the command */
1070 }
1071#endif
1072 else {
1073 char *endp;
Simon Glass8927bf22019-12-28 10:45:10 -07001074#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001075 i = simple_strtoull(console_buffer, &endp, 16);
1076#else
wdenk38635852002-08-27 05:55:31 +00001077 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001078#endif
wdenk38635852002-08-27 05:55:31 +00001079 nbytes = endp - console_buffer;
1080 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001081 /* good enough to not time out
1082 */
Simon Glass09007c42014-04-10 20:01:31 -06001083 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001084 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001085 *((u32 *)ptr) = i;
Simon Glass8927bf22019-12-28 10:45:10 -07001086#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001087 else if (size == 8)
1088 *((u64 *)ptr) = i;
1089#endif
wdenk38635852002-08-27 05:55:31 +00001090 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001091 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001092 else
York Sund8a405d2014-02-12 15:55:35 -08001093 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001094 if (incrflag)
1095 addr += size;
1096 }
1097 }
1098 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001099 if (ptr)
1100 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001101
1102 mm_last_addr = addr;
1103 mm_last_size = size;
1104 return 0;
1105}
1106
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001107#ifdef CONFIG_CMD_CRC32
1108
Kim Phillipsdc00a682012-10-29 13:34:31 +00001109static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001110{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001111 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001112 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001113 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001114
Simon Glass0bbd76f2013-02-24 20:30:22 +00001115 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001116 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001117
1118 av = argv + 1;
1119 ac = argc - 1;
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001120#ifdef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001121 if (strcmp(*av, "-v") == 0) {
Joe Hershberger5fcee9a2015-05-05 12:23:53 -05001122 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenk6203e402004-04-18 10:13:26 +00001123 av++;
1124 ac--;
wdenk6203e402004-04-18 10:13:26 +00001125 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001126#endif
wdenk6203e402004-04-18 10:13:26 +00001127
Simon Glass0bbd76f2013-02-24 20:30:22 +00001128 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001129}
wdenk6203e402004-04-18 10:13:26 +00001130
Robin Getz93d6cb02009-07-27 00:07:59 -04001131#endif
1132
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001133#ifdef CONFIG_CMD_RANDOM
1134static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1135{
1136 unsigned long addr, len;
1137 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1138 unsigned int *buf, *start;
1139 unsigned char *buf8;
1140 unsigned int i;
1141
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001142 if (argc < 3 || argc > 4)
1143 return CMD_RET_USAGE;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001144
1145 len = simple_strtoul(argv[2], NULL, 16);
1146 addr = simple_strtoul(argv[1], NULL, 16);
1147
1148 if (argc == 4) {
1149 seed = simple_strtoul(argv[3], NULL, 16);
1150 if (seed == 0) {
1151 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1152 seed = 0xDEADBEEF;
1153 }
1154 } else {
1155 seed = get_timer(0) ^ rand();
1156 }
1157
1158 srand(seed);
1159 start = map_sysmem(addr, len);
1160 buf = start;
1161 for (i = 0; i < (len / 4); i++)
1162 *buf++ = rand();
1163
1164 buf8 = (unsigned char *)buf;
1165 for (i = 0; i < (len % 4); i++)
1166 *buf8++ = rand() & 0xFF;
1167
1168 unmap_sysmem(start);
1169 printf("%lu bytes filled with random data\n", len);
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001170
1171 return CMD_RET_SUCCESS;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001172}
1173#endif
1174
wdenk57b2d802003-06-27 21:31:46 +00001175/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001176U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001177 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001178 "memory display",
Simon Glass8927bf22019-12-28 10:45:10 -07001179#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001180 "[.b, .w, .l, .q] address [# of objects]"
1181#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001182 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001183#endif
wdenk57b2d802003-06-27 21:31:46 +00001184);
1185
1186
wdenkf287a242003-07-01 21:06:45 +00001187U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001188 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001189 "memory modify (auto-incrementing address)",
Simon Glass8927bf22019-12-28 10:45:10 -07001190#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001191 "[.b, .w, .l, .q] address"
1192#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001193 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001194#endif
wdenk57b2d802003-06-27 21:31:46 +00001195);
1196
1197
wdenkf287a242003-07-01 21:06:45 +00001198U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001199 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001200 "memory modify (constant address)",
Simon Glass8927bf22019-12-28 10:45:10 -07001201#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001202 "[.b, .w, .l, .q] address"
1203#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001204 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001205#endif
wdenk57b2d802003-06-27 21:31:46 +00001206);
1207
wdenkf287a242003-07-01 21:06:45 +00001208U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001209 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001210 "memory write (fill)",
Simon Glass8927bf22019-12-28 10:45:10 -07001211#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001212 "[.b, .w, .l, .q] address value [count]"
1213#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001214 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001215#endif
wdenk57b2d802003-06-27 21:31:46 +00001216);
1217
wdenkf287a242003-07-01 21:06:45 +00001218U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001219 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001220 "memory copy",
Simon Glass8927bf22019-12-28 10:45:10 -07001221#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001222 "[.b, .w, .l, .q] source target count"
1223#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001224 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001225#endif
wdenk57b2d802003-06-27 21:31:46 +00001226);
1227
wdenkf287a242003-07-01 21:06:45 +00001228U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001229 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001230 "memory compare",
Simon Glass8927bf22019-12-28 10:45:10 -07001231#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001232 "[.b, .w, .l, .q] addr1 addr2 count"
1233#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001234 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001235#endif
wdenk57b2d802003-06-27 21:31:46 +00001236);
1237
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001238#ifdef CONFIG_CMD_CRC32
1239
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001240#ifndef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001241
wdenkf287a242003-07-01 21:06:45 +00001242U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001243 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001244 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001245 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001246);
1247
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001248#else /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001249
1250U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001251 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001252 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001253 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001254 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001255);
1256
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001257#endif /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001258
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001259#endif
1260
Simon Glasseacd14f2012-11-30 13:01:20 +00001261#ifdef CONFIG_CMD_MEMINFO
Simon Glasseacd14f2012-11-30 13:01:20 +00001262static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1263 char * const argv[])
1264{
Simon Glass320a5d42019-11-14 12:57:44 -07001265 puts("DRAM: ");
1266 print_size(gd->ram_size, "\n");
Simon Glasseacd14f2012-11-30 13:01:20 +00001267
1268 return 0;
1269}
1270#endif
1271
wdenkf287a242003-07-01 21:06:45 +00001272U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001273 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001274 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001275 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001276 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001277);
1278
wdenkf287a242003-07-01 21:06:45 +00001279U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001280 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001281 "infinite loop on address range",
Simon Glass8927bf22019-12-28 10:45:10 -07001282#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001283 "[.b, .w, .l, .q] address number_of_objects"
1284#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001285 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001286#endif
wdenk57b2d802003-06-27 21:31:46 +00001287);
wdenk64519362004-07-11 17:40:54 +00001288
1289#ifdef CONFIG_LOOPW
1290U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001291 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001292 "infinite write loop on address range",
Simon Glass8927bf22019-12-28 10:45:10 -07001293#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001294 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1295#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001296 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001297#endif
wdenk64519362004-07-11 17:40:54 +00001298);
1299#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001300
Wolfgang Denk9d009282013-03-08 10:51:32 +00001301#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001302U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001303 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001304 "simple RAM read/write test",
1305 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001306);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001307#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001308
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001309#ifdef CONFIG_CMD_MX_CYCLIC
stroesefb5e0ac2004-12-16 17:42:39 +00001310U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001311 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001312 "memory display cyclic",
Simon Glass8927bf22019-12-28 10:45:10 -07001313#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001314 "[.b, .w, .l, .q] address count delay(ms)"
1315#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001316 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001317#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001318);
1319
1320U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001321 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001322 "memory write cyclic",
Simon Glass8927bf22019-12-28 10:45:10 -07001323#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001324 "[.b, .w, .l, .q] address value delay(ms)"
1325#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001326 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001327#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001328);
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001329#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001330
1331#ifdef CONFIG_CMD_MEMINFO
1332U_BOOT_CMD(
1333 meminfo, 3, 1, do_mem_info,
1334 "display memory information",
1335 ""
1336);
1337#endif
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001338
1339#ifdef CONFIG_CMD_RANDOM
1340U_BOOT_CMD(
1341 random, 4, 0, do_random,
1342 "fill memory with random pattern",
1343 "<addr> <len> [<seed>]\n"
1344 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1345);
1346#endif