blob: a203e0d3e4dd021a084c214f5c36c8e6b6798b9c [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>
Jon Loeligerc76fe472007-07-08 18:02:23 -050032#if defined(CONFIG_CMD_MMC)
wdenk71f95112003-06-15 22:40:42 +000033#include <mmc.h>
34#endif
wdenk2abbe072003-06-16 23:50:08 +000035#ifdef CONFIG_HAS_DATAFLASH
36#include <dataflash.h>
37#endif
Sergei Poselenova6e6fc62008-04-09 16:09:41 +020038#include <watchdog.h>
wdenk38635852002-08-27 05:55:31 +000039
wdenk38635852002-08-27 05:55:31 +000040#ifdef CMD_MEM_DEBUG
41#define PRINTF(fmt,args...) printf (fmt ,##args)
42#else
43#define PRINTF(fmt,args...)
44#endif
45
46static int mod_mem(cmd_tbl_t *, int, int, int, char *[]);
47
48/* Display values from last command.
49 * Memory modify remembered values are different from display memory.
50 */
51uint dp_last_addr, dp_last_size;
52uint dp_last_length = 0x40;
53uint mm_last_addr, mm_last_size;
54
55static ulong base_address = 0;
56
57/* Memory Display
58 *
59 * Syntax:
60 * md{.b, .w, .l} {addr} {len}
61 */
62#define DISP_LINE_LEN 16
63int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
64{
wdenk27b207f2003-07-24 23:38:38 +000065 ulong addr, length;
Grant Likelyc95c4282007-02-20 09:05:00 +010066#if defined(CONFIG_HAS_DATAFLASH)
67 ulong nbytes, linebytes;
68#endif
wdenk27b207f2003-07-24 23:38:38 +000069 int size;
wdenk38635852002-08-27 05:55:31 +000070 int rc = 0;
71
72 /* We use the last specified parameters, unless new ones are
73 * entered.
74 */
75 addr = dp_last_addr;
76 size = dp_last_size;
77 length = dp_last_length;
78
79 if (argc < 2) {
Peter Tyser62c3ae72009-01-27 18:03:10 -060080 cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +000081 return 1;
82 }
83
84 if ((flag & CMD_FLAG_REPEAT) == 0) {
85 /* New command specified. Check for a size specification.
86 * Defaults to long if no or incorrect specification.
87 */
wdenk27b207f2003-07-24 23:38:38 +000088 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
89 return 1;
wdenk38635852002-08-27 05:55:31 +000090
91 /* Address is specified since argc > 1
92 */
93 addr = simple_strtoul(argv[1], NULL, 16);
94 addr += base_address;
95
96 /* If another parameter, it is the length to display.
97 * Length is the number of objects, not number of bytes.
98 */
99 if (argc > 2)
100 length = simple_strtoul(argv[2], NULL, 16);
101 }
102
Grant Likelyc95c4282007-02-20 09:05:00 +0100103#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +0000104 /* Print the lines.
105 *
106 * We buffer all read data, so we can make sure data is read only
107 * once, and all accesses are with the specified bus width.
108 */
109 nbytes = length * size;
110 do {
111 char linebuf[DISP_LINE_LEN];
Grant Likelyc95c4282007-02-20 09:05:00 +0100112 void* p;
wdenk38635852002-08-27 05:55:31 +0000113 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk2abbe072003-06-16 23:50:08 +0000114
Grant Likelyc95c4282007-02-20 09:05:00 +0100115 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
116 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
117 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk8bde7f72003-06-27 21:31:46 +0000118
wdenk38635852002-08-27 05:55:31 +0000119 nbytes -= linebytes;
Grant Likelyc95c4282007-02-20 09:05:00 +0100120 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000121 if (ctrlc()) {
122 rc = 1;
123 break;
124 }
125 } while (nbytes > 0);
Grant Likelyc95c4282007-02-20 09:05:00 +0100126#else
Mike Frysinger4c727c72008-02-04 19:26:56 -0500127
128# if defined(CONFIG_BLACKFIN)
129 /* See if we're trying to display L1 inst */
130 if (addr_bfin_on_chip_mem(addr)) {
131 char linebuf[DISP_LINE_LEN];
132 ulong linebytes, nbytes = length * size;
133 do {
134 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
135 memcpy(linebuf, (void *)addr, linebytes);
136 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
137
138 nbytes -= linebytes;
139 addr += linebytes;
140 if (ctrlc()) {
141 rc = 1;
142 break;
143 }
144 } while (nbytes > 0);
145 } else
146# endif
147
148 {
149 /* Print the lines. */
150 print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
151 addr += size*length;
152 }
Grant Likelyc95c4282007-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
161int do_mem_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
162{
163 return mod_mem (cmdtp, 1, flag, argc, argv);
164}
165int do_mem_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
166{
167 return mod_mem (cmdtp, 0, flag, argc, argv);
168}
169
170int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
171{
wdenk27b207f2003-07-24 23:38:38 +0000172 ulong addr, writeval, count;
173 int size;
wdenk38635852002-08-27 05:55:31 +0000174
175 if ((argc < 3) || (argc > 4)) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600176 cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000177 return 1;
178 }
179
180 /* Check for size specification.
181 */
wdenk27b207f2003-07-24 23:38:38 +0000182 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
183 return 1;
wdenk38635852002-08-27 05:55:31 +0000184
185 /* Address is specified since argc > 1
186 */
187 addr = simple_strtoul(argv[1], NULL, 16);
188 addr += base_address;
189
190 /* Get the value to write.
191 */
192 writeval = simple_strtoul(argv[2], NULL, 16);
193
194 /* Count ? */
195 if (argc == 4) {
196 count = simple_strtoul(argv[3], NULL, 16);
197 } else {
198 count = 1;
199 }
200
201 while (count-- > 0) {
202 if (size == 4)
203 *((ulong *)addr) = (ulong )writeval;
204 else if (size == 2)
205 *((ushort *)addr) = (ushort)writeval;
206 else
207 *((u_char *)addr) = (u_char)writeval;
208 addr += size;
209 }
210 return 0;
211}
212
stroese4aaf29b2004-12-16 17:42:39 +0000213#ifdef CONFIG_MX_CYCLIC
214int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
215{
216 int i;
217 ulong count;
218
219 if (argc < 4) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600220 cmd_usage(cmdtp);
stroese4aaf29b2004-12-16 17:42:39 +0000221 return 1;
222 }
223
224 count = simple_strtoul(argv[3], NULL, 10);
225
226 for (;;) {
227 do_mem_md (NULL, 0, 3, argv);
228
229 /* delay for <count> ms... */
230 for (i=0; i<count; i++)
231 udelay (1000);
232
233 /* check for ctrl-c to abort... */
234 if (ctrlc()) {
235 puts("Abort\n");
236 return 0;
237 }
238 }
239
240 return 0;
241}
242
243int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
244{
245 int i;
246 ulong count;
247
248 if (argc < 4) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600249 cmd_usage(cmdtp);
stroese4aaf29b2004-12-16 17:42:39 +0000250 return 1;
251 }
252
253 count = simple_strtoul(argv[3], NULL, 10);
254
255 for (;;) {
256 do_mem_mw (NULL, 0, 3, argv);
257
258 /* delay for <count> ms... */
259 for (i=0; i<count; i++)
260 udelay (1000);
261
262 /* check for ctrl-c to abort... */
263 if (ctrlc()) {
264 puts("Abort\n");
265 return 0;
266 }
267 }
268
269 return 0;
270}
271#endif /* CONFIG_MX_CYCLIC */
272
wdenk38635852002-08-27 05:55:31 +0000273int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
274{
wdenk27b207f2003-07-24 23:38:38 +0000275 ulong addr1, addr2, count, ngood;
276 int size;
wdenk38635852002-08-27 05:55:31 +0000277 int rcode = 0;
278
279 if (argc != 4) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600280 cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000281 return 1;
282 }
283
284 /* Check for size specification.
285 */
wdenk27b207f2003-07-24 23:38:38 +0000286 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
287 return 1;
wdenk38635852002-08-27 05:55:31 +0000288
289 addr1 = simple_strtoul(argv[1], NULL, 16);
290 addr1 += base_address;
291
292 addr2 = simple_strtoul(argv[2], NULL, 16);
293 addr2 += base_address;
294
295 count = simple_strtoul(argv[3], NULL, 16);
296
wdenk2abbe072003-06-16 23:50:08 +0000297#ifdef CONFIG_HAS_DATAFLASH
298 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk4b9206e2004-03-23 22:14:11 +0000299 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000300 return 0;
301 }
302#endif
303
Mike Frysinger4c727c72008-02-04 19:26:56 -0500304#ifdef CONFIG_BLACKFIN
305 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
306 puts ("Comparison with L1 instruction memory not supported.\n\r");
307 return 0;
308 }
309#endif
310
wdenk38635852002-08-27 05:55:31 +0000311 ngood = 0;
312
313 while (count-- > 0) {
314 if (size == 4) {
315 ulong word1 = *(ulong *)addr1;
316 ulong word2 = *(ulong *)addr2;
317 if (word1 != word2) {
318 printf("word at 0x%08lx (0x%08lx) "
319 "!= word at 0x%08lx (0x%08lx)\n",
320 addr1, word1, addr2, word2);
321 rcode = 1;
322 break;
323 }
324 }
325 else if (size == 2) {
326 ushort hword1 = *(ushort *)addr1;
327 ushort hword2 = *(ushort *)addr2;
328 if (hword1 != hword2) {
329 printf("halfword at 0x%08lx (0x%04x) "
330 "!= halfword at 0x%08lx (0x%04x)\n",
331 addr1, hword1, addr2, hword2);
332 rcode = 1;
333 break;
334 }
335 }
336 else {
337 u_char byte1 = *(u_char *)addr1;
338 u_char byte2 = *(u_char *)addr2;
339 if (byte1 != byte2) {
340 printf("byte at 0x%08lx (0x%02x) "
341 "!= byte at 0x%08lx (0x%02x)\n",
342 addr1, byte1, addr2, byte2);
343 rcode = 1;
344 break;
345 }
346 }
347 ngood++;
348 addr1 += size;
349 addr2 += size;
350 }
351
352 printf("Total of %ld %s%s were the same\n",
353 ngood, size == 4 ? "word" : size == 2 ? "halfword" : "byte",
354 ngood == 1 ? "" : "s");
355 return rcode;
356}
357
358int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
359{
wdenk27b207f2003-07-24 23:38:38 +0000360 ulong addr, dest, count;
361 int size;
wdenk38635852002-08-27 05:55:31 +0000362
363 if (argc != 4) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600364 cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000365 return 1;
366 }
367
368 /* Check for size specification.
369 */
wdenk27b207f2003-07-24 23:38:38 +0000370 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
371 return 1;
wdenk38635852002-08-27 05:55:31 +0000372
373 addr = simple_strtoul(argv[1], NULL, 16);
374 addr += base_address;
375
376 dest = simple_strtoul(argv[2], NULL, 16);
377 dest += base_address;
378
379 count = simple_strtoul(argv[3], NULL, 16);
380
381 if (count == 0) {
382 puts ("Zero length ???\n");
383 return 1;
384 }
385
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200386#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000387 /* check if we are copying to Flash */
wdenk2abbe072003-06-16 23:50:08 +0000388 if ( (addr2info(dest) != NULL)
389#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino84d0c2f2008-03-03 10:39:13 +0200390 && (!addr_dataflash(dest))
wdenk2abbe072003-06-16 23:50:08 +0000391#endif
392 ) {
wdenk38635852002-08-27 05:55:31 +0000393 int rc;
394
wdenk4b9206e2004-03-23 22:14:11 +0000395 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000396
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200397 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000398 if (rc != 0) {
399 flash_perror (rc);
400 return (1);
401 }
402 puts ("done\n");
403 return 0;
404 }
405#endif
406
Jon Loeligerc76fe472007-07-08 18:02:23 -0500407#if defined(CONFIG_CMD_MMC)
wdenk71f95112003-06-15 22:40:42 +0000408 if (mmc2info(dest)) {
409 int rc;
410
wdenk4b9206e2004-03-23 22:14:11 +0000411 puts ("Copy to MMC... ");
wdenk71f95112003-06-15 22:40:42 +0000412 switch (rc = mmc_write ((uchar *)addr, dest, count*size)) {
413 case 0:
wdenk4b9206e2004-03-23 22:14:11 +0000414 putc ('\n');
wdenk71f95112003-06-15 22:40:42 +0000415 return 1;
416 case -1:
wdenk4b9206e2004-03-23 22:14:11 +0000417 puts ("failed\n");
wdenk71f95112003-06-15 22:40:42 +0000418 return 1;
419 default:
420 printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
421 return 1;
422 }
423 puts ("done\n");
424 return 0;
425 }
426
427 if (mmc2info(addr)) {
428 int rc;
429
wdenk4b9206e2004-03-23 22:14:11 +0000430 puts ("Copy from MMC... ");
wdenk71f95112003-06-15 22:40:42 +0000431 switch (rc = mmc_read (addr, (uchar *)dest, count*size)) {
432 case 0:
wdenk4b9206e2004-03-23 22:14:11 +0000433 putc ('\n');
wdenk71f95112003-06-15 22:40:42 +0000434 return 1;
435 case -1:
wdenk4b9206e2004-03-23 22:14:11 +0000436 puts ("failed\n");
wdenk71f95112003-06-15 22:40:42 +0000437 return 1;
438 default:
439 printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
440 return 1;
441 }
442 puts ("done\n");
443 return 0;
444 }
445#endif
446
wdenk2abbe072003-06-16 23:50:08 +0000447#ifdef CONFIG_HAS_DATAFLASH
448 /* Check if we are copying from RAM or Flash to DataFlash */
449 if (addr_dataflash(dest) && !addr_dataflash(addr)){
450 int rc;
451
wdenk4b9206e2004-03-23 22:14:11 +0000452 puts ("Copy to DataFlash... ");
wdenk2abbe072003-06-16 23:50:08 +0000453
454 rc = write_dataflash (dest, addr, count*size);
455
456 if (rc != 1) {
457 dataflash_perror (rc);
458 return (1);
459 }
460 puts ("done\n");
461 return 0;
462 }
wdenk8bde7f72003-06-27 21:31:46 +0000463
wdenk2abbe072003-06-16 23:50:08 +0000464 /* Check if we are copying from DataFlash to RAM */
Stelian Pop880cc432008-03-26 22:52:35 +0100465 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200466#ifndef CONFIG_SYS_NO_FLASH
Stelian Pop880cc432008-03-26 22:52:35 +0100467 && (addr2info(dest) == NULL)
468#endif
469 ){
wdenk5779d8d2003-12-06 23:55:10 +0000470 int rc;
471 rc = read_dataflash(addr, count * size, (char *) dest);
472 if (rc != 1) {
wdenkd4ca31c2004-01-02 14:00:00 +0000473 dataflash_perror (rc);
474 return (1);
475 }
wdenk2abbe072003-06-16 23:50:08 +0000476 return 0;
477 }
478
479 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk4b9206e2004-03-23 22:14:11 +0000480 puts ("Unsupported combination of source/destination.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000481 return 1;
482 }
483#endif
484
Mike Frysinger4c727c72008-02-04 19:26:56 -0500485#ifdef CONFIG_BLACKFIN
486 /* See if we're copying to/from L1 inst */
487 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
488 memcpy((void *)dest, (void *)addr, count * size);
489 return 0;
490 }
491#endif
492
wdenk38635852002-08-27 05:55:31 +0000493 while (count-- > 0) {
494 if (size == 4)
495 *((ulong *)dest) = *((ulong *)addr);
496 else if (size == 2)
497 *((ushort *)dest) = *((ushort *)addr);
498 else
499 *((u_char *)dest) = *((u_char *)addr);
500 addr += size;
501 dest += size;
502 }
503 return 0;
504}
505
506int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
507{
508 if (argc > 1) {
509 /* Set new base address.
510 */
511 base_address = simple_strtoul(argv[1], NULL, 16);
512 }
513 /* Print the current base address.
514 */
515 printf("Base Address: 0x%08lx\n", base_address);
516 return 0;
517}
518
519int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
520{
wdenk27b207f2003-07-24 23:38:38 +0000521 ulong addr, length, i, junk;
522 int size;
wdenk38635852002-08-27 05:55:31 +0000523 volatile uint *longp;
524 volatile ushort *shortp;
525 volatile u_char *cp;
526
527 if (argc < 3) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600528 cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000529 return 1;
530 }
531
532 /* Check for a size spefication.
533 * Defaults to long if no or incorrect specification.
534 */
wdenk27b207f2003-07-24 23:38:38 +0000535 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
536 return 1;
wdenk38635852002-08-27 05:55:31 +0000537
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 /* 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 i = *longp;
554 }
555 if (size == 2) {
556 shortp = (ushort *)addr;
557 for (;;)
558 i = *shortp;
559 }
560 cp = (u_char *)addr;
561 for (;;)
562 i = *cp;
563 }
564
565 if (size == 4) {
566 for (;;) {
567 longp = (uint *)addr;
568 i = length;
569 while (i-- > 0)
570 junk = *longp++;
571 }
572 }
573 if (size == 2) {
574 for (;;) {
575 shortp = (ushort *)addr;
576 i = length;
577 while (i-- > 0)
578 junk = *shortp++;
579 }
580 }
581 for (;;) {
582 cp = (u_char *)addr;
583 i = length;
584 while (i-- > 0)
585 junk = *cp++;
586 }
587}
588
wdenk56523f12004-07-11 17:40:54 +0000589#ifdef CONFIG_LOOPW
590int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
591{
592 ulong addr, length, i, data;
593 int size;
594 volatile uint *longp;
595 volatile ushort *shortp;
596 volatile u_char *cp;
wdenk81050922004-07-11 20:04:51 +0000597
wdenk56523f12004-07-11 17:40:54 +0000598 if (argc < 4) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600599 cmd_usage(cmdtp);
wdenk56523f12004-07-11 17:40:54 +0000600 return 1;
601 }
602
603 /* Check for a size spefication.
604 * Defaults to long if no or incorrect specification.
605 */
606 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
607 return 1;
608
609 /* Address is always specified.
610 */
611 addr = simple_strtoul(argv[1], NULL, 16);
612
613 /* Length is the number of objects, not number of bytes.
614 */
615 length = simple_strtoul(argv[2], NULL, 16);
616
617 /* data to write */
618 data = simple_strtoul(argv[3], NULL, 16);
wdenk81050922004-07-11 20:04:51 +0000619
wdenk56523f12004-07-11 17:40:54 +0000620 /* We want to optimize the loops to run as fast as possible.
621 * If we have only one object, just run infinite loops.
622 */
623 if (length == 1) {
624 if (size == 4) {
625 longp = (uint *)addr;
626 for (;;)
627 *longp = data;
628 }
629 if (size == 2) {
630 shortp = (ushort *)addr;
631 for (;;)
632 *shortp = data;
633 }
634 cp = (u_char *)addr;
635 for (;;)
636 *cp = data;
637 }
638
639 if (size == 4) {
640 for (;;) {
641 longp = (uint *)addr;
642 i = length;
643 while (i-- > 0)
644 *longp++ = data;
645 }
646 }
647 if (size == 2) {
648 for (;;) {
649 shortp = (ushort *)addr;
650 i = length;
651 while (i-- > 0)
652 *shortp++ = data;
653 }
654 }
655 for (;;) {
656 cp = (u_char *)addr;
657 i = length;
658 while (i-- > 0)
659 *cp++ = data;
660 }
661}
662#endif /* CONFIG_LOOPW */
663
wdenk38635852002-08-27 05:55:31 +0000664/*
665 * Perform a memory test. A more complete alternative test can be
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200666 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
wdenk38635852002-08-27 05:55:31 +0000667 * interrupted by ctrl-c or by a failure of one of the sub-tests.
668 */
669int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
670{
671 vu_long *addr, *start, *end;
672 ulong val;
673 ulong readback;
Guennadi Liakhovetski1f780aa2008-02-13 11:19:19 +0100674 int rcode = 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100675 int iterations = 1;
676 int iteration_limit;
wdenk38635852002-08-27 05:55:31 +0000677
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200678#if defined(CONFIG_SYS_ALT_MEMTEST)
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100679 vu_long len;
wdenk38635852002-08-27 05:55:31 +0000680 vu_long offset;
681 vu_long test_offset;
682 vu_long pattern;
683 vu_long temp;
684 vu_long anti_pattern;
685 vu_long num_words;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200686#if defined(CONFIG_SYS_MEMTEST_SCRATCH)
687 vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH;
wdenk5f535fe2003-09-18 09:21:33 +0000688#else
Wolfgang Denk029b6dc2006-07-21 11:37:40 +0200689 vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
wdenk5f535fe2003-09-18 09:21:33 +0000690#endif
wdenk38635852002-08-27 05:55:31 +0000691 int j;
wdenk38635852002-08-27 05:55:31 +0000692
693 static const ulong bitpattern[] = {
694 0x00000001, /* single bit */
695 0x00000003, /* two adjacent bits */
696 0x00000007, /* three adjacent bits */
697 0x0000000F, /* four adjacent bits */
698 0x00000005, /* two non-adjacent bits */
699 0x00000015, /* three non-adjacent bits */
700 0x00000055, /* four non-adjacent bits */
701 0xaaaaaaaa, /* alternating 1/0 */
702 };
703#else
704 ulong incr;
705 ulong pattern;
wdenk38635852002-08-27 05:55:31 +0000706#endif
707
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100708 if (argc > 1)
wdenk38635852002-08-27 05:55:31 +0000709 start = (ulong *)simple_strtoul(argv[1], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100710 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200711 start = (ulong *)CONFIG_SYS_MEMTEST_START;
wdenk38635852002-08-27 05:55:31 +0000712
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100713 if (argc > 2)
wdenk38635852002-08-27 05:55:31 +0000714 end = (ulong *)simple_strtoul(argv[2], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100715 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200716 end = (ulong *)(CONFIG_SYS_MEMTEST_END);
wdenk38635852002-08-27 05:55:31 +0000717
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100718 if (argc > 3)
wdenk38635852002-08-27 05:55:31 +0000719 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100720 else
wdenk38635852002-08-27 05:55:31 +0000721 pattern = 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100722
723 if (argc > 4)
724 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
725 else
726 iteration_limit = 0;
wdenk38635852002-08-27 05:55:31 +0000727
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200728#if defined(CONFIG_SYS_ALT_MEMTEST)
wdenk38635852002-08-27 05:55:31 +0000729 printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
730 PRINTF("%s:%d: start 0x%p end 0x%p\n",
731 __FUNCTION__, __LINE__, start, end);
732
733 for (;;) {
734 if (ctrlc()) {
735 putc ('\n');
736 return 1;
737 }
738
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100739
740 if (iteration_limit && iterations > iteration_limit) {
741 printf("Tested %d iteration(s) without errors.\n",
742 iterations-1);
743 return 0;
744 }
745
wdenk38635852002-08-27 05:55:31 +0000746 printf("Iteration: %6d\r", iterations);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100747 PRINTF("\n");
wdenk38635852002-08-27 05:55:31 +0000748 iterations++;
749
750 /*
751 * Data line test: write a pattern to the first
752 * location, write the 1's complement to a 'parking'
753 * address (changes the state of the data bus so a
754 * floating bus doen't give a false OK), and then
755 * read the value back. Note that we read it back
756 * into a variable because the next time we read it,
757 * it might be right (been there, tough to explain to
758 * the quality guys why it prints a failure when the
759 * "is" and "should be" are obviously the same in the
760 * error message).
761 *
762 * Rather than exhaustively testing, we test some
763 * patterns by shifting '1' bits through a field of
764 * '0's and '0' bits through a field of '1's (i.e.
765 * pattern and ~pattern).
766 */
767 addr = start;
768 for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) {
769 val = bitpattern[j];
770 for(; val != 0; val <<= 1) {
771 *addr = val;
772 *dummy = ~val; /* clear the test data off of the bus */
773 readback = *addr;
774 if(readback != val) {
775 printf ("FAILURE (data line): "
776 "expected %08lx, actual %08lx\n",
777 val, readback);
778 }
779 *addr = ~val;
780 *dummy = val;
781 readback = *addr;
782 if(readback != ~val) {
783 printf ("FAILURE (data line): "
784 "Is %08lx, should be %08lx\n",
wdenke1599e82004-10-10 23:27:33 +0000785 readback, ~val);
wdenk38635852002-08-27 05:55:31 +0000786 }
787 }
788 }
789
790 /*
791 * Based on code whose Original Author and Copyright
792 * information follows: Copyright (c) 1998 by Michael
793 * Barr. This software is placed into the public
794 * domain and may be used for any purpose. However,
795 * this notice must not be changed or removed and no
796 * warranty is either expressed or implied by its
797 * publication or distribution.
798 */
799
800 /*
801 * Address line test
802 *
803 * Description: Test the address bus wiring in a
804 * memory region by performing a walking
805 * 1's test on the relevant bits of the
806 * address and checking for aliasing.
807 * This test will find single-bit
808 * address failures such as stuck -high,
809 * stuck-low, and shorted pins. The base
810 * address and size of the region are
811 * selected by the caller.
812 *
813 * Notes: For best results, the selected base
814 * address should have enough LSB 0's to
815 * guarantee single address bit changes.
816 * For example, to test a 64-Kbyte
817 * region, select a base address on a
818 * 64-Kbyte boundary. Also, select the
819 * region size as a power-of-two if at
820 * all possible.
821 *
822 * Returns: 0 if the test succeeds, 1 if the test fails.
wdenk38635852002-08-27 05:55:31 +0000823 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100824 len = ((ulong)end - (ulong)start)/sizeof(vu_long);
wdenk38635852002-08-27 05:55:31 +0000825 pattern = (vu_long) 0xaaaaaaaa;
826 anti_pattern = (vu_long) 0x55555555;
827
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100828 PRINTF("%s:%d: length = 0x%.8lx\n",
wdenk38635852002-08-27 05:55:31 +0000829 __FUNCTION__, __LINE__,
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100830 len);
wdenk38635852002-08-27 05:55:31 +0000831 /*
832 * Write the default pattern at each of the
833 * power-of-two offsets.
834 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100835 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000836 start[offset] = pattern;
837 }
838
839 /*
840 * Check for address bits stuck high.
841 */
842 test_offset = 0;
843 start[test_offset] = anti_pattern;
844
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100845 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000846 temp = start[offset];
847 if (temp != pattern) {
848 printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
849 " expected 0x%.8lx, actual 0x%.8lx\n",
850 (ulong)&start[offset], pattern, temp);
851 return 1;
852 }
853 }
854 start[test_offset] = pattern;
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200855 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000856
857 /*
858 * Check for addr bits stuck low or shorted.
859 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100860 for (test_offset = 1; test_offset < len; test_offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000861 start[test_offset] = anti_pattern;
862
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100863 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000864 temp = start[offset];
865 if ((temp != pattern) && (offset != test_offset)) {
866 printf ("\nFAILURE: Address bit stuck low or shorted @"
867 " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n",
868 (ulong)&start[offset], pattern, temp);
869 return 1;
870 }
871 }
872 start[test_offset] = pattern;
873 }
874
875 /*
876 * Description: Test the integrity of a physical
877 * memory device by performing an
878 * increment/decrement test over the
879 * entire region. In the process every
880 * storage bit in the device is tested
881 * as a zero and a one. The base address
882 * and the size of the region are
883 * selected by the caller.
884 *
885 * Returns: 0 if the test succeeds, 1 if the test fails.
886 */
887 num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1;
888
889 /*
890 * Fill memory with a known pattern.
891 */
892 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200893 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000894 start[offset] = pattern;
895 }
896
897 /*
898 * Check each location and invert it for the second pass.
899 */
900 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200901 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000902 temp = start[offset];
903 if (temp != pattern) {
904 printf ("\nFAILURE (read/write) @ 0x%.8lx:"
905 " expected 0x%.8lx, actual 0x%.8lx)\n",
906 (ulong)&start[offset], pattern, temp);
907 return 1;
908 }
909
910 anti_pattern = ~pattern;
911 start[offset] = anti_pattern;
912 }
913
914 /*
915 * Check each location for the inverted pattern and zero it.
916 */
917 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200918 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000919 anti_pattern = ~pattern;
920 temp = start[offset];
921 if (temp != anti_pattern) {
922 printf ("\nFAILURE (read/write): @ 0x%.8lx:"
923 " expected 0x%.8lx, actual 0x%.8lx)\n",
924 (ulong)&start[offset], anti_pattern, temp);
925 return 1;
926 }
927 start[offset] = 0;
928 }
929 }
930
931#else /* The original, quickie test */
932 incr = 1;
933 for (;;) {
934 if (ctrlc()) {
935 putc ('\n');
936 return 1;
937 }
938
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100939 if (iteration_limit && iterations > iteration_limit) {
940 printf("Tested %d iteration(s) without errors.\n",
941 iterations-1);
942 return 0;
943 }
944 ++iterations;
945
wdenk38635852002-08-27 05:55:31 +0000946 printf ("\rPattern %08lX Writing..."
947 "%12s"
948 "\b\b\b\b\b\b\b\b\b\b",
949 pattern, "");
950
951 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200952 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000953 *addr = val;
954 val += incr;
955 }
956
wdenk4b9206e2004-03-23 22:14:11 +0000957 puts ("Reading...");
wdenk38635852002-08-27 05:55:31 +0000958
959 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200960 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000961 readback = *addr;
962 if (readback != val) {
963 printf ("\nMem error @ 0x%08X: "
964 "found %08lX, expected %08lX\n",
965 (uint)addr, readback, val);
966 rcode = 1;
967 }
968 val += incr;
969 }
970
971 /*
972 * Flip the pattern each time to make lots of zeros and
973 * then, the next time, lots of ones. We decrement
974 * the "negative" patterns and increment the "positive"
975 * patterns to preserve this feature.
976 */
977 if(pattern & 0x80000000) {
978 pattern = -pattern; /* complement & increment */
979 }
980 else {
981 pattern = ~pattern;
982 }
983 incr = -incr;
984 }
wdenk38635852002-08-27 05:55:31 +0000985#endif
Guennadi Liakhovetski1f780aa2008-02-13 11:19:19 +0100986 return rcode;
wdenk38635852002-08-27 05:55:31 +0000987}
988
989
990/* Modify memory.
991 *
992 * Syntax:
993 * mm{.b, .w, .l} {addr}
994 * nm{.b, .w, .l} {addr}
995 */
996static int
997mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[])
998{
wdenk27b207f2003-07-24 23:38:38 +0000999 ulong addr, i;
1000 int nbytes, size;
wdenk38635852002-08-27 05:55:31 +00001001 extern char console_buffer[];
1002
1003 if (argc != 2) {
Peter Tyser62c3ae72009-01-27 18:03:10 -06001004 cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +00001005 return 1;
1006 }
1007
1008#ifdef CONFIG_BOOT_RETRY_TIME
1009 reset_cmd_timeout(); /* got a good command to get here */
1010#endif
1011 /* We use the last specified parameters, unless new ones are
1012 * entered.
1013 */
1014 addr = mm_last_addr;
1015 size = mm_last_size;
1016
1017 if ((flag & CMD_FLAG_REPEAT) == 0) {
1018 /* New command specified. Check for a size specification.
1019 * Defaults to long if no or incorrect specification.
1020 */
wdenk27b207f2003-07-24 23:38:38 +00001021 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1022 return 1;
wdenk38635852002-08-27 05:55:31 +00001023
1024 /* Address is specified since argc > 1
1025 */
1026 addr = simple_strtoul(argv[1], NULL, 16);
1027 addr += base_address;
1028 }
1029
wdenk2abbe072003-06-16 23:50:08 +00001030#ifdef CONFIG_HAS_DATAFLASH
1031 if (addr_dataflash(addr)){
wdenk4b9206e2004-03-23 22:14:11 +00001032 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk2abbe072003-06-16 23:50:08 +00001033 return 0;
1034 }
1035#endif
1036
Mike Frysinger4c727c72008-02-04 19:26:56 -05001037#ifdef CONFIG_BLACKFIN
1038 if (addr_bfin_on_chip_mem(addr)) {
1039 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1040 return 0;
1041 }
1042#endif
1043
wdenk38635852002-08-27 05:55:31 +00001044 /* Print the address, followed by value. Then accept input for
1045 * the next value. A non-converted value exits.
1046 */
1047 do {
1048 printf("%08lx:", addr);
1049 if (size == 4)
1050 printf(" %08x", *((uint *)addr));
1051 else if (size == 2)
1052 printf(" %04x", *((ushort *)addr));
1053 else
1054 printf(" %02x", *((u_char *)addr));
1055
1056 nbytes = readline (" ? ");
1057 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1058 /* <CR> pressed as only input, don't modify current
1059 * location and move to next. "-" pressed will go back.
1060 */
1061 if (incrflag)
1062 addr += nbytes ? -size : size;
1063 nbytes = 1;
1064#ifdef CONFIG_BOOT_RETRY_TIME
1065 reset_cmd_timeout(); /* good enough to not time out */
1066#endif
1067 }
1068#ifdef CONFIG_BOOT_RETRY_TIME
1069 else if (nbytes == -2) {
1070 break; /* timed out, exit the command */
1071 }
1072#endif
1073 else {
1074 char *endp;
1075 i = simple_strtoul(console_buffer, &endp, 16);
1076 nbytes = endp - console_buffer;
1077 if (nbytes) {
1078#ifdef CONFIG_BOOT_RETRY_TIME
1079 /* good enough to not time out
1080 */
1081 reset_cmd_timeout();
1082#endif
1083 if (size == 4)
1084 *((uint *)addr) = i;
1085 else if (size == 2)
1086 *((ushort *)addr) = i;
1087 else
1088 *((u_char *)addr) = i;
1089 if (incrflag)
1090 addr += size;
1091 }
1092 }
1093 } while (nbytes);
1094
1095 mm_last_addr = addr;
1096 mm_last_size = size;
1097 return 0;
1098}
1099
wdenkc26e4542004-04-18 10:13:26 +00001100#ifndef CONFIG_CRC32_VERIFY
1101
wdenk38635852002-08-27 05:55:31 +00001102int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1103{
wdenk71f95112003-06-15 22:40:42 +00001104 ulong addr, length;
1105 ulong crc;
1106 ulong *ptr;
wdenk38635852002-08-27 05:55:31 +00001107
1108 if (argc < 3) {
Peter Tyser62c3ae72009-01-27 18:03:10 -06001109 cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +00001110 return 1;
1111 }
1112
wdenk71f95112003-06-15 22:40:42 +00001113 addr = simple_strtoul (argv[1], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001114 addr += base_address;
1115
wdenk71f95112003-06-15 22:40:42 +00001116 length = simple_strtoul (argv[2], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001117
wdenk71f95112003-06-15 22:40:42 +00001118 crc = crc32 (0, (const uchar *) addr, length);
wdenk38635852002-08-27 05:55:31 +00001119
1120 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
wdenk71f95112003-06-15 22:40:42 +00001121 addr, addr + length - 1, crc);
wdenk38635852002-08-27 05:55:31 +00001122
wdenk71f95112003-06-15 22:40:42 +00001123 if (argc > 3) {
1124 ptr = (ulong *) simple_strtoul (argv[3], NULL, 16);
1125 *ptr = crc;
1126 }
wdenk38635852002-08-27 05:55:31 +00001127
1128 return 0;
1129}
1130
wdenkc26e4542004-04-18 10:13:26 +00001131#else /* CONFIG_CRC32_VERIFY */
1132
1133int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1134{
1135 ulong addr, length;
1136 ulong crc;
1137 ulong *ptr;
wdenk6e592382004-04-18 17:39:38 +00001138 ulong vcrc;
wdenkc26e4542004-04-18 10:13:26 +00001139 int verify;
1140 int ac;
1141 char **av;
1142
1143 if (argc < 3) {
1144 usage:
Peter Tyser62c3ae72009-01-27 18:03:10 -06001145 cmd_usage(cmdtp);
wdenkc26e4542004-04-18 10:13:26 +00001146 return 1;
1147 }
1148
1149 av = argv + 1;
1150 ac = argc - 1;
1151 if (strcmp(*av, "-v") == 0) {
1152 verify = 1;
1153 av++;
1154 ac--;
1155 if (ac < 3)
1156 goto usage;
1157 } else
1158 verify = 0;
1159
1160 addr = simple_strtoul(*av++, NULL, 16);
1161 addr += base_address;
1162 length = simple_strtoul(*av++, NULL, 16);
1163
1164 crc = crc32(0, (const uchar *) addr, length);
1165
1166 if (!verify) {
1167 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
1168 addr, addr + length - 1, crc);
1169 if (ac > 2) {
1170 ptr = (ulong *) simple_strtoul (*av++, NULL, 16);
1171 *ptr = crc;
1172 }
1173 } else {
1174 vcrc = simple_strtoul(*av++, NULL, 16);
1175 if (vcrc != crc) {
1176 printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n",
1177 addr, addr + length - 1, crc, vcrc);
1178 return 1;
1179 }
1180 }
1181
1182 return 0;
1183
1184}
1185#endif /* CONFIG_CRC32_VERIFY */
1186
Harald Weltefe2ce552008-07-06 15:56:38 +08001187
1188#ifdef CONFIG_CMD_UNZIP
1189int gunzip (void *, int, unsigned char *, unsigned long *);
1190
1191int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1192{
1193 unsigned long src, dst;
1194 unsigned long src_len = ~0UL, dst_len = ~0UL;
Harald Weltefe2ce552008-07-06 15:56:38 +08001195
1196 switch (argc) {
1197 case 4:
1198 dst_len = simple_strtoul(argv[3], NULL, 16);
1199 /* fall through */
1200 case 3:
1201 src = simple_strtoul(argv[1], NULL, 16);
1202 dst = simple_strtoul(argv[2], NULL, 16);
1203 break;
1204 default:
Peter Tyser62c3ae72009-01-27 18:03:10 -06001205 cmd_usage(cmdtp);
Harald Weltefe2ce552008-07-06 15:56:38 +08001206 return 1;
1207 }
1208
1209 return !!gunzip((void *) dst, dst_len, (void *) src, &src_len);
1210}
1211#endif /* CONFIG_CMD_UNZIP */
1212
1213
wdenk8bde7f72003-06-27 21:31:46 +00001214/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001215U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001216 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001217 "memory display",
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001218 "[.b, .w, .l] address [# of objects]\n - memory display\n"
wdenk8bde7f72003-06-27 21:31:46 +00001219);
1220
1221
wdenk0d498392003-07-01 21:06:45 +00001222U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001223 mm, 2, 1, do_mem_mm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001224 "memory modify (auto-incrementing)",
wdenk8bde7f72003-06-27 21:31:46 +00001225 "[.b, .w, .l] address\n" " - memory modify, auto increment address\n"
1226);
1227
1228
wdenk0d498392003-07-01 21:06:45 +00001229U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001230 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001231 "memory modify (constant address)",
wdenk8bde7f72003-06-27 21:31:46 +00001232 "[.b, .w, .l] address\n - memory modify, read and keep address\n"
1233);
1234
wdenk0d498392003-07-01 21:06:45 +00001235U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001236 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001237 "memory write (fill)",
Wolfgang Denk19f10142008-08-26 13:14:34 +02001238 "[.b, .w, .l] address value [count]\n - write memory\n"
wdenk8bde7f72003-06-27 21:31:46 +00001239);
1240
wdenk0d498392003-07-01 21:06:45 +00001241U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001242 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001243 "memory copy",
wdenk8bde7f72003-06-27 21:31:46 +00001244 "[.b, .w, .l] source target count\n - copy memory\n"
1245);
1246
wdenk0d498392003-07-01 21:06:45 +00001247U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001248 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001249 "memory compare",
wdenk8bde7f72003-06-27 21:31:46 +00001250 "[.b, .w, .l] addr1 addr2 count\n - compare memory\n"
1251);
1252
wdenkc26e4542004-04-18 10:13:26 +00001253#ifndef CONFIG_CRC32_VERIFY
1254
wdenk0d498392003-07-01 21:06:45 +00001255U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001256 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001257 "checksum calculation",
wdenk8bde7f72003-06-27 21:31:46 +00001258 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
1259);
1260
wdenkc26e4542004-04-18 10:13:26 +00001261#else /* CONFIG_CRC32_VERIFY */
1262
1263U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001264 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001265 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001266 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
1267 "-v address count crc\n - verify crc of memory area\n"
1268);
1269
1270#endif /* CONFIG_CRC32_VERIFY */
1271
wdenk0d498392003-07-01 21:06:45 +00001272U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001273 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001274 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001275 "\n - print address offset for memory commands\n"
1276 "base off\n - set address offset for memory commands to 'off'\n"
1277);
1278
wdenk0d498392003-07-01 21:06:45 +00001279U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001280 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001281 "infinite loop on address range",
wdenk8bde7f72003-06-27 21:31:46 +00001282 "[.b, .w, .l] address number_of_objects\n"
1283 " - loop on a set of addresses\n"
1284);
1285
wdenk56523f12004-07-11 17:40:54 +00001286#ifdef CONFIG_LOOPW
1287U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001288 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001289 "infinite write loop on address range",
wdenk56523f12004-07-11 17:40:54 +00001290 "[.b, .w, .l] address number_of_objects data_to_write\n"
1291 " - loop on a set of addresses\n"
1292);
1293#endif /* CONFIG_LOOPW */
1294
wdenk0d498392003-07-01 21:06:45 +00001295U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001296 mtest, 5, 1, do_mem_mtest,
Peter Tyser2fb26042009-01-27 18:03:12 -06001297 "simple RAM test",
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001298 "[start [end [pattern [iterations]]]]\n"
wdenk8bde7f72003-06-27 21:31:46 +00001299 " - simple RAM read/write test\n"
1300);
1301
stroese4aaf29b2004-12-16 17:42:39 +00001302#ifdef CONFIG_MX_CYCLIC
1303U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001304 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001305 "memory display cyclic",
stroese4aaf29b2004-12-16 17:42:39 +00001306 "[.b, .w, .l] address count delay(ms)\n - memory display cyclic\n"
1307);
1308
1309U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001310 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001311 "memory write cyclic",
stroese4aaf29b2004-12-16 17:42:39 +00001312 "[.b, .w, .l] address value delay(ms)\n - memory write cyclic\n"
1313);
1314#endif /* CONFIG_MX_CYCLIC */
1315
Harald Weltefe2ce552008-07-06 15:56:38 +08001316#ifdef CONFIG_CMD_UNZIP
1317U_BOOT_CMD(
1318 unzip, 4, 1, do_unzip,
Peter Tyser2fb26042009-01-27 18:03:12 -06001319 "unzip a memory region",
Harald Weltefe2ce552008-07-06 15:56:38 +08001320 "srcaddr dstaddr [dstsize]\n"
1321);
1322#endif /* CONFIG_CMD_UNZIP */