blob: a690957d0ff93b99296aea9acffd46306415a15e [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{
Simon Glass0628ab82013-02-24 17:33:15 +0000375 ulong addr, dest, count, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000376 int size;
Simon Glass0628ab82013-02-24 17:33:15 +0000377 const void *src;
378 void *buf;
wdenk38635852002-08-27 05:55:31 +0000379
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200380 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000381 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000382
383 /* Check for size specification.
384 */
wdenk27b207f2003-07-24 23:38:38 +0000385 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
386 return 1;
wdenk38635852002-08-27 05:55:31 +0000387
388 addr = simple_strtoul(argv[1], NULL, 16);
389 addr += base_address;
390
391 dest = simple_strtoul(argv[2], NULL, 16);
392 dest += base_address;
393
394 count = simple_strtoul(argv[3], NULL, 16);
395
396 if (count == 0) {
397 puts ("Zero length ???\n");
398 return 1;
399 }
400
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200401#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000402 /* check if we are copying to Flash */
wdenk2abbe072003-06-16 23:50:08 +0000403 if ( (addr2info(dest) != NULL)
404#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino84d0c2f2008-03-03 10:39:13 +0200405 && (!addr_dataflash(dest))
wdenk2abbe072003-06-16 23:50:08 +0000406#endif
407 ) {
wdenk38635852002-08-27 05:55:31 +0000408 int rc;
409
wdenk4b9206e2004-03-23 22:14:11 +0000410 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000411
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200412 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000413 if (rc != 0) {
414 flash_perror (rc);
415 return (1);
416 }
417 puts ("done\n");
418 return 0;
419 }
420#endif
421
wdenk2abbe072003-06-16 23:50:08 +0000422#ifdef CONFIG_HAS_DATAFLASH
423 /* Check if we are copying from RAM or Flash to DataFlash */
424 if (addr_dataflash(dest) && !addr_dataflash(addr)){
425 int rc;
426
wdenk4b9206e2004-03-23 22:14:11 +0000427 puts ("Copy to DataFlash... ");
wdenk2abbe072003-06-16 23:50:08 +0000428
429 rc = write_dataflash (dest, addr, count*size);
430
431 if (rc != 1) {
432 dataflash_perror (rc);
433 return (1);
434 }
435 puts ("done\n");
436 return 0;
437 }
wdenk8bde7f72003-06-27 21:31:46 +0000438
wdenk2abbe072003-06-16 23:50:08 +0000439 /* Check if we are copying from DataFlash to RAM */
Stelian Pop880cc432008-03-26 22:52:35 +0100440 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200441#ifndef CONFIG_SYS_NO_FLASH
Stelian Pop880cc432008-03-26 22:52:35 +0100442 && (addr2info(dest) == NULL)
443#endif
444 ){
wdenk5779d8d2003-12-06 23:55:10 +0000445 int rc;
446 rc = read_dataflash(addr, count * size, (char *) dest);
447 if (rc != 1) {
wdenkd4ca31c2004-01-02 14:00:00 +0000448 dataflash_perror (rc);
449 return (1);
450 }
wdenk2abbe072003-06-16 23:50:08 +0000451 return 0;
452 }
453
454 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk4b9206e2004-03-23 22:14:11 +0000455 puts ("Unsupported combination of source/destination.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000456 return 1;
457 }
458#endif
459
Mike Frysinger4c727c72008-02-04 19:26:56 -0500460#ifdef CONFIG_BLACKFIN
461 /* See if we're copying to/from L1 inst */
462 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
463 memcpy((void *)dest, (void *)addr, count * size);
464 return 0;
465 }
466#endif
467
Simon Glass0628ab82013-02-24 17:33:15 +0000468 bytes = size * count;
Masahiro Yamada53237af2013-05-20 21:08:08 +0000469 buf = map_sysmem(dest, bytes);
Simon Glass0628ab82013-02-24 17:33:15 +0000470 src = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000471 while (count-- > 0) {
472 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -0800473 *((u32 *)buf) = *((u32 *)src);
York Sun4d1fd7f2014-02-26 17:03:19 -0800474#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
475 else if (size == 8)
476 *((u64 *)buf) = *((u64 *)src);
477#endif
wdenk38635852002-08-27 05:55:31 +0000478 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -0800479 *((u16 *)buf) = *((u16 *)src);
wdenk38635852002-08-27 05:55:31 +0000480 else
York Sun76698b42014-02-12 15:55:35 -0800481 *((u8 *)buf) = *((u8 *)src);
Simon Glass0628ab82013-02-24 17:33:15 +0000482 src += size;
483 buf += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200484
485 /* reset watchdog from time to time */
486 if ((count % (64 << 10)) == 0)
487 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000488 }
Masahiro Yamadaa3a47492014-10-23 17:46:24 +0900489 unmap_sysmem(buf);
490 unmap_sysmem(src);
491
wdenk38635852002-08-27 05:55:31 +0000492 return 0;
493}
494
Kim Phillips088f1b12012-10-29 13:34:31 +0000495static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
496 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000497{
498 if (argc > 1) {
499 /* Set new base address.
500 */
501 base_address = simple_strtoul(argv[1], NULL, 16);
502 }
503 /* Print the current base address.
504 */
505 printf("Base Address: 0x%08lx\n", base_address);
506 return 0;
507}
508
Kim Phillips088f1b12012-10-29 13:34:31 +0000509static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
510 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000511{
Simon Glass0628ab82013-02-24 17:33:15 +0000512 ulong addr, length, i, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000513 int size;
York Sun4d1fd7f2014-02-26 17:03:19 -0800514#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
515 volatile u64 *llp;
516#endif
York Sun76698b42014-02-12 15:55:35 -0800517 volatile u32 *longp;
518 volatile u16 *shortp;
519 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000520 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000521
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200522 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000523 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000524
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000525 /*
526 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000527 * Defaults to long if no or incorrect specification.
528 */
wdenk27b207f2003-07-24 23:38:38 +0000529 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
530 return 1;
wdenk38635852002-08-27 05:55:31 +0000531
532 /* Address is always specified.
533 */
534 addr = simple_strtoul(argv[1], NULL, 16);
535
536 /* Length is the number of objects, not number of bytes.
537 */
538 length = simple_strtoul(argv[2], NULL, 16);
539
Simon Glass0628ab82013-02-24 17:33:15 +0000540 bytes = size * length;
541 buf = map_sysmem(addr, bytes);
542
wdenk38635852002-08-27 05:55:31 +0000543 /* We want to optimize the loops to run as fast as possible.
544 * If we have only one object, just run infinite loops.
545 */
546 if (length == 1) {
York Sun4d1fd7f2014-02-26 17:03:19 -0800547#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
548 if (size == 8) {
549 llp = (u64 *)buf;
550 for (;;)
551 i = *llp;
552 }
553#endif
wdenk38635852002-08-27 05:55:31 +0000554 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800555 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000556 for (;;)
557 i = *longp;
558 }
559 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800560 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000561 for (;;)
562 i = *shortp;
563 }
York Sun76698b42014-02-12 15:55:35 -0800564 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000565 for (;;)
566 i = *cp;
567 }
568
York Sun4d1fd7f2014-02-26 17:03:19 -0800569#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
570 if (size == 8) {
571 for (;;) {
572 llp = (u64 *)buf;
573 i = length;
574 while (i-- > 0)
575 *llp++;
576 }
577 }
578#endif
wdenk38635852002-08-27 05:55:31 +0000579 if (size == 4) {
580 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800581 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000582 i = length;
583 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200584 *longp++;
wdenk38635852002-08-27 05:55:31 +0000585 }
586 }
587 if (size == 2) {
588 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800589 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000590 i = length;
591 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200592 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000593 }
594 }
595 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800596 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000597 i = length;
598 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200599 *cp++;
wdenk38635852002-08-27 05:55:31 +0000600 }
Simon Glass0628ab82013-02-24 17:33:15 +0000601 unmap_sysmem(buf);
Simon Glass92765f422013-06-11 11:14:35 -0700602
603 return 0;
wdenk38635852002-08-27 05:55:31 +0000604}
605
wdenk56523f12004-07-11 17:40:54 +0000606#ifdef CONFIG_LOOPW
Masahiro Yamada5a8608e2014-09-04 00:38:26 +0900607static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
608 char * const argv[])
wdenk56523f12004-07-11 17:40:54 +0000609{
York Sun4d1fd7f2014-02-26 17:03:19 -0800610 ulong addr, length, i, bytes;
wdenk56523f12004-07-11 17:40:54 +0000611 int size;
York Sun4d1fd7f2014-02-26 17:03:19 -0800612#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
613 volatile u64 *llp;
614 u64 data;
615#else
616 ulong data;
617#endif
York Sun76698b42014-02-12 15:55:35 -0800618 volatile u32 *longp;
619 volatile u16 *shortp;
620 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000621 void *buf;
wdenk81050922004-07-11 20:04:51 +0000622
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200623 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000624 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000625
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000626 /*
627 * Check for a size specification.
wdenk56523f12004-07-11 17:40:54 +0000628 * Defaults to long if no or incorrect specification.
629 */
630 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
631 return 1;
632
633 /* Address is always specified.
634 */
635 addr = simple_strtoul(argv[1], NULL, 16);
636
637 /* Length is the number of objects, not number of bytes.
638 */
639 length = simple_strtoul(argv[2], NULL, 16);
640
641 /* data to write */
York Sun4d1fd7f2014-02-26 17:03:19 -0800642#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
643 data = simple_strtoull(argv[3], NULL, 16);
644#else
wdenk56523f12004-07-11 17:40:54 +0000645 data = simple_strtoul(argv[3], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800646#endif
wdenk81050922004-07-11 20:04:51 +0000647
Simon Glass0628ab82013-02-24 17:33:15 +0000648 bytes = size * length;
649 buf = map_sysmem(addr, bytes);
650
wdenk56523f12004-07-11 17:40:54 +0000651 /* We want to optimize the loops to run as fast as possible.
652 * If we have only one object, just run infinite loops.
653 */
654 if (length == 1) {
York Sun4d1fd7f2014-02-26 17:03:19 -0800655#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
656 if (size == 8) {
657 llp = (u64 *)buf;
658 for (;;)
659 *llp = data;
660 }
661#endif
wdenk56523f12004-07-11 17:40:54 +0000662 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800663 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000664 for (;;)
665 *longp = data;
York Sun4d1fd7f2014-02-26 17:03:19 -0800666 }
wdenk56523f12004-07-11 17:40:54 +0000667 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800668 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000669 for (;;)
670 *shortp = data;
671 }
York Sun76698b42014-02-12 15:55:35 -0800672 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000673 for (;;)
674 *cp = data;
675 }
676
York Sun4d1fd7f2014-02-26 17:03:19 -0800677#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
678 if (size == 8) {
679 for (;;) {
680 llp = (u64 *)buf;
681 i = length;
682 while (i-- > 0)
683 *llp++ = data;
684 }
685 }
686#endif
wdenk56523f12004-07-11 17:40:54 +0000687 if (size == 4) {
688 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800689 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000690 i = length;
691 while (i-- > 0)
692 *longp++ = data;
693 }
694 }
695 if (size == 2) {
696 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800697 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000698 i = length;
699 while (i-- > 0)
700 *shortp++ = data;
701 }
702 }
703 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800704 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000705 i = length;
706 while (i-- > 0)
707 *cp++ = data;
708 }
709}
710#endif /* CONFIG_LOOPW */
711
Tom Rini68149e92013-03-12 10:07:19 -0400712#ifdef CONFIG_CMD_MEMTEST
Simon Glass5512d5b2013-02-28 17:47:14 +0000713static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
714 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000715{
Simon Glassc9638f52013-02-24 17:33:16 +0000716 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000717 ulong errs = 0;
718 ulong val, readback;
719 int j;
Simon Glassc9638f52013-02-24 17:33:16 +0000720 vu_long offset;
721 vu_long test_offset;
722 vu_long pattern;
723 vu_long temp;
724 vu_long anti_pattern;
725 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000726 static const ulong bitpattern[] = {
727 0x00000001, /* single bit */
728 0x00000003, /* two adjacent bits */
729 0x00000007, /* three adjacent bits */
730 0x0000000F, /* four adjacent bits */
731 0x00000005, /* two non-adjacent bits */
732 0x00000015, /* three non-adjacent bits */
733 0x00000055, /* four non-adjacent bits */
734 0xaaaaaaaa, /* alternating 1/0 */
735 };
wdenk38635852002-08-27 05:55:31 +0000736
Simon Glass5512d5b2013-02-28 17:47:14 +0000737 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000738
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000739 /*
740 * Data line test: write a pattern to the first
741 * location, write the 1's complement to a 'parking'
742 * address (changes the state of the data bus so a
743 * floating bus doesn't give a false OK), and then
744 * read the value back. Note that we read it back
745 * into a variable because the next time we read it,
746 * it might be right (been there, tough to explain to
747 * the quality guys why it prints a failure when the
748 * "is" and "should be" are obviously the same in the
749 * error message).
750 *
751 * Rather than exhaustively testing, we test some
752 * patterns by shifting '1' bits through a field of
753 * '0's and '0' bits through a field of '1's (i.e.
754 * pattern and ~pattern).
755 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000756 addr = buf;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000757 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
758 val = bitpattern[j];
759 for (; val != 0; val <<= 1) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000760 *addr = val;
Simon Glassc9638f52013-02-24 17:33:16 +0000761 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000762 readback = *addr;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000763 if (readback != val) {
Simon Glassc9638f52013-02-24 17:33:16 +0000764 printf("FAILURE (data line): "
765 "expected %08lx, actual %08lx\n",
766 val, readback);
767 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000768 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000769 return -1;
wdenk38635852002-08-27 05:55:31 +0000770 }
771 *addr = ~val;
772 *dummy = val;
773 readback = *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000774 if (readback != ~val) {
775 printf("FAILURE (data line): "
776 "Is %08lx, should be %08lx\n",
777 readback, ~val);
778 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000779 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000780 return -1;
wdenk38635852002-08-27 05:55:31 +0000781 }
wdenk38635852002-08-27 05:55:31 +0000782 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000783 }
wdenk38635852002-08-27 05:55:31 +0000784
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000785 /*
786 * Based on code whose Original Author and Copyright
787 * information follows: Copyright (c) 1998 by Michael
788 * Barr. This software is placed into the public
789 * domain and may be used for any purpose. However,
790 * this notice must not be changed or removed and no
791 * warranty is either expressed or implied by its
792 * publication or distribution.
793 */
wdenk38635852002-08-27 05:55:31 +0000794
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000795 /*
796 * Address line test
wdenk38635852002-08-27 05:55:31 +0000797
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000798 * Description: Test the address bus wiring in a
799 * memory region by performing a walking
800 * 1's test on the relevant bits of the
801 * address and checking for aliasing.
802 * This test will find single-bit
803 * address failures such as stuck-high,
804 * stuck-low, and shorted pins. The base
805 * address and size of the region are
806 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000807
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000808 * Notes: For best results, the selected base
809 * address should have enough LSB 0's to
810 * guarantee single address bit changes.
811 * For example, to test a 64-Kbyte
812 * region, select a base address on a
813 * 64-Kbyte boundary. Also, select the
814 * region size as a power-of-two if at
815 * all possible.
816 *
817 * Returns: 0 if the test succeeds, 1 if the test fails.
818 */
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000819 pattern = (vu_long) 0xaaaaaaaa;
820 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000821
Simon Glass5512d5b2013-02-28 17:47:14 +0000822 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000823 /*
824 * Write the default pattern at each of the
825 * power-of-two offsets.
826 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000827 for (offset = 1; offset < num_words; offset <<= 1)
828 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000829
830 /*
831 * Check for address bits stuck high.
832 */
833 test_offset = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000834 addr[test_offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000835
Simon Glass5512d5b2013-02-28 17:47:14 +0000836 for (offset = 1; offset < num_words; offset <<= 1) {
837 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000838 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000839 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000840 " expected 0x%.8lx, actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800841 start_addr + offset*sizeof(vu_long),
842 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400843 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000844 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000845 return -1;
wdenk38635852002-08-27 05:55:31 +0000846 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000847 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000848 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000849 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000850
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000851 /*
852 * Check for addr bits stuck low or shorted.
853 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000854 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
855 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000856
Simon Glass5512d5b2013-02-28 17:47:14 +0000857 for (offset = 1; offset < num_words; offset <<= 1) {
858 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000859 if ((temp != pattern) && (offset != test_offset)) {
860 printf("\nFAILURE: Address bit stuck low or"
861 " shorted @ 0x%.8lx: expected 0x%.8lx,"
862 " actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800863 start_addr + offset*sizeof(vu_long),
864 pattern, temp);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000865 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000866 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000867 return -1;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000868 }
wdenk38635852002-08-27 05:55:31 +0000869 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000870 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000871 }
wdenk38635852002-08-27 05:55:31 +0000872
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000873 /*
874 * Description: Test the integrity of a physical
875 * memory device by performing an
876 * increment/decrement test over the
877 * entire region. In the process every
878 * storage bit in the device is tested
879 * as a zero and a one. The base address
880 * and the size of the region are
881 * selected by the caller.
882 *
883 * Returns: 0 if the test succeeds, 1 if the test fails.
884 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000885 num_words++;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000886
887 /*
888 * Fill memory with a known pattern.
889 */
890 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
891 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000892 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000893 }
894
895 /*
896 * Check each location and invert it for the second pass.
897 */
898 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
899 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000900 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000901 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000902 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000903 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800904 start_addr + offset*sizeof(vu_long),
905 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400906 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000907 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000908 return -1;
wdenk38635852002-08-27 05:55:31 +0000909 }
910
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000911 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000912 addr[offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000913 }
914
915 /*
916 * Check each location for the inverted pattern and zero it.
917 */
918 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
919 WATCHDOG_RESET();
920 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000921 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000922 if (temp != anti_pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000923 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000924 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800925 start_addr + offset*sizeof(vu_long),
926 anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400927 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000928 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000929 return -1;
wdenk38635852002-08-27 05:55:31 +0000930 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000931 addr[offset] = 0;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000932 }
Simon Glass51209b12013-02-24 17:33:17 +0000933
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100934 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000935}
wdenk38635852002-08-27 05:55:31 +0000936
Simon Glass5512d5b2013-02-28 17:47:14 +0000937static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
938 vu_long pattern, int iteration)
Simon Glassc9638f52013-02-24 17:33:16 +0000939{
Simon Glass5512d5b2013-02-28 17:47:14 +0000940 vu_long *end;
Simon Glassc9638f52013-02-24 17:33:16 +0000941 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000942 ulong errs = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000943 ulong incr, length;
Simon Glassc9638f52013-02-24 17:33:16 +0000944 ulong val, readback;
945
Simon Glass51209b12013-02-24 17:33:17 +0000946 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000947 incr = 1;
Simon Glass51209b12013-02-24 17:33:17 +0000948 if (iteration & 1) {
949 incr = -incr;
950 /*
951 * Flip the pattern each time to make lots of zeros and
952 * then, the next time, lots of ones. We decrement
953 * the "negative" patterns and increment the "positive"
954 * patterns to preserve this feature.
955 */
956 if (pattern & 0x80000000)
957 pattern = -pattern; /* complement & increment */
958 else
959 pattern = ~pattern;
960 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000961 length = (end_addr - start_addr) / sizeof(ulong);
962 end = buf + length;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000963 printf("\rPattern %08lX Writing..."
964 "%12s"
965 "\b\b\b\b\b\b\b\b\b\b",
966 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000967
Simon Glass5512d5b2013-02-28 17:47:14 +0000968 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000969 WATCHDOG_RESET();
970 *addr = val;
971 val += incr;
972 }
wdenk38635852002-08-27 05:55:31 +0000973
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000974 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000975
Simon Glass5512d5b2013-02-28 17:47:14 +0000976 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000977 WATCHDOG_RESET();
978 readback = *addr;
979 if (readback != val) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000980 ulong offset = addr - buf;
981
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000982 printf("\nMem error @ 0x%08X: "
983 "found %08lX, expected %08lX\n",
David Feng102c0512014-02-12 16:10:08 +0800984 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glass5512d5b2013-02-28 17:47:14 +0000985 readback, val);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000986 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000987 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000988 return -1;
wdenk38635852002-08-27 05:55:31 +0000989 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000990 val += incr;
991 }
wdenk38635852002-08-27 05:55:31 +0000992
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100993 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000994}
995
996/*
997 * Perform a memory test. A more complete alternative test can be
998 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
999 * interrupted by ctrl-c or by a failure of one of the sub-tests.
1000 */
1001static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
1002 char * const argv[])
1003{
Simon Glass8c86bbe2013-02-24 17:33:20 +00001004 ulong start, end;
Simon Glass5512d5b2013-02-28 17:47:14 +00001005 vu_long *buf, *dummy;
Tom Riniadcc5702015-04-07 09:38:54 -04001006 ulong iteration_limit = 0;
Simon Glassc9638f52013-02-24 17:33:16 +00001007 int ret;
Simon Glass51209b12013-02-24 17:33:17 +00001008 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Macheke37f1eb2015-04-01 13:50:41 +02001009 ulong pattern = 0;
Simon Glass51209b12013-02-24 17:33:17 +00001010 int iteration;
Simon Glassc9638f52013-02-24 17:33:16 +00001011#if defined(CONFIG_SYS_ALT_MEMTEST)
1012 const int alt_test = 1;
1013#else
1014 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +00001015#endif
Simon Glassc9638f52013-02-24 17:33:16 +00001016
Pavel Macheke37f1eb2015-04-01 13:50:41 +02001017 start = CONFIG_SYS_MEMTEST_START;
1018 end = CONFIG_SYS_MEMTEST_END;
1019
Simon Glassc9638f52013-02-24 17:33:16 +00001020 if (argc > 1)
Pavel Macheke37f1eb2015-04-01 13:50:41 +02001021 if (strict_strtoul(argv[1], 16, &start) < 0)
1022 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +00001023
1024 if (argc > 2)
Pavel Macheke37f1eb2015-04-01 13:50:41 +02001025 if (strict_strtoul(argv[2], 16, &end) < 0)
1026 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +00001027
1028 if (argc > 3)
Pavel Macheke37f1eb2015-04-01 13:50:41 +02001029 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1030 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +00001031
1032 if (argc > 4)
Pavel Macheke37f1eb2015-04-01 13:50:41 +02001033 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
1034 return CMD_RET_USAGE;
1035
1036 if (end < start) {
1037 printf("Refusing to do empty test\n");
1038 return -1;
1039 }
Simon Glassc9638f52013-02-24 17:33:16 +00001040
Michal Simekdfe461d2016-02-24 08:36:02 +01001041 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass8c86bbe2013-02-24 17:33:20 +00001042 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1043 start, end);
Simon Glass51209b12013-02-24 17:33:17 +00001044
Simon Glass5512d5b2013-02-28 17:47:14 +00001045 buf = map_sysmem(start, end - start);
1046 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass51209b12013-02-24 17:33:17 +00001047 for (iteration = 0;
1048 !iteration_limit || iteration < iteration_limit;
1049 iteration++) {
1050 if (ctrlc()) {
Simon Glass51209b12013-02-24 17:33:17 +00001051 errs = -1UL;
1052 break;
1053 }
1054
1055 printf("Iteration: %6d\r", iteration + 1);
1056 debug("\n");
Simon Glass5512d5b2013-02-28 17:47:14 +00001057 if (alt_test) {
1058 errs = mem_test_alt(buf, start, end, dummy);
1059 } else {
1060 errs = mem_test_quick(buf, start, end, pattern,
1061 iteration);
1062 }
1063 if (errs == -1UL)
1064 break;
1065 }
1066
1067 /*
1068 * Work-around for eldk-4.2 which gives this warning if we try to
1069 * case in the unmap_sysmem() call:
1070 * warning: initialization discards qualifiers from pointer target type
1071 */
1072 {
1073 void *vbuf = (void *)buf;
1074 void *vdummy = (void *)dummy;
1075
1076 unmap_sysmem(vbuf);
1077 unmap_sysmem(vdummy);
Simon Glass51209b12013-02-24 17:33:17 +00001078 }
1079
1080 if (errs == -1UL) {
Simon Glassc44d4382013-02-24 17:33:19 +00001081 /* Memory test was aborted - write a newline to finish off */
1082 putc('\n');
Simon Glass51209b12013-02-24 17:33:17 +00001083 ret = 1;
1084 } else {
1085 printf("Tested %d iteration(s) with %lu errors.\n",
1086 iteration, errs);
1087 ret = errs != 0;
1088 }
Simon Glassc9638f52013-02-24 17:33:16 +00001089
Pavel Macheke37f1eb2015-04-01 13:50:41 +02001090 return ret;
wdenk38635852002-08-27 05:55:31 +00001091}
Wolfgang Denka2681702013-03-08 10:51:32 +00001092#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001093
1094/* Modify memory.
1095 *
1096 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -08001097 * mm{.b, .w, .l, .q} {addr}
1098 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001099 */
1100static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001101mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001102{
York Sun4d1fd7f2014-02-26 17:03:19 -08001103 ulong addr;
1104#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1105 u64 i;
1106#else
1107 ulong i;
1108#endif
wdenk27b207f2003-07-24 23:38:38 +00001109 int nbytes, size;
Simon Glass0628ab82013-02-24 17:33:15 +00001110 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001111
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001112 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001113 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001114
Simon Glassb26440f2014-04-10 20:01:31 -06001115 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001116 /* We use the last specified parameters, unless new ones are
1117 * entered.
1118 */
1119 addr = mm_last_addr;
1120 size = mm_last_size;
1121
1122 if ((flag & CMD_FLAG_REPEAT) == 0) {
1123 /* New command specified. Check for a size specification.
1124 * Defaults to long if no or incorrect specification.
1125 */
wdenk27b207f2003-07-24 23:38:38 +00001126 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1127 return 1;
wdenk38635852002-08-27 05:55:31 +00001128
1129 /* Address is specified since argc > 1
1130 */
1131 addr = simple_strtoul(argv[1], NULL, 16);
1132 addr += base_address;
1133 }
1134
wdenk2abbe072003-06-16 23:50:08 +00001135#ifdef CONFIG_HAS_DATAFLASH
1136 if (addr_dataflash(addr)){
wdenk4b9206e2004-03-23 22:14:11 +00001137 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk2abbe072003-06-16 23:50:08 +00001138 return 0;
1139 }
1140#endif
1141
Mike Frysinger4c727c72008-02-04 19:26:56 -05001142#ifdef CONFIG_BLACKFIN
1143 if (addr_bfin_on_chip_mem(addr)) {
1144 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1145 return 0;
1146 }
1147#endif
1148
wdenk38635852002-08-27 05:55:31 +00001149 /* Print the address, followed by value. Then accept input for
1150 * the next value. A non-converted value exits.
1151 */
1152 do {
Simon Glass0628ab82013-02-24 17:33:15 +00001153 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001154 printf("%08lx:", addr);
1155 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001156 printf(" %08x", *((u32 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001157#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1158 else if (size == 8)
Simon Glasse48f3742014-11-11 12:47:07 -07001159 printf(" %016" PRIx64, *((u64 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001160#endif
wdenk38635852002-08-27 05:55:31 +00001161 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001162 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001163 else
York Sun76698b42014-02-12 15:55:35 -08001164 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001165
Simon Glasse1bf8242014-04-10 20:01:27 -06001166 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001167 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1168 /* <CR> pressed as only input, don't modify current
1169 * location and move to next. "-" pressed will go back.
1170 */
1171 if (incrflag)
1172 addr += nbytes ? -size : size;
1173 nbytes = 1;
Simon Glassb26440f2014-04-10 20:01:31 -06001174 /* good enough to not time out */
1175 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001176 }
1177#ifdef CONFIG_BOOT_RETRY_TIME
1178 else if (nbytes == -2) {
1179 break; /* timed out, exit the command */
1180 }
1181#endif
1182 else {
1183 char *endp;
York Sun4d1fd7f2014-02-26 17:03:19 -08001184#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1185 i = simple_strtoull(console_buffer, &endp, 16);
1186#else
wdenk38635852002-08-27 05:55:31 +00001187 i = simple_strtoul(console_buffer, &endp, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -08001188#endif
wdenk38635852002-08-27 05:55:31 +00001189 nbytes = endp - console_buffer;
1190 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001191 /* good enough to not time out
1192 */
Simon Glassb26440f2014-04-10 20:01:31 -06001193 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001194 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001195 *((u32 *)ptr) = i;
York Sun4d1fd7f2014-02-26 17:03:19 -08001196#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1197 else if (size == 8)
1198 *((u64 *)ptr) = i;
1199#endif
wdenk38635852002-08-27 05:55:31 +00001200 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001201 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001202 else
York Sun76698b42014-02-12 15:55:35 -08001203 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001204 if (incrflag)
1205 addr += size;
1206 }
1207 }
1208 } while (nbytes);
Simon Glass0628ab82013-02-24 17:33:15 +00001209 if (ptr)
1210 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001211
1212 mm_last_addr = addr;
1213 mm_last_size = size;
1214 return 0;
1215}
1216
Mike Frysinger710b9932010-12-21 14:19:51 -05001217#ifdef CONFIG_CMD_CRC32
1218
Kim Phillips088f1b12012-10-29 13:34:31 +00001219static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001220{
Simon Glassd20a40d2013-02-24 20:30:22 +00001221 int flags = 0;
1222 int ac;
1223 char * const *av;
wdenk38635852002-08-27 05:55:31 +00001224
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001225 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001226 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001227
wdenkc26e4542004-04-18 10:13:26 +00001228 av = argv + 1;
1229 ac = argc - 1;
Simon Glassd20a40d2013-02-24 20:30:22 +00001230#ifdef CONFIG_HASH_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001231 if (strcmp(*av, "-v") == 0) {
Joe Hershbergera69bdba2015-05-05 12:23:53 -05001232 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenkc26e4542004-04-18 10:13:26 +00001233 av++;
1234 ac--;
wdenkc26e4542004-04-18 10:13:26 +00001235 }
Simon Glassd20a40d2013-02-24 20:30:22 +00001236#endif
wdenkc26e4542004-04-18 10:13:26 +00001237
Simon Glassd20a40d2013-02-24 20:30:22 +00001238 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenkc26e4542004-04-18 10:13:26 +00001239}
wdenkc26e4542004-04-18 10:13:26 +00001240
Mike Frysinger710b9932010-12-21 14:19:51 -05001241#endif
1242
wdenk8bde7f72003-06-27 21:31:46 +00001243/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001244U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001245 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001246 "memory display",
York Sun4d1fd7f2014-02-26 17:03:19 -08001247#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1248 "[.b, .w, .l, .q] address [# of objects]"
1249#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001250 "[.b, .w, .l] address [# of objects]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001251#endif
wdenk8bde7f72003-06-27 21:31:46 +00001252);
1253
1254
wdenk0d498392003-07-01 21:06:45 +00001255U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001256 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001257 "memory modify (auto-incrementing address)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001258#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1259 "[.b, .w, .l, .q] address"
1260#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001261 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001262#endif
wdenk8bde7f72003-06-27 21:31:46 +00001263);
1264
1265
wdenk0d498392003-07-01 21:06:45 +00001266U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001267 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001268 "memory modify (constant address)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001269#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1270 "[.b, .w, .l, .q] address"
1271#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001272 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001273#endif
wdenk8bde7f72003-06-27 21:31:46 +00001274);
1275
wdenk0d498392003-07-01 21:06:45 +00001276U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001277 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001278 "memory write (fill)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001279#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1280 "[.b, .w, .l, .q] address value [count]"
1281#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001282 "[.b, .w, .l] address value [count]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001283#endif
wdenk8bde7f72003-06-27 21:31:46 +00001284);
1285
wdenk0d498392003-07-01 21:06:45 +00001286U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001287 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001288 "memory copy",
York Sun4d1fd7f2014-02-26 17:03:19 -08001289#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1290 "[.b, .w, .l, .q] source target count"
1291#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001292 "[.b, .w, .l] source target count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001293#endif
wdenk8bde7f72003-06-27 21:31:46 +00001294);
1295
wdenk0d498392003-07-01 21:06:45 +00001296U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001297 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001298 "memory compare",
York Sun4d1fd7f2014-02-26 17:03:19 -08001299#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1300 "[.b, .w, .l, .q] addr1 addr2 count"
1301#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001302 "[.b, .w, .l] addr1 addr2 count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001303#endif
wdenk8bde7f72003-06-27 21:31:46 +00001304);
1305
Mike Frysinger710b9932010-12-21 14:19:51 -05001306#ifdef CONFIG_CMD_CRC32
1307
Joe Hershberger849337b2015-05-05 12:23:52 -05001308#ifndef CONFIG_HASH_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001309
wdenk0d498392003-07-01 21:06:45 +00001310U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001311 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001312 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001313 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001314);
1315
Joe Hershberger849337b2015-05-05 12:23:52 -05001316#else /* CONFIG_HASH_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001317
1318U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001319 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001320 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001321 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001322 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001323);
1324
Joe Hershberger849337b2015-05-05 12:23:52 -05001325#endif /* CONFIG_HASH_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001326
Mike Frysinger710b9932010-12-21 14:19:51 -05001327#endif
1328
Simon Glass15a33e42012-11-30 13:01:20 +00001329#ifdef CONFIG_CMD_MEMINFO
Andrew Bradfordea11b402015-05-22 08:30:14 -04001330__weak void board_show_dram(phys_size_t size)
Simon Glass15a33e42012-11-30 13:01:20 +00001331{
1332 puts("DRAM: ");
1333 print_size(size, "\n");
1334}
1335
1336static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1337 char * const argv[])
1338{
1339 board_show_dram(gd->ram_size);
1340
1341 return 0;
1342}
1343#endif
1344
wdenk0d498392003-07-01 21:06:45 +00001345U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001346 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001347 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001348 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001349 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001350);
1351
wdenk0d498392003-07-01 21:06:45 +00001352U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001353 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001354 "infinite loop on address range",
York Sun4d1fd7f2014-02-26 17:03:19 -08001355#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1356 "[.b, .w, .l, .q] address number_of_objects"
1357#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001358 "[.b, .w, .l] address number_of_objects"
York Sun4d1fd7f2014-02-26 17:03:19 -08001359#endif
wdenk8bde7f72003-06-27 21:31:46 +00001360);
1361
wdenk56523f12004-07-11 17:40:54 +00001362#ifdef CONFIG_LOOPW
1363U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001364 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001365 "infinite write loop on address range",
York Sun4d1fd7f2014-02-26 17:03:19 -08001366#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1367 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1368#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001369 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun4d1fd7f2014-02-26 17:03:19 -08001370#endif
wdenk56523f12004-07-11 17:40:54 +00001371);
1372#endif /* CONFIG_LOOPW */
1373
Wolfgang Denka2681702013-03-08 10:51:32 +00001374#ifdef CONFIG_CMD_MEMTEST
wdenk0d498392003-07-01 21:06:45 +00001375U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001376 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001377 "simple RAM read/write test",
1378 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001379);
Wolfgang Denka2681702013-03-08 10:51:32 +00001380#endif /* CONFIG_CMD_MEMTEST */
wdenk8bde7f72003-06-27 21:31:46 +00001381
stroese4aaf29b2004-12-16 17:42:39 +00001382#ifdef CONFIG_MX_CYCLIC
1383U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001384 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001385 "memory display cyclic",
York Sun4d1fd7f2014-02-26 17:03:19 -08001386#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1387 "[.b, .w, .l, .q] address count delay(ms)"
1388#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001389 "[.b, .w, .l] address count delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001390#endif
stroese4aaf29b2004-12-16 17:42:39 +00001391);
1392
1393U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001394 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001395 "memory write cyclic",
York Sun4d1fd7f2014-02-26 17:03:19 -08001396#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1397 "[.b, .w, .l, .q] address value delay(ms)"
1398#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001399 "[.b, .w, .l] address value delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001400#endif
stroese4aaf29b2004-12-16 17:42:39 +00001401);
1402#endif /* CONFIG_MX_CYCLIC */
Simon Glass15a33e42012-11-30 13:01:20 +00001403
1404#ifdef CONFIG_CMD_MEMINFO
1405U_BOOT_CMD(
1406 meminfo, 3, 1, do_mem_info,
1407 "display memory information",
1408 ""
1409);
1410#endif