blob: 1febddb916c2fc6603ab890679782700923b88fa [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 Glass0098e172014-04-10 20:01:30 -060015#include <bootretry.h>
Simon Glass18d66532014-04-10 20:01:25 -060016#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000017#include <command.h>
wdenk2abbe072003-06-16 23:50:08 +000018#ifdef CONFIG_HAS_DATAFLASH
19#include <dataflash.h>
20#endif
Simon Glassd20a40d2013-02-24 20:30:22 +000021#include <hash.h>
Sergei Poselenova6e6fc62008-04-09 16:09:41 +020022#include <watchdog.h>
Simon Glass0628ab82013-02-24 17:33:15 +000023#include <asm/io.h>
Simon Glass15a33e42012-11-30 13:01:20 +000024#include <linux/compiler.h>
25
26DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000027
Simon Glass8e169cc2013-02-24 17:33:29 +000028#ifndef CONFIG_SYS_MEMTEST_SCRATCH
29#define CONFIG_SYS_MEMTEST_SCRATCH 0
30#endif
31
Wolfgang Denk54841ab2010-06-28 22:00:46 +020032static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000033
34/* Display values from last command.
35 * Memory modify remembered values are different from display memory.
36 */
Mike Frysingerd6efe242010-12-22 09:40:29 -050037static uint dp_last_addr, dp_last_size;
38static uint dp_last_length = 0x40;
39static uint mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000040
41static ulong base_address = 0;
42
43/* Memory Display
44 *
45 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -080046 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000047 */
48#define DISP_LINE_LEN 16
Kim Phillips088f1b12012-10-29 13:34:31 +000049static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000050{
wdenk27b207f2003-07-24 23:38:38 +000051 ulong addr, length;
Grant Likelyc95c4282007-02-20 09:05:00 +010052#if defined(CONFIG_HAS_DATAFLASH)
53 ulong nbytes, linebytes;
54#endif
wdenk27b207f2003-07-24 23:38:38 +000055 int size;
wdenk38635852002-08-27 05:55:31 +000056 int rc = 0;
57
58 /* We use the last specified parameters, unless new ones are
59 * entered.
60 */
61 addr = dp_last_addr;
62 size = dp_last_size;
63 length = dp_last_length;
64
Wolfgang Denk47e26b12010-07-17 01:06:04 +020065 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000066 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000067
68 if ((flag & CMD_FLAG_REPEAT) == 0) {
69 /* New command specified. Check for a size specification.
70 * Defaults to long if no or incorrect specification.
71 */
wdenk27b207f2003-07-24 23:38:38 +000072 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
73 return 1;
wdenk38635852002-08-27 05:55:31 +000074
75 /* Address is specified since argc > 1
76 */
77 addr = simple_strtoul(argv[1], NULL, 16);
78 addr += base_address;
79
80 /* If another parameter, it is the length to display.
81 * Length is the number of objects, not number of bytes.
82 */
83 if (argc > 2)
84 length = simple_strtoul(argv[2], NULL, 16);
85 }
86
Grant Likelyc95c4282007-02-20 09:05:00 +010087#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +000088 /* Print the lines.
89 *
90 * We buffer all read data, so we can make sure data is read only
91 * once, and all accesses are with the specified bus width.
92 */
93 nbytes = length * size;
94 do {
95 char linebuf[DISP_LINE_LEN];
Grant Likelyc95c4282007-02-20 09:05:00 +010096 void* p;
wdenk38635852002-08-27 05:55:31 +000097 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk2abbe072003-06-16 23:50:08 +000098
Grant Likelyc95c4282007-02-20 09:05:00 +010099 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
100 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
101 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk8bde7f72003-06-27 21:31:46 +0000102
wdenk38635852002-08-27 05:55:31 +0000103 nbytes -= linebytes;
Grant Likelyc95c4282007-02-20 09:05:00 +0100104 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000105 if (ctrlc()) {
106 rc = 1;
107 break;
108 }
109 } while (nbytes > 0);
Grant Likelyc95c4282007-02-20 09:05:00 +0100110#else
Mike Frysinger4c727c72008-02-04 19:26:56 -0500111
112# if defined(CONFIG_BLACKFIN)
113 /* See if we're trying to display L1 inst */
114 if (addr_bfin_on_chip_mem(addr)) {
115 char linebuf[DISP_LINE_LEN];
116 ulong linebytes, nbytes = length * size;
117 do {
118 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
119 memcpy(linebuf, (void *)addr, linebytes);
120 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
121
122 nbytes -= linebytes;
123 addr += linebytes;
124 if (ctrlc()) {
125 rc = 1;
126 break;
127 }
128 } while (nbytes > 0);
129 } else
130# endif
131
132 {
Simon Glass0628ab82013-02-24 17:33:15 +0000133 ulong bytes = size * length;
134 const void *buf = map_sysmem(addr, bytes);
135
Mike Frysinger4c727c72008-02-04 19:26:56 -0500136 /* Print the lines. */
Simon Glass0628ab82013-02-24 17:33:15 +0000137 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
138 addr += bytes;
139 unmap_sysmem(buf);
Mike Frysinger4c727c72008-02-04 19:26:56 -0500140 }
Grant Likelyc95c4282007-02-20 09:05:00 +0100141#endif
wdenk38635852002-08-27 05:55:31 +0000142
143 dp_last_addr = addr;
144 dp_last_length = length;
145 dp_last_size = size;
146 return (rc);
147}
148
Kim Phillips088f1b12012-10-29 13:34:31 +0000149static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000150{
151 return mod_mem (cmdtp, 1, flag, argc, argv);
152}
Kim Phillips088f1b12012-10-29 13:34:31 +0000153static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000154{
155 return mod_mem (cmdtp, 0, flag, argc, argv);
156}
157
Kim Phillips088f1b12012-10-29 13:34:31 +0000158static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000159{
York Sun4d1fd7f2014-02-26 17:03:19 -0800160#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
161 u64 writeval;
162#else
163 ulong writeval;
164#endif
165 ulong addr, count;
wdenk27b207f2003-07-24 23:38:38 +0000166 int size;
Simon Glass0628ab82013-02-24 17:33:15 +0000167 void *buf;
168 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000169
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200170 if ((argc < 3) || (argc > 4))
Simon Glass4c12eeb2011-12-10 08:44:01 +0000171 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000172
173 /* Check for size specification.
174 */
wdenk27b207f2003-07-24 23:38:38 +0000175 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
176 return 1;
wdenk38635852002-08-27 05:55:31 +0000177
178 /* Address is specified since argc > 1
179 */
180 addr = simple_strtoul(argv[1], NULL, 16);
181 addr += base_address;
182
183 /* Get the value to write.
184 */
York Sun4d1fd7f2014-02-26 17:03:19 -0800185#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
186 writeval = simple_strtoull(argv[2], NULL, 16);
187#else
wdenk38635852002-08-27 05:55:31 +0000188 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800189#endif
wdenk38635852002-08-27 05:55:31 +0000190
191 /* Count ? */
192 if (argc == 4) {
193 count = simple_strtoul(argv[3], NULL, 16);
194 } else {
195 count = 1;
196 }
197
Simon Glass0628ab82013-02-24 17:33:15 +0000198 bytes = size * count;
199 buf = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000200 while (count-- > 0) {
201 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -0800202 *((u32 *)buf) = (u32)writeval;
York Sun4d1fd7f2014-02-26 17:03:19 -0800203#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
204 else if (size == 8)
205 *((u64 *)buf) = (u64)writeval;
206#endif
wdenk38635852002-08-27 05:55:31 +0000207 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -0800208 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000209 else
York Sun76698b42014-02-12 15:55:35 -0800210 *((u8 *)buf) = (u8)writeval;
Simon Glass0628ab82013-02-24 17:33:15 +0000211 buf += size;
wdenk38635852002-08-27 05:55:31 +0000212 }
Simon Glass0628ab82013-02-24 17:33:15 +0000213 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +0000214 return 0;
215}
216
stroese4aaf29b2004-12-16 17:42:39 +0000217#ifdef CONFIG_MX_CYCLIC
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200218int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000219{
220 int i;
221 ulong count;
222
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200223 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000224 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000225
226 count = simple_strtoul(argv[3], NULL, 10);
227
228 for (;;) {
229 do_mem_md (NULL, 0, 3, argv);
230
231 /* delay for <count> ms... */
232 for (i=0; i<count; i++)
233 udelay (1000);
234
235 /* check for ctrl-c to abort... */
236 if (ctrlc()) {
237 puts("Abort\n");
238 return 0;
239 }
240 }
241
242 return 0;
243}
244
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200245int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000246{
247 int i;
248 ulong count;
249
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200250 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000251 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000252
253 count = simple_strtoul(argv[3], NULL, 10);
254
255 for (;;) {
256 do_mem_mw (NULL, 0, 3, argv);
257
258 /* delay for <count> ms... */
259 for (i=0; i<count; i++)
260 udelay (1000);
261
262 /* check for ctrl-c to abort... */
263 if (ctrlc()) {
264 puts("Abort\n");
265 return 0;
266 }
267 }
268
269 return 0;
270}
271#endif /* CONFIG_MX_CYCLIC */
272
Kim Phillips088f1b12012-10-29 13:34:31 +0000273static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000274{
Simon Glass0628ab82013-02-24 17:33:15 +0000275 ulong addr1, addr2, count, ngood, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000276 int size;
wdenk38635852002-08-27 05:55:31 +0000277 int rcode = 0;
Mike Frysinger054ea172012-01-20 09:07:21 +0000278 const char *type;
Simon Glass0628ab82013-02-24 17:33:15 +0000279 const void *buf1, *buf2, *base;
York Sun4d1fd7f2014-02-26 17:03:19 -0800280#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
281 u64 word1, word2;
282#else
283 ulong word1, word2;
284#endif
wdenk38635852002-08-27 05:55:31 +0000285
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200286 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000287 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000288
289 /* Check for size specification.
290 */
wdenk27b207f2003-07-24 23:38:38 +0000291 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
292 return 1;
York Sun4d1fd7f2014-02-26 17:03:19 -0800293 type = size == 8 ? "double word" :
294 size == 4 ? "word" :
295 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000296
297 addr1 = simple_strtoul(argv[1], NULL, 16);
298 addr1 += base_address;
299
300 addr2 = simple_strtoul(argv[2], NULL, 16);
301 addr2 += base_address;
302
303 count = simple_strtoul(argv[3], NULL, 16);
304
wdenk2abbe072003-06-16 23:50:08 +0000305#ifdef CONFIG_HAS_DATAFLASH
306 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk4b9206e2004-03-23 22:14:11 +0000307 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000308 return 0;
309 }
310#endif
311
Mike Frysinger4c727c72008-02-04 19:26:56 -0500312#ifdef CONFIG_BLACKFIN
313 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
314 puts ("Comparison with L1 instruction memory not supported.\n\r");
315 return 0;
316 }
317#endif
318
Simon Glass0628ab82013-02-24 17:33:15 +0000319 bytes = size * count;
320 base = buf1 = map_sysmem(addr1, bytes);
321 buf2 = map_sysmem(addr2, bytes);
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000322 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000323 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800324 word1 = *(u32 *)buf1;
325 word2 = *(u32 *)buf2;
York Sun4d1fd7f2014-02-26 17:03:19 -0800326#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
327 } else if (size == 8) {
328 word1 = *(u64 *)buf1;
329 word2 = *(u64 *)buf2;
330#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000331 } else if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800332 word1 = *(u16 *)buf1;
333 word2 = *(u16 *)buf2;
Mike Frysinger054ea172012-01-20 09:07:21 +0000334 } else {
York Sun76698b42014-02-12 15:55:35 -0800335 word1 = *(u8 *)buf1;
336 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000337 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000338 if (word1 != word2) {
Simon Glass0628ab82013-02-24 17:33:15 +0000339 ulong offset = buf1 - base;
York Sun4d1fd7f2014-02-26 17:03:19 -0800340#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
341 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
342 type, (void *)(addr1 + offset), size, word1,
343 type, (void *)(addr2 + offset), size, word2);
344#else
Mike Frysinger054ea172012-01-20 09:07:21 +0000345 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glass0628ab82013-02-24 17:33:15 +0000346 type, (ulong)(addr1 + offset), size, word1,
347 type, (ulong)(addr2 + offset), size, word2);
York Sun4d1fd7f2014-02-26 17:03:19 -0800348#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000349 rcode = 1;
350 break;
wdenk38635852002-08-27 05:55:31 +0000351 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000352
Simon Glass0628ab82013-02-24 17:33:15 +0000353 buf1 += size;
354 buf2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200355
356 /* reset watchdog from time to time */
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000357 if ((ngood % (64 << 10)) == 0)
Stefan Roeseeaadb442010-09-13 11:10:34 +0200358 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000359 }
Simon Glass0628ab82013-02-24 17:33:15 +0000360 unmap_sysmem(buf1);
361 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000362
Mike Frysinger054ea172012-01-20 09:07:21 +0000363 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000364 return rcode;
365}
366
Kim Phillips088f1b12012-10-29 13:34:31 +0000367static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000368{
Simon Glass0628ab82013-02-24 17:33:15 +0000369 ulong addr, dest, count, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000370 int size;
Simon Glass0628ab82013-02-24 17:33:15 +0000371 const void *src;
372 void *buf;
wdenk38635852002-08-27 05:55:31 +0000373
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200374 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000375 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000376
377 /* Check for size specification.
378 */
wdenk27b207f2003-07-24 23:38:38 +0000379 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
380 return 1;
wdenk38635852002-08-27 05:55:31 +0000381
382 addr = simple_strtoul(argv[1], NULL, 16);
383 addr += base_address;
384
385 dest = simple_strtoul(argv[2], NULL, 16);
386 dest += base_address;
387
388 count = simple_strtoul(argv[3], NULL, 16);
389
390 if (count == 0) {
391 puts ("Zero length ???\n");
392 return 1;
393 }
394
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200395#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000396 /* check if we are copying to Flash */
wdenk2abbe072003-06-16 23:50:08 +0000397 if ( (addr2info(dest) != NULL)
398#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino84d0c2f2008-03-03 10:39:13 +0200399 && (!addr_dataflash(dest))
wdenk2abbe072003-06-16 23:50:08 +0000400#endif
401 ) {
wdenk38635852002-08-27 05:55:31 +0000402 int rc;
403
wdenk4b9206e2004-03-23 22:14:11 +0000404 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000405
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200406 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000407 if (rc != 0) {
408 flash_perror (rc);
409 return (1);
410 }
411 puts ("done\n");
412 return 0;
413 }
414#endif
415
wdenk2abbe072003-06-16 23:50:08 +0000416#ifdef CONFIG_HAS_DATAFLASH
417 /* Check if we are copying from RAM or Flash to DataFlash */
418 if (addr_dataflash(dest) && !addr_dataflash(addr)){
419 int rc;
420
wdenk4b9206e2004-03-23 22:14:11 +0000421 puts ("Copy to DataFlash... ");
wdenk2abbe072003-06-16 23:50:08 +0000422
423 rc = write_dataflash (dest, addr, count*size);
424
425 if (rc != 1) {
426 dataflash_perror (rc);
427 return (1);
428 }
429 puts ("done\n");
430 return 0;
431 }
wdenk8bde7f72003-06-27 21:31:46 +0000432
wdenk2abbe072003-06-16 23:50:08 +0000433 /* Check if we are copying from DataFlash to RAM */
Stelian Pop880cc432008-03-26 22:52:35 +0100434 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200435#ifndef CONFIG_SYS_NO_FLASH
Stelian Pop880cc432008-03-26 22:52:35 +0100436 && (addr2info(dest) == NULL)
437#endif
438 ){
wdenk5779d8d2003-12-06 23:55:10 +0000439 int rc;
440 rc = read_dataflash(addr, count * size, (char *) dest);
441 if (rc != 1) {
wdenkd4ca31c2004-01-02 14:00:00 +0000442 dataflash_perror (rc);
443 return (1);
444 }
wdenk2abbe072003-06-16 23:50:08 +0000445 return 0;
446 }
447
448 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk4b9206e2004-03-23 22:14:11 +0000449 puts ("Unsupported combination of source/destination.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000450 return 1;
451 }
452#endif
453
Mike Frysinger4c727c72008-02-04 19:26:56 -0500454#ifdef CONFIG_BLACKFIN
455 /* See if we're copying to/from L1 inst */
456 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
457 memcpy((void *)dest, (void *)addr, count * size);
458 return 0;
459 }
460#endif
461
Simon Glass0628ab82013-02-24 17:33:15 +0000462 bytes = size * count;
Masahiro Yamada53237af2013-05-20 21:08:08 +0000463 buf = map_sysmem(dest, bytes);
Simon Glass0628ab82013-02-24 17:33:15 +0000464 src = map_sysmem(addr, bytes);
wdenk38635852002-08-27 05:55:31 +0000465 while (count-- > 0) {
466 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -0800467 *((u32 *)buf) = *((u32 *)src);
York Sun4d1fd7f2014-02-26 17:03:19 -0800468#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
469 else if (size == 8)
470 *((u64 *)buf) = *((u64 *)src);
471#endif
wdenk38635852002-08-27 05:55:31 +0000472 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -0800473 *((u16 *)buf) = *((u16 *)src);
wdenk38635852002-08-27 05:55:31 +0000474 else
York Sun76698b42014-02-12 15:55:35 -0800475 *((u8 *)buf) = *((u8 *)src);
Simon Glass0628ab82013-02-24 17:33:15 +0000476 src += size;
477 buf += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200478
479 /* reset watchdog from time to time */
480 if ((count % (64 << 10)) == 0)
481 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000482 }
483 return 0;
484}
485
Kim Phillips088f1b12012-10-29 13:34:31 +0000486static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
487 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000488{
489 if (argc > 1) {
490 /* Set new base address.
491 */
492 base_address = simple_strtoul(argv[1], NULL, 16);
493 }
494 /* Print the current base address.
495 */
496 printf("Base Address: 0x%08lx\n", base_address);
497 return 0;
498}
499
Kim Phillips088f1b12012-10-29 13:34:31 +0000500static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
501 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000502{
Simon Glass0628ab82013-02-24 17:33:15 +0000503 ulong addr, length, i, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000504 int size;
York Sun4d1fd7f2014-02-26 17:03:19 -0800505#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
506 volatile u64 *llp;
507#endif
York Sun76698b42014-02-12 15:55:35 -0800508 volatile u32 *longp;
509 volatile u16 *shortp;
510 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000511 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000512
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200513 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000514 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000515
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000516 /*
517 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000518 * Defaults to long if no or incorrect specification.
519 */
wdenk27b207f2003-07-24 23:38:38 +0000520 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
521 return 1;
wdenk38635852002-08-27 05:55:31 +0000522
523 /* Address is always specified.
524 */
525 addr = simple_strtoul(argv[1], NULL, 16);
526
527 /* Length is the number of objects, not number of bytes.
528 */
529 length = simple_strtoul(argv[2], NULL, 16);
530
Simon Glass0628ab82013-02-24 17:33:15 +0000531 bytes = size * length;
532 buf = map_sysmem(addr, bytes);
533
wdenk38635852002-08-27 05:55:31 +0000534 /* We want to optimize the loops to run as fast as possible.
535 * If we have only one object, just run infinite loops.
536 */
537 if (length == 1) {
York Sun4d1fd7f2014-02-26 17:03:19 -0800538#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
539 if (size == 8) {
540 llp = (u64 *)buf;
541 for (;;)
542 i = *llp;
543 }
544#endif
wdenk38635852002-08-27 05:55:31 +0000545 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800546 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000547 for (;;)
548 i = *longp;
549 }
550 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800551 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000552 for (;;)
553 i = *shortp;
554 }
York Sun76698b42014-02-12 15:55:35 -0800555 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000556 for (;;)
557 i = *cp;
558 }
559
York Sun4d1fd7f2014-02-26 17:03:19 -0800560#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
561 if (size == 8) {
562 for (;;) {
563 llp = (u64 *)buf;
564 i = length;
565 while (i-- > 0)
566 *llp++;
567 }
568 }
569#endif
wdenk38635852002-08-27 05:55:31 +0000570 if (size == 4) {
571 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800572 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000573 i = length;
574 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200575 *longp++;
wdenk38635852002-08-27 05:55:31 +0000576 }
577 }
578 if (size == 2) {
579 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800580 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000581 i = length;
582 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200583 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000584 }
585 }
586 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800587 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000588 i = length;
589 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200590 *cp++;
wdenk38635852002-08-27 05:55:31 +0000591 }
Simon Glass0628ab82013-02-24 17:33:15 +0000592 unmap_sysmem(buf);
Simon Glass92765f422013-06-11 11:14:35 -0700593
594 return 0;
wdenk38635852002-08-27 05:55:31 +0000595}
596
wdenk56523f12004-07-11 17:40:54 +0000597#ifdef CONFIG_LOOPW
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200598int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk56523f12004-07-11 17:40:54 +0000599{
York Sun4d1fd7f2014-02-26 17:03:19 -0800600 ulong addr, length, i, bytes;
wdenk56523f12004-07-11 17:40:54 +0000601 int size;
York Sun4d1fd7f2014-02-26 17:03:19 -0800602#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
603 volatile u64 *llp;
604 u64 data;
605#else
606 ulong data;
607#endif
York Sun76698b42014-02-12 15:55:35 -0800608 volatile u32 *longp;
609 volatile u16 *shortp;
610 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000611 void *buf;
wdenk81050922004-07-11 20:04:51 +0000612
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200613 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000614 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000615
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000616 /*
617 * Check for a size specification.
wdenk56523f12004-07-11 17:40:54 +0000618 * Defaults to long if no or incorrect specification.
619 */
620 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
621 return 1;
622
623 /* Address is always specified.
624 */
625 addr = simple_strtoul(argv[1], NULL, 16);
626
627 /* Length is the number of objects, not number of bytes.
628 */
629 length = simple_strtoul(argv[2], NULL, 16);
630
631 /* data to write */
York Sun4d1fd7f2014-02-26 17:03:19 -0800632#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
633 data = simple_strtoull(argv[3], NULL, 16);
634#else
wdenk56523f12004-07-11 17:40:54 +0000635 data = simple_strtoul(argv[3], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800636#endif
wdenk81050922004-07-11 20:04:51 +0000637
Simon Glass0628ab82013-02-24 17:33:15 +0000638 bytes = size * length;
639 buf = map_sysmem(addr, bytes);
640
wdenk56523f12004-07-11 17:40:54 +0000641 /* We want to optimize the loops to run as fast as possible.
642 * If we have only one object, just run infinite loops.
643 */
644 if (length == 1) {
York Sun4d1fd7f2014-02-26 17:03:19 -0800645#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
646 if (size == 8) {
647 llp = (u64 *)buf;
648 for (;;)
649 *llp = data;
650 }
651#endif
wdenk56523f12004-07-11 17:40:54 +0000652 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800653 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000654 for (;;)
655 *longp = data;
York Sun4d1fd7f2014-02-26 17:03:19 -0800656 }
wdenk56523f12004-07-11 17:40:54 +0000657 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800658 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000659 for (;;)
660 *shortp = data;
661 }
York Sun76698b42014-02-12 15:55:35 -0800662 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000663 for (;;)
664 *cp = data;
665 }
666
York Sun4d1fd7f2014-02-26 17:03:19 -0800667#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
668 if (size == 8) {
669 for (;;) {
670 llp = (u64 *)buf;
671 i = length;
672 while (i-- > 0)
673 *llp++ = data;
674 }
675 }
676#endif
wdenk56523f12004-07-11 17:40:54 +0000677 if (size == 4) {
678 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800679 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000680 i = length;
681 while (i-- > 0)
682 *longp++ = data;
683 }
684 }
685 if (size == 2) {
686 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800687 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000688 i = length;
689 while (i-- > 0)
690 *shortp++ = data;
691 }
692 }
693 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800694 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000695 i = length;
696 while (i-- > 0)
697 *cp++ = data;
698 }
699}
700#endif /* CONFIG_LOOPW */
701
Tom Rini68149e92013-03-12 10:07:19 -0400702#ifdef CONFIG_CMD_MEMTEST
Simon Glass5512d5b2013-02-28 17:47:14 +0000703static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
704 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000705{
Simon Glassc9638f52013-02-24 17:33:16 +0000706 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000707 ulong errs = 0;
708 ulong val, readback;
709 int j;
Simon Glassc9638f52013-02-24 17:33:16 +0000710 vu_long offset;
711 vu_long test_offset;
712 vu_long pattern;
713 vu_long temp;
714 vu_long anti_pattern;
715 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000716 static const ulong bitpattern[] = {
717 0x00000001, /* single bit */
718 0x00000003, /* two adjacent bits */
719 0x00000007, /* three adjacent bits */
720 0x0000000F, /* four adjacent bits */
721 0x00000005, /* two non-adjacent bits */
722 0x00000015, /* three non-adjacent bits */
723 0x00000055, /* four non-adjacent bits */
724 0xaaaaaaaa, /* alternating 1/0 */
725 };
wdenk38635852002-08-27 05:55:31 +0000726
Simon Glass5512d5b2013-02-28 17:47:14 +0000727 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000728
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000729 /*
730 * Data line test: write a pattern to the first
731 * location, write the 1's complement to a 'parking'
732 * address (changes the state of the data bus so a
733 * floating bus doesn't give a false OK), and then
734 * read the value back. Note that we read it back
735 * into a variable because the next time we read it,
736 * it might be right (been there, tough to explain to
737 * the quality guys why it prints a failure when the
738 * "is" and "should be" are obviously the same in the
739 * error message).
740 *
741 * Rather than exhaustively testing, we test some
742 * patterns by shifting '1' bits through a field of
743 * '0's and '0' bits through a field of '1's (i.e.
744 * pattern and ~pattern).
745 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000746 addr = buf;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000747 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
748 val = bitpattern[j];
749 for (; val != 0; val <<= 1) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000750 *addr = val;
Simon Glassc9638f52013-02-24 17:33:16 +0000751 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000752 readback = *addr;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000753 if (readback != val) {
Simon Glassc9638f52013-02-24 17:33:16 +0000754 printf("FAILURE (data line): "
755 "expected %08lx, actual %08lx\n",
756 val, readback);
757 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000758 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000759 return -1;
wdenk38635852002-08-27 05:55:31 +0000760 }
761 *addr = ~val;
762 *dummy = val;
763 readback = *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000764 if (readback != ~val) {
765 printf("FAILURE (data line): "
766 "Is %08lx, should be %08lx\n",
767 readback, ~val);
768 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000769 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000770 return -1;
wdenk38635852002-08-27 05:55:31 +0000771 }
wdenk38635852002-08-27 05:55:31 +0000772 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000773 }
wdenk38635852002-08-27 05:55:31 +0000774
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000775 /*
776 * Based on code whose Original Author and Copyright
777 * information follows: Copyright (c) 1998 by Michael
778 * Barr. This software is placed into the public
779 * domain and may be used for any purpose. However,
780 * this notice must not be changed or removed and no
781 * warranty is either expressed or implied by its
782 * publication or distribution.
783 */
wdenk38635852002-08-27 05:55:31 +0000784
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000785 /*
786 * Address line test
wdenk38635852002-08-27 05:55:31 +0000787
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000788 * Description: Test the address bus wiring in a
789 * memory region by performing a walking
790 * 1's test on the relevant bits of the
791 * address and checking for aliasing.
792 * This test will find single-bit
793 * address failures such as stuck-high,
794 * stuck-low, and shorted pins. The base
795 * address and size of the region are
796 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000797
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000798 * Notes: For best results, the selected base
799 * address should have enough LSB 0's to
800 * guarantee single address bit changes.
801 * For example, to test a 64-Kbyte
802 * region, select a base address on a
803 * 64-Kbyte boundary. Also, select the
804 * region size as a power-of-two if at
805 * all possible.
806 *
807 * Returns: 0 if the test succeeds, 1 if the test fails.
808 */
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000809 pattern = (vu_long) 0xaaaaaaaa;
810 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000811
Simon Glass5512d5b2013-02-28 17:47:14 +0000812 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000813 /*
814 * Write the default pattern at each of the
815 * power-of-two offsets.
816 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000817 for (offset = 1; offset < num_words; offset <<= 1)
818 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000819
820 /*
821 * Check for address bits stuck high.
822 */
823 test_offset = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000824 addr[test_offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000825
Simon Glass5512d5b2013-02-28 17:47:14 +0000826 for (offset = 1; offset < num_words; offset <<= 1) {
827 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000828 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000829 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000830 " expected 0x%.8lx, actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800831 start_addr + offset*sizeof(vu_long),
832 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400833 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000834 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000835 return -1;
wdenk38635852002-08-27 05:55:31 +0000836 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000837 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000838 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000839 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000840
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000841 /*
842 * Check for addr bits stuck low or shorted.
843 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000844 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
845 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000846
Simon Glass5512d5b2013-02-28 17:47:14 +0000847 for (offset = 1; offset < num_words; offset <<= 1) {
848 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000849 if ((temp != pattern) && (offset != test_offset)) {
850 printf("\nFAILURE: Address bit stuck low or"
851 " shorted @ 0x%.8lx: expected 0x%.8lx,"
852 " actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800853 start_addr + offset*sizeof(vu_long),
854 pattern, temp);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000855 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000856 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000857 return -1;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000858 }
wdenk38635852002-08-27 05:55:31 +0000859 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000860 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000861 }
wdenk38635852002-08-27 05:55:31 +0000862
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000863 /*
864 * Description: Test the integrity of a physical
865 * memory device by performing an
866 * increment/decrement test over the
867 * entire region. In the process every
868 * storage bit in the device is tested
869 * as a zero and a one. The base address
870 * and the size of the region are
871 * selected by the caller.
872 *
873 * Returns: 0 if the test succeeds, 1 if the test fails.
874 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000875 num_words++;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000876
877 /*
878 * Fill memory with a known pattern.
879 */
880 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
881 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000882 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000883 }
884
885 /*
886 * Check each location and invert it for the second pass.
887 */
888 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
889 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000890 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000891 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000892 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000893 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800894 start_addr + offset*sizeof(vu_long),
895 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400896 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000897 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000898 return -1;
wdenk38635852002-08-27 05:55:31 +0000899 }
900
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000901 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000902 addr[offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000903 }
904
905 /*
906 * Check each location for the inverted pattern and zero it.
907 */
908 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
909 WATCHDOG_RESET();
910 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000911 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000912 if (temp != anti_pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000913 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000914 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800915 start_addr + offset*sizeof(vu_long),
916 anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400917 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000918 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000919 return -1;
wdenk38635852002-08-27 05:55:31 +0000920 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000921 addr[offset] = 0;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000922 }
Simon Glass51209b12013-02-24 17:33:17 +0000923
924 return 0;
Simon Glassc9638f52013-02-24 17:33:16 +0000925}
wdenk38635852002-08-27 05:55:31 +0000926
Simon Glass5512d5b2013-02-28 17:47:14 +0000927static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
928 vu_long pattern, int iteration)
Simon Glassc9638f52013-02-24 17:33:16 +0000929{
Simon Glass5512d5b2013-02-28 17:47:14 +0000930 vu_long *end;
Simon Glassc9638f52013-02-24 17:33:16 +0000931 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000932 ulong errs = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000933 ulong incr, length;
Simon Glassc9638f52013-02-24 17:33:16 +0000934 ulong val, readback;
935
Simon Glass51209b12013-02-24 17:33:17 +0000936 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000937 incr = 1;
Simon Glass51209b12013-02-24 17:33:17 +0000938 if (iteration & 1) {
939 incr = -incr;
940 /*
941 * Flip the pattern each time to make lots of zeros and
942 * then, the next time, lots of ones. We decrement
943 * the "negative" patterns and increment the "positive"
944 * patterns to preserve this feature.
945 */
946 if (pattern & 0x80000000)
947 pattern = -pattern; /* complement & increment */
948 else
949 pattern = ~pattern;
950 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000951 length = (end_addr - start_addr) / sizeof(ulong);
952 end = buf + length;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000953 printf("\rPattern %08lX Writing..."
954 "%12s"
955 "\b\b\b\b\b\b\b\b\b\b",
956 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000957
Simon Glass5512d5b2013-02-28 17:47:14 +0000958 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000959 WATCHDOG_RESET();
960 *addr = val;
961 val += incr;
962 }
wdenk38635852002-08-27 05:55:31 +0000963
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000964 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000965
Simon Glass5512d5b2013-02-28 17:47:14 +0000966 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000967 WATCHDOG_RESET();
968 readback = *addr;
969 if (readback != val) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000970 ulong offset = addr - buf;
971
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000972 printf("\nMem error @ 0x%08X: "
973 "found %08lX, expected %08lX\n",
David Feng102c0512014-02-12 16:10:08 +0800974 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glass5512d5b2013-02-28 17:47:14 +0000975 readback, val);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000976 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000977 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000978 return -1;
wdenk38635852002-08-27 05:55:31 +0000979 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000980 val += incr;
981 }
wdenk38635852002-08-27 05:55:31 +0000982
Simon Glass51209b12013-02-24 17:33:17 +0000983 return 0;
Simon Glassc9638f52013-02-24 17:33:16 +0000984}
985
986/*
987 * Perform a memory test. A more complete alternative test can be
988 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
989 * interrupted by ctrl-c or by a failure of one of the sub-tests.
990 */
991static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
992 char * const argv[])
993{
Simon Glass8c86bbe2013-02-24 17:33:20 +0000994 ulong start, end;
Simon Glass5512d5b2013-02-28 17:47:14 +0000995 vu_long *buf, *dummy;
Simon Glassc9638f52013-02-24 17:33:16 +0000996 int iteration_limit;
997 int ret;
Simon Glass51209b12013-02-24 17:33:17 +0000998 ulong errs = 0; /* number of errors, or -1 if interrupted */
Simon Glassc9638f52013-02-24 17:33:16 +0000999 ulong pattern;
Simon Glass51209b12013-02-24 17:33:17 +00001000 int iteration;
Simon Glassc9638f52013-02-24 17:33:16 +00001001#if defined(CONFIG_SYS_ALT_MEMTEST)
1002 const int alt_test = 1;
1003#else
1004 const int alt_test = 0;
wdenk38635852002-08-27 05:55:31 +00001005#endif
Simon Glassc9638f52013-02-24 17:33:16 +00001006
1007 if (argc > 1)
Simon Glass8c86bbe2013-02-24 17:33:20 +00001008 start = simple_strtoul(argv[1], NULL, 16);
Simon Glassc9638f52013-02-24 17:33:16 +00001009 else
Simon Glass8c86bbe2013-02-24 17:33:20 +00001010 start = CONFIG_SYS_MEMTEST_START;
Simon Glassc9638f52013-02-24 17:33:16 +00001011
1012 if (argc > 2)
Simon Glass8c86bbe2013-02-24 17:33:20 +00001013 end = simple_strtoul(argv[2], NULL, 16);
Simon Glassc9638f52013-02-24 17:33:16 +00001014 else
Simon Glass8c86bbe2013-02-24 17:33:20 +00001015 end = CONFIG_SYS_MEMTEST_END;
Simon Glassc9638f52013-02-24 17:33:16 +00001016
1017 if (argc > 3)
1018 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
1019 else
1020 pattern = 0;
1021
1022 if (argc > 4)
1023 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
1024 else
1025 iteration_limit = 0;
1026
Simon Glass8c86bbe2013-02-24 17:33:20 +00001027 printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
1028 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1029 start, end);
Simon Glass51209b12013-02-24 17:33:17 +00001030
Simon Glass5512d5b2013-02-28 17:47:14 +00001031 buf = map_sysmem(start, end - start);
1032 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
Simon Glass51209b12013-02-24 17:33:17 +00001033 for (iteration = 0;
1034 !iteration_limit || iteration < iteration_limit;
1035 iteration++) {
1036 if (ctrlc()) {
Simon Glass51209b12013-02-24 17:33:17 +00001037 errs = -1UL;
1038 break;
1039 }
1040
1041 printf("Iteration: %6d\r", iteration + 1);
1042 debug("\n");
Simon Glass5512d5b2013-02-28 17:47:14 +00001043 if (alt_test) {
1044 errs = mem_test_alt(buf, start, end, dummy);
1045 } else {
1046 errs = mem_test_quick(buf, start, end, pattern,
1047 iteration);
1048 }
1049 if (errs == -1UL)
1050 break;
1051 }
1052
1053 /*
1054 * Work-around for eldk-4.2 which gives this warning if we try to
1055 * case in the unmap_sysmem() call:
1056 * warning: initialization discards qualifiers from pointer target type
1057 */
1058 {
1059 void *vbuf = (void *)buf;
1060 void *vdummy = (void *)dummy;
1061
1062 unmap_sysmem(vbuf);
1063 unmap_sysmem(vdummy);
Simon Glass51209b12013-02-24 17:33:17 +00001064 }
1065
1066 if (errs == -1UL) {
Simon Glassc44d4382013-02-24 17:33:19 +00001067 /* Memory test was aborted - write a newline to finish off */
1068 putc('\n');
Simon Glass51209b12013-02-24 17:33:17 +00001069 ret = 1;
1070 } else {
1071 printf("Tested %d iteration(s) with %lu errors.\n",
1072 iteration, errs);
1073 ret = errs != 0;
1074 }
Simon Glassc9638f52013-02-24 17:33:16 +00001075
1076 return ret; /* not reached */
wdenk38635852002-08-27 05:55:31 +00001077}
Wolfgang Denka2681702013-03-08 10:51:32 +00001078#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001079
1080/* Modify memory.
1081 *
1082 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -08001083 * mm{.b, .w, .l, .q} {addr}
1084 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001085 */
1086static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001087mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001088{
York Sun4d1fd7f2014-02-26 17:03:19 -08001089 ulong addr;
1090#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1091 u64 i;
1092#else
1093 ulong i;
1094#endif
wdenk27b207f2003-07-24 23:38:38 +00001095 int nbytes, size;
Simon Glass0628ab82013-02-24 17:33:15 +00001096 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001097
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001098 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001099 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001100
Simon Glassb26440f2014-04-10 20:01:31 -06001101 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001102 /* We use the last specified parameters, unless new ones are
1103 * entered.
1104 */
1105 addr = mm_last_addr;
1106 size = mm_last_size;
1107
1108 if ((flag & CMD_FLAG_REPEAT) == 0) {
1109 /* New command specified. Check for a size specification.
1110 * Defaults to long if no or incorrect specification.
1111 */
wdenk27b207f2003-07-24 23:38:38 +00001112 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1113 return 1;
wdenk38635852002-08-27 05:55:31 +00001114
1115 /* Address is specified since argc > 1
1116 */
1117 addr = simple_strtoul(argv[1], NULL, 16);
1118 addr += base_address;
1119 }
1120
wdenk2abbe072003-06-16 23:50:08 +00001121#ifdef CONFIG_HAS_DATAFLASH
1122 if (addr_dataflash(addr)){
wdenk4b9206e2004-03-23 22:14:11 +00001123 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk2abbe072003-06-16 23:50:08 +00001124 return 0;
1125 }
1126#endif
1127
Mike Frysinger4c727c72008-02-04 19:26:56 -05001128#ifdef CONFIG_BLACKFIN
1129 if (addr_bfin_on_chip_mem(addr)) {
1130 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1131 return 0;
1132 }
1133#endif
1134
wdenk38635852002-08-27 05:55:31 +00001135 /* Print the address, followed by value. Then accept input for
1136 * the next value. A non-converted value exits.
1137 */
1138 do {
Simon Glass0628ab82013-02-24 17:33:15 +00001139 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001140 printf("%08lx:", addr);
1141 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001142 printf(" %08x", *((u32 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001143#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1144 else if (size == 8)
1145 printf(" %016llx", *((u64 *)ptr));
1146#endif
wdenk38635852002-08-27 05:55:31 +00001147 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001148 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001149 else
York Sun76698b42014-02-12 15:55:35 -08001150 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001151
Simon Glasse1bf8242014-04-10 20:01:27 -06001152 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001153 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1154 /* <CR> pressed as only input, don't modify current
1155 * location and move to next. "-" pressed will go back.
1156 */
1157 if (incrflag)
1158 addr += nbytes ? -size : size;
1159 nbytes = 1;
Simon Glassb26440f2014-04-10 20:01:31 -06001160 /* good enough to not time out */
1161 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001162 }
1163#ifdef CONFIG_BOOT_RETRY_TIME
1164 else if (nbytes == -2) {
1165 break; /* timed out, exit the command */
1166 }
1167#endif
1168 else {
1169 char *endp;
York Sun4d1fd7f2014-02-26 17:03:19 -08001170#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1171 i = simple_strtoull(console_buffer, &endp, 16);
1172#else
wdenk38635852002-08-27 05:55:31 +00001173 i = simple_strtoul(console_buffer, &endp, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -08001174#endif
wdenk38635852002-08-27 05:55:31 +00001175 nbytes = endp - console_buffer;
1176 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001177 /* good enough to not time out
1178 */
Simon Glassb26440f2014-04-10 20:01:31 -06001179 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001180 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001181 *((u32 *)ptr) = i;
York Sun4d1fd7f2014-02-26 17:03:19 -08001182#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1183 else if (size == 8)
1184 *((u64 *)ptr) = i;
1185#endif
wdenk38635852002-08-27 05:55:31 +00001186 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001187 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001188 else
York Sun76698b42014-02-12 15:55:35 -08001189 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001190 if (incrflag)
1191 addr += size;
1192 }
1193 }
1194 } while (nbytes);
Simon Glass0628ab82013-02-24 17:33:15 +00001195 if (ptr)
1196 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001197
1198 mm_last_addr = addr;
1199 mm_last_size = size;
1200 return 0;
1201}
1202
Mike Frysinger710b9932010-12-21 14:19:51 -05001203#ifdef CONFIG_CMD_CRC32
1204
Kim Phillips088f1b12012-10-29 13:34:31 +00001205static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001206{
Simon Glassd20a40d2013-02-24 20:30:22 +00001207 int flags = 0;
1208 int ac;
1209 char * const *av;
wdenk38635852002-08-27 05:55:31 +00001210
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001211 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001212 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001213
wdenkc26e4542004-04-18 10:13:26 +00001214 av = argv + 1;
1215 ac = argc - 1;
Simon Glassd20a40d2013-02-24 20:30:22 +00001216#ifdef CONFIG_HASH_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001217 if (strcmp(*av, "-v") == 0) {
Simon Glassd20a40d2013-02-24 20:30:22 +00001218 flags |= HASH_FLAG_VERIFY;
wdenkc26e4542004-04-18 10:13:26 +00001219 av++;
1220 ac--;
wdenkc26e4542004-04-18 10:13:26 +00001221 }
Simon Glassd20a40d2013-02-24 20:30:22 +00001222#endif
wdenkc26e4542004-04-18 10:13:26 +00001223
Simon Glassd20a40d2013-02-24 20:30:22 +00001224 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenkc26e4542004-04-18 10:13:26 +00001225}
wdenkc26e4542004-04-18 10:13:26 +00001226
Mike Frysinger710b9932010-12-21 14:19:51 -05001227#endif
1228
wdenk8bde7f72003-06-27 21:31:46 +00001229/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001230U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001231 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001232 "memory display",
York Sun4d1fd7f2014-02-26 17:03:19 -08001233#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1234 "[.b, .w, .l, .q] address [# of objects]"
1235#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001236 "[.b, .w, .l] address [# of objects]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001237#endif
wdenk8bde7f72003-06-27 21:31:46 +00001238);
1239
1240
wdenk0d498392003-07-01 21:06:45 +00001241U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001242 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001243 "memory modify (auto-incrementing address)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001244#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1245 "[.b, .w, .l, .q] address"
1246#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001247 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001248#endif
wdenk8bde7f72003-06-27 21:31:46 +00001249);
1250
1251
wdenk0d498392003-07-01 21:06:45 +00001252U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001253 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001254 "memory modify (constant address)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001255#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1256 "[.b, .w, .l, .q] address"
1257#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001258 "[.b, .w, .l] address"
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 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001264 "memory write (fill)",
York Sun4d1fd7f2014-02-26 17:03:19 -08001265#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1266 "[.b, .w, .l, .q] address value [count]"
1267#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001268 "[.b, .w, .l] address value [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 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001274 "memory copy",
York Sun4d1fd7f2014-02-26 17:03:19 -08001275#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1276 "[.b, .w, .l, .q] source target count"
1277#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001278 "[.b, .w, .l] source target count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001279#endif
wdenk8bde7f72003-06-27 21:31:46 +00001280);
1281
wdenk0d498392003-07-01 21:06:45 +00001282U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001283 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001284 "memory compare",
York Sun4d1fd7f2014-02-26 17:03:19 -08001285#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1286 "[.b, .w, .l, .q] addr1 addr2 count"
1287#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001288 "[.b, .w, .l] addr1 addr2 count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001289#endif
wdenk8bde7f72003-06-27 21:31:46 +00001290);
1291
Mike Frysinger710b9932010-12-21 14:19:51 -05001292#ifdef CONFIG_CMD_CRC32
1293
wdenkc26e4542004-04-18 10:13:26 +00001294#ifndef CONFIG_CRC32_VERIFY
1295
wdenk0d498392003-07-01 21:06:45 +00001296U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001297 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001298 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001299 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001300);
1301
wdenkc26e4542004-04-18 10:13:26 +00001302#else /* CONFIG_CRC32_VERIFY */
1303
1304U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001305 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001306 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001307 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001308 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001309);
1310
1311#endif /* CONFIG_CRC32_VERIFY */
1312
Mike Frysinger710b9932010-12-21 14:19:51 -05001313#endif
1314
Simon Glass15a33e42012-11-30 13:01:20 +00001315#ifdef CONFIG_CMD_MEMINFO
1316__weak void board_show_dram(ulong size)
1317{
1318 puts("DRAM: ");
1319 print_size(size, "\n");
1320}
1321
1322static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1323 char * const argv[])
1324{
1325 board_show_dram(gd->ram_size);
1326
1327 return 0;
1328}
1329#endif
1330
wdenk0d498392003-07-01 21:06:45 +00001331U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001332 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001333 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001334 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001335 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001336);
1337
wdenk0d498392003-07-01 21:06:45 +00001338U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001339 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001340 "infinite loop on address range",
York Sun4d1fd7f2014-02-26 17:03:19 -08001341#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1342 "[.b, .w, .l, .q] address number_of_objects"
1343#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001344 "[.b, .w, .l] address number_of_objects"
York Sun4d1fd7f2014-02-26 17:03:19 -08001345#endif
wdenk8bde7f72003-06-27 21:31:46 +00001346);
1347
wdenk56523f12004-07-11 17:40:54 +00001348#ifdef CONFIG_LOOPW
1349U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001350 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001351 "infinite write loop on address range",
York Sun4d1fd7f2014-02-26 17:03:19 -08001352#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1353 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1354#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001355 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun4d1fd7f2014-02-26 17:03:19 -08001356#endif
wdenk56523f12004-07-11 17:40:54 +00001357);
1358#endif /* CONFIG_LOOPW */
1359
Wolfgang Denka2681702013-03-08 10:51:32 +00001360#ifdef CONFIG_CMD_MEMTEST
wdenk0d498392003-07-01 21:06:45 +00001361U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001362 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001363 "simple RAM read/write test",
1364 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001365);
Wolfgang Denka2681702013-03-08 10:51:32 +00001366#endif /* CONFIG_CMD_MEMTEST */
wdenk8bde7f72003-06-27 21:31:46 +00001367
stroese4aaf29b2004-12-16 17:42:39 +00001368#ifdef CONFIG_MX_CYCLIC
1369U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001370 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001371 "memory display cyclic",
York Sun4d1fd7f2014-02-26 17:03:19 -08001372#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1373 "[.b, .w, .l, .q] address count delay(ms)"
1374#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001375 "[.b, .w, .l] address count delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001376#endif
stroese4aaf29b2004-12-16 17:42:39 +00001377);
1378
1379U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001380 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001381 "memory write cyclic",
York Sun4d1fd7f2014-02-26 17:03:19 -08001382#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1383 "[.b, .w, .l, .q] address value delay(ms)"
1384#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001385 "[.b, .w, .l] address value delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001386#endif
stroese4aaf29b2004-12-16 17:42:39 +00001387);
1388#endif /* CONFIG_MX_CYCLIC */
Simon Glass15a33e42012-11-30 13:01:20 +00001389
1390#ifdef CONFIG_CMD_MEMINFO
1391U_BOOT_CMD(
1392 meminfo, 3, 1, do_mem_info,
1393 "display memory information",
1394 ""
1395);
1396#endif