blob: b6e200b97c09dca26897fcce4306ad5e5eaaa1c1 [file] [log] [blame]
wdenk38635852002-08-27 05:55:31 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00006 */
7
8/*
9 * Memory Functions
10 *
11 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
12 */
13
14#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -070015#include <console.h>
Simon Glass399ed9a2014-04-10 20:01:30 -060016#include <bootretry.h>
Simon Glassdec3c012014-04-10 20:01:25 -060017#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000018#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070019#include <console.h>
wdenk381669a2003-06-16 23:50:08 +000020#ifdef CONFIG_HAS_DATAFLASH
21#include <dataflash.h>
22#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +000023#include <hash.h>
Simon Glasse9f343f2014-11-11 12:47:07 -070024#include <inttypes.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050025#include <mapmem.h>
Sergei Poselenov474dbb82008-04-09 16:09:41 +020026#include <watchdog.h>
Simon Glasse6d0ca22013-02-24 17:33:15 +000027#include <asm/io.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000028#include <linux/compiler.h>
29
30DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000031
Simon Glass1c6c7252013-02-24 17:33:29 +000032#ifndef CONFIG_SYS_MEMTEST_SCRATCH
33#define CONFIG_SYS_MEMTEST_SCRATCH 0
34#endif
35
Wolfgang Denk6262d0212010-06-28 22:00:46 +020036static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000037
38/* Display values from last command.
39 * Memory modify remembered values are different from display memory.
40 */
Scott Wood3ec02882015-03-19 09:43:12 -070041static ulong dp_last_addr, dp_last_size;
42static ulong dp_last_length = 0x40;
43static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000044
45static ulong base_address = 0;
46
47/* Memory Display
48 *
49 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080050 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000051 */
52#define DISP_LINE_LEN 16
Kim Phillipsdc00a682012-10-29 13:34:31 +000053static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000054{
wdenk874ac262003-07-24 23:38:38 +000055 ulong addr, length;
Grant Likely02a00782007-02-20 09:05:00 +010056#if defined(CONFIG_HAS_DATAFLASH)
57 ulong nbytes, linebytes;
58#endif
wdenk874ac262003-07-24 23:38:38 +000059 int size;
wdenk38635852002-08-27 05:55:31 +000060 int rc = 0;
61
62 /* We use the last specified parameters, unless new ones are
63 * entered.
64 */
65 addr = dp_last_addr;
66 size = dp_last_size;
67 length = dp_last_length;
68
Wolfgang Denk3b683112010-07-17 01:06:04 +020069 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000070 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000071
72 if ((flag & CMD_FLAG_REPEAT) == 0) {
73 /* New command specified. Check for a size specification.
74 * Defaults to long if no or incorrect specification.
75 */
wdenk874ac262003-07-24 23:38:38 +000076 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
77 return 1;
wdenk38635852002-08-27 05:55:31 +000078
79 /* Address is specified since argc > 1
80 */
81 addr = simple_strtoul(argv[1], NULL, 16);
82 addr += base_address;
83
84 /* If another parameter, it is the length to display.
85 * Length is the number of objects, not number of bytes.
86 */
87 if (argc > 2)
88 length = simple_strtoul(argv[2], NULL, 16);
89 }
90
Grant Likely02a00782007-02-20 09:05:00 +010091#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +000092 /* Print the lines.
93 *
94 * We buffer all read data, so we can make sure data is read only
95 * once, and all accesses are with the specified bus width.
96 */
97 nbytes = length * size;
98 do {
99 char linebuf[DISP_LINE_LEN];
Grant Likely02a00782007-02-20 09:05:00 +0100100 void* p;
wdenk38635852002-08-27 05:55:31 +0000101 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk381669a2003-06-16 23:50:08 +0000102
Grant Likely02a00782007-02-20 09:05:00 +0100103 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
104 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
105 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk57b2d802003-06-27 21:31:46 +0000106
wdenk38635852002-08-27 05:55:31 +0000107 nbytes -= linebytes;
Grant Likely02a00782007-02-20 09:05:00 +0100108 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000109 if (ctrlc()) {
110 rc = 1;
111 break;
112 }
113 } while (nbytes > 0);
Grant Likely02a00782007-02-20 09:05:00 +0100114#else
Mike Frysingere578d682008-02-04 19:26:56 -0500115 {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000116 ulong bytes = size * length;
117 const void *buf = map_sysmem(addr, bytes);
118
Mike Frysingere578d682008-02-04 19:26:56 -0500119 /* Print the lines. */
Simon Glasse6d0ca22013-02-24 17:33:15 +0000120 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
121 addr += bytes;
122 unmap_sysmem(buf);
Mike Frysingere578d682008-02-04 19:26:56 -0500123 }
Grant Likely02a00782007-02-20 09:05:00 +0100124#endif
wdenk38635852002-08-27 05:55:31 +0000125
126 dp_last_addr = addr;
127 dp_last_length = length;
128 dp_last_size = size;
129 return (rc);
130}
131
Kim Phillipsdc00a682012-10-29 13:34:31 +0000132static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000133{
134 return mod_mem (cmdtp, 1, flag, argc, argv);
135}
Kim Phillipsdc00a682012-10-29 13:34:31 +0000136static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000137{
138 return mod_mem (cmdtp, 0, flag, argc, argv);
139}
140
Kim Phillipsdc00a682012-10-29 13:34:31 +0000141static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000142{
York Sun6c480012014-02-26 17:03:19 -0800143#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
144 u64 writeval;
145#else
146 ulong writeval;
147#endif
148 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000149 int size;
Simon Glass3c4a2872015-03-05 12:25:18 -0700150 void *buf, *start;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000151 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000152
Wolfgang Denk3b683112010-07-17 01:06:04 +0200153 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000154 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000155
156 /* Check for size specification.
157 */
wdenk874ac262003-07-24 23:38:38 +0000158 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
159 return 1;
wdenk38635852002-08-27 05:55:31 +0000160
161 /* Address is specified since argc > 1
162 */
163 addr = simple_strtoul(argv[1], NULL, 16);
164 addr += base_address;
165
166 /* Get the value to write.
167 */
York Sun6c480012014-02-26 17:03:19 -0800168#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
169 writeval = simple_strtoull(argv[2], NULL, 16);
170#else
wdenk38635852002-08-27 05:55:31 +0000171 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800172#endif
wdenk38635852002-08-27 05:55:31 +0000173
174 /* Count ? */
175 if (argc == 4) {
176 count = simple_strtoul(argv[3], NULL, 16);
177 } else {
178 count = 1;
179 }
180
Simon Glasse6d0ca22013-02-24 17:33:15 +0000181 bytes = size * count;
Simon Glass3c4a2872015-03-05 12:25:18 -0700182 start = map_sysmem(addr, bytes);
183 buf = start;
wdenk38635852002-08-27 05:55:31 +0000184 while (count-- > 0) {
185 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800186 *((u32 *)buf) = (u32)writeval;
York Sun6c480012014-02-26 17:03:19 -0800187#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
188 else if (size == 8)
189 *((u64 *)buf) = (u64)writeval;
190#endif
wdenk38635852002-08-27 05:55:31 +0000191 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800192 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000193 else
York Sund8a405d2014-02-12 15:55:35 -0800194 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000195 buf += size;
wdenk38635852002-08-27 05:55:31 +0000196 }
Simon Glass3c4a2872015-03-05 12:25:18 -0700197 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000198 return 0;
199}
200
stroesefb5e0ac2004-12-16 17:42:39 +0000201#ifdef CONFIG_MX_CYCLIC
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900202static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000203{
204 int i;
205 ulong count;
206
Wolfgang Denk3b683112010-07-17 01:06:04 +0200207 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000208 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000209
210 count = simple_strtoul(argv[3], NULL, 10);
211
212 for (;;) {
213 do_mem_md (NULL, 0, 3, argv);
214
215 /* delay for <count> ms... */
216 for (i=0; i<count; i++)
217 udelay (1000);
218
219 /* check for ctrl-c to abort... */
220 if (ctrlc()) {
221 puts("Abort\n");
222 return 0;
223 }
224 }
225
226 return 0;
227}
228
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900229static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000230{
231 int i;
232 ulong count;
233
Wolfgang Denk3b683112010-07-17 01:06:04 +0200234 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000235 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000236
237 count = simple_strtoul(argv[3], NULL, 10);
238
239 for (;;) {
240 do_mem_mw (NULL, 0, 3, argv);
241
242 /* delay for <count> ms... */
243 for (i=0; i<count; i++)
244 udelay (1000);
245
246 /* check for ctrl-c to abort... */
247 if (ctrlc()) {
248 puts("Abort\n");
249 return 0;
250 }
251 }
252
253 return 0;
254}
255#endif /* CONFIG_MX_CYCLIC */
256
Kim Phillipsdc00a682012-10-29 13:34:31 +0000257static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000258{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000259 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000260 int size;
wdenk38635852002-08-27 05:55:31 +0000261 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000262 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000263 const void *buf1, *buf2, *base;
York Sun6c480012014-02-26 17:03:19 -0800264#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
265 u64 word1, word2;
266#else
267 ulong word1, word2;
268#endif
wdenk38635852002-08-27 05:55:31 +0000269
Wolfgang Denk3b683112010-07-17 01:06:04 +0200270 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000271 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000272
273 /* Check for size specification.
274 */
wdenk874ac262003-07-24 23:38:38 +0000275 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
276 return 1;
York Sun6c480012014-02-26 17:03:19 -0800277 type = size == 8 ? "double word" :
278 size == 4 ? "word" :
279 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000280
281 addr1 = simple_strtoul(argv[1], NULL, 16);
282 addr1 += base_address;
283
284 addr2 = simple_strtoul(argv[2], NULL, 16);
285 addr2 += base_address;
286
287 count = simple_strtoul(argv[3], NULL, 16);
288
wdenk381669a2003-06-16 23:50:08 +0000289#ifdef CONFIG_HAS_DATAFLASH
290 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk42c05472004-03-23 22:14:11 +0000291 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000292 return 0;
293 }
294#endif
295
Simon Glasse6d0ca22013-02-24 17:33:15 +0000296 bytes = size * count;
297 base = buf1 = map_sysmem(addr1, bytes);
298 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000299 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000300 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800301 word1 = *(u32 *)buf1;
302 word2 = *(u32 *)buf2;
York Sun6c480012014-02-26 17:03:19 -0800303#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
304 } else if (size == 8) {
305 word1 = *(u64 *)buf1;
306 word2 = *(u64 *)buf2;
307#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000308 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800309 word1 = *(u16 *)buf1;
310 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000311 } else {
York Sund8a405d2014-02-12 15:55:35 -0800312 word1 = *(u8 *)buf1;
313 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000314 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000315 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000316 ulong offset = buf1 - base;
York Sun6c480012014-02-26 17:03:19 -0800317#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
Simon Glasse9f343f2014-11-11 12:47:07 -0700318 printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
319 PRIx64 ")\n",
York Sun6c480012014-02-26 17:03:19 -0800320 type, (void *)(addr1 + offset), size, word1,
321 type, (void *)(addr2 + offset), size, word2);
322#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000323 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000324 type, (ulong)(addr1 + offset), size, word1,
325 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800326#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000327 rcode = 1;
328 break;
wdenk38635852002-08-27 05:55:31 +0000329 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000330
Simon Glasse6d0ca22013-02-24 17:33:15 +0000331 buf1 += size;
332 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200333
334 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000335 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200336 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000337 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000338 unmap_sysmem(buf1);
339 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000340
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000341 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000342 return rcode;
343}
344
Kim Phillipsdc00a682012-10-29 13:34:31 +0000345static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000346{
Fabio Estevamb03b0c82016-12-15 16:00:13 -0200347 ulong addr, dest, count;
wdenk874ac262003-07-24 23:38:38 +0000348 int size;
wdenk38635852002-08-27 05:55:31 +0000349
Wolfgang Denk3b683112010-07-17 01:06:04 +0200350 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000351 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000352
353 /* Check for size specification.
354 */
wdenk874ac262003-07-24 23:38:38 +0000355 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
356 return 1;
wdenk38635852002-08-27 05:55:31 +0000357
358 addr = simple_strtoul(argv[1], NULL, 16);
359 addr += base_address;
360
361 dest = simple_strtoul(argv[2], NULL, 16);
362 dest += base_address;
363
364 count = simple_strtoul(argv[3], NULL, 16);
365
366 if (count == 0) {
367 puts ("Zero length ???\n");
368 return 1;
369 }
370
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900371#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000372 /* check if we are copying to Flash */
wdenk381669a2003-06-16 23:50:08 +0000373 if ( (addr2info(dest) != NULL)
374#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino1eb0fd52008-03-03 10:39:13 +0200375 && (!addr_dataflash(dest))
wdenk381669a2003-06-16 23:50:08 +0000376#endif
377 ) {
wdenk38635852002-08-27 05:55:31 +0000378 int rc;
379
wdenk42c05472004-03-23 22:14:11 +0000380 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000381
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200382 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000383 if (rc != 0) {
384 flash_perror (rc);
385 return (1);
386 }
387 puts ("done\n");
388 return 0;
389 }
390#endif
391
wdenk381669a2003-06-16 23:50:08 +0000392#ifdef CONFIG_HAS_DATAFLASH
393 /* Check if we are copying from RAM or Flash to DataFlash */
394 if (addr_dataflash(dest) && !addr_dataflash(addr)){
395 int rc;
396
wdenk42c05472004-03-23 22:14:11 +0000397 puts ("Copy to DataFlash... ");
wdenk381669a2003-06-16 23:50:08 +0000398
399 rc = write_dataflash (dest, addr, count*size);
400
401 if (rc != 1) {
402 dataflash_perror (rc);
403 return (1);
404 }
405 puts ("done\n");
406 return 0;
407 }
wdenk57b2d802003-06-27 21:31:46 +0000408
wdenk381669a2003-06-16 23:50:08 +0000409 /* Check if we are copying from DataFlash to RAM */
Stelian Popa63d2eb2008-03-26 22:52:35 +0100410 if (addr_dataflash(addr) && !addr_dataflash(dest)
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900411#ifdef CONFIG_MTD_NOR_FLASH
Stelian Popa63d2eb2008-03-26 22:52:35 +0100412 && (addr2info(dest) == NULL)
413#endif
414 ){
wdenk86765902003-12-06 23:55:10 +0000415 int rc;
416 rc = read_dataflash(addr, count * size, (char *) dest);
417 if (rc != 1) {
wdenk1ebf41e2004-01-02 14:00:00 +0000418 dataflash_perror (rc);
419 return (1);
420 }
wdenk381669a2003-06-16 23:50:08 +0000421 return 0;
422 }
423
424 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk42c05472004-03-23 22:14:11 +0000425 puts ("Unsupported combination of source/destination.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000426 return 1;
427 }
wdenk7a428cc2003-06-15 22:40:42 +0000428#endif
429
Fabio Estevamb03b0c82016-12-15 16:00:13 -0200430 memcpy((void *)dest, (void *)addr, count * size);
Masahiro Yamada787b0c52014-10-23 17:46:24 +0900431
wdenk38635852002-08-27 05:55:31 +0000432 return 0;
433}
434
Kim Phillipsdc00a682012-10-29 13:34:31 +0000435static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
436 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000437{
438 if (argc > 1) {
439 /* Set new base address.
440 */
441 base_address = simple_strtoul(argv[1], NULL, 16);
442 }
443 /* Print the current base address.
444 */
445 printf("Base Address: 0x%08lx\n", base_address);
446 return 0;
447}
448
Kim Phillipsdc00a682012-10-29 13:34:31 +0000449static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
450 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000451{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000452 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000453 int size;
York Sun6c480012014-02-26 17:03:19 -0800454#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
455 volatile u64 *llp;
456#endif
York Sund8a405d2014-02-12 15:55:35 -0800457 volatile u32 *longp;
458 volatile u16 *shortp;
459 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000460 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000461
Wolfgang Denk3b683112010-07-17 01:06:04 +0200462 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000463 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000464
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000465 /*
466 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000467 * Defaults to long if no or incorrect specification.
468 */
wdenk874ac262003-07-24 23:38:38 +0000469 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
470 return 1;
wdenk38635852002-08-27 05:55:31 +0000471
472 /* Address is always specified.
473 */
474 addr = simple_strtoul(argv[1], NULL, 16);
475
476 /* Length is the number of objects, not number of bytes.
477 */
478 length = simple_strtoul(argv[2], NULL, 16);
479
Simon Glasse6d0ca22013-02-24 17:33:15 +0000480 bytes = size * length;
481 buf = map_sysmem(addr, bytes);
482
wdenk38635852002-08-27 05:55:31 +0000483 /* We want to optimize the loops to run as fast as possible.
484 * If we have only one object, just run infinite loops.
485 */
486 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800487#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
488 if (size == 8) {
489 llp = (u64 *)buf;
490 for (;;)
491 i = *llp;
492 }
493#endif
wdenk38635852002-08-27 05:55:31 +0000494 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800495 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000496 for (;;)
497 i = *longp;
498 }
499 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800500 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000501 for (;;)
502 i = *shortp;
503 }
York Sund8a405d2014-02-12 15:55:35 -0800504 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000505 for (;;)
506 i = *cp;
507 }
508
York Sun6c480012014-02-26 17:03:19 -0800509#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
510 if (size == 8) {
511 for (;;) {
512 llp = (u64 *)buf;
513 i = length;
514 while (i-- > 0)
515 *llp++;
516 }
517 }
518#endif
wdenk38635852002-08-27 05:55:31 +0000519 if (size == 4) {
520 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800521 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000522 i = length;
523 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200524 *longp++;
wdenk38635852002-08-27 05:55:31 +0000525 }
526 }
527 if (size == 2) {
528 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800529 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000530 i = length;
531 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200532 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000533 }
534 }
535 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800536 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000537 i = length;
538 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200539 *cp++;
wdenk38635852002-08-27 05:55:31 +0000540 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000541 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700542
543 return 0;
wdenk38635852002-08-27 05:55:31 +0000544}
545
wdenk64519362004-07-11 17:40:54 +0000546#ifdef CONFIG_LOOPW
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900547static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
548 char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000549{
York Sun6c480012014-02-26 17:03:19 -0800550 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000551 int size;
York Sun6c480012014-02-26 17:03:19 -0800552#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
553 volatile u64 *llp;
554 u64 data;
555#else
556 ulong data;
557#endif
York Sund8a405d2014-02-12 15:55:35 -0800558 volatile u32 *longp;
559 volatile u16 *shortp;
560 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000561 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000562
Wolfgang Denk3b683112010-07-17 01:06:04 +0200563 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000564 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000565
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000566 /*
567 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000568 * Defaults to long if no or incorrect specification.
569 */
570 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
571 return 1;
572
573 /* Address is always specified.
574 */
575 addr = simple_strtoul(argv[1], NULL, 16);
576
577 /* Length is the number of objects, not number of bytes.
578 */
579 length = simple_strtoul(argv[2], NULL, 16);
580
581 /* data to write */
York Sun6c480012014-02-26 17:03:19 -0800582#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
583 data = simple_strtoull(argv[3], NULL, 16);
584#else
wdenk64519362004-07-11 17:40:54 +0000585 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800586#endif
wdenk7dd13292004-07-11 20:04:51 +0000587
Simon Glasse6d0ca22013-02-24 17:33:15 +0000588 bytes = size * length;
589 buf = map_sysmem(addr, bytes);
590
wdenk64519362004-07-11 17:40:54 +0000591 /* We want to optimize the loops to run as fast as possible.
592 * If we have only one object, just run infinite loops.
593 */
594 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800595#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
596 if (size == 8) {
597 llp = (u64 *)buf;
598 for (;;)
599 *llp = data;
600 }
601#endif
wdenk64519362004-07-11 17:40:54 +0000602 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800603 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000604 for (;;)
605 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800606 }
wdenk64519362004-07-11 17:40:54 +0000607 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800608 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000609 for (;;)
610 *shortp = data;
611 }
York Sund8a405d2014-02-12 15:55:35 -0800612 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000613 for (;;)
614 *cp = data;
615 }
616
York Sun6c480012014-02-26 17:03:19 -0800617#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
618 if (size == 8) {
619 for (;;) {
620 llp = (u64 *)buf;
621 i = length;
622 while (i-- > 0)
623 *llp++ = data;
624 }
625 }
626#endif
wdenk64519362004-07-11 17:40:54 +0000627 if (size == 4) {
628 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800629 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000630 i = length;
631 while (i-- > 0)
632 *longp++ = data;
633 }
634 }
635 if (size == 2) {
636 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800637 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000638 i = length;
639 while (i-- > 0)
640 *shortp++ = data;
641 }
642 }
643 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800644 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000645 i = length;
646 while (i-- > 0)
647 *cp++ = data;
648 }
649}
650#endif /* CONFIG_LOOPW */
651
Tom Rinia5f02702013-03-12 10:07:19 -0400652#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000653static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
654 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000655{
Simon Glass8f2c7582013-02-24 17:33:16 +0000656 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000657 ulong errs = 0;
658 ulong val, readback;
659 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000660 vu_long offset;
661 vu_long test_offset;
662 vu_long pattern;
663 vu_long temp;
664 vu_long anti_pattern;
665 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000666 static const ulong bitpattern[] = {
667 0x00000001, /* single bit */
668 0x00000003, /* two adjacent bits */
669 0x00000007, /* three adjacent bits */
670 0x0000000F, /* four adjacent bits */
671 0x00000005, /* two non-adjacent bits */
672 0x00000015, /* three non-adjacent bits */
673 0x00000055, /* four non-adjacent bits */
674 0xaaaaaaaa, /* alternating 1/0 */
675 };
wdenk38635852002-08-27 05:55:31 +0000676
Simon Glassad02a012013-02-28 17:47:14 +0000677 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000678
Simon Glass130103e2013-02-24 17:33:18 +0000679 /*
680 * Data line test: write a pattern to the first
681 * location, write the 1's complement to a 'parking'
682 * address (changes the state of the data bus so a
683 * floating bus doesn't give a false OK), and then
684 * read the value back. Note that we read it back
685 * into a variable because the next time we read it,
686 * it might be right (been there, tough to explain to
687 * the quality guys why it prints a failure when the
688 * "is" and "should be" are obviously the same in the
689 * error message).
690 *
691 * Rather than exhaustively testing, we test some
692 * patterns by shifting '1' bits through a field of
693 * '0's and '0' bits through a field of '1's (i.e.
694 * pattern and ~pattern).
695 */
Simon Glassad02a012013-02-28 17:47:14 +0000696 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000697 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
698 val = bitpattern[j];
699 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000700 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000701 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000702 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000703 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000704 printf("FAILURE (data line): "
705 "expected %08lx, actual %08lx\n",
706 val, readback);
707 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000708 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000709 return -1;
wdenk38635852002-08-27 05:55:31 +0000710 }
711 *addr = ~val;
712 *dummy = val;
713 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000714 if (readback != ~val) {
715 printf("FAILURE (data line): "
716 "Is %08lx, should be %08lx\n",
717 readback, ~val);
718 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000719 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000720 return -1;
wdenk38635852002-08-27 05:55:31 +0000721 }
wdenk38635852002-08-27 05:55:31 +0000722 }
Simon Glass130103e2013-02-24 17:33:18 +0000723 }
wdenk38635852002-08-27 05:55:31 +0000724
Simon Glass130103e2013-02-24 17:33:18 +0000725 /*
726 * Based on code whose Original Author and Copyright
727 * information follows: Copyright (c) 1998 by Michael
728 * Barr. This software is placed into the public
729 * domain and may be used for any purpose. However,
730 * this notice must not be changed or removed and no
731 * warranty is either expressed or implied by its
732 * publication or distribution.
733 */
wdenk38635852002-08-27 05:55:31 +0000734
Simon Glass130103e2013-02-24 17:33:18 +0000735 /*
736 * Address line test
wdenk38635852002-08-27 05:55:31 +0000737
Simon Glass130103e2013-02-24 17:33:18 +0000738 * Description: Test the address bus wiring in a
739 * memory region by performing a walking
740 * 1's test on the relevant bits of the
741 * address and checking for aliasing.
742 * This test will find single-bit
743 * address failures such as stuck-high,
744 * stuck-low, and shorted pins. The base
745 * address and size of the region are
746 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000747
Simon Glass130103e2013-02-24 17:33:18 +0000748 * Notes: For best results, the selected base
749 * address should have enough LSB 0's to
750 * guarantee single address bit changes.
751 * For example, to test a 64-Kbyte
752 * region, select a base address on a
753 * 64-Kbyte boundary. Also, select the
754 * region size as a power-of-two if at
755 * all possible.
756 *
757 * Returns: 0 if the test succeeds, 1 if the test fails.
758 */
Simon Glass130103e2013-02-24 17:33:18 +0000759 pattern = (vu_long) 0xaaaaaaaa;
760 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000761
Simon Glassad02a012013-02-28 17:47:14 +0000762 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000763 /*
764 * Write the default pattern at each of the
765 * power-of-two offsets.
766 */
Simon Glassad02a012013-02-28 17:47:14 +0000767 for (offset = 1; offset < num_words; offset <<= 1)
768 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000769
770 /*
771 * Check for address bits stuck high.
772 */
773 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000774 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000775
Simon Glassad02a012013-02-28 17:47:14 +0000776 for (offset = 1; offset < num_words; offset <<= 1) {
777 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000778 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000779 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000780 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800781 start_addr + offset*sizeof(vu_long),
782 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400783 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000784 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000785 return -1;
wdenk38635852002-08-27 05:55:31 +0000786 }
Simon Glass130103e2013-02-24 17:33:18 +0000787 }
Simon Glassad02a012013-02-28 17:47:14 +0000788 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000789 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000790
Simon Glass130103e2013-02-24 17:33:18 +0000791 /*
792 * Check for addr bits stuck low or shorted.
793 */
Simon Glassad02a012013-02-28 17:47:14 +0000794 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
795 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000796
Simon Glassad02a012013-02-28 17:47:14 +0000797 for (offset = 1; offset < num_words; offset <<= 1) {
798 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000799 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000800 printf("\nFAILURE: Address bit stuck low or"
801 " shorted @ 0x%.8lx: expected 0x%.8lx,"
802 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800803 start_addr + offset*sizeof(vu_long),
804 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000805 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000806 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000807 return -1;
wdenk38635852002-08-27 05:55:31 +0000808 }
wdenk38635852002-08-27 05:55:31 +0000809 }
Simon Glassad02a012013-02-28 17:47:14 +0000810 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000811 }
wdenk38635852002-08-27 05:55:31 +0000812
Simon Glass130103e2013-02-24 17:33:18 +0000813 /*
814 * Description: Test the integrity of a physical
815 * memory device by performing an
816 * increment/decrement test over the
817 * entire region. In the process every
818 * storage bit in the device is tested
819 * as a zero and a one. The base address
820 * and the size of the region are
821 * selected by the caller.
822 *
823 * Returns: 0 if the test succeeds, 1 if the test fails.
824 */
Simon Glassad02a012013-02-28 17:47:14 +0000825 num_words++;
wdenk38635852002-08-27 05:55:31 +0000826
Simon Glass130103e2013-02-24 17:33:18 +0000827 /*
828 * Fill memory with a known pattern.
829 */
830 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
831 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000832 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000833 }
wdenk38635852002-08-27 05:55:31 +0000834
Simon Glass130103e2013-02-24 17:33:18 +0000835 /*
836 * Check each location and invert it for the second pass.
837 */
838 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
839 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000840 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000841 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000842 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000843 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800844 start_addr + offset*sizeof(vu_long),
845 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400846 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000847 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000848 return -1;
wdenk38635852002-08-27 05:55:31 +0000849 }
850
Simon Glass130103e2013-02-24 17:33:18 +0000851 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000852 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000853 }
854
855 /*
856 * Check each location for the inverted pattern and zero it.
857 */
858 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
859 WATCHDOG_RESET();
860 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000861 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000862 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000863 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000864 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800865 start_addr + offset*sizeof(vu_long),
866 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400867 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000868 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000869 return -1;
wdenk38635852002-08-27 05:55:31 +0000870 }
Simon Glassad02a012013-02-28 17:47:14 +0000871 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000872 }
Simon Glass57ee4432013-02-24 17:33:17 +0000873
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100874 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000875}
876
Simon Glassad02a012013-02-28 17:47:14 +0000877static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
878 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000879{
Simon Glassad02a012013-02-28 17:47:14 +0000880 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000881 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000882 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000883 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000884 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000885
Simon Glass57ee4432013-02-24 17:33:17 +0000886 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000887 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000888 if (iteration & 1) {
889 incr = -incr;
890 /*
891 * Flip the pattern each time to make lots of zeros and
892 * then, the next time, lots of ones. We decrement
893 * the "negative" patterns and increment the "positive"
894 * patterns to preserve this feature.
895 */
896 if (pattern & 0x80000000)
897 pattern = -pattern; /* complement & increment */
898 else
899 pattern = ~pattern;
900 }
Simon Glassad02a012013-02-28 17:47:14 +0000901 length = (end_addr - start_addr) / sizeof(ulong);
902 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000903 printf("\rPattern %08lX Writing..."
904 "%12s"
905 "\b\b\b\b\b\b\b\b\b\b",
906 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000907
Simon Glassad02a012013-02-28 17:47:14 +0000908 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000909 WATCHDOG_RESET();
910 *addr = val;
911 val += incr;
912 }
wdenk38635852002-08-27 05:55:31 +0000913
Simon Glass130103e2013-02-24 17:33:18 +0000914 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000915
Simon Glassad02a012013-02-28 17:47:14 +0000916 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000917 WATCHDOG_RESET();
918 readback = *addr;
919 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000920 ulong offset = addr - buf;
921
Simon Glass130103e2013-02-24 17:33:18 +0000922 printf("\nMem error @ 0x%08X: "
923 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800924 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000925 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000926 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000927 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000928 return -1;
wdenk38635852002-08-27 05:55:31 +0000929 }
Simon Glass130103e2013-02-24 17:33:18 +0000930 val += incr;
931 }
wdenk38635852002-08-27 05:55:31 +0000932
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100933 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000934}
935
936/*
937 * Perform a memory test. A more complete alternative test can be
938 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
939 * interrupted by ctrl-c or by a failure of one of the sub-tests.
940 */
941static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
942 char * const argv[])
943{
Simon Glass51075252013-02-24 17:33:20 +0000944 ulong start, end;
Simon Glassad02a012013-02-28 17:47:14 +0000945 vu_long *buf, *dummy;
Tom Rinib9180882015-04-07 09:38:54 -0400946 ulong iteration_limit = 0;
Simon Glass8f2c7582013-02-24 17:33:16 +0000947 int ret;
Simon Glass57ee4432013-02-24 17:33:17 +0000948 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Machekd319f592015-04-01 13:50:41 +0200949 ulong pattern = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000950 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +0000951#if defined(CONFIG_SYS_ALT_MEMTEST)
952 const int alt_test = 1;
953#else
954 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +0000955#endif
Simon Glass8f2c7582013-02-24 17:33:16 +0000956
Pavel Machekd319f592015-04-01 13:50:41 +0200957 start = CONFIG_SYS_MEMTEST_START;
958 end = CONFIG_SYS_MEMTEST_END;
959
Simon Glass8f2c7582013-02-24 17:33:16 +0000960 if (argc > 1)
Pavel Machekd319f592015-04-01 13:50:41 +0200961 if (strict_strtoul(argv[1], 16, &start) < 0)
962 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000963
964 if (argc > 2)
Pavel Machekd319f592015-04-01 13:50:41 +0200965 if (strict_strtoul(argv[2], 16, &end) < 0)
966 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000967
968 if (argc > 3)
Pavel Machekd319f592015-04-01 13:50:41 +0200969 if (strict_strtoul(argv[3], 16, &pattern) < 0)
970 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000971
972 if (argc > 4)
Pavel Machekd319f592015-04-01 13:50:41 +0200973 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
974 return CMD_RET_USAGE;
975
976 if (end < start) {
977 printf("Refusing to do empty test\n");
978 return -1;
979 }
Simon Glass8f2c7582013-02-24 17:33:16 +0000980
Michal Simek45f8e332016-02-24 08:36:02 +0100981 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass51075252013-02-24 17:33:20 +0000982 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
983 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +0000984
Simon Glassad02a012013-02-28 17:47:14 +0000985 buf = map_sysmem(start, end - start);
986 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass57ee4432013-02-24 17:33:17 +0000987 for (iteration = 0;
988 !iteration_limit || iteration < iteration_limit;
989 iteration++) {
990 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +0000991 errs = -1UL;
992 break;
993 }
994
995 printf("Iteration: %6d\r", iteration + 1);
996 debug("\n");
Simon Glassad02a012013-02-28 17:47:14 +0000997 if (alt_test) {
998 errs = mem_test_alt(buf, start, end, dummy);
999 } else {
1000 errs = mem_test_quick(buf, start, end, pattern,
1001 iteration);
1002 }
1003 if (errs == -1UL)
1004 break;
1005 }
1006
1007 /*
1008 * Work-around for eldk-4.2 which gives this warning if we try to
1009 * case in the unmap_sysmem() call:
1010 * warning: initialization discards qualifiers from pointer target type
1011 */
1012 {
1013 void *vbuf = (void *)buf;
1014 void *vdummy = (void *)dummy;
1015
1016 unmap_sysmem(vbuf);
1017 unmap_sysmem(vdummy);
Simon Glass57ee4432013-02-24 17:33:17 +00001018 }
1019
1020 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001021 /* Memory test was aborted - write a newline to finish off */
1022 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001023 ret = 1;
1024 } else {
1025 printf("Tested %d iteration(s) with %lu errors.\n",
1026 iteration, errs);
1027 ret = errs != 0;
1028 }
Simon Glass8f2c7582013-02-24 17:33:16 +00001029
Pavel Machekd319f592015-04-01 13:50:41 +02001030 return ret;
wdenk38635852002-08-27 05:55:31 +00001031}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001032#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001033
1034/* Modify memory.
1035 *
1036 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001037 * mm{.b, .w, .l, .q} {addr}
1038 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001039 */
1040static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001041mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001042{
York Sun6c480012014-02-26 17:03:19 -08001043 ulong addr;
1044#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1045 u64 i;
1046#else
1047 ulong i;
1048#endif
wdenk874ac262003-07-24 23:38:38 +00001049 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001050 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001051
Wolfgang Denk3b683112010-07-17 01:06:04 +02001052 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001053 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001054
Simon Glass09007c42014-04-10 20:01:31 -06001055 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001056 /* We use the last specified parameters, unless new ones are
1057 * entered.
1058 */
1059 addr = mm_last_addr;
1060 size = mm_last_size;
1061
1062 if ((flag & CMD_FLAG_REPEAT) == 0) {
1063 /* New command specified. Check for a size specification.
1064 * Defaults to long if no or incorrect specification.
1065 */
wdenk874ac262003-07-24 23:38:38 +00001066 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1067 return 1;
wdenk38635852002-08-27 05:55:31 +00001068
1069 /* Address is specified since argc > 1
1070 */
1071 addr = simple_strtoul(argv[1], NULL, 16);
1072 addr += base_address;
1073 }
1074
wdenk381669a2003-06-16 23:50:08 +00001075#ifdef CONFIG_HAS_DATAFLASH
1076 if (addr_dataflash(addr)){
wdenk42c05472004-03-23 22:14:11 +00001077 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk381669a2003-06-16 23:50:08 +00001078 return 0;
1079 }
1080#endif
1081
wdenk38635852002-08-27 05:55:31 +00001082 /* Print the address, followed by value. Then accept input for
1083 * the next value. A non-converted value exits.
1084 */
1085 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001086 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001087 printf("%08lx:", addr);
1088 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001089 printf(" %08x", *((u32 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001090#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1091 else if (size == 8)
Simon Glasse9f343f2014-11-11 12:47:07 -07001092 printf(" %016" PRIx64, *((u64 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001093#endif
wdenk38635852002-08-27 05:55:31 +00001094 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001095 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001096 else
York Sund8a405d2014-02-12 15:55:35 -08001097 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001098
Simon Glassbe6aafc2014-04-10 20:01:27 -06001099 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001100 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1101 /* <CR> pressed as only input, don't modify current
1102 * location and move to next. "-" pressed will go back.
1103 */
1104 if (incrflag)
1105 addr += nbytes ? -size : size;
1106 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001107 /* good enough to not time out */
1108 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001109 }
1110#ifdef CONFIG_BOOT_RETRY_TIME
1111 else if (nbytes == -2) {
1112 break; /* timed out, exit the command */
1113 }
1114#endif
1115 else {
1116 char *endp;
York Sun6c480012014-02-26 17:03:19 -08001117#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1118 i = simple_strtoull(console_buffer, &endp, 16);
1119#else
wdenk38635852002-08-27 05:55:31 +00001120 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001121#endif
wdenk38635852002-08-27 05:55:31 +00001122 nbytes = endp - console_buffer;
1123 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001124 /* good enough to not time out
1125 */
Simon Glass09007c42014-04-10 20:01:31 -06001126 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001127 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001128 *((u32 *)ptr) = i;
York Sun6c480012014-02-26 17:03:19 -08001129#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1130 else if (size == 8)
1131 *((u64 *)ptr) = i;
1132#endif
wdenk38635852002-08-27 05:55:31 +00001133 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001134 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001135 else
York Sund8a405d2014-02-12 15:55:35 -08001136 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001137 if (incrflag)
1138 addr += size;
1139 }
1140 }
1141 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001142 if (ptr)
1143 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001144
1145 mm_last_addr = addr;
1146 mm_last_size = size;
1147 return 0;
1148}
1149
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001150#ifdef CONFIG_CMD_CRC32
1151
Kim Phillipsdc00a682012-10-29 13:34:31 +00001152static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001153{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001154 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001155 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001156 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001157
Simon Glass0bbd76f2013-02-24 20:30:22 +00001158 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001159 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001160
1161 av = argv + 1;
1162 ac = argc - 1;
Simon Glass0bbd76f2013-02-24 20:30:22 +00001163#ifdef CONFIG_HASH_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001164 if (strcmp(*av, "-v") == 0) {
Joe Hershberger5fcee9a2015-05-05 12:23:53 -05001165 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenk6203e402004-04-18 10:13:26 +00001166 av++;
1167 ac--;
wdenk6203e402004-04-18 10:13:26 +00001168 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001169#endif
wdenk6203e402004-04-18 10:13:26 +00001170
Simon Glass0bbd76f2013-02-24 20:30:22 +00001171 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001172}
wdenk6203e402004-04-18 10:13:26 +00001173
Robin Getz93d6cb02009-07-27 00:07:59 -04001174#endif
1175
wdenk57b2d802003-06-27 21:31:46 +00001176/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001177U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001178 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001179 "memory display",
York Sun6c480012014-02-26 17:03:19 -08001180#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1181 "[.b, .w, .l, .q] address [# of objects]"
1182#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001183 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001184#endif
wdenk57b2d802003-06-27 21:31:46 +00001185);
1186
1187
wdenkf287a242003-07-01 21:06:45 +00001188U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001189 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001190 "memory modify (auto-incrementing address)",
York Sun6c480012014-02-26 17:03:19 -08001191#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1192 "[.b, .w, .l, .q] address"
1193#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001194 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001195#endif
wdenk57b2d802003-06-27 21:31:46 +00001196);
1197
1198
wdenkf287a242003-07-01 21:06:45 +00001199U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001200 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001201 "memory modify (constant address)",
York Sun6c480012014-02-26 17:03:19 -08001202#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1203 "[.b, .w, .l, .q] address"
1204#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001205 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001206#endif
wdenk57b2d802003-06-27 21:31:46 +00001207);
1208
wdenkf287a242003-07-01 21:06:45 +00001209U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001210 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001211 "memory write (fill)",
York Sun6c480012014-02-26 17:03:19 -08001212#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1213 "[.b, .w, .l, .q] address value [count]"
1214#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001215 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001216#endif
wdenk57b2d802003-06-27 21:31:46 +00001217);
1218
wdenkf287a242003-07-01 21:06:45 +00001219U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001220 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001221 "memory copy",
York Sun6c480012014-02-26 17:03:19 -08001222#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1223 "[.b, .w, .l, .q] source target count"
1224#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001225 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001226#endif
wdenk57b2d802003-06-27 21:31:46 +00001227);
1228
wdenkf287a242003-07-01 21:06:45 +00001229U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001230 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001231 "memory compare",
York Sun6c480012014-02-26 17:03:19 -08001232#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1233 "[.b, .w, .l, .q] addr1 addr2 count"
1234#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001235 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001236#endif
wdenk57b2d802003-06-27 21:31:46 +00001237);
1238
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001239#ifdef CONFIG_CMD_CRC32
1240
Joe Hershbergerf62c1ec2015-05-05 12:23:52 -05001241#ifndef CONFIG_HASH_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001242
wdenkf287a242003-07-01 21:06:45 +00001243U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001244 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001245 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001246 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001247);
1248
Joe Hershbergerf62c1ec2015-05-05 12:23:52 -05001249#else /* CONFIG_HASH_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001250
1251U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001252 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001253 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001254 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001255 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001256);
1257
Joe Hershbergerf62c1ec2015-05-05 12:23:52 -05001258#endif /* CONFIG_HASH_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001259
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001260#endif
1261
Simon Glasseacd14f2012-11-30 13:01:20 +00001262#ifdef CONFIG_CMD_MEMINFO
Andrew Bradfordec9dbc92015-05-22 08:30:14 -04001263__weak void board_show_dram(phys_size_t size)
Simon Glasseacd14f2012-11-30 13:01:20 +00001264{
1265 puts("DRAM: ");
1266 print_size(size, "\n");
1267}
1268
1269static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1270 char * const argv[])
1271{
1272 board_show_dram(gd->ram_size);
1273
1274 return 0;
1275}
1276#endif
1277
wdenkf287a242003-07-01 21:06:45 +00001278U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001279 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001280 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001281 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001282 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001283);
1284
wdenkf287a242003-07-01 21:06:45 +00001285U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001286 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001287 "infinite loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001288#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1289 "[.b, .w, .l, .q] address number_of_objects"
1290#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001291 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001292#endif
wdenk57b2d802003-06-27 21:31:46 +00001293);
wdenk64519362004-07-11 17:40:54 +00001294
1295#ifdef CONFIG_LOOPW
1296U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001297 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001298 "infinite write loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001299#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1300 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1301#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001302 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001303#endif
wdenk64519362004-07-11 17:40:54 +00001304);
1305#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001306
Wolfgang Denk9d009282013-03-08 10:51:32 +00001307#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001308U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001309 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001310 "simple RAM read/write test",
1311 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001312);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001313#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001314
1315#ifdef CONFIG_MX_CYCLIC
1316U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001317 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001318 "memory display cyclic",
York Sun6c480012014-02-26 17:03:19 -08001319#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1320 "[.b, .w, .l, .q] address count delay(ms)"
1321#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001322 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001323#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001324);
1325
1326U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001327 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001328 "memory write cyclic",
York Sun6c480012014-02-26 17:03:19 -08001329#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1330 "[.b, .w, .l, .q] address value delay(ms)"
1331#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001332 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001333#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001334);
1335#endif /* CONFIG_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001336
1337#ifdef CONFIG_CMD_MEMINFO
1338U_BOOT_CMD(
1339 meminfo, 3, 1, do_mem_info,
1340 "display memory information",
1341 ""
1342);
1343#endif