blob: 7a199f51b10fd6edf08644deda72e683e290ccf3 [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
wdenk38635852002-08-27 05:55:31 +0000294 ngood = 0;
295
296 while (count-- > 0) {
Mike Frysinger054ea172012-01-20 09:07:21 +0000297 ulong word1, word2;
wdenk38635852002-08-27 05:55:31 +0000298 if (size == 4) {
Mike Frysinger054ea172012-01-20 09:07:21 +0000299 word1 = *(ulong *)addr1;
300 word2 = *(ulong *)addr2;
301 } else if (size == 2) {
302 word1 = *(ushort *)addr1;
303 word2 = *(ushort *)addr2;
304 } else {
305 word1 = *(u_char *)addr1;
306 word2 = *(u_char *)addr2;
wdenk38635852002-08-27 05:55:31 +0000307 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000308 if (word1 != word2) {
309 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
310 type, addr1, size, word1,
311 type, addr2, size, word2);
312 rcode = 1;
313 break;
wdenk38635852002-08-27 05:55:31 +0000314 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000315
wdenk38635852002-08-27 05:55:31 +0000316 ngood++;
317 addr1 += size;
318 addr2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200319
320 /* reset watchdog from time to time */
321 if ((count % (64 << 10)) == 0)
322 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000323 }
324
Mike Frysinger054ea172012-01-20 09:07:21 +0000325 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000326 return rcode;
327}
328
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200329int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000330{
wdenk27b207f2003-07-24 23:38:38 +0000331 ulong addr, dest, count;
332 int size;
wdenk38635852002-08-27 05:55:31 +0000333
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200334 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000335 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000336
337 /* Check for size specification.
338 */
wdenk27b207f2003-07-24 23:38:38 +0000339 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
340 return 1;
wdenk38635852002-08-27 05:55:31 +0000341
342 addr = simple_strtoul(argv[1], NULL, 16);
343 addr += base_address;
344
345 dest = simple_strtoul(argv[2], NULL, 16);
346 dest += base_address;
347
348 count = simple_strtoul(argv[3], NULL, 16);
349
350 if (count == 0) {
351 puts ("Zero length ???\n");
352 return 1;
353 }
354
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200355#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000356 /* check if we are copying to Flash */
wdenk2abbe072003-06-16 23:50:08 +0000357 if ( (addr2info(dest) != NULL)
358#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino84d0c2f2008-03-03 10:39:13 +0200359 && (!addr_dataflash(dest))
wdenk2abbe072003-06-16 23:50:08 +0000360#endif
361 ) {
wdenk38635852002-08-27 05:55:31 +0000362 int rc;
363
wdenk4b9206e2004-03-23 22:14:11 +0000364 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000365
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200366 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000367 if (rc != 0) {
368 flash_perror (rc);
369 return (1);
370 }
371 puts ("done\n");
372 return 0;
373 }
374#endif
375
wdenk2abbe072003-06-16 23:50:08 +0000376#ifdef CONFIG_HAS_DATAFLASH
377 /* Check if we are copying from RAM or Flash to DataFlash */
378 if (addr_dataflash(dest) && !addr_dataflash(addr)){
379 int rc;
380
wdenk4b9206e2004-03-23 22:14:11 +0000381 puts ("Copy to DataFlash... ");
wdenk2abbe072003-06-16 23:50:08 +0000382
383 rc = write_dataflash (dest, addr, count*size);
384
385 if (rc != 1) {
386 dataflash_perror (rc);
387 return (1);
388 }
389 puts ("done\n");
390 return 0;
391 }
wdenk8bde7f72003-06-27 21:31:46 +0000392
wdenk2abbe072003-06-16 23:50:08 +0000393 /* Check if we are copying from DataFlash to RAM */
Stelian Pop880cc432008-03-26 22:52:35 +0100394 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200395#ifndef CONFIG_SYS_NO_FLASH
Stelian Pop880cc432008-03-26 22:52:35 +0100396 && (addr2info(dest) == NULL)
397#endif
398 ){
wdenk5779d8d2003-12-06 23:55:10 +0000399 int rc;
400 rc = read_dataflash(addr, count * size, (char *) dest);
401 if (rc != 1) {
wdenkd4ca31c2004-01-02 14:00:00 +0000402 dataflash_perror (rc);
403 return (1);
404 }
wdenk2abbe072003-06-16 23:50:08 +0000405 return 0;
406 }
407
408 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk4b9206e2004-03-23 22:14:11 +0000409 puts ("Unsupported combination of source/destination.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000410 return 1;
411 }
412#endif
413
Mike Frysinger4c727c72008-02-04 19:26:56 -0500414#ifdef CONFIG_BLACKFIN
415 /* See if we're copying to/from L1 inst */
416 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
417 memcpy((void *)dest, (void *)addr, count * size);
418 return 0;
419 }
420#endif
421
wdenk38635852002-08-27 05:55:31 +0000422 while (count-- > 0) {
423 if (size == 4)
424 *((ulong *)dest) = *((ulong *)addr);
425 else if (size == 2)
426 *((ushort *)dest) = *((ushort *)addr);
427 else
428 *((u_char *)dest) = *((u_char *)addr);
429 addr += size;
430 dest += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200431
432 /* reset watchdog from time to time */
433 if ((count % (64 << 10)) == 0)
434 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000435 }
436 return 0;
437}
438
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200439int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000440{
441 if (argc > 1) {
442 /* Set new base address.
443 */
444 base_address = simple_strtoul(argv[1], NULL, 16);
445 }
446 /* Print the current base address.
447 */
448 printf("Base Address: 0x%08lx\n", base_address);
449 return 0;
450}
451
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200452int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000453{
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200454 ulong addr, length, i;
wdenk27b207f2003-07-24 23:38:38 +0000455 int size;
wdenk38635852002-08-27 05:55:31 +0000456 volatile uint *longp;
457 volatile ushort *shortp;
458 volatile u_char *cp;
459
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200460 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000461 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000462
463 /* Check for a size spefication.
464 * Defaults to long if no or incorrect specification.
465 */
wdenk27b207f2003-07-24 23:38:38 +0000466 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
467 return 1;
wdenk38635852002-08-27 05:55:31 +0000468
469 /* Address is always specified.
470 */
471 addr = simple_strtoul(argv[1], NULL, 16);
472
473 /* Length is the number of objects, not number of bytes.
474 */
475 length = simple_strtoul(argv[2], NULL, 16);
476
477 /* We want to optimize the loops to run as fast as possible.
478 * If we have only one object, just run infinite loops.
479 */
480 if (length == 1) {
481 if (size == 4) {
482 longp = (uint *)addr;
483 for (;;)
484 i = *longp;
485 }
486 if (size == 2) {
487 shortp = (ushort *)addr;
488 for (;;)
489 i = *shortp;
490 }
491 cp = (u_char *)addr;
492 for (;;)
493 i = *cp;
494 }
495
496 if (size == 4) {
497 for (;;) {
498 longp = (uint *)addr;
499 i = length;
500 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200501 *longp++;
wdenk38635852002-08-27 05:55:31 +0000502 }
503 }
504 if (size == 2) {
505 for (;;) {
506 shortp = (ushort *)addr;
507 i = length;
508 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200509 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000510 }
511 }
512 for (;;) {
513 cp = (u_char *)addr;
514 i = length;
515 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200516 *cp++;
wdenk38635852002-08-27 05:55:31 +0000517 }
518}
519
wdenk56523f12004-07-11 17:40:54 +0000520#ifdef CONFIG_LOOPW
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200521int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk56523f12004-07-11 17:40:54 +0000522{
523 ulong addr, length, i, data;
524 int size;
525 volatile uint *longp;
526 volatile ushort *shortp;
527 volatile u_char *cp;
wdenk81050922004-07-11 20:04:51 +0000528
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200529 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000530 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000531
532 /* Check for a size spefication.
533 * Defaults to long if no or incorrect specification.
534 */
535 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
536 return 1;
537
538 /* Address is always specified.
539 */
540 addr = simple_strtoul(argv[1], NULL, 16);
541
542 /* Length is the number of objects, not number of bytes.
543 */
544 length = simple_strtoul(argv[2], NULL, 16);
545
546 /* data to write */
547 data = simple_strtoul(argv[3], NULL, 16);
wdenk81050922004-07-11 20:04:51 +0000548
wdenk56523f12004-07-11 17:40:54 +0000549 /* We want to optimize the loops to run as fast as possible.
550 * If we have only one object, just run infinite loops.
551 */
552 if (length == 1) {
553 if (size == 4) {
554 longp = (uint *)addr;
555 for (;;)
556 *longp = data;
557 }
558 if (size == 2) {
559 shortp = (ushort *)addr;
560 for (;;)
561 *shortp = data;
562 }
563 cp = (u_char *)addr;
564 for (;;)
565 *cp = data;
566 }
567
568 if (size == 4) {
569 for (;;) {
570 longp = (uint *)addr;
571 i = length;
572 while (i-- > 0)
573 *longp++ = data;
574 }
575 }
576 if (size == 2) {
577 for (;;) {
578 shortp = (ushort *)addr;
579 i = length;
580 while (i-- > 0)
581 *shortp++ = data;
582 }
583 }
584 for (;;) {
585 cp = (u_char *)addr;
586 i = length;
587 while (i-- > 0)
588 *cp++ = data;
589 }
590}
591#endif /* CONFIG_LOOPW */
592
wdenk38635852002-08-27 05:55:31 +0000593/*
594 * Perform a memory test. A more complete alternative test can be
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200595 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
wdenk38635852002-08-27 05:55:31 +0000596 * interrupted by ctrl-c or by a failure of one of the sub-tests.
597 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200598int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000599{
600 vu_long *addr, *start, *end;
601 ulong val;
602 ulong readback;
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400603 ulong errs = 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100604 int iterations = 1;
605 int iteration_limit;
wdenk38635852002-08-27 05:55:31 +0000606
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200607#if defined(CONFIG_SYS_ALT_MEMTEST)
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100608 vu_long len;
wdenk38635852002-08-27 05:55:31 +0000609 vu_long offset;
610 vu_long test_offset;
611 vu_long pattern;
612 vu_long temp;
613 vu_long anti_pattern;
614 vu_long num_words;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200615#if defined(CONFIG_SYS_MEMTEST_SCRATCH)
616 vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH;
wdenk5f535fe2003-09-18 09:21:33 +0000617#else
Wolfgang Denk029b6dc2006-07-21 11:37:40 +0200618 vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
wdenk5f535fe2003-09-18 09:21:33 +0000619#endif
wdenk38635852002-08-27 05:55:31 +0000620 int j;
wdenk38635852002-08-27 05:55:31 +0000621
622 static const ulong bitpattern[] = {
623 0x00000001, /* single bit */
624 0x00000003, /* two adjacent bits */
625 0x00000007, /* three adjacent bits */
626 0x0000000F, /* four adjacent bits */
627 0x00000005, /* two non-adjacent bits */
628 0x00000015, /* three non-adjacent bits */
629 0x00000055, /* four non-adjacent bits */
630 0xaaaaaaaa, /* alternating 1/0 */
631 };
632#else
633 ulong incr;
634 ulong pattern;
wdenk38635852002-08-27 05:55:31 +0000635#endif
636
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100637 if (argc > 1)
wdenk38635852002-08-27 05:55:31 +0000638 start = (ulong *)simple_strtoul(argv[1], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100639 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200640 start = (ulong *)CONFIG_SYS_MEMTEST_START;
wdenk38635852002-08-27 05:55:31 +0000641
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100642 if (argc > 2)
wdenk38635852002-08-27 05:55:31 +0000643 end = (ulong *)simple_strtoul(argv[2], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100644 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200645 end = (ulong *)(CONFIG_SYS_MEMTEST_END);
wdenk38635852002-08-27 05:55:31 +0000646
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100647 if (argc > 3)
wdenk38635852002-08-27 05:55:31 +0000648 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100649 else
wdenk38635852002-08-27 05:55:31 +0000650 pattern = 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100651
652 if (argc > 4)
653 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
654 else
655 iteration_limit = 0;
wdenk38635852002-08-27 05:55:31 +0000656
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200657#if defined(CONFIG_SYS_ALT_MEMTEST)
wdenk38635852002-08-27 05:55:31 +0000658 printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
Mike Frysinger9504a552012-01-20 09:07:20 +0000659 debug("%s:%d: start 0x%p end 0x%p\n",
wdenk38635852002-08-27 05:55:31 +0000660 __FUNCTION__, __LINE__, start, end);
661
662 for (;;) {
663 if (ctrlc()) {
664 putc ('\n');
665 return 1;
666 }
667
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100668
669 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400670 printf("Tested %d iteration(s) with %lu errors.\n",
671 iterations-1, errs);
672 return errs != 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100673 }
674
wdenk38635852002-08-27 05:55:31 +0000675 printf("Iteration: %6d\r", iterations);
Mike Frysinger9504a552012-01-20 09:07:20 +0000676 debug("\n");
wdenk38635852002-08-27 05:55:31 +0000677 iterations++;
678
679 /*
680 * Data line test: write a pattern to the first
681 * location, write the 1's complement to a 'parking'
682 * address (changes the state of the data bus so a
683 * floating bus doen't give a false OK), and then
684 * read the value back. Note that we read it back
685 * into a variable because the next time we read it,
686 * it might be right (been there, tough to explain to
687 * the quality guys why it prints a failure when the
688 * "is" and "should be" are obviously the same in the
689 * error message).
690 *
691 * Rather than exhaustively testing, we test some
692 * patterns by shifting '1' bits through a field of
693 * '0's and '0' bits through a field of '1's (i.e.
694 * pattern and ~pattern).
695 */
696 addr = start;
697 for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) {
698 val = bitpattern[j];
699 for(; val != 0; val <<= 1) {
700 *addr = val;
701 *dummy = ~val; /* clear the test data off of the bus */
702 readback = *addr;
703 if(readback != val) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400704 printf ("FAILURE (data line): "
wdenk38635852002-08-27 05:55:31 +0000705 "expected %08lx, actual %08lx\n",
706 val, readback);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400707 errs++;
708 if (ctrlc()) {
709 putc ('\n');
710 return 1;
711 }
wdenk38635852002-08-27 05:55:31 +0000712 }
713 *addr = ~val;
714 *dummy = val;
715 readback = *addr;
716 if(readback != ~val) {
717 printf ("FAILURE (data line): "
718 "Is %08lx, should be %08lx\n",
wdenke1599e82004-10-10 23:27:33 +0000719 readback, ~val);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400720 errs++;
721 if (ctrlc()) {
722 putc ('\n');
723 return 1;
724 }
wdenk38635852002-08-27 05:55:31 +0000725 }
726 }
727 }
728
729 /*
730 * Based on code whose Original Author and Copyright
731 * information follows: Copyright (c) 1998 by Michael
732 * Barr. This software is placed into the public
733 * domain and may be used for any purpose. However,
734 * this notice must not be changed or removed and no
735 * warranty is either expressed or implied by its
736 * publication or distribution.
737 */
738
739 /*
740 * Address line test
741 *
742 * Description: Test the address bus wiring in a
743 * memory region by performing a walking
744 * 1's test on the relevant bits of the
745 * address and checking for aliasing.
746 * This test will find single-bit
747 * address failures such as stuck -high,
748 * stuck-low, and shorted pins. The base
749 * address and size of the region are
750 * selected by the caller.
751 *
752 * Notes: For best results, the selected base
753 * address should have enough LSB 0's to
754 * guarantee single address bit changes.
755 * For example, to test a 64-Kbyte
756 * region, select a base address on a
757 * 64-Kbyte boundary. Also, select the
758 * region size as a power-of-two if at
759 * all possible.
760 *
761 * Returns: 0 if the test succeeds, 1 if the test fails.
wdenk38635852002-08-27 05:55:31 +0000762 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100763 len = ((ulong)end - (ulong)start)/sizeof(vu_long);
wdenk38635852002-08-27 05:55:31 +0000764 pattern = (vu_long) 0xaaaaaaaa;
765 anti_pattern = (vu_long) 0x55555555;
766
Mike Frysinger9504a552012-01-20 09:07:20 +0000767 debug("%s:%d: length = 0x%.8lx\n",
wdenk38635852002-08-27 05:55:31 +0000768 __FUNCTION__, __LINE__,
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100769 len);
wdenk38635852002-08-27 05:55:31 +0000770 /*
771 * Write the default pattern at each of the
772 * power-of-two offsets.
773 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100774 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000775 start[offset] = pattern;
776 }
777
778 /*
779 * Check for address bits stuck high.
780 */
781 test_offset = 0;
782 start[test_offset] = anti_pattern;
783
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100784 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000785 temp = start[offset];
786 if (temp != pattern) {
787 printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
788 " expected 0x%.8lx, actual 0x%.8lx\n",
789 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400790 errs++;
791 if (ctrlc()) {
792 putc ('\n');
793 return 1;
794 }
wdenk38635852002-08-27 05:55:31 +0000795 }
796 }
797 start[test_offset] = pattern;
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200798 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000799
800 /*
801 * Check for addr bits stuck low or shorted.
802 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100803 for (test_offset = 1; test_offset < len; test_offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000804 start[test_offset] = anti_pattern;
805
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100806 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000807 temp = start[offset];
808 if ((temp != pattern) && (offset != test_offset)) {
809 printf ("\nFAILURE: Address bit stuck low or shorted @"
810 " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n",
811 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400812 errs++;
813 if (ctrlc()) {
814 putc ('\n');
815 return 1;
816 }
wdenk38635852002-08-27 05:55:31 +0000817 }
818 }
819 start[test_offset] = pattern;
820 }
821
822 /*
823 * Description: Test the integrity of a physical
824 * memory device by performing an
825 * increment/decrement test over the
826 * entire region. In the process every
827 * storage bit in the device is tested
828 * as a zero and a one. The base address
829 * and the size of the region are
830 * selected by the caller.
831 *
832 * Returns: 0 if the test succeeds, 1 if the test fails.
833 */
834 num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1;
835
836 /*
837 * Fill memory with a known pattern.
838 */
839 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200840 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000841 start[offset] = pattern;
842 }
843
844 /*
845 * Check each location and invert it for the second pass.
846 */
847 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200848 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000849 temp = start[offset];
850 if (temp != pattern) {
851 printf ("\nFAILURE (read/write) @ 0x%.8lx:"
852 " expected 0x%.8lx, actual 0x%.8lx)\n",
853 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400854 errs++;
855 if (ctrlc()) {
856 putc ('\n');
857 return 1;
858 }
wdenk38635852002-08-27 05:55:31 +0000859 }
860
861 anti_pattern = ~pattern;
862 start[offset] = anti_pattern;
863 }
864
865 /*
866 * Check each location for the inverted pattern and zero it.
867 */
868 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200869 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000870 anti_pattern = ~pattern;
871 temp = start[offset];
872 if (temp != anti_pattern) {
873 printf ("\nFAILURE (read/write): @ 0x%.8lx:"
874 " expected 0x%.8lx, actual 0x%.8lx)\n",
875 (ulong)&start[offset], anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400876 errs++;
877 if (ctrlc()) {
878 putc ('\n');
879 return 1;
880 }
wdenk38635852002-08-27 05:55:31 +0000881 }
882 start[offset] = 0;
883 }
884 }
885
886#else /* The original, quickie test */
887 incr = 1;
888 for (;;) {
889 if (ctrlc()) {
890 putc ('\n');
891 return 1;
892 }
893
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100894 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400895 printf("Tested %d iteration(s) with %lu errors.\n",
896 iterations-1, errs);
897 return errs != 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100898 }
899 ++iterations;
900
wdenk38635852002-08-27 05:55:31 +0000901 printf ("\rPattern %08lX Writing..."
902 "%12s"
903 "\b\b\b\b\b\b\b\b\b\b",
904 pattern, "");
905
906 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200907 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000908 *addr = val;
909 val += incr;
910 }
911
wdenk4b9206e2004-03-23 22:14:11 +0000912 puts ("Reading...");
wdenk38635852002-08-27 05:55:31 +0000913
914 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200915 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000916 readback = *addr;
917 if (readback != val) {
918 printf ("\nMem error @ 0x%08X: "
919 "found %08lX, expected %08lX\n",
Simon Glass92549352011-09-17 06:48:58 +0000920 (uint)(uintptr_t)addr, readback, val);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400921 errs++;
922 if (ctrlc()) {
923 putc ('\n');
924 return 1;
925 }
wdenk38635852002-08-27 05:55:31 +0000926 }
927 val += incr;
928 }
929
930 /*
931 * Flip the pattern each time to make lots of zeros and
932 * then, the next time, lots of ones. We decrement
933 * the "negative" patterns and increment the "positive"
934 * patterns to preserve this feature.
935 */
936 if(pattern & 0x80000000) {
937 pattern = -pattern; /* complement & increment */
938 }
939 else {
940 pattern = ~pattern;
941 }
942 incr = -incr;
943 }
wdenk38635852002-08-27 05:55:31 +0000944#endif
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400945 return 0; /* not reached */
wdenk38635852002-08-27 05:55:31 +0000946}
947
948
949/* Modify memory.
950 *
951 * Syntax:
952 * mm{.b, .w, .l} {addr}
953 * nm{.b, .w, .l} {addr}
954 */
955static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200956mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000957{
wdenk27b207f2003-07-24 23:38:38 +0000958 ulong addr, i;
959 int nbytes, size;
wdenk38635852002-08-27 05:55:31 +0000960
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200961 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000962 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000963
964#ifdef CONFIG_BOOT_RETRY_TIME
965 reset_cmd_timeout(); /* got a good command to get here */
966#endif
967 /* We use the last specified parameters, unless new ones are
968 * entered.
969 */
970 addr = mm_last_addr;
971 size = mm_last_size;
972
973 if ((flag & CMD_FLAG_REPEAT) == 0) {
974 /* New command specified. Check for a size specification.
975 * Defaults to long if no or incorrect specification.
976 */
wdenk27b207f2003-07-24 23:38:38 +0000977 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
978 return 1;
wdenk38635852002-08-27 05:55:31 +0000979
980 /* Address is specified since argc > 1
981 */
982 addr = simple_strtoul(argv[1], NULL, 16);
983 addr += base_address;
984 }
985
wdenk2abbe072003-06-16 23:50:08 +0000986#ifdef CONFIG_HAS_DATAFLASH
987 if (addr_dataflash(addr)){
wdenk4b9206e2004-03-23 22:14:11 +0000988 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000989 return 0;
990 }
991#endif
992
Mike Frysinger4c727c72008-02-04 19:26:56 -0500993#ifdef CONFIG_BLACKFIN
994 if (addr_bfin_on_chip_mem(addr)) {
995 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
996 return 0;
997 }
998#endif
999
wdenk38635852002-08-27 05:55:31 +00001000 /* Print the address, followed by value. Then accept input for
1001 * the next value. A non-converted value exits.
1002 */
1003 do {
1004 printf("%08lx:", addr);
1005 if (size == 4)
1006 printf(" %08x", *((uint *)addr));
1007 else if (size == 2)
1008 printf(" %04x", *((ushort *)addr));
1009 else
1010 printf(" %02x", *((u_char *)addr));
1011
1012 nbytes = readline (" ? ");
1013 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1014 /* <CR> pressed as only input, don't modify current
1015 * location and move to next. "-" pressed will go back.
1016 */
1017 if (incrflag)
1018 addr += nbytes ? -size : size;
1019 nbytes = 1;
1020#ifdef CONFIG_BOOT_RETRY_TIME
1021 reset_cmd_timeout(); /* good enough to not time out */
1022#endif
1023 }
1024#ifdef CONFIG_BOOT_RETRY_TIME
1025 else if (nbytes == -2) {
1026 break; /* timed out, exit the command */
1027 }
1028#endif
1029 else {
1030 char *endp;
1031 i = simple_strtoul(console_buffer, &endp, 16);
1032 nbytes = endp - console_buffer;
1033 if (nbytes) {
1034#ifdef CONFIG_BOOT_RETRY_TIME
1035 /* good enough to not time out
1036 */
1037 reset_cmd_timeout();
1038#endif
1039 if (size == 4)
1040 *((uint *)addr) = i;
1041 else if (size == 2)
1042 *((ushort *)addr) = i;
1043 else
1044 *((u_char *)addr) = i;
1045 if (incrflag)
1046 addr += size;
1047 }
1048 }
1049 } while (nbytes);
1050
1051 mm_last_addr = addr;
1052 mm_last_size = size;
1053 return 0;
1054}
1055
Mike Frysinger710b9932010-12-21 14:19:51 -05001056#ifdef CONFIG_CMD_CRC32
1057
wdenkc26e4542004-04-18 10:13:26 +00001058#ifndef CONFIG_CRC32_VERIFY
1059
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001060int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001061{
wdenk71f95112003-06-15 22:40:42 +00001062 ulong addr, length;
1063 ulong crc;
1064 ulong *ptr;
wdenk38635852002-08-27 05:55:31 +00001065
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001066 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001067 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001068
wdenk71f95112003-06-15 22:40:42 +00001069 addr = simple_strtoul (argv[1], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001070 addr += base_address;
1071
wdenk71f95112003-06-15 22:40:42 +00001072 length = simple_strtoul (argv[2], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001073
Jens Scharsig39c6e032011-07-18 08:46:26 +02001074 crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
wdenk38635852002-08-27 05:55:31 +00001075
1076 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
wdenk71f95112003-06-15 22:40:42 +00001077 addr, addr + length - 1, crc);
wdenk38635852002-08-27 05:55:31 +00001078
wdenk71f95112003-06-15 22:40:42 +00001079 if (argc > 3) {
1080 ptr = (ulong *) simple_strtoul (argv[3], NULL, 16);
1081 *ptr = crc;
1082 }
wdenk38635852002-08-27 05:55:31 +00001083
1084 return 0;
1085}
1086
wdenkc26e4542004-04-18 10:13:26 +00001087#else /* CONFIG_CRC32_VERIFY */
1088
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001089int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkc26e4542004-04-18 10:13:26 +00001090{
1091 ulong addr, length;
1092 ulong crc;
1093 ulong *ptr;
wdenk6e592382004-04-18 17:39:38 +00001094 ulong vcrc;
wdenkc26e4542004-04-18 10:13:26 +00001095 int verify;
1096 int ac;
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001097 char * const *av;
wdenkc26e4542004-04-18 10:13:26 +00001098
1099 if (argc < 3) {
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001100usage:
Simon Glass4c12eeb2011-12-10 08:44:01 +00001101 return CMD_RET_USAGE;
wdenkc26e4542004-04-18 10:13:26 +00001102 }
1103
1104 av = argv + 1;
1105 ac = argc - 1;
1106 if (strcmp(*av, "-v") == 0) {
1107 verify = 1;
1108 av++;
1109 ac--;
1110 if (ac < 3)
1111 goto usage;
1112 } else
1113 verify = 0;
1114
1115 addr = simple_strtoul(*av++, NULL, 16);
1116 addr += base_address;
1117 length = simple_strtoul(*av++, NULL, 16);
1118
Jens Scharsig39c6e032011-07-18 08:46:26 +02001119 crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
wdenkc26e4542004-04-18 10:13:26 +00001120
1121 if (!verify) {
1122 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
1123 addr, addr + length - 1, crc);
1124 if (ac > 2) {
1125 ptr = (ulong *) simple_strtoul (*av++, NULL, 16);
1126 *ptr = crc;
1127 }
1128 } else {
1129 vcrc = simple_strtoul(*av++, NULL, 16);
1130 if (vcrc != crc) {
1131 printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n",
1132 addr, addr + length - 1, crc, vcrc);
1133 return 1;
1134 }
1135 }
1136
1137 return 0;
1138
1139}
1140#endif /* CONFIG_CRC32_VERIFY */
1141
Mike Frysinger710b9932010-12-21 14:19:51 -05001142#endif
1143
wdenk8bde7f72003-06-27 21:31:46 +00001144/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001145U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001146 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001147 "memory display",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001148 "[.b, .w, .l] address [# of objects]"
wdenk8bde7f72003-06-27 21:31:46 +00001149);
1150
1151
wdenk0d498392003-07-01 21:06:45 +00001152U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001153 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001154 "memory modify (auto-incrementing address)",
1155 "[.b, .w, .l] address"
wdenk8bde7f72003-06-27 21:31:46 +00001156);
1157
1158
wdenk0d498392003-07-01 21:06:45 +00001159U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001160 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001161 "memory modify (constant address)",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001162 "[.b, .w, .l] address"
wdenk8bde7f72003-06-27 21:31:46 +00001163);
1164
wdenk0d498392003-07-01 21:06:45 +00001165U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001166 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001167 "memory write (fill)",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001168 "[.b, .w, .l] address value [count]"
wdenk8bde7f72003-06-27 21:31:46 +00001169);
1170
wdenk0d498392003-07-01 21:06:45 +00001171U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001172 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001173 "memory copy",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001174 "[.b, .w, .l] source target count"
wdenk8bde7f72003-06-27 21:31:46 +00001175);
1176
wdenk0d498392003-07-01 21:06:45 +00001177U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001178 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001179 "memory compare",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001180 "[.b, .w, .l] addr1 addr2 count"
wdenk8bde7f72003-06-27 21:31:46 +00001181);
1182
Mike Frysinger710b9932010-12-21 14:19:51 -05001183#ifdef CONFIG_CMD_CRC32
1184
wdenkc26e4542004-04-18 10:13:26 +00001185#ifndef CONFIG_CRC32_VERIFY
1186
wdenk0d498392003-07-01 21:06:45 +00001187U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001188 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001189 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001190 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001191);
1192
wdenkc26e4542004-04-18 10:13:26 +00001193#else /* CONFIG_CRC32_VERIFY */
1194
1195U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001196 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001197 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001198 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001199 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001200);
1201
1202#endif /* CONFIG_CRC32_VERIFY */
1203
Mike Frysinger710b9932010-12-21 14:19:51 -05001204#endif
1205
wdenk0d498392003-07-01 21:06:45 +00001206U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001207 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001208 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001209 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001210 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001211);
1212
wdenk0d498392003-07-01 21:06:45 +00001213U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001214 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001215 "infinite loop on address range",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001216 "[.b, .w, .l] address number_of_objects"
wdenk8bde7f72003-06-27 21:31:46 +00001217);
1218
wdenk56523f12004-07-11 17:40:54 +00001219#ifdef CONFIG_LOOPW
1220U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001221 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001222 "infinite write loop on address range",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001223 "[.b, .w, .l] address number_of_objects data_to_write"
wdenk56523f12004-07-11 17:40:54 +00001224);
1225#endif /* CONFIG_LOOPW */
1226
wdenk0d498392003-07-01 21:06:45 +00001227U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001228 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001229 "simple RAM read/write test",
1230 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001231);
1232
stroese4aaf29b2004-12-16 17:42:39 +00001233#ifdef CONFIG_MX_CYCLIC
1234U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001235 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001236 "memory display cyclic",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001237 "[.b, .w, .l] address count delay(ms)"
stroese4aaf29b2004-12-16 17:42:39 +00001238);
1239
1240U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001241 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001242 "memory write cyclic",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001243 "[.b, .w, .l] address value delay(ms)"
stroese4aaf29b2004-12-16 17:42:39 +00001244);
1245#endif /* CONFIG_MX_CYCLIC */