blob: efa39296ef7a170e0f6463cd1a29c23bd446904b [file] [log] [blame]
wdenk38635852002-08-27 05:55:31 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00006 */
7
8/*
9 * Memory Functions
10 *
11 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
12 */
13
14#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -070015#include <console.h>
Simon Glass399ed9a2014-04-10 20:01:30 -060016#include <bootretry.h>
Simon Glassdec3c012014-04-10 20:01:25 -060017#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000018#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070019#include <console.h>
wdenk381669a2003-06-16 23:50:08 +000020#ifdef CONFIG_HAS_DATAFLASH
21#include <dataflash.h>
22#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +000023#include <hash.h>
Simon Glasse9f343f2014-11-11 12:47:07 -070024#include <inttypes.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050025#include <mapmem.h>
Sergei Poselenov474dbb82008-04-09 16:09:41 +020026#include <watchdog.h>
Simon Glasse6d0ca22013-02-24 17:33:15 +000027#include <asm/io.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000028#include <linux/compiler.h>
29
30DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000031
Simon Glass1c6c7252013-02-24 17:33:29 +000032#ifndef CONFIG_SYS_MEMTEST_SCRATCH
33#define CONFIG_SYS_MEMTEST_SCRATCH 0
34#endif
35
Wolfgang Denk6262d0212010-06-28 22:00:46 +020036static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000037
38/* Display values from last command.
39 * Memory modify remembered values are different from display memory.
40 */
Scott Wood3ec02882015-03-19 09:43:12 -070041static ulong dp_last_addr, dp_last_size;
42static ulong dp_last_length = 0x40;
43static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000044
45static ulong base_address = 0;
46
47/* Memory Display
48 *
49 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080050 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000051 */
52#define DISP_LINE_LEN 16
Kim Phillipsdc00a682012-10-29 13:34:31 +000053static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000054{
wdenk874ac262003-07-24 23:38:38 +000055 ulong addr, length;
Grant Likely02a00782007-02-20 09:05:00 +010056#if defined(CONFIG_HAS_DATAFLASH)
57 ulong nbytes, linebytes;
58#endif
wdenk874ac262003-07-24 23:38:38 +000059 int size;
wdenk38635852002-08-27 05:55:31 +000060 int rc = 0;
61
62 /* We use the last specified parameters, unless new ones are
63 * entered.
64 */
65 addr = dp_last_addr;
66 size = dp_last_size;
67 length = dp_last_length;
68
Wolfgang Denk3b683112010-07-17 01:06:04 +020069 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000070 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000071
72 if ((flag & CMD_FLAG_REPEAT) == 0) {
73 /* New command specified. Check for a size specification.
74 * Defaults to long if no or incorrect specification.
75 */
wdenk874ac262003-07-24 23:38:38 +000076 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
77 return 1;
wdenk38635852002-08-27 05:55:31 +000078
79 /* Address is specified since argc > 1
80 */
81 addr = simple_strtoul(argv[1], NULL, 16);
82 addr += base_address;
83
84 /* If another parameter, it is the length to display.
85 * Length is the number of objects, not number of bytes.
86 */
87 if (argc > 2)
88 length = simple_strtoul(argv[2], NULL, 16);
89 }
90
Grant Likely02a00782007-02-20 09:05:00 +010091#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +000092 /* Print the lines.
93 *
94 * We buffer all read data, so we can make sure data is read only
95 * once, and all accesses are with the specified bus width.
96 */
97 nbytes = length * size;
98 do {
99 char linebuf[DISP_LINE_LEN];
Grant Likely02a00782007-02-20 09:05:00 +0100100 void* p;
wdenk38635852002-08-27 05:55:31 +0000101 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk381669a2003-06-16 23:50:08 +0000102
Grant Likely02a00782007-02-20 09:05:00 +0100103 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
104 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
105 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk57b2d802003-06-27 21:31:46 +0000106
wdenk38635852002-08-27 05:55:31 +0000107 nbytes -= linebytes;
Grant Likely02a00782007-02-20 09:05:00 +0100108 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000109 if (ctrlc()) {
110 rc = 1;
111 break;
112 }
113 } while (nbytes > 0);
Grant Likely02a00782007-02-20 09:05:00 +0100114#else
Mike Frysingere578d682008-02-04 19:26:56 -0500115
116# if defined(CONFIG_BLACKFIN)
117 /* See if we're trying to display L1 inst */
118 if (addr_bfin_on_chip_mem(addr)) {
119 char linebuf[DISP_LINE_LEN];
120 ulong linebytes, nbytes = length * size;
121 do {
122 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
123 memcpy(linebuf, (void *)addr, linebytes);
124 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
125
126 nbytes -= linebytes;
127 addr += linebytes;
128 if (ctrlc()) {
129 rc = 1;
130 break;
131 }
132 } while (nbytes > 0);
133 } else
134# endif
135
136 {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000137 ulong bytes = size * length;
138 const void *buf = map_sysmem(addr, bytes);
139
Mike Frysingere578d682008-02-04 19:26:56 -0500140 /* Print the lines. */
Simon Glasse6d0ca22013-02-24 17:33:15 +0000141 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
142 addr += bytes;
143 unmap_sysmem(buf);
Mike Frysingere578d682008-02-04 19:26:56 -0500144 }
Grant Likely02a00782007-02-20 09:05:00 +0100145#endif
wdenk38635852002-08-27 05:55:31 +0000146
147 dp_last_addr = addr;
148 dp_last_length = length;
149 dp_last_size = size;
150 return (rc);
151}
152
Kim Phillipsdc00a682012-10-29 13:34:31 +0000153static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000154{
155 return mod_mem (cmdtp, 1, flag, argc, argv);
156}
Kim Phillipsdc00a682012-10-29 13:34:31 +0000157static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000158{
159 return mod_mem (cmdtp, 0, flag, argc, argv);
160}
161
Kim Phillipsdc00a682012-10-29 13:34:31 +0000162static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000163{
York Sun6c480012014-02-26 17:03:19 -0800164#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
165 u64 writeval;
166#else
167 ulong writeval;
168#endif
169 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000170 int size;
Simon Glass3c4a2872015-03-05 12:25:18 -0700171 void *buf, *start;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000172 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000173
Wolfgang Denk3b683112010-07-17 01:06:04 +0200174 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000175 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000176
177 /* Check for size specification.
178 */
wdenk874ac262003-07-24 23:38:38 +0000179 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
180 return 1;
wdenk38635852002-08-27 05:55:31 +0000181
182 /* Address is specified since argc > 1
183 */
184 addr = simple_strtoul(argv[1], NULL, 16);
185 addr += base_address;
186
187 /* Get the value to write.
188 */
York Sun6c480012014-02-26 17:03:19 -0800189#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
190 writeval = simple_strtoull(argv[2], NULL, 16);
191#else
wdenk38635852002-08-27 05:55:31 +0000192 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800193#endif
wdenk38635852002-08-27 05:55:31 +0000194
195 /* Count ? */
196 if (argc == 4) {
197 count = simple_strtoul(argv[3], NULL, 16);
198 } else {
199 count = 1;
200 }
201
Simon Glasse6d0ca22013-02-24 17:33:15 +0000202 bytes = size * count;
Simon Glass3c4a2872015-03-05 12:25:18 -0700203 start = map_sysmem(addr, bytes);
204 buf = start;
wdenk38635852002-08-27 05:55:31 +0000205 while (count-- > 0) {
206 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800207 *((u32 *)buf) = (u32)writeval;
York Sun6c480012014-02-26 17:03:19 -0800208#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
209 else if (size == 8)
210 *((u64 *)buf) = (u64)writeval;
211#endif
wdenk38635852002-08-27 05:55:31 +0000212 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800213 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000214 else
York Sund8a405d2014-02-12 15:55:35 -0800215 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000216 buf += size;
wdenk38635852002-08-27 05:55:31 +0000217 }
Simon Glass3c4a2872015-03-05 12:25:18 -0700218 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000219 return 0;
220}
221
stroesefb5e0ac2004-12-16 17:42:39 +0000222#ifdef CONFIG_MX_CYCLIC
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900223static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000224{
225 int i;
226 ulong count;
227
Wolfgang Denk3b683112010-07-17 01:06:04 +0200228 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000229 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000230
231 count = simple_strtoul(argv[3], NULL, 10);
232
233 for (;;) {
234 do_mem_md (NULL, 0, 3, argv);
235
236 /* delay for <count> ms... */
237 for (i=0; i<count; i++)
238 udelay (1000);
239
240 /* check for ctrl-c to abort... */
241 if (ctrlc()) {
242 puts("Abort\n");
243 return 0;
244 }
245 }
246
247 return 0;
248}
249
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900250static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000251{
252 int i;
253 ulong count;
254
Wolfgang Denk3b683112010-07-17 01:06:04 +0200255 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000256 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000257
258 count = simple_strtoul(argv[3], NULL, 10);
259
260 for (;;) {
261 do_mem_mw (NULL, 0, 3, argv);
262
263 /* delay for <count> ms... */
264 for (i=0; i<count; i++)
265 udelay (1000);
266
267 /* check for ctrl-c to abort... */
268 if (ctrlc()) {
269 puts("Abort\n");
270 return 0;
271 }
272 }
273
274 return 0;
275}
276#endif /* CONFIG_MX_CYCLIC */
277
Kim Phillipsdc00a682012-10-29 13:34:31 +0000278static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000279{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000280 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000281 int size;
wdenk38635852002-08-27 05:55:31 +0000282 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000283 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000284 const void *buf1, *buf2, *base;
York Sun6c480012014-02-26 17:03:19 -0800285#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
286 u64 word1, word2;
287#else
288 ulong word1, word2;
289#endif
wdenk38635852002-08-27 05:55:31 +0000290
Wolfgang Denk3b683112010-07-17 01:06:04 +0200291 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000292 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000293
294 /* Check for size specification.
295 */
wdenk874ac262003-07-24 23:38:38 +0000296 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
297 return 1;
York Sun6c480012014-02-26 17:03:19 -0800298 type = size == 8 ? "double word" :
299 size == 4 ? "word" :
300 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000301
302 addr1 = simple_strtoul(argv[1], NULL, 16);
303 addr1 += base_address;
304
305 addr2 = simple_strtoul(argv[2], NULL, 16);
306 addr2 += base_address;
307
308 count = simple_strtoul(argv[3], NULL, 16);
309
wdenk381669a2003-06-16 23:50:08 +0000310#ifdef CONFIG_HAS_DATAFLASH
311 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk42c05472004-03-23 22:14:11 +0000312 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000313 return 0;
314 }
315#endif
316
Mike Frysingere578d682008-02-04 19:26:56 -0500317#ifdef CONFIG_BLACKFIN
318 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
319 puts ("Comparison with L1 instruction memory not supported.\n\r");
320 return 0;
321 }
322#endif
323
Simon Glasse6d0ca22013-02-24 17:33:15 +0000324 bytes = size * count;
325 base = buf1 = map_sysmem(addr1, bytes);
326 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000327 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000328 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800329 word1 = *(u32 *)buf1;
330 word2 = *(u32 *)buf2;
York Sun6c480012014-02-26 17:03:19 -0800331#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
332 } else if (size == 8) {
333 word1 = *(u64 *)buf1;
334 word2 = *(u64 *)buf2;
335#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000336 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800337 word1 = *(u16 *)buf1;
338 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000339 } else {
York Sund8a405d2014-02-12 15:55:35 -0800340 word1 = *(u8 *)buf1;
341 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000342 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000343 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000344 ulong offset = buf1 - base;
York Sun6c480012014-02-26 17:03:19 -0800345#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
Simon Glasse9f343f2014-11-11 12:47:07 -0700346 printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
347 PRIx64 ")\n",
York Sun6c480012014-02-26 17:03:19 -0800348 type, (void *)(addr1 + offset), size, word1,
349 type, (void *)(addr2 + offset), size, word2);
350#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000351 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000352 type, (ulong)(addr1 + offset), size, word1,
353 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800354#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000355 rcode = 1;
356 break;
wdenk38635852002-08-27 05:55:31 +0000357 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000358
Simon Glasse6d0ca22013-02-24 17:33:15 +0000359 buf1 += size;
360 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200361
362 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000363 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200364 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000365 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000366 unmap_sysmem(buf1);
367 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000368
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000369 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000370 return rcode;
371}
372
Kim Phillipsdc00a682012-10-29 13:34:31 +0000373static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000374{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000375 ulong addr, dest, count, bytes;
wdenk874ac262003-07-24 23:38:38 +0000376 int size;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000377 const void *src;
378 void *buf;
wdenk38635852002-08-27 05:55:31 +0000379
Wolfgang Denk3b683112010-07-17 01:06:04 +0200380 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000381 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000382
383 /* Check for size specification.
384 */
wdenk874ac262003-07-24 23:38:38 +0000385 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
386 return 1;
wdenk38635852002-08-27 05:55:31 +0000387
388 addr = simple_strtoul(argv[1], NULL, 16);
389 addr += base_address;
390
391 dest = simple_strtoul(argv[2], NULL, 16);
392 dest += base_address;
393
394 count = simple_strtoul(argv[3], NULL, 16);
395
396 if (count == 0) {
397 puts ("Zero length ???\n");
398 return 1;
399 }
400
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200401#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000402 /* check if we are copying to Flash */
wdenk381669a2003-06-16 23:50:08 +0000403 if ( (addr2info(dest) != NULL)
404#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino1eb0fd52008-03-03 10:39:13 +0200405 && (!addr_dataflash(dest))
wdenk381669a2003-06-16 23:50:08 +0000406#endif
407 ) {
wdenk38635852002-08-27 05:55:31 +0000408 int rc;
409
wdenk42c05472004-03-23 22:14:11 +0000410 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000411
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200412 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000413 if (rc != 0) {
414 flash_perror (rc);
415 return (1);
416 }
417 puts ("done\n");
418 return 0;
419 }
420#endif
421
wdenk381669a2003-06-16 23:50:08 +0000422#ifdef CONFIG_HAS_DATAFLASH
423 /* Check if we are copying from RAM or Flash to DataFlash */
424 if (addr_dataflash(dest) && !addr_dataflash(addr)){
425 int rc;
426
wdenk42c05472004-03-23 22:14:11 +0000427 puts ("Copy to DataFlash... ");
wdenk381669a2003-06-16 23:50:08 +0000428
429 rc = write_dataflash (dest, addr, count*size);
430
431 if (rc != 1) {
432 dataflash_perror (rc);
433 return (1);
434 }
435 puts ("done\n");
436 return 0;
437 }
wdenk57b2d802003-06-27 21:31:46 +0000438
wdenk381669a2003-06-16 23:50:08 +0000439 /* Check if we are copying from DataFlash to RAM */
Stelian Popa63d2eb2008-03-26 22:52:35 +0100440 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200441#ifndef CONFIG_SYS_NO_FLASH
Stelian Popa63d2eb2008-03-26 22:52:35 +0100442 && (addr2info(dest) == NULL)
443#endif
444 ){
wdenk86765902003-12-06 23:55:10 +0000445 int rc;
446 rc = read_dataflash(addr, count * size, (char *) dest);
447 if (rc != 1) {
wdenk1ebf41e2004-01-02 14:00:00 +0000448 dataflash_perror (rc);
449 return (1);
450 }
wdenk381669a2003-06-16 23:50:08 +0000451 return 0;
452 }
453
454 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk42c05472004-03-23 22:14:11 +0000455 puts ("Unsupported combination of source/destination.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000456 return 1;
457 }
wdenk7a428cc2003-06-15 22:40:42 +0000458#endif
459
Mike Frysingere578d682008-02-04 19:26:56 -0500460#ifdef CONFIG_BLACKFIN
461 /* See if we're copying to/from L1 inst */
462 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
463 memcpy((void *)dest, (void *)addr, count * size);
464 return 0;
465 }
466#endif
467
Simon Glasse6d0ca22013-02-24 17:33:15 +0000468 bytes = size * count;
Masahiro Yamada4ad7dd52013-05-20 21:08:08 +0000469 buf = map_sysmem(dest, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +0000470 src = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000471 while (count-- > 0) {
472 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800473 *((u32 *)buf) = *((u32 *)src);
York Sun6c480012014-02-26 17:03:19 -0800474#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
475 else if (size == 8)
476 *((u64 *)buf) = *((u64 *)src);
477#endif
wdenk38635852002-08-27 05:55:31 +0000478 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800479 *((u16 *)buf) = *((u16 *)src);
wdenk38635852002-08-27 05:55:31 +0000480 else
York Sund8a405d2014-02-12 15:55:35 -0800481 *((u8 *)buf) = *((u8 *)src);
Simon Glasse6d0ca22013-02-24 17:33:15 +0000482 src += size;
483 buf += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200484
485 /* reset watchdog from time to time */
486 if ((count % (64 << 10)) == 0)
487 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000488 }
Masahiro Yamada787b0c52014-10-23 17:46:24 +0900489 unmap_sysmem(buf);
490 unmap_sysmem(src);
491
wdenk38635852002-08-27 05:55:31 +0000492 return 0;
493}
494
Kim Phillipsdc00a682012-10-29 13:34:31 +0000495static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
496 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000497{
498 if (argc > 1) {
499 /* Set new base address.
500 */
501 base_address = simple_strtoul(argv[1], NULL, 16);
502 }
503 /* Print the current base address.
504 */
505 printf("Base Address: 0x%08lx\n", base_address);
506 return 0;
507}
508
Kim Phillipsdc00a682012-10-29 13:34:31 +0000509static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
510 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000511{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000512 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000513 int size;
York Sun6c480012014-02-26 17:03:19 -0800514#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
515 volatile u64 *llp;
516#endif
York Sund8a405d2014-02-12 15:55:35 -0800517 volatile u32 *longp;
518 volatile u16 *shortp;
519 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000520 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000521
Wolfgang Denk3b683112010-07-17 01:06:04 +0200522 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000523 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000524
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000525 /*
526 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000527 * Defaults to long if no or incorrect specification.
528 */
wdenk874ac262003-07-24 23:38:38 +0000529 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
530 return 1;
wdenk38635852002-08-27 05:55:31 +0000531
532 /* Address is always specified.
533 */
534 addr = simple_strtoul(argv[1], NULL, 16);
535
536 /* Length is the number of objects, not number of bytes.
537 */
538 length = simple_strtoul(argv[2], NULL, 16);
539
Simon Glasse6d0ca22013-02-24 17:33:15 +0000540 bytes = size * length;
541 buf = map_sysmem(addr, bytes);
542
wdenk38635852002-08-27 05:55:31 +0000543 /* We want to optimize the loops to run as fast as possible.
544 * If we have only one object, just run infinite loops.
545 */
546 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800547#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
548 if (size == 8) {
549 llp = (u64 *)buf;
550 for (;;)
551 i = *llp;
552 }
553#endif
wdenk38635852002-08-27 05:55:31 +0000554 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800555 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000556 for (;;)
557 i = *longp;
558 }
559 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800560 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000561 for (;;)
562 i = *shortp;
563 }
York Sund8a405d2014-02-12 15:55:35 -0800564 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000565 for (;;)
566 i = *cp;
567 }
568
York Sun6c480012014-02-26 17:03:19 -0800569#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
570 if (size == 8) {
571 for (;;) {
572 llp = (u64 *)buf;
573 i = length;
574 while (i-- > 0)
575 *llp++;
576 }
577 }
578#endif
wdenk38635852002-08-27 05:55:31 +0000579 if (size == 4) {
580 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800581 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000582 i = length;
583 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200584 *longp++;
wdenk38635852002-08-27 05:55:31 +0000585 }
586 }
587 if (size == 2) {
588 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800589 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000590 i = length;
591 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200592 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000593 }
594 }
595 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800596 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000597 i = length;
598 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200599 *cp++;
wdenk38635852002-08-27 05:55:31 +0000600 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000601 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700602
603 return 0;
wdenk38635852002-08-27 05:55:31 +0000604}
605
wdenk64519362004-07-11 17:40:54 +0000606#ifdef CONFIG_LOOPW
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900607static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
608 char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000609{
York Sun6c480012014-02-26 17:03:19 -0800610 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000611 int size;
York Sun6c480012014-02-26 17:03:19 -0800612#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
613 volatile u64 *llp;
614 u64 data;
615#else
616 ulong data;
617#endif
York Sund8a405d2014-02-12 15:55:35 -0800618 volatile u32 *longp;
619 volatile u16 *shortp;
620 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000621 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000622
Wolfgang Denk3b683112010-07-17 01:06:04 +0200623 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000624 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000625
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000626 /*
627 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000628 * Defaults to long if no or incorrect specification.
629 */
630 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
631 return 1;
632
633 /* Address is always specified.
634 */
635 addr = simple_strtoul(argv[1], NULL, 16);
636
637 /* Length is the number of objects, not number of bytes.
638 */
639 length = simple_strtoul(argv[2], NULL, 16);
640
641 /* data to write */
York Sun6c480012014-02-26 17:03:19 -0800642#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
643 data = simple_strtoull(argv[3], NULL, 16);
644#else
wdenk64519362004-07-11 17:40:54 +0000645 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800646#endif
wdenk7dd13292004-07-11 20:04:51 +0000647
Simon Glasse6d0ca22013-02-24 17:33:15 +0000648 bytes = size * length;
649 buf = map_sysmem(addr, bytes);
650
wdenk64519362004-07-11 17:40:54 +0000651 /* We want to optimize the loops to run as fast as possible.
652 * If we have only one object, just run infinite loops.
653 */
654 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800655#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
656 if (size == 8) {
657 llp = (u64 *)buf;
658 for (;;)
659 *llp = data;
660 }
661#endif
wdenk64519362004-07-11 17:40:54 +0000662 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800663 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000664 for (;;)
665 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800666 }
wdenk64519362004-07-11 17:40:54 +0000667 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800668 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000669 for (;;)
670 *shortp = data;
671 }
York Sund8a405d2014-02-12 15:55:35 -0800672 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000673 for (;;)
674 *cp = data;
675 }
676
York Sun6c480012014-02-26 17:03:19 -0800677#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
678 if (size == 8) {
679 for (;;) {
680 llp = (u64 *)buf;
681 i = length;
682 while (i-- > 0)
683 *llp++ = data;
684 }
685 }
686#endif
wdenk64519362004-07-11 17:40:54 +0000687 if (size == 4) {
688 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800689 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000690 i = length;
691 while (i-- > 0)
692 *longp++ = data;
693 }
694 }
695 if (size == 2) {
696 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800697 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000698 i = length;
699 while (i-- > 0)
700 *shortp++ = data;
701 }
702 }
703 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800704 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000705 i = length;
706 while (i-- > 0)
707 *cp++ = data;
708 }
709}
710#endif /* CONFIG_LOOPW */
711
Tom Rinia5f02702013-03-12 10:07:19 -0400712#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000713static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
714 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000715{
Simon Glass8f2c7582013-02-24 17:33:16 +0000716 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000717 ulong errs = 0;
718 ulong val, readback;
719 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000720 vu_long offset;
721 vu_long test_offset;
722 vu_long pattern;
723 vu_long temp;
724 vu_long anti_pattern;
725 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000726 static const ulong bitpattern[] = {
727 0x00000001, /* single bit */
728 0x00000003, /* two adjacent bits */
729 0x00000007, /* three adjacent bits */
730 0x0000000F, /* four adjacent bits */
731 0x00000005, /* two non-adjacent bits */
732 0x00000015, /* three non-adjacent bits */
733 0x00000055, /* four non-adjacent bits */
734 0xaaaaaaaa, /* alternating 1/0 */
735 };
wdenk38635852002-08-27 05:55:31 +0000736
Simon Glassad02a012013-02-28 17:47:14 +0000737 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000738
Simon Glass130103e2013-02-24 17:33:18 +0000739 /*
740 * Data line test: write a pattern to the first
741 * location, write the 1's complement to a 'parking'
742 * address (changes the state of the data bus so a
743 * floating bus doesn't give a false OK), and then
744 * read the value back. Note that we read it back
745 * into a variable because the next time we read it,
746 * it might be right (been there, tough to explain to
747 * the quality guys why it prints a failure when the
748 * "is" and "should be" are obviously the same in the
749 * error message).
750 *
751 * Rather than exhaustively testing, we test some
752 * patterns by shifting '1' bits through a field of
753 * '0's and '0' bits through a field of '1's (i.e.
754 * pattern and ~pattern).
755 */
Simon Glassad02a012013-02-28 17:47:14 +0000756 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000757 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
758 val = bitpattern[j];
759 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000760 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000761 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000762 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000763 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000764 printf("FAILURE (data line): "
765 "expected %08lx, actual %08lx\n",
766 val, readback);
767 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000768 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000769 return -1;
wdenk38635852002-08-27 05:55:31 +0000770 }
771 *addr = ~val;
772 *dummy = val;
773 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000774 if (readback != ~val) {
775 printf("FAILURE (data line): "
776 "Is %08lx, should be %08lx\n",
777 readback, ~val);
778 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000779 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000780 return -1;
wdenk38635852002-08-27 05:55:31 +0000781 }
wdenk38635852002-08-27 05:55:31 +0000782 }
Simon Glass130103e2013-02-24 17:33:18 +0000783 }
wdenk38635852002-08-27 05:55:31 +0000784
Simon Glass130103e2013-02-24 17:33:18 +0000785 /*
786 * Based on code whose Original Author and Copyright
787 * information follows: Copyright (c) 1998 by Michael
788 * Barr. This software is placed into the public
789 * domain and may be used for any purpose. However,
790 * this notice must not be changed or removed and no
791 * warranty is either expressed or implied by its
792 * publication or distribution.
793 */
wdenk38635852002-08-27 05:55:31 +0000794
Simon Glass130103e2013-02-24 17:33:18 +0000795 /*
796 * Address line test
wdenk38635852002-08-27 05:55:31 +0000797
Simon Glass130103e2013-02-24 17:33:18 +0000798 * Description: Test the address bus wiring in a
799 * memory region by performing a walking
800 * 1's test on the relevant bits of the
801 * address and checking for aliasing.
802 * This test will find single-bit
803 * address failures such as stuck-high,
804 * stuck-low, and shorted pins. The base
805 * address and size of the region are
806 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000807
Simon Glass130103e2013-02-24 17:33:18 +0000808 * Notes: For best results, the selected base
809 * address should have enough LSB 0's to
810 * guarantee single address bit changes.
811 * For example, to test a 64-Kbyte
812 * region, select a base address on a
813 * 64-Kbyte boundary. Also, select the
814 * region size as a power-of-two if at
815 * all possible.
816 *
817 * Returns: 0 if the test succeeds, 1 if the test fails.
818 */
Simon Glass130103e2013-02-24 17:33:18 +0000819 pattern = (vu_long) 0xaaaaaaaa;
820 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000821
Simon Glassad02a012013-02-28 17:47:14 +0000822 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000823 /*
824 * Write the default pattern at each of the
825 * power-of-two offsets.
826 */
Simon Glassad02a012013-02-28 17:47:14 +0000827 for (offset = 1; offset < num_words; offset <<= 1)
828 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000829
830 /*
831 * Check for address bits stuck high.
832 */
833 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000834 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000835
Simon Glassad02a012013-02-28 17:47:14 +0000836 for (offset = 1; offset < num_words; offset <<= 1) {
837 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000838 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000839 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000840 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800841 start_addr + offset*sizeof(vu_long),
842 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400843 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000844 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000845 return -1;
wdenk38635852002-08-27 05:55:31 +0000846 }
Simon Glass130103e2013-02-24 17:33:18 +0000847 }
Simon Glassad02a012013-02-28 17:47:14 +0000848 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000849 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000850
Simon Glass130103e2013-02-24 17:33:18 +0000851 /*
852 * Check for addr bits stuck low or shorted.
853 */
Simon Glassad02a012013-02-28 17:47:14 +0000854 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
855 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000856
Simon Glassad02a012013-02-28 17:47:14 +0000857 for (offset = 1; offset < num_words; offset <<= 1) {
858 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000859 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000860 printf("\nFAILURE: Address bit stuck low or"
861 " shorted @ 0x%.8lx: expected 0x%.8lx,"
862 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800863 start_addr + offset*sizeof(vu_long),
864 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000865 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000866 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000867 return -1;
wdenk38635852002-08-27 05:55:31 +0000868 }
wdenk38635852002-08-27 05:55:31 +0000869 }
Simon Glassad02a012013-02-28 17:47:14 +0000870 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000871 }
wdenk38635852002-08-27 05:55:31 +0000872
Simon Glass130103e2013-02-24 17:33:18 +0000873 /*
874 * Description: Test the integrity of a physical
875 * memory device by performing an
876 * increment/decrement test over the
877 * entire region. In the process every
878 * storage bit in the device is tested
879 * as a zero and a one. The base address
880 * and the size of the region are
881 * selected by the caller.
882 *
883 * Returns: 0 if the test succeeds, 1 if the test fails.
884 */
Simon Glassad02a012013-02-28 17:47:14 +0000885 num_words++;
wdenk38635852002-08-27 05:55:31 +0000886
Simon Glass130103e2013-02-24 17:33:18 +0000887 /*
888 * Fill memory with a known pattern.
889 */
890 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
891 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000892 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000893 }
wdenk38635852002-08-27 05:55:31 +0000894
Simon Glass130103e2013-02-24 17:33:18 +0000895 /*
896 * Check each location and invert it for the second pass.
897 */
898 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
899 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000900 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000901 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000902 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000903 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800904 start_addr + offset*sizeof(vu_long),
905 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400906 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000907 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000908 return -1;
wdenk38635852002-08-27 05:55:31 +0000909 }
910
Simon Glass130103e2013-02-24 17:33:18 +0000911 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000912 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000913 }
914
915 /*
916 * Check each location for the inverted pattern and zero it.
917 */
918 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
919 WATCHDOG_RESET();
920 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000921 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000922 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000923 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000924 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800925 start_addr + offset*sizeof(vu_long),
926 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400927 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000928 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000929 return -1;
wdenk38635852002-08-27 05:55:31 +0000930 }
Simon Glassad02a012013-02-28 17:47:14 +0000931 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000932 }
Simon Glass57ee4432013-02-24 17:33:17 +0000933
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100934 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000935}
936
Simon Glassad02a012013-02-28 17:47:14 +0000937static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
938 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000939{
Simon Glassad02a012013-02-28 17:47:14 +0000940 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000941 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000942 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000943 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000944 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000945
Simon Glass57ee4432013-02-24 17:33:17 +0000946 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000947 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000948 if (iteration & 1) {
949 incr = -incr;
950 /*
951 * Flip the pattern each time to make lots of zeros and
952 * then, the next time, lots of ones. We decrement
953 * the "negative" patterns and increment the "positive"
954 * patterns to preserve this feature.
955 */
956 if (pattern & 0x80000000)
957 pattern = -pattern; /* complement & increment */
958 else
959 pattern = ~pattern;
960 }
Simon Glassad02a012013-02-28 17:47:14 +0000961 length = (end_addr - start_addr) / sizeof(ulong);
962 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000963 printf("\rPattern %08lX Writing..."
964 "%12s"
965 "\b\b\b\b\b\b\b\b\b\b",
966 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000967
Simon Glassad02a012013-02-28 17:47:14 +0000968 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000969 WATCHDOG_RESET();
970 *addr = val;
971 val += incr;
972 }
wdenk38635852002-08-27 05:55:31 +0000973
Simon Glass130103e2013-02-24 17:33:18 +0000974 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000975
Simon Glassad02a012013-02-28 17:47:14 +0000976 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000977 WATCHDOG_RESET();
978 readback = *addr;
979 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000980 ulong offset = addr - buf;
981
Simon Glass130103e2013-02-24 17:33:18 +0000982 printf("\nMem error @ 0x%08X: "
983 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800984 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000985 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000986 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000987 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000988 return -1;
wdenk38635852002-08-27 05:55:31 +0000989 }
Simon Glass130103e2013-02-24 17:33:18 +0000990 val += incr;
991 }
wdenk38635852002-08-27 05:55:31 +0000992
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100993 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000994}
995
996/*
997 * Perform a memory test. A more complete alternative test can be
998 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
999 * interrupted by ctrl-c or by a failure of one of the sub-tests.
1000 */
1001static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
1002 char * const argv[])
1003{
Simon Glass51075252013-02-24 17:33:20 +00001004 ulong start, end;
Simon Glassad02a012013-02-28 17:47:14 +00001005 vu_long *buf, *dummy;
Tom Rinib9180882015-04-07 09:38:54 -04001006 ulong iteration_limit = 0;
Simon Glass8f2c7582013-02-24 17:33:16 +00001007 int ret;
Simon Glass57ee4432013-02-24 17:33:17 +00001008 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Machekd319f592015-04-01 13:50:41 +02001009 ulong pattern = 0;
Simon Glass57ee4432013-02-24 17:33:17 +00001010 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +00001011#if defined(CONFIG_SYS_ALT_MEMTEST)
1012 const int alt_test = 1;
1013#else
1014 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +00001015#endif
Simon Glass8f2c7582013-02-24 17:33:16 +00001016
Pavel Machekd319f592015-04-01 13:50:41 +02001017 start = CONFIG_SYS_MEMTEST_START;
1018 end = CONFIG_SYS_MEMTEST_END;
1019
Simon Glass8f2c7582013-02-24 17:33:16 +00001020 if (argc > 1)
Pavel Machekd319f592015-04-01 13:50:41 +02001021 if (strict_strtoul(argv[1], 16, &start) < 0)
1022 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +00001023
1024 if (argc > 2)
Pavel Machekd319f592015-04-01 13:50:41 +02001025 if (strict_strtoul(argv[2], 16, &end) < 0)
1026 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +00001027
1028 if (argc > 3)
Pavel Machekd319f592015-04-01 13:50:41 +02001029 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1030 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +00001031
1032 if (argc > 4)
Pavel Machekd319f592015-04-01 13:50:41 +02001033 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
1034 return CMD_RET_USAGE;
1035
1036 if (end < start) {
1037 printf("Refusing to do empty test\n");
1038 return -1;
1039 }
Simon Glass8f2c7582013-02-24 17:33:16 +00001040
Simon Glass51075252013-02-24 17:33:20 +00001041 printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
1042 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1043 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +00001044
Simon Glassad02a012013-02-28 17:47:14 +00001045 buf = map_sysmem(start, end - start);
1046 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass57ee4432013-02-24 17:33:17 +00001047 for (iteration = 0;
1048 !iteration_limit || iteration < iteration_limit;
1049 iteration++) {
1050 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +00001051 errs = -1UL;
1052 break;
1053 }
1054
1055 printf("Iteration: %6d\r", iteration + 1);
1056 debug("\n");
Simon Glassad02a012013-02-28 17:47:14 +00001057 if (alt_test) {
1058 errs = mem_test_alt(buf, start, end, dummy);
1059 } else {
1060 errs = mem_test_quick(buf, start, end, pattern,
1061 iteration);
1062 }
1063 if (errs == -1UL)
1064 break;
1065 }
1066
1067 /*
1068 * Work-around for eldk-4.2 which gives this warning if we try to
1069 * case in the unmap_sysmem() call:
1070 * warning: initialization discards qualifiers from pointer target type
1071 */
1072 {
1073 void *vbuf = (void *)buf;
1074 void *vdummy = (void *)dummy;
1075
1076 unmap_sysmem(vbuf);
1077 unmap_sysmem(vdummy);
Simon Glass57ee4432013-02-24 17:33:17 +00001078 }
1079
1080 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001081 /* Memory test was aborted - write a newline to finish off */
1082 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001083 ret = 1;
1084 } else {
1085 printf("Tested %d iteration(s) with %lu errors.\n",
1086 iteration, errs);
1087 ret = errs != 0;
1088 }
Simon Glass8f2c7582013-02-24 17:33:16 +00001089
Pavel Machekd319f592015-04-01 13:50:41 +02001090 return ret;
wdenk38635852002-08-27 05:55:31 +00001091}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001092#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001093
1094/* Modify memory.
1095 *
1096 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001097 * mm{.b, .w, .l, .q} {addr}
1098 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001099 */
1100static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001101mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001102{
York Sun6c480012014-02-26 17:03:19 -08001103 ulong addr;
1104#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1105 u64 i;
1106#else
1107 ulong i;
1108#endif
wdenk874ac262003-07-24 23:38:38 +00001109 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001110 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001111
Wolfgang Denk3b683112010-07-17 01:06:04 +02001112 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001113 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001114
Simon Glass09007c42014-04-10 20:01:31 -06001115 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001116 /* We use the last specified parameters, unless new ones are
1117 * entered.
1118 */
1119 addr = mm_last_addr;
1120 size = mm_last_size;
1121
1122 if ((flag & CMD_FLAG_REPEAT) == 0) {
1123 /* New command specified. Check for a size specification.
1124 * Defaults to long if no or incorrect specification.
1125 */
wdenk874ac262003-07-24 23:38:38 +00001126 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1127 return 1;
wdenk38635852002-08-27 05:55:31 +00001128
1129 /* Address is specified since argc > 1
1130 */
1131 addr = simple_strtoul(argv[1], NULL, 16);
1132 addr += base_address;
1133 }
1134
wdenk381669a2003-06-16 23:50:08 +00001135#ifdef CONFIG_HAS_DATAFLASH
1136 if (addr_dataflash(addr)){
wdenk42c05472004-03-23 22:14:11 +00001137 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk381669a2003-06-16 23:50:08 +00001138 return 0;
1139 }
1140#endif
1141
Mike Frysingere578d682008-02-04 19:26:56 -05001142#ifdef CONFIG_BLACKFIN
1143 if (addr_bfin_on_chip_mem(addr)) {
1144 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1145 return 0;
1146 }
1147#endif
1148
wdenk38635852002-08-27 05:55:31 +00001149 /* Print the address, followed by value. Then accept input for
1150 * the next value. A non-converted value exits.
1151 */
1152 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001153 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001154 printf("%08lx:", addr);
1155 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001156 printf(" %08x", *((u32 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001157#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1158 else if (size == 8)
Simon Glasse9f343f2014-11-11 12:47:07 -07001159 printf(" %016" PRIx64, *((u64 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001160#endif
wdenk38635852002-08-27 05:55:31 +00001161 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001162 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001163 else
York Sund8a405d2014-02-12 15:55:35 -08001164 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001165
Simon Glassbe6aafc2014-04-10 20:01:27 -06001166 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001167 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1168 /* <CR> pressed as only input, don't modify current
1169 * location and move to next. "-" pressed will go back.
1170 */
1171 if (incrflag)
1172 addr += nbytes ? -size : size;
1173 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001174 /* good enough to not time out */
1175 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001176 }
1177#ifdef CONFIG_BOOT_RETRY_TIME
1178 else if (nbytes == -2) {
1179 break; /* timed out, exit the command */
1180 }
1181#endif
1182 else {
1183 char *endp;
York Sun6c480012014-02-26 17:03:19 -08001184#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1185 i = simple_strtoull(console_buffer, &endp, 16);
1186#else
wdenk38635852002-08-27 05:55:31 +00001187 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001188#endif
wdenk38635852002-08-27 05:55:31 +00001189 nbytes = endp - console_buffer;
1190 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001191 /* good enough to not time out
1192 */
Simon Glass09007c42014-04-10 20:01:31 -06001193 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001194 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001195 *((u32 *)ptr) = i;
York Sun6c480012014-02-26 17:03:19 -08001196#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1197 else if (size == 8)
1198 *((u64 *)ptr) = i;
1199#endif
wdenk38635852002-08-27 05:55:31 +00001200 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001201 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001202 else
York Sund8a405d2014-02-12 15:55:35 -08001203 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001204 if (incrflag)
1205 addr += size;
1206 }
1207 }
1208 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001209 if (ptr)
1210 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001211
1212 mm_last_addr = addr;
1213 mm_last_size = size;
1214 return 0;
1215}
1216
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001217#ifdef CONFIG_CMD_CRC32
1218
Kim Phillipsdc00a682012-10-29 13:34:31 +00001219static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001220{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001221 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001222 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001223 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001224
Simon Glass0bbd76f2013-02-24 20:30:22 +00001225 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001226 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001227
1228 av = argv + 1;
1229 ac = argc - 1;
Simon Glass0bbd76f2013-02-24 20:30:22 +00001230#ifdef CONFIG_HASH_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001231 if (strcmp(*av, "-v") == 0) {
Joe Hershberger5fcee9a2015-05-05 12:23:53 -05001232 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenk6203e402004-04-18 10:13:26 +00001233 av++;
1234 ac--;
wdenk6203e402004-04-18 10:13:26 +00001235 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001236#endif
wdenk6203e402004-04-18 10:13:26 +00001237
Simon Glass0bbd76f2013-02-24 20:30:22 +00001238 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001239}
wdenk6203e402004-04-18 10:13:26 +00001240
Robin Getz93d6cb02009-07-27 00:07:59 -04001241#endif
1242
wdenk57b2d802003-06-27 21:31:46 +00001243/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001244U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001245 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001246 "memory display",
York Sun6c480012014-02-26 17:03:19 -08001247#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1248 "[.b, .w, .l, .q] address [# of objects]"
1249#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001250 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001251#endif
wdenk57b2d802003-06-27 21:31:46 +00001252);
1253
1254
wdenkf287a242003-07-01 21:06:45 +00001255U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001256 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001257 "memory modify (auto-incrementing address)",
York Sun6c480012014-02-26 17:03:19 -08001258#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1259 "[.b, .w, .l, .q] address"
1260#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001261 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001262#endif
wdenk57b2d802003-06-27 21:31:46 +00001263);
1264
1265
wdenkf287a242003-07-01 21:06:45 +00001266U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001267 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001268 "memory modify (constant address)",
York Sun6c480012014-02-26 17:03:19 -08001269#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1270 "[.b, .w, .l, .q] address"
1271#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001272 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001273#endif
wdenk57b2d802003-06-27 21:31:46 +00001274);
1275
wdenkf287a242003-07-01 21:06:45 +00001276U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001277 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001278 "memory write (fill)",
York Sun6c480012014-02-26 17:03:19 -08001279#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1280 "[.b, .w, .l, .q] address value [count]"
1281#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001282 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001283#endif
wdenk57b2d802003-06-27 21:31:46 +00001284);
1285
wdenkf287a242003-07-01 21:06:45 +00001286U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001287 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001288 "memory copy",
York Sun6c480012014-02-26 17:03:19 -08001289#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1290 "[.b, .w, .l, .q] source target count"
1291#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001292 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001293#endif
wdenk57b2d802003-06-27 21:31:46 +00001294);
1295
wdenkf287a242003-07-01 21:06:45 +00001296U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001297 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001298 "memory compare",
York Sun6c480012014-02-26 17:03:19 -08001299#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1300 "[.b, .w, .l, .q] addr1 addr2 count"
1301#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001302 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001303#endif
wdenk57b2d802003-06-27 21:31:46 +00001304);
1305
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001306#ifdef CONFIG_CMD_CRC32
1307
Joe Hershbergerf62c1ec2015-05-05 12:23:52 -05001308#ifndef CONFIG_HASH_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001309
wdenkf287a242003-07-01 21:06:45 +00001310U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001311 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001312 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001313 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001314);
1315
Joe Hershbergerf62c1ec2015-05-05 12:23:52 -05001316#else /* CONFIG_HASH_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001317
1318U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001319 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001320 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001321 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001322 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001323);
1324
Joe Hershbergerf62c1ec2015-05-05 12:23:52 -05001325#endif /* CONFIG_HASH_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001326
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001327#endif
1328
Simon Glasseacd14f2012-11-30 13:01:20 +00001329#ifdef CONFIG_CMD_MEMINFO
Andrew Bradfordec9dbc92015-05-22 08:30:14 -04001330__weak void board_show_dram(phys_size_t size)
Simon Glasseacd14f2012-11-30 13:01:20 +00001331{
1332 puts("DRAM: ");
1333 print_size(size, "\n");
1334}
1335
1336static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1337 char * const argv[])
1338{
1339 board_show_dram(gd->ram_size);
1340
1341 return 0;
1342}
1343#endif
1344
wdenkf287a242003-07-01 21:06:45 +00001345U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001346 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001347 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001348 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001349 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001350);
1351
wdenkf287a242003-07-01 21:06:45 +00001352U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001353 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001354 "infinite loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001355#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1356 "[.b, .w, .l, .q] address number_of_objects"
1357#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001358 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001359#endif
wdenk57b2d802003-06-27 21:31:46 +00001360);
wdenk64519362004-07-11 17:40:54 +00001361
1362#ifdef CONFIG_LOOPW
1363U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001364 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001365 "infinite write loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001366#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1367 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1368#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001369 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001370#endif
wdenk64519362004-07-11 17:40:54 +00001371);
1372#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001373
Wolfgang Denk9d009282013-03-08 10:51:32 +00001374#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001375U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001376 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001377 "simple RAM read/write test",
1378 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001379);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001380#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001381
1382#ifdef CONFIG_MX_CYCLIC
1383U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001384 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001385 "memory display cyclic",
York Sun6c480012014-02-26 17:03:19 -08001386#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1387 "[.b, .w, .l, .q] address count delay(ms)"
1388#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001389 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001390#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001391);
1392
1393U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001394 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001395 "memory write cyclic",
York Sun6c480012014-02-26 17:03:19 -08001396#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1397 "[.b, .w, .l, .q] address value delay(ms)"
1398#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001399 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001400#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001401);
1402#endif /* CONFIG_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001403
1404#ifdef CONFIG_CMD_MEMINFO
1405U_BOOT_CMD(
1406 meminfo, 3, 1, do_mem_info,
1407 "display memory information",
1408 ""
1409);
1410#endif