blob: 18f0a3f50fcb85ec1401dcad52a15f42e3dc8eb9 [file] [log] [blame]
wdenk38635852002-08-27 05:55:31 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * Memory Functions
26 *
27 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
28 */
29
30#include <common.h>
31#include <command.h>
wdenk2abbe072003-06-16 23:50:08 +000032#ifdef CONFIG_HAS_DATAFLASH
33#include <dataflash.h>
34#endif
Sergei Poselenova6e6fc62008-04-09 16:09:41 +020035#include <watchdog.h>
wdenk38635852002-08-27 05:55:31 +000036
Wolfgang Denk54841ab2010-06-28 22:00:46 +020037static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000038
39/* Display values from last command.
40 * Memory modify remembered values are different from display memory.
41 */
Mike Frysingerd6efe242010-12-22 09:40:29 -050042static uint dp_last_addr, dp_last_size;
43static uint dp_last_length = 0x40;
44static uint mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000045
46static ulong base_address = 0;
47
48/* Memory Display
49 *
50 * Syntax:
51 * md{.b, .w, .l} {addr} {len}
52 */
53#define DISP_LINE_LEN 16
Wolfgang Denk54841ab2010-06-28 22:00:46 +020054int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000055{
wdenk27b207f2003-07-24 23:38:38 +000056 ulong addr, length;
Grant Likelyc95c4282007-02-20 09:05:00 +010057#if defined(CONFIG_HAS_DATAFLASH)
58 ulong nbytes, linebytes;
59#endif
wdenk27b207f2003-07-24 23:38:38 +000060 int size;
wdenk38635852002-08-27 05:55:31 +000061 int rc = 0;
62
63 /* We use the last specified parameters, unless new ones are
64 * entered.
65 */
66 addr = dp_last_addr;
67 size = dp_last_size;
68 length = dp_last_length;
69
Wolfgang Denk47e26b12010-07-17 01:06:04 +020070 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000071 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000072
73 if ((flag & CMD_FLAG_REPEAT) == 0) {
74 /* New command specified. Check for a size specification.
75 * Defaults to long if no or incorrect specification.
76 */
wdenk27b207f2003-07-24 23:38:38 +000077 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
78 return 1;
wdenk38635852002-08-27 05:55:31 +000079
80 /* Address is specified since argc > 1
81 */
82 addr = simple_strtoul(argv[1], NULL, 16);
83 addr += base_address;
84
85 /* If another parameter, it is the length to display.
86 * Length is the number of objects, not number of bytes.
87 */
88 if (argc > 2)
89 length = simple_strtoul(argv[2], NULL, 16);
90 }
91
Grant Likelyc95c4282007-02-20 09:05:00 +010092#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +000093 /* Print the lines.
94 *
95 * We buffer all read data, so we can make sure data is read only
96 * once, and all accesses are with the specified bus width.
97 */
98 nbytes = length * size;
99 do {
100 char linebuf[DISP_LINE_LEN];
Grant Likelyc95c4282007-02-20 09:05:00 +0100101 void* p;
wdenk38635852002-08-27 05:55:31 +0000102 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk2abbe072003-06-16 23:50:08 +0000103
Grant Likelyc95c4282007-02-20 09:05:00 +0100104 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
105 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
106 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk8bde7f72003-06-27 21:31:46 +0000107
wdenk38635852002-08-27 05:55:31 +0000108 nbytes -= linebytes;
Grant Likelyc95c4282007-02-20 09:05:00 +0100109 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000110 if (ctrlc()) {
111 rc = 1;
112 break;
113 }
114 } while (nbytes > 0);
Grant Likelyc95c4282007-02-20 09:05:00 +0100115#else
Mike Frysinger4c727c72008-02-04 19:26:56 -0500116
117# if defined(CONFIG_BLACKFIN)
118 /* See if we're trying to display L1 inst */
119 if (addr_bfin_on_chip_mem(addr)) {
120 char linebuf[DISP_LINE_LEN];
121 ulong linebytes, nbytes = length * size;
122 do {
123 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
124 memcpy(linebuf, (void *)addr, linebytes);
125 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
126
127 nbytes -= linebytes;
128 addr += linebytes;
129 if (ctrlc()) {
130 rc = 1;
131 break;
132 }
133 } while (nbytes > 0);
134 } else
135# endif
136
137 {
138 /* Print the lines. */
Kumar Gala94c50f12011-11-12 08:02:12 +0000139 print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
140 addr += size*length;
Mike Frysinger4c727c72008-02-04 19:26:56 -0500141 }
Grant Likelyc95c4282007-02-20 09:05:00 +0100142#endif
wdenk38635852002-08-27 05:55:31 +0000143
144 dp_last_addr = addr;
145 dp_last_length = length;
146 dp_last_size = size;
147 return (rc);
148}
149
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200150int do_mem_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000151{
152 return mod_mem (cmdtp, 1, flag, argc, argv);
153}
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200154int do_mem_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000155{
156 return mod_mem (cmdtp, 0, flag, argc, argv);
157}
158
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200159int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000160{
wdenk27b207f2003-07-24 23:38:38 +0000161 ulong addr, writeval, count;
162 int size;
wdenk38635852002-08-27 05:55:31 +0000163
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200164 if ((argc < 3) || (argc > 4))
Simon Glass4c12eeb2011-12-10 08:44:01 +0000165 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000166
167 /* Check for size specification.
168 */
wdenk27b207f2003-07-24 23:38:38 +0000169 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
170 return 1;
wdenk38635852002-08-27 05:55:31 +0000171
172 /* Address is specified since argc > 1
173 */
174 addr = simple_strtoul(argv[1], NULL, 16);
175 addr += base_address;
176
177 /* Get the value to write.
178 */
179 writeval = simple_strtoul(argv[2], NULL, 16);
180
181 /* Count ? */
182 if (argc == 4) {
183 count = simple_strtoul(argv[3], NULL, 16);
184 } else {
185 count = 1;
186 }
187
188 while (count-- > 0) {
189 if (size == 4)
190 *((ulong *)addr) = (ulong )writeval;
191 else if (size == 2)
192 *((ushort *)addr) = (ushort)writeval;
193 else
194 *((u_char *)addr) = (u_char)writeval;
195 addr += size;
196 }
197 return 0;
198}
199
stroese4aaf29b2004-12-16 17:42:39 +0000200#ifdef CONFIG_MX_CYCLIC
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200201int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000202{
203 int i;
204 ulong count;
205
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200206 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000207 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000208
209 count = simple_strtoul(argv[3], NULL, 10);
210
211 for (;;) {
212 do_mem_md (NULL, 0, 3, argv);
213
214 /* delay for <count> ms... */
215 for (i=0; i<count; i++)
216 udelay (1000);
217
218 /* check for ctrl-c to abort... */
219 if (ctrlc()) {
220 puts("Abort\n");
221 return 0;
222 }
223 }
224
225 return 0;
226}
227
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200228int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000229{
230 int i;
231 ulong count;
232
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200233 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000234 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000235
236 count = simple_strtoul(argv[3], NULL, 10);
237
238 for (;;) {
239 do_mem_mw (NULL, 0, 3, argv);
240
241 /* delay for <count> ms... */
242 for (i=0; i<count; i++)
243 udelay (1000);
244
245 /* check for ctrl-c to abort... */
246 if (ctrlc()) {
247 puts("Abort\n");
248 return 0;
249 }
250 }
251
252 return 0;
253}
254#endif /* CONFIG_MX_CYCLIC */
255
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200256int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000257{
wdenk27b207f2003-07-24 23:38:38 +0000258 ulong addr1, addr2, count, ngood;
259 int size;
wdenk38635852002-08-27 05:55:31 +0000260 int rcode = 0;
Mike Frysinger054ea172012-01-20 09:07:21 +0000261 const char *type;
wdenk38635852002-08-27 05:55:31 +0000262
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200263 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000264 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000265
266 /* Check for size specification.
267 */
wdenk27b207f2003-07-24 23:38:38 +0000268 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
269 return 1;
Mike Frysinger054ea172012-01-20 09:07:21 +0000270 type = size == 4 ? "word" : size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000271
272 addr1 = simple_strtoul(argv[1], NULL, 16);
273 addr1 += base_address;
274
275 addr2 = simple_strtoul(argv[2], NULL, 16);
276 addr2 += base_address;
277
278 count = simple_strtoul(argv[3], NULL, 16);
279
wdenk2abbe072003-06-16 23:50:08 +0000280#ifdef CONFIG_HAS_DATAFLASH
281 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk4b9206e2004-03-23 22:14:11 +0000282 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000283 return 0;
284 }
285#endif
286
Mike Frysinger4c727c72008-02-04 19:26:56 -0500287#ifdef CONFIG_BLACKFIN
288 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
289 puts ("Comparison with L1 instruction memory not supported.\n\r");
290 return 0;
291 }
292#endif
293
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000294 for (ngood = 0; ngood < count; ++ngood) {
Mike Frysinger054ea172012-01-20 09:07:21 +0000295 ulong word1, word2;
wdenk38635852002-08-27 05:55:31 +0000296 if (size == 4) {
Mike Frysinger054ea172012-01-20 09:07:21 +0000297 word1 = *(ulong *)addr1;
298 word2 = *(ulong *)addr2;
299 } else if (size == 2) {
300 word1 = *(ushort *)addr1;
301 word2 = *(ushort *)addr2;
302 } else {
303 word1 = *(u_char *)addr1;
304 word2 = *(u_char *)addr2;
wdenk38635852002-08-27 05:55:31 +0000305 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000306 if (word1 != word2) {
307 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
308 type, addr1, size, word1,
309 type, addr2, size, word2);
310 rcode = 1;
311 break;
wdenk38635852002-08-27 05:55:31 +0000312 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000313
wdenk38635852002-08-27 05:55:31 +0000314 addr1 += size;
315 addr2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200316
317 /* reset watchdog from time to time */
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000318 if ((ngood % (64 << 10)) == 0)
Stefan Roeseeaadb442010-09-13 11:10:34 +0200319 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000320 }
321
Mike Frysinger054ea172012-01-20 09:07:21 +0000322 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000323 return rcode;
324}
325
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200326int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000327{
wdenk27b207f2003-07-24 23:38:38 +0000328 ulong addr, dest, count;
329 int size;
wdenk38635852002-08-27 05:55:31 +0000330
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200331 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000332 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000333
334 /* Check for size specification.
335 */
wdenk27b207f2003-07-24 23:38:38 +0000336 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
337 return 1;
wdenk38635852002-08-27 05:55:31 +0000338
339 addr = simple_strtoul(argv[1], NULL, 16);
340 addr += base_address;
341
342 dest = simple_strtoul(argv[2], NULL, 16);
343 dest += base_address;
344
345 count = simple_strtoul(argv[3], NULL, 16);
346
347 if (count == 0) {
348 puts ("Zero length ???\n");
349 return 1;
350 }
351
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200352#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000353 /* check if we are copying to Flash */
wdenk2abbe072003-06-16 23:50:08 +0000354 if ( (addr2info(dest) != NULL)
355#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino84d0c2f2008-03-03 10:39:13 +0200356 && (!addr_dataflash(dest))
wdenk2abbe072003-06-16 23:50:08 +0000357#endif
358 ) {
wdenk38635852002-08-27 05:55:31 +0000359 int rc;
360
wdenk4b9206e2004-03-23 22:14:11 +0000361 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000362
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200363 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000364 if (rc != 0) {
365 flash_perror (rc);
366 return (1);
367 }
368 puts ("done\n");
369 return 0;
370 }
371#endif
372
wdenk2abbe072003-06-16 23:50:08 +0000373#ifdef CONFIG_HAS_DATAFLASH
374 /* Check if we are copying from RAM or Flash to DataFlash */
375 if (addr_dataflash(dest) && !addr_dataflash(addr)){
376 int rc;
377
wdenk4b9206e2004-03-23 22:14:11 +0000378 puts ("Copy to DataFlash... ");
wdenk2abbe072003-06-16 23:50:08 +0000379
380 rc = write_dataflash (dest, addr, count*size);
381
382 if (rc != 1) {
383 dataflash_perror (rc);
384 return (1);
385 }
386 puts ("done\n");
387 return 0;
388 }
wdenk8bde7f72003-06-27 21:31:46 +0000389
wdenk2abbe072003-06-16 23:50:08 +0000390 /* Check if we are copying from DataFlash to RAM */
Stelian Pop880cc432008-03-26 22:52:35 +0100391 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200392#ifndef CONFIG_SYS_NO_FLASH
Stelian Pop880cc432008-03-26 22:52:35 +0100393 && (addr2info(dest) == NULL)
394#endif
395 ){
wdenk5779d8d2003-12-06 23:55:10 +0000396 int rc;
397 rc = read_dataflash(addr, count * size, (char *) dest);
398 if (rc != 1) {
wdenkd4ca31c2004-01-02 14:00:00 +0000399 dataflash_perror (rc);
400 return (1);
401 }
wdenk2abbe072003-06-16 23:50:08 +0000402 return 0;
403 }
404
405 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk4b9206e2004-03-23 22:14:11 +0000406 puts ("Unsupported combination of source/destination.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000407 return 1;
408 }
409#endif
410
Mike Frysinger4c727c72008-02-04 19:26:56 -0500411#ifdef CONFIG_BLACKFIN
412 /* See if we're copying to/from L1 inst */
413 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
414 memcpy((void *)dest, (void *)addr, count * size);
415 return 0;
416 }
417#endif
418
wdenk38635852002-08-27 05:55:31 +0000419 while (count-- > 0) {
420 if (size == 4)
421 *((ulong *)dest) = *((ulong *)addr);
422 else if (size == 2)
423 *((ushort *)dest) = *((ushort *)addr);
424 else
425 *((u_char *)dest) = *((u_char *)addr);
426 addr += size;
427 dest += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200428
429 /* reset watchdog from time to time */
430 if ((count % (64 << 10)) == 0)
431 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000432 }
433 return 0;
434}
435
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200436int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000437{
438 if (argc > 1) {
439 /* Set new base address.
440 */
441 base_address = simple_strtoul(argv[1], NULL, 16);
442 }
443 /* Print the current base address.
444 */
445 printf("Base Address: 0x%08lx\n", base_address);
446 return 0;
447}
448
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200449int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000450{
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200451 ulong addr, length, i;
wdenk27b207f2003-07-24 23:38:38 +0000452 int size;
wdenk38635852002-08-27 05:55:31 +0000453 volatile uint *longp;
454 volatile ushort *shortp;
455 volatile u_char *cp;
456
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200457 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000458 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000459
460 /* Check for a size spefication.
461 * Defaults to long if no or incorrect specification.
462 */
wdenk27b207f2003-07-24 23:38:38 +0000463 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
464 return 1;
wdenk38635852002-08-27 05:55:31 +0000465
466 /* Address is always specified.
467 */
468 addr = simple_strtoul(argv[1], NULL, 16);
469
470 /* Length is the number of objects, not number of bytes.
471 */
472 length = simple_strtoul(argv[2], NULL, 16);
473
474 /* We want to optimize the loops to run as fast as possible.
475 * If we have only one object, just run infinite loops.
476 */
477 if (length == 1) {
478 if (size == 4) {
479 longp = (uint *)addr;
480 for (;;)
481 i = *longp;
482 }
483 if (size == 2) {
484 shortp = (ushort *)addr;
485 for (;;)
486 i = *shortp;
487 }
488 cp = (u_char *)addr;
489 for (;;)
490 i = *cp;
491 }
492
493 if (size == 4) {
494 for (;;) {
495 longp = (uint *)addr;
496 i = length;
497 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200498 *longp++;
wdenk38635852002-08-27 05:55:31 +0000499 }
500 }
501 if (size == 2) {
502 for (;;) {
503 shortp = (ushort *)addr;
504 i = length;
505 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200506 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000507 }
508 }
509 for (;;) {
510 cp = (u_char *)addr;
511 i = length;
512 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200513 *cp++;
wdenk38635852002-08-27 05:55:31 +0000514 }
515}
516
wdenk56523f12004-07-11 17:40:54 +0000517#ifdef CONFIG_LOOPW
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200518int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk56523f12004-07-11 17:40:54 +0000519{
520 ulong addr, length, i, data;
521 int size;
522 volatile uint *longp;
523 volatile ushort *shortp;
524 volatile u_char *cp;
wdenk81050922004-07-11 20:04:51 +0000525
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200526 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000527 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000528
529 /* Check for a size spefication.
530 * Defaults to long if no or incorrect specification.
531 */
532 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
533 return 1;
534
535 /* Address is always specified.
536 */
537 addr = simple_strtoul(argv[1], NULL, 16);
538
539 /* Length is the number of objects, not number of bytes.
540 */
541 length = simple_strtoul(argv[2], NULL, 16);
542
543 /* data to write */
544 data = simple_strtoul(argv[3], NULL, 16);
wdenk81050922004-07-11 20:04:51 +0000545
wdenk56523f12004-07-11 17:40:54 +0000546 /* We want to optimize the loops to run as fast as possible.
547 * If we have only one object, just run infinite loops.
548 */
549 if (length == 1) {
550 if (size == 4) {
551 longp = (uint *)addr;
552 for (;;)
553 *longp = data;
554 }
555 if (size == 2) {
556 shortp = (ushort *)addr;
557 for (;;)
558 *shortp = data;
559 }
560 cp = (u_char *)addr;
561 for (;;)
562 *cp = data;
563 }
564
565 if (size == 4) {
566 for (;;) {
567 longp = (uint *)addr;
568 i = length;
569 while (i-- > 0)
570 *longp++ = data;
571 }
572 }
573 if (size == 2) {
574 for (;;) {
575 shortp = (ushort *)addr;
576 i = length;
577 while (i-- > 0)
578 *shortp++ = data;
579 }
580 }
581 for (;;) {
582 cp = (u_char *)addr;
583 i = length;
584 while (i-- > 0)
585 *cp++ = data;
586 }
587}
588#endif /* CONFIG_LOOPW */
589
wdenk38635852002-08-27 05:55:31 +0000590/*
591 * Perform a memory test. A more complete alternative test can be
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200592 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
wdenk38635852002-08-27 05:55:31 +0000593 * interrupted by ctrl-c or by a failure of one of the sub-tests.
594 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200595int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000596{
597 vu_long *addr, *start, *end;
598 ulong val;
599 ulong readback;
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400600 ulong errs = 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100601 int iterations = 1;
602 int iteration_limit;
wdenk38635852002-08-27 05:55:31 +0000603
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200604#if defined(CONFIG_SYS_ALT_MEMTEST)
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100605 vu_long len;
wdenk38635852002-08-27 05:55:31 +0000606 vu_long offset;
607 vu_long test_offset;
608 vu_long pattern;
609 vu_long temp;
610 vu_long anti_pattern;
611 vu_long num_words;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200612#if defined(CONFIG_SYS_MEMTEST_SCRATCH)
613 vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH;
wdenk5f535fe2003-09-18 09:21:33 +0000614#else
Wolfgang Denk029b6dc2006-07-21 11:37:40 +0200615 vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
wdenk5f535fe2003-09-18 09:21:33 +0000616#endif
wdenk38635852002-08-27 05:55:31 +0000617 int j;
wdenk38635852002-08-27 05:55:31 +0000618
619 static const ulong bitpattern[] = {
620 0x00000001, /* single bit */
621 0x00000003, /* two adjacent bits */
622 0x00000007, /* three adjacent bits */
623 0x0000000F, /* four adjacent bits */
624 0x00000005, /* two non-adjacent bits */
625 0x00000015, /* three non-adjacent bits */
626 0x00000055, /* four non-adjacent bits */
627 0xaaaaaaaa, /* alternating 1/0 */
628 };
629#else
630 ulong incr;
631 ulong pattern;
wdenk38635852002-08-27 05:55:31 +0000632#endif
633
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100634 if (argc > 1)
wdenk38635852002-08-27 05:55:31 +0000635 start = (ulong *)simple_strtoul(argv[1], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100636 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200637 start = (ulong *)CONFIG_SYS_MEMTEST_START;
wdenk38635852002-08-27 05:55:31 +0000638
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100639 if (argc > 2)
wdenk38635852002-08-27 05:55:31 +0000640 end = (ulong *)simple_strtoul(argv[2], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100641 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200642 end = (ulong *)(CONFIG_SYS_MEMTEST_END);
wdenk38635852002-08-27 05:55:31 +0000643
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100644 if (argc > 3)
wdenk38635852002-08-27 05:55:31 +0000645 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100646 else
wdenk38635852002-08-27 05:55:31 +0000647 pattern = 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100648
649 if (argc > 4)
650 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
651 else
652 iteration_limit = 0;
wdenk38635852002-08-27 05:55:31 +0000653
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200654#if defined(CONFIG_SYS_ALT_MEMTEST)
wdenk38635852002-08-27 05:55:31 +0000655 printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
Mike Frysinger9504a552012-01-20 09:07:20 +0000656 debug("%s:%d: start 0x%p end 0x%p\n",
wdenk38635852002-08-27 05:55:31 +0000657 __FUNCTION__, __LINE__, start, end);
658
659 for (;;) {
660 if (ctrlc()) {
661 putc ('\n');
662 return 1;
663 }
664
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100665
666 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400667 printf("Tested %d iteration(s) with %lu errors.\n",
668 iterations-1, errs);
669 return errs != 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100670 }
671
wdenk38635852002-08-27 05:55:31 +0000672 printf("Iteration: %6d\r", iterations);
Mike Frysinger9504a552012-01-20 09:07:20 +0000673 debug("\n");
wdenk38635852002-08-27 05:55:31 +0000674 iterations++;
675
676 /*
677 * Data line test: write a pattern to the first
678 * location, write the 1's complement to a 'parking'
679 * address (changes the state of the data bus so a
680 * floating bus doen't give a false OK), and then
681 * read the value back. Note that we read it back
682 * into a variable because the next time we read it,
683 * it might be right (been there, tough to explain to
684 * the quality guys why it prints a failure when the
685 * "is" and "should be" are obviously the same in the
686 * error message).
687 *
688 * Rather than exhaustively testing, we test some
689 * patterns by shifting '1' bits through a field of
690 * '0's and '0' bits through a field of '1's (i.e.
691 * pattern and ~pattern).
692 */
693 addr = start;
694 for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) {
695 val = bitpattern[j];
696 for(; val != 0; val <<= 1) {
697 *addr = val;
698 *dummy = ~val; /* clear the test data off of the bus */
699 readback = *addr;
700 if(readback != val) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400701 printf ("FAILURE (data line): "
wdenk38635852002-08-27 05:55:31 +0000702 "expected %08lx, actual %08lx\n",
703 val, readback);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400704 errs++;
705 if (ctrlc()) {
706 putc ('\n');
707 return 1;
708 }
wdenk38635852002-08-27 05:55:31 +0000709 }
710 *addr = ~val;
711 *dummy = val;
712 readback = *addr;
713 if(readback != ~val) {
714 printf ("FAILURE (data line): "
715 "Is %08lx, should be %08lx\n",
wdenke1599e82004-10-10 23:27:33 +0000716 readback, ~val);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400717 errs++;
718 if (ctrlc()) {
719 putc ('\n');
720 return 1;
721 }
wdenk38635852002-08-27 05:55:31 +0000722 }
723 }
724 }
725
726 /*
727 * Based on code whose Original Author and Copyright
728 * information follows: Copyright (c) 1998 by Michael
729 * Barr. This software is placed into the public
730 * domain and may be used for any purpose. However,
731 * this notice must not be changed or removed and no
732 * warranty is either expressed or implied by its
733 * publication or distribution.
734 */
735
736 /*
737 * Address line test
738 *
739 * Description: Test the address bus wiring in a
740 * memory region by performing a walking
741 * 1's test on the relevant bits of the
742 * address and checking for aliasing.
743 * This test will find single-bit
744 * address failures such as stuck -high,
745 * stuck-low, and shorted pins. The base
746 * address and size of the region are
747 * selected by the caller.
748 *
749 * Notes: For best results, the selected base
750 * address should have enough LSB 0's to
751 * guarantee single address bit changes.
752 * For example, to test a 64-Kbyte
753 * region, select a base address on a
754 * 64-Kbyte boundary. Also, select the
755 * region size as a power-of-two if at
756 * all possible.
757 *
758 * Returns: 0 if the test succeeds, 1 if the test fails.
wdenk38635852002-08-27 05:55:31 +0000759 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100760 len = ((ulong)end - (ulong)start)/sizeof(vu_long);
wdenk38635852002-08-27 05:55:31 +0000761 pattern = (vu_long) 0xaaaaaaaa;
762 anti_pattern = (vu_long) 0x55555555;
763
Mike Frysinger9504a552012-01-20 09:07:20 +0000764 debug("%s:%d: length = 0x%.8lx\n",
wdenk38635852002-08-27 05:55:31 +0000765 __FUNCTION__, __LINE__,
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100766 len);
wdenk38635852002-08-27 05:55:31 +0000767 /*
768 * Write the default pattern at each of the
769 * power-of-two offsets.
770 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100771 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000772 start[offset] = pattern;
773 }
774
775 /*
776 * Check for address bits stuck high.
777 */
778 test_offset = 0;
779 start[test_offset] = anti_pattern;
780
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100781 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000782 temp = start[offset];
783 if (temp != pattern) {
784 printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
785 " expected 0x%.8lx, actual 0x%.8lx\n",
786 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400787 errs++;
788 if (ctrlc()) {
789 putc ('\n');
790 return 1;
791 }
wdenk38635852002-08-27 05:55:31 +0000792 }
793 }
794 start[test_offset] = pattern;
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200795 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000796
797 /*
798 * Check for addr bits stuck low or shorted.
799 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100800 for (test_offset = 1; test_offset < len; test_offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000801 start[test_offset] = anti_pattern;
802
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100803 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000804 temp = start[offset];
805 if ((temp != pattern) && (offset != test_offset)) {
806 printf ("\nFAILURE: Address bit stuck low or shorted @"
807 " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n",
808 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400809 errs++;
810 if (ctrlc()) {
811 putc ('\n');
812 return 1;
813 }
wdenk38635852002-08-27 05:55:31 +0000814 }
815 }
816 start[test_offset] = pattern;
817 }
818
819 /*
820 * Description: Test the integrity of a physical
821 * memory device by performing an
822 * increment/decrement test over the
823 * entire region. In the process every
824 * storage bit in the device is tested
825 * as a zero and a one. The base address
826 * and the size of the region are
827 * selected by the caller.
828 *
829 * Returns: 0 if the test succeeds, 1 if the test fails.
830 */
831 num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1;
832
833 /*
834 * Fill memory with a known pattern.
835 */
836 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200837 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000838 start[offset] = pattern;
839 }
840
841 /*
842 * Check each location and invert it for the second pass.
843 */
844 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200845 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000846 temp = start[offset];
847 if (temp != pattern) {
848 printf ("\nFAILURE (read/write) @ 0x%.8lx:"
849 " expected 0x%.8lx, actual 0x%.8lx)\n",
850 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400851 errs++;
852 if (ctrlc()) {
853 putc ('\n');
854 return 1;
855 }
wdenk38635852002-08-27 05:55:31 +0000856 }
857
858 anti_pattern = ~pattern;
859 start[offset] = anti_pattern;
860 }
861
862 /*
863 * Check each location for the inverted pattern and zero it.
864 */
865 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200866 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000867 anti_pattern = ~pattern;
868 temp = start[offset];
869 if (temp != anti_pattern) {
870 printf ("\nFAILURE (read/write): @ 0x%.8lx:"
871 " expected 0x%.8lx, actual 0x%.8lx)\n",
872 (ulong)&start[offset], anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400873 errs++;
874 if (ctrlc()) {
875 putc ('\n');
876 return 1;
877 }
wdenk38635852002-08-27 05:55:31 +0000878 }
879 start[offset] = 0;
880 }
881 }
882
883#else /* The original, quickie test */
884 incr = 1;
885 for (;;) {
886 if (ctrlc()) {
887 putc ('\n');
888 return 1;
889 }
890
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100891 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400892 printf("Tested %d iteration(s) with %lu errors.\n",
893 iterations-1, errs);
894 return errs != 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100895 }
896 ++iterations;
897
wdenk38635852002-08-27 05:55:31 +0000898 printf ("\rPattern %08lX Writing..."
899 "%12s"
900 "\b\b\b\b\b\b\b\b\b\b",
901 pattern, "");
902
903 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200904 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000905 *addr = val;
906 val += incr;
907 }
908
wdenk4b9206e2004-03-23 22:14:11 +0000909 puts ("Reading...");
wdenk38635852002-08-27 05:55:31 +0000910
911 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200912 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000913 readback = *addr;
914 if (readback != val) {
915 printf ("\nMem error @ 0x%08X: "
916 "found %08lX, expected %08lX\n",
Simon Glass92549352011-09-17 06:48:58 +0000917 (uint)(uintptr_t)addr, readback, val);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400918 errs++;
919 if (ctrlc()) {
920 putc ('\n');
921 return 1;
922 }
wdenk38635852002-08-27 05:55:31 +0000923 }
924 val += incr;
925 }
926
927 /*
928 * Flip the pattern each time to make lots of zeros and
929 * then, the next time, lots of ones. We decrement
930 * the "negative" patterns and increment the "positive"
931 * patterns to preserve this feature.
932 */
933 if(pattern & 0x80000000) {
934 pattern = -pattern; /* complement & increment */
935 }
936 else {
937 pattern = ~pattern;
938 }
939 incr = -incr;
940 }
wdenk38635852002-08-27 05:55:31 +0000941#endif
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400942 return 0; /* not reached */
wdenk38635852002-08-27 05:55:31 +0000943}
944
945
946/* Modify memory.
947 *
948 * Syntax:
949 * mm{.b, .w, .l} {addr}
950 * nm{.b, .w, .l} {addr}
951 */
952static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200953mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000954{
wdenk27b207f2003-07-24 23:38:38 +0000955 ulong addr, i;
956 int nbytes, size;
wdenk38635852002-08-27 05:55:31 +0000957
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200958 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000959 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000960
961#ifdef CONFIG_BOOT_RETRY_TIME
962 reset_cmd_timeout(); /* got a good command to get here */
963#endif
964 /* We use the last specified parameters, unless new ones are
965 * entered.
966 */
967 addr = mm_last_addr;
968 size = mm_last_size;
969
970 if ((flag & CMD_FLAG_REPEAT) == 0) {
971 /* New command specified. Check for a size specification.
972 * Defaults to long if no or incorrect specification.
973 */
wdenk27b207f2003-07-24 23:38:38 +0000974 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
975 return 1;
wdenk38635852002-08-27 05:55:31 +0000976
977 /* Address is specified since argc > 1
978 */
979 addr = simple_strtoul(argv[1], NULL, 16);
980 addr += base_address;
981 }
982
wdenk2abbe072003-06-16 23:50:08 +0000983#ifdef CONFIG_HAS_DATAFLASH
984 if (addr_dataflash(addr)){
wdenk4b9206e2004-03-23 22:14:11 +0000985 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000986 return 0;
987 }
988#endif
989
Mike Frysinger4c727c72008-02-04 19:26:56 -0500990#ifdef CONFIG_BLACKFIN
991 if (addr_bfin_on_chip_mem(addr)) {
992 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
993 return 0;
994 }
995#endif
996
wdenk38635852002-08-27 05:55:31 +0000997 /* Print the address, followed by value. Then accept input for
998 * the next value. A non-converted value exits.
999 */
1000 do {
1001 printf("%08lx:", addr);
1002 if (size == 4)
1003 printf(" %08x", *((uint *)addr));
1004 else if (size == 2)
1005 printf(" %04x", *((ushort *)addr));
1006 else
1007 printf(" %02x", *((u_char *)addr));
1008
1009 nbytes = readline (" ? ");
1010 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1011 /* <CR> pressed as only input, don't modify current
1012 * location and move to next. "-" pressed will go back.
1013 */
1014 if (incrflag)
1015 addr += nbytes ? -size : size;
1016 nbytes = 1;
1017#ifdef CONFIG_BOOT_RETRY_TIME
1018 reset_cmd_timeout(); /* good enough to not time out */
1019#endif
1020 }
1021#ifdef CONFIG_BOOT_RETRY_TIME
1022 else if (nbytes == -2) {
1023 break; /* timed out, exit the command */
1024 }
1025#endif
1026 else {
1027 char *endp;
1028 i = simple_strtoul(console_buffer, &endp, 16);
1029 nbytes = endp - console_buffer;
1030 if (nbytes) {
1031#ifdef CONFIG_BOOT_RETRY_TIME
1032 /* good enough to not time out
1033 */
1034 reset_cmd_timeout();
1035#endif
1036 if (size == 4)
1037 *((uint *)addr) = i;
1038 else if (size == 2)
1039 *((ushort *)addr) = i;
1040 else
1041 *((u_char *)addr) = i;
1042 if (incrflag)
1043 addr += size;
1044 }
1045 }
1046 } while (nbytes);
1047
1048 mm_last_addr = addr;
1049 mm_last_size = size;
1050 return 0;
1051}
1052
Mike Frysinger710b9932010-12-21 14:19:51 -05001053#ifdef CONFIG_CMD_CRC32
1054
wdenkc26e4542004-04-18 10:13:26 +00001055#ifndef CONFIG_CRC32_VERIFY
1056
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001057int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001058{
wdenk71f95112003-06-15 22:40:42 +00001059 ulong addr, length;
1060 ulong crc;
1061 ulong *ptr;
wdenk38635852002-08-27 05:55:31 +00001062
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001063 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001064 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001065
wdenk71f95112003-06-15 22:40:42 +00001066 addr = simple_strtoul (argv[1], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001067 addr += base_address;
1068
wdenk71f95112003-06-15 22:40:42 +00001069 length = simple_strtoul (argv[2], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001070
Jens Scharsig39c6e032011-07-18 08:46:26 +02001071 crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
wdenk38635852002-08-27 05:55:31 +00001072
1073 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
wdenk71f95112003-06-15 22:40:42 +00001074 addr, addr + length - 1, crc);
wdenk38635852002-08-27 05:55:31 +00001075
wdenk71f95112003-06-15 22:40:42 +00001076 if (argc > 3) {
1077 ptr = (ulong *) simple_strtoul (argv[3], NULL, 16);
1078 *ptr = crc;
1079 }
wdenk38635852002-08-27 05:55:31 +00001080
1081 return 0;
1082}
1083
wdenkc26e4542004-04-18 10:13:26 +00001084#else /* CONFIG_CRC32_VERIFY */
1085
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001086int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkc26e4542004-04-18 10:13:26 +00001087{
1088 ulong addr, length;
1089 ulong crc;
1090 ulong *ptr;
wdenk6e592382004-04-18 17:39:38 +00001091 ulong vcrc;
wdenkc26e4542004-04-18 10:13:26 +00001092 int verify;
1093 int ac;
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001094 char * const *av;
wdenkc26e4542004-04-18 10:13:26 +00001095
1096 if (argc < 3) {
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001097usage:
Simon Glass4c12eeb2011-12-10 08:44:01 +00001098 return CMD_RET_USAGE;
wdenkc26e4542004-04-18 10:13:26 +00001099 }
1100
1101 av = argv + 1;
1102 ac = argc - 1;
1103 if (strcmp(*av, "-v") == 0) {
1104 verify = 1;
1105 av++;
1106 ac--;
1107 if (ac < 3)
1108 goto usage;
1109 } else
1110 verify = 0;
1111
1112 addr = simple_strtoul(*av++, NULL, 16);
1113 addr += base_address;
1114 length = simple_strtoul(*av++, NULL, 16);
1115
Jens Scharsig39c6e032011-07-18 08:46:26 +02001116 crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
wdenkc26e4542004-04-18 10:13:26 +00001117
1118 if (!verify) {
1119 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
1120 addr, addr + length - 1, crc);
1121 if (ac > 2) {
1122 ptr = (ulong *) simple_strtoul (*av++, NULL, 16);
1123 *ptr = crc;
1124 }
1125 } else {
1126 vcrc = simple_strtoul(*av++, NULL, 16);
1127 if (vcrc != crc) {
1128 printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n",
1129 addr, addr + length - 1, crc, vcrc);
1130 return 1;
1131 }
1132 }
1133
1134 return 0;
1135
1136}
1137#endif /* CONFIG_CRC32_VERIFY */
1138
Mike Frysinger710b9932010-12-21 14:19:51 -05001139#endif
1140
wdenk8bde7f72003-06-27 21:31:46 +00001141/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001142U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001143 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001144 "memory display",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001145 "[.b, .w, .l] address [# of objects]"
wdenk8bde7f72003-06-27 21:31:46 +00001146);
1147
1148
wdenk0d498392003-07-01 21:06:45 +00001149U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001150 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001151 "memory modify (auto-incrementing address)",
1152 "[.b, .w, .l] address"
wdenk8bde7f72003-06-27 21:31:46 +00001153);
1154
1155
wdenk0d498392003-07-01 21:06:45 +00001156U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001157 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001158 "memory modify (constant address)",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001159 "[.b, .w, .l] address"
wdenk8bde7f72003-06-27 21:31:46 +00001160);
1161
wdenk0d498392003-07-01 21:06:45 +00001162U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001163 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001164 "memory write (fill)",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001165 "[.b, .w, .l] address value [count]"
wdenk8bde7f72003-06-27 21:31:46 +00001166);
1167
wdenk0d498392003-07-01 21:06:45 +00001168U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001169 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001170 "memory copy",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001171 "[.b, .w, .l] source target count"
wdenk8bde7f72003-06-27 21:31:46 +00001172);
1173
wdenk0d498392003-07-01 21:06:45 +00001174U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001175 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001176 "memory compare",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001177 "[.b, .w, .l] addr1 addr2 count"
wdenk8bde7f72003-06-27 21:31:46 +00001178);
1179
Mike Frysinger710b9932010-12-21 14:19:51 -05001180#ifdef CONFIG_CMD_CRC32
1181
wdenkc26e4542004-04-18 10:13:26 +00001182#ifndef CONFIG_CRC32_VERIFY
1183
wdenk0d498392003-07-01 21:06:45 +00001184U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001185 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001186 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001187 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001188);
1189
wdenkc26e4542004-04-18 10:13:26 +00001190#else /* CONFIG_CRC32_VERIFY */
1191
1192U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001193 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001194 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001195 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001196 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001197);
1198
1199#endif /* CONFIG_CRC32_VERIFY */
1200
Mike Frysinger710b9932010-12-21 14:19:51 -05001201#endif
1202
wdenk0d498392003-07-01 21:06:45 +00001203U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001204 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001205 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001206 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001207 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001208);
1209
wdenk0d498392003-07-01 21:06:45 +00001210U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001211 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001212 "infinite loop on address range",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001213 "[.b, .w, .l] address number_of_objects"
wdenk8bde7f72003-06-27 21:31:46 +00001214);
1215
wdenk56523f12004-07-11 17:40:54 +00001216#ifdef CONFIG_LOOPW
1217U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001218 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001219 "infinite write loop on address range",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001220 "[.b, .w, .l] address number_of_objects data_to_write"
wdenk56523f12004-07-11 17:40:54 +00001221);
1222#endif /* CONFIG_LOOPW */
1223
wdenk0d498392003-07-01 21:06:45 +00001224U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001225 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001226 "simple RAM read/write test",
1227 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001228);
1229
stroese4aaf29b2004-12-16 17:42:39 +00001230#ifdef CONFIG_MX_CYCLIC
1231U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001232 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001233 "memory display cyclic",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001234 "[.b, .w, .l] address count delay(ms)"
stroese4aaf29b2004-12-16 17:42:39 +00001235);
1236
1237U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001238 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001239 "memory write cyclic",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001240 "[.b, .w, .l] address value delay(ms)"
stroese4aaf29b2004-12-16 17:42:39 +00001241);
1242#endif /* CONFIG_MX_CYCLIC */