blob: bfca59e351f0f6705b9949b911b1aa2bf2d93af2 [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>
Sergei Poselenov474dbb82008-04-09 16:09:41 +020022#include <watchdog.h>
Simon Glasse6d0ca22013-02-24 17:33:15 +000023#include <asm/io.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000024#include <linux/compiler.h>
25
26DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000027
Simon Glass1c6c7252013-02-24 17:33:29 +000028#ifndef CONFIG_SYS_MEMTEST_SCRATCH
29#define CONFIG_SYS_MEMTEST_SCRATCH 0
30#endif
31
Wolfgang Denk6262d0212010-06-28 22:00:46 +020032static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000033
34/* Display values from last command.
35 * Memory modify remembered values are different from display memory.
36 */
Mike Frysinger1a4af8c2010-12-22 09:40:29 -050037static uint dp_last_addr, dp_last_size;
38static uint dp_last_length = 0x40;
39static uint mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000040
41static ulong base_address = 0;
42
43/* Memory Display
44 *
45 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080046 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000047 */
48#define DISP_LINE_LEN 16
Kim Phillipsdc00a682012-10-29 13:34:31 +000049static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000050{
wdenk874ac262003-07-24 23:38:38 +000051 ulong addr, length;
Grant Likely02a00782007-02-20 09:05:00 +010052#if defined(CONFIG_HAS_DATAFLASH)
53 ulong nbytes, linebytes;
54#endif
wdenk874ac262003-07-24 23:38:38 +000055 int size;
wdenk38635852002-08-27 05:55:31 +000056 int rc = 0;
57
58 /* We use the last specified parameters, unless new ones are
59 * entered.
60 */
61 addr = dp_last_addr;
62 size = dp_last_size;
63 length = dp_last_length;
64
Wolfgang Denk3b683112010-07-17 01:06:04 +020065 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000066 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000067
68 if ((flag & CMD_FLAG_REPEAT) == 0) {
69 /* New command specified. Check for a size specification.
70 * Defaults to long if no or incorrect specification.
71 */
wdenk874ac262003-07-24 23:38:38 +000072 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
73 return 1;
wdenk38635852002-08-27 05:55:31 +000074
75 /* Address is specified since argc > 1
76 */
77 addr = simple_strtoul(argv[1], NULL, 16);
78 addr += base_address;
79
80 /* If another parameter, it is the length to display.
81 * Length is the number of objects, not number of bytes.
82 */
83 if (argc > 2)
84 length = simple_strtoul(argv[2], NULL, 16);
85 }
86
Grant Likely02a00782007-02-20 09:05:00 +010087#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +000088 /* Print the lines.
89 *
90 * We buffer all read data, so we can make sure data is read only
91 * once, and all accesses are with the specified bus width.
92 */
93 nbytes = length * size;
94 do {
95 char linebuf[DISP_LINE_LEN];
Grant Likely02a00782007-02-20 09:05:00 +010096 void* p;
wdenk38635852002-08-27 05:55:31 +000097 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk381669a2003-06-16 23:50:08 +000098
Grant Likely02a00782007-02-20 09:05:00 +010099 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
100 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
101 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk57b2d802003-06-27 21:31:46 +0000102
wdenk38635852002-08-27 05:55:31 +0000103 nbytes -= linebytes;
Grant Likely02a00782007-02-20 09:05:00 +0100104 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000105 if (ctrlc()) {
106 rc = 1;
107 break;
108 }
109 } while (nbytes > 0);
Grant Likely02a00782007-02-20 09:05:00 +0100110#else
Mike Frysingere578d682008-02-04 19:26:56 -0500111
112# if defined(CONFIG_BLACKFIN)
113 /* See if we're trying to display L1 inst */
114 if (addr_bfin_on_chip_mem(addr)) {
115 char linebuf[DISP_LINE_LEN];
116 ulong linebytes, nbytes = length * size;
117 do {
118 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
119 memcpy(linebuf, (void *)addr, linebytes);
120 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
121
122 nbytes -= linebytes;
123 addr += linebytes;
124 if (ctrlc()) {
125 rc = 1;
126 break;
127 }
128 } while (nbytes > 0);
129 } else
130# endif
131
132 {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000133 ulong bytes = size * length;
134 const void *buf = map_sysmem(addr, bytes);
135
Mike Frysingere578d682008-02-04 19:26:56 -0500136 /* Print the lines. */
Simon Glasse6d0ca22013-02-24 17:33:15 +0000137 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
138 addr += bytes;
139 unmap_sysmem(buf);
Mike Frysingere578d682008-02-04 19:26:56 -0500140 }
Grant Likely02a00782007-02-20 09:05:00 +0100141#endif
wdenk38635852002-08-27 05:55:31 +0000142
143 dp_last_addr = addr;
144 dp_last_length = length;
145 dp_last_size = size;
146 return (rc);
147}
148
Kim Phillipsdc00a682012-10-29 13:34:31 +0000149static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000150{
151 return mod_mem (cmdtp, 1, flag, argc, argv);
152}
Kim Phillipsdc00a682012-10-29 13:34:31 +0000153static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000154{
155 return mod_mem (cmdtp, 0, flag, argc, argv);
156}
157
Kim Phillipsdc00a682012-10-29 13:34:31 +0000158static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000159{
York Sun6c480012014-02-26 17:03:19 -0800160#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
161 u64 writeval;
162#else
163 ulong writeval;
164#endif
165 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000166 int size;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000167 void *buf;
168 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000169
Wolfgang Denk3b683112010-07-17 01:06:04 +0200170 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000171 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000172
173 /* Check for size specification.
174 */
wdenk874ac262003-07-24 23:38:38 +0000175 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
176 return 1;
wdenk38635852002-08-27 05:55:31 +0000177
178 /* Address is specified since argc > 1
179 */
180 addr = simple_strtoul(argv[1], NULL, 16);
181 addr += base_address;
182
183 /* Get the value to write.
184 */
York Sun6c480012014-02-26 17:03:19 -0800185#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
186 writeval = simple_strtoull(argv[2], NULL, 16);
187#else
wdenk38635852002-08-27 05:55:31 +0000188 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800189#endif
wdenk38635852002-08-27 05:55:31 +0000190
191 /* Count ? */
192 if (argc == 4) {
193 count = simple_strtoul(argv[3], NULL, 16);
194 } else {
195 count = 1;
196 }
197
Simon Glasse6d0ca22013-02-24 17:33:15 +0000198 bytes = size * count;
199 buf = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000200 while (count-- > 0) {
201 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800202 *((u32 *)buf) = (u32)writeval;
York Sun6c480012014-02-26 17:03:19 -0800203#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
204 else if (size == 8)
205 *((u64 *)buf) = (u64)writeval;
206#endif
wdenk38635852002-08-27 05:55:31 +0000207 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800208 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000209 else
York Sund8a405d2014-02-12 15:55:35 -0800210 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000211 buf += size;
wdenk38635852002-08-27 05:55:31 +0000212 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000213 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +0000214 return 0;
215}
216
stroesefb5e0ac2004-12-16 17:42:39 +0000217#ifdef CONFIG_MX_CYCLIC
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900218static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000219{
220 int i;
221 ulong count;
222
Wolfgang Denk3b683112010-07-17 01:06:04 +0200223 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000224 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000225
226 count = simple_strtoul(argv[3], NULL, 10);
227
228 for (;;) {
229 do_mem_md (NULL, 0, 3, argv);
230
231 /* delay for <count> ms... */
232 for (i=0; i<count; i++)
233 udelay (1000);
234
235 /* check for ctrl-c to abort... */
236 if (ctrlc()) {
237 puts("Abort\n");
238 return 0;
239 }
240 }
241
242 return 0;
243}
244
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900245static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000246{
247 int i;
248 ulong count;
249
Wolfgang Denk3b683112010-07-17 01:06:04 +0200250 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000251 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000252
253 count = simple_strtoul(argv[3], NULL, 10);
254
255 for (;;) {
256 do_mem_mw (NULL, 0, 3, argv);
257
258 /* delay for <count> ms... */
259 for (i=0; i<count; i++)
260 udelay (1000);
261
262 /* check for ctrl-c to abort... */
263 if (ctrlc()) {
264 puts("Abort\n");
265 return 0;
266 }
267 }
268
269 return 0;
270}
271#endif /* CONFIG_MX_CYCLIC */
272
Kim Phillipsdc00a682012-10-29 13:34:31 +0000273static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000274{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000275 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000276 int size;
wdenk38635852002-08-27 05:55:31 +0000277 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000278 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000279 const void *buf1, *buf2, *base;
York Sun6c480012014-02-26 17:03:19 -0800280#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
281 u64 word1, word2;
282#else
283 ulong word1, word2;
284#endif
wdenk38635852002-08-27 05:55:31 +0000285
Wolfgang Denk3b683112010-07-17 01:06:04 +0200286 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000287 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000288
289 /* Check for size specification.
290 */
wdenk874ac262003-07-24 23:38:38 +0000291 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
292 return 1;
York Sun6c480012014-02-26 17:03:19 -0800293 type = size == 8 ? "double word" :
294 size == 4 ? "word" :
295 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000296
297 addr1 = simple_strtoul(argv[1], NULL, 16);
298 addr1 += base_address;
299
300 addr2 = simple_strtoul(argv[2], NULL, 16);
301 addr2 += base_address;
302
303 count = simple_strtoul(argv[3], NULL, 16);
304
wdenk381669a2003-06-16 23:50:08 +0000305#ifdef CONFIG_HAS_DATAFLASH
306 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk42c05472004-03-23 22:14:11 +0000307 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000308 return 0;
309 }
310#endif
311
Mike Frysingere578d682008-02-04 19:26:56 -0500312#ifdef CONFIG_BLACKFIN
313 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
314 puts ("Comparison with L1 instruction memory not supported.\n\r");
315 return 0;
316 }
317#endif
318
Simon Glasse6d0ca22013-02-24 17:33:15 +0000319 bytes = size * count;
320 base = buf1 = map_sysmem(addr1, bytes);
321 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000322 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000323 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800324 word1 = *(u32 *)buf1;
325 word2 = *(u32 *)buf2;
York Sun6c480012014-02-26 17:03:19 -0800326#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
327 } else if (size == 8) {
328 word1 = *(u64 *)buf1;
329 word2 = *(u64 *)buf2;
330#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000331 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800332 word1 = *(u16 *)buf1;
333 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000334 } else {
York Sund8a405d2014-02-12 15:55:35 -0800335 word1 = *(u8 *)buf1;
336 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000337 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000338 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000339 ulong offset = buf1 - base;
York Sun6c480012014-02-26 17:03:19 -0800340#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
341 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
342 type, (void *)(addr1 + offset), size, word1,
343 type, (void *)(addr2 + offset), size, word2);
344#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000345 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000346 type, (ulong)(addr1 + offset), size, word1,
347 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800348#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000349 rcode = 1;
350 break;
wdenk38635852002-08-27 05:55:31 +0000351 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000352
Simon Glasse6d0ca22013-02-24 17:33:15 +0000353 buf1 += size;
354 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200355
356 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000357 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200358 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000359 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000360 unmap_sysmem(buf1);
361 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000362
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000363 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000364 return rcode;
365}
366
Kim Phillipsdc00a682012-10-29 13:34:31 +0000367static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000368{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000369 ulong addr, dest, count, bytes;
wdenk874ac262003-07-24 23:38:38 +0000370 int size;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000371 const void *src;
372 void *buf;
wdenk38635852002-08-27 05:55:31 +0000373
Wolfgang Denk3b683112010-07-17 01:06:04 +0200374 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000375 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000376
377 /* Check for size specification.
378 */
wdenk874ac262003-07-24 23:38:38 +0000379 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
380 return 1;
wdenk38635852002-08-27 05:55:31 +0000381
382 addr = simple_strtoul(argv[1], NULL, 16);
383 addr += base_address;
384
385 dest = simple_strtoul(argv[2], NULL, 16);
386 dest += base_address;
387
388 count = simple_strtoul(argv[3], NULL, 16);
389
390 if (count == 0) {
391 puts ("Zero length ???\n");
392 return 1;
393 }
394
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200395#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000396 /* check if we are copying to Flash */
wdenk381669a2003-06-16 23:50:08 +0000397 if ( (addr2info(dest) != NULL)
398#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino1eb0fd52008-03-03 10:39:13 +0200399 && (!addr_dataflash(dest))
wdenk381669a2003-06-16 23:50:08 +0000400#endif
401 ) {
wdenk38635852002-08-27 05:55:31 +0000402 int rc;
403
wdenk42c05472004-03-23 22:14:11 +0000404 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000405
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200406 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000407 if (rc != 0) {
408 flash_perror (rc);
409 return (1);
410 }
411 puts ("done\n");
412 return 0;
413 }
414#endif
415
wdenk381669a2003-06-16 23:50:08 +0000416#ifdef CONFIG_HAS_DATAFLASH
417 /* Check if we are copying from RAM or Flash to DataFlash */
418 if (addr_dataflash(dest) && !addr_dataflash(addr)){
419 int rc;
420
wdenk42c05472004-03-23 22:14:11 +0000421 puts ("Copy to DataFlash... ");
wdenk381669a2003-06-16 23:50:08 +0000422
423 rc = write_dataflash (dest, addr, count*size);
424
425 if (rc != 1) {
426 dataflash_perror (rc);
427 return (1);
428 }
429 puts ("done\n");
430 return 0;
431 }
wdenk57b2d802003-06-27 21:31:46 +0000432
wdenk381669a2003-06-16 23:50:08 +0000433 /* Check if we are copying from DataFlash to RAM */
Stelian Popa63d2eb2008-03-26 22:52:35 +0100434 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200435#ifndef CONFIG_SYS_NO_FLASH
Stelian Popa63d2eb2008-03-26 22:52:35 +0100436 && (addr2info(dest) == NULL)
437#endif
438 ){
wdenk86765902003-12-06 23:55:10 +0000439 int rc;
440 rc = read_dataflash(addr, count * size, (char *) dest);
441 if (rc != 1) {
wdenk1ebf41e2004-01-02 14:00:00 +0000442 dataflash_perror (rc);
443 return (1);
444 }
wdenk381669a2003-06-16 23:50:08 +0000445 return 0;
446 }
447
448 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk42c05472004-03-23 22:14:11 +0000449 puts ("Unsupported combination of source/destination.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000450 return 1;
451 }
wdenk7a428cc2003-06-15 22:40:42 +0000452#endif
453
Mike Frysingere578d682008-02-04 19:26:56 -0500454#ifdef CONFIG_BLACKFIN
455 /* See if we're copying to/from L1 inst */
456 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
457 memcpy((void *)dest, (void *)addr, count * size);
458 return 0;
459 }
460#endif
461
Simon Glasse6d0ca22013-02-24 17:33:15 +0000462 bytes = size * count;
Masahiro Yamada4ad7dd52013-05-20 21:08:08 +0000463 buf = map_sysmem(dest, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +0000464 src = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000465 while (count-- > 0) {
466 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800467 *((u32 *)buf) = *((u32 *)src);
York Sun6c480012014-02-26 17:03:19 -0800468#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
469 else if (size == 8)
470 *((u64 *)buf) = *((u64 *)src);
471#endif
wdenk38635852002-08-27 05:55:31 +0000472 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800473 *((u16 *)buf) = *((u16 *)src);
wdenk38635852002-08-27 05:55:31 +0000474 else
York Sund8a405d2014-02-12 15:55:35 -0800475 *((u8 *)buf) = *((u8 *)src);
Simon Glasse6d0ca22013-02-24 17:33:15 +0000476 src += size;
477 buf += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200478
479 /* reset watchdog from time to time */
480 if ((count % (64 << 10)) == 0)
481 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000482 }
483 return 0;
484}
485
Kim Phillipsdc00a682012-10-29 13:34:31 +0000486static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
487 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000488{
489 if (argc > 1) {
490 /* Set new base address.
491 */
492 base_address = simple_strtoul(argv[1], NULL, 16);
493 }
494 /* Print the current base address.
495 */
496 printf("Base Address: 0x%08lx\n", base_address);
497 return 0;
498}
499
Kim Phillipsdc00a682012-10-29 13:34:31 +0000500static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
501 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000502{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000503 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000504 int size;
York Sun6c480012014-02-26 17:03:19 -0800505#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
506 volatile u64 *llp;
507#endif
York Sund8a405d2014-02-12 15:55:35 -0800508 volatile u32 *longp;
509 volatile u16 *shortp;
510 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000511 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000512
Wolfgang Denk3b683112010-07-17 01:06:04 +0200513 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000514 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000515
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000516 /*
517 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000518 * Defaults to long if no or incorrect specification.
519 */
wdenk874ac262003-07-24 23:38:38 +0000520 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
521 return 1;
wdenk38635852002-08-27 05:55:31 +0000522
523 /* Address is always specified.
524 */
525 addr = simple_strtoul(argv[1], NULL, 16);
526
527 /* Length is the number of objects, not number of bytes.
528 */
529 length = simple_strtoul(argv[2], NULL, 16);
530
Simon Glasse6d0ca22013-02-24 17:33:15 +0000531 bytes = size * length;
532 buf = map_sysmem(addr, bytes);
533
wdenk38635852002-08-27 05:55:31 +0000534 /* We want to optimize the loops to run as fast as possible.
535 * If we have only one object, just run infinite loops.
536 */
537 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800538#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
539 if (size == 8) {
540 llp = (u64 *)buf;
541 for (;;)
542 i = *llp;
543 }
544#endif
wdenk38635852002-08-27 05:55:31 +0000545 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800546 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000547 for (;;)
548 i = *longp;
549 }
550 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800551 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000552 for (;;)
553 i = *shortp;
554 }
York Sund8a405d2014-02-12 15:55:35 -0800555 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000556 for (;;)
557 i = *cp;
558 }
559
York Sun6c480012014-02-26 17:03:19 -0800560#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
561 if (size == 8) {
562 for (;;) {
563 llp = (u64 *)buf;
564 i = length;
565 while (i-- > 0)
566 *llp++;
567 }
568 }
569#endif
wdenk38635852002-08-27 05:55:31 +0000570 if (size == 4) {
571 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800572 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000573 i = length;
574 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200575 *longp++;
wdenk38635852002-08-27 05:55:31 +0000576 }
577 }
578 if (size == 2) {
579 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800580 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000581 i = length;
582 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200583 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000584 }
585 }
586 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800587 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000588 i = length;
589 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200590 *cp++;
wdenk38635852002-08-27 05:55:31 +0000591 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000592 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700593
594 return 0;
wdenk38635852002-08-27 05:55:31 +0000595}
596
wdenk64519362004-07-11 17:40:54 +0000597#ifdef CONFIG_LOOPW
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900598static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
599 char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000600{
York Sun6c480012014-02-26 17:03:19 -0800601 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000602 int size;
York Sun6c480012014-02-26 17:03:19 -0800603#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
604 volatile u64 *llp;
605 u64 data;
606#else
607 ulong data;
608#endif
York Sund8a405d2014-02-12 15:55:35 -0800609 volatile u32 *longp;
610 volatile u16 *shortp;
611 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000612 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000613
Wolfgang Denk3b683112010-07-17 01:06:04 +0200614 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000615 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000616
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000617 /*
618 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000619 * Defaults to long if no or incorrect specification.
620 */
621 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
622 return 1;
623
624 /* Address is always specified.
625 */
626 addr = simple_strtoul(argv[1], NULL, 16);
627
628 /* Length is the number of objects, not number of bytes.
629 */
630 length = simple_strtoul(argv[2], NULL, 16);
631
632 /* data to write */
York Sun6c480012014-02-26 17:03:19 -0800633#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
634 data = simple_strtoull(argv[3], NULL, 16);
635#else
wdenk64519362004-07-11 17:40:54 +0000636 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800637#endif
wdenk7dd13292004-07-11 20:04:51 +0000638
Simon Glasse6d0ca22013-02-24 17:33:15 +0000639 bytes = size * length;
640 buf = map_sysmem(addr, bytes);
641
wdenk64519362004-07-11 17:40:54 +0000642 /* We want to optimize the loops to run as fast as possible.
643 * If we have only one object, just run infinite loops.
644 */
645 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800646#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
647 if (size == 8) {
648 llp = (u64 *)buf;
649 for (;;)
650 *llp = data;
651 }
652#endif
wdenk64519362004-07-11 17:40:54 +0000653 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800654 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000655 for (;;)
656 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800657 }
wdenk64519362004-07-11 17:40:54 +0000658 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800659 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000660 for (;;)
661 *shortp = data;
662 }
York Sund8a405d2014-02-12 15:55:35 -0800663 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000664 for (;;)
665 *cp = data;
666 }
667
York Sun6c480012014-02-26 17:03:19 -0800668#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
669 if (size == 8) {
670 for (;;) {
671 llp = (u64 *)buf;
672 i = length;
673 while (i-- > 0)
674 *llp++ = data;
675 }
676 }
677#endif
wdenk64519362004-07-11 17:40:54 +0000678 if (size == 4) {
679 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800680 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000681 i = length;
682 while (i-- > 0)
683 *longp++ = data;
684 }
685 }
686 if (size == 2) {
687 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800688 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000689 i = length;
690 while (i-- > 0)
691 *shortp++ = data;
692 }
693 }
694 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800695 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000696 i = length;
697 while (i-- > 0)
698 *cp++ = data;
699 }
700}
701#endif /* CONFIG_LOOPW */
702
Tom Rinia5f02702013-03-12 10:07:19 -0400703#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000704static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
705 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000706{
Simon Glass8f2c7582013-02-24 17:33:16 +0000707 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000708 ulong errs = 0;
709 ulong val, readback;
710 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000711 vu_long offset;
712 vu_long test_offset;
713 vu_long pattern;
714 vu_long temp;
715 vu_long anti_pattern;
716 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000717 static const ulong bitpattern[] = {
718 0x00000001, /* single bit */
719 0x00000003, /* two adjacent bits */
720 0x00000007, /* three adjacent bits */
721 0x0000000F, /* four adjacent bits */
722 0x00000005, /* two non-adjacent bits */
723 0x00000015, /* three non-adjacent bits */
724 0x00000055, /* four non-adjacent bits */
725 0xaaaaaaaa, /* alternating 1/0 */
726 };
wdenk38635852002-08-27 05:55:31 +0000727
Simon Glassad02a012013-02-28 17:47:14 +0000728 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000729
Simon Glass130103e2013-02-24 17:33:18 +0000730 /*
731 * Data line test: write a pattern to the first
732 * location, write the 1's complement to a 'parking'
733 * address (changes the state of the data bus so a
734 * floating bus doesn't give a false OK), and then
735 * read the value back. Note that we read it back
736 * into a variable because the next time we read it,
737 * it might be right (been there, tough to explain to
738 * the quality guys why it prints a failure when the
739 * "is" and "should be" are obviously the same in the
740 * error message).
741 *
742 * Rather than exhaustively testing, we test some
743 * patterns by shifting '1' bits through a field of
744 * '0's and '0' bits through a field of '1's (i.e.
745 * pattern and ~pattern).
746 */
Simon Glassad02a012013-02-28 17:47:14 +0000747 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000748 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
749 val = bitpattern[j];
750 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000751 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000752 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000753 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000754 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000755 printf("FAILURE (data line): "
756 "expected %08lx, actual %08lx\n",
757 val, readback);
758 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000759 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000760 return -1;
wdenk38635852002-08-27 05:55:31 +0000761 }
762 *addr = ~val;
763 *dummy = val;
764 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000765 if (readback != ~val) {
766 printf("FAILURE (data line): "
767 "Is %08lx, should be %08lx\n",
768 readback, ~val);
769 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000770 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000771 return -1;
wdenk38635852002-08-27 05:55:31 +0000772 }
wdenk38635852002-08-27 05:55:31 +0000773 }
Simon Glass130103e2013-02-24 17:33:18 +0000774 }
wdenk38635852002-08-27 05:55:31 +0000775
Simon Glass130103e2013-02-24 17:33:18 +0000776 /*
777 * Based on code whose Original Author and Copyright
778 * information follows: Copyright (c) 1998 by Michael
779 * Barr. This software is placed into the public
780 * domain and may be used for any purpose. However,
781 * this notice must not be changed or removed and no
782 * warranty is either expressed or implied by its
783 * publication or distribution.
784 */
wdenk38635852002-08-27 05:55:31 +0000785
Simon Glass130103e2013-02-24 17:33:18 +0000786 /*
787 * Address line test
wdenk38635852002-08-27 05:55:31 +0000788
Simon Glass130103e2013-02-24 17:33:18 +0000789 * Description: Test the address bus wiring in a
790 * memory region by performing a walking
791 * 1's test on the relevant bits of the
792 * address and checking for aliasing.
793 * This test will find single-bit
794 * address failures such as stuck-high,
795 * stuck-low, and shorted pins. The base
796 * address and size of the region are
797 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000798
Simon Glass130103e2013-02-24 17:33:18 +0000799 * Notes: For best results, the selected base
800 * address should have enough LSB 0's to
801 * guarantee single address bit changes.
802 * For example, to test a 64-Kbyte
803 * region, select a base address on a
804 * 64-Kbyte boundary. Also, select the
805 * region size as a power-of-two if at
806 * all possible.
807 *
808 * Returns: 0 if the test succeeds, 1 if the test fails.
809 */
Simon Glass130103e2013-02-24 17:33:18 +0000810 pattern = (vu_long) 0xaaaaaaaa;
811 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000812
Simon Glassad02a012013-02-28 17:47:14 +0000813 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000814 /*
815 * Write the default pattern at each of the
816 * power-of-two offsets.
817 */
Simon Glassad02a012013-02-28 17:47:14 +0000818 for (offset = 1; offset < num_words; offset <<= 1)
819 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000820
821 /*
822 * Check for address bits stuck high.
823 */
824 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000825 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000826
Simon Glassad02a012013-02-28 17:47:14 +0000827 for (offset = 1; offset < num_words; offset <<= 1) {
828 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000829 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000830 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000831 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800832 start_addr + offset*sizeof(vu_long),
833 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400834 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000835 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000836 return -1;
wdenk38635852002-08-27 05:55:31 +0000837 }
Simon Glass130103e2013-02-24 17:33:18 +0000838 }
Simon Glassad02a012013-02-28 17:47:14 +0000839 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000840 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000841
Simon Glass130103e2013-02-24 17:33:18 +0000842 /*
843 * Check for addr bits stuck low or shorted.
844 */
Simon Glassad02a012013-02-28 17:47:14 +0000845 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
846 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000847
Simon Glassad02a012013-02-28 17:47:14 +0000848 for (offset = 1; offset < num_words; offset <<= 1) {
849 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000850 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000851 printf("\nFAILURE: Address bit stuck low or"
852 " shorted @ 0x%.8lx: expected 0x%.8lx,"
853 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800854 start_addr + offset*sizeof(vu_long),
855 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000856 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000857 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000858 return -1;
wdenk38635852002-08-27 05:55:31 +0000859 }
wdenk38635852002-08-27 05:55:31 +0000860 }
Simon Glassad02a012013-02-28 17:47:14 +0000861 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000862 }
wdenk38635852002-08-27 05:55:31 +0000863
Simon Glass130103e2013-02-24 17:33:18 +0000864 /*
865 * Description: Test the integrity of a physical
866 * memory device by performing an
867 * increment/decrement test over the
868 * entire region. In the process every
869 * storage bit in the device is tested
870 * as a zero and a one. The base address
871 * and the size of the region are
872 * selected by the caller.
873 *
874 * Returns: 0 if the test succeeds, 1 if the test fails.
875 */
Simon Glassad02a012013-02-28 17:47:14 +0000876 num_words++;
wdenk38635852002-08-27 05:55:31 +0000877
Simon Glass130103e2013-02-24 17:33:18 +0000878 /*
879 * Fill memory with a known pattern.
880 */
881 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
882 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000883 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000884 }
wdenk38635852002-08-27 05:55:31 +0000885
Simon Glass130103e2013-02-24 17:33:18 +0000886 /*
887 * Check each location and invert it for the second pass.
888 */
889 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
890 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000891 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000892 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000893 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000894 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800895 start_addr + offset*sizeof(vu_long),
896 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400897 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000898 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000899 return -1;
wdenk38635852002-08-27 05:55:31 +0000900 }
901
Simon Glass130103e2013-02-24 17:33:18 +0000902 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000903 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000904 }
905
906 /*
907 * Check each location for the inverted pattern and zero it.
908 */
909 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
910 WATCHDOG_RESET();
911 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000912 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000913 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000914 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000915 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800916 start_addr + offset*sizeof(vu_long),
917 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400918 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000919 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000920 return -1;
wdenk38635852002-08-27 05:55:31 +0000921 }
Simon Glassad02a012013-02-28 17:47:14 +0000922 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000923 }
Simon Glass57ee4432013-02-24 17:33:17 +0000924
925 return 0;
Simon Glass8f2c7582013-02-24 17:33:16 +0000926}
927
Simon Glassad02a012013-02-28 17:47:14 +0000928static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
929 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000930{
Simon Glassad02a012013-02-28 17:47:14 +0000931 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000932 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000933 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000934 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000935 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000936
Simon Glass57ee4432013-02-24 17:33:17 +0000937 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000938 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000939 if (iteration & 1) {
940 incr = -incr;
941 /*
942 * Flip the pattern each time to make lots of zeros and
943 * then, the next time, lots of ones. We decrement
944 * the "negative" patterns and increment the "positive"
945 * patterns to preserve this feature.
946 */
947 if (pattern & 0x80000000)
948 pattern = -pattern; /* complement & increment */
949 else
950 pattern = ~pattern;
951 }
Simon Glassad02a012013-02-28 17:47:14 +0000952 length = (end_addr - start_addr) / sizeof(ulong);
953 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000954 printf("\rPattern %08lX Writing..."
955 "%12s"
956 "\b\b\b\b\b\b\b\b\b\b",
957 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000958
Simon Glassad02a012013-02-28 17:47:14 +0000959 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000960 WATCHDOG_RESET();
961 *addr = val;
962 val += incr;
963 }
wdenk38635852002-08-27 05:55:31 +0000964
Simon Glass130103e2013-02-24 17:33:18 +0000965 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000966
Simon Glassad02a012013-02-28 17:47:14 +0000967 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000968 WATCHDOG_RESET();
969 readback = *addr;
970 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000971 ulong offset = addr - buf;
972
Simon Glass130103e2013-02-24 17:33:18 +0000973 printf("\nMem error @ 0x%08X: "
974 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800975 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000976 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000977 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000978 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000979 return -1;
wdenk38635852002-08-27 05:55:31 +0000980 }
Simon Glass130103e2013-02-24 17:33:18 +0000981 val += incr;
982 }
wdenk38635852002-08-27 05:55:31 +0000983
Simon Glass57ee4432013-02-24 17:33:17 +0000984 return 0;
Simon Glass8f2c7582013-02-24 17:33:16 +0000985}
986
987/*
988 * Perform a memory test. A more complete alternative test can be
989 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
990 * interrupted by ctrl-c or by a failure of one of the sub-tests.
991 */
992static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
993 char * const argv[])
994{
Simon Glass51075252013-02-24 17:33:20 +0000995 ulong start, end;
Simon Glassad02a012013-02-28 17:47:14 +0000996 vu_long *buf, *dummy;
Simon Glass8f2c7582013-02-24 17:33:16 +0000997 int iteration_limit;
998 int ret;
Simon Glass57ee4432013-02-24 17:33:17 +0000999 ulong errs = 0; /* number of errors, or -1 if interrupted */
Simon Glass8f2c7582013-02-24 17:33:16 +00001000 ulong pattern;
Simon Glass57ee4432013-02-24 17:33:17 +00001001 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +00001002#if defined(CONFIG_SYS_ALT_MEMTEST)
1003 const int alt_test = 1;
1004#else
1005 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +00001006#endif
Simon Glass8f2c7582013-02-24 17:33:16 +00001007
1008 if (argc > 1)
Simon Glass51075252013-02-24 17:33:20 +00001009 start = simple_strtoul(argv[1], NULL, 16);
Simon Glass8f2c7582013-02-24 17:33:16 +00001010 else
Simon Glass51075252013-02-24 17:33:20 +00001011 start = CONFIG_SYS_MEMTEST_START;
Simon Glass8f2c7582013-02-24 17:33:16 +00001012
1013 if (argc > 2)
Simon Glass51075252013-02-24 17:33:20 +00001014 end = simple_strtoul(argv[2], NULL, 16);
Simon Glass8f2c7582013-02-24 17:33:16 +00001015 else
Simon Glass51075252013-02-24 17:33:20 +00001016 end = CONFIG_SYS_MEMTEST_END;
Simon Glass8f2c7582013-02-24 17:33:16 +00001017
1018 if (argc > 3)
1019 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
1020 else
1021 pattern = 0;
1022
1023 if (argc > 4)
1024 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
1025 else
1026 iteration_limit = 0;
1027
Simon Glass51075252013-02-24 17:33:20 +00001028 printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
1029 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1030 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +00001031
Simon Glassad02a012013-02-28 17:47:14 +00001032 buf = map_sysmem(start, end - start);
1033 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass57ee4432013-02-24 17:33:17 +00001034 for (iteration = 0;
1035 !iteration_limit || iteration < iteration_limit;
1036 iteration++) {
1037 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +00001038 errs = -1UL;
1039 break;
1040 }
1041
1042 printf("Iteration: %6d\r", iteration + 1);
1043 debug("\n");
Simon Glassad02a012013-02-28 17:47:14 +00001044 if (alt_test) {
1045 errs = mem_test_alt(buf, start, end, dummy);
1046 } else {
1047 errs = mem_test_quick(buf, start, end, pattern,
1048 iteration);
1049 }
1050 if (errs == -1UL)
1051 break;
1052 }
1053
1054 /*
1055 * Work-around for eldk-4.2 which gives this warning if we try to
1056 * case in the unmap_sysmem() call:
1057 * warning: initialization discards qualifiers from pointer target type
1058 */
1059 {
1060 void *vbuf = (void *)buf;
1061 void *vdummy = (void *)dummy;
1062
1063 unmap_sysmem(vbuf);
1064 unmap_sysmem(vdummy);
Simon Glass57ee4432013-02-24 17:33:17 +00001065 }
1066
1067 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001068 /* Memory test was aborted - write a newline to finish off */
1069 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001070 ret = 1;
1071 } else {
1072 printf("Tested %d iteration(s) with %lu errors.\n",
1073 iteration, errs);
1074 ret = errs != 0;
1075 }
Simon Glass8f2c7582013-02-24 17:33:16 +00001076
1077 return ret; /* not reached */
wdenk38635852002-08-27 05:55:31 +00001078}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001079#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001080
1081/* Modify memory.
1082 *
1083 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001084 * mm{.b, .w, .l, .q} {addr}
1085 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001086 */
1087static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001088mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001089{
York Sun6c480012014-02-26 17:03:19 -08001090 ulong addr;
1091#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1092 u64 i;
1093#else
1094 ulong i;
1095#endif
wdenk874ac262003-07-24 23:38:38 +00001096 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001097 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001098
Wolfgang Denk3b683112010-07-17 01:06:04 +02001099 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001100 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001101
Simon Glass09007c42014-04-10 20:01:31 -06001102 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001103 /* We use the last specified parameters, unless new ones are
1104 * entered.
1105 */
1106 addr = mm_last_addr;
1107 size = mm_last_size;
1108
1109 if ((flag & CMD_FLAG_REPEAT) == 0) {
1110 /* New command specified. Check for a size specification.
1111 * Defaults to long if no or incorrect specification.
1112 */
wdenk874ac262003-07-24 23:38:38 +00001113 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1114 return 1;
wdenk38635852002-08-27 05:55:31 +00001115
1116 /* Address is specified since argc > 1
1117 */
1118 addr = simple_strtoul(argv[1], NULL, 16);
1119 addr += base_address;
1120 }
1121
wdenk381669a2003-06-16 23:50:08 +00001122#ifdef CONFIG_HAS_DATAFLASH
1123 if (addr_dataflash(addr)){
wdenk42c05472004-03-23 22:14:11 +00001124 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk381669a2003-06-16 23:50:08 +00001125 return 0;
1126 }
1127#endif
1128
Mike Frysingere578d682008-02-04 19:26:56 -05001129#ifdef CONFIG_BLACKFIN
1130 if (addr_bfin_on_chip_mem(addr)) {
1131 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1132 return 0;
1133 }
1134#endif
1135
wdenk38635852002-08-27 05:55:31 +00001136 /* Print the address, followed by value. Then accept input for
1137 * the next value. A non-converted value exits.
1138 */
1139 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001140 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001141 printf("%08lx:", addr);
1142 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001143 printf(" %08x", *((u32 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001144#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1145 else if (size == 8)
1146 printf(" %016llx", *((u64 *)ptr));
1147#endif
wdenk38635852002-08-27 05:55:31 +00001148 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001149 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001150 else
York Sund8a405d2014-02-12 15:55:35 -08001151 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001152
Simon Glassbe6aafc2014-04-10 20:01:27 -06001153 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001154 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1155 /* <CR> pressed as only input, don't modify current
1156 * location and move to next. "-" pressed will go back.
1157 */
1158 if (incrflag)
1159 addr += nbytes ? -size : size;
1160 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001161 /* good enough to not time out */
1162 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001163 }
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) {
wdenk38635852002-08-27 05:55:31 +00001178 /* good enough to not time out
1179 */
Simon Glass09007c42014-04-10 20:01:31 -06001180 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001181 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001182 *((u32 *)ptr) = i;
York Sun6c480012014-02-26 17:03:19 -08001183#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1184 else if (size == 8)
1185 *((u64 *)ptr) = i;
1186#endif
wdenk38635852002-08-27 05:55:31 +00001187 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001188 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001189 else
York Sund8a405d2014-02-12 15:55:35 -08001190 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001191 if (incrflag)
1192 addr += size;
1193 }
1194 }
1195 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001196 if (ptr)
1197 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001198
1199 mm_last_addr = addr;
1200 mm_last_size = size;
1201 return 0;
1202}
1203
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001204#ifdef CONFIG_CMD_CRC32
1205
Kim Phillipsdc00a682012-10-29 13:34:31 +00001206static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001207{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001208 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001209 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001210 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001211
Simon Glass0bbd76f2013-02-24 20:30:22 +00001212 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001213 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001214
1215 av = argv + 1;
1216 ac = argc - 1;
Simon Glass0bbd76f2013-02-24 20:30:22 +00001217#ifdef CONFIG_HASH_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001218 if (strcmp(*av, "-v") == 0) {
Simon Glass0bbd76f2013-02-24 20:30:22 +00001219 flags |= HASH_FLAG_VERIFY;
wdenk6203e402004-04-18 10:13:26 +00001220 av++;
1221 ac--;
wdenk6203e402004-04-18 10:13:26 +00001222 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001223#endif
wdenk6203e402004-04-18 10:13:26 +00001224
Simon Glass0bbd76f2013-02-24 20:30:22 +00001225 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001226}
wdenk6203e402004-04-18 10:13:26 +00001227
Robin Getz93d6cb02009-07-27 00:07:59 -04001228#endif
1229
wdenk57b2d802003-06-27 21:31:46 +00001230/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001231U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001232 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001233 "memory display",
York Sun6c480012014-02-26 17:03:19 -08001234#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1235 "[.b, .w, .l, .q] address [# of objects]"
1236#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001237 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001238#endif
wdenk57b2d802003-06-27 21:31:46 +00001239);
1240
1241
wdenkf287a242003-07-01 21:06:45 +00001242U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001243 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001244 "memory modify (auto-incrementing address)",
York Sun6c480012014-02-26 17:03:19 -08001245#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1246 "[.b, .w, .l, .q] address"
1247#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001248 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001249#endif
wdenk57b2d802003-06-27 21:31:46 +00001250);
1251
1252
wdenkf287a242003-07-01 21:06:45 +00001253U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001254 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001255 "memory modify (constant address)",
York Sun6c480012014-02-26 17:03:19 -08001256#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1257 "[.b, .w, .l, .q] address"
1258#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001259 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001260#endif
wdenk57b2d802003-06-27 21:31:46 +00001261);
1262
wdenkf287a242003-07-01 21:06:45 +00001263U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001264 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001265 "memory write (fill)",
York Sun6c480012014-02-26 17:03:19 -08001266#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1267 "[.b, .w, .l, .q] address value [count]"
1268#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001269 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001270#endif
wdenk57b2d802003-06-27 21:31:46 +00001271);
1272
wdenkf287a242003-07-01 21:06:45 +00001273U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001274 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001275 "memory copy",
York Sun6c480012014-02-26 17:03:19 -08001276#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1277 "[.b, .w, .l, .q] source target count"
1278#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001279 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001280#endif
wdenk57b2d802003-06-27 21:31:46 +00001281);
1282
wdenkf287a242003-07-01 21:06:45 +00001283U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001284 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001285 "memory compare",
York Sun6c480012014-02-26 17:03:19 -08001286#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1287 "[.b, .w, .l, .q] addr1 addr2 count"
1288#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001289 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001290#endif
wdenk57b2d802003-06-27 21:31:46 +00001291);
1292
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001293#ifdef CONFIG_CMD_CRC32
1294
wdenk6203e402004-04-18 10:13:26 +00001295#ifndef CONFIG_CRC32_VERIFY
1296
wdenkf287a242003-07-01 21:06:45 +00001297U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001298 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001299 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001300 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001301);
1302
wdenk6203e402004-04-18 10:13:26 +00001303#else /* CONFIG_CRC32_VERIFY */
1304
1305U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001306 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001307 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001308 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001309 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001310);
1311
1312#endif /* CONFIG_CRC32_VERIFY */
1313
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001314#endif
1315
Simon Glasseacd14f2012-11-30 13:01:20 +00001316#ifdef CONFIG_CMD_MEMINFO
1317__weak void board_show_dram(ulong size)
1318{
1319 puts("DRAM: ");
1320 print_size(size, "\n");
1321}
1322
1323static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1324 char * const argv[])
1325{
1326 board_show_dram(gd->ram_size);
1327
1328 return 0;
1329}
1330#endif
1331
wdenkf287a242003-07-01 21:06:45 +00001332U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001333 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001334 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001335 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001336 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001337);
1338
wdenkf287a242003-07-01 21:06:45 +00001339U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001340 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001341 "infinite loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001342#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1343 "[.b, .w, .l, .q] address number_of_objects"
1344#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001345 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001346#endif
wdenk57b2d802003-06-27 21:31:46 +00001347);
wdenk64519362004-07-11 17:40:54 +00001348
1349#ifdef CONFIG_LOOPW
1350U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001351 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001352 "infinite write loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001353#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1354 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1355#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001356 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001357#endif
wdenk64519362004-07-11 17:40:54 +00001358);
1359#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001360
Wolfgang Denk9d009282013-03-08 10:51:32 +00001361#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001362U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001363 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001364 "simple RAM read/write test",
1365 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001366);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001367#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001368
1369#ifdef CONFIG_MX_CYCLIC
1370U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001371 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001372 "memory display cyclic",
York Sun6c480012014-02-26 17:03:19 -08001373#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1374 "[.b, .w, .l, .q] address count delay(ms)"
1375#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001376 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001377#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001378);
1379
1380U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001381 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001382 "memory write cyclic",
York Sun6c480012014-02-26 17:03:19 -08001383#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1384 "[.b, .w, .l, .q] address value delay(ms)"
1385#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001386 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001387#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001388);
1389#endif /* CONFIG_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001390
1391#ifdef CONFIG_CMD_MEMINFO
1392U_BOOT_CMD(
1393 meminfo, 3, 1, do_mem_info,
1394 "display memory information",
1395 ""
1396);
1397#endif