blob: ff6a7709d2070bda873d0f28e1a06869f9a5d771 [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{
Fabio Estevamb03b0c82016-12-15 16:00:13 -0200375 ulong addr, dest, count;
wdenk874ac262003-07-24 23:38:38 +0000376 int size;
wdenk38635852002-08-27 05:55:31 +0000377
Wolfgang Denk3b683112010-07-17 01:06:04 +0200378 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000379 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000380
381 /* Check for size specification.
382 */
wdenk874ac262003-07-24 23:38:38 +0000383 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
384 return 1;
wdenk38635852002-08-27 05:55:31 +0000385
386 addr = simple_strtoul(argv[1], NULL, 16);
387 addr += base_address;
388
389 dest = simple_strtoul(argv[2], NULL, 16);
390 dest += base_address;
391
392 count = simple_strtoul(argv[3], NULL, 16);
393
394 if (count == 0) {
395 puts ("Zero length ???\n");
396 return 1;
397 }
398
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200399#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000400 /* check if we are copying to Flash */
wdenk381669a2003-06-16 23:50:08 +0000401 if ( (addr2info(dest) != NULL)
402#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino1eb0fd52008-03-03 10:39:13 +0200403 && (!addr_dataflash(dest))
wdenk381669a2003-06-16 23:50:08 +0000404#endif
405 ) {
wdenk38635852002-08-27 05:55:31 +0000406 int rc;
407
wdenk42c05472004-03-23 22:14:11 +0000408 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000409
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200410 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000411 if (rc != 0) {
412 flash_perror (rc);
413 return (1);
414 }
415 puts ("done\n");
416 return 0;
417 }
418#endif
419
wdenk381669a2003-06-16 23:50:08 +0000420#ifdef CONFIG_HAS_DATAFLASH
421 /* Check if we are copying from RAM or Flash to DataFlash */
422 if (addr_dataflash(dest) && !addr_dataflash(addr)){
423 int rc;
424
wdenk42c05472004-03-23 22:14:11 +0000425 puts ("Copy to DataFlash... ");
wdenk381669a2003-06-16 23:50:08 +0000426
427 rc = write_dataflash (dest, addr, count*size);
428
429 if (rc != 1) {
430 dataflash_perror (rc);
431 return (1);
432 }
433 puts ("done\n");
434 return 0;
435 }
wdenk57b2d802003-06-27 21:31:46 +0000436
wdenk381669a2003-06-16 23:50:08 +0000437 /* Check if we are copying from DataFlash to RAM */
Stelian Popa63d2eb2008-03-26 22:52:35 +0100438 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200439#ifndef CONFIG_SYS_NO_FLASH
Stelian Popa63d2eb2008-03-26 22:52:35 +0100440 && (addr2info(dest) == NULL)
441#endif
442 ){
wdenk86765902003-12-06 23:55:10 +0000443 int rc;
444 rc = read_dataflash(addr, count * size, (char *) dest);
445 if (rc != 1) {
wdenk1ebf41e2004-01-02 14:00:00 +0000446 dataflash_perror (rc);
447 return (1);
448 }
wdenk381669a2003-06-16 23:50:08 +0000449 return 0;
450 }
451
452 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk42c05472004-03-23 22:14:11 +0000453 puts ("Unsupported combination of source/destination.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000454 return 1;
455 }
wdenk7a428cc2003-06-15 22:40:42 +0000456#endif
457
Mike Frysingere578d682008-02-04 19:26:56 -0500458#ifdef CONFIG_BLACKFIN
459 /* See if we're copying to/from L1 inst */
460 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
461 memcpy((void *)dest, (void *)addr, count * size);
462 return 0;
463 }
464#endif
465
Fabio Estevamb03b0c82016-12-15 16:00:13 -0200466 memcpy((void *)dest, (void *)addr, count * size);
Masahiro Yamada787b0c52014-10-23 17:46:24 +0900467
wdenk38635852002-08-27 05:55:31 +0000468 return 0;
469}
470
Kim Phillipsdc00a682012-10-29 13:34:31 +0000471static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
472 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000473{
474 if (argc > 1) {
475 /* Set new base address.
476 */
477 base_address = simple_strtoul(argv[1], NULL, 16);
478 }
479 /* Print the current base address.
480 */
481 printf("Base Address: 0x%08lx\n", base_address);
482 return 0;
483}
484
Kim Phillipsdc00a682012-10-29 13:34:31 +0000485static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
486 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000487{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000488 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000489 int size;
York Sun6c480012014-02-26 17:03:19 -0800490#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
491 volatile u64 *llp;
492#endif
York Sund8a405d2014-02-12 15:55:35 -0800493 volatile u32 *longp;
494 volatile u16 *shortp;
495 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000496 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000497
Wolfgang Denk3b683112010-07-17 01:06:04 +0200498 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000499 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000500
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000501 /*
502 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000503 * Defaults to long if no or incorrect specification.
504 */
wdenk874ac262003-07-24 23:38:38 +0000505 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
506 return 1;
wdenk38635852002-08-27 05:55:31 +0000507
508 /* Address is always specified.
509 */
510 addr = simple_strtoul(argv[1], NULL, 16);
511
512 /* Length is the number of objects, not number of bytes.
513 */
514 length = simple_strtoul(argv[2], NULL, 16);
515
Simon Glasse6d0ca22013-02-24 17:33:15 +0000516 bytes = size * length;
517 buf = map_sysmem(addr, bytes);
518
wdenk38635852002-08-27 05:55:31 +0000519 /* We want to optimize the loops to run as fast as possible.
520 * If we have only one object, just run infinite loops.
521 */
522 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800523#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
524 if (size == 8) {
525 llp = (u64 *)buf;
526 for (;;)
527 i = *llp;
528 }
529#endif
wdenk38635852002-08-27 05:55:31 +0000530 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800531 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000532 for (;;)
533 i = *longp;
534 }
535 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800536 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000537 for (;;)
538 i = *shortp;
539 }
York Sund8a405d2014-02-12 15:55:35 -0800540 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000541 for (;;)
542 i = *cp;
543 }
544
York Sun6c480012014-02-26 17:03:19 -0800545#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
546 if (size == 8) {
547 for (;;) {
548 llp = (u64 *)buf;
549 i = length;
550 while (i-- > 0)
551 *llp++;
552 }
553 }
554#endif
wdenk38635852002-08-27 05:55:31 +0000555 if (size == 4) {
556 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800557 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000558 i = length;
559 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200560 *longp++;
wdenk38635852002-08-27 05:55:31 +0000561 }
562 }
563 if (size == 2) {
564 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800565 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000566 i = length;
567 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200568 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000569 }
570 }
571 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800572 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000573 i = length;
574 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200575 *cp++;
wdenk38635852002-08-27 05:55:31 +0000576 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000577 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700578
579 return 0;
wdenk38635852002-08-27 05:55:31 +0000580}
581
wdenk64519362004-07-11 17:40:54 +0000582#ifdef CONFIG_LOOPW
Masahiro Yamada0b2f3312014-09-04 00:38:26 +0900583static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
584 char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000585{
York Sun6c480012014-02-26 17:03:19 -0800586 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000587 int size;
York Sun6c480012014-02-26 17:03:19 -0800588#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
589 volatile u64 *llp;
590 u64 data;
591#else
592 ulong data;
593#endif
York Sund8a405d2014-02-12 15:55:35 -0800594 volatile u32 *longp;
595 volatile u16 *shortp;
596 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000597 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000598
Wolfgang Denk3b683112010-07-17 01:06:04 +0200599 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000600 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000601
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000602 /*
603 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000604 * Defaults to long if no or incorrect specification.
605 */
606 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
607 return 1;
608
609 /* Address is always specified.
610 */
611 addr = simple_strtoul(argv[1], NULL, 16);
612
613 /* Length is the number of objects, not number of bytes.
614 */
615 length = simple_strtoul(argv[2], NULL, 16);
616
617 /* data to write */
York Sun6c480012014-02-26 17:03:19 -0800618#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
619 data = simple_strtoull(argv[3], NULL, 16);
620#else
wdenk64519362004-07-11 17:40:54 +0000621 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800622#endif
wdenk7dd13292004-07-11 20:04:51 +0000623
Simon Glasse6d0ca22013-02-24 17:33:15 +0000624 bytes = size * length;
625 buf = map_sysmem(addr, bytes);
626
wdenk64519362004-07-11 17:40:54 +0000627 /* We want to optimize the loops to run as fast as possible.
628 * If we have only one object, just run infinite loops.
629 */
630 if (length == 1) {
York Sun6c480012014-02-26 17:03:19 -0800631#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
632 if (size == 8) {
633 llp = (u64 *)buf;
634 for (;;)
635 *llp = data;
636 }
637#endif
wdenk64519362004-07-11 17:40:54 +0000638 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800639 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000640 for (;;)
641 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800642 }
wdenk64519362004-07-11 17:40:54 +0000643 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800644 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000645 for (;;)
646 *shortp = data;
647 }
York Sund8a405d2014-02-12 15:55:35 -0800648 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000649 for (;;)
650 *cp = data;
651 }
652
York Sun6c480012014-02-26 17:03:19 -0800653#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
654 if (size == 8) {
655 for (;;) {
656 llp = (u64 *)buf;
657 i = length;
658 while (i-- > 0)
659 *llp++ = data;
660 }
661 }
662#endif
wdenk64519362004-07-11 17:40:54 +0000663 if (size == 4) {
664 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800665 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000666 i = length;
667 while (i-- > 0)
668 *longp++ = data;
669 }
670 }
671 if (size == 2) {
672 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800673 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000674 i = length;
675 while (i-- > 0)
676 *shortp++ = data;
677 }
678 }
679 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800680 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000681 i = length;
682 while (i-- > 0)
683 *cp++ = data;
684 }
685}
686#endif /* CONFIG_LOOPW */
687
Tom Rinia5f02702013-03-12 10:07:19 -0400688#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000689static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
690 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000691{
Simon Glass8f2c7582013-02-24 17:33:16 +0000692 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000693 ulong errs = 0;
694 ulong val, readback;
695 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000696 vu_long offset;
697 vu_long test_offset;
698 vu_long pattern;
699 vu_long temp;
700 vu_long anti_pattern;
701 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000702 static const ulong bitpattern[] = {
703 0x00000001, /* single bit */
704 0x00000003, /* two adjacent bits */
705 0x00000007, /* three adjacent bits */
706 0x0000000F, /* four adjacent bits */
707 0x00000005, /* two non-adjacent bits */
708 0x00000015, /* three non-adjacent bits */
709 0x00000055, /* four non-adjacent bits */
710 0xaaaaaaaa, /* alternating 1/0 */
711 };
wdenk38635852002-08-27 05:55:31 +0000712
Simon Glassad02a012013-02-28 17:47:14 +0000713 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000714
Simon Glass130103e2013-02-24 17:33:18 +0000715 /*
716 * Data line test: write a pattern to the first
717 * location, write the 1's complement to a 'parking'
718 * address (changes the state of the data bus so a
719 * floating bus doesn't give a false OK), and then
720 * read the value back. Note that we read it back
721 * into a variable because the next time we read it,
722 * it might be right (been there, tough to explain to
723 * the quality guys why it prints a failure when the
724 * "is" and "should be" are obviously the same in the
725 * error message).
726 *
727 * Rather than exhaustively testing, we test some
728 * patterns by shifting '1' bits through a field of
729 * '0's and '0' bits through a field of '1's (i.e.
730 * pattern and ~pattern).
731 */
Simon Glassad02a012013-02-28 17:47:14 +0000732 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000733 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
734 val = bitpattern[j];
735 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000736 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000737 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000738 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000739 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000740 printf("FAILURE (data line): "
741 "expected %08lx, actual %08lx\n",
742 val, readback);
743 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000744 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000745 return -1;
wdenk38635852002-08-27 05:55:31 +0000746 }
747 *addr = ~val;
748 *dummy = val;
749 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000750 if (readback != ~val) {
751 printf("FAILURE (data line): "
752 "Is %08lx, should be %08lx\n",
753 readback, ~val);
754 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000755 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000756 return -1;
wdenk38635852002-08-27 05:55:31 +0000757 }
wdenk38635852002-08-27 05:55:31 +0000758 }
Simon Glass130103e2013-02-24 17:33:18 +0000759 }
wdenk38635852002-08-27 05:55:31 +0000760
Simon Glass130103e2013-02-24 17:33:18 +0000761 /*
762 * Based on code whose Original Author and Copyright
763 * information follows: Copyright (c) 1998 by Michael
764 * Barr. This software is placed into the public
765 * domain and may be used for any purpose. However,
766 * this notice must not be changed or removed and no
767 * warranty is either expressed or implied by its
768 * publication or distribution.
769 */
wdenk38635852002-08-27 05:55:31 +0000770
Simon Glass130103e2013-02-24 17:33:18 +0000771 /*
772 * Address line test
wdenk38635852002-08-27 05:55:31 +0000773
Simon Glass130103e2013-02-24 17:33:18 +0000774 * Description: Test the address bus wiring in a
775 * memory region by performing a walking
776 * 1's test on the relevant bits of the
777 * address and checking for aliasing.
778 * This test will find single-bit
779 * address failures such as stuck-high,
780 * stuck-low, and shorted pins. The base
781 * address and size of the region are
782 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000783
Simon Glass130103e2013-02-24 17:33:18 +0000784 * Notes: For best results, the selected base
785 * address should have enough LSB 0's to
786 * guarantee single address bit changes.
787 * For example, to test a 64-Kbyte
788 * region, select a base address on a
789 * 64-Kbyte boundary. Also, select the
790 * region size as a power-of-two if at
791 * all possible.
792 *
793 * Returns: 0 if the test succeeds, 1 if the test fails.
794 */
Simon Glass130103e2013-02-24 17:33:18 +0000795 pattern = (vu_long) 0xaaaaaaaa;
796 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000797
Simon Glassad02a012013-02-28 17:47:14 +0000798 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000799 /*
800 * Write the default pattern at each of the
801 * power-of-two offsets.
802 */
Simon Glassad02a012013-02-28 17:47:14 +0000803 for (offset = 1; offset < num_words; offset <<= 1)
804 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000805
806 /*
807 * Check for address bits stuck high.
808 */
809 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000810 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000811
Simon Glassad02a012013-02-28 17:47:14 +0000812 for (offset = 1; offset < num_words; offset <<= 1) {
813 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000814 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000815 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000816 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800817 start_addr + offset*sizeof(vu_long),
818 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400819 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000820 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000821 return -1;
wdenk38635852002-08-27 05:55:31 +0000822 }
Simon Glass130103e2013-02-24 17:33:18 +0000823 }
Simon Glassad02a012013-02-28 17:47:14 +0000824 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000825 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000826
Simon Glass130103e2013-02-24 17:33:18 +0000827 /*
828 * Check for addr bits stuck low or shorted.
829 */
Simon Glassad02a012013-02-28 17:47:14 +0000830 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
831 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000832
Simon Glassad02a012013-02-28 17:47:14 +0000833 for (offset = 1; offset < num_words; offset <<= 1) {
834 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000835 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000836 printf("\nFAILURE: Address bit stuck low or"
837 " shorted @ 0x%.8lx: expected 0x%.8lx,"
838 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800839 start_addr + offset*sizeof(vu_long),
840 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000841 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000842 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000843 return -1;
wdenk38635852002-08-27 05:55:31 +0000844 }
wdenk38635852002-08-27 05:55:31 +0000845 }
Simon Glassad02a012013-02-28 17:47:14 +0000846 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000847 }
wdenk38635852002-08-27 05:55:31 +0000848
Simon Glass130103e2013-02-24 17:33:18 +0000849 /*
850 * Description: Test the integrity of a physical
851 * memory device by performing an
852 * increment/decrement test over the
853 * entire region. In the process every
854 * storage bit in the device is tested
855 * as a zero and a one. The base address
856 * and the size of the region are
857 * selected by the caller.
858 *
859 * Returns: 0 if the test succeeds, 1 if the test fails.
860 */
Simon Glassad02a012013-02-28 17:47:14 +0000861 num_words++;
wdenk38635852002-08-27 05:55:31 +0000862
Simon Glass130103e2013-02-24 17:33:18 +0000863 /*
864 * Fill memory with a known pattern.
865 */
866 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
867 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000868 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000869 }
wdenk38635852002-08-27 05:55:31 +0000870
Simon Glass130103e2013-02-24 17:33:18 +0000871 /*
872 * Check each location and invert it for the second pass.
873 */
874 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
875 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000876 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000877 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000878 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000879 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800880 start_addr + offset*sizeof(vu_long),
881 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400882 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000883 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000884 return -1;
wdenk38635852002-08-27 05:55:31 +0000885 }
886
Simon Glass130103e2013-02-24 17:33:18 +0000887 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000888 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000889 }
890
891 /*
892 * Check each location for the inverted pattern and zero it.
893 */
894 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
895 WATCHDOG_RESET();
896 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000897 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000898 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000899 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000900 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800901 start_addr + offset*sizeof(vu_long),
902 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400903 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000904 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000905 return -1;
wdenk38635852002-08-27 05:55:31 +0000906 }
Simon Glassad02a012013-02-28 17:47:14 +0000907 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000908 }
Simon Glass57ee4432013-02-24 17:33:17 +0000909
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100910 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000911}
912
Simon Glassad02a012013-02-28 17:47:14 +0000913static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
914 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000915{
Simon Glassad02a012013-02-28 17:47:14 +0000916 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000917 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000918 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000919 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000920 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000921
Simon Glass57ee4432013-02-24 17:33:17 +0000922 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000923 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000924 if (iteration & 1) {
925 incr = -incr;
926 /*
927 * Flip the pattern each time to make lots of zeros and
928 * then, the next time, lots of ones. We decrement
929 * the "negative" patterns and increment the "positive"
930 * patterns to preserve this feature.
931 */
932 if (pattern & 0x80000000)
933 pattern = -pattern; /* complement & increment */
934 else
935 pattern = ~pattern;
936 }
Simon Glassad02a012013-02-28 17:47:14 +0000937 length = (end_addr - start_addr) / sizeof(ulong);
938 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000939 printf("\rPattern %08lX Writing..."
940 "%12s"
941 "\b\b\b\b\b\b\b\b\b\b",
942 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000943
Simon Glassad02a012013-02-28 17:47:14 +0000944 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000945 WATCHDOG_RESET();
946 *addr = val;
947 val += incr;
948 }
wdenk38635852002-08-27 05:55:31 +0000949
Simon Glass130103e2013-02-24 17:33:18 +0000950 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000951
Simon Glassad02a012013-02-28 17:47:14 +0000952 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000953 WATCHDOG_RESET();
954 readback = *addr;
955 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000956 ulong offset = addr - buf;
957
Simon Glass130103e2013-02-24 17:33:18 +0000958 printf("\nMem error @ 0x%08X: "
959 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800960 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000961 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000962 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000963 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000964 return -1;
wdenk38635852002-08-27 05:55:31 +0000965 }
Simon Glass130103e2013-02-24 17:33:18 +0000966 val += incr;
967 }
wdenk38635852002-08-27 05:55:31 +0000968
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100969 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000970}
971
972/*
973 * Perform a memory test. A more complete alternative test can be
974 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
975 * interrupted by ctrl-c or by a failure of one of the sub-tests.
976 */
977static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
978 char * const argv[])
979{
Simon Glass51075252013-02-24 17:33:20 +0000980 ulong start, end;
Simon Glassad02a012013-02-28 17:47:14 +0000981 vu_long *buf, *dummy;
Tom Rinib9180882015-04-07 09:38:54 -0400982 ulong iteration_limit = 0;
Simon Glass8f2c7582013-02-24 17:33:16 +0000983 int ret;
Simon Glass57ee4432013-02-24 17:33:17 +0000984 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Machekd319f592015-04-01 13:50:41 +0200985 ulong pattern = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000986 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +0000987#if defined(CONFIG_SYS_ALT_MEMTEST)
988 const int alt_test = 1;
989#else
990 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +0000991#endif
Simon Glass8f2c7582013-02-24 17:33:16 +0000992
Pavel Machekd319f592015-04-01 13:50:41 +0200993 start = CONFIG_SYS_MEMTEST_START;
994 end = CONFIG_SYS_MEMTEST_END;
995
Simon Glass8f2c7582013-02-24 17:33:16 +0000996 if (argc > 1)
Pavel Machekd319f592015-04-01 13:50:41 +0200997 if (strict_strtoul(argv[1], 16, &start) < 0)
998 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000999
1000 if (argc > 2)
Pavel Machekd319f592015-04-01 13:50:41 +02001001 if (strict_strtoul(argv[2], 16, &end) < 0)
1002 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +00001003
1004 if (argc > 3)
Pavel Machekd319f592015-04-01 13:50:41 +02001005 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1006 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +00001007
1008 if (argc > 4)
Pavel Machekd319f592015-04-01 13:50:41 +02001009 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
1010 return CMD_RET_USAGE;
1011
1012 if (end < start) {
1013 printf("Refusing to do empty test\n");
1014 return -1;
1015 }
Simon Glass8f2c7582013-02-24 17:33:16 +00001016
Michal Simek45f8e332016-02-24 08:36:02 +01001017 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass51075252013-02-24 17:33:20 +00001018 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1019 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +00001020
Simon Glassad02a012013-02-28 17:47:14 +00001021 buf = map_sysmem(start, end - start);
1022 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass57ee4432013-02-24 17:33:17 +00001023 for (iteration = 0;
1024 !iteration_limit || iteration < iteration_limit;
1025 iteration++) {
1026 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +00001027 errs = -1UL;
1028 break;
1029 }
1030
1031 printf("Iteration: %6d\r", iteration + 1);
1032 debug("\n");
Simon Glassad02a012013-02-28 17:47:14 +00001033 if (alt_test) {
1034 errs = mem_test_alt(buf, start, end, dummy);
1035 } else {
1036 errs = mem_test_quick(buf, start, end, pattern,
1037 iteration);
1038 }
1039 if (errs == -1UL)
1040 break;
1041 }
1042
1043 /*
1044 * Work-around for eldk-4.2 which gives this warning if we try to
1045 * case in the unmap_sysmem() call:
1046 * warning: initialization discards qualifiers from pointer target type
1047 */
1048 {
1049 void *vbuf = (void *)buf;
1050 void *vdummy = (void *)dummy;
1051
1052 unmap_sysmem(vbuf);
1053 unmap_sysmem(vdummy);
Simon Glass57ee4432013-02-24 17:33:17 +00001054 }
1055
1056 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001057 /* Memory test was aborted - write a newline to finish off */
1058 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001059 ret = 1;
1060 } else {
1061 printf("Tested %d iteration(s) with %lu errors.\n",
1062 iteration, errs);
1063 ret = errs != 0;
1064 }
Simon Glass8f2c7582013-02-24 17:33:16 +00001065
Pavel Machekd319f592015-04-01 13:50:41 +02001066 return ret;
wdenk38635852002-08-27 05:55:31 +00001067}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001068#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001069
1070/* Modify memory.
1071 *
1072 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001073 * mm{.b, .w, .l, .q} {addr}
1074 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001075 */
1076static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001077mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001078{
York Sun6c480012014-02-26 17:03:19 -08001079 ulong addr;
1080#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1081 u64 i;
1082#else
1083 ulong i;
1084#endif
wdenk874ac262003-07-24 23:38:38 +00001085 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001086 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001087
Wolfgang Denk3b683112010-07-17 01:06:04 +02001088 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001089 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001090
Simon Glass09007c42014-04-10 20:01:31 -06001091 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001092 /* We use the last specified parameters, unless new ones are
1093 * entered.
1094 */
1095 addr = mm_last_addr;
1096 size = mm_last_size;
1097
1098 if ((flag & CMD_FLAG_REPEAT) == 0) {
1099 /* New command specified. Check for a size specification.
1100 * Defaults to long if no or incorrect specification.
1101 */
wdenk874ac262003-07-24 23:38:38 +00001102 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1103 return 1;
wdenk38635852002-08-27 05:55:31 +00001104
1105 /* Address is specified since argc > 1
1106 */
1107 addr = simple_strtoul(argv[1], NULL, 16);
1108 addr += base_address;
1109 }
1110
wdenk381669a2003-06-16 23:50:08 +00001111#ifdef CONFIG_HAS_DATAFLASH
1112 if (addr_dataflash(addr)){
wdenk42c05472004-03-23 22:14:11 +00001113 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk381669a2003-06-16 23:50:08 +00001114 return 0;
1115 }
1116#endif
1117
Mike Frysingere578d682008-02-04 19:26:56 -05001118#ifdef CONFIG_BLACKFIN
1119 if (addr_bfin_on_chip_mem(addr)) {
1120 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1121 return 0;
1122 }
1123#endif
1124
wdenk38635852002-08-27 05:55:31 +00001125 /* Print the address, followed by value. Then accept input for
1126 * the next value. A non-converted value exits.
1127 */
1128 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001129 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001130 printf("%08lx:", addr);
1131 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001132 printf(" %08x", *((u32 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001133#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1134 else if (size == 8)
Simon Glasse9f343f2014-11-11 12:47:07 -07001135 printf(" %016" PRIx64, *((u64 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001136#endif
wdenk38635852002-08-27 05:55:31 +00001137 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001138 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001139 else
York Sund8a405d2014-02-12 15:55:35 -08001140 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001141
Simon Glassbe6aafc2014-04-10 20:01:27 -06001142 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001143 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1144 /* <CR> pressed as only input, don't modify current
1145 * location and move to next. "-" pressed will go back.
1146 */
1147 if (incrflag)
1148 addr += nbytes ? -size : size;
1149 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001150 /* good enough to not time out */
1151 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001152 }
1153#ifdef CONFIG_BOOT_RETRY_TIME
1154 else if (nbytes == -2) {
1155 break; /* timed out, exit the command */
1156 }
1157#endif
1158 else {
1159 char *endp;
York Sun6c480012014-02-26 17:03:19 -08001160#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1161 i = simple_strtoull(console_buffer, &endp, 16);
1162#else
wdenk38635852002-08-27 05:55:31 +00001163 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001164#endif
wdenk38635852002-08-27 05:55:31 +00001165 nbytes = endp - console_buffer;
1166 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001167 /* good enough to not time out
1168 */
Simon Glass09007c42014-04-10 20:01:31 -06001169 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001170 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001171 *((u32 *)ptr) = i;
York Sun6c480012014-02-26 17:03:19 -08001172#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1173 else if (size == 8)
1174 *((u64 *)ptr) = i;
1175#endif
wdenk38635852002-08-27 05:55:31 +00001176 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001177 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001178 else
York Sund8a405d2014-02-12 15:55:35 -08001179 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001180 if (incrflag)
1181 addr += size;
1182 }
1183 }
1184 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001185 if (ptr)
1186 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001187
1188 mm_last_addr = addr;
1189 mm_last_size = size;
1190 return 0;
1191}
1192
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001193#ifdef CONFIG_CMD_CRC32
1194
Kim Phillipsdc00a682012-10-29 13:34:31 +00001195static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001196{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001197 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001198 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001199 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001200
Simon Glass0bbd76f2013-02-24 20:30:22 +00001201 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001202 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001203
1204 av = argv + 1;
1205 ac = argc - 1;
Simon Glass0bbd76f2013-02-24 20:30:22 +00001206#ifdef CONFIG_HASH_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001207 if (strcmp(*av, "-v") == 0) {
Joe Hershberger5fcee9a2015-05-05 12:23:53 -05001208 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenk6203e402004-04-18 10:13:26 +00001209 av++;
1210 ac--;
wdenk6203e402004-04-18 10:13:26 +00001211 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001212#endif
wdenk6203e402004-04-18 10:13:26 +00001213
Simon Glass0bbd76f2013-02-24 20:30:22 +00001214 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001215}
wdenk6203e402004-04-18 10:13:26 +00001216
Robin Getz93d6cb02009-07-27 00:07:59 -04001217#endif
1218
wdenk57b2d802003-06-27 21:31:46 +00001219/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001220U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001221 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001222 "memory display",
York Sun6c480012014-02-26 17:03:19 -08001223#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1224 "[.b, .w, .l, .q] address [# of objects]"
1225#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001226 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001227#endif
wdenk57b2d802003-06-27 21:31:46 +00001228);
1229
1230
wdenkf287a242003-07-01 21:06:45 +00001231U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001232 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001233 "memory modify (auto-incrementing address)",
York Sun6c480012014-02-26 17:03:19 -08001234#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1235 "[.b, .w, .l, .q] address"
1236#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001237 "[.b, .w, .l] address"
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 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001244 "memory modify (constant 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
wdenkf287a242003-07-01 21:06:45 +00001252U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001253 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001254 "memory write (fill)",
York Sun6c480012014-02-26 17:03:19 -08001255#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1256 "[.b, .w, .l, .q] address value [count]"
1257#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001258 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001259#endif
wdenk57b2d802003-06-27 21:31:46 +00001260);
1261
wdenkf287a242003-07-01 21:06:45 +00001262U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001263 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001264 "memory copy",
York Sun6c480012014-02-26 17:03:19 -08001265#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1266 "[.b, .w, .l, .q] source target count"
1267#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001268 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001269#endif
wdenk57b2d802003-06-27 21:31:46 +00001270);
1271
wdenkf287a242003-07-01 21:06:45 +00001272U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001273 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001274 "memory compare",
York Sun6c480012014-02-26 17:03:19 -08001275#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1276 "[.b, .w, .l, .q] addr1 addr2 count"
1277#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001278 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001279#endif
wdenk57b2d802003-06-27 21:31:46 +00001280);
1281
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001282#ifdef CONFIG_CMD_CRC32
1283
Joe Hershbergerf62c1ec2015-05-05 12:23:52 -05001284#ifndef CONFIG_HASH_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001285
wdenkf287a242003-07-01 21:06:45 +00001286U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001287 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001288 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001289 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001290);
1291
Joe Hershbergerf62c1ec2015-05-05 12:23:52 -05001292#else /* CONFIG_HASH_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001293
1294U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001295 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001296 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001297 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001298 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001299);
1300
Joe Hershbergerf62c1ec2015-05-05 12:23:52 -05001301#endif /* CONFIG_HASH_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001302
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001303#endif
1304
Simon Glasseacd14f2012-11-30 13:01:20 +00001305#ifdef CONFIG_CMD_MEMINFO
Andrew Bradfordec9dbc92015-05-22 08:30:14 -04001306__weak void board_show_dram(phys_size_t size)
Simon Glasseacd14f2012-11-30 13:01:20 +00001307{
1308 puts("DRAM: ");
1309 print_size(size, "\n");
1310}
1311
1312static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1313 char * const argv[])
1314{
1315 board_show_dram(gd->ram_size);
1316
1317 return 0;
1318}
1319#endif
1320
wdenkf287a242003-07-01 21:06:45 +00001321U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001322 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001323 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001324 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001325 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001326);
1327
wdenkf287a242003-07-01 21:06:45 +00001328U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001329 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001330 "infinite loop on address range",
York Sun6c480012014-02-26 17:03:19 -08001331#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1332 "[.b, .w, .l, .q] address number_of_objects"
1333#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001334 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001335#endif
wdenk57b2d802003-06-27 21:31:46 +00001336);
wdenk64519362004-07-11 17:40:54 +00001337
1338#ifdef CONFIG_LOOPW
1339U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001340 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001341 "infinite write 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 data_to_write"
1344#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001345 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001346#endif
wdenk64519362004-07-11 17:40:54 +00001347);
1348#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001349
Wolfgang Denk9d009282013-03-08 10:51:32 +00001350#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001351U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001352 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001353 "simple RAM read/write test",
1354 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001355);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001356#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001357
1358#ifdef CONFIG_MX_CYCLIC
1359U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001360 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001361 "memory display cyclic",
York Sun6c480012014-02-26 17:03:19 -08001362#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1363 "[.b, .w, .l, .q] address count delay(ms)"
1364#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001365 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001366#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001367);
1368
1369U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001370 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001371 "memory write cyclic",
York Sun6c480012014-02-26 17:03:19 -08001372#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1373 "[.b, .w, .l, .q] address value delay(ms)"
1374#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001375 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001376#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001377);
1378#endif /* CONFIG_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001379
1380#ifdef CONFIG_CMD_MEMINFO
1381U_BOOT_CMD(
1382 meminfo, 3, 1, do_mem_info,
1383 "display memory information",
1384 ""
1385);
1386#endif