blob: 461ee1977d59d4e57f84203c514635b509cacb05 [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>
wdenk381669a2003-06-16 23:50:08 +000032#ifdef CONFIG_HAS_DATAFLASH
33#include <dataflash.h>
34#endif
Sergei Poselenov474dbb82008-04-09 16:09:41 +020035#include <watchdog.h>
Simon Glass117310f2011-10-25 13:51:09 +000036#include <asm/io.h>
wdenk38635852002-08-27 05:55:31 +000037
wdenk38635852002-08-27 05:55:31 +000038#ifdef CMD_MEM_DEBUG
39#define PRINTF(fmt,args...) printf (fmt ,##args)
40#else
41#define PRINTF(fmt,args...)
42#endif
43
Wolfgang Denk6262d0212010-06-28 22:00:46 +020044static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000045
46/* Display values from last command.
47 * Memory modify remembered values are different from display memory.
48 */
Mike Frysinger1a4af8c2010-12-22 09:40:29 -050049static uint dp_last_addr, dp_last_size;
50static uint dp_last_length = 0x40;
51static uint mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000052
53static ulong base_address = 0;
54
55/* Memory Display
56 *
57 * Syntax:
58 * md{.b, .w, .l} {addr} {len}
59 */
60#define DISP_LINE_LEN 16
Wolfgang Denk6262d0212010-06-28 22:00:46 +020061int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000062{
wdenk874ac262003-07-24 23:38:38 +000063 ulong addr, length;
Grant Likely02a00782007-02-20 09:05:00 +010064#if defined(CONFIG_HAS_DATAFLASH)
65 ulong nbytes, linebytes;
66#endif
wdenk874ac262003-07-24 23:38:38 +000067 int size;
wdenk38635852002-08-27 05:55:31 +000068 int rc = 0;
69
70 /* We use the last specified parameters, unless new ones are
71 * entered.
72 */
73 addr = dp_last_addr;
74 size = dp_last_size;
75 length = dp_last_length;
76
Wolfgang Denk3b683112010-07-17 01:06:04 +020077 if (argc < 2)
78 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +000079
80 if ((flag & CMD_FLAG_REPEAT) == 0) {
81 /* New command specified. Check for a size specification.
82 * Defaults to long if no or incorrect specification.
83 */
wdenk874ac262003-07-24 23:38:38 +000084 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
85 return 1;
wdenk38635852002-08-27 05:55:31 +000086
87 /* Address is specified since argc > 1
88 */
89 addr = simple_strtoul(argv[1], NULL, 16);
90 addr += base_address;
91
92 /* If another parameter, it is the length to display.
93 * Length is the number of objects, not number of bytes.
94 */
95 if (argc > 2)
96 length = simple_strtoul(argv[2], NULL, 16);
97 }
98
Grant Likely02a00782007-02-20 09:05:00 +010099#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +0000100 /* Print the lines.
101 *
102 * We buffer all read data, so we can make sure data is read only
103 * once, and all accesses are with the specified bus width.
104 */
105 nbytes = length * size;
106 do {
107 char linebuf[DISP_LINE_LEN];
Grant Likely02a00782007-02-20 09:05:00 +0100108 void* p;
wdenk38635852002-08-27 05:55:31 +0000109 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk381669a2003-06-16 23:50:08 +0000110
Grant Likely02a00782007-02-20 09:05:00 +0100111 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
112 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
113 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk57b2d802003-06-27 21:31:46 +0000114
wdenk38635852002-08-27 05:55:31 +0000115 nbytes -= linebytes;
Grant Likely02a00782007-02-20 09:05:00 +0100116 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000117 if (ctrlc()) {
118 rc = 1;
119 break;
120 }
121 } while (nbytes > 0);
Grant Likely02a00782007-02-20 09:05:00 +0100122#else
Mike Frysingere578d682008-02-04 19:26:56 -0500123
124# if defined(CONFIG_BLACKFIN)
125 /* See if we're trying to display L1 inst */
126 if (addr_bfin_on_chip_mem(addr)) {
127 char linebuf[DISP_LINE_LEN];
128 ulong linebytes, nbytes = length * size;
129 do {
130 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
131 memcpy(linebuf, (void *)addr, linebytes);
132 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
133
134 nbytes -= linebytes;
135 addr += linebytes;
136 if (ctrlc()) {
137 rc = 1;
138 break;
139 }
140 } while (nbytes > 0);
141 } else
142# endif
143
144 {
Simon Glass117310f2011-10-25 13:51:09 +0000145 ulong bytes = size * length;
146 void *buf = map_physmem(addr, bytes, MAP_WRBACK);
147
Mike Frysingere578d682008-02-04 19:26:56 -0500148 /* Print the lines. */
Simon Glass117310f2011-10-25 13:51:09 +0000149 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
150 addr += bytes;
151 unmap_physmem(buf, bytes);
Mike Frysingere578d682008-02-04 19:26:56 -0500152 }
Grant Likely02a00782007-02-20 09:05:00 +0100153#endif
wdenk38635852002-08-27 05:55:31 +0000154
155 dp_last_addr = addr;
156 dp_last_length = length;
157 dp_last_size = size;
158 return (rc);
159}
160
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200161int do_mem_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000162{
163 return mod_mem (cmdtp, 1, flag, argc, argv);
164}
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200165int do_mem_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000166{
167 return mod_mem (cmdtp, 0, flag, argc, argv);
168}
169
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200170int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000171{
wdenk874ac262003-07-24 23:38:38 +0000172 ulong addr, writeval, count;
173 int size;
wdenk38635852002-08-27 05:55:31 +0000174
Wolfgang Denk3b683112010-07-17 01:06:04 +0200175 if ((argc < 3) || (argc > 4))
176 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000177
178 /* Check for size specification.
179 */
wdenk874ac262003-07-24 23:38:38 +0000180 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
181 return 1;
wdenk38635852002-08-27 05:55:31 +0000182
183 /* Address is specified since argc > 1
184 */
185 addr = simple_strtoul(argv[1], NULL, 16);
186 addr += base_address;
187
188 /* Get the value to write.
189 */
190 writeval = simple_strtoul(argv[2], NULL, 16);
191
192 /* Count ? */
193 if (argc == 4) {
194 count = simple_strtoul(argv[3], NULL, 16);
195 } else {
196 count = 1;
197 }
198
199 while (count-- > 0) {
200 if (size == 4)
201 *((ulong *)addr) = (ulong )writeval;
202 else if (size == 2)
203 *((ushort *)addr) = (ushort)writeval;
204 else
205 *((u_char *)addr) = (u_char)writeval;
206 addr += size;
207 }
208 return 0;
209}
210
stroesefb5e0ac2004-12-16 17:42:39 +0000211#ifdef CONFIG_MX_CYCLIC
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200212int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000213{
214 int i;
215 ulong count;
216
Wolfgang Denk3b683112010-07-17 01:06:04 +0200217 if (argc < 4)
218 return cmd_usage(cmdtp);
stroesefb5e0ac2004-12-16 17:42:39 +0000219
220 count = simple_strtoul(argv[3], NULL, 10);
221
222 for (;;) {
223 do_mem_md (NULL, 0, 3, argv);
224
225 /* delay for <count> ms... */
226 for (i=0; i<count; i++)
227 udelay (1000);
228
229 /* check for ctrl-c to abort... */
230 if (ctrlc()) {
231 puts("Abort\n");
232 return 0;
233 }
234 }
235
236 return 0;
237}
238
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200239int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000240{
241 int i;
242 ulong count;
243
Wolfgang Denk3b683112010-07-17 01:06:04 +0200244 if (argc < 4)
245 return cmd_usage(cmdtp);
stroesefb5e0ac2004-12-16 17:42:39 +0000246
247 count = simple_strtoul(argv[3], NULL, 10);
248
249 for (;;) {
250 do_mem_mw (NULL, 0, 3, argv);
251
252 /* delay for <count> ms... */
253 for (i=0; i<count; i++)
254 udelay (1000);
255
256 /* check for ctrl-c to abort... */
257 if (ctrlc()) {
258 puts("Abort\n");
259 return 0;
260 }
261 }
262
263 return 0;
264}
265#endif /* CONFIG_MX_CYCLIC */
266
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200267int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000268{
wdenk874ac262003-07-24 23:38:38 +0000269 ulong addr1, addr2, count, ngood;
270 int size;
wdenk38635852002-08-27 05:55:31 +0000271 int rcode = 0;
272
Wolfgang Denk3b683112010-07-17 01:06:04 +0200273 if (argc != 4)
274 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000275
276 /* Check for size specification.
277 */
wdenk874ac262003-07-24 23:38:38 +0000278 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
279 return 1;
wdenk38635852002-08-27 05:55:31 +0000280
281 addr1 = simple_strtoul(argv[1], NULL, 16);
282 addr1 += base_address;
283
284 addr2 = simple_strtoul(argv[2], NULL, 16);
285 addr2 += base_address;
286
287 count = simple_strtoul(argv[3], NULL, 16);
288
wdenk381669a2003-06-16 23:50:08 +0000289#ifdef CONFIG_HAS_DATAFLASH
290 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk42c05472004-03-23 22:14:11 +0000291 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000292 return 0;
293 }
294#endif
295
Mike Frysingere578d682008-02-04 19:26:56 -0500296#ifdef CONFIG_BLACKFIN
297 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
298 puts ("Comparison with L1 instruction memory not supported.\n\r");
299 return 0;
300 }
301#endif
302
wdenk38635852002-08-27 05:55:31 +0000303 ngood = 0;
304
305 while (count-- > 0) {
306 if (size == 4) {
307 ulong word1 = *(ulong *)addr1;
308 ulong word2 = *(ulong *)addr2;
309 if (word1 != word2) {
310 printf("word at 0x%08lx (0x%08lx) "
311 "!= word at 0x%08lx (0x%08lx)\n",
312 addr1, word1, addr2, word2);
313 rcode = 1;
314 break;
315 }
316 }
317 else if (size == 2) {
318 ushort hword1 = *(ushort *)addr1;
319 ushort hword2 = *(ushort *)addr2;
320 if (hword1 != hword2) {
321 printf("halfword at 0x%08lx (0x%04x) "
322 "!= halfword at 0x%08lx (0x%04x)\n",
323 addr1, hword1, addr2, hword2);
324 rcode = 1;
325 break;
326 }
327 }
328 else {
329 u_char byte1 = *(u_char *)addr1;
330 u_char byte2 = *(u_char *)addr2;
331 if (byte1 != byte2) {
332 printf("byte at 0x%08lx (0x%02x) "
333 "!= byte at 0x%08lx (0x%02x)\n",
334 addr1, byte1, addr2, byte2);
335 rcode = 1;
336 break;
337 }
338 }
339 ngood++;
340 addr1 += size;
341 addr2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200342
343 /* reset watchdog from time to time */
344 if ((count % (64 << 10)) == 0)
345 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000346 }
347
348 printf("Total of %ld %s%s were the same\n",
349 ngood, size == 4 ? "word" : size == 2 ? "halfword" : "byte",
350 ngood == 1 ? "" : "s");
351 return rcode;
352}
353
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200354int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000355{
wdenk874ac262003-07-24 23:38:38 +0000356 ulong addr, dest, count;
357 int size;
wdenk38635852002-08-27 05:55:31 +0000358
Wolfgang Denk3b683112010-07-17 01:06:04 +0200359 if (argc != 4)
360 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000361
362 /* Check for size specification.
363 */
wdenk874ac262003-07-24 23:38:38 +0000364 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
365 return 1;
wdenk38635852002-08-27 05:55:31 +0000366
367 addr = simple_strtoul(argv[1], NULL, 16);
368 addr += base_address;
369
370 dest = simple_strtoul(argv[2], NULL, 16);
371 dest += base_address;
372
373 count = simple_strtoul(argv[3], NULL, 16);
374
375 if (count == 0) {
376 puts ("Zero length ???\n");
377 return 1;
378 }
379
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200380#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000381 /* check if we are copying to Flash */
wdenk381669a2003-06-16 23:50:08 +0000382 if ( (addr2info(dest) != NULL)
383#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino1eb0fd52008-03-03 10:39:13 +0200384 && (!addr_dataflash(dest))
wdenk381669a2003-06-16 23:50:08 +0000385#endif
386 ) {
wdenk38635852002-08-27 05:55:31 +0000387 int rc;
388
wdenk42c05472004-03-23 22:14:11 +0000389 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000390
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200391 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000392 if (rc != 0) {
393 flash_perror (rc);
394 return (1);
395 }
396 puts ("done\n");
397 return 0;
398 }
399#endif
400
wdenk381669a2003-06-16 23:50:08 +0000401#ifdef CONFIG_HAS_DATAFLASH
402 /* Check if we are copying from RAM or Flash to DataFlash */
403 if (addr_dataflash(dest) && !addr_dataflash(addr)){
404 int rc;
405
wdenk42c05472004-03-23 22:14:11 +0000406 puts ("Copy to DataFlash... ");
wdenk381669a2003-06-16 23:50:08 +0000407
408 rc = write_dataflash (dest, addr, count*size);
409
410 if (rc != 1) {
411 dataflash_perror (rc);
412 return (1);
413 }
414 puts ("done\n");
415 return 0;
416 }
wdenk57b2d802003-06-27 21:31:46 +0000417
wdenk381669a2003-06-16 23:50:08 +0000418 /* Check if we are copying from DataFlash to RAM */
Stelian Popa63d2eb2008-03-26 22:52:35 +0100419 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200420#ifndef CONFIG_SYS_NO_FLASH
Stelian Popa63d2eb2008-03-26 22:52:35 +0100421 && (addr2info(dest) == NULL)
422#endif
423 ){
wdenk86765902003-12-06 23:55:10 +0000424 int rc;
425 rc = read_dataflash(addr, count * size, (char *) dest);
426 if (rc != 1) {
wdenk1ebf41e2004-01-02 14:00:00 +0000427 dataflash_perror (rc);
428 return (1);
429 }
wdenk381669a2003-06-16 23:50:08 +0000430 return 0;
431 }
432
433 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk42c05472004-03-23 22:14:11 +0000434 puts ("Unsupported combination of source/destination.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000435 return 1;
436 }
wdenk7a428cc2003-06-15 22:40:42 +0000437#endif
438
Mike Frysingere578d682008-02-04 19:26:56 -0500439#ifdef CONFIG_BLACKFIN
440 /* See if we're copying to/from L1 inst */
441 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
442 memcpy((void *)dest, (void *)addr, count * size);
443 return 0;
444 }
445#endif
446
wdenk38635852002-08-27 05:55:31 +0000447 while (count-- > 0) {
448 if (size == 4)
449 *((ulong *)dest) = *((ulong *)addr);
450 else if (size == 2)
451 *((ushort *)dest) = *((ushort *)addr);
452 else
453 *((u_char *)dest) = *((u_char *)addr);
454 addr += size;
455 dest += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200456
457 /* reset watchdog from time to time */
458 if ((count % (64 << 10)) == 0)
459 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000460 }
461 return 0;
462}
463
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200464int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000465{
466 if (argc > 1) {
467 /* Set new base address.
468 */
469 base_address = simple_strtoul(argv[1], NULL, 16);
470 }
471 /* Print the current base address.
472 */
473 printf("Base Address: 0x%08lx\n", base_address);
474 return 0;
475}
476
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200477int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000478{
Marek Vasut7d335822011-09-26 02:26:06 +0200479 ulong addr, length, i;
wdenk874ac262003-07-24 23:38:38 +0000480 int size;
wdenk38635852002-08-27 05:55:31 +0000481 volatile uint *longp;
482 volatile ushort *shortp;
483 volatile u_char *cp;
484
Wolfgang Denk3b683112010-07-17 01:06:04 +0200485 if (argc < 3)
486 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000487
488 /* Check for a size spefication.
489 * Defaults to long if no or incorrect specification.
490 */
wdenk874ac262003-07-24 23:38:38 +0000491 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
492 return 1;
wdenk38635852002-08-27 05:55:31 +0000493
494 /* Address is always specified.
495 */
496 addr = simple_strtoul(argv[1], NULL, 16);
497
498 /* Length is the number of objects, not number of bytes.
499 */
500 length = simple_strtoul(argv[2], NULL, 16);
501
502 /* We want to optimize the loops to run as fast as possible.
503 * If we have only one object, just run infinite loops.
504 */
505 if (length == 1) {
506 if (size == 4) {
507 longp = (uint *)addr;
508 for (;;)
509 i = *longp;
510 }
511 if (size == 2) {
512 shortp = (ushort *)addr;
513 for (;;)
514 i = *shortp;
515 }
516 cp = (u_char *)addr;
517 for (;;)
518 i = *cp;
519 }
520
521 if (size == 4) {
522 for (;;) {
523 longp = (uint *)addr;
524 i = length;
525 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200526 *longp++;
wdenk38635852002-08-27 05:55:31 +0000527 }
528 }
529 if (size == 2) {
530 for (;;) {
531 shortp = (ushort *)addr;
532 i = length;
533 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200534 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000535 }
536 }
537 for (;;) {
538 cp = (u_char *)addr;
539 i = length;
540 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200541 *cp++;
wdenk38635852002-08-27 05:55:31 +0000542 }
543}
544
wdenk64519362004-07-11 17:40:54 +0000545#ifdef CONFIG_LOOPW
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200546int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000547{
548 ulong addr, length, i, data;
549 int size;
550 volatile uint *longp;
551 volatile ushort *shortp;
552 volatile u_char *cp;
wdenk7dd13292004-07-11 20:04:51 +0000553
Wolfgang Denk3b683112010-07-17 01:06:04 +0200554 if (argc < 4)
555 return cmd_usage(cmdtp);
wdenk64519362004-07-11 17:40:54 +0000556
557 /* Check for a size spefication.
558 * Defaults to long if no or incorrect specification.
559 */
560 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
561 return 1;
562
563 /* Address is always specified.
564 */
565 addr = simple_strtoul(argv[1], NULL, 16);
566
567 /* Length is the number of objects, not number of bytes.
568 */
569 length = simple_strtoul(argv[2], NULL, 16);
570
571 /* data to write */
572 data = simple_strtoul(argv[3], NULL, 16);
wdenk7dd13292004-07-11 20:04:51 +0000573
wdenk64519362004-07-11 17:40:54 +0000574 /* We want to optimize the loops to run as fast as possible.
575 * If we have only one object, just run infinite loops.
576 */
577 if (length == 1) {
578 if (size == 4) {
579 longp = (uint *)addr;
580 for (;;)
581 *longp = data;
582 }
583 if (size == 2) {
584 shortp = (ushort *)addr;
585 for (;;)
586 *shortp = data;
587 }
588 cp = (u_char *)addr;
589 for (;;)
590 *cp = data;
591 }
592
593 if (size == 4) {
594 for (;;) {
595 longp = (uint *)addr;
596 i = length;
597 while (i-- > 0)
598 *longp++ = data;
599 }
600 }
601 if (size == 2) {
602 for (;;) {
603 shortp = (ushort *)addr;
604 i = length;
605 while (i-- > 0)
606 *shortp++ = data;
607 }
608 }
609 for (;;) {
610 cp = (u_char *)addr;
611 i = length;
612 while (i-- > 0)
613 *cp++ = data;
614 }
615}
616#endif /* CONFIG_LOOPW */
617
wdenk38635852002-08-27 05:55:31 +0000618/*
619 * Perform a memory test. A more complete alternative test can be
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200620 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
wdenk38635852002-08-27 05:55:31 +0000621 * interrupted by ctrl-c or by a failure of one of the sub-tests.
622 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200623int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000624{
625 vu_long *addr, *start, *end;
626 ulong val;
627 ulong readback;
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400628 ulong errs = 0;
Dirk Eibachb2659892008-12-16 14:51:56 +0100629 int iterations = 1;
630 int iteration_limit;
wdenk38635852002-08-27 05:55:31 +0000631
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200632#if defined(CONFIG_SYS_ALT_MEMTEST)
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100633 vu_long len;
wdenk38635852002-08-27 05:55:31 +0000634 vu_long offset;
635 vu_long test_offset;
636 vu_long pattern;
637 vu_long temp;
638 vu_long anti_pattern;
639 vu_long num_words;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200640#if defined(CONFIG_SYS_MEMTEST_SCRATCH)
641 vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH;
wdenk5958f4a2003-09-18 09:21:33 +0000642#else
Wolfgang Denkf0e38c12006-07-21 11:37:40 +0200643 vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
wdenk5958f4a2003-09-18 09:21:33 +0000644#endif
wdenk38635852002-08-27 05:55:31 +0000645 int j;
wdenk38635852002-08-27 05:55:31 +0000646
647 static const ulong bitpattern[] = {
648 0x00000001, /* single bit */
649 0x00000003, /* two adjacent bits */
650 0x00000007, /* three adjacent bits */
651 0x0000000F, /* four adjacent bits */
652 0x00000005, /* two non-adjacent bits */
653 0x00000015, /* three non-adjacent bits */
654 0x00000055, /* four non-adjacent bits */
655 0xaaaaaaaa, /* alternating 1/0 */
656 };
657#else
658 ulong incr;
659 ulong pattern;
wdenk38635852002-08-27 05:55:31 +0000660#endif
661
Dirk Eibachb2659892008-12-16 14:51:56 +0100662 if (argc > 1)
wdenk38635852002-08-27 05:55:31 +0000663 start = (ulong *)simple_strtoul(argv[1], NULL, 16);
Dirk Eibachb2659892008-12-16 14:51:56 +0100664 else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200665 start = (ulong *)CONFIG_SYS_MEMTEST_START;
wdenk38635852002-08-27 05:55:31 +0000666
Dirk Eibachb2659892008-12-16 14:51:56 +0100667 if (argc > 2)
wdenk38635852002-08-27 05:55:31 +0000668 end = (ulong *)simple_strtoul(argv[2], NULL, 16);
Dirk Eibachb2659892008-12-16 14:51:56 +0100669 else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200670 end = (ulong *)(CONFIG_SYS_MEMTEST_END);
wdenk38635852002-08-27 05:55:31 +0000671
Dirk Eibachb2659892008-12-16 14:51:56 +0100672 if (argc > 3)
wdenk38635852002-08-27 05:55:31 +0000673 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
Dirk Eibachb2659892008-12-16 14:51:56 +0100674 else
wdenk38635852002-08-27 05:55:31 +0000675 pattern = 0;
Dirk Eibachb2659892008-12-16 14:51:56 +0100676
677 if (argc > 4)
678 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
679 else
680 iteration_limit = 0;
wdenk38635852002-08-27 05:55:31 +0000681
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200682#if defined(CONFIG_SYS_ALT_MEMTEST)
wdenk38635852002-08-27 05:55:31 +0000683 printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
684 PRINTF("%s:%d: start 0x%p end 0x%p\n",
685 __FUNCTION__, __LINE__, start, end);
686
687 for (;;) {
688 if (ctrlc()) {
689 putc ('\n');
690 return 1;
691 }
692
Dirk Eibachb2659892008-12-16 14:51:56 +0100693
694 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400695 printf("Tested %d iteration(s) with %lu errors.\n",
696 iterations-1, errs);
697 return errs != 0;
Dirk Eibachb2659892008-12-16 14:51:56 +0100698 }
699
wdenk38635852002-08-27 05:55:31 +0000700 printf("Iteration: %6d\r", iterations);
Dirk Eibachb2659892008-12-16 14:51:56 +0100701 PRINTF("\n");
wdenk38635852002-08-27 05:55:31 +0000702 iterations++;
703
704 /*
705 * Data line test: write a pattern to the first
706 * location, write the 1's complement to a 'parking'
707 * address (changes the state of the data bus so a
708 * floating bus doen't give a false OK), and then
709 * read the value back. Note that we read it back
710 * into a variable because the next time we read it,
711 * it might be right (been there, tough to explain to
712 * the quality guys why it prints a failure when the
713 * "is" and "should be" are obviously the same in the
714 * error message).
715 *
716 * Rather than exhaustively testing, we test some
717 * patterns by shifting '1' bits through a field of
718 * '0's and '0' bits through a field of '1's (i.e.
719 * pattern and ~pattern).
720 */
721 addr = start;
722 for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) {
723 val = bitpattern[j];
724 for(; val != 0; val <<= 1) {
725 *addr = val;
726 *dummy = ~val; /* clear the test data off of the bus */
727 readback = *addr;
728 if(readback != val) {
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400729 printf ("FAILURE (data line): "
wdenk38635852002-08-27 05:55:31 +0000730 "expected %08lx, actual %08lx\n",
731 val, readback);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400732 errs++;
733 if (ctrlc()) {
734 putc ('\n');
735 return 1;
736 }
wdenk38635852002-08-27 05:55:31 +0000737 }
738 *addr = ~val;
739 *dummy = val;
740 readback = *addr;
741 if(readback != ~val) {
742 printf ("FAILURE (data line): "
743 "Is %08lx, should be %08lx\n",
wdenk391b5742004-10-10 23:27:33 +0000744 readback, ~val);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400745 errs++;
746 if (ctrlc()) {
747 putc ('\n');
748 return 1;
749 }
wdenk38635852002-08-27 05:55:31 +0000750 }
751 }
752 }
753
754 /*
755 * Based on code whose Original Author and Copyright
756 * information follows: Copyright (c) 1998 by Michael
757 * Barr. This software is placed into the public
758 * domain and may be used for any purpose. However,
759 * this notice must not be changed or removed and no
760 * warranty is either expressed or implied by its
761 * publication or distribution.
762 */
763
764 /*
765 * Address line test
766 *
767 * Description: Test the address bus wiring in a
768 * memory region by performing a walking
769 * 1's test on the relevant bits of the
770 * address and checking for aliasing.
771 * This test will find single-bit
772 * address failures such as stuck -high,
773 * stuck-low, and shorted pins. The base
774 * address and size of the region are
775 * selected by the caller.
776 *
777 * Notes: For best results, the selected base
778 * address should have enough LSB 0's to
779 * guarantee single address bit changes.
780 * For example, to test a 64-Kbyte
781 * region, select a base address on a
782 * 64-Kbyte boundary. Also, select the
783 * region size as a power-of-two if at
784 * all possible.
785 *
786 * Returns: 0 if the test succeeds, 1 if the test fails.
wdenk38635852002-08-27 05:55:31 +0000787 */
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100788 len = ((ulong)end - (ulong)start)/sizeof(vu_long);
wdenk38635852002-08-27 05:55:31 +0000789 pattern = (vu_long) 0xaaaaaaaa;
790 anti_pattern = (vu_long) 0x55555555;
791
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100792 PRINTF("%s:%d: length = 0x%.8lx\n",
wdenk38635852002-08-27 05:55:31 +0000793 __FUNCTION__, __LINE__,
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100794 len);
wdenk38635852002-08-27 05:55:31 +0000795 /*
796 * Write the default pattern at each of the
797 * power-of-two offsets.
798 */
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100799 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000800 start[offset] = pattern;
801 }
802
803 /*
804 * Check for address bits stuck high.
805 */
806 test_offset = 0;
807 start[test_offset] = anti_pattern;
808
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100809 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000810 temp = start[offset];
811 if (temp != pattern) {
812 printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
813 " expected 0x%.8lx, actual 0x%.8lx\n",
814 (ulong)&start[offset], pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400815 errs++;
816 if (ctrlc()) {
817 putc ('\n');
818 return 1;
819 }
wdenk38635852002-08-27 05:55:31 +0000820 }
821 }
822 start[test_offset] = pattern;
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200823 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000824
825 /*
826 * Check for addr bits stuck low or shorted.
827 */
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100828 for (test_offset = 1; test_offset < len; test_offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000829 start[test_offset] = anti_pattern;
830
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100831 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000832 temp = start[offset];
833 if ((temp != pattern) && (offset != test_offset)) {
834 printf ("\nFAILURE: Address bit stuck low or shorted @"
835 " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n",
836 (ulong)&start[offset], pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400837 errs++;
838 if (ctrlc()) {
839 putc ('\n');
840 return 1;
841 }
wdenk38635852002-08-27 05:55:31 +0000842 }
843 }
844 start[test_offset] = pattern;
845 }
846
847 /*
848 * Description: Test the integrity of a physical
849 * memory device by performing an
850 * increment/decrement test over the
851 * entire region. In the process every
852 * storage bit in the device is tested
853 * as a zero and a one. The base address
854 * and the size of the region are
855 * selected by the caller.
856 *
857 * Returns: 0 if the test succeeds, 1 if the test fails.
858 */
859 num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1;
860
861 /*
862 * Fill memory with a known pattern.
863 */
864 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200865 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000866 start[offset] = pattern;
867 }
868
869 /*
870 * Check each location and invert it for the second pass.
871 */
872 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200873 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000874 temp = start[offset];
875 if (temp != pattern) {
876 printf ("\nFAILURE (read/write) @ 0x%.8lx:"
877 " expected 0x%.8lx, actual 0x%.8lx)\n",
878 (ulong)&start[offset], pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400879 errs++;
880 if (ctrlc()) {
881 putc ('\n');
882 return 1;
883 }
wdenk38635852002-08-27 05:55:31 +0000884 }
885
886 anti_pattern = ~pattern;
887 start[offset] = anti_pattern;
888 }
889
890 /*
891 * Check each location for the inverted pattern and zero it.
892 */
893 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200894 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000895 anti_pattern = ~pattern;
896 temp = start[offset];
897 if (temp != anti_pattern) {
898 printf ("\nFAILURE (read/write): @ 0x%.8lx:"
899 " expected 0x%.8lx, actual 0x%.8lx)\n",
900 (ulong)&start[offset], anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400901 errs++;
902 if (ctrlc()) {
903 putc ('\n');
904 return 1;
905 }
wdenk38635852002-08-27 05:55:31 +0000906 }
907 start[offset] = 0;
908 }
909 }
910
911#else /* The original, quickie test */
912 incr = 1;
913 for (;;) {
914 if (ctrlc()) {
915 putc ('\n');
916 return 1;
917 }
Dirk Eibachb2659892008-12-16 14:51:56 +0100918
919 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400920 printf("Tested %d iteration(s) with %lu errors.\n",
921 iterations-1, errs);
922 return errs != 0;
Dirk Eibachb2659892008-12-16 14:51:56 +0100923 }
924 ++iterations;
wdenk38635852002-08-27 05:55:31 +0000925
926 printf ("\rPattern %08lX Writing..."
927 "%12s"
928 "\b\b\b\b\b\b\b\b\b\b",
929 pattern, "");
930
931 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200932 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000933 *addr = val;
934 val += incr;
935 }
936
wdenk42c05472004-03-23 22:14:11 +0000937 puts ("Reading...");
wdenk38635852002-08-27 05:55:31 +0000938
939 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200940 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000941 readback = *addr;
942 if (readback != val) {
943 printf ("\nMem error @ 0x%08X: "
944 "found %08lX, expected %08lX\n",
Simon Glassfc953242011-09-17 06:48:58 +0000945 (uint)(uintptr_t)addr, readback, val);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400946 errs++;
947 if (ctrlc()) {
948 putc ('\n');
949 return 1;
950 }
wdenk38635852002-08-27 05:55:31 +0000951 }
952 val += incr;
953 }
954
955 /*
956 * Flip the pattern each time to make lots of zeros and
957 * then, the next time, lots of ones. We decrement
958 * the "negative" patterns and increment the "positive"
959 * patterns to preserve this feature.
960 */
961 if(pattern & 0x80000000) {
962 pattern = -pattern; /* complement & increment */
963 }
964 else {
965 pattern = ~pattern;
966 }
967 incr = -incr;
968 }
wdenk38635852002-08-27 05:55:31 +0000969#endif
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400970 return 0; /* not reached */
wdenk38635852002-08-27 05:55:31 +0000971}
972
973
974/* Modify memory.
975 *
976 * Syntax:
977 * mm{.b, .w, .l} {addr}
978 * nm{.b, .w, .l} {addr}
979 */
980static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200981mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000982{
wdenk874ac262003-07-24 23:38:38 +0000983 ulong addr, i;
984 int nbytes, size;
wdenk38635852002-08-27 05:55:31 +0000985 extern char console_buffer[];
986
Wolfgang Denk3b683112010-07-17 01:06:04 +0200987 if (argc != 2)
988 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000989
990#ifdef CONFIG_BOOT_RETRY_TIME
991 reset_cmd_timeout(); /* got a good command to get here */
992#endif
993 /* We use the last specified parameters, unless new ones are
994 * entered.
995 */
996 addr = mm_last_addr;
997 size = mm_last_size;
998
999 if ((flag & CMD_FLAG_REPEAT) == 0) {
1000 /* New command specified. Check for a size specification.
1001 * Defaults to long if no or incorrect specification.
1002 */
wdenk874ac262003-07-24 23:38:38 +00001003 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1004 return 1;
wdenk38635852002-08-27 05:55:31 +00001005
1006 /* Address is specified since argc > 1
1007 */
1008 addr = simple_strtoul(argv[1], NULL, 16);
1009 addr += base_address;
1010 }
1011
wdenk381669a2003-06-16 23:50:08 +00001012#ifdef CONFIG_HAS_DATAFLASH
1013 if (addr_dataflash(addr)){
wdenk42c05472004-03-23 22:14:11 +00001014 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk381669a2003-06-16 23:50:08 +00001015 return 0;
1016 }
1017#endif
1018
Mike Frysingere578d682008-02-04 19:26:56 -05001019#ifdef CONFIG_BLACKFIN
1020 if (addr_bfin_on_chip_mem(addr)) {
1021 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1022 return 0;
1023 }
1024#endif
1025
wdenk38635852002-08-27 05:55:31 +00001026 /* Print the address, followed by value. Then accept input for
1027 * the next value. A non-converted value exits.
1028 */
1029 do {
1030 printf("%08lx:", addr);
1031 if (size == 4)
1032 printf(" %08x", *((uint *)addr));
1033 else if (size == 2)
1034 printf(" %04x", *((ushort *)addr));
1035 else
1036 printf(" %02x", *((u_char *)addr));
1037
1038 nbytes = readline (" ? ");
1039 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1040 /* <CR> pressed as only input, don't modify current
1041 * location and move to next. "-" pressed will go back.
1042 */
1043 if (incrflag)
1044 addr += nbytes ? -size : size;
1045 nbytes = 1;
1046#ifdef CONFIG_BOOT_RETRY_TIME
1047 reset_cmd_timeout(); /* good enough to not time out */
1048#endif
1049 }
1050#ifdef CONFIG_BOOT_RETRY_TIME
1051 else if (nbytes == -2) {
1052 break; /* timed out, exit the command */
1053 }
1054#endif
1055 else {
1056 char *endp;
1057 i = simple_strtoul(console_buffer, &endp, 16);
1058 nbytes = endp - console_buffer;
1059 if (nbytes) {
1060#ifdef CONFIG_BOOT_RETRY_TIME
1061 /* good enough to not time out
1062 */
1063 reset_cmd_timeout();
1064#endif
1065 if (size == 4)
1066 *((uint *)addr) = i;
1067 else if (size == 2)
1068 *((ushort *)addr) = i;
1069 else
1070 *((u_char *)addr) = i;
1071 if (incrflag)
1072 addr += size;
1073 }
1074 }
1075 } while (nbytes);
1076
1077 mm_last_addr = addr;
1078 mm_last_size = size;
1079 return 0;
1080}
1081
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001082#ifdef CONFIG_CMD_CRC32
1083
wdenk6203e402004-04-18 10:13:26 +00001084#ifndef CONFIG_CRC32_VERIFY
1085
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001086int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001087{
wdenk7a428cc2003-06-15 22:40:42 +00001088 ulong addr, length;
1089 ulong crc;
1090 ulong *ptr;
wdenk38635852002-08-27 05:55:31 +00001091
Wolfgang Denk3b683112010-07-17 01:06:04 +02001092 if (argc < 3)
1093 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +00001094
wdenk7a428cc2003-06-15 22:40:42 +00001095 addr = simple_strtoul (argv[1], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001096 addr += base_address;
1097
wdenk7a428cc2003-06-15 22:40:42 +00001098 length = simple_strtoul (argv[2], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001099
Jens Scharsig5b2e6c22011-07-18 08:46:26 +02001100 crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
wdenk38635852002-08-27 05:55:31 +00001101
1102 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
wdenk7a428cc2003-06-15 22:40:42 +00001103 addr, addr + length - 1, crc);
wdenk38635852002-08-27 05:55:31 +00001104
wdenk7a428cc2003-06-15 22:40:42 +00001105 if (argc > 3) {
1106 ptr = (ulong *) simple_strtoul (argv[3], NULL, 16);
1107 *ptr = crc;
1108 }
wdenk38635852002-08-27 05:55:31 +00001109
1110 return 0;
1111}
1112
wdenk6203e402004-04-18 10:13:26 +00001113#else /* CONFIG_CRC32_VERIFY */
1114
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001115int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk6203e402004-04-18 10:13:26 +00001116{
1117 ulong addr, length;
1118 ulong crc;
1119 ulong *ptr;
wdenk05939202004-04-18 17:39:38 +00001120 ulong vcrc;
wdenk6203e402004-04-18 10:13:26 +00001121 int verify;
1122 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001123 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001124
1125 if (argc < 3) {
Wolfgang Denk3b683112010-07-17 01:06:04 +02001126usage:
1127 return cmd_usage(cmdtp);
wdenk6203e402004-04-18 10:13:26 +00001128 }
1129
1130 av = argv + 1;
1131 ac = argc - 1;
1132 if (strcmp(*av, "-v") == 0) {
1133 verify = 1;
1134 av++;
1135 ac--;
1136 if (ac < 3)
1137 goto usage;
1138 } else
1139 verify = 0;
1140
1141 addr = simple_strtoul(*av++, NULL, 16);
1142 addr += base_address;
1143 length = simple_strtoul(*av++, NULL, 16);
1144
Jens Scharsig5b2e6c22011-07-18 08:46:26 +02001145 crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
wdenk6203e402004-04-18 10:13:26 +00001146
1147 if (!verify) {
1148 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
1149 addr, addr + length - 1, crc);
1150 if (ac > 2) {
1151 ptr = (ulong *) simple_strtoul (*av++, NULL, 16);
1152 *ptr = crc;
1153 }
1154 } else {
1155 vcrc = simple_strtoul(*av++, NULL, 16);
1156 if (vcrc != crc) {
1157 printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n",
1158 addr, addr + length - 1, crc, vcrc);
1159 return 1;
1160 }
1161 }
1162
1163 return 0;
1164
1165}
1166#endif /* CONFIG_CRC32_VERIFY */
1167
Robin Getz93d6cb02009-07-27 00:07:59 -04001168#endif
1169
wdenk57b2d802003-06-27 21:31:46 +00001170/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001171U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001172 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001173 "memory display",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001174 "[.b, .w, .l] address [# of objects]"
wdenk57b2d802003-06-27 21:31:46 +00001175);
1176
1177
wdenkf287a242003-07-01 21:06:45 +00001178U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001179 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001180 "memory modify (auto-incrementing address)",
1181 "[.b, .w, .l] address"
wdenk57b2d802003-06-27 21:31:46 +00001182);
1183
1184
wdenkf287a242003-07-01 21:06:45 +00001185U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001186 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001187 "memory modify (constant address)",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001188 "[.b, .w, .l] address"
wdenk57b2d802003-06-27 21:31:46 +00001189);
1190
wdenkf287a242003-07-01 21:06:45 +00001191U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001192 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001193 "memory write (fill)",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001194 "[.b, .w, .l] address value [count]"
wdenk57b2d802003-06-27 21:31:46 +00001195);
1196
wdenkf287a242003-07-01 21:06:45 +00001197U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001198 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001199 "memory copy",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001200 "[.b, .w, .l] source target count"
wdenk57b2d802003-06-27 21:31:46 +00001201);
1202
wdenkf287a242003-07-01 21:06:45 +00001203U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001204 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001205 "memory compare",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001206 "[.b, .w, .l] addr1 addr2 count"
wdenk57b2d802003-06-27 21:31:46 +00001207);
1208
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001209#ifdef CONFIG_CMD_CRC32
1210
wdenk6203e402004-04-18 10:13:26 +00001211#ifndef CONFIG_CRC32_VERIFY
1212
wdenkf287a242003-07-01 21:06:45 +00001213U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001214 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001215 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001216 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001217);
1218
wdenk6203e402004-04-18 10:13:26 +00001219#else /* CONFIG_CRC32_VERIFY */
1220
1221U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001222 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001223 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001224 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001225 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001226);
1227
1228#endif /* CONFIG_CRC32_VERIFY */
1229
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001230#endif
1231
wdenkf287a242003-07-01 21:06:45 +00001232U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001233 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001234 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001235 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001236 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001237);
1238
wdenkf287a242003-07-01 21:06:45 +00001239U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001240 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001241 "infinite loop on address range",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001242 "[.b, .w, .l] address number_of_objects"
wdenk57b2d802003-06-27 21:31:46 +00001243);
wdenk64519362004-07-11 17:40:54 +00001244
1245#ifdef CONFIG_LOOPW
1246U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001247 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001248 "infinite write loop on address range",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001249 "[.b, .w, .l] address number_of_objects data_to_write"
wdenk64519362004-07-11 17:40:54 +00001250);
1251#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001252
wdenkf287a242003-07-01 21:06:45 +00001253U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001254 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001255 "simple RAM read/write test",
1256 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001257);
stroesefb5e0ac2004-12-16 17:42:39 +00001258
1259#ifdef CONFIG_MX_CYCLIC
1260U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001261 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001262 "memory display cyclic",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001263 "[.b, .w, .l] address count delay(ms)"
stroesefb5e0ac2004-12-16 17:42:39 +00001264);
1265
1266U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001267 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001268 "memory write cyclic",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001269 "[.b, .w, .l] address value delay(ms)"
stroesefb5e0ac2004-12-16 17:42:39 +00001270);
1271#endif /* CONFIG_MX_CYCLIC */