blob: 4b8738b4f036a9e12cea34962085b156f3e42380 [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 Glassdec3c012014-04-10 20:01:25 -060015#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000016#include <command.h>
wdenk381669a2003-06-16 23:50:08 +000017#ifdef CONFIG_HAS_DATAFLASH
18#include <dataflash.h>
19#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +000020#include <hash.h>
Sergei Poselenov474dbb82008-04-09 16:09:41 +020021#include <watchdog.h>
Simon Glasse6d0ca22013-02-24 17:33:15 +000022#include <asm/io.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000023#include <linux/compiler.h>
24
25DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000026
Simon Glass1c6c7252013-02-24 17:33:29 +000027#ifndef CONFIG_SYS_MEMTEST_SCRATCH
28#define CONFIG_SYS_MEMTEST_SCRATCH 0
29#endif
30
Wolfgang Denk6262d0212010-06-28 22:00:46 +020031static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000032
33/* Display values from last command.
34 * Memory modify remembered values are different from display memory.
35 */
Mike Frysinger1a4af8c2010-12-22 09:40:29 -050036static uint dp_last_addr, dp_last_size;
37static uint dp_last_length = 0x40;
38static uint mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000039
40static ulong base_address = 0;
41
42/* Memory Display
43 *
44 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080045 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000046 */
47#define DISP_LINE_LEN 16
Kim Phillipsdc00a682012-10-29 13:34:31 +000048static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000049{
wdenk874ac262003-07-24 23:38:38 +000050 ulong addr, length;
Grant Likely02a00782007-02-20 09:05:00 +010051#if defined(CONFIG_HAS_DATAFLASH)
52 ulong nbytes, linebytes;
53#endif
wdenk874ac262003-07-24 23:38:38 +000054 int size;
wdenk38635852002-08-27 05:55:31 +000055 int rc = 0;
56
57 /* We use the last specified parameters, unless new ones are
58 * entered.
59 */
60 addr = dp_last_addr;
61 size = dp_last_size;
62 length = dp_last_length;
63
Wolfgang Denk3b683112010-07-17 01:06:04 +020064 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000065 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000066
67 if ((flag & CMD_FLAG_REPEAT) == 0) {
68 /* New command specified. Check for a size specification.
69 * Defaults to long if no or incorrect specification.
70 */
wdenk874ac262003-07-24 23:38:38 +000071 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
72 return 1;
wdenk38635852002-08-27 05:55:31 +000073
74 /* Address is specified since argc > 1
75 */
76 addr = simple_strtoul(argv[1], NULL, 16);
77 addr += base_address;
78
79 /* If another parameter, it is the length to display.
80 * Length is the number of objects, not number of bytes.
81 */
82 if (argc > 2)
83 length = simple_strtoul(argv[2], NULL, 16);
84 }
85
Grant Likely02a00782007-02-20 09:05:00 +010086#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +000087 /* Print the lines.
88 *
89 * We buffer all read data, so we can make sure data is read only
90 * once, and all accesses are with the specified bus width.
91 */
92 nbytes = length * size;
93 do {
94 char linebuf[DISP_LINE_LEN];
Grant Likely02a00782007-02-20 09:05:00 +010095 void* p;
wdenk38635852002-08-27 05:55:31 +000096 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk381669a2003-06-16 23:50:08 +000097
Grant Likely02a00782007-02-20 09:05:00 +010098 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
99 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
100 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk57b2d802003-06-27 21:31:46 +0000101
wdenk38635852002-08-27 05:55:31 +0000102 nbytes -= linebytes;
Grant Likely02a00782007-02-20 09:05:00 +0100103 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000104 if (ctrlc()) {
105 rc = 1;
106 break;
107 }
108 } while (nbytes > 0);
Grant Likely02a00782007-02-20 09:05:00 +0100109#else
Mike Frysingere578d682008-02-04 19:26:56 -0500110
111# if defined(CONFIG_BLACKFIN)
112 /* See if we're trying to display L1 inst */
113 if (addr_bfin_on_chip_mem(addr)) {
114 char linebuf[DISP_LINE_LEN];
115 ulong linebytes, nbytes = length * size;
116 do {
117 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
118 memcpy(linebuf, (void *)addr, linebytes);
119 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
120
121 nbytes -= linebytes;
122 addr += linebytes;
123 if (ctrlc()) {
124 rc = 1;
125 break;
126 }
127 } while (nbytes > 0);
128 } else
129# endif
130
131 {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000132 ulong bytes = size * length;
133 const void *buf = map_sysmem(addr, bytes);
134
Mike Frysingere578d682008-02-04 19:26:56 -0500135 /* Print the lines. */
Simon Glasse6d0ca22013-02-24 17:33:15 +0000136 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
137 addr += bytes;
138 unmap_sysmem(buf);
Mike Frysingere578d682008-02-04 19:26:56 -0500139 }
Grant Likely02a00782007-02-20 09:05:00 +0100140#endif
wdenk38635852002-08-27 05:55:31 +0000141
142 dp_last_addr = addr;
143 dp_last_length = length;
144 dp_last_size = size;
145 return (rc);
146}
147
Kim Phillipsdc00a682012-10-29 13:34:31 +0000148static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000149{
150 return mod_mem (cmdtp, 1, flag, argc, argv);
151}
Kim Phillipsdc00a682012-10-29 13:34:31 +0000152static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000153{
154 return mod_mem (cmdtp, 0, flag, argc, argv);
155}
156
Kim Phillipsdc00a682012-10-29 13:34:31 +0000157static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000158{
York Sun6c480012014-02-26 17:03:19 -0800159#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
160 u64 writeval;
161#else
162 ulong writeval;
163#endif
164 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000165 int size;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000166 void *buf;
167 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000168
Wolfgang Denk3b683112010-07-17 01:06:04 +0200169 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000170 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000171
172 /* Check for size specification.
173 */
wdenk874ac262003-07-24 23:38:38 +0000174 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
175 return 1;
wdenk38635852002-08-27 05:55:31 +0000176
177 /* Address is specified since argc > 1
178 */
179 addr = simple_strtoul(argv[1], NULL, 16);
180 addr += base_address;
181
182 /* Get the value to write.
183 */
York Sun6c480012014-02-26 17:03:19 -0800184#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
185 writeval = simple_strtoull(argv[2], NULL, 16);
186#else
wdenk38635852002-08-27 05:55:31 +0000187 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800188#endif
wdenk38635852002-08-27 05:55:31 +0000189
190 /* Count ? */
191 if (argc == 4) {
192 count = simple_strtoul(argv[3], NULL, 16);
193 } else {
194 count = 1;
195 }
196
Simon Glasse6d0ca22013-02-24 17:33:15 +0000197 bytes = size * count;
198 buf = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000199 while (count-- > 0) {
200 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800201 *((u32 *)buf) = (u32)writeval;
York Sun6c480012014-02-26 17:03:19 -0800202#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
203 else if (size == 8)
204 *((u64 *)buf) = (u64)writeval;
205#endif
wdenk38635852002-08-27 05:55:31 +0000206 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800207 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000208 else
York Sund8a405d2014-02-12 15:55:35 -0800209 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000210 buf += size;
wdenk38635852002-08-27 05:55:31 +0000211 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000212 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +0000213 return 0;
214}
215
stroesefb5e0ac2004-12-16 17:42:39 +0000216#ifdef CONFIG_MX_CYCLIC
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200217int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000218{
219 int i;
220 ulong count;
221
Wolfgang Denk3b683112010-07-17 01:06:04 +0200222 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000223 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000224
225 count = simple_strtoul(argv[3], NULL, 10);
226
227 for (;;) {
228 do_mem_md (NULL, 0, 3, argv);
229
230 /* delay for <count> ms... */
231 for (i=0; i<count; i++)
232 udelay (1000);
233
234 /* check for ctrl-c to abort... */
235 if (ctrlc()) {
236 puts("Abort\n");
237 return 0;
238 }
239 }
240
241 return 0;
242}
243
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200244int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000245{
246 int i;
247 ulong count;
248
Wolfgang Denk3b683112010-07-17 01:06:04 +0200249 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000250 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000251
252 count = simple_strtoul(argv[3], NULL, 10);
253
254 for (;;) {
255 do_mem_mw (NULL, 0, 3, argv);
256
257 /* delay for <count> ms... */
258 for (i=0; i<count; i++)
259 udelay (1000);
260
261 /* check for ctrl-c to abort... */
262 if (ctrlc()) {
263 puts("Abort\n");
264 return 0;
265 }
266 }
267
268 return 0;
269}
270#endif /* CONFIG_MX_CYCLIC */
271
Kim Phillipsdc00a682012-10-29 13:34:31 +0000272static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000273{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000274 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000275 int size;
wdenk38635852002-08-27 05:55:31 +0000276 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000277 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000278 const void *buf1, *buf2, *base;
York Sun6c480012014-02-26 17:03:19 -0800279#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
280 u64 word1, word2;
281#else
282 ulong word1, word2;
283#endif
wdenk38635852002-08-27 05:55:31 +0000284
Wolfgang Denk3b683112010-07-17 01:06:04 +0200285 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000286 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000287
288 /* Check for size specification.
289 */
wdenk874ac262003-07-24 23:38:38 +0000290 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
291 return 1;
York Sun6c480012014-02-26 17:03:19 -0800292 type = size == 8 ? "double word" :
293 size == 4 ? "word" :
294 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000295
296 addr1 = simple_strtoul(argv[1], NULL, 16);
297 addr1 += base_address;
298
299 addr2 = simple_strtoul(argv[2], NULL, 16);
300 addr2 += base_address;
301
302 count = simple_strtoul(argv[3], NULL, 16);
303
wdenk381669a2003-06-16 23:50:08 +0000304#ifdef CONFIG_HAS_DATAFLASH
305 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk42c05472004-03-23 22:14:11 +0000306 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000307 return 0;
308 }
309#endif
310
Mike Frysingere578d682008-02-04 19:26:56 -0500311#ifdef CONFIG_BLACKFIN
312 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
313 puts ("Comparison with L1 instruction memory not supported.\n\r");
314 return 0;
315 }
316#endif
317
Simon Glasse6d0ca22013-02-24 17:33:15 +0000318 bytes = size * count;
319 base = buf1 = map_sysmem(addr1, bytes);
320 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000321 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000322 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800323 word1 = *(u32 *)buf1;
324 word2 = *(u32 *)buf2;
York Sun6c480012014-02-26 17:03:19 -0800325#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
326 } else if (size == 8) {
327 word1 = *(u64 *)buf1;
328 word2 = *(u64 *)buf2;
329#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000330 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800331 word1 = *(u16 *)buf1;
332 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000333 } else {
York Sund8a405d2014-02-12 15:55:35 -0800334 word1 = *(u8 *)buf1;
335 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000336 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000337 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000338 ulong offset = buf1 - base;
York Sun6c480012014-02-26 17:03:19 -0800339#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
340 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
341 type, (void *)(addr1 + offset), size, word1,
342 type, (void *)(addr2 + offset), size, word2);
343#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000344 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000345 type, (ulong)(addr1 + offset), size, word1,
346 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800347#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000348 rcode = 1;
349 break;
wdenk38635852002-08-27 05:55:31 +0000350 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000351
Simon Glasse6d0ca22013-02-24 17:33:15 +0000352 buf1 += size;
353 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200354
355 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000356 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200357 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000358 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000359 unmap_sysmem(buf1);
360 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000361
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000362 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000363 return rcode;
364}
365
Kim Phillipsdc00a682012-10-29 13:34:31 +0000366static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000367{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000368 ulong addr, dest, count, bytes;
wdenk874ac262003-07-24 23:38:38 +0000369 int size;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000370 const void *src;
371 void *buf;
wdenk38635852002-08-27 05:55:31 +0000372
Wolfgang Denk3b683112010-07-17 01:06:04 +0200373 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000374 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000375
376 /* Check for size specification.
377 */
wdenk874ac262003-07-24 23:38:38 +0000378 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
379 return 1;
wdenk38635852002-08-27 05:55:31 +0000380
381 addr = simple_strtoul(argv[1], NULL, 16);
382 addr += base_address;
383
384 dest = simple_strtoul(argv[2], NULL, 16);
385 dest += base_address;
386
387 count = simple_strtoul(argv[3], NULL, 16);
388
389 if (count == 0) {
390 puts ("Zero length ???\n");
391 return 1;
392 }
393
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200394#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000395 /* check if we are copying to Flash */
wdenk381669a2003-06-16 23:50:08 +0000396 if ( (addr2info(dest) != NULL)
397#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino1eb0fd52008-03-03 10:39:13 +0200398 && (!addr_dataflash(dest))
wdenk381669a2003-06-16 23:50:08 +0000399#endif
400 ) {
wdenk38635852002-08-27 05:55:31 +0000401 int rc;
402
wdenk42c05472004-03-23 22:14:11 +0000403 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000404
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200405 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000406 if (rc != 0) {
407 flash_perror (rc);
408 return (1);
409 }
410 puts ("done\n");
411 return 0;
412 }
413#endif
414
wdenk381669a2003-06-16 23:50:08 +0000415#ifdef CONFIG_HAS_DATAFLASH
416 /* Check if we are copying from RAM or Flash to DataFlash */
417 if (addr_dataflash(dest) && !addr_dataflash(addr)){
418 int rc;
419
wdenk42c05472004-03-23 22:14:11 +0000420 puts ("Copy to DataFlash... ");
wdenk381669a2003-06-16 23:50:08 +0000421
422 rc = write_dataflash (dest, addr, count*size);
423
424 if (rc != 1) {
425 dataflash_perror (rc);
426 return (1);
427 }
428 puts ("done\n");
429 return 0;
430 }
wdenk57b2d802003-06-27 21:31:46 +0000431
wdenk381669a2003-06-16 23:50:08 +0000432 /* Check if we are copying from DataFlash to RAM */
Stelian Popa63d2eb2008-03-26 22:52:35 +0100433 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200434#ifndef CONFIG_SYS_NO_FLASH
Stelian Popa63d2eb2008-03-26 22:52:35 +0100435 && (addr2info(dest) == NULL)
436#endif
437 ){
wdenk86765902003-12-06 23:55:10 +0000438 int rc;
439 rc = read_dataflash(addr, count * size, (char *) dest);
440 if (rc != 1) {
wdenk1ebf41e2004-01-02 14:00:00 +0000441 dataflash_perror (rc);
442 return (1);
443 }
wdenk381669a2003-06-16 23:50:08 +0000444 return 0;
445 }
446
447 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk42c05472004-03-23 22:14:11 +0000448 puts ("Unsupported combination of source/destination.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000449 return 1;
450 }
wdenk7a428cc2003-06-15 22:40:42 +0000451#endif
452
Mike Frysingere578d682008-02-04 19:26:56 -0500453#ifdef CONFIG_BLACKFIN
454 /* See if we're copying to/from L1 inst */
455 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
456 memcpy((void *)dest, (void *)addr, count * size);
457 return 0;
458 }
459#endif
460
Simon Glasse6d0ca22013-02-24 17:33:15 +0000461 bytes = size * count;
Masahiro Yamada4ad7dd52013-05-20 21:08:08 +0000462 buf = map_sysmem(dest, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +0000463 src = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000464 while (count-- > 0) {
465 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800466 *((u32 *)buf) = *((u32 *)src);
York Sun6c480012014-02-26 17:03:19 -0800467#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
468 else if (size == 8)
469 *((u64 *)buf) = *((u64 *)src);
470#endif
wdenk38635852002-08-27 05:55:31 +0000471 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800472 *((u16 *)buf) = *((u16 *)src);
wdenk38635852002-08-27 05:55:31 +0000473 else
York Sund8a405d2014-02-12 15:55:35 -0800474 *((u8 *)buf) = *((u8 *)src);
Simon Glasse6d0ca22013-02-24 17:33:15 +0000475 src += size;
476 buf += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200477
478 /* reset watchdog from time to time */
479 if ((count % (64 << 10)) == 0)
480 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000481 }
482 return 0;
483}
484
Kim Phillipsdc00a682012-10-29 13:34:31 +0000485static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
486 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000487{
488 if (argc > 1) {
489 /* Set new base address.
490 */
491 base_address = simple_strtoul(argv[1], NULL, 16);
492 }
493 /* Print the current base address.
494 */
495 printf("Base Address: 0x%08lx\n", base_address);
496 return 0;
497}
498
Kim Phillipsdc00a682012-10-29 13:34:31 +0000499static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
500 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000501{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000502 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000503 int size;
York Sun6c480012014-02-26 17:03:19 -0800504#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
505 volatile u64 *llp;
506#endif
York Sund8a405d2014-02-12 15:55:35 -0800507 volatile u32 *longp;
508 volatile u16 *shortp;
509 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000510 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000511
Wolfgang Denk3b683112010-07-17 01:06:04 +0200512 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000513 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000514
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000515 /*
516 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000517 * Defaults to long if no or incorrect specification.
518 */
wdenk874ac262003-07-24 23:38:38 +0000519 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
520 return 1;
wdenk38635852002-08-27 05:55:31 +0000521
522 /* Address is always specified.
523 */
524 addr = simple_strtoul(argv[1], NULL, 16);
525
526 /* Length is the number of objects, not number of bytes.
527 */
528 length = simple_strtoul(argv[2], NULL, 16);
529
Simon Glasse6d0ca22013-02-24 17:33:15 +0000530 bytes = size * length;
531 buf = map_sysmem(addr, bytes);
532
wdenk38635852002-08-27 05:55:31 +0000533 /* We want to optimize the loops to run as fast as possible.
534 * If we have only one object, just run infinite loops.
535 */
536 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800537#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
538 if (size == 8) {
539 llp = (u64 *)buf;
540 for (;;)
541 i = *llp;
542 }
543#endif
wdenk38635852002-08-27 05:55:31 +0000544 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800545 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000546 for (;;)
547 i = *longp;
548 }
549 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800550 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000551 for (;;)
552 i = *shortp;
553 }
York Sund8a405d2014-02-12 15:55:35 -0800554 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000555 for (;;)
556 i = *cp;
557 }
558
York Sun6c480012014-02-26 17:03:19 -0800559#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
560 if (size == 8) {
561 for (;;) {
562 llp = (u64 *)buf;
563 i = length;
564 while (i-- > 0)
565 *llp++;
566 }
567 }
568#endif
wdenk38635852002-08-27 05:55:31 +0000569 if (size == 4) {
570 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800571 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000572 i = length;
573 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200574 *longp++;
wdenk38635852002-08-27 05:55:31 +0000575 }
576 }
577 if (size == 2) {
578 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800579 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000580 i = length;
581 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200582 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000583 }
584 }
585 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800586 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000587 i = length;
588 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200589 *cp++;
wdenk38635852002-08-27 05:55:31 +0000590 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000591 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700592
593 return 0;
wdenk38635852002-08-27 05:55:31 +0000594}
595
wdenk64519362004-07-11 17:40:54 +0000596#ifdef CONFIG_LOOPW
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200597int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000598{
York Sun6c480012014-02-26 17:03:19 -0800599 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000600 int size;
York Sun6c480012014-02-26 17:03:19 -0800601#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
602 volatile u64 *llp;
603 u64 data;
604#else
605 ulong data;
606#endif
York Sund8a405d2014-02-12 15:55:35 -0800607 volatile u32 *longp;
608 volatile u16 *shortp;
609 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000610 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000611
Wolfgang Denk3b683112010-07-17 01:06:04 +0200612 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000613 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000614
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000615 /*
616 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000617 * Defaults to long if no or incorrect specification.
618 */
619 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
620 return 1;
621
622 /* Address is always specified.
623 */
624 addr = simple_strtoul(argv[1], NULL, 16);
625
626 /* Length is the number of objects, not number of bytes.
627 */
628 length = simple_strtoul(argv[2], NULL, 16);
629
630 /* data to write */
York Sun6c480012014-02-26 17:03:19 -0800631#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
632 data = simple_strtoull(argv[3], NULL, 16);
633#else
wdenk64519362004-07-11 17:40:54 +0000634 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800635#endif
wdenk7dd13292004-07-11 20:04:51 +0000636
Simon Glasse6d0ca22013-02-24 17:33:15 +0000637 bytes = size * length;
638 buf = map_sysmem(addr, bytes);
639
wdenk64519362004-07-11 17:40:54 +0000640 /* We want to optimize the loops to run as fast as possible.
641 * If we have only one object, just run infinite loops.
642 */
643 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800644#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
645 if (size == 8) {
646 llp = (u64 *)buf;
647 for (;;)
648 *llp = data;
649 }
650#endif
wdenk64519362004-07-11 17:40:54 +0000651 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800652 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000653 for (;;)
654 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800655 }
wdenk64519362004-07-11 17:40:54 +0000656 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800657 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000658 for (;;)
659 *shortp = data;
660 }
York Sund8a405d2014-02-12 15:55:35 -0800661 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000662 for (;;)
663 *cp = data;
664 }
665
York Sun6c480012014-02-26 17:03:19 -0800666#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
667 if (size == 8) {
668 for (;;) {
669 llp = (u64 *)buf;
670 i = length;
671 while (i-- > 0)
672 *llp++ = data;
673 }
674 }
675#endif
wdenk64519362004-07-11 17:40:54 +0000676 if (size == 4) {
677 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800678 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000679 i = length;
680 while (i-- > 0)
681 *longp++ = data;
682 }
683 }
684 if (size == 2) {
685 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800686 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000687 i = length;
688 while (i-- > 0)
689 *shortp++ = data;
690 }
691 }
692 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800693 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000694 i = length;
695 while (i-- > 0)
696 *cp++ = data;
697 }
698}
699#endif /* CONFIG_LOOPW */
700
Tom Rinia5f02702013-03-12 10:07:19 -0400701#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000702static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
703 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000704{
Simon Glass8f2c7582013-02-24 17:33:16 +0000705 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000706 ulong errs = 0;
707 ulong val, readback;
708 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000709 vu_long offset;
710 vu_long test_offset;
711 vu_long pattern;
712 vu_long temp;
713 vu_long anti_pattern;
714 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000715 static const ulong bitpattern[] = {
716 0x00000001, /* single bit */
717 0x00000003, /* two adjacent bits */
718 0x00000007, /* three adjacent bits */
719 0x0000000F, /* four adjacent bits */
720 0x00000005, /* two non-adjacent bits */
721 0x00000015, /* three non-adjacent bits */
722 0x00000055, /* four non-adjacent bits */
723 0xaaaaaaaa, /* alternating 1/0 */
724 };
wdenk38635852002-08-27 05:55:31 +0000725
Simon Glassad02a012013-02-28 17:47:14 +0000726 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000727
Simon Glass130103e2013-02-24 17:33:18 +0000728 /*
729 * Data line test: write a pattern to the first
730 * location, write the 1's complement to a 'parking'
731 * address (changes the state of the data bus so a
732 * floating bus doesn't give a false OK), and then
733 * read the value back. Note that we read it back
734 * into a variable because the next time we read it,
735 * it might be right (been there, tough to explain to
736 * the quality guys why it prints a failure when the
737 * "is" and "should be" are obviously the same in the
738 * error message).
739 *
740 * Rather than exhaustively testing, we test some
741 * patterns by shifting '1' bits through a field of
742 * '0's and '0' bits through a field of '1's (i.e.
743 * pattern and ~pattern).
744 */
Simon Glassad02a012013-02-28 17:47:14 +0000745 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000746 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
747 val = bitpattern[j];
748 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000749 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000750 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000751 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000752 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000753 printf("FAILURE (data line): "
754 "expected %08lx, actual %08lx\n",
755 val, readback);
756 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000757 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000758 return -1;
wdenk38635852002-08-27 05:55:31 +0000759 }
760 *addr = ~val;
761 *dummy = val;
762 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000763 if (readback != ~val) {
764 printf("FAILURE (data line): "
765 "Is %08lx, should be %08lx\n",
766 readback, ~val);
767 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000768 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000769 return -1;
wdenk38635852002-08-27 05:55:31 +0000770 }
wdenk38635852002-08-27 05:55:31 +0000771 }
Simon Glass130103e2013-02-24 17:33:18 +0000772 }
wdenk38635852002-08-27 05:55:31 +0000773
Simon Glass130103e2013-02-24 17:33:18 +0000774 /*
775 * Based on code whose Original Author and Copyright
776 * information follows: Copyright (c) 1998 by Michael
777 * Barr. This software is placed into the public
778 * domain and may be used for any purpose. However,
779 * this notice must not be changed or removed and no
780 * warranty is either expressed or implied by its
781 * publication or distribution.
782 */
wdenk38635852002-08-27 05:55:31 +0000783
Simon Glass130103e2013-02-24 17:33:18 +0000784 /*
785 * Address line test
wdenk38635852002-08-27 05:55:31 +0000786
Simon Glass130103e2013-02-24 17:33:18 +0000787 * Description: Test the address bus wiring in a
788 * memory region by performing a walking
789 * 1's test on the relevant bits of the
790 * address and checking for aliasing.
791 * This test will find single-bit
792 * address failures such as stuck-high,
793 * stuck-low, and shorted pins. The base
794 * address and size of the region are
795 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000796
Simon Glass130103e2013-02-24 17:33:18 +0000797 * Notes: For best results, the selected base
798 * address should have enough LSB 0's to
799 * guarantee single address bit changes.
800 * For example, to test a 64-Kbyte
801 * region, select a base address on a
802 * 64-Kbyte boundary. Also, select the
803 * region size as a power-of-two if at
804 * all possible.
805 *
806 * Returns: 0 if the test succeeds, 1 if the test fails.
807 */
Simon Glass130103e2013-02-24 17:33:18 +0000808 pattern = (vu_long) 0xaaaaaaaa;
809 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000810
Simon Glassad02a012013-02-28 17:47:14 +0000811 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000812 /*
813 * Write the default pattern at each of the
814 * power-of-two offsets.
815 */
Simon Glassad02a012013-02-28 17:47:14 +0000816 for (offset = 1; offset < num_words; offset <<= 1)
817 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000818
819 /*
820 * Check for address bits stuck high.
821 */
822 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000823 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000824
Simon Glassad02a012013-02-28 17:47:14 +0000825 for (offset = 1; offset < num_words; offset <<= 1) {
826 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000827 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000828 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000829 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800830 start_addr + offset*sizeof(vu_long),
831 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400832 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000833 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000834 return -1;
wdenk38635852002-08-27 05:55:31 +0000835 }
Simon Glass130103e2013-02-24 17:33:18 +0000836 }
Simon Glassad02a012013-02-28 17:47:14 +0000837 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000838 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000839
Simon Glass130103e2013-02-24 17:33:18 +0000840 /*
841 * Check for addr bits stuck low or shorted.
842 */
Simon Glassad02a012013-02-28 17:47:14 +0000843 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
844 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000845
Simon Glassad02a012013-02-28 17:47:14 +0000846 for (offset = 1; offset < num_words; offset <<= 1) {
847 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000848 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000849 printf("\nFAILURE: Address bit stuck low or"
850 " shorted @ 0x%.8lx: expected 0x%.8lx,"
851 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800852 start_addr + offset*sizeof(vu_long),
853 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000854 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000855 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000856 return -1;
wdenk38635852002-08-27 05:55:31 +0000857 }
wdenk38635852002-08-27 05:55:31 +0000858 }
Simon Glassad02a012013-02-28 17:47:14 +0000859 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000860 }
wdenk38635852002-08-27 05:55:31 +0000861
Simon Glass130103e2013-02-24 17:33:18 +0000862 /*
863 * Description: Test the integrity of a physical
864 * memory device by performing an
865 * increment/decrement test over the
866 * entire region. In the process every
867 * storage bit in the device is tested
868 * as a zero and a one. The base address
869 * and the size of the region are
870 * selected by the caller.
871 *
872 * Returns: 0 if the test succeeds, 1 if the test fails.
873 */
Simon Glassad02a012013-02-28 17:47:14 +0000874 num_words++;
wdenk38635852002-08-27 05:55:31 +0000875
Simon Glass130103e2013-02-24 17:33:18 +0000876 /*
877 * Fill memory with a known pattern.
878 */
879 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
880 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000881 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000882 }
wdenk38635852002-08-27 05:55:31 +0000883
Simon Glass130103e2013-02-24 17:33:18 +0000884 /*
885 * Check each location and invert it for the second pass.
886 */
887 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
888 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000889 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000890 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000891 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000892 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800893 start_addr + offset*sizeof(vu_long),
894 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400895 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000896 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000897 return -1;
wdenk38635852002-08-27 05:55:31 +0000898 }
899
Simon Glass130103e2013-02-24 17:33:18 +0000900 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000901 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000902 }
903
904 /*
905 * Check each location for the inverted pattern and zero it.
906 */
907 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
908 WATCHDOG_RESET();
909 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000910 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000911 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000912 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000913 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800914 start_addr + offset*sizeof(vu_long),
915 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400916 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000917 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000918 return -1;
wdenk38635852002-08-27 05:55:31 +0000919 }
Simon Glassad02a012013-02-28 17:47:14 +0000920 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000921 }
Simon Glass57ee4432013-02-24 17:33:17 +0000922
923 return 0;
Simon Glass8f2c7582013-02-24 17:33:16 +0000924}
925
Simon Glassad02a012013-02-28 17:47:14 +0000926static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
927 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000928{
Simon Glassad02a012013-02-28 17:47:14 +0000929 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000930 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000931 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000932 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000933 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000934
Simon Glass57ee4432013-02-24 17:33:17 +0000935 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000936 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000937 if (iteration & 1) {
938 incr = -incr;
939 /*
940 * Flip the pattern each time to make lots of zeros and
941 * then, the next time, lots of ones. We decrement
942 * the "negative" patterns and increment the "positive"
943 * patterns to preserve this feature.
944 */
945 if (pattern & 0x80000000)
946 pattern = -pattern; /* complement & increment */
947 else
948 pattern = ~pattern;
949 }
Simon Glassad02a012013-02-28 17:47:14 +0000950 length = (end_addr - start_addr) / sizeof(ulong);
951 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000952 printf("\rPattern %08lX Writing..."
953 "%12s"
954 "\b\b\b\b\b\b\b\b\b\b",
955 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000956
Simon Glassad02a012013-02-28 17:47:14 +0000957 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000958 WATCHDOG_RESET();
959 *addr = val;
960 val += incr;
961 }
wdenk38635852002-08-27 05:55:31 +0000962
Simon Glass130103e2013-02-24 17:33:18 +0000963 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000964
Simon Glassad02a012013-02-28 17:47:14 +0000965 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000966 WATCHDOG_RESET();
967 readback = *addr;
968 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000969 ulong offset = addr - buf;
970
Simon Glass130103e2013-02-24 17:33:18 +0000971 printf("\nMem error @ 0x%08X: "
972 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800973 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000974 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000975 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000976 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000977 return -1;
wdenk38635852002-08-27 05:55:31 +0000978 }
Simon Glass130103e2013-02-24 17:33:18 +0000979 val += incr;
980 }
wdenk38635852002-08-27 05:55:31 +0000981
Simon Glass57ee4432013-02-24 17:33:17 +0000982 return 0;
Simon Glass8f2c7582013-02-24 17:33:16 +0000983}
984
985/*
986 * Perform a memory test. A more complete alternative test can be
987 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
988 * interrupted by ctrl-c or by a failure of one of the sub-tests.
989 */
990static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
991 char * const argv[])
992{
Simon Glass51075252013-02-24 17:33:20 +0000993 ulong start, end;
Simon Glassad02a012013-02-28 17:47:14 +0000994 vu_long *buf, *dummy;
Simon Glass8f2c7582013-02-24 17:33:16 +0000995 int iteration_limit;
996 int ret;
Simon Glass57ee4432013-02-24 17:33:17 +0000997 ulong errs = 0; /* number of errors, or -1 if interrupted */
Simon Glass8f2c7582013-02-24 17:33:16 +0000998 ulong pattern;
Simon Glass57ee4432013-02-24 17:33:17 +0000999 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +00001000#if defined(CONFIG_SYS_ALT_MEMTEST)
1001 const int alt_test = 1;
1002#else
1003 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +00001004#endif
Simon Glass8f2c7582013-02-24 17:33:16 +00001005
1006 if (argc > 1)
Simon Glass51075252013-02-24 17:33:20 +00001007 start = simple_strtoul(argv[1], NULL, 16);
Simon Glass8f2c7582013-02-24 17:33:16 +00001008 else
Simon Glass51075252013-02-24 17:33:20 +00001009 start = CONFIG_SYS_MEMTEST_START;
Simon Glass8f2c7582013-02-24 17:33:16 +00001010
1011 if (argc > 2)
Simon Glass51075252013-02-24 17:33:20 +00001012 end = simple_strtoul(argv[2], NULL, 16);
Simon Glass8f2c7582013-02-24 17:33:16 +00001013 else
Simon Glass51075252013-02-24 17:33:20 +00001014 end = CONFIG_SYS_MEMTEST_END;
Simon Glass8f2c7582013-02-24 17:33:16 +00001015
1016 if (argc > 3)
1017 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
1018 else
1019 pattern = 0;
1020
1021 if (argc > 4)
1022 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
1023 else
1024 iteration_limit = 0;
1025
Simon Glass51075252013-02-24 17:33:20 +00001026 printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
1027 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1028 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +00001029
Simon Glassad02a012013-02-28 17:47:14 +00001030 buf = map_sysmem(start, end - start);
1031 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass57ee4432013-02-24 17:33:17 +00001032 for (iteration = 0;
1033 !iteration_limit || iteration < iteration_limit;
1034 iteration++) {
1035 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +00001036 errs = -1UL;
1037 break;
1038 }
1039
1040 printf("Iteration: %6d\r", iteration + 1);
1041 debug("\n");
Simon Glassad02a012013-02-28 17:47:14 +00001042 if (alt_test) {
1043 errs = mem_test_alt(buf, start, end, dummy);
1044 } else {
1045 errs = mem_test_quick(buf, start, end, pattern,
1046 iteration);
1047 }
1048 if (errs == -1UL)
1049 break;
1050 }
1051
1052 /*
1053 * Work-around for eldk-4.2 which gives this warning if we try to
1054 * case in the unmap_sysmem() call:
1055 * warning: initialization discards qualifiers from pointer target type
1056 */
1057 {
1058 void *vbuf = (void *)buf;
1059 void *vdummy = (void *)dummy;
1060
1061 unmap_sysmem(vbuf);
1062 unmap_sysmem(vdummy);
Simon Glass57ee4432013-02-24 17:33:17 +00001063 }
1064
1065 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001066 /* Memory test was aborted - write a newline to finish off */
1067 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001068 ret = 1;
1069 } else {
1070 printf("Tested %d iteration(s) with %lu errors.\n",
1071 iteration, errs);
1072 ret = errs != 0;
1073 }
Simon Glass8f2c7582013-02-24 17:33:16 +00001074
1075 return ret; /* not reached */
wdenk38635852002-08-27 05:55:31 +00001076}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001077#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001078
1079/* Modify memory.
1080 *
1081 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001082 * mm{.b, .w, .l, .q} {addr}
1083 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001084 */
1085static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001086mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001087{
York Sun6c480012014-02-26 17:03:19 -08001088 ulong addr;
1089#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1090 u64 i;
1091#else
1092 ulong i;
1093#endif
wdenk874ac262003-07-24 23:38:38 +00001094 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001095 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001096
Wolfgang Denk3b683112010-07-17 01:06:04 +02001097 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001098 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001099
1100#ifdef CONFIG_BOOT_RETRY_TIME
1101 reset_cmd_timeout(); /* got a good command to get here */
1102#endif
1103 /* We use the last specified parameters, unless new ones are
1104 * entered.
1105 */
1106 addr = mm_last_addr;
1107 size = mm_last_size;
1108
1109 if ((flag & CMD_FLAG_REPEAT) == 0) {
1110 /* New command specified. Check for a size specification.
1111 * Defaults to long if no or incorrect specification.
1112 */
wdenk874ac262003-07-24 23:38:38 +00001113 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1114 return 1;
wdenk38635852002-08-27 05:55:31 +00001115
1116 /* Address is specified since argc > 1
1117 */
1118 addr = simple_strtoul(argv[1], NULL, 16);
1119 addr += base_address;
1120 }
1121
wdenk381669a2003-06-16 23:50:08 +00001122#ifdef CONFIG_HAS_DATAFLASH
1123 if (addr_dataflash(addr)){
wdenk42c05472004-03-23 22:14:11 +00001124 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk381669a2003-06-16 23:50:08 +00001125 return 0;
1126 }
1127#endif
1128
Mike Frysingere578d682008-02-04 19:26:56 -05001129#ifdef CONFIG_BLACKFIN
1130 if (addr_bfin_on_chip_mem(addr)) {
1131 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1132 return 0;
1133 }
1134#endif
1135
wdenk38635852002-08-27 05:55:31 +00001136 /* Print the address, followed by value. Then accept input for
1137 * the next value. A non-converted value exits.
1138 */
1139 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001140 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001141 printf("%08lx:", addr);
1142 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001143 printf(" %08x", *((u32 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001144#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1145 else if (size == 8)
1146 printf(" %016llx", *((u64 *)ptr));
1147#endif
wdenk38635852002-08-27 05:55:31 +00001148 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001149 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001150 else
York Sund8a405d2014-02-12 15:55:35 -08001151 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001152
1153 nbytes = readline (" ? ");
1154 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1155 /* <CR> pressed as only input, don't modify current
1156 * location and move to next. "-" pressed will go back.
1157 */
1158 if (incrflag)
1159 addr += nbytes ? -size : size;
1160 nbytes = 1;
1161#ifdef CONFIG_BOOT_RETRY_TIME
1162 reset_cmd_timeout(); /* good enough to not time out */
1163#endif
1164 }
1165#ifdef CONFIG_BOOT_RETRY_TIME
1166 else if (nbytes == -2) {
1167 break; /* timed out, exit the command */
1168 }
1169#endif
1170 else {
1171 char *endp;
York Sun6c480012014-02-26 17:03:19 -08001172#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1173 i = simple_strtoull(console_buffer, &endp, 16);
1174#else
wdenk38635852002-08-27 05:55:31 +00001175 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001176#endif
wdenk38635852002-08-27 05:55:31 +00001177 nbytes = endp - console_buffer;
1178 if (nbytes) {
1179#ifdef CONFIG_BOOT_RETRY_TIME
1180 /* good enough to not time out
1181 */
1182 reset_cmd_timeout();
1183#endif
1184 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001185 *((u32 *)ptr) = i;
York Sun6c480012014-02-26 17:03:19 -08001186#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1187 else if (size == 8)
1188 *((u64 *)ptr) = i;
1189#endif
wdenk38635852002-08-27 05:55:31 +00001190 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001191 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001192 else
York Sund8a405d2014-02-12 15:55:35 -08001193 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001194 if (incrflag)
1195 addr += size;
1196 }
1197 }
1198 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001199 if (ptr)
1200 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001201
1202 mm_last_addr = addr;
1203 mm_last_size = size;
1204 return 0;
1205}
1206
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001207#ifdef CONFIG_CMD_CRC32
1208
Kim Phillipsdc00a682012-10-29 13:34:31 +00001209static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001210{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001211 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001212 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001213 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001214
Simon Glass0bbd76f2013-02-24 20:30:22 +00001215 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001216 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001217
1218 av = argv + 1;
1219 ac = argc - 1;
Simon Glass0bbd76f2013-02-24 20:30:22 +00001220#ifdef CONFIG_HASH_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001221 if (strcmp(*av, "-v") == 0) {
Simon Glass0bbd76f2013-02-24 20:30:22 +00001222 flags |= HASH_FLAG_VERIFY;
wdenk6203e402004-04-18 10:13:26 +00001223 av++;
1224 ac--;
wdenk6203e402004-04-18 10:13:26 +00001225 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001226#endif
wdenk6203e402004-04-18 10:13:26 +00001227
Simon Glass0bbd76f2013-02-24 20:30:22 +00001228 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001229}
wdenk6203e402004-04-18 10:13:26 +00001230
Robin Getz93d6cb02009-07-27 00:07:59 -04001231#endif
1232
wdenk57b2d802003-06-27 21:31:46 +00001233/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001234U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001235 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001236 "memory display",
York Sun6c480012014-02-26 17:03:19 -08001237#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1238 "[.b, .w, .l, .q] address [# of objects]"
1239#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001240 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001241#endif
wdenk57b2d802003-06-27 21:31:46 +00001242);
1243
1244
wdenkf287a242003-07-01 21:06:45 +00001245U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001246 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001247 "memory modify (auto-incrementing address)",
York Sun6c480012014-02-26 17:03:19 -08001248#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1249 "[.b, .w, .l, .q] address"
1250#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001251 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001252#endif
wdenk57b2d802003-06-27 21:31:46 +00001253);
1254
1255
wdenkf287a242003-07-01 21:06:45 +00001256U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001257 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001258 "memory modify (constant address)",
York Sun6c480012014-02-26 17:03:19 -08001259#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1260 "[.b, .w, .l, .q] address"
1261#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001262 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001263#endif
wdenk57b2d802003-06-27 21:31:46 +00001264);
1265
wdenkf287a242003-07-01 21:06:45 +00001266U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001267 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001268 "memory write (fill)",
York Sun6c480012014-02-26 17:03:19 -08001269#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1270 "[.b, .w, .l, .q] address value [count]"
1271#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001272 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001273#endif
wdenk57b2d802003-06-27 21:31:46 +00001274);
1275
wdenkf287a242003-07-01 21:06:45 +00001276U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001277 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001278 "memory copy",
York Sun6c480012014-02-26 17:03:19 -08001279#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1280 "[.b, .w, .l, .q] source target count"
1281#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001282 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001283#endif
wdenk57b2d802003-06-27 21:31:46 +00001284);
1285
wdenkf287a242003-07-01 21:06:45 +00001286U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001287 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001288 "memory compare",
York Sun6c480012014-02-26 17:03:19 -08001289#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1290 "[.b, .w, .l, .q] addr1 addr2 count"
1291#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001292 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001293#endif
wdenk57b2d802003-06-27 21:31:46 +00001294);
1295
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001296#ifdef CONFIG_CMD_CRC32
1297
wdenk6203e402004-04-18 10:13:26 +00001298#ifndef CONFIG_CRC32_VERIFY
1299
wdenkf287a242003-07-01 21:06:45 +00001300U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001301 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001302 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001303 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001304);
1305
wdenk6203e402004-04-18 10:13:26 +00001306#else /* CONFIG_CRC32_VERIFY */
1307
1308U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001309 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001310 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001311 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001312 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001313);
1314
1315#endif /* CONFIG_CRC32_VERIFY */
1316
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001317#endif
1318
Simon Glasseacd14f2012-11-30 13:01:20 +00001319#ifdef CONFIG_CMD_MEMINFO
1320__weak void board_show_dram(ulong size)
1321{
1322 puts("DRAM: ");
1323 print_size(size, "\n");
1324}
1325
1326static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1327 char * const argv[])
1328{
1329 board_show_dram(gd->ram_size);
1330
1331 return 0;
1332}
1333#endif
1334
wdenkf287a242003-07-01 21:06:45 +00001335U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001336 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001337 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001338 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001339 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001340);
1341
wdenkf287a242003-07-01 21:06:45 +00001342U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001343 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001344 "infinite loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001345#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1346 "[.b, .w, .l, .q] address number_of_objects"
1347#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001348 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001349#endif
wdenk57b2d802003-06-27 21:31:46 +00001350);
wdenk64519362004-07-11 17:40:54 +00001351
1352#ifdef CONFIG_LOOPW
1353U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001354 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001355 "infinite write loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001356#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1357 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1358#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001359 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001360#endif
wdenk64519362004-07-11 17:40:54 +00001361);
1362#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001363
Wolfgang Denk9d009282013-03-08 10:51:32 +00001364#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001365U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001366 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001367 "simple RAM read/write test",
1368 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001369);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001370#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001371
1372#ifdef CONFIG_MX_CYCLIC
1373U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001374 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001375 "memory display cyclic",
York Sun6c480012014-02-26 17:03:19 -08001376#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1377 "[.b, .w, .l, .q] address count delay(ms)"
1378#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001379 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001380#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001381);
1382
1383U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001384 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001385 "memory write cyclic",
York Sun6c480012014-02-26 17:03:19 -08001386#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1387 "[.b, .w, .l, .q] address value delay(ms)"
1388#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001389 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001390#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001391);
1392#endif /* CONFIG_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001393
1394#ifdef CONFIG_CMD_MEMINFO
1395U_BOOT_CMD(
1396 meminfo, 3, 1, do_mem_info,
1397 "display memory information",
1398 ""
1399);
1400#endif