blob: 4b524cfc160396e7b64bc5424cbc4c525dfe8760 [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
Robin Getz02c9aa12009-07-27 00:07:59 -040037#include <u-boot/md5.h>
38#include <sha1.h>
39
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
Wolfgang Denk54841ab2010-06-28 22:00:46 +020046static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000047
48/* Display values from last command.
49 * Memory modify remembered values are different from display memory.
50 */
Mike Frysingerd6efe242010-12-22 09:40:29 -050051static uint dp_last_addr, dp_last_size;
52static uint dp_last_length = 0x40;
53static uint mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000054
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
Wolfgang Denk54841ab2010-06-28 22:00:46 +020063int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000064{
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
Wolfgang Denk47e26b12010-07-17 01:06:04 +020079 if (argc < 2)
80 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +000081
82 if ((flag & CMD_FLAG_REPEAT) == 0) {
83 /* New command specified. Check for a size specification.
84 * Defaults to long if no or incorrect specification.
85 */
wdenk27b207f2003-07-24 23:38:38 +000086 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
87 return 1;
wdenk38635852002-08-27 05:55:31 +000088
89 /* Address is specified since argc > 1
90 */
91 addr = simple_strtoul(argv[1], NULL, 16);
92 addr += base_address;
93
94 /* If another parameter, it is the length to display.
95 * Length is the number of objects, not number of bytes.
96 */
97 if (argc > 2)
98 length = simple_strtoul(argv[2], NULL, 16);
99 }
100
Grant Likelyc95c4282007-02-20 09:05:00 +0100101#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +0000102 /* Print the lines.
103 *
104 * We buffer all read data, so we can make sure data is read only
105 * once, and all accesses are with the specified bus width.
106 */
107 nbytes = length * size;
108 do {
109 char linebuf[DISP_LINE_LEN];
Grant Likelyc95c4282007-02-20 09:05:00 +0100110 void* p;
wdenk38635852002-08-27 05:55:31 +0000111 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk2abbe072003-06-16 23:50:08 +0000112
Grant Likelyc95c4282007-02-20 09:05:00 +0100113 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
114 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
115 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk8bde7f72003-06-27 21:31:46 +0000116
wdenk38635852002-08-27 05:55:31 +0000117 nbytes -= linebytes;
Grant Likelyc95c4282007-02-20 09:05:00 +0100118 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000119 if (ctrlc()) {
120 rc = 1;
121 break;
122 }
123 } while (nbytes > 0);
Grant Likelyc95c4282007-02-20 09:05:00 +0100124#else
Mike Frysinger4c727c72008-02-04 19:26:56 -0500125
126# if defined(CONFIG_BLACKFIN)
127 /* See if we're trying to display L1 inst */
128 if (addr_bfin_on_chip_mem(addr)) {
129 char linebuf[DISP_LINE_LEN];
130 ulong linebytes, nbytes = length * size;
131 do {
132 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
133 memcpy(linebuf, (void *)addr, linebytes);
134 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
135
136 nbytes -= linebytes;
137 addr += linebytes;
138 if (ctrlc()) {
139 rc = 1;
140 break;
141 }
142 } while (nbytes > 0);
143 } else
144# endif
145
146 {
147 /* Print the lines. */
148 print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
149 addr += size*length;
150 }
Grant Likelyc95c4282007-02-20 09:05:00 +0100151#endif
wdenk38635852002-08-27 05:55:31 +0000152
153 dp_last_addr = addr;
154 dp_last_length = length;
155 dp_last_size = size;
156 return (rc);
157}
158
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200159int do_mem_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000160{
161 return mod_mem (cmdtp, 1, flag, argc, argv);
162}
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200163int do_mem_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000164{
165 return mod_mem (cmdtp, 0, flag, argc, argv);
166}
167
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200168int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000169{
wdenk27b207f2003-07-24 23:38:38 +0000170 ulong addr, writeval, count;
171 int size;
wdenk38635852002-08-27 05:55:31 +0000172
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200173 if ((argc < 3) || (argc > 4))
174 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000175
176 /* Check for size specification.
177 */
wdenk27b207f2003-07-24 23:38:38 +0000178 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
179 return 1;
wdenk38635852002-08-27 05:55:31 +0000180
181 /* Address is specified since argc > 1
182 */
183 addr = simple_strtoul(argv[1], NULL, 16);
184 addr += base_address;
185
186 /* Get the value to write.
187 */
188 writeval = simple_strtoul(argv[2], NULL, 16);
189
190 /* Count ? */
191 if (argc == 4) {
192 count = simple_strtoul(argv[3], NULL, 16);
193 } else {
194 count = 1;
195 }
196
197 while (count-- > 0) {
198 if (size == 4)
199 *((ulong *)addr) = (ulong )writeval;
200 else if (size == 2)
201 *((ushort *)addr) = (ushort)writeval;
202 else
203 *((u_char *)addr) = (u_char)writeval;
204 addr += size;
205 }
206 return 0;
207}
208
stroese4aaf29b2004-12-16 17:42:39 +0000209#ifdef CONFIG_MX_CYCLIC
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200210int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000211{
212 int i;
213 ulong count;
214
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200215 if (argc < 4)
216 return cmd_usage(cmdtp);
stroese4aaf29b2004-12-16 17:42:39 +0000217
218 count = simple_strtoul(argv[3], NULL, 10);
219
220 for (;;) {
221 do_mem_md (NULL, 0, 3, argv);
222
223 /* delay for <count> ms... */
224 for (i=0; i<count; i++)
225 udelay (1000);
226
227 /* check for ctrl-c to abort... */
228 if (ctrlc()) {
229 puts("Abort\n");
230 return 0;
231 }
232 }
233
234 return 0;
235}
236
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200237int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000238{
239 int i;
240 ulong count;
241
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200242 if (argc < 4)
243 return cmd_usage(cmdtp);
stroese4aaf29b2004-12-16 17:42:39 +0000244
245 count = simple_strtoul(argv[3], NULL, 10);
246
247 for (;;) {
248 do_mem_mw (NULL, 0, 3, argv);
249
250 /* delay for <count> ms... */
251 for (i=0; i<count; i++)
252 udelay (1000);
253
254 /* check for ctrl-c to abort... */
255 if (ctrlc()) {
256 puts("Abort\n");
257 return 0;
258 }
259 }
260
261 return 0;
262}
263#endif /* CONFIG_MX_CYCLIC */
264
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200265int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000266{
wdenk27b207f2003-07-24 23:38:38 +0000267 ulong addr1, addr2, count, ngood;
268 int size;
wdenk38635852002-08-27 05:55:31 +0000269 int rcode = 0;
270
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200271 if (argc != 4)
272 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000273
274 /* Check for size specification.
275 */
wdenk27b207f2003-07-24 23:38:38 +0000276 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
277 return 1;
wdenk38635852002-08-27 05:55:31 +0000278
279 addr1 = simple_strtoul(argv[1], NULL, 16);
280 addr1 += base_address;
281
282 addr2 = simple_strtoul(argv[2], NULL, 16);
283 addr2 += base_address;
284
285 count = simple_strtoul(argv[3], NULL, 16);
286
wdenk2abbe072003-06-16 23:50:08 +0000287#ifdef CONFIG_HAS_DATAFLASH
288 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk4b9206e2004-03-23 22:14:11 +0000289 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000290 return 0;
291 }
292#endif
293
Mike Frysinger4c727c72008-02-04 19:26:56 -0500294#ifdef CONFIG_BLACKFIN
295 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
296 puts ("Comparison with L1 instruction memory not supported.\n\r");
297 return 0;
298 }
299#endif
300
wdenk38635852002-08-27 05:55:31 +0000301 ngood = 0;
302
303 while (count-- > 0) {
304 if (size == 4) {
305 ulong word1 = *(ulong *)addr1;
306 ulong word2 = *(ulong *)addr2;
307 if (word1 != word2) {
308 printf("word at 0x%08lx (0x%08lx) "
309 "!= word at 0x%08lx (0x%08lx)\n",
310 addr1, word1, addr2, word2);
311 rcode = 1;
312 break;
313 }
314 }
315 else if (size == 2) {
316 ushort hword1 = *(ushort *)addr1;
317 ushort hword2 = *(ushort *)addr2;
318 if (hword1 != hword2) {
319 printf("halfword at 0x%08lx (0x%04x) "
320 "!= halfword at 0x%08lx (0x%04x)\n",
321 addr1, hword1, addr2, hword2);
322 rcode = 1;
323 break;
324 }
325 }
326 else {
327 u_char byte1 = *(u_char *)addr1;
328 u_char byte2 = *(u_char *)addr2;
329 if (byte1 != byte2) {
330 printf("byte at 0x%08lx (0x%02x) "
331 "!= byte at 0x%08lx (0x%02x)\n",
332 addr1, byte1, addr2, byte2);
333 rcode = 1;
334 break;
335 }
336 }
337 ngood++;
338 addr1 += size;
339 addr2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200340
341 /* reset watchdog from time to time */
342 if ((count % (64 << 10)) == 0)
343 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000344 }
345
346 printf("Total of %ld %s%s were the same\n",
347 ngood, size == 4 ? "word" : size == 2 ? "halfword" : "byte",
348 ngood == 1 ? "" : "s");
349 return rcode;
350}
351
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200352int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000353{
wdenk27b207f2003-07-24 23:38:38 +0000354 ulong addr, dest, count;
355 int size;
wdenk38635852002-08-27 05:55:31 +0000356
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200357 if (argc != 4)
358 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000359
360 /* Check for size specification.
361 */
wdenk27b207f2003-07-24 23:38:38 +0000362 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
363 return 1;
wdenk38635852002-08-27 05:55:31 +0000364
365 addr = simple_strtoul(argv[1], NULL, 16);
366 addr += base_address;
367
368 dest = simple_strtoul(argv[2], NULL, 16);
369 dest += base_address;
370
371 count = simple_strtoul(argv[3], NULL, 16);
372
373 if (count == 0) {
374 puts ("Zero length ???\n");
375 return 1;
376 }
377
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200378#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000379 /* check if we are copying to Flash */
wdenk2abbe072003-06-16 23:50:08 +0000380 if ( (addr2info(dest) != NULL)
381#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino84d0c2f2008-03-03 10:39:13 +0200382 && (!addr_dataflash(dest))
wdenk2abbe072003-06-16 23:50:08 +0000383#endif
384 ) {
wdenk38635852002-08-27 05:55:31 +0000385 int rc;
386
wdenk4b9206e2004-03-23 22:14:11 +0000387 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000388
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200389 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000390 if (rc != 0) {
391 flash_perror (rc);
392 return (1);
393 }
394 puts ("done\n");
395 return 0;
396 }
397#endif
398
wdenk2abbe072003-06-16 23:50:08 +0000399#ifdef CONFIG_HAS_DATAFLASH
400 /* Check if we are copying from RAM or Flash to DataFlash */
401 if (addr_dataflash(dest) && !addr_dataflash(addr)){
402 int rc;
403
wdenk4b9206e2004-03-23 22:14:11 +0000404 puts ("Copy to DataFlash... ");
wdenk2abbe072003-06-16 23:50:08 +0000405
406 rc = write_dataflash (dest, addr, count*size);
407
408 if (rc != 1) {
409 dataflash_perror (rc);
410 return (1);
411 }
412 puts ("done\n");
413 return 0;
414 }
wdenk8bde7f72003-06-27 21:31:46 +0000415
wdenk2abbe072003-06-16 23:50:08 +0000416 /* Check if we are copying from DataFlash to RAM */
Stelian Pop880cc432008-03-26 22:52:35 +0100417 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200418#ifndef CONFIG_SYS_NO_FLASH
Stelian Pop880cc432008-03-26 22:52:35 +0100419 && (addr2info(dest) == NULL)
420#endif
421 ){
wdenk5779d8d2003-12-06 23:55:10 +0000422 int rc;
423 rc = read_dataflash(addr, count * size, (char *) dest);
424 if (rc != 1) {
wdenkd4ca31c2004-01-02 14:00:00 +0000425 dataflash_perror (rc);
426 return (1);
427 }
wdenk2abbe072003-06-16 23:50:08 +0000428 return 0;
429 }
430
431 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk4b9206e2004-03-23 22:14:11 +0000432 puts ("Unsupported combination of source/destination.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000433 return 1;
434 }
435#endif
436
Mike Frysinger4c727c72008-02-04 19:26:56 -0500437#ifdef CONFIG_BLACKFIN
438 /* See if we're copying to/from L1 inst */
439 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
440 memcpy((void *)dest, (void *)addr, count * size);
441 return 0;
442 }
443#endif
444
wdenk38635852002-08-27 05:55:31 +0000445 while (count-- > 0) {
446 if (size == 4)
447 *((ulong *)dest) = *((ulong *)addr);
448 else if (size == 2)
449 *((ushort *)dest) = *((ushort *)addr);
450 else
451 *((u_char *)dest) = *((u_char *)addr);
452 addr += size;
453 dest += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200454
455 /* reset watchdog from time to time */
456 if ((count % (64 << 10)) == 0)
457 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000458 }
459 return 0;
460}
461
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200462int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000463{
464 if (argc > 1) {
465 /* Set new base address.
466 */
467 base_address = simple_strtoul(argv[1], NULL, 16);
468 }
469 /* Print the current base address.
470 */
471 printf("Base Address: 0x%08lx\n", base_address);
472 return 0;
473}
474
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200475int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000476{
wdenk27b207f2003-07-24 23:38:38 +0000477 ulong addr, length, i, junk;
478 int size;
wdenk38635852002-08-27 05:55:31 +0000479 volatile uint *longp;
480 volatile ushort *shortp;
481 volatile u_char *cp;
482
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200483 if (argc < 3)
484 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000485
486 /* Check for a size spefication.
487 * Defaults to long if no or incorrect specification.
488 */
wdenk27b207f2003-07-24 23:38:38 +0000489 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
490 return 1;
wdenk38635852002-08-27 05:55:31 +0000491
492 /* Address is always specified.
493 */
494 addr = simple_strtoul(argv[1], NULL, 16);
495
496 /* Length is the number of objects, not number of bytes.
497 */
498 length = simple_strtoul(argv[2], NULL, 16);
499
500 /* We want to optimize the loops to run as fast as possible.
501 * If we have only one object, just run infinite loops.
502 */
503 if (length == 1) {
504 if (size == 4) {
505 longp = (uint *)addr;
506 for (;;)
507 i = *longp;
508 }
509 if (size == 2) {
510 shortp = (ushort *)addr;
511 for (;;)
512 i = *shortp;
513 }
514 cp = (u_char *)addr;
515 for (;;)
516 i = *cp;
517 }
518
519 if (size == 4) {
520 for (;;) {
521 longp = (uint *)addr;
522 i = length;
523 while (i-- > 0)
524 junk = *longp++;
525 }
526 }
527 if (size == 2) {
528 for (;;) {
529 shortp = (ushort *)addr;
530 i = length;
531 while (i-- > 0)
532 junk = *shortp++;
533 }
534 }
535 for (;;) {
536 cp = (u_char *)addr;
537 i = length;
538 while (i-- > 0)
539 junk = *cp++;
540 }
541}
542
wdenk56523f12004-07-11 17:40:54 +0000543#ifdef CONFIG_LOOPW
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200544int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk56523f12004-07-11 17:40:54 +0000545{
546 ulong addr, length, i, data;
547 int size;
548 volatile uint *longp;
549 volatile ushort *shortp;
550 volatile u_char *cp;
wdenk81050922004-07-11 20:04:51 +0000551
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200552 if (argc < 4)
553 return cmd_usage(cmdtp);
wdenk56523f12004-07-11 17:40:54 +0000554
555 /* Check for a size spefication.
556 * Defaults to long if no or incorrect specification.
557 */
558 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
559 return 1;
560
561 /* Address is always specified.
562 */
563 addr = simple_strtoul(argv[1], NULL, 16);
564
565 /* Length is the number of objects, not number of bytes.
566 */
567 length = simple_strtoul(argv[2], NULL, 16);
568
569 /* data to write */
570 data = simple_strtoul(argv[3], NULL, 16);
wdenk81050922004-07-11 20:04:51 +0000571
wdenk56523f12004-07-11 17:40:54 +0000572 /* We want to optimize the loops to run as fast as possible.
573 * If we have only one object, just run infinite loops.
574 */
575 if (length == 1) {
576 if (size == 4) {
577 longp = (uint *)addr;
578 for (;;)
579 *longp = data;
580 }
581 if (size == 2) {
582 shortp = (ushort *)addr;
583 for (;;)
584 *shortp = data;
585 }
586 cp = (u_char *)addr;
587 for (;;)
588 *cp = data;
589 }
590
591 if (size == 4) {
592 for (;;) {
593 longp = (uint *)addr;
594 i = length;
595 while (i-- > 0)
596 *longp++ = data;
597 }
598 }
599 if (size == 2) {
600 for (;;) {
601 shortp = (ushort *)addr;
602 i = length;
603 while (i-- > 0)
604 *shortp++ = data;
605 }
606 }
607 for (;;) {
608 cp = (u_char *)addr;
609 i = length;
610 while (i-- > 0)
611 *cp++ = data;
612 }
613}
614#endif /* CONFIG_LOOPW */
615
wdenk38635852002-08-27 05:55:31 +0000616/*
617 * Perform a memory test. A more complete alternative test can be
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200618 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
wdenk38635852002-08-27 05:55:31 +0000619 * interrupted by ctrl-c or by a failure of one of the sub-tests.
620 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200621int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000622{
623 vu_long *addr, *start, *end;
624 ulong val;
625 ulong readback;
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400626 ulong errs = 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100627 int iterations = 1;
628 int iteration_limit;
wdenk38635852002-08-27 05:55:31 +0000629
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200630#if defined(CONFIG_SYS_ALT_MEMTEST)
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100631 vu_long len;
wdenk38635852002-08-27 05:55:31 +0000632 vu_long offset;
633 vu_long test_offset;
634 vu_long pattern;
635 vu_long temp;
636 vu_long anti_pattern;
637 vu_long num_words;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200638#if defined(CONFIG_SYS_MEMTEST_SCRATCH)
639 vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH;
wdenk5f535fe2003-09-18 09:21:33 +0000640#else
Wolfgang Denk029b6dc2006-07-21 11:37:40 +0200641 vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
wdenk5f535fe2003-09-18 09:21:33 +0000642#endif
wdenk38635852002-08-27 05:55:31 +0000643 int j;
wdenk38635852002-08-27 05:55:31 +0000644
645 static const ulong bitpattern[] = {
646 0x00000001, /* single bit */
647 0x00000003, /* two adjacent bits */
648 0x00000007, /* three adjacent bits */
649 0x0000000F, /* four adjacent bits */
650 0x00000005, /* two non-adjacent bits */
651 0x00000015, /* three non-adjacent bits */
652 0x00000055, /* four non-adjacent bits */
653 0xaaaaaaaa, /* alternating 1/0 */
654 };
655#else
656 ulong incr;
657 ulong pattern;
wdenk38635852002-08-27 05:55:31 +0000658#endif
659
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100660 if (argc > 1)
wdenk38635852002-08-27 05:55:31 +0000661 start = (ulong *)simple_strtoul(argv[1], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100662 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200663 start = (ulong *)CONFIG_SYS_MEMTEST_START;
wdenk38635852002-08-27 05:55:31 +0000664
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100665 if (argc > 2)
wdenk38635852002-08-27 05:55:31 +0000666 end = (ulong *)simple_strtoul(argv[2], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100667 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200668 end = (ulong *)(CONFIG_SYS_MEMTEST_END);
wdenk38635852002-08-27 05:55:31 +0000669
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100670 if (argc > 3)
wdenk38635852002-08-27 05:55:31 +0000671 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100672 else
wdenk38635852002-08-27 05:55:31 +0000673 pattern = 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100674
675 if (argc > 4)
676 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
677 else
678 iteration_limit = 0;
wdenk38635852002-08-27 05:55:31 +0000679
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200680#if defined(CONFIG_SYS_ALT_MEMTEST)
wdenk38635852002-08-27 05:55:31 +0000681 printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
682 PRINTF("%s:%d: start 0x%p end 0x%p\n",
683 __FUNCTION__, __LINE__, start, end);
684
685 for (;;) {
686 if (ctrlc()) {
687 putc ('\n');
688 return 1;
689 }
690
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100691
692 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400693 printf("Tested %d iteration(s) with %lu errors.\n",
694 iterations-1, errs);
695 return errs != 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100696 }
697
wdenk38635852002-08-27 05:55:31 +0000698 printf("Iteration: %6d\r", iterations);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100699 PRINTF("\n");
wdenk38635852002-08-27 05:55:31 +0000700 iterations++;
701
702 /*
703 * Data line test: write a pattern to the first
704 * location, write the 1's complement to a 'parking'
705 * address (changes the state of the data bus so a
706 * floating bus doen't give a false OK), and then
707 * read the value back. Note that we read it back
708 * into a variable because the next time we read it,
709 * it might be right (been there, tough to explain to
710 * the quality guys why it prints a failure when the
711 * "is" and "should be" are obviously the same in the
712 * error message).
713 *
714 * Rather than exhaustively testing, we test some
715 * patterns by shifting '1' bits through a field of
716 * '0's and '0' bits through a field of '1's (i.e.
717 * pattern and ~pattern).
718 */
719 addr = start;
720 for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) {
721 val = bitpattern[j];
722 for(; val != 0; val <<= 1) {
723 *addr = val;
724 *dummy = ~val; /* clear the test data off of the bus */
725 readback = *addr;
726 if(readback != val) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400727 printf ("FAILURE (data line): "
wdenk38635852002-08-27 05:55:31 +0000728 "expected %08lx, actual %08lx\n",
729 val, readback);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400730 errs++;
731 if (ctrlc()) {
732 putc ('\n');
733 return 1;
734 }
wdenk38635852002-08-27 05:55:31 +0000735 }
736 *addr = ~val;
737 *dummy = val;
738 readback = *addr;
739 if(readback != ~val) {
740 printf ("FAILURE (data line): "
741 "Is %08lx, should be %08lx\n",
wdenke1599e82004-10-10 23:27:33 +0000742 readback, ~val);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400743 errs++;
744 if (ctrlc()) {
745 putc ('\n');
746 return 1;
747 }
wdenk38635852002-08-27 05:55:31 +0000748 }
749 }
750 }
751
752 /*
753 * Based on code whose Original Author and Copyright
754 * information follows: Copyright (c) 1998 by Michael
755 * Barr. This software is placed into the public
756 * domain and may be used for any purpose. However,
757 * this notice must not be changed or removed and no
758 * warranty is either expressed or implied by its
759 * publication or distribution.
760 */
761
762 /*
763 * Address line test
764 *
765 * Description: Test the address bus wiring in a
766 * memory region by performing a walking
767 * 1's test on the relevant bits of the
768 * address and checking for aliasing.
769 * This test will find single-bit
770 * address failures such as stuck -high,
771 * stuck-low, and shorted pins. The base
772 * address and size of the region are
773 * selected by the caller.
774 *
775 * Notes: For best results, the selected base
776 * address should have enough LSB 0's to
777 * guarantee single address bit changes.
778 * For example, to test a 64-Kbyte
779 * region, select a base address on a
780 * 64-Kbyte boundary. Also, select the
781 * region size as a power-of-two if at
782 * all possible.
783 *
784 * Returns: 0 if the test succeeds, 1 if the test fails.
wdenk38635852002-08-27 05:55:31 +0000785 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100786 len = ((ulong)end - (ulong)start)/sizeof(vu_long);
wdenk38635852002-08-27 05:55:31 +0000787 pattern = (vu_long) 0xaaaaaaaa;
788 anti_pattern = (vu_long) 0x55555555;
789
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100790 PRINTF("%s:%d: length = 0x%.8lx\n",
wdenk38635852002-08-27 05:55:31 +0000791 __FUNCTION__, __LINE__,
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100792 len);
wdenk38635852002-08-27 05:55:31 +0000793 /*
794 * Write the default pattern at each of the
795 * power-of-two offsets.
796 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100797 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000798 start[offset] = pattern;
799 }
800
801 /*
802 * Check for address bits stuck high.
803 */
804 test_offset = 0;
805 start[test_offset] = anti_pattern;
806
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100807 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000808 temp = start[offset];
809 if (temp != pattern) {
810 printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
811 " expected 0x%.8lx, actual 0x%.8lx\n",
812 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400813 errs++;
814 if (ctrlc()) {
815 putc ('\n');
816 return 1;
817 }
wdenk38635852002-08-27 05:55:31 +0000818 }
819 }
820 start[test_offset] = pattern;
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200821 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000822
823 /*
824 * Check for addr bits stuck low or shorted.
825 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100826 for (test_offset = 1; test_offset < len; test_offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000827 start[test_offset] = anti_pattern;
828
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100829 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000830 temp = start[offset];
831 if ((temp != pattern) && (offset != test_offset)) {
832 printf ("\nFAILURE: Address bit stuck low or shorted @"
833 " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n",
834 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400835 errs++;
836 if (ctrlc()) {
837 putc ('\n');
838 return 1;
839 }
wdenk38635852002-08-27 05:55:31 +0000840 }
841 }
842 start[test_offset] = pattern;
843 }
844
845 /*
846 * Description: Test the integrity of a physical
847 * memory device by performing an
848 * increment/decrement test over the
849 * entire region. In the process every
850 * storage bit in the device is tested
851 * as a zero and a one. The base address
852 * and the size of the region are
853 * selected by the caller.
854 *
855 * Returns: 0 if the test succeeds, 1 if the test fails.
856 */
857 num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1;
858
859 /*
860 * Fill memory with a known pattern.
861 */
862 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200863 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000864 start[offset] = pattern;
865 }
866
867 /*
868 * Check each location and invert it for the second pass.
869 */
870 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200871 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000872 temp = start[offset];
873 if (temp != pattern) {
874 printf ("\nFAILURE (read/write) @ 0x%.8lx:"
875 " expected 0x%.8lx, actual 0x%.8lx)\n",
876 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400877 errs++;
878 if (ctrlc()) {
879 putc ('\n');
880 return 1;
881 }
wdenk38635852002-08-27 05:55:31 +0000882 }
883
884 anti_pattern = ~pattern;
885 start[offset] = anti_pattern;
886 }
887
888 /*
889 * Check each location for the inverted pattern and zero it.
890 */
891 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200892 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000893 anti_pattern = ~pattern;
894 temp = start[offset];
895 if (temp != anti_pattern) {
896 printf ("\nFAILURE (read/write): @ 0x%.8lx:"
897 " expected 0x%.8lx, actual 0x%.8lx)\n",
898 (ulong)&start[offset], anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400899 errs++;
900 if (ctrlc()) {
901 putc ('\n');
902 return 1;
903 }
wdenk38635852002-08-27 05:55:31 +0000904 }
905 start[offset] = 0;
906 }
907 }
908
909#else /* The original, quickie test */
910 incr = 1;
911 for (;;) {
912 if (ctrlc()) {
913 putc ('\n');
914 return 1;
915 }
916
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100917 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400918 printf("Tested %d iteration(s) with %lu errors.\n",
919 iterations-1, errs);
920 return errs != 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100921 }
922 ++iterations;
923
wdenk38635852002-08-27 05:55:31 +0000924 printf ("\rPattern %08lX Writing..."
925 "%12s"
926 "\b\b\b\b\b\b\b\b\b\b",
927 pattern, "");
928
929 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200930 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000931 *addr = val;
932 val += incr;
933 }
934
wdenk4b9206e2004-03-23 22:14:11 +0000935 puts ("Reading...");
wdenk38635852002-08-27 05:55:31 +0000936
937 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200938 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000939 readback = *addr;
940 if (readback != val) {
941 printf ("\nMem error @ 0x%08X: "
942 "found %08lX, expected %08lX\n",
943 (uint)addr, readback, val);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400944 errs++;
945 if (ctrlc()) {
946 putc ('\n');
947 return 1;
948 }
wdenk38635852002-08-27 05:55:31 +0000949 }
950 val += incr;
951 }
952
953 /*
954 * Flip the pattern each time to make lots of zeros and
955 * then, the next time, lots of ones. We decrement
956 * the "negative" patterns and increment the "positive"
957 * patterns to preserve this feature.
958 */
959 if(pattern & 0x80000000) {
960 pattern = -pattern; /* complement & increment */
961 }
962 else {
963 pattern = ~pattern;
964 }
965 incr = -incr;
966 }
wdenk38635852002-08-27 05:55:31 +0000967#endif
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400968 return 0; /* not reached */
wdenk38635852002-08-27 05:55:31 +0000969}
970
971
972/* Modify memory.
973 *
974 * Syntax:
975 * mm{.b, .w, .l} {addr}
976 * nm{.b, .w, .l} {addr}
977 */
978static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200979mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000980{
wdenk27b207f2003-07-24 23:38:38 +0000981 ulong addr, i;
982 int nbytes, size;
wdenk38635852002-08-27 05:55:31 +0000983 extern char console_buffer[];
984
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200985 if (argc != 2)
986 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000987
988#ifdef CONFIG_BOOT_RETRY_TIME
989 reset_cmd_timeout(); /* got a good command to get here */
990#endif
991 /* We use the last specified parameters, unless new ones are
992 * entered.
993 */
994 addr = mm_last_addr;
995 size = mm_last_size;
996
997 if ((flag & CMD_FLAG_REPEAT) == 0) {
998 /* New command specified. Check for a size specification.
999 * Defaults to long if no or incorrect specification.
1000 */
wdenk27b207f2003-07-24 23:38:38 +00001001 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1002 return 1;
wdenk38635852002-08-27 05:55:31 +00001003
1004 /* Address is specified since argc > 1
1005 */
1006 addr = simple_strtoul(argv[1], NULL, 16);
1007 addr += base_address;
1008 }
1009
wdenk2abbe072003-06-16 23:50:08 +00001010#ifdef CONFIG_HAS_DATAFLASH
1011 if (addr_dataflash(addr)){
wdenk4b9206e2004-03-23 22:14:11 +00001012 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk2abbe072003-06-16 23:50:08 +00001013 return 0;
1014 }
1015#endif
1016
Mike Frysinger4c727c72008-02-04 19:26:56 -05001017#ifdef CONFIG_BLACKFIN
1018 if (addr_bfin_on_chip_mem(addr)) {
1019 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1020 return 0;
1021 }
1022#endif
1023
wdenk38635852002-08-27 05:55:31 +00001024 /* Print the address, followed by value. Then accept input for
1025 * the next value. A non-converted value exits.
1026 */
1027 do {
1028 printf("%08lx:", addr);
1029 if (size == 4)
1030 printf(" %08x", *((uint *)addr));
1031 else if (size == 2)
1032 printf(" %04x", *((ushort *)addr));
1033 else
1034 printf(" %02x", *((u_char *)addr));
1035
1036 nbytes = readline (" ? ");
1037 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1038 /* <CR> pressed as only input, don't modify current
1039 * location and move to next. "-" pressed will go back.
1040 */
1041 if (incrflag)
1042 addr += nbytes ? -size : size;
1043 nbytes = 1;
1044#ifdef CONFIG_BOOT_RETRY_TIME
1045 reset_cmd_timeout(); /* good enough to not time out */
1046#endif
1047 }
1048#ifdef CONFIG_BOOT_RETRY_TIME
1049 else if (nbytes == -2) {
1050 break; /* timed out, exit the command */
1051 }
1052#endif
1053 else {
1054 char *endp;
1055 i = simple_strtoul(console_buffer, &endp, 16);
1056 nbytes = endp - console_buffer;
1057 if (nbytes) {
1058#ifdef CONFIG_BOOT_RETRY_TIME
1059 /* good enough to not time out
1060 */
1061 reset_cmd_timeout();
1062#endif
1063 if (size == 4)
1064 *((uint *)addr) = i;
1065 else if (size == 2)
1066 *((ushort *)addr) = i;
1067 else
1068 *((u_char *)addr) = i;
1069 if (incrflag)
1070 addr += size;
1071 }
1072 }
1073 } while (nbytes);
1074
1075 mm_last_addr = addr;
1076 mm_last_size = size;
1077 return 0;
1078}
1079
wdenkc26e4542004-04-18 10:13:26 +00001080#ifndef CONFIG_CRC32_VERIFY
1081
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001082int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001083{
wdenk71f95112003-06-15 22:40:42 +00001084 ulong addr, length;
1085 ulong crc;
1086 ulong *ptr;
wdenk38635852002-08-27 05:55:31 +00001087
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001088 if (argc < 3)
1089 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +00001090
wdenk71f95112003-06-15 22:40:42 +00001091 addr = simple_strtoul (argv[1], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001092 addr += base_address;
1093
wdenk71f95112003-06-15 22:40:42 +00001094 length = simple_strtoul (argv[2], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001095
wdenk71f95112003-06-15 22:40:42 +00001096 crc = crc32 (0, (const uchar *) addr, length);
wdenk38635852002-08-27 05:55:31 +00001097
1098 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
wdenk71f95112003-06-15 22:40:42 +00001099 addr, addr + length - 1, crc);
wdenk38635852002-08-27 05:55:31 +00001100
wdenk71f95112003-06-15 22:40:42 +00001101 if (argc > 3) {
1102 ptr = (ulong *) simple_strtoul (argv[3], NULL, 16);
1103 *ptr = crc;
1104 }
wdenk38635852002-08-27 05:55:31 +00001105
1106 return 0;
1107}
1108
wdenkc26e4542004-04-18 10:13:26 +00001109#else /* CONFIG_CRC32_VERIFY */
1110
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001111int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkc26e4542004-04-18 10:13:26 +00001112{
1113 ulong addr, length;
1114 ulong crc;
1115 ulong *ptr;
wdenk6e592382004-04-18 17:39:38 +00001116 ulong vcrc;
wdenkc26e4542004-04-18 10:13:26 +00001117 int verify;
1118 int ac;
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001119 char * const *av;
wdenkc26e4542004-04-18 10:13:26 +00001120
1121 if (argc < 3) {
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001122usage:
1123 return cmd_usage(cmdtp);
wdenkc26e4542004-04-18 10:13:26 +00001124 }
1125
1126 av = argv + 1;
1127 ac = argc - 1;
1128 if (strcmp(*av, "-v") == 0) {
1129 verify = 1;
1130 av++;
1131 ac--;
1132 if (ac < 3)
1133 goto usage;
1134 } else
1135 verify = 0;
1136
1137 addr = simple_strtoul(*av++, NULL, 16);
1138 addr += base_address;
1139 length = simple_strtoul(*av++, NULL, 16);
1140
1141 crc = crc32(0, (const uchar *) addr, length);
1142
1143 if (!verify) {
1144 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
1145 addr, addr + length - 1, crc);
1146 if (ac > 2) {
1147 ptr = (ulong *) simple_strtoul (*av++, NULL, 16);
1148 *ptr = crc;
1149 }
1150 } else {
1151 vcrc = simple_strtoul(*av++, NULL, 16);
1152 if (vcrc != crc) {
1153 printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n",
1154 addr, addr + length - 1, crc, vcrc);
1155 return 1;
1156 }
1157 }
1158
1159 return 0;
1160
1161}
1162#endif /* CONFIG_CRC32_VERIFY */
1163
Robin Getz02c9aa12009-07-27 00:07:59 -04001164#ifdef CONFIG_CMD_MD5SUM
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001165int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Robin Getz02c9aa12009-07-27 00:07:59 -04001166{
1167 unsigned long addr, len;
1168 unsigned int i;
1169 u8 output[16];
1170
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001171 if (argc < 3)
1172 return cmd_usage(cmdtp);
Robin Getz02c9aa12009-07-27 00:07:59 -04001173
1174 addr = simple_strtoul(argv[1], NULL, 16);
1175 len = simple_strtoul(argv[2], NULL, 16);
1176
1177 md5((unsigned char *) addr, len, output);
1178 printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1);
1179 for (i = 0; i < 16; i++)
1180 printf("%02x", output[i]);
1181 printf("\n");
1182
1183 return 0;
1184}
1185#endif
1186
Alexander Hollerc6b1ee62011-01-18 09:48:08 +01001187#ifdef CONFIG_CMD_SHA1SUM
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001188int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Robin Getz02c9aa12009-07-27 00:07:59 -04001189{
1190 unsigned long addr, len;
1191 unsigned int i;
1192 u8 output[20];
1193
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001194 if (argc < 3)
1195 return cmd_usage(cmdtp);
Robin Getz02c9aa12009-07-27 00:07:59 -04001196
1197 addr = simple_strtoul(argv[1], NULL, 16);
1198 len = simple_strtoul(argv[2], NULL, 16);
1199
1200 sha1_csum((unsigned char *) addr, len, output);
1201 printf("SHA1 for %08lx ... %08lx ==> ", addr, addr + len - 1);
1202 for (i = 0; i < 20; i++)
1203 printf("%02x", output[i]);
1204 printf("\n");
1205
1206 return 0;
1207}
1208#endif
Harald Weltefe2ce552008-07-06 15:56:38 +08001209
1210#ifdef CONFIG_CMD_UNZIP
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001211int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Harald Weltefe2ce552008-07-06 15:56:38 +08001212{
1213 unsigned long src, dst;
1214 unsigned long src_len = ~0UL, dst_len = ~0UL;
Wolfgang Denk67fb0622011-02-11 20:20:51 +01001215 char buf[32];
Harald Weltefe2ce552008-07-06 15:56:38 +08001216
1217 switch (argc) {
1218 case 4:
1219 dst_len = simple_strtoul(argv[3], NULL, 16);
1220 /* fall through */
1221 case 3:
1222 src = simple_strtoul(argv[1], NULL, 16);
1223 dst = simple_strtoul(argv[2], NULL, 16);
1224 break;
1225 default:
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001226 return cmd_usage(cmdtp);
Harald Weltefe2ce552008-07-06 15:56:38 +08001227 }
1228
Wolfgang Denk67fb0622011-02-11 20:20:51 +01001229 if (gunzip((void *) dst, dst_len, (void *) src, &src_len) != 0)
1230 return 1;
1231
1232 printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
1233 sprintf(buf, "%lX", src_len);
1234 setenv("filesize", buf);
1235
1236 return 0;
Harald Weltefe2ce552008-07-06 15:56:38 +08001237}
1238#endif /* CONFIG_CMD_UNZIP */
1239
1240
wdenk8bde7f72003-06-27 21:31:46 +00001241/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001242U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001243 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001244 "memory display",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001245 "[.b, .w, .l] address [# of objects]"
wdenk8bde7f72003-06-27 21:31:46 +00001246);
1247
1248
wdenk0d498392003-07-01 21:06:45 +00001249U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001250 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001251 "memory modify (auto-incrementing address)",
1252 "[.b, .w, .l] address"
wdenk8bde7f72003-06-27 21:31:46 +00001253);
1254
1255
wdenk0d498392003-07-01 21:06:45 +00001256U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001257 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001258 "memory modify (constant address)",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001259 "[.b, .w, .l] address"
wdenk8bde7f72003-06-27 21:31:46 +00001260);
1261
wdenk0d498392003-07-01 21:06:45 +00001262U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001263 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001264 "memory write (fill)",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001265 "[.b, .w, .l] address value [count]"
wdenk8bde7f72003-06-27 21:31:46 +00001266);
1267
wdenk0d498392003-07-01 21:06:45 +00001268U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001269 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001270 "memory copy",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001271 "[.b, .w, .l] source target count"
wdenk8bde7f72003-06-27 21:31:46 +00001272);
1273
wdenk0d498392003-07-01 21:06:45 +00001274U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001275 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001276 "memory compare",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001277 "[.b, .w, .l] addr1 addr2 count"
wdenk8bde7f72003-06-27 21:31:46 +00001278);
1279
wdenkc26e4542004-04-18 10:13:26 +00001280#ifndef CONFIG_CRC32_VERIFY
1281
wdenk0d498392003-07-01 21:06:45 +00001282U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001283 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001284 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001285 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001286);
1287
wdenkc26e4542004-04-18 10:13:26 +00001288#else /* CONFIG_CRC32_VERIFY */
1289
1290U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001291 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001292 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001293 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001294 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001295);
1296
1297#endif /* CONFIG_CRC32_VERIFY */
1298
wdenk0d498392003-07-01 21:06:45 +00001299U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001300 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001301 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001302 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001303 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001304);
1305
wdenk0d498392003-07-01 21:06:45 +00001306U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001307 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001308 "infinite loop on address range",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001309 "[.b, .w, .l] address number_of_objects"
wdenk8bde7f72003-06-27 21:31:46 +00001310);
1311
wdenk56523f12004-07-11 17:40:54 +00001312#ifdef CONFIG_LOOPW
1313U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001314 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001315 "infinite write loop on address range",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001316 "[.b, .w, .l] address number_of_objects data_to_write"
wdenk56523f12004-07-11 17:40:54 +00001317);
1318#endif /* CONFIG_LOOPW */
1319
wdenk0d498392003-07-01 21:06:45 +00001320U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001321 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001322 "simple RAM read/write test",
1323 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001324);
1325
stroese4aaf29b2004-12-16 17:42:39 +00001326#ifdef CONFIG_MX_CYCLIC
1327U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001328 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001329 "memory display cyclic",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001330 "[.b, .w, .l] address count delay(ms)"
stroese4aaf29b2004-12-16 17:42:39 +00001331);
1332
1333U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001334 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001335 "memory write cyclic",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001336 "[.b, .w, .l] address value delay(ms)"
stroese4aaf29b2004-12-16 17:42:39 +00001337);
1338#endif /* CONFIG_MX_CYCLIC */
1339
Robin Getz02c9aa12009-07-27 00:07:59 -04001340#ifdef CONFIG_CMD_MD5SUM
1341U_BOOT_CMD(
1342 md5sum, 3, 1, do_md5sum,
1343 "compute MD5 message digest",
1344 "address count"
1345);
1346#endif
1347
1348#ifdef CONFIG_CMD_SHA1SUM
1349U_BOOT_CMD(
1350 sha1sum, 3, 1, do_sha1sum,
1351 "compute SHA1 message digest",
1352 "address count"
1353);
Alexander Hollerc6b1ee62011-01-18 09:48:08 +01001354#endif /* CONFIG_CMD_SHA1SUM */
Robin Getz02c9aa12009-07-27 00:07:59 -04001355
Harald Weltefe2ce552008-07-06 15:56:38 +08001356#ifdef CONFIG_CMD_UNZIP
1357U_BOOT_CMD(
1358 unzip, 4, 1, do_unzip,
Peter Tyser2fb26042009-01-27 18:03:12 -06001359 "unzip a memory region",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001360 "srcaddr dstaddr [dstsize]"
Harald Weltefe2ce552008-07-06 15:56:38 +08001361);
1362#endif /* CONFIG_CMD_UNZIP */