blob: bcb3ee325ac9ceaf217bbbe7f86118b55aa1b116 [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 Glass399ed9a2014-04-10 20:01:30 -060015#include <bootretry.h>
Simon Glassdec3c012014-04-10 20:01:25 -060016#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000017#include <command.h>
wdenk381669a2003-06-16 23:50:08 +000018#ifdef CONFIG_HAS_DATAFLASH
19#include <dataflash.h>
20#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +000021#include <hash.h>
Simon Glasse9f343f2014-11-11 12:47:07 -070022#include <inttypes.h>
Sergei Poselenov474dbb82008-04-09 16:09:41 +020023#include <watchdog.h>
Simon Glasse6d0ca22013-02-24 17:33:15 +000024#include <asm/io.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000025#include <linux/compiler.h>
26
27DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000028
Simon Glass1c6c7252013-02-24 17:33:29 +000029#ifndef CONFIG_SYS_MEMTEST_SCRATCH
30#define CONFIG_SYS_MEMTEST_SCRATCH 0
31#endif
32
Wolfgang Denk6262d0212010-06-28 22:00:46 +020033static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000034
35/* Display values from last command.
36 * Memory modify remembered values are different from display memory.
37 */
Mike Frysinger1a4af8c2010-12-22 09:40:29 -050038static uint dp_last_addr, dp_last_size;
39static uint dp_last_length = 0x40;
40static uint mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000041
42static ulong base_address = 0;
43
44/* Memory Display
45 *
46 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080047 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000048 */
49#define DISP_LINE_LEN 16
Kim Phillipsdc00a682012-10-29 13:34:31 +000050static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000051{
wdenk874ac262003-07-24 23:38:38 +000052 ulong addr, length;
Grant Likely02a00782007-02-20 09:05:00 +010053#if defined(CONFIG_HAS_DATAFLASH)
54 ulong nbytes, linebytes;
55#endif
wdenk874ac262003-07-24 23:38:38 +000056 int size;
wdenk38635852002-08-27 05:55:31 +000057 int rc = 0;
58
59 /* We use the last specified parameters, unless new ones are
60 * entered.
61 */
62 addr = dp_last_addr;
63 size = dp_last_size;
64 length = dp_last_length;
65
Wolfgang Denk3b683112010-07-17 01:06:04 +020066 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000067 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000068
69 if ((flag & CMD_FLAG_REPEAT) == 0) {
70 /* New command specified. Check for a size specification.
71 * Defaults to long if no or incorrect specification.
72 */
wdenk874ac262003-07-24 23:38:38 +000073 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
74 return 1;
wdenk38635852002-08-27 05:55:31 +000075
76 /* Address is specified since argc > 1
77 */
78 addr = simple_strtoul(argv[1], NULL, 16);
79 addr += base_address;
80
81 /* If another parameter, it is the length to display.
82 * Length is the number of objects, not number of bytes.
83 */
84 if (argc > 2)
85 length = simple_strtoul(argv[2], NULL, 16);
86 }
87
Grant Likely02a00782007-02-20 09:05:00 +010088#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +000089 /* Print the lines.
90 *
91 * We buffer all read data, so we can make sure data is read only
92 * once, and all accesses are with the specified bus width.
93 */
94 nbytes = length * size;
95 do {
96 char linebuf[DISP_LINE_LEN];
Grant Likely02a00782007-02-20 09:05:00 +010097 void* p;
wdenk38635852002-08-27 05:55:31 +000098 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk381669a2003-06-16 23:50:08 +000099
Grant Likely02a00782007-02-20 09:05:00 +0100100 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
101 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
102 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk57b2d802003-06-27 21:31:46 +0000103
wdenk38635852002-08-27 05:55:31 +0000104 nbytes -= linebytes;
Grant Likely02a00782007-02-20 09:05:00 +0100105 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000106 if (ctrlc()) {
107 rc = 1;
108 break;
109 }
110 } while (nbytes > 0);
Grant Likely02a00782007-02-20 09:05:00 +0100111#else
Mike Frysingere578d682008-02-04 19:26:56 -0500112
113# if defined(CONFIG_BLACKFIN)
114 /* See if we're trying to display L1 inst */
115 if (addr_bfin_on_chip_mem(addr)) {
116 char linebuf[DISP_LINE_LEN];
117 ulong linebytes, nbytes = length * size;
118 do {
119 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
120 memcpy(linebuf, (void *)addr, linebytes);
121 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
122
123 nbytes -= linebytes;
124 addr += linebytes;
125 if (ctrlc()) {
126 rc = 1;
127 break;
128 }
129 } while (nbytes > 0);
130 } else
131# endif
132
133 {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000134 ulong bytes = size * length;
135 const void *buf = map_sysmem(addr, bytes);
136
Mike Frysingere578d682008-02-04 19:26:56 -0500137 /* Print the lines. */
Simon Glasse6d0ca22013-02-24 17:33:15 +0000138 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
139 addr += bytes;
140 unmap_sysmem(buf);
Mike Frysingere578d682008-02-04 19:26:56 -0500141 }
Grant Likely02a00782007-02-20 09:05:00 +0100142#endif
wdenk38635852002-08-27 05:55:31 +0000143
144 dp_last_addr = addr;
145 dp_last_length = length;
146 dp_last_size = size;
147 return (rc);
148}
149
Kim Phillipsdc00a682012-10-29 13:34:31 +0000150static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000151{
152 return mod_mem (cmdtp, 1, flag, argc, argv);
153}
Kim Phillipsdc00a682012-10-29 13:34:31 +0000154static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000155{
156 return mod_mem (cmdtp, 0, flag, argc, argv);
157}
158
Kim Phillipsdc00a682012-10-29 13:34:31 +0000159static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000160{
York Sun6c480012014-02-26 17:03:19 -0800161#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
162 u64 writeval;
163#else
164 ulong writeval;
165#endif
166 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000167 int size;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000168 void *buf;
169 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000170
Wolfgang Denk3b683112010-07-17 01:06:04 +0200171 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000172 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000173
174 /* Check for size specification.
175 */
wdenk874ac262003-07-24 23:38:38 +0000176 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
177 return 1;
wdenk38635852002-08-27 05:55:31 +0000178
179 /* Address is specified since argc > 1
180 */
181 addr = simple_strtoul(argv[1], NULL, 16);
182 addr += base_address;
183
184 /* Get the value to write.
185 */
York Sun6c480012014-02-26 17:03:19 -0800186#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
187 writeval = simple_strtoull(argv[2], NULL, 16);
188#else
wdenk38635852002-08-27 05:55:31 +0000189 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800190#endif
wdenk38635852002-08-27 05:55:31 +0000191
192 /* Count ? */
193 if (argc == 4) {
194 count = simple_strtoul(argv[3], NULL, 16);
195 } else {
196 count = 1;
197 }
198
Simon Glasse6d0ca22013-02-24 17:33:15 +0000199 bytes = size * count;
200 buf = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000201 while (count-- > 0) {
202 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800203 *((u32 *)buf) = (u32)writeval;
York Sun6c480012014-02-26 17:03:19 -0800204#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
205 else if (size == 8)
206 *((u64 *)buf) = (u64)writeval;
207#endif
wdenk38635852002-08-27 05:55:31 +0000208 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800209 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000210 else
York Sund8a405d2014-02-12 15:55:35 -0800211 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000212 buf += size;
wdenk38635852002-08-27 05:55:31 +0000213 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000214 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +0000215 return 0;
216}
217
stroesefb5e0ac2004-12-16 17:42:39 +0000218#ifdef CONFIG_MX_CYCLIC
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900219static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000220{
221 int i;
222 ulong count;
223
Wolfgang Denk3b683112010-07-17 01:06:04 +0200224 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000225 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000226
227 count = simple_strtoul(argv[3], NULL, 10);
228
229 for (;;) {
230 do_mem_md (NULL, 0, 3, argv);
231
232 /* delay for <count> ms... */
233 for (i=0; i<count; i++)
234 udelay (1000);
235
236 /* check for ctrl-c to abort... */
237 if (ctrlc()) {
238 puts("Abort\n");
239 return 0;
240 }
241 }
242
243 return 0;
244}
245
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900246static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000247{
248 int i;
249 ulong count;
250
Wolfgang Denk3b683112010-07-17 01:06:04 +0200251 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000252 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000253
254 count = simple_strtoul(argv[3], NULL, 10);
255
256 for (;;) {
257 do_mem_mw (NULL, 0, 3, argv);
258
259 /* delay for <count> ms... */
260 for (i=0; i<count; i++)
261 udelay (1000);
262
263 /* check for ctrl-c to abort... */
264 if (ctrlc()) {
265 puts("Abort\n");
266 return 0;
267 }
268 }
269
270 return 0;
271}
272#endif /* CONFIG_MX_CYCLIC */
273
Kim Phillipsdc00a682012-10-29 13:34:31 +0000274static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000275{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000276 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000277 int size;
wdenk38635852002-08-27 05:55:31 +0000278 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000279 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000280 const void *buf1, *buf2, *base;
York Sun6c480012014-02-26 17:03:19 -0800281#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
282 u64 word1, word2;
283#else
284 ulong word1, word2;
285#endif
wdenk38635852002-08-27 05:55:31 +0000286
Wolfgang Denk3b683112010-07-17 01:06:04 +0200287 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000288 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000289
290 /* Check for size specification.
291 */
wdenk874ac262003-07-24 23:38:38 +0000292 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
293 return 1;
York Sun6c480012014-02-26 17:03:19 -0800294 type = size == 8 ? "double word" :
295 size == 4 ? "word" :
296 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000297
298 addr1 = simple_strtoul(argv[1], NULL, 16);
299 addr1 += base_address;
300
301 addr2 = simple_strtoul(argv[2], NULL, 16);
302 addr2 += base_address;
303
304 count = simple_strtoul(argv[3], NULL, 16);
305
wdenk381669a2003-06-16 23:50:08 +0000306#ifdef CONFIG_HAS_DATAFLASH
307 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk42c05472004-03-23 22:14:11 +0000308 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000309 return 0;
310 }
311#endif
312
Mike Frysingere578d682008-02-04 19:26:56 -0500313#ifdef CONFIG_BLACKFIN
314 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
315 puts ("Comparison with L1 instruction memory not supported.\n\r");
316 return 0;
317 }
318#endif
319
Simon Glasse6d0ca22013-02-24 17:33:15 +0000320 bytes = size * count;
321 base = buf1 = map_sysmem(addr1, bytes);
322 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000323 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000324 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800325 word1 = *(u32 *)buf1;
326 word2 = *(u32 *)buf2;
York Sun6c480012014-02-26 17:03:19 -0800327#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
328 } else if (size == 8) {
329 word1 = *(u64 *)buf1;
330 word2 = *(u64 *)buf2;
331#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000332 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800333 word1 = *(u16 *)buf1;
334 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000335 } else {
York Sund8a405d2014-02-12 15:55:35 -0800336 word1 = *(u8 *)buf1;
337 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000338 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000339 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000340 ulong offset = buf1 - base;
York Sun6c480012014-02-26 17:03:19 -0800341#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
Simon Glasse9f343f2014-11-11 12:47:07 -0700342 printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
343 PRIx64 ")\n",
York Sun6c480012014-02-26 17:03:19 -0800344 type, (void *)(addr1 + offset), size, word1,
345 type, (void *)(addr2 + offset), size, word2);
346#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000347 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000348 type, (ulong)(addr1 + offset), size, word1,
349 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800350#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000351 rcode = 1;
352 break;
wdenk38635852002-08-27 05:55:31 +0000353 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000354
Simon Glasse6d0ca22013-02-24 17:33:15 +0000355 buf1 += size;
356 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200357
358 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000359 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200360 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000361 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000362 unmap_sysmem(buf1);
363 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000364
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000365 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000366 return rcode;
367}
368
Kim Phillipsdc00a682012-10-29 13:34:31 +0000369static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000370{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000371 ulong addr, dest, count, bytes;
wdenk874ac262003-07-24 23:38:38 +0000372 int size;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000373 const void *src;
374 void *buf;
wdenk38635852002-08-27 05:55:31 +0000375
Wolfgang Denk3b683112010-07-17 01:06:04 +0200376 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000377 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000378
379 /* Check for size specification.
380 */
wdenk874ac262003-07-24 23:38:38 +0000381 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
382 return 1;
wdenk38635852002-08-27 05:55:31 +0000383
384 addr = simple_strtoul(argv[1], NULL, 16);
385 addr += base_address;
386
387 dest = simple_strtoul(argv[2], NULL, 16);
388 dest += base_address;
389
390 count = simple_strtoul(argv[3], NULL, 16);
391
392 if (count == 0) {
393 puts ("Zero length ???\n");
394 return 1;
395 }
396
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200397#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000398 /* check if we are copying to Flash */
wdenk381669a2003-06-16 23:50:08 +0000399 if ( (addr2info(dest) != NULL)
400#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino1eb0fd52008-03-03 10:39:13 +0200401 && (!addr_dataflash(dest))
wdenk381669a2003-06-16 23:50:08 +0000402#endif
403 ) {
wdenk38635852002-08-27 05:55:31 +0000404 int rc;
405
wdenk42c05472004-03-23 22:14:11 +0000406 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000407
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200408 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000409 if (rc != 0) {
410 flash_perror (rc);
411 return (1);
412 }
413 puts ("done\n");
414 return 0;
415 }
416#endif
417
wdenk381669a2003-06-16 23:50:08 +0000418#ifdef CONFIG_HAS_DATAFLASH
419 /* Check if we are copying from RAM or Flash to DataFlash */
420 if (addr_dataflash(dest) && !addr_dataflash(addr)){
421 int rc;
422
wdenk42c05472004-03-23 22:14:11 +0000423 puts ("Copy to DataFlash... ");
wdenk381669a2003-06-16 23:50:08 +0000424
425 rc = write_dataflash (dest, addr, count*size);
426
427 if (rc != 1) {
428 dataflash_perror (rc);
429 return (1);
430 }
431 puts ("done\n");
432 return 0;
433 }
wdenk57b2d802003-06-27 21:31:46 +0000434
wdenk381669a2003-06-16 23:50:08 +0000435 /* Check if we are copying from DataFlash to RAM */
Stelian Popa63d2eb2008-03-26 22:52:35 +0100436 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200437#ifndef CONFIG_SYS_NO_FLASH
Stelian Popa63d2eb2008-03-26 22:52:35 +0100438 && (addr2info(dest) == NULL)
439#endif
440 ){
wdenk86765902003-12-06 23:55:10 +0000441 int rc;
442 rc = read_dataflash(addr, count * size, (char *) dest);
443 if (rc != 1) {
wdenk1ebf41e2004-01-02 14:00:00 +0000444 dataflash_perror (rc);
445 return (1);
446 }
wdenk381669a2003-06-16 23:50:08 +0000447 return 0;
448 }
449
450 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk42c05472004-03-23 22:14:11 +0000451 puts ("Unsupported combination of source/destination.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000452 return 1;
453 }
wdenk7a428cc2003-06-15 22:40:42 +0000454#endif
455
Mike Frysingere578d682008-02-04 19:26:56 -0500456#ifdef CONFIG_BLACKFIN
457 /* See if we're copying to/from L1 inst */
458 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
459 memcpy((void *)dest, (void *)addr, count * size);
460 return 0;
461 }
462#endif
463
Simon Glasse6d0ca22013-02-24 17:33:15 +0000464 bytes = size * count;
Masahiro Yamada4ad7dd52013-05-20 21:08:08 +0000465 buf = map_sysmem(dest, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +0000466 src = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000467 while (count-- > 0) {
468 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800469 *((u32 *)buf) = *((u32 *)src);
York Sun6c480012014-02-26 17:03:19 -0800470#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
471 else if (size == 8)
472 *((u64 *)buf) = *((u64 *)src);
473#endif
wdenk38635852002-08-27 05:55:31 +0000474 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800475 *((u16 *)buf) = *((u16 *)src);
wdenk38635852002-08-27 05:55:31 +0000476 else
York Sund8a405d2014-02-12 15:55:35 -0800477 *((u8 *)buf) = *((u8 *)src);
Simon Glasse6d0ca22013-02-24 17:33:15 +0000478 src += size;
479 buf += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200480
481 /* reset watchdog from time to time */
482 if ((count % (64 << 10)) == 0)
483 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000484 }
Masahiro Yamada787b0c52014-10-23 17:46:24 +0900485 unmap_sysmem(buf);
486 unmap_sysmem(src);
487
wdenk38635852002-08-27 05:55:31 +0000488 return 0;
489}
490
Kim Phillipsdc00a682012-10-29 13:34:31 +0000491static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
492 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000493{
494 if (argc > 1) {
495 /* Set new base address.
496 */
497 base_address = simple_strtoul(argv[1], NULL, 16);
498 }
499 /* Print the current base address.
500 */
501 printf("Base Address: 0x%08lx\n", base_address);
502 return 0;
503}
504
Kim Phillipsdc00a682012-10-29 13:34:31 +0000505static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
506 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000507{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000508 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000509 int size;
York Sun6c480012014-02-26 17:03:19 -0800510#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
511 volatile u64 *llp;
512#endif
York Sund8a405d2014-02-12 15:55:35 -0800513 volatile u32 *longp;
514 volatile u16 *shortp;
515 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000516 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000517
Wolfgang Denk3b683112010-07-17 01:06:04 +0200518 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000519 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000520
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000521 /*
522 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000523 * Defaults to long if no or incorrect specification.
524 */
wdenk874ac262003-07-24 23:38:38 +0000525 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
526 return 1;
wdenk38635852002-08-27 05:55:31 +0000527
528 /* Address is always specified.
529 */
530 addr = simple_strtoul(argv[1], NULL, 16);
531
532 /* Length is the number of objects, not number of bytes.
533 */
534 length = simple_strtoul(argv[2], NULL, 16);
535
Simon Glasse6d0ca22013-02-24 17:33:15 +0000536 bytes = size * length;
537 buf = map_sysmem(addr, bytes);
538
wdenk38635852002-08-27 05:55:31 +0000539 /* We want to optimize the loops to run as fast as possible.
540 * If we have only one object, just run infinite loops.
541 */
542 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800543#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
544 if (size == 8) {
545 llp = (u64 *)buf;
546 for (;;)
547 i = *llp;
548 }
549#endif
wdenk38635852002-08-27 05:55:31 +0000550 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800551 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000552 for (;;)
553 i = *longp;
554 }
555 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800556 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000557 for (;;)
558 i = *shortp;
559 }
York Sund8a405d2014-02-12 15:55:35 -0800560 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000561 for (;;)
562 i = *cp;
563 }
564
York Sun6c480012014-02-26 17:03:19 -0800565#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
566 if (size == 8) {
567 for (;;) {
568 llp = (u64 *)buf;
569 i = length;
570 while (i-- > 0)
571 *llp++;
572 }
573 }
574#endif
wdenk38635852002-08-27 05:55:31 +0000575 if (size == 4) {
576 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800577 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000578 i = length;
579 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200580 *longp++;
wdenk38635852002-08-27 05:55:31 +0000581 }
582 }
583 if (size == 2) {
584 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800585 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000586 i = length;
587 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200588 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000589 }
590 }
591 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800592 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000593 i = length;
594 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200595 *cp++;
wdenk38635852002-08-27 05:55:31 +0000596 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000597 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700598
599 return 0;
wdenk38635852002-08-27 05:55:31 +0000600}
601
wdenk64519362004-07-11 17:40:54 +0000602#ifdef CONFIG_LOOPW
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900603static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
604 char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000605{
York Sun6c480012014-02-26 17:03:19 -0800606 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000607 int size;
York Sun6c480012014-02-26 17:03:19 -0800608#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
609 volatile u64 *llp;
610 u64 data;
611#else
612 ulong data;
613#endif
York Sund8a405d2014-02-12 15:55:35 -0800614 volatile u32 *longp;
615 volatile u16 *shortp;
616 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000617 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000618
Wolfgang Denk3b683112010-07-17 01:06:04 +0200619 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000620 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000621
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000622 /*
623 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000624 * Defaults to long if no or incorrect specification.
625 */
626 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
627 return 1;
628
629 /* Address is always specified.
630 */
631 addr = simple_strtoul(argv[1], NULL, 16);
632
633 /* Length is the number of objects, not number of bytes.
634 */
635 length = simple_strtoul(argv[2], NULL, 16);
636
637 /* data to write */
York Sun6c480012014-02-26 17:03:19 -0800638#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
639 data = simple_strtoull(argv[3], NULL, 16);
640#else
wdenk64519362004-07-11 17:40:54 +0000641 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800642#endif
wdenk7dd13292004-07-11 20:04:51 +0000643
Simon Glasse6d0ca22013-02-24 17:33:15 +0000644 bytes = size * length;
645 buf = map_sysmem(addr, bytes);
646
wdenk64519362004-07-11 17:40:54 +0000647 /* We want to optimize the loops to run as fast as possible.
648 * If we have only one object, just run infinite loops.
649 */
650 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800651#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
652 if (size == 8) {
653 llp = (u64 *)buf;
654 for (;;)
655 *llp = data;
656 }
657#endif
wdenk64519362004-07-11 17:40:54 +0000658 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800659 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000660 for (;;)
661 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800662 }
wdenk64519362004-07-11 17:40:54 +0000663 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800664 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000665 for (;;)
666 *shortp = data;
667 }
York Sund8a405d2014-02-12 15:55:35 -0800668 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000669 for (;;)
670 *cp = data;
671 }
672
York Sun6c480012014-02-26 17:03:19 -0800673#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
674 if (size == 8) {
675 for (;;) {
676 llp = (u64 *)buf;
677 i = length;
678 while (i-- > 0)
679 *llp++ = data;
680 }
681 }
682#endif
wdenk64519362004-07-11 17:40:54 +0000683 if (size == 4) {
684 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800685 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000686 i = length;
687 while (i-- > 0)
688 *longp++ = data;
689 }
690 }
691 if (size == 2) {
692 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800693 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000694 i = length;
695 while (i-- > 0)
696 *shortp++ = data;
697 }
698 }
699 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800700 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000701 i = length;
702 while (i-- > 0)
703 *cp++ = data;
704 }
705}
706#endif /* CONFIG_LOOPW */
707
Tom Rinia5f02702013-03-12 10:07:19 -0400708#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000709static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
710 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000711{
Simon Glass8f2c7582013-02-24 17:33:16 +0000712 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000713 ulong errs = 0;
714 ulong val, readback;
715 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000716 vu_long offset;
717 vu_long test_offset;
718 vu_long pattern;
719 vu_long temp;
720 vu_long anti_pattern;
721 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000722 static const ulong bitpattern[] = {
723 0x00000001, /* single bit */
724 0x00000003, /* two adjacent bits */
725 0x00000007, /* three adjacent bits */
726 0x0000000F, /* four adjacent bits */
727 0x00000005, /* two non-adjacent bits */
728 0x00000015, /* three non-adjacent bits */
729 0x00000055, /* four non-adjacent bits */
730 0xaaaaaaaa, /* alternating 1/0 */
731 };
wdenk38635852002-08-27 05:55:31 +0000732
Simon Glassad02a012013-02-28 17:47:14 +0000733 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000734
Simon Glass130103e2013-02-24 17:33:18 +0000735 /*
736 * Data line test: write a pattern to the first
737 * location, write the 1's complement to a 'parking'
738 * address (changes the state of the data bus so a
739 * floating bus doesn't give a false OK), and then
740 * read the value back. Note that we read it back
741 * into a variable because the next time we read it,
742 * it might be right (been there, tough to explain to
743 * the quality guys why it prints a failure when the
744 * "is" and "should be" are obviously the same in the
745 * error message).
746 *
747 * Rather than exhaustively testing, we test some
748 * patterns by shifting '1' bits through a field of
749 * '0's and '0' bits through a field of '1's (i.e.
750 * pattern and ~pattern).
751 */
Simon Glassad02a012013-02-28 17:47:14 +0000752 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000753 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
754 val = bitpattern[j];
755 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000756 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000757 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000758 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000759 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000760 printf("FAILURE (data line): "
761 "expected %08lx, actual %08lx\n",
762 val, readback);
763 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000764 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000765 return -1;
wdenk38635852002-08-27 05:55:31 +0000766 }
767 *addr = ~val;
768 *dummy = val;
769 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000770 if (readback != ~val) {
771 printf("FAILURE (data line): "
772 "Is %08lx, should be %08lx\n",
773 readback, ~val);
774 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000775 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000776 return -1;
wdenk38635852002-08-27 05:55:31 +0000777 }
wdenk38635852002-08-27 05:55:31 +0000778 }
Simon Glass130103e2013-02-24 17:33:18 +0000779 }
wdenk38635852002-08-27 05:55:31 +0000780
Simon Glass130103e2013-02-24 17:33:18 +0000781 /*
782 * Based on code whose Original Author and Copyright
783 * information follows: Copyright (c) 1998 by Michael
784 * Barr. This software is placed into the public
785 * domain and may be used for any purpose. However,
786 * this notice must not be changed or removed and no
787 * warranty is either expressed or implied by its
788 * publication or distribution.
789 */
wdenk38635852002-08-27 05:55:31 +0000790
Simon Glass130103e2013-02-24 17:33:18 +0000791 /*
792 * Address line test
wdenk38635852002-08-27 05:55:31 +0000793
Simon Glass130103e2013-02-24 17:33:18 +0000794 * Description: Test the address bus wiring in a
795 * memory region by performing a walking
796 * 1's test on the relevant bits of the
797 * address and checking for aliasing.
798 * This test will find single-bit
799 * address failures such as stuck-high,
800 * stuck-low, and shorted pins. The base
801 * address and size of the region are
802 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000803
Simon Glass130103e2013-02-24 17:33:18 +0000804 * Notes: For best results, the selected base
805 * address should have enough LSB 0's to
806 * guarantee single address bit changes.
807 * For example, to test a 64-Kbyte
808 * region, select a base address on a
809 * 64-Kbyte boundary. Also, select the
810 * region size as a power-of-two if at
811 * all possible.
812 *
813 * Returns: 0 if the test succeeds, 1 if the test fails.
814 */
Simon Glass130103e2013-02-24 17:33:18 +0000815 pattern = (vu_long) 0xaaaaaaaa;
816 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000817
Simon Glassad02a012013-02-28 17:47:14 +0000818 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000819 /*
820 * Write the default pattern at each of the
821 * power-of-two offsets.
822 */
Simon Glassad02a012013-02-28 17:47:14 +0000823 for (offset = 1; offset < num_words; offset <<= 1)
824 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000825
826 /*
827 * Check for address bits stuck high.
828 */
829 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000830 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000831
Simon Glassad02a012013-02-28 17:47:14 +0000832 for (offset = 1; offset < num_words; offset <<= 1) {
833 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000834 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000835 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000836 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800837 start_addr + offset*sizeof(vu_long),
838 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400839 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000840 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000841 return -1;
wdenk38635852002-08-27 05:55:31 +0000842 }
Simon Glass130103e2013-02-24 17:33:18 +0000843 }
Simon Glassad02a012013-02-28 17:47:14 +0000844 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000845 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000846
Simon Glass130103e2013-02-24 17:33:18 +0000847 /*
848 * Check for addr bits stuck low or shorted.
849 */
Simon Glassad02a012013-02-28 17:47:14 +0000850 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
851 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000852
Simon Glassad02a012013-02-28 17:47:14 +0000853 for (offset = 1; offset < num_words; offset <<= 1) {
854 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000855 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000856 printf("\nFAILURE: Address bit stuck low or"
857 " shorted @ 0x%.8lx: expected 0x%.8lx,"
858 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800859 start_addr + offset*sizeof(vu_long),
860 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000861 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000862 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000863 return -1;
wdenk38635852002-08-27 05:55:31 +0000864 }
wdenk38635852002-08-27 05:55:31 +0000865 }
Simon Glassad02a012013-02-28 17:47:14 +0000866 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000867 }
wdenk38635852002-08-27 05:55:31 +0000868
Simon Glass130103e2013-02-24 17:33:18 +0000869 /*
870 * Description: Test the integrity of a physical
871 * memory device by performing an
872 * increment/decrement test over the
873 * entire region. In the process every
874 * storage bit in the device is tested
875 * as a zero and a one. The base address
876 * and the size of the region are
877 * selected by the caller.
878 *
879 * Returns: 0 if the test succeeds, 1 if the test fails.
880 */
Simon Glassad02a012013-02-28 17:47:14 +0000881 num_words++;
wdenk38635852002-08-27 05:55:31 +0000882
Simon Glass130103e2013-02-24 17:33:18 +0000883 /*
884 * Fill memory with a known pattern.
885 */
886 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
887 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000888 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000889 }
wdenk38635852002-08-27 05:55:31 +0000890
Simon Glass130103e2013-02-24 17:33:18 +0000891 /*
892 * Check each location and invert it for the second pass.
893 */
894 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
895 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000896 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000897 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000898 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000899 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800900 start_addr + offset*sizeof(vu_long),
901 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400902 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000903 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000904 return -1;
wdenk38635852002-08-27 05:55:31 +0000905 }
906
Simon Glass130103e2013-02-24 17:33:18 +0000907 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000908 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000909 }
910
911 /*
912 * Check each location for the inverted pattern and zero it.
913 */
914 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
915 WATCHDOG_RESET();
916 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000917 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000918 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000919 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000920 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800921 start_addr + offset*sizeof(vu_long),
922 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400923 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000924 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000925 return -1;
wdenk38635852002-08-27 05:55:31 +0000926 }
Simon Glassad02a012013-02-28 17:47:14 +0000927 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000928 }
Simon Glass57ee4432013-02-24 17:33:17 +0000929
930 return 0;
Simon Glass8f2c7582013-02-24 17:33:16 +0000931}
932
Simon Glassad02a012013-02-28 17:47:14 +0000933static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
934 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000935{
Simon Glassad02a012013-02-28 17:47:14 +0000936 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000937 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000938 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000939 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000940 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000941
Simon Glass57ee4432013-02-24 17:33:17 +0000942 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000943 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000944 if (iteration & 1) {
945 incr = -incr;
946 /*
947 * Flip the pattern each time to make lots of zeros and
948 * then, the next time, lots of ones. We decrement
949 * the "negative" patterns and increment the "positive"
950 * patterns to preserve this feature.
951 */
952 if (pattern & 0x80000000)
953 pattern = -pattern; /* complement & increment */
954 else
955 pattern = ~pattern;
956 }
Simon Glassad02a012013-02-28 17:47:14 +0000957 length = (end_addr - start_addr) / sizeof(ulong);
958 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000959 printf("\rPattern %08lX Writing..."
960 "%12s"
961 "\b\b\b\b\b\b\b\b\b\b",
962 pattern, "");
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 *addr = val;
967 val += incr;
968 }
wdenk38635852002-08-27 05:55:31 +0000969
Simon Glass130103e2013-02-24 17:33:18 +0000970 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000971
Simon Glassad02a012013-02-28 17:47:14 +0000972 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000973 WATCHDOG_RESET();
974 readback = *addr;
975 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000976 ulong offset = addr - buf;
977
Simon Glass130103e2013-02-24 17:33:18 +0000978 printf("\nMem error @ 0x%08X: "
979 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800980 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000981 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000982 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000983 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000984 return -1;
wdenk38635852002-08-27 05:55:31 +0000985 }
Simon Glass130103e2013-02-24 17:33:18 +0000986 val += incr;
987 }
wdenk38635852002-08-27 05:55:31 +0000988
Simon Glass57ee4432013-02-24 17:33:17 +0000989 return 0;
Simon Glass8f2c7582013-02-24 17:33:16 +0000990}
991
992/*
993 * Perform a memory test. A more complete alternative test can be
994 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
995 * interrupted by ctrl-c or by a failure of one of the sub-tests.
996 */
997static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
998 char * const argv[])
999{
Simon Glass51075252013-02-24 17:33:20 +00001000 ulong start, end;
Simon Glassad02a012013-02-28 17:47:14 +00001001 vu_long *buf, *dummy;
Simon Glass8f2c7582013-02-24 17:33:16 +00001002 int iteration_limit;
1003 int ret;
Simon Glass57ee4432013-02-24 17:33:17 +00001004 ulong errs = 0; /* number of errors, or -1 if interrupted */
Simon Glass8f2c7582013-02-24 17:33:16 +00001005 ulong pattern;
Simon Glass57ee4432013-02-24 17:33:17 +00001006 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +00001007#if defined(CONFIG_SYS_ALT_MEMTEST)
1008 const int alt_test = 1;
1009#else
1010 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +00001011#endif
Simon Glass8f2c7582013-02-24 17:33:16 +00001012
1013 if (argc > 1)
Simon Glass51075252013-02-24 17:33:20 +00001014 start = simple_strtoul(argv[1], NULL, 16);
Simon Glass8f2c7582013-02-24 17:33:16 +00001015 else
Simon Glass51075252013-02-24 17:33:20 +00001016 start = CONFIG_SYS_MEMTEST_START;
Simon Glass8f2c7582013-02-24 17:33:16 +00001017
1018 if (argc > 2)
Simon Glass51075252013-02-24 17:33:20 +00001019 end = simple_strtoul(argv[2], NULL, 16);
Simon Glass8f2c7582013-02-24 17:33:16 +00001020 else
Simon Glass51075252013-02-24 17:33:20 +00001021 end = CONFIG_SYS_MEMTEST_END;
Simon Glass8f2c7582013-02-24 17:33:16 +00001022
1023 if (argc > 3)
1024 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
1025 else
1026 pattern = 0;
1027
1028 if (argc > 4)
1029 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
1030 else
1031 iteration_limit = 0;
1032
Simon Glass51075252013-02-24 17:33:20 +00001033 printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
1034 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1035 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +00001036
Simon Glassad02a012013-02-28 17:47:14 +00001037 buf = map_sysmem(start, end - start);
1038 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass57ee4432013-02-24 17:33:17 +00001039 for (iteration = 0;
1040 !iteration_limit || iteration < iteration_limit;
1041 iteration++) {
1042 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +00001043 errs = -1UL;
1044 break;
1045 }
1046
1047 printf("Iteration: %6d\r", iteration + 1);
1048 debug("\n");
Simon Glassad02a012013-02-28 17:47:14 +00001049 if (alt_test) {
1050 errs = mem_test_alt(buf, start, end, dummy);
1051 } else {
1052 errs = mem_test_quick(buf, start, end, pattern,
1053 iteration);
1054 }
1055 if (errs == -1UL)
1056 break;
1057 }
1058
1059 /*
1060 * Work-around for eldk-4.2 which gives this warning if we try to
1061 * case in the unmap_sysmem() call:
1062 * warning: initialization discards qualifiers from pointer target type
1063 */
1064 {
1065 void *vbuf = (void *)buf;
1066 void *vdummy = (void *)dummy;
1067
1068 unmap_sysmem(vbuf);
1069 unmap_sysmem(vdummy);
Simon Glass57ee4432013-02-24 17:33:17 +00001070 }
1071
1072 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001073 /* Memory test was aborted - write a newline to finish off */
1074 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001075 ret = 1;
1076 } else {
1077 printf("Tested %d iteration(s) with %lu errors.\n",
1078 iteration, errs);
1079 ret = errs != 0;
1080 }
Simon Glass8f2c7582013-02-24 17:33:16 +00001081
1082 return ret; /* not reached */
wdenk38635852002-08-27 05:55:31 +00001083}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001084#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001085
1086/* Modify memory.
1087 *
1088 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001089 * mm{.b, .w, .l, .q} {addr}
1090 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001091 */
1092static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001093mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001094{
York Sun6c480012014-02-26 17:03:19 -08001095 ulong addr;
1096#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1097 u64 i;
1098#else
1099 ulong i;
1100#endif
wdenk874ac262003-07-24 23:38:38 +00001101 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001102 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001103
Wolfgang Denk3b683112010-07-17 01:06:04 +02001104 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001105 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001106
Simon Glass09007c42014-04-10 20:01:31 -06001107 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001108 /* We use the last specified parameters, unless new ones are
1109 * entered.
1110 */
1111 addr = mm_last_addr;
1112 size = mm_last_size;
1113
1114 if ((flag & CMD_FLAG_REPEAT) == 0) {
1115 /* New command specified. Check for a size specification.
1116 * Defaults to long if no or incorrect specification.
1117 */
wdenk874ac262003-07-24 23:38:38 +00001118 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1119 return 1;
wdenk38635852002-08-27 05:55:31 +00001120
1121 /* Address is specified since argc > 1
1122 */
1123 addr = simple_strtoul(argv[1], NULL, 16);
1124 addr += base_address;
1125 }
1126
wdenk381669a2003-06-16 23:50:08 +00001127#ifdef CONFIG_HAS_DATAFLASH
1128 if (addr_dataflash(addr)){
wdenk42c05472004-03-23 22:14:11 +00001129 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk381669a2003-06-16 23:50:08 +00001130 return 0;
1131 }
1132#endif
1133
Mike Frysingere578d682008-02-04 19:26:56 -05001134#ifdef CONFIG_BLACKFIN
1135 if (addr_bfin_on_chip_mem(addr)) {
1136 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1137 return 0;
1138 }
1139#endif
1140
wdenk38635852002-08-27 05:55:31 +00001141 /* Print the address, followed by value. Then accept input for
1142 * the next value. A non-converted value exits.
1143 */
1144 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001145 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001146 printf("%08lx:", addr);
1147 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001148 printf(" %08x", *((u32 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001149#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1150 else if (size == 8)
Simon Glasse9f343f2014-11-11 12:47:07 -07001151 printf(" %016" PRIx64, *((u64 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001152#endif
wdenk38635852002-08-27 05:55:31 +00001153 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001154 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001155 else
York Sund8a405d2014-02-12 15:55:35 -08001156 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001157
Simon Glassbe6aafc2014-04-10 20:01:27 -06001158 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001159 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1160 /* <CR> pressed as only input, don't modify current
1161 * location and move to next. "-" pressed will go back.
1162 */
1163 if (incrflag)
1164 addr += nbytes ? -size : size;
1165 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001166 /* good enough to not time out */
1167 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001168 }
1169#ifdef CONFIG_BOOT_RETRY_TIME
1170 else if (nbytes == -2) {
1171 break; /* timed out, exit the command */
1172 }
1173#endif
1174 else {
1175 char *endp;
York Sun6c480012014-02-26 17:03:19 -08001176#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1177 i = simple_strtoull(console_buffer, &endp, 16);
1178#else
wdenk38635852002-08-27 05:55:31 +00001179 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001180#endif
wdenk38635852002-08-27 05:55:31 +00001181 nbytes = endp - console_buffer;
1182 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001183 /* good enough to not time out
1184 */
Simon Glass09007c42014-04-10 20:01:31 -06001185 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001186 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001187 *((u32 *)ptr) = i;
York Sun6c480012014-02-26 17:03:19 -08001188#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1189 else if (size == 8)
1190 *((u64 *)ptr) = i;
1191#endif
wdenk38635852002-08-27 05:55:31 +00001192 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001193 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001194 else
York Sund8a405d2014-02-12 15:55:35 -08001195 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001196 if (incrflag)
1197 addr += size;
1198 }
1199 }
1200 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001201 if (ptr)
1202 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001203
1204 mm_last_addr = addr;
1205 mm_last_size = size;
1206 return 0;
1207}
1208
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001209#ifdef CONFIG_CMD_CRC32
1210
Kim Phillipsdc00a682012-10-29 13:34:31 +00001211static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001212{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001213 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001214 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001215 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001216
Simon Glass0bbd76f2013-02-24 20:30:22 +00001217 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001218 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001219
1220 av = argv + 1;
1221 ac = argc - 1;
Simon Glass0bbd76f2013-02-24 20:30:22 +00001222#ifdef CONFIG_HASH_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001223 if (strcmp(*av, "-v") == 0) {
Simon Glass0bbd76f2013-02-24 20:30:22 +00001224 flags |= HASH_FLAG_VERIFY;
wdenk6203e402004-04-18 10:13:26 +00001225 av++;
1226 ac--;
wdenk6203e402004-04-18 10:13:26 +00001227 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001228#endif
wdenk6203e402004-04-18 10:13:26 +00001229
Simon Glass0bbd76f2013-02-24 20:30:22 +00001230 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001231}
wdenk6203e402004-04-18 10:13:26 +00001232
Robin Getz93d6cb02009-07-27 00:07:59 -04001233#endif
1234
wdenk57b2d802003-06-27 21:31:46 +00001235/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001236U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001237 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001238 "memory display",
York Sun6c480012014-02-26 17:03:19 -08001239#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1240 "[.b, .w, .l, .q] address [# of objects]"
1241#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001242 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001243#endif
wdenk57b2d802003-06-27 21:31:46 +00001244);
1245
1246
wdenkf287a242003-07-01 21:06:45 +00001247U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001248 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001249 "memory modify (auto-incrementing address)",
York Sun6c480012014-02-26 17:03:19 -08001250#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1251 "[.b, .w, .l, .q] address"
1252#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001253 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001254#endif
wdenk57b2d802003-06-27 21:31:46 +00001255);
1256
1257
wdenkf287a242003-07-01 21:06:45 +00001258U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001259 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001260 "memory modify (constant address)",
York Sun6c480012014-02-26 17:03:19 -08001261#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1262 "[.b, .w, .l, .q] address"
1263#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001264 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001265#endif
wdenk57b2d802003-06-27 21:31:46 +00001266);
1267
wdenkf287a242003-07-01 21:06:45 +00001268U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001269 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001270 "memory write (fill)",
York Sun6c480012014-02-26 17:03:19 -08001271#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1272 "[.b, .w, .l, .q] address value [count]"
1273#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001274 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001275#endif
wdenk57b2d802003-06-27 21:31:46 +00001276);
1277
wdenkf287a242003-07-01 21:06:45 +00001278U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001279 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001280 "memory copy",
York Sun6c480012014-02-26 17:03:19 -08001281#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1282 "[.b, .w, .l, .q] source target count"
1283#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001284 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001285#endif
wdenk57b2d802003-06-27 21:31:46 +00001286);
1287
wdenkf287a242003-07-01 21:06:45 +00001288U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001289 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001290 "memory compare",
York Sun6c480012014-02-26 17:03:19 -08001291#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1292 "[.b, .w, .l, .q] addr1 addr2 count"
1293#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001294 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001295#endif
wdenk57b2d802003-06-27 21:31:46 +00001296);
1297
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001298#ifdef CONFIG_CMD_CRC32
1299
wdenk6203e402004-04-18 10:13:26 +00001300#ifndef CONFIG_CRC32_VERIFY
1301
wdenkf287a242003-07-01 21:06:45 +00001302U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001303 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001304 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001305 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001306);
1307
wdenk6203e402004-04-18 10:13:26 +00001308#else /* CONFIG_CRC32_VERIFY */
1309
1310U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001311 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001312 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001313 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001314 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001315);
1316
1317#endif /* CONFIG_CRC32_VERIFY */
1318
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001319#endif
1320
Simon Glasseacd14f2012-11-30 13:01:20 +00001321#ifdef CONFIG_CMD_MEMINFO
1322__weak void board_show_dram(ulong size)
1323{
1324 puts("DRAM: ");
1325 print_size(size, "\n");
1326}
1327
1328static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1329 char * const argv[])
1330{
1331 board_show_dram(gd->ram_size);
1332
1333 return 0;
1334}
1335#endif
1336
wdenkf287a242003-07-01 21:06:45 +00001337U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001338 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001339 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001340 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001341 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001342);
1343
wdenkf287a242003-07-01 21:06:45 +00001344U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001345 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001346 "infinite loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001347#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1348 "[.b, .w, .l, .q] address number_of_objects"
1349#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001350 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001351#endif
wdenk57b2d802003-06-27 21:31:46 +00001352);
wdenk64519362004-07-11 17:40:54 +00001353
1354#ifdef CONFIG_LOOPW
1355U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001356 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001357 "infinite write loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001358#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1359 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1360#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001361 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001362#endif
wdenk64519362004-07-11 17:40:54 +00001363);
1364#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001365
Wolfgang Denk9d009282013-03-08 10:51:32 +00001366#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001367U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001368 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001369 "simple RAM read/write test",
1370 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001371);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001372#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001373
1374#ifdef CONFIG_MX_CYCLIC
1375U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001376 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001377 "memory display cyclic",
York Sun6c480012014-02-26 17:03:19 -08001378#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1379 "[.b, .w, .l, .q] address count delay(ms)"
1380#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001381 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001382#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001383);
1384
1385U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001386 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001387 "memory write cyclic",
York Sun6c480012014-02-26 17:03:19 -08001388#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1389 "[.b, .w, .l, .q] address value delay(ms)"
1390#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001391 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001392#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001393);
1394#endif /* CONFIG_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001395
1396#ifdef CONFIG_CMD_MEMINFO
1397U_BOOT_CMD(
1398 meminfo, 3, 1, do_mem_info,
1399 "display memory information",
1400 ""
1401);
1402#endif