blob: 83d34faf2d8885147e54ec62a200ae5ad41b6e18 [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 Denk1a459662013-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 Glass24b852a2015-11-08 23:47:45 -070015#include <console.h>
Simon Glass0098e172014-04-10 20:01:30 -060016#include <bootretry.h>
Simon Glass18d66532014-04-10 20:01:25 -060017#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000018#include <command.h>
Simon Glass24b852a2015-11-08 23:47:45 -070019#include <console.h>
wdenk2abbe072003-06-16 23:50:08 +000020#ifdef CONFIG_HAS_DATAFLASH
21#include <dataflash.h>
22#endif
Simon Glassd20a40d2013-02-24 20:30:22 +000023#include <hash.h>
Simon Glasse48f3742014-11-11 12:47:07 -070024#include <inttypes.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050025#include <mapmem.h>
Sergei Poselenova6e6fc62008-04-09 16:09:41 +020026#include <watchdog.h>
Simon Glass0628ab82013-02-24 17:33:15 +000027#include <asm/io.h>
Simon Glass15a33e42012-11-30 13:01:20 +000028#include <linux/compiler.h>
29
30DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000031
Simon Glass8e169cc2013-02-24 17:33:29 +000032#ifndef CONFIG_SYS_MEMTEST_SCRATCH
33#define CONFIG_SYS_MEMTEST_SCRATCH 0
34#endif
35
Wolfgang Denk54841ab2010-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 Wood581508b2015-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 Sun4d1fd7f2014-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 Phillips088f1b12012-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{
wdenk27b207f2003-07-24 23:38:38 +000055 ulong addr, length;
Grant Likelyc95c4282007-02-20 09:05:00 +010056#if defined(CONFIG_HAS_DATAFLASH)
57 ulong nbytes, linebytes;
58#endif
wdenk27b207f2003-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 Denk47e26b12010-07-17 01:06:04 +020069 if (argc < 2)
Simon Glass4c12eeb2011-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 */
wdenk27b207f2003-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 Likelyc95c4282007-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 Likelyc95c4282007-02-20 09:05:00 +0100100 void* p;
wdenk38635852002-08-27 05:55:31 +0000101 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk2abbe072003-06-16 23:50:08 +0000102
Grant Likelyc95c4282007-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);
wdenk8bde7f72003-06-27 21:31:46 +0000106
wdenk38635852002-08-27 05:55:31 +0000107 nbytes -= linebytes;
Grant Likelyc95c4282007-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 Likelyc95c4282007-02-20 09:05:00 +0100114#else
Mike Frysinger4c727c72008-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 Glass0628ab82013-02-24 17:33:15 +0000137 ulong bytes = size * length;
138 const void *buf = map_sysmem(addr, bytes);
139
Mike Frysinger4c727c72008-02-04 19:26:56 -0500140 /* Print the lines. */
Simon Glass0628ab82013-02-24 17:33:15 +0000141 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
142 addr += bytes;
143 unmap_sysmem(buf);
Mike Frysinger4c727c72008-02-04 19:26:56 -0500144 }
Grant Likelyc95c4282007-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 Phillips088f1b12012-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 Phillips088f1b12012-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 Phillips088f1b12012-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 Sun4d1fd7f2014-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;
wdenk27b207f2003-07-24 23:38:38 +0000170 int size;
Simon Glasscc5e1962015-03-05 12:25:18 -0700171 void *buf, *start;
Simon Glass0628ab82013-02-24 17:33:15 +0000172 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000173
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200174 if ((argc < 3) || (argc > 4))
Simon Glass4c12eeb2011-12-10 08:44:01 +0000175 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000176
177 /* Check for size specification.
178 */
wdenk27b207f2003-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 Sun4d1fd7f2014-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 Sun4d1fd7f2014-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 Glass0628ab82013-02-24 17:33:15 +0000202 bytes = size * count;
Simon Glasscc5e1962015-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 Sun76698b42014-02-12 15:55:35 -0800207 *((u32 *)buf) = (u32)writeval;
York Sun4d1fd7f2014-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 Sun76698b42014-02-12 15:55:35 -0800213 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000214 else
York Sun76698b42014-02-12 15:55:35 -0800215 *((u8 *)buf) = (u8)writeval;
Simon Glass0628ab82013-02-24 17:33:15 +0000216 buf += size;
wdenk38635852002-08-27 05:55:31 +0000217 }
Simon Glasscc5e1962015-03-05 12:25:18 -0700218 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000219 return 0;
220}
221
stroese4aaf29b2004-12-16 17:42:39 +0000222#ifdef CONFIG_MX_CYCLIC
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900223static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000224{
225 int i;
226 ulong count;
227
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200228 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000229 return CMD_RET_USAGE;
stroese4aaf29b2004-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 Yamada5a8608e2014-09-04 00:38:26 +0900250static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000251{
252 int i;
253 ulong count;
254
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200255 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000256 return CMD_RET_USAGE;
stroese4aaf29b2004-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 Phillips088f1b12012-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 Glass0628ab82013-02-24 17:33:15 +0000280 ulong addr1, addr2, count, ngood, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000281 int size;
wdenk38635852002-08-27 05:55:31 +0000282 int rcode = 0;
Mike Frysinger054ea172012-01-20 09:07:21 +0000283 const char *type;
Simon Glass0628ab82013-02-24 17:33:15 +0000284 const void *buf1, *buf2, *base;
York Sun4d1fd7f2014-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 Denk47e26b12010-07-17 01:06:04 +0200291 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000292 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000293
294 /* Check for size specification.
295 */
wdenk27b207f2003-07-24 23:38:38 +0000296 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
297 return 1;
York Sun4d1fd7f2014-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
wdenk2abbe072003-06-16 23:50:08 +0000310#ifdef CONFIG_HAS_DATAFLASH
311 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk4b9206e2004-03-23 22:14:11 +0000312 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000313 return 0;
314 }
315#endif
316
Mike Frysinger4c727c72008-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 Glass0628ab82013-02-24 17:33:15 +0000324 bytes = size * count;
325 base = buf1 = map_sysmem(addr1, bytes);
326 buf2 = map_sysmem(addr2, bytes);
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000327 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000328 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800329 word1 = *(u32 *)buf1;
330 word2 = *(u32 *)buf2;
York Sun4d1fd7f2014-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 Frysinger054ea172012-01-20 09:07:21 +0000336 } else if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800337 word1 = *(u16 *)buf1;
338 word2 = *(u16 *)buf2;
Mike Frysinger054ea172012-01-20 09:07:21 +0000339 } else {
York Sun76698b42014-02-12 15:55:35 -0800340 word1 = *(u8 *)buf1;
341 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000342 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000343 if (word1 != word2) {
Simon Glass0628ab82013-02-24 17:33:15 +0000344 ulong offset = buf1 - base;
York Sun4d1fd7f2014-02-26 17:03:19 -0800345#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
Simon Glasse48f3742014-11-11 12:47:07 -0700346 printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
347 PRIx64 ")\n",
York Sun4d1fd7f2014-02-26 17:03:19 -0800348 type, (void *)(addr1 + offset), size, word1,
349 type, (void *)(addr2 + offset), size, word2);
350#else
Mike Frysinger054ea172012-01-20 09:07:21 +0000351 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glass0628ab82013-02-24 17:33:15 +0000352 type, (ulong)(addr1 + offset), size, word1,
353 type, (ulong)(addr2 + offset), size, word2);
York Sun4d1fd7f2014-02-26 17:03:19 -0800354#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000355 rcode = 1;
356 break;
wdenk38635852002-08-27 05:55:31 +0000357 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000358
Simon Glass0628ab82013-02-24 17:33:15 +0000359 buf1 += size;
360 buf2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200361
362 /* reset watchdog from time to time */
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000363 if ((ngood % (64 << 10)) == 0)
Stefan Roeseeaadb442010-09-13 11:10:34 +0200364 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000365 }
Simon Glass0628ab82013-02-24 17:33:15 +0000366 unmap_sysmem(buf1);
367 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000368
Mike Frysinger054ea172012-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 Phillips088f1b12012-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 Estevamc2538422016-12-15 16:00:13 -0200375 ulong addr, dest, count;
wdenk27b207f2003-07-24 23:38:38 +0000376 int size;
wdenk38635852002-08-27 05:55:31 +0000377
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200378 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000379 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000380
381 /* Check for size specification.
382 */
wdenk27b207f2003-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
Masahiro Yamadae856bdc2017-02-11 22:43:54 +0900399#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000400 /* check if we are copying to Flash */
wdenk2abbe072003-06-16 23:50:08 +0000401 if ( (addr2info(dest) != NULL)
402#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino84d0c2f2008-03-03 10:39:13 +0200403 && (!addr_dataflash(dest))
wdenk2abbe072003-06-16 23:50:08 +0000404#endif
405 ) {
wdenk38635852002-08-27 05:55:31 +0000406 int rc;
407
wdenk4b9206e2004-03-23 22:14:11 +0000408 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000409
Wolfgang Denk77ddac92005-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
wdenk2abbe072003-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
wdenk4b9206e2004-03-23 22:14:11 +0000425 puts ("Copy to DataFlash... ");
wdenk2abbe072003-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 }
wdenk8bde7f72003-06-27 21:31:46 +0000436
wdenk2abbe072003-06-16 23:50:08 +0000437 /* Check if we are copying from DataFlash to RAM */
Stelian Pop880cc432008-03-26 22:52:35 +0100438 if (addr_dataflash(addr) && !addr_dataflash(dest)
Masahiro Yamadae856bdc2017-02-11 22:43:54 +0900439#ifdef CONFIG_MTD_NOR_FLASH
Stelian Pop880cc432008-03-26 22:52:35 +0100440 && (addr2info(dest) == NULL)
441#endif
442 ){
wdenk5779d8d2003-12-06 23:55:10 +0000443 int rc;
444 rc = read_dataflash(addr, count * size, (char *) dest);
445 if (rc != 1) {
wdenkd4ca31c2004-01-02 14:00:00 +0000446 dataflash_perror (rc);
447 return (1);
448 }
wdenk2abbe072003-06-16 23:50:08 +0000449 return 0;
450 }
451
452 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk4b9206e2004-03-23 22:14:11 +0000453 puts ("Unsupported combination of source/destination.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000454 return 1;
455 }
456#endif
457
Mike Frysinger4c727c72008-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 Estevamc2538422016-12-15 16:00:13 -0200466 memcpy((void *)dest, (void *)addr, count * size);
Masahiro Yamadaa3a47492014-10-23 17:46:24 +0900467
wdenk38635852002-08-27 05:55:31 +0000468 return 0;
469}
470
Kim Phillips088f1b12012-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 Phillips088f1b12012-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 Glass0628ab82013-02-24 17:33:15 +0000488 ulong addr, length, i, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000489 int size;
York Sun4d1fd7f2014-02-26 17:03:19 -0800490#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
491 volatile u64 *llp;
492#endif
York Sun76698b42014-02-12 15:55:35 -0800493 volatile u32 *longp;
494 volatile u16 *shortp;
495 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000496 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000497
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200498 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000499 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000500
Robert P. J. Day85de63e2013-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 */
wdenk27b207f2003-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 Glass0628ab82013-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 Sun4d1fd7f2014-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 Sun76698b42014-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 Sun76698b42014-02-12 15:55:35 -0800536 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000537 for (;;)
538 i = *shortp;
539 }
York Sun76698b42014-02-12 15:55:35 -0800540 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000541 for (;;)
542 i = *cp;
543 }
544
York Sun4d1fd7f2014-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 Sun76698b42014-02-12 15:55:35 -0800557 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000558 i = length;
559 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200560 *longp++;
wdenk38635852002-08-27 05:55:31 +0000561 }
562 }
563 if (size == 2) {
564 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800565 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000566 i = length;
567 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200568 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000569 }
570 }
571 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800572 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000573 i = length;
574 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200575 *cp++;
wdenk38635852002-08-27 05:55:31 +0000576 }
Simon Glass0628ab82013-02-24 17:33:15 +0000577 unmap_sysmem(buf);
Simon Glass92765f422013-06-11 11:14:35 -0700578
579 return 0;
wdenk38635852002-08-27 05:55:31 +0000580}
581
wdenk56523f12004-07-11 17:40:54 +0000582#ifdef CONFIG_LOOPW
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900583static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
584 char * const argv[])
wdenk56523f12004-07-11 17:40:54 +0000585{
York Sun4d1fd7f2014-02-26 17:03:19 -0800586 ulong addr, length, i, bytes;
wdenk56523f12004-07-11 17:40:54 +0000587 int size;
York Sun4d1fd7f2014-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 Sun76698b42014-02-12 15:55:35 -0800594 volatile u32 *longp;
595 volatile u16 *shortp;
596 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000597 void *buf;
wdenk81050922004-07-11 20:04:51 +0000598
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200599 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000600 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000601
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000602 /*
603 * Check for a size specification.
wdenk56523f12004-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 Sun4d1fd7f2014-02-26 17:03:19 -0800618#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
619 data = simple_strtoull(argv[3], NULL, 16);
620#else
wdenk56523f12004-07-11 17:40:54 +0000621 data = simple_strtoul(argv[3], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800622#endif
wdenk81050922004-07-11 20:04:51 +0000623
Simon Glass0628ab82013-02-24 17:33:15 +0000624 bytes = size * length;
625 buf = map_sysmem(addr, bytes);
626
wdenk56523f12004-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 Sun4d1fd7f2014-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
wdenk56523f12004-07-11 17:40:54 +0000638 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800639 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000640 for (;;)
641 *longp = data;
York Sun4d1fd7f2014-02-26 17:03:19 -0800642 }
wdenk56523f12004-07-11 17:40:54 +0000643 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800644 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000645 for (;;)
646 *shortp = data;
647 }
York Sun76698b42014-02-12 15:55:35 -0800648 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000649 for (;;)
650 *cp = data;
651 }
652
York Sun4d1fd7f2014-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
wdenk56523f12004-07-11 17:40:54 +0000663 if (size == 4) {
664 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800665 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000666 i = length;
667 while (i-- > 0)
668 *longp++ = data;
669 }
670 }
671 if (size == 2) {
672 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800673 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000674 i = length;
675 while (i-- > 0)
676 *shortp++ = data;
677 }
678 }
679 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800680 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000681 i = length;
682 while (i-- > 0)
683 *cp++ = data;
684 }
685}
686#endif /* CONFIG_LOOPW */
687
Tom Rini68149e92013-03-12 10:07:19 -0400688#ifdef CONFIG_CMD_MEMTEST
Simon Glass5512d5b2013-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 Glassc9638f52013-02-24 17:33:16 +0000692 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000693 ulong errs = 0;
694 ulong val, readback;
695 int j;
Simon Glassc9638f52013-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 Glass5512d5b2013-02-28 17:47:14 +0000713 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000714
Simon Glass7ecbd4d2013-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 Glass5512d5b2013-02-28 17:47:14 +0000732 addr = buf;
Simon Glass7ecbd4d2013-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 Glass5512d5b2013-02-28 17:47:14 +0000736 *addr = val;
Simon Glassc9638f52013-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 Glass7ecbd4d2013-02-24 17:33:18 +0000739 if (readback != val) {
Simon Glassc9638f52013-02-24 17:33:16 +0000740 printf("FAILURE (data line): "
741 "expected %08lx, actual %08lx\n",
742 val, readback);
743 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000744 if (ctrlc())
Simon Glass51209b12013-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 Glassc9638f52013-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 Glassc44d4382013-02-24 17:33:19 +0000755 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000756 return -1;
wdenk38635852002-08-27 05:55:31 +0000757 }
wdenk38635852002-08-27 05:55:31 +0000758 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000759 }
wdenk38635852002-08-27 05:55:31 +0000760
Simon Glass7ecbd4d2013-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 Glass7ecbd4d2013-02-24 17:33:18 +0000771 /*
772 * Address line test
wdenk38635852002-08-27 05:55:31 +0000773
Simon Glass7ecbd4d2013-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 Glass7ecbd4d2013-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 Glass7ecbd4d2013-02-24 17:33:18 +0000795 pattern = (vu_long) 0xaaaaaaaa;
796 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000797
Simon Glass5512d5b2013-02-28 17:47:14 +0000798 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000799 /*
800 * Write the default pattern at each of the
801 * power-of-two offsets.
802 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000803 for (offset = 1; offset < num_words; offset <<= 1)
804 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000805
806 /*
807 * Check for address bits stuck high.
808 */
809 test_offset = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000810 addr[test_offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000811
Simon Glass5512d5b2013-02-28 17:47:14 +0000812 for (offset = 1; offset < num_words; offset <<= 1) {
813 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000814 if (temp != pattern) {
Simon Glassc9638f52013-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 Feng102c0512014-02-12 16:10:08 +0800817 start_addr + offset*sizeof(vu_long),
818 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400819 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000820 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000821 return -1;
wdenk38635852002-08-27 05:55:31 +0000822 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000823 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000824 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000825 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000826
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000827 /*
828 * Check for addr bits stuck low or shorted.
829 */
Simon Glass5512d5b2013-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 Glass5512d5b2013-02-28 17:47:14 +0000833 for (offset = 1; offset < num_words; offset <<= 1) {
834 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000835 if ((temp != pattern) && (offset != test_offset)) {
836 printf("\nFAILURE: Address bit stuck low or"
837 " shorted @ 0x%.8lx: expected 0x%.8lx,"
838 " actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800839 start_addr + offset*sizeof(vu_long),
840 pattern, temp);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000841 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000842 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000843 return -1;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000844 }
wdenk38635852002-08-27 05:55:31 +0000845 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000846 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000847 }
wdenk38635852002-08-27 05:55:31 +0000848
Simon Glass7ecbd4d2013-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 Glass5512d5b2013-02-28 17:47:14 +0000861 num_words++;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000862
863 /*
864 * Fill memory with a known pattern.
865 */
866 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
867 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000868 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000869 }
870
871 /*
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 Glass5512d5b2013-02-28 17:47:14 +0000876 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000877 if (temp != pattern) {
Simon Glassc9638f52013-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 Feng102c0512014-02-12 16:10:08 +0800880 start_addr + offset*sizeof(vu_long),
881 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400882 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000883 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000884 return -1;
wdenk38635852002-08-27 05:55:31 +0000885 }
886
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000887 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000888 addr[offset] = anti_pattern;
Simon Glass7ecbd4d2013-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 Glass5512d5b2013-02-28 17:47:14 +0000897 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000898 if (temp != anti_pattern) {
Simon Glassc9638f52013-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 Feng102c0512014-02-12 16:10:08 +0800901 start_addr + offset*sizeof(vu_long),
902 anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400903 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000904 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000905 return -1;
wdenk38635852002-08-27 05:55:31 +0000906 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000907 addr[offset] = 0;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000908 }
Simon Glass51209b12013-02-24 17:33:17 +0000909
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100910 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000911}
wdenk38635852002-08-27 05:55:31 +0000912
Simon Glass5512d5b2013-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 Glassc9638f52013-02-24 17:33:16 +0000915{
Simon Glass5512d5b2013-02-28 17:47:14 +0000916 vu_long *end;
Simon Glassc9638f52013-02-24 17:33:16 +0000917 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000918 ulong errs = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000919 ulong incr, length;
Simon Glassc9638f52013-02-24 17:33:16 +0000920 ulong val, readback;
921
Simon Glass51209b12013-02-24 17:33:17 +0000922 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000923 incr = 1;
Simon Glass51209b12013-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 Glass5512d5b2013-02-28 17:47:14 +0000937 length = (end_addr - start_addr) / sizeof(ulong);
938 end = buf + length;
Simon Glass7ecbd4d2013-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 Glass5512d5b2013-02-28 17:47:14 +0000944 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000945 WATCHDOG_RESET();
946 *addr = val;
947 val += incr;
948 }
wdenk38635852002-08-27 05:55:31 +0000949
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000950 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000951
Simon Glass5512d5b2013-02-28 17:47:14 +0000952 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000953 WATCHDOG_RESET();
954 readback = *addr;
955 if (readback != val) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000956 ulong offset = addr - buf;
957
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000958 printf("\nMem error @ 0x%08X: "
959 "found %08lX, expected %08lX\n",
David Feng102c0512014-02-12 16:10:08 +0800960 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glass5512d5b2013-02-28 17:47:14 +0000961 readback, val);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000962 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000963 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000964 return -1;
wdenk38635852002-08-27 05:55:31 +0000965 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000966 val += incr;
967 }
wdenk38635852002-08-27 05:55:31 +0000968
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100969 return errs;
Simon Glassc9638f52013-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 Glass8c86bbe2013-02-24 17:33:20 +0000980 ulong start, end;
Simon Glass5512d5b2013-02-28 17:47:14 +0000981 vu_long *buf, *dummy;
Tom Riniadcc5702015-04-07 09:38:54 -0400982 ulong iteration_limit = 0;
Simon Glassc9638f52013-02-24 17:33:16 +0000983 int ret;
Simon Glass51209b12013-02-24 17:33:17 +0000984 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200985 ulong pattern = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000986 int iteration;
Simon Glassc9638f52013-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 Glassc9638f52013-02-24 17:33:16 +0000992
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200993 start = CONFIG_SYS_MEMTEST_START;
994 end = CONFIG_SYS_MEMTEST_END;
995
Simon Glassc9638f52013-02-24 17:33:16 +0000996 if (argc > 1)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200997 if (strict_strtoul(argv[1], 16, &start) < 0)
998 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000999
1000 if (argc > 2)
Pavel Macheke37f1eb2015-04-01 13:50:41 +02001001 if (strict_strtoul(argv[2], 16, &end) < 0)
1002 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +00001003
1004 if (argc > 3)
Pavel Macheke37f1eb2015-04-01 13:50:41 +02001005 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1006 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +00001007
1008 if (argc > 4)
Pavel Macheke37f1eb2015-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 Glassc9638f52013-02-24 17:33:16 +00001016
Michal Simekdfe461d2016-02-24 08:36:02 +01001017 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass8c86bbe2013-02-24 17:33:20 +00001018 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1019 start, end);
Simon Glass51209b12013-02-24 17:33:17 +00001020
Simon Glass5512d5b2013-02-28 17:47:14 +00001021 buf = map_sysmem(start, end - start);
1022 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass51209b12013-02-24 17:33:17 +00001023 for (iteration = 0;
1024 !iteration_limit || iteration < iteration_limit;
1025 iteration++) {
1026 if (ctrlc()) {
Simon Glass51209b12013-02-24 17:33:17 +00001027 errs = -1UL;
1028 break;
1029 }
1030
1031 printf("Iteration: %6d\r", iteration + 1);
1032 debug("\n");
Simon Glass5512d5b2013-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 Glass51209b12013-02-24 17:33:17 +00001054 }
1055
1056 if (errs == -1UL) {
Simon Glassc44d4382013-02-24 17:33:19 +00001057 /* Memory test was aborted - write a newline to finish off */
1058 putc('\n');
Simon Glass51209b12013-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 Glassc9638f52013-02-24 17:33:16 +00001065
Pavel Macheke37f1eb2015-04-01 13:50:41 +02001066 return ret;
wdenk38635852002-08-27 05:55:31 +00001067}
Wolfgang Denka2681702013-03-08 10:51:32 +00001068#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001069
1070/* Modify memory.
1071 *
1072 * Syntax:
York Sun4d1fd7f2014-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 Denk54841ab2010-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 Sun4d1fd7f2014-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
wdenk27b207f2003-07-24 23:38:38 +00001085 int nbytes, size;
Simon Glass0628ab82013-02-24 17:33:15 +00001086 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001087
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001088 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001089 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001090
Simon Glassb26440f2014-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 */
wdenk27b207f2003-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
wdenk2abbe072003-06-16 23:50:08 +00001111#ifdef CONFIG_HAS_DATAFLASH
1112 if (addr_dataflash(addr)){
wdenk4b9206e2004-03-23 22:14:11 +00001113 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk2abbe072003-06-16 23:50:08 +00001114 return 0;
1115 }
1116#endif
1117
Mike Frysinger4c727c72008-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 Glass0628ab82013-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 Sun76698b42014-02-12 15:55:35 -08001132 printf(" %08x", *((u32 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001133#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1134 else if (size == 8)
Simon Glasse48f3742014-11-11 12:47:07 -07001135 printf(" %016" PRIx64, *((u64 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001136#endif
wdenk38635852002-08-27 05:55:31 +00001137 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001138 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001139 else
York Sun76698b42014-02-12 15:55:35 -08001140 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001141
Simon Glasse1bf8242014-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 Glassb26440f2014-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 Sun4d1fd7f2014-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 Sun4d1fd7f2014-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 Glassb26440f2014-04-10 20:01:31 -06001169 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001170 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001171 *((u32 *)ptr) = i;
York Sun4d1fd7f2014-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 Sun76698b42014-02-12 15:55:35 -08001177 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001178 else
York Sun76698b42014-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 Glass0628ab82013-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 Frysinger710b9932010-12-21 14:19:51 -05001193#ifdef CONFIG_CMD_CRC32
1194
Kim Phillips088f1b12012-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 Glassd20a40d2013-02-24 20:30:22 +00001197 int flags = 0;
1198 int ac;
1199 char * const *av;
wdenk38635852002-08-27 05:55:31 +00001200
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001201 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001202 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001203
wdenkc26e4542004-04-18 10:13:26 +00001204 av = argv + 1;
1205 ac = argc - 1;
Simon Glassd20a40d2013-02-24 20:30:22 +00001206#ifdef CONFIG_HASH_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001207 if (strcmp(*av, "-v") == 0) {
Joe Hershbergera69bdba2015-05-05 12:23:53 -05001208 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenkc26e4542004-04-18 10:13:26 +00001209 av++;
1210 ac--;
wdenkc26e4542004-04-18 10:13:26 +00001211 }
Simon Glassd20a40d2013-02-24 20:30:22 +00001212#endif
wdenkc26e4542004-04-18 10:13:26 +00001213
Simon Glassd20a40d2013-02-24 20:30:22 +00001214 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenkc26e4542004-04-18 10:13:26 +00001215}
wdenkc26e4542004-04-18 10:13:26 +00001216
Mike Frysinger710b9932010-12-21 14:19:51 -05001217#endif
1218
wdenk8bde7f72003-06-27 21:31:46 +00001219/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001220U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001221 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001222 "memory display",
York Sun4d1fd7f2014-02-26 17:03:19 -08001223#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1224 "[.b, .w, .l, .q] address [# of objects]"
1225#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001226 "[.b, .w, .l] address [# of objects]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001227#endif
wdenk8bde7f72003-06-27 21:31:46 +00001228);
1229
1230
wdenk0d498392003-07-01 21:06:45 +00001231U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001232 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001233 "memory modify (auto-incrementing address)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001234#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1235 "[.b, .w, .l, .q] address"
1236#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001237 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001238#endif
wdenk8bde7f72003-06-27 21:31:46 +00001239);
1240
1241
wdenk0d498392003-07-01 21:06:45 +00001242U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001243 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001244 "memory modify (constant address)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001245#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1246 "[.b, .w, .l, .q] address"
1247#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001248 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001249#endif
wdenk8bde7f72003-06-27 21:31:46 +00001250);
1251
wdenk0d498392003-07-01 21:06:45 +00001252U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001253 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001254 "memory write (fill)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001255#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1256 "[.b, .w, .l, .q] address value [count]"
1257#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001258 "[.b, .w, .l] address value [count]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001259#endif
wdenk8bde7f72003-06-27 21:31:46 +00001260);
1261
wdenk0d498392003-07-01 21:06:45 +00001262U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001263 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001264 "memory copy",
York Sun4d1fd7f2014-02-26 17:03:19 -08001265#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1266 "[.b, .w, .l, .q] source target count"
1267#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001268 "[.b, .w, .l] source target count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001269#endif
wdenk8bde7f72003-06-27 21:31:46 +00001270);
1271
wdenk0d498392003-07-01 21:06:45 +00001272U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001273 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001274 "memory compare",
York Sun4d1fd7f2014-02-26 17:03:19 -08001275#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1276 "[.b, .w, .l, .q] addr1 addr2 count"
1277#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001278 "[.b, .w, .l] addr1 addr2 count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001279#endif
wdenk8bde7f72003-06-27 21:31:46 +00001280);
1281
Mike Frysinger710b9932010-12-21 14:19:51 -05001282#ifdef CONFIG_CMD_CRC32
1283
Joe Hershberger849337b2015-05-05 12:23:52 -05001284#ifndef CONFIG_HASH_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001285
wdenk0d498392003-07-01 21:06:45 +00001286U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001287 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001288 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001289 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001290);
1291
Joe Hershberger849337b2015-05-05 12:23:52 -05001292#else /* CONFIG_HASH_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001293
1294U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001295 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001296 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001297 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001298 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001299);
1300
Joe Hershberger849337b2015-05-05 12:23:52 -05001301#endif /* CONFIG_HASH_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001302
Mike Frysinger710b9932010-12-21 14:19:51 -05001303#endif
1304
Simon Glass15a33e42012-11-30 13:01:20 +00001305#ifdef CONFIG_CMD_MEMINFO
Andrew Bradfordea11b402015-05-22 08:30:14 -04001306__weak void board_show_dram(phys_size_t size)
Simon Glass15a33e42012-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
wdenk0d498392003-07-01 21:06:45 +00001321U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001322 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001323 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001324 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001325 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001326);
1327
wdenk0d498392003-07-01 21:06:45 +00001328U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001329 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001330 "infinite loop on address range",
York Sun4d1fd7f2014-02-26 17:03:19 -08001331#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1332 "[.b, .w, .l, .q] address number_of_objects"
1333#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001334 "[.b, .w, .l] address number_of_objects"
York Sun4d1fd7f2014-02-26 17:03:19 -08001335#endif
wdenk8bde7f72003-06-27 21:31:46 +00001336);
1337
wdenk56523f12004-07-11 17:40:54 +00001338#ifdef CONFIG_LOOPW
1339U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001340 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001341 "infinite write loop on address range",
York Sun4d1fd7f2014-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 Denka89c33d2009-05-24 17:06:54 +02001345 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun4d1fd7f2014-02-26 17:03:19 -08001346#endif
wdenk56523f12004-07-11 17:40:54 +00001347);
1348#endif /* CONFIG_LOOPW */
1349
Wolfgang Denka2681702013-03-08 10:51:32 +00001350#ifdef CONFIG_CMD_MEMTEST
wdenk0d498392003-07-01 21:06:45 +00001351U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001352 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001353 "simple RAM read/write test",
1354 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001355);
Wolfgang Denka2681702013-03-08 10:51:32 +00001356#endif /* CONFIG_CMD_MEMTEST */
wdenk8bde7f72003-06-27 21:31:46 +00001357
stroese4aaf29b2004-12-16 17:42:39 +00001358#ifdef CONFIG_MX_CYCLIC
1359U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001360 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001361 "memory display cyclic",
York Sun4d1fd7f2014-02-26 17:03:19 -08001362#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1363 "[.b, .w, .l, .q] address count delay(ms)"
1364#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001365 "[.b, .w, .l] address count delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001366#endif
stroese4aaf29b2004-12-16 17:42:39 +00001367);
1368
1369U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001370 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001371 "memory write cyclic",
York Sun4d1fd7f2014-02-26 17:03:19 -08001372#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1373 "[.b, .w, .l, .q] address value delay(ms)"
1374#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001375 "[.b, .w, .l] address value delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001376#endif
stroese4aaf29b2004-12-16 17:42:39 +00001377);
1378#endif /* CONFIG_MX_CYCLIC */
Simon Glass15a33e42012-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