blob: 5b03c2d5b10b97777ef972a365262eae71fe0c9a [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>
15#include <command.h>
wdenk381669a2003-06-16 23:50:08 +000016#ifdef CONFIG_HAS_DATAFLASH
17#include <dataflash.h>
18#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +000019#include <hash.h>
Sergei Poselenov474dbb82008-04-09 16:09:41 +020020#include <watchdog.h>
Simon Glasse6d0ca22013-02-24 17:33:15 +000021#include <asm/io.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000022#include <linux/compiler.h>
23
24DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000025
Simon Glass1c6c7252013-02-24 17:33:29 +000026#ifndef CONFIG_SYS_MEMTEST_SCRATCH
27#define CONFIG_SYS_MEMTEST_SCRATCH 0
28#endif
29
Wolfgang Denk6262d0212010-06-28 22:00:46 +020030static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000031
32/* Display values from last command.
33 * Memory modify remembered values are different from display memory.
34 */
Mike Frysinger1a4af8c2010-12-22 09:40:29 -050035static uint dp_last_addr, dp_last_size;
36static uint dp_last_length = 0x40;
37static uint mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000038
39static ulong base_address = 0;
40
41/* Memory Display
42 *
43 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080044 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000045 */
46#define DISP_LINE_LEN 16
Kim Phillipsdc00a682012-10-29 13:34:31 +000047static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000048{
wdenk874ac262003-07-24 23:38:38 +000049 ulong addr, length;
Grant Likely02a00782007-02-20 09:05:00 +010050#if defined(CONFIG_HAS_DATAFLASH)
51 ulong nbytes, linebytes;
52#endif
wdenk874ac262003-07-24 23:38:38 +000053 int size;
wdenk38635852002-08-27 05:55:31 +000054 int rc = 0;
55
56 /* We use the last specified parameters, unless new ones are
57 * entered.
58 */
59 addr = dp_last_addr;
60 size = dp_last_size;
61 length = dp_last_length;
62
Wolfgang Denk3b683112010-07-17 01:06:04 +020063 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000064 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000065
66 if ((flag & CMD_FLAG_REPEAT) == 0) {
67 /* New command specified. Check for a size specification.
68 * Defaults to long if no or incorrect specification.
69 */
wdenk874ac262003-07-24 23:38:38 +000070 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
71 return 1;
wdenk38635852002-08-27 05:55:31 +000072
73 /* Address is specified since argc > 1
74 */
75 addr = simple_strtoul(argv[1], NULL, 16);
76 addr += base_address;
77
78 /* If another parameter, it is the length to display.
79 * Length is the number of objects, not number of bytes.
80 */
81 if (argc > 2)
82 length = simple_strtoul(argv[2], NULL, 16);
83 }
84
Grant Likely02a00782007-02-20 09:05:00 +010085#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +000086 /* Print the lines.
87 *
88 * We buffer all read data, so we can make sure data is read only
89 * once, and all accesses are with the specified bus width.
90 */
91 nbytes = length * size;
92 do {
93 char linebuf[DISP_LINE_LEN];
Grant Likely02a00782007-02-20 09:05:00 +010094 void* p;
wdenk38635852002-08-27 05:55:31 +000095 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk381669a2003-06-16 23:50:08 +000096
Grant Likely02a00782007-02-20 09:05:00 +010097 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
98 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
99 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk57b2d802003-06-27 21:31:46 +0000100
wdenk38635852002-08-27 05:55:31 +0000101 nbytes -= linebytes;
Grant Likely02a00782007-02-20 09:05:00 +0100102 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000103 if (ctrlc()) {
104 rc = 1;
105 break;
106 }
107 } while (nbytes > 0);
Grant Likely02a00782007-02-20 09:05:00 +0100108#else
Mike Frysingere578d682008-02-04 19:26:56 -0500109
110# if defined(CONFIG_BLACKFIN)
111 /* See if we're trying to display L1 inst */
112 if (addr_bfin_on_chip_mem(addr)) {
113 char linebuf[DISP_LINE_LEN];
114 ulong linebytes, nbytes = length * size;
115 do {
116 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
117 memcpy(linebuf, (void *)addr, linebytes);
118 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
119
120 nbytes -= linebytes;
121 addr += linebytes;
122 if (ctrlc()) {
123 rc = 1;
124 break;
125 }
126 } while (nbytes > 0);
127 } else
128# endif
129
130 {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000131 ulong bytes = size * length;
132 const void *buf = map_sysmem(addr, bytes);
133
Mike Frysingere578d682008-02-04 19:26:56 -0500134 /* Print the lines. */
Simon Glasse6d0ca22013-02-24 17:33:15 +0000135 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
136 addr += bytes;
137 unmap_sysmem(buf);
Mike Frysingere578d682008-02-04 19:26:56 -0500138 }
Grant Likely02a00782007-02-20 09:05:00 +0100139#endif
wdenk38635852002-08-27 05:55:31 +0000140
141 dp_last_addr = addr;
142 dp_last_length = length;
143 dp_last_size = size;
144 return (rc);
145}
146
Kim Phillipsdc00a682012-10-29 13:34:31 +0000147static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000148{
149 return mod_mem (cmdtp, 1, flag, argc, argv);
150}
Kim Phillipsdc00a682012-10-29 13:34:31 +0000151static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000152{
153 return mod_mem (cmdtp, 0, flag, argc, argv);
154}
155
Kim Phillipsdc00a682012-10-29 13:34:31 +0000156static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000157{
York Sun6c480012014-02-26 17:03:19 -0800158#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
159 u64 writeval;
160#else
161 ulong writeval;
162#endif
163 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000164 int size;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000165 void *buf;
166 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000167
Wolfgang Denk3b683112010-07-17 01:06:04 +0200168 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000169 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000170
171 /* Check for size specification.
172 */
wdenk874ac262003-07-24 23:38:38 +0000173 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
174 return 1;
wdenk38635852002-08-27 05:55:31 +0000175
176 /* Address is specified since argc > 1
177 */
178 addr = simple_strtoul(argv[1], NULL, 16);
179 addr += base_address;
180
181 /* Get the value to write.
182 */
York Sun6c480012014-02-26 17:03:19 -0800183#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
184 writeval = simple_strtoull(argv[2], NULL, 16);
185#else
wdenk38635852002-08-27 05:55:31 +0000186 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800187#endif
wdenk38635852002-08-27 05:55:31 +0000188
189 /* Count ? */
190 if (argc == 4) {
191 count = simple_strtoul(argv[3], NULL, 16);
192 } else {
193 count = 1;
194 }
195
Simon Glasse6d0ca22013-02-24 17:33:15 +0000196 bytes = size * count;
197 buf = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000198 while (count-- > 0) {
199 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800200 *((u32 *)buf) = (u32)writeval;
York Sun6c480012014-02-26 17:03:19 -0800201#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
202 else if (size == 8)
203 *((u64 *)buf) = (u64)writeval;
204#endif
wdenk38635852002-08-27 05:55:31 +0000205 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800206 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000207 else
York Sund8a405d2014-02-12 15:55:35 -0800208 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000209 buf += size;
wdenk38635852002-08-27 05:55:31 +0000210 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000211 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +0000212 return 0;
213}
214
stroesefb5e0ac2004-12-16 17:42:39 +0000215#ifdef CONFIG_MX_CYCLIC
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200216int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000217{
218 int i;
219 ulong count;
220
Wolfgang Denk3b683112010-07-17 01:06:04 +0200221 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000222 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000223
224 count = simple_strtoul(argv[3], NULL, 10);
225
226 for (;;) {
227 do_mem_md (NULL, 0, 3, argv);
228
229 /* delay for <count> ms... */
230 for (i=0; i<count; i++)
231 udelay (1000);
232
233 /* check for ctrl-c to abort... */
234 if (ctrlc()) {
235 puts("Abort\n");
236 return 0;
237 }
238 }
239
240 return 0;
241}
242
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200243int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000244{
245 int i;
246 ulong count;
247
Wolfgang Denk3b683112010-07-17 01:06:04 +0200248 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000249 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000250
251 count = simple_strtoul(argv[3], NULL, 10);
252
253 for (;;) {
254 do_mem_mw (NULL, 0, 3, argv);
255
256 /* delay for <count> ms... */
257 for (i=0; i<count; i++)
258 udelay (1000);
259
260 /* check for ctrl-c to abort... */
261 if (ctrlc()) {
262 puts("Abort\n");
263 return 0;
264 }
265 }
266
267 return 0;
268}
269#endif /* CONFIG_MX_CYCLIC */
270
Kim Phillipsdc00a682012-10-29 13:34:31 +0000271static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000272{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000273 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000274 int size;
wdenk38635852002-08-27 05:55:31 +0000275 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000276 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000277 const void *buf1, *buf2, *base;
York Sun6c480012014-02-26 17:03:19 -0800278#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
279 u64 word1, word2;
280#else
281 ulong word1, word2;
282#endif
wdenk38635852002-08-27 05:55:31 +0000283
Wolfgang Denk3b683112010-07-17 01:06:04 +0200284 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000285 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000286
287 /* Check for size specification.
288 */
wdenk874ac262003-07-24 23:38:38 +0000289 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
290 return 1;
York Sun6c480012014-02-26 17:03:19 -0800291 type = size == 8 ? "double word" :
292 size == 4 ? "word" :
293 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000294
295 addr1 = simple_strtoul(argv[1], NULL, 16);
296 addr1 += base_address;
297
298 addr2 = simple_strtoul(argv[2], NULL, 16);
299 addr2 += base_address;
300
301 count = simple_strtoul(argv[3], NULL, 16);
302
wdenk381669a2003-06-16 23:50:08 +0000303#ifdef CONFIG_HAS_DATAFLASH
304 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk42c05472004-03-23 22:14:11 +0000305 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000306 return 0;
307 }
308#endif
309
Mike Frysingere578d682008-02-04 19:26:56 -0500310#ifdef CONFIG_BLACKFIN
311 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
312 puts ("Comparison with L1 instruction memory not supported.\n\r");
313 return 0;
314 }
315#endif
316
Simon Glasse6d0ca22013-02-24 17:33:15 +0000317 bytes = size * count;
318 base = buf1 = map_sysmem(addr1, bytes);
319 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000320 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000321 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800322 word1 = *(u32 *)buf1;
323 word2 = *(u32 *)buf2;
York Sun6c480012014-02-26 17:03:19 -0800324#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
325 } else if (size == 8) {
326 word1 = *(u64 *)buf1;
327 word2 = *(u64 *)buf2;
328#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000329 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800330 word1 = *(u16 *)buf1;
331 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000332 } else {
York Sund8a405d2014-02-12 15:55:35 -0800333 word1 = *(u8 *)buf1;
334 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000335 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000336 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000337 ulong offset = buf1 - base;
York Sun6c480012014-02-26 17:03:19 -0800338#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
339 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
340 type, (void *)(addr1 + offset), size, word1,
341 type, (void *)(addr2 + offset), size, word2);
342#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000343 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000344 type, (ulong)(addr1 + offset), size, word1,
345 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800346#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000347 rcode = 1;
348 break;
wdenk38635852002-08-27 05:55:31 +0000349 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000350
Simon Glasse6d0ca22013-02-24 17:33:15 +0000351 buf1 += size;
352 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200353
354 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000355 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200356 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000357 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000358 unmap_sysmem(buf1);
359 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000360
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000361 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000362 return rcode;
363}
364
Kim Phillipsdc00a682012-10-29 13:34:31 +0000365static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000366{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000367 ulong addr, dest, count, bytes;
wdenk874ac262003-07-24 23:38:38 +0000368 int size;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000369 const void *src;
370 void *buf;
wdenk38635852002-08-27 05:55:31 +0000371
Wolfgang Denk3b683112010-07-17 01:06:04 +0200372 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000373 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000374
375 /* Check for size specification.
376 */
wdenk874ac262003-07-24 23:38:38 +0000377 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
378 return 1;
wdenk38635852002-08-27 05:55:31 +0000379
380 addr = simple_strtoul(argv[1], NULL, 16);
381 addr += base_address;
382
383 dest = simple_strtoul(argv[2], NULL, 16);
384 dest += base_address;
385
386 count = simple_strtoul(argv[3], NULL, 16);
387
388 if (count == 0) {
389 puts ("Zero length ???\n");
390 return 1;
391 }
392
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200393#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000394 /* check if we are copying to Flash */
wdenk381669a2003-06-16 23:50:08 +0000395 if ( (addr2info(dest) != NULL)
396#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino1eb0fd52008-03-03 10:39:13 +0200397 && (!addr_dataflash(dest))
wdenk381669a2003-06-16 23:50:08 +0000398#endif
399 ) {
wdenk38635852002-08-27 05:55:31 +0000400 int rc;
401
wdenk42c05472004-03-23 22:14:11 +0000402 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000403
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200404 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000405 if (rc != 0) {
406 flash_perror (rc);
407 return (1);
408 }
409 puts ("done\n");
410 return 0;
411 }
412#endif
413
wdenk381669a2003-06-16 23:50:08 +0000414#ifdef CONFIG_HAS_DATAFLASH
415 /* Check if we are copying from RAM or Flash to DataFlash */
416 if (addr_dataflash(dest) && !addr_dataflash(addr)){
417 int rc;
418
wdenk42c05472004-03-23 22:14:11 +0000419 puts ("Copy to DataFlash... ");
wdenk381669a2003-06-16 23:50:08 +0000420
421 rc = write_dataflash (dest, addr, count*size);
422
423 if (rc != 1) {
424 dataflash_perror (rc);
425 return (1);
426 }
427 puts ("done\n");
428 return 0;
429 }
wdenk57b2d802003-06-27 21:31:46 +0000430
wdenk381669a2003-06-16 23:50:08 +0000431 /* Check if we are copying from DataFlash to RAM */
Stelian Popa63d2eb2008-03-26 22:52:35 +0100432 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200433#ifndef CONFIG_SYS_NO_FLASH
Stelian Popa63d2eb2008-03-26 22:52:35 +0100434 && (addr2info(dest) == NULL)
435#endif
436 ){
wdenk86765902003-12-06 23:55:10 +0000437 int rc;
438 rc = read_dataflash(addr, count * size, (char *) dest);
439 if (rc != 1) {
wdenk1ebf41e2004-01-02 14:00:00 +0000440 dataflash_perror (rc);
441 return (1);
442 }
wdenk381669a2003-06-16 23:50:08 +0000443 return 0;
444 }
445
446 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk42c05472004-03-23 22:14:11 +0000447 puts ("Unsupported combination of source/destination.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000448 return 1;
449 }
wdenk7a428cc2003-06-15 22:40:42 +0000450#endif
451
Mike Frysingere578d682008-02-04 19:26:56 -0500452#ifdef CONFIG_BLACKFIN
453 /* See if we're copying to/from L1 inst */
454 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
455 memcpy((void *)dest, (void *)addr, count * size);
456 return 0;
457 }
458#endif
459
Simon Glasse6d0ca22013-02-24 17:33:15 +0000460 bytes = size * count;
Masahiro Yamada4ad7dd52013-05-20 21:08:08 +0000461 buf = map_sysmem(dest, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +0000462 src = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000463 while (count-- > 0) {
464 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800465 *((u32 *)buf) = *((u32 *)src);
York Sun6c480012014-02-26 17:03:19 -0800466#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
467 else if (size == 8)
468 *((u64 *)buf) = *((u64 *)src);
469#endif
wdenk38635852002-08-27 05:55:31 +0000470 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800471 *((u16 *)buf) = *((u16 *)src);
wdenk38635852002-08-27 05:55:31 +0000472 else
York Sund8a405d2014-02-12 15:55:35 -0800473 *((u8 *)buf) = *((u8 *)src);
Simon Glasse6d0ca22013-02-24 17:33:15 +0000474 src += size;
475 buf += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200476
477 /* reset watchdog from time to time */
478 if ((count % (64 << 10)) == 0)
479 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000480 }
481 return 0;
482}
483
Kim Phillipsdc00a682012-10-29 13:34:31 +0000484static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
485 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000486{
487 if (argc > 1) {
488 /* Set new base address.
489 */
490 base_address = simple_strtoul(argv[1], NULL, 16);
491 }
492 /* Print the current base address.
493 */
494 printf("Base Address: 0x%08lx\n", base_address);
495 return 0;
496}
497
Kim Phillipsdc00a682012-10-29 13:34:31 +0000498static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
499 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000500{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000501 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000502 int size;
York Sun6c480012014-02-26 17:03:19 -0800503#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
504 volatile u64 *llp;
505#endif
York Sund8a405d2014-02-12 15:55:35 -0800506 volatile u32 *longp;
507 volatile u16 *shortp;
508 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000509 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000510
Wolfgang Denk3b683112010-07-17 01:06:04 +0200511 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000512 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000513
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000514 /*
515 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000516 * Defaults to long if no or incorrect specification.
517 */
wdenk874ac262003-07-24 23:38:38 +0000518 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
519 return 1;
wdenk38635852002-08-27 05:55:31 +0000520
521 /* Address is always specified.
522 */
523 addr = simple_strtoul(argv[1], NULL, 16);
524
525 /* Length is the number of objects, not number of bytes.
526 */
527 length = simple_strtoul(argv[2], NULL, 16);
528
Simon Glasse6d0ca22013-02-24 17:33:15 +0000529 bytes = size * length;
530 buf = map_sysmem(addr, bytes);
531
wdenk38635852002-08-27 05:55:31 +0000532 /* We want to optimize the loops to run as fast as possible.
533 * If we have only one object, just run infinite loops.
534 */
535 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800536#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
537 if (size == 8) {
538 llp = (u64 *)buf;
539 for (;;)
540 i = *llp;
541 }
542#endif
wdenk38635852002-08-27 05:55:31 +0000543 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800544 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000545 for (;;)
546 i = *longp;
547 }
548 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800549 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000550 for (;;)
551 i = *shortp;
552 }
York Sund8a405d2014-02-12 15:55:35 -0800553 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000554 for (;;)
555 i = *cp;
556 }
557
York Sun6c480012014-02-26 17:03:19 -0800558#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
559 if (size == 8) {
560 for (;;) {
561 llp = (u64 *)buf;
562 i = length;
563 while (i-- > 0)
564 *llp++;
565 }
566 }
567#endif
wdenk38635852002-08-27 05:55:31 +0000568 if (size == 4) {
569 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800570 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000571 i = length;
572 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200573 *longp++;
wdenk38635852002-08-27 05:55:31 +0000574 }
575 }
576 if (size == 2) {
577 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800578 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000579 i = length;
580 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200581 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000582 }
583 }
584 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800585 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000586 i = length;
587 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200588 *cp++;
wdenk38635852002-08-27 05:55:31 +0000589 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000590 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700591
592 return 0;
wdenk38635852002-08-27 05:55:31 +0000593}
594
wdenk64519362004-07-11 17:40:54 +0000595#ifdef CONFIG_LOOPW
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200596int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000597{
York Sun6c480012014-02-26 17:03:19 -0800598 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000599 int size;
York Sun6c480012014-02-26 17:03:19 -0800600#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
601 volatile u64 *llp;
602 u64 data;
603#else
604 ulong data;
605#endif
York Sund8a405d2014-02-12 15:55:35 -0800606 volatile u32 *longp;
607 volatile u16 *shortp;
608 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000609 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000610
Wolfgang Denk3b683112010-07-17 01:06:04 +0200611 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000612 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000613
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000614 /*
615 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000616 * Defaults to long if no or incorrect specification.
617 */
618 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
619 return 1;
620
621 /* Address is always specified.
622 */
623 addr = simple_strtoul(argv[1], NULL, 16);
624
625 /* Length is the number of objects, not number of bytes.
626 */
627 length = simple_strtoul(argv[2], NULL, 16);
628
629 /* data to write */
York Sun6c480012014-02-26 17:03:19 -0800630#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
631 data = simple_strtoull(argv[3], NULL, 16);
632#else
wdenk64519362004-07-11 17:40:54 +0000633 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800634#endif
wdenk7dd13292004-07-11 20:04:51 +0000635
Simon Glasse6d0ca22013-02-24 17:33:15 +0000636 bytes = size * length;
637 buf = map_sysmem(addr, bytes);
638
wdenk64519362004-07-11 17:40:54 +0000639 /* We want to optimize the loops to run as fast as possible.
640 * If we have only one object, just run infinite loops.
641 */
642 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800643#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
644 if (size == 8) {
645 llp = (u64 *)buf;
646 for (;;)
647 *llp = data;
648 }
649#endif
wdenk64519362004-07-11 17:40:54 +0000650 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800651 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000652 for (;;)
653 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800654 }
wdenk64519362004-07-11 17:40:54 +0000655 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800656 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000657 for (;;)
658 *shortp = data;
659 }
York Sund8a405d2014-02-12 15:55:35 -0800660 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000661 for (;;)
662 *cp = data;
663 }
664
York Sun6c480012014-02-26 17:03:19 -0800665#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
666 if (size == 8) {
667 for (;;) {
668 llp = (u64 *)buf;
669 i = length;
670 while (i-- > 0)
671 *llp++ = data;
672 }
673 }
674#endif
wdenk64519362004-07-11 17:40:54 +0000675 if (size == 4) {
676 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800677 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000678 i = length;
679 while (i-- > 0)
680 *longp++ = data;
681 }
682 }
683 if (size == 2) {
684 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800685 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000686 i = length;
687 while (i-- > 0)
688 *shortp++ = data;
689 }
690 }
691 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800692 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000693 i = length;
694 while (i-- > 0)
695 *cp++ = data;
696 }
697}
698#endif /* CONFIG_LOOPW */
699
Tom Rinia5f02702013-03-12 10:07:19 -0400700#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000701static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
702 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000703{
Simon Glass8f2c7582013-02-24 17:33:16 +0000704 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000705 ulong errs = 0;
706 ulong val, readback;
707 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000708 vu_long offset;
709 vu_long test_offset;
710 vu_long pattern;
711 vu_long temp;
712 vu_long anti_pattern;
713 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000714 static const ulong bitpattern[] = {
715 0x00000001, /* single bit */
716 0x00000003, /* two adjacent bits */
717 0x00000007, /* three adjacent bits */
718 0x0000000F, /* four adjacent bits */
719 0x00000005, /* two non-adjacent bits */
720 0x00000015, /* three non-adjacent bits */
721 0x00000055, /* four non-adjacent bits */
722 0xaaaaaaaa, /* alternating 1/0 */
723 };
wdenk38635852002-08-27 05:55:31 +0000724
Simon Glassad02a012013-02-28 17:47:14 +0000725 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000726
Simon Glass130103e2013-02-24 17:33:18 +0000727 /*
728 * Data line test: write a pattern to the first
729 * location, write the 1's complement to a 'parking'
730 * address (changes the state of the data bus so a
731 * floating bus doesn't give a false OK), and then
732 * read the value back. Note that we read it back
733 * into a variable because the next time we read it,
734 * it might be right (been there, tough to explain to
735 * the quality guys why it prints a failure when the
736 * "is" and "should be" are obviously the same in the
737 * error message).
738 *
739 * Rather than exhaustively testing, we test some
740 * patterns by shifting '1' bits through a field of
741 * '0's and '0' bits through a field of '1's (i.e.
742 * pattern and ~pattern).
743 */
Simon Glassad02a012013-02-28 17:47:14 +0000744 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000745 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
746 val = bitpattern[j];
747 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000748 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000749 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000750 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000751 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000752 printf("FAILURE (data line): "
753 "expected %08lx, actual %08lx\n",
754 val, readback);
755 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000756 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000757 return -1;
wdenk38635852002-08-27 05:55:31 +0000758 }
759 *addr = ~val;
760 *dummy = val;
761 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000762 if (readback != ~val) {
763 printf("FAILURE (data line): "
764 "Is %08lx, should be %08lx\n",
765 readback, ~val);
766 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000767 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000768 return -1;
wdenk38635852002-08-27 05:55:31 +0000769 }
wdenk38635852002-08-27 05:55:31 +0000770 }
Simon Glass130103e2013-02-24 17:33:18 +0000771 }
wdenk38635852002-08-27 05:55:31 +0000772
Simon Glass130103e2013-02-24 17:33:18 +0000773 /*
774 * Based on code whose Original Author and Copyright
775 * information follows: Copyright (c) 1998 by Michael
776 * Barr. This software is placed into the public
777 * domain and may be used for any purpose. However,
778 * this notice must not be changed or removed and no
779 * warranty is either expressed or implied by its
780 * publication or distribution.
781 */
wdenk38635852002-08-27 05:55:31 +0000782
Simon Glass130103e2013-02-24 17:33:18 +0000783 /*
784 * Address line test
wdenk38635852002-08-27 05:55:31 +0000785
Simon Glass130103e2013-02-24 17:33:18 +0000786 * Description: Test the address bus wiring in a
787 * memory region by performing a walking
788 * 1's test on the relevant bits of the
789 * address and checking for aliasing.
790 * This test will find single-bit
791 * address failures such as stuck-high,
792 * stuck-low, and shorted pins. The base
793 * address and size of the region are
794 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000795
Simon Glass130103e2013-02-24 17:33:18 +0000796 * Notes: For best results, the selected base
797 * address should have enough LSB 0's to
798 * guarantee single address bit changes.
799 * For example, to test a 64-Kbyte
800 * region, select a base address on a
801 * 64-Kbyte boundary. Also, select the
802 * region size as a power-of-two if at
803 * all possible.
804 *
805 * Returns: 0 if the test succeeds, 1 if the test fails.
806 */
Simon Glass130103e2013-02-24 17:33:18 +0000807 pattern = (vu_long) 0xaaaaaaaa;
808 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000809
Simon Glassad02a012013-02-28 17:47:14 +0000810 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000811 /*
812 * Write the default pattern at each of the
813 * power-of-two offsets.
814 */
Simon Glassad02a012013-02-28 17:47:14 +0000815 for (offset = 1; offset < num_words; offset <<= 1)
816 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000817
818 /*
819 * Check for address bits stuck high.
820 */
821 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000822 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000823
Simon Glassad02a012013-02-28 17:47:14 +0000824 for (offset = 1; offset < num_words; offset <<= 1) {
825 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000826 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000827 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000828 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800829 start_addr + offset*sizeof(vu_long),
830 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400831 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000832 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000833 return -1;
wdenk38635852002-08-27 05:55:31 +0000834 }
Simon Glass130103e2013-02-24 17:33:18 +0000835 }
Simon Glassad02a012013-02-28 17:47:14 +0000836 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000837 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000838
Simon Glass130103e2013-02-24 17:33:18 +0000839 /*
840 * Check for addr bits stuck low or shorted.
841 */
Simon Glassad02a012013-02-28 17:47:14 +0000842 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
843 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000844
Simon Glassad02a012013-02-28 17:47:14 +0000845 for (offset = 1; offset < num_words; offset <<= 1) {
846 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000847 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000848 printf("\nFAILURE: Address bit stuck low or"
849 " shorted @ 0x%.8lx: expected 0x%.8lx,"
850 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800851 start_addr + offset*sizeof(vu_long),
852 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000853 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000854 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000855 return -1;
wdenk38635852002-08-27 05:55:31 +0000856 }
wdenk38635852002-08-27 05:55:31 +0000857 }
Simon Glassad02a012013-02-28 17:47:14 +0000858 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000859 }
wdenk38635852002-08-27 05:55:31 +0000860
Simon Glass130103e2013-02-24 17:33:18 +0000861 /*
862 * Description: Test the integrity of a physical
863 * memory device by performing an
864 * increment/decrement test over the
865 * entire region. In the process every
866 * storage bit in the device is tested
867 * as a zero and a one. The base address
868 * and the size of the region are
869 * selected by the caller.
870 *
871 * Returns: 0 if the test succeeds, 1 if the test fails.
872 */
Simon Glassad02a012013-02-28 17:47:14 +0000873 num_words++;
wdenk38635852002-08-27 05:55:31 +0000874
Simon Glass130103e2013-02-24 17:33:18 +0000875 /*
876 * Fill memory with a known pattern.
877 */
878 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
879 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000880 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000881 }
wdenk38635852002-08-27 05:55:31 +0000882
Simon Glass130103e2013-02-24 17:33:18 +0000883 /*
884 * Check each location and invert it for the second pass.
885 */
886 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
887 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000888 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000889 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000890 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000891 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800892 start_addr + offset*sizeof(vu_long),
893 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400894 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000895 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000896 return -1;
wdenk38635852002-08-27 05:55:31 +0000897 }
898
Simon Glass130103e2013-02-24 17:33:18 +0000899 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000900 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000901 }
902
903 /*
904 * Check each location for the inverted pattern and zero it.
905 */
906 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
907 WATCHDOG_RESET();
908 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000909 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000910 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000911 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000912 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800913 start_addr + offset*sizeof(vu_long),
914 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400915 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000916 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000917 return -1;
wdenk38635852002-08-27 05:55:31 +0000918 }
Simon Glassad02a012013-02-28 17:47:14 +0000919 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000920 }
Simon Glass57ee4432013-02-24 17:33:17 +0000921
922 return 0;
Simon Glass8f2c7582013-02-24 17:33:16 +0000923}
924
Simon Glassad02a012013-02-28 17:47:14 +0000925static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
926 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000927{
Simon Glassad02a012013-02-28 17:47:14 +0000928 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000929 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000930 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000931 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000932 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000933
Simon Glass57ee4432013-02-24 17:33:17 +0000934 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000935 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000936 if (iteration & 1) {
937 incr = -incr;
938 /*
939 * Flip the pattern each time to make lots of zeros and
940 * then, the next time, lots of ones. We decrement
941 * the "negative" patterns and increment the "positive"
942 * patterns to preserve this feature.
943 */
944 if (pattern & 0x80000000)
945 pattern = -pattern; /* complement & increment */
946 else
947 pattern = ~pattern;
948 }
Simon Glassad02a012013-02-28 17:47:14 +0000949 length = (end_addr - start_addr) / sizeof(ulong);
950 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000951 printf("\rPattern %08lX Writing..."
952 "%12s"
953 "\b\b\b\b\b\b\b\b\b\b",
954 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000955
Simon Glassad02a012013-02-28 17:47:14 +0000956 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000957 WATCHDOG_RESET();
958 *addr = val;
959 val += incr;
960 }
wdenk38635852002-08-27 05:55:31 +0000961
Simon Glass130103e2013-02-24 17:33:18 +0000962 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000963
Simon Glassad02a012013-02-28 17:47:14 +0000964 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000965 WATCHDOG_RESET();
966 readback = *addr;
967 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000968 ulong offset = addr - buf;
969
Simon Glass130103e2013-02-24 17:33:18 +0000970 printf("\nMem error @ 0x%08X: "
971 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800972 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000973 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000974 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000975 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000976 return -1;
wdenk38635852002-08-27 05:55:31 +0000977 }
Simon Glass130103e2013-02-24 17:33:18 +0000978 val += incr;
979 }
wdenk38635852002-08-27 05:55:31 +0000980
Simon Glass57ee4432013-02-24 17:33:17 +0000981 return 0;
Simon Glass8f2c7582013-02-24 17:33:16 +0000982}
983
984/*
985 * Perform a memory test. A more complete alternative test can be
986 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
987 * interrupted by ctrl-c or by a failure of one of the sub-tests.
988 */
989static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
990 char * const argv[])
991{
Simon Glass51075252013-02-24 17:33:20 +0000992 ulong start, end;
Simon Glassad02a012013-02-28 17:47:14 +0000993 vu_long *buf, *dummy;
Simon Glass8f2c7582013-02-24 17:33:16 +0000994 int iteration_limit;
995 int ret;
Simon Glass57ee4432013-02-24 17:33:17 +0000996 ulong errs = 0; /* number of errors, or -1 if interrupted */
Simon Glass8f2c7582013-02-24 17:33:16 +0000997 ulong pattern;
Simon Glass57ee4432013-02-24 17:33:17 +0000998 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +0000999#if defined(CONFIG_SYS_ALT_MEMTEST)
1000 const int alt_test = 1;
1001#else
1002 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +00001003#endif
Simon Glass8f2c7582013-02-24 17:33:16 +00001004
1005 if (argc > 1)
Simon Glass51075252013-02-24 17:33:20 +00001006 start = simple_strtoul(argv[1], NULL, 16);
Simon Glass8f2c7582013-02-24 17:33:16 +00001007 else
Simon Glass51075252013-02-24 17:33:20 +00001008 start = CONFIG_SYS_MEMTEST_START;
Simon Glass8f2c7582013-02-24 17:33:16 +00001009
1010 if (argc > 2)
Simon Glass51075252013-02-24 17:33:20 +00001011 end = simple_strtoul(argv[2], NULL, 16);
Simon Glass8f2c7582013-02-24 17:33:16 +00001012 else
Simon Glass51075252013-02-24 17:33:20 +00001013 end = CONFIG_SYS_MEMTEST_END;
Simon Glass8f2c7582013-02-24 17:33:16 +00001014
1015 if (argc > 3)
1016 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
1017 else
1018 pattern = 0;
1019
1020 if (argc > 4)
1021 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
1022 else
1023 iteration_limit = 0;
1024
Simon Glass51075252013-02-24 17:33:20 +00001025 printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
1026 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1027 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +00001028
Simon Glassad02a012013-02-28 17:47:14 +00001029 buf = map_sysmem(start, end - start);
1030 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass57ee4432013-02-24 17:33:17 +00001031 for (iteration = 0;
1032 !iteration_limit || iteration < iteration_limit;
1033 iteration++) {
1034 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +00001035 errs = -1UL;
1036 break;
1037 }
1038
1039 printf("Iteration: %6d\r", iteration + 1);
1040 debug("\n");
Simon Glassad02a012013-02-28 17:47:14 +00001041 if (alt_test) {
1042 errs = mem_test_alt(buf, start, end, dummy);
1043 } else {
1044 errs = mem_test_quick(buf, start, end, pattern,
1045 iteration);
1046 }
1047 if (errs == -1UL)
1048 break;
1049 }
1050
1051 /*
1052 * Work-around for eldk-4.2 which gives this warning if we try to
1053 * case in the unmap_sysmem() call:
1054 * warning: initialization discards qualifiers from pointer target type
1055 */
1056 {
1057 void *vbuf = (void *)buf;
1058 void *vdummy = (void *)dummy;
1059
1060 unmap_sysmem(vbuf);
1061 unmap_sysmem(vdummy);
Simon Glass57ee4432013-02-24 17:33:17 +00001062 }
1063
1064 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001065 /* Memory test was aborted - write a newline to finish off */
1066 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001067 ret = 1;
1068 } else {
1069 printf("Tested %d iteration(s) with %lu errors.\n",
1070 iteration, errs);
1071 ret = errs != 0;
1072 }
Simon Glass8f2c7582013-02-24 17:33:16 +00001073
1074 return ret; /* not reached */
wdenk38635852002-08-27 05:55:31 +00001075}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001076#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001077
1078/* Modify memory.
1079 *
1080 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001081 * mm{.b, .w, .l, .q} {addr}
1082 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001083 */
1084static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001085mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001086{
York Sun6c480012014-02-26 17:03:19 -08001087 ulong addr;
1088#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1089 u64 i;
1090#else
1091 ulong i;
1092#endif
wdenk874ac262003-07-24 23:38:38 +00001093 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001094 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001095
Wolfgang Denk3b683112010-07-17 01:06:04 +02001096 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001097 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001098
1099#ifdef CONFIG_BOOT_RETRY_TIME
1100 reset_cmd_timeout(); /* got a good command to get here */
1101#endif
1102 /* We use the last specified parameters, unless new ones are
1103 * entered.
1104 */
1105 addr = mm_last_addr;
1106 size = mm_last_size;
1107
1108 if ((flag & CMD_FLAG_REPEAT) == 0) {
1109 /* New command specified. Check for a size specification.
1110 * Defaults to long if no or incorrect specification.
1111 */
wdenk874ac262003-07-24 23:38:38 +00001112 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1113 return 1;
wdenk38635852002-08-27 05:55:31 +00001114
1115 /* Address is specified since argc > 1
1116 */
1117 addr = simple_strtoul(argv[1], NULL, 16);
1118 addr += base_address;
1119 }
1120
wdenk381669a2003-06-16 23:50:08 +00001121#ifdef CONFIG_HAS_DATAFLASH
1122 if (addr_dataflash(addr)){
wdenk42c05472004-03-23 22:14:11 +00001123 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk381669a2003-06-16 23:50:08 +00001124 return 0;
1125 }
1126#endif
1127
Mike Frysingere578d682008-02-04 19:26:56 -05001128#ifdef CONFIG_BLACKFIN
1129 if (addr_bfin_on_chip_mem(addr)) {
1130 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1131 return 0;
1132 }
1133#endif
1134
wdenk38635852002-08-27 05:55:31 +00001135 /* Print the address, followed by value. Then accept input for
1136 * the next value. A non-converted value exits.
1137 */
1138 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001139 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001140 printf("%08lx:", addr);
1141 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001142 printf(" %08x", *((u32 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001143#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1144 else if (size == 8)
1145 printf(" %016llx", *((u64 *)ptr));
1146#endif
wdenk38635852002-08-27 05:55:31 +00001147 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001148 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001149 else
York Sund8a405d2014-02-12 15:55:35 -08001150 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001151
1152 nbytes = readline (" ? ");
1153 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1154 /* <CR> pressed as only input, don't modify current
1155 * location and move to next. "-" pressed will go back.
1156 */
1157 if (incrflag)
1158 addr += nbytes ? -size : size;
1159 nbytes = 1;
1160#ifdef CONFIG_BOOT_RETRY_TIME
1161 reset_cmd_timeout(); /* good enough to not time out */
1162#endif
1163 }
1164#ifdef CONFIG_BOOT_RETRY_TIME
1165 else if (nbytes == -2) {
1166 break; /* timed out, exit the command */
1167 }
1168#endif
1169 else {
1170 char *endp;
York Sun6c480012014-02-26 17:03:19 -08001171#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1172 i = simple_strtoull(console_buffer, &endp, 16);
1173#else
wdenk38635852002-08-27 05:55:31 +00001174 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001175#endif
wdenk38635852002-08-27 05:55:31 +00001176 nbytes = endp - console_buffer;
1177 if (nbytes) {
1178#ifdef CONFIG_BOOT_RETRY_TIME
1179 /* good enough to not time out
1180 */
1181 reset_cmd_timeout();
1182#endif
1183 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001184 *((u32 *)ptr) = i;
York Sun6c480012014-02-26 17:03:19 -08001185#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1186 else if (size == 8)
1187 *((u64 *)ptr) = i;
1188#endif
wdenk38635852002-08-27 05:55:31 +00001189 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001190 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001191 else
York Sund8a405d2014-02-12 15:55:35 -08001192 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001193 if (incrflag)
1194 addr += size;
1195 }
1196 }
1197 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001198 if (ptr)
1199 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001200
1201 mm_last_addr = addr;
1202 mm_last_size = size;
1203 return 0;
1204}
1205
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001206#ifdef CONFIG_CMD_CRC32
1207
Kim Phillipsdc00a682012-10-29 13:34:31 +00001208static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001209{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001210 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001211 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001212 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001213
Simon Glass0bbd76f2013-02-24 20:30:22 +00001214 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001215 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001216
1217 av = argv + 1;
1218 ac = argc - 1;
Simon Glass0bbd76f2013-02-24 20:30:22 +00001219#ifdef CONFIG_HASH_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001220 if (strcmp(*av, "-v") == 0) {
Simon Glass0bbd76f2013-02-24 20:30:22 +00001221 flags |= HASH_FLAG_VERIFY;
wdenk6203e402004-04-18 10:13:26 +00001222 av++;
1223 ac--;
wdenk6203e402004-04-18 10:13:26 +00001224 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001225#endif
wdenk6203e402004-04-18 10:13:26 +00001226
Simon Glass0bbd76f2013-02-24 20:30:22 +00001227 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001228}
wdenk6203e402004-04-18 10:13:26 +00001229
Robin Getz93d6cb02009-07-27 00:07:59 -04001230#endif
1231
wdenk57b2d802003-06-27 21:31:46 +00001232/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001233U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001234 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001235 "memory display",
York Sun6c480012014-02-26 17:03:19 -08001236#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1237 "[.b, .w, .l, .q] address [# of objects]"
1238#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001239 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001240#endif
wdenk57b2d802003-06-27 21:31:46 +00001241);
1242
1243
wdenkf287a242003-07-01 21:06:45 +00001244U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001245 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001246 "memory modify (auto-incrementing address)",
York Sun6c480012014-02-26 17:03:19 -08001247#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1248 "[.b, .w, .l, .q] address"
1249#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001250 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001251#endif
wdenk57b2d802003-06-27 21:31:46 +00001252);
1253
1254
wdenkf287a242003-07-01 21:06:45 +00001255U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001256 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001257 "memory modify (constant address)",
York Sun6c480012014-02-26 17:03:19 -08001258#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1259 "[.b, .w, .l, .q] address"
1260#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001261 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001262#endif
wdenk57b2d802003-06-27 21:31:46 +00001263);
1264
wdenkf287a242003-07-01 21:06:45 +00001265U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001266 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001267 "memory write (fill)",
York Sun6c480012014-02-26 17:03:19 -08001268#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1269 "[.b, .w, .l, .q] address value [count]"
1270#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001271 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001272#endif
wdenk57b2d802003-06-27 21:31:46 +00001273);
1274
wdenkf287a242003-07-01 21:06:45 +00001275U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001276 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001277 "memory copy",
York Sun6c480012014-02-26 17:03:19 -08001278#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1279 "[.b, .w, .l, .q] source target count"
1280#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001281 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001282#endif
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 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001287 "memory compare",
York Sun6c480012014-02-26 17:03:19 -08001288#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1289 "[.b, .w, .l, .q] addr1 addr2 count"
1290#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001291 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001292#endif
wdenk57b2d802003-06-27 21:31:46 +00001293);
1294
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001295#ifdef CONFIG_CMD_CRC32
1296
wdenk6203e402004-04-18 10:13:26 +00001297#ifndef CONFIG_CRC32_VERIFY
1298
wdenkf287a242003-07-01 21:06:45 +00001299U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001300 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001301 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001302 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001303);
1304
wdenk6203e402004-04-18 10:13:26 +00001305#else /* CONFIG_CRC32_VERIFY */
1306
1307U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001308 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001309 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001310 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001311 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001312);
1313
1314#endif /* CONFIG_CRC32_VERIFY */
1315
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001316#endif
1317
Simon Glasseacd14f2012-11-30 13:01:20 +00001318#ifdef CONFIG_CMD_MEMINFO
1319__weak void board_show_dram(ulong size)
1320{
1321 puts("DRAM: ");
1322 print_size(size, "\n");
1323}
1324
1325static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1326 char * const argv[])
1327{
1328 board_show_dram(gd->ram_size);
1329
1330 return 0;
1331}
1332#endif
1333
wdenkf287a242003-07-01 21:06:45 +00001334U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001335 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001336 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001337 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001338 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001339);
1340
wdenkf287a242003-07-01 21:06:45 +00001341U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001342 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001343 "infinite loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001344#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1345 "[.b, .w, .l, .q] address number_of_objects"
1346#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001347 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001348#endif
wdenk57b2d802003-06-27 21:31:46 +00001349);
wdenk64519362004-07-11 17:40:54 +00001350
1351#ifdef CONFIG_LOOPW
1352U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001353 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001354 "infinite write loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001355#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1356 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1357#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001358 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001359#endif
wdenk64519362004-07-11 17:40:54 +00001360);
1361#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001362
Wolfgang Denk9d009282013-03-08 10:51:32 +00001363#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001364U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001365 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001366 "simple RAM read/write test",
1367 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001368);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001369#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001370
1371#ifdef CONFIG_MX_CYCLIC
1372U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001373 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001374 "memory display cyclic",
York Sun6c480012014-02-26 17:03:19 -08001375#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1376 "[.b, .w, .l, .q] address count delay(ms)"
1377#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001378 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001379#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001380);
1381
1382U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001383 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001384 "memory write cyclic",
York Sun6c480012014-02-26 17:03:19 -08001385#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1386 "[.b, .w, .l, .q] address value delay(ms)"
1387#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001388 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001389#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001390);
1391#endif /* CONFIG_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001392
1393#ifdef CONFIG_CMD_MEMINFO
1394U_BOOT_CMD(
1395 meminfo, 3, 1, do_mem_info,
1396 "display memory information",
1397 ""
1398);
1399#endif