]> Git Repo - J-u-boot.git/blame - common/cmd_mem.c
common: tsi148 - fix gcc 4.6 compiler warning
[J-u-boot.git] / common / cmd_mem.c
CommitLineData
3863585b
WD
1/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, [email protected].
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 ([email protected])
28 */
29
30#include <common.h>
31#include <command.h>
2abbe075
WD
32#ifdef CONFIG_HAS_DATAFLASH
33#include <dataflash.h>
34#endif
a6e6fc61 35#include <watchdog.h>
355a8357 36#include <asm/io.h>
3863585b 37
3863585b
WD
38#ifdef CMD_MEM_DEBUG
39#define PRINTF(fmt,args...) printf (fmt ,##args)
40#else
41#define PRINTF(fmt,args...)
42#endif
43
54841ab5 44static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
3863585b
WD
45
46/* Display values from last command.
47 * Memory modify remembered values are different from display memory.
48 */
d6efe244
MF
49static uint dp_last_addr, dp_last_size;
50static uint dp_last_length = 0x40;
51static uint mm_last_addr, mm_last_size;
3863585b
WD
52
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
54841ab5 61int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 62{
27b207fd 63 ulong addr, length;
c95c4280
GL
64#if defined(CONFIG_HAS_DATAFLASH)
65 ulong nbytes, linebytes;
66#endif
27b207fd 67 int size;
3863585b
WD
68 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
47e26b1b
WD
77 if (argc < 2)
78 return cmd_usage(cmdtp);
3863585b
WD
79
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 */
27b207fd
WD
84 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
85 return 1;
3863585b
WD
86
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
c95c4280 99#if defined(CONFIG_HAS_DATAFLASH)
3863585b
WD
100 /* 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];
c95c4280 108 void* p;
3863585b 109 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
2abbe075 110
c95c4280
GL
111 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);
114
3863585b 115 nbytes -= linebytes;
c95c4280 116 addr += linebytes;
3863585b
WD
117 if (ctrlc()) {
118 rc = 1;
119 break;
120 }
121 } while (nbytes > 0);
c95c4280 122#else
4c727c77
MF
123
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 {
355a8357
SG
145 ulong bytes = size * length;
146 void *buf = map_physmem(addr, bytes, MAP_WRBACK);
147
4c727c77 148 /* Print the lines. */
355a8357
SG
149 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
150 addr += bytes;
151 unmap_physmem(buf, bytes);
4c727c77 152 }
c95c4280 153#endif
3863585b
WD
154
155 dp_last_addr = addr;
156 dp_last_length = length;
157 dp_last_size = size;
158 return (rc);
159}
160
54841ab5 161int do_mem_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b
WD
162{
163 return mod_mem (cmdtp, 1, flag, argc, argv);
164}
54841ab5 165int do_mem_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b
WD
166{
167 return mod_mem (cmdtp, 0, flag, argc, argv);
168}
169
54841ab5 170int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 171{
27b207fd
WD
172 ulong addr, writeval, count;
173 int size;
3863585b 174
47e26b1b
WD
175 if ((argc < 3) || (argc > 4))
176 return cmd_usage(cmdtp);
3863585b
WD
177
178 /* Check for size specification.
179 */
27b207fd
WD
180 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
181 return 1;
3863585b
WD
182
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
4aaf29b2 211#ifdef CONFIG_MX_CYCLIC
54841ab5 212int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
4aaf29b2
SR
213{
214 int i;
215 ulong count;
216
47e26b1b
WD
217 if (argc < 4)
218 return cmd_usage(cmdtp);
4aaf29b2
SR
219
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
54841ab5 239int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
4aaf29b2
SR
240{
241 int i;
242 ulong count;
243
47e26b1b
WD
244 if (argc < 4)
245 return cmd_usage(cmdtp);
4aaf29b2
SR
246
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
54841ab5 267int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 268{
27b207fd
WD
269 ulong addr1, addr2, count, ngood;
270 int size;
3863585b
WD
271 int rcode = 0;
272
47e26b1b
WD
273 if (argc != 4)
274 return cmd_usage(cmdtp);
3863585b
WD
275
276 /* Check for size specification.
277 */
27b207fd
WD
278 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
279 return 1;
3863585b
WD
280
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
2abbe075
WD
289#ifdef CONFIG_HAS_DATAFLASH
290 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
4b9206ed 291 puts ("Comparison with DataFlash space not supported.\n\r");
2abbe075
WD
292 return 0;
293 }
294#endif
295
4c727c77
MF
296#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
3863585b
WD
303 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;
eaadb44e
SR
342
343 /* reset watchdog from time to time */
344 if ((count % (64 << 10)) == 0)
345 WATCHDOG_RESET();
3863585b
WD
346 }
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
54841ab5 354int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 355{
27b207fd
WD
356 ulong addr, dest, count;
357 int size;
3863585b 358
47e26b1b
WD
359 if (argc != 4)
360 return cmd_usage(cmdtp);
3863585b
WD
361
362 /* Check for size specification.
363 */
27b207fd
WD
364 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
365 return 1;
3863585b
WD
366
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
6d0f6bcf 380#ifndef CONFIG_SYS_NO_FLASH
3863585b 381 /* check if we are copying to Flash */
2abbe075
WD
382 if ( (addr2info(dest) != NULL)
383#ifdef CONFIG_HAS_DATAFLASH
84d0c2f1 384 && (!addr_dataflash(dest))
2abbe075
WD
385#endif
386 ) {
3863585b
WD
387 int rc;
388
4b9206ed 389 puts ("Copy to Flash... ");
3863585b 390
77ddac94 391 rc = flash_write ((char *)addr, dest, count*size);
3863585b
WD
392 if (rc != 0) {
393 flash_perror (rc);
394 return (1);
395 }
396 puts ("done\n");
397 return 0;
398 }
399#endif
400
2abbe075
WD
401#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
4b9206ed 406 puts ("Copy to DataFlash... ");
2abbe075
WD
407
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 }
8bde7f77 417
2abbe075 418 /* Check if we are copying from DataFlash to RAM */
880cc438 419 if (addr_dataflash(addr) && !addr_dataflash(dest)
6d0f6bcf 420#ifndef CONFIG_SYS_NO_FLASH
880cc438
SP
421 && (addr2info(dest) == NULL)
422#endif
423 ){
5779d8d9
WD
424 int rc;
425 rc = read_dataflash(addr, count * size, (char *) dest);
426 if (rc != 1) {
d4ca31c4
WD
427 dataflash_perror (rc);
428 return (1);
429 }
2abbe075
WD
430 return 0;
431 }
432
433 if (addr_dataflash(addr) && addr_dataflash(dest)){
4b9206ed 434 puts ("Unsupported combination of source/destination.\n\r");
2abbe075
WD
435 return 1;
436 }
437#endif
438
4c727c77
MF
439#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
3863585b
WD
447 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;
eaadb44e
SR
456
457 /* reset watchdog from time to time */
458 if ((count % (64 << 10)) == 0)
459 WATCHDOG_RESET();
3863585b
WD
460 }
461 return 0;
462}
463
54841ab5 464int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b
WD
465{
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
54841ab5 477int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 478{
f3b3c3df 479 ulong addr, length, i;
27b207fd 480 int size;
3863585b
WD
481 volatile uint *longp;
482 volatile ushort *shortp;
483 volatile u_char *cp;
484
47e26b1b
WD
485 if (argc < 3)
486 return cmd_usage(cmdtp);
3863585b
WD
487
488 /* Check for a size spefication.
489 * Defaults to long if no or incorrect specification.
490 */
27b207fd
WD
491 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
492 return 1;
3863585b
WD
493
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)
f3b3c3df 526 *longp++;
3863585b
WD
527 }
528 }
529 if (size == 2) {
530 for (;;) {
531 shortp = (ushort *)addr;
532 i = length;
533 while (i-- > 0)
f3b3c3df 534 *shortp++;
3863585b
WD
535 }
536 }
537 for (;;) {
538 cp = (u_char *)addr;
539 i = length;
540 while (i-- > 0)
f3b3c3df 541 *cp++;
3863585b
WD
542 }
543}
544
56523f12 545#ifdef CONFIG_LOOPW
54841ab5 546int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
56523f12
WD
547{
548 ulong addr, length, i, data;
549 int size;
550 volatile uint *longp;
551 volatile ushort *shortp;
552 volatile u_char *cp;
81050926 553
47e26b1b
WD
554 if (argc < 4)
555 return cmd_usage(cmdtp);
56523f12
WD
556
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);
81050926 573
56523f12
WD
574 /* 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
3863585b
WD
618/*
619 * Perform a memory test. A more complete alternative test can be
6d0f6bcf 620 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
3863585b
WD
621 * interrupted by ctrl-c or by a failure of one of the sub-tests.
622 */
54841ab5 623int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b
WD
624{
625 vu_long *addr, *start, *end;
626 ulong val;
627 ulong readback;
87b22b77 628 ulong errs = 0;
b6fc6fd4
DE
629 int iterations = 1;
630 int iteration_limit;
3863585b 631
6d0f6bcf 632#if defined(CONFIG_SYS_ALT_MEMTEST)
6f4abee7 633 vu_long len;
3863585b
WD
634 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;
6d0f6bcf
JCPV
640#if defined(CONFIG_SYS_MEMTEST_SCRATCH)
641 vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH;
5f535fe1 642#else
029b6dc7 643 vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
5f535fe1 644#endif
3863585b 645 int j;
3863585b
WD
646
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;
3863585b
WD
660#endif
661
b6fc6fd4 662 if (argc > 1)
3863585b 663 start = (ulong *)simple_strtoul(argv[1], NULL, 16);
b6fc6fd4 664 else
6d0f6bcf 665 start = (ulong *)CONFIG_SYS_MEMTEST_START;
3863585b 666
b6fc6fd4 667 if (argc > 2)
3863585b 668 end = (ulong *)simple_strtoul(argv[2], NULL, 16);
b6fc6fd4 669 else
6d0f6bcf 670 end = (ulong *)(CONFIG_SYS_MEMTEST_END);
3863585b 671
b6fc6fd4 672 if (argc > 3)
3863585b 673 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
b6fc6fd4 674 else
3863585b 675 pattern = 0;
b6fc6fd4
DE
676
677 if (argc > 4)
678 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
679 else
680 iteration_limit = 0;
3863585b 681
6d0f6bcf 682#if defined(CONFIG_SYS_ALT_MEMTEST)
3863585b
WD
683 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
b6fc6fd4
DE
693
694 if (iteration_limit && iterations > iteration_limit) {
87b22b77
PG
695 printf("Tested %d iteration(s) with %lu errors.\n",
696 iterations-1, errs);
697 return errs != 0;
b6fc6fd4
DE
698 }
699
3863585b 700 printf("Iteration: %6d\r", iterations);
b6fc6fd4 701 PRINTF("\n");
3863585b
WD
702 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) {
87b22b77 729 printf ("FAILURE (data line): "
3863585b
WD
730 "expected %08lx, actual %08lx\n",
731 val, readback);
87b22b77
PG
732 errs++;
733 if (ctrlc()) {
734 putc ('\n');
735 return 1;
736 }
3863585b
WD
737 }
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",
e1599e83 744 readback, ~val);
87b22b77
PG
745 errs++;
746 if (ctrlc()) {
747 putc ('\n');
748 return 1;
749 }
3863585b
WD
750 }
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.
3863585b 787 */
6f4abee7 788 len = ((ulong)end - (ulong)start)/sizeof(vu_long);
3863585b
WD
789 pattern = (vu_long) 0xaaaaaaaa;
790 anti_pattern = (vu_long) 0x55555555;
791
6f4abee7 792 PRINTF("%s:%d: length = 0x%.8lx\n",
3863585b 793 __FUNCTION__, __LINE__,
6f4abee7 794 len);
3863585b
WD
795 /*
796 * Write the default pattern at each of the
797 * power-of-two offsets.
798 */
6f4abee7 799 for (offset = 1; offset < len; offset <<= 1) {
3863585b
WD
800 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
6f4abee7 809 for (offset = 1; offset < len; offset <<= 1) {
3863585b
WD
810 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);
87b22b77
PG
815 errs++;
816 if (ctrlc()) {
817 putc ('\n');
818 return 1;
819 }
3863585b
WD
820 }
821 }
822 start[test_offset] = pattern;
a6e6fc61 823 WATCHDOG_RESET();
3863585b
WD
824
825 /*
826 * Check for addr bits stuck low or shorted.
827 */
6f4abee7 828 for (test_offset = 1; test_offset < len; test_offset <<= 1) {
3863585b
WD
829 start[test_offset] = anti_pattern;
830
6f4abee7 831 for (offset = 1; offset < len; offset <<= 1) {
3863585b
WD
832 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);
87b22b77
PG
837 errs++;
838 if (ctrlc()) {
839 putc ('\n');
840 return 1;
841 }
3863585b
WD
842 }
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++) {
a6e6fc61 865 WATCHDOG_RESET();
3863585b
WD
866 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++) {
a6e6fc61 873 WATCHDOG_RESET();
3863585b
WD
874 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);
87b22b77
PG
879 errs++;
880 if (ctrlc()) {
881 putc ('\n');
882 return 1;
883 }
3863585b
WD
884 }
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++) {
a6e6fc61 894 WATCHDOG_RESET();
3863585b
WD
895 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);
87b22b77
PG
901 errs++;
902 if (ctrlc()) {
903 putc ('\n');
904 return 1;
905 }
3863585b
WD
906 }
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 }
918
b6fc6fd4 919 if (iteration_limit && iterations > iteration_limit) {
87b22b77
PG
920 printf("Tested %d iteration(s) with %lu errors.\n",
921 iterations-1, errs);
922 return errs != 0;
b6fc6fd4
DE
923 }
924 ++iterations;
925
3863585b
WD
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++) {
a6e6fc61 932 WATCHDOG_RESET();
3863585b
WD
933 *addr = val;
934 val += incr;
935 }
936
4b9206ed 937 puts ("Reading...");
3863585b
WD
938
939 for (addr=start,val=pattern; addr<end; addr++) {
a6e6fc61 940 WATCHDOG_RESET();
3863585b
WD
941 readback = *addr;
942 if (readback != val) {
943 printf ("\nMem error @ 0x%08X: "
944 "found %08lX, expected %08lX\n",
92549358 945 (uint)(uintptr_t)addr, readback, val);
87b22b77
PG
946 errs++;
947 if (ctrlc()) {
948 putc ('\n');
949 return 1;
950 }
3863585b
WD
951 }
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 }
3863585b 969#endif
87b22b77 970 return 0; /* not reached */
3863585b
WD
971}
972
973
974/* Modify memory.
975 *
976 * Syntax:
977 * mm{.b, .w, .l} {addr}
978 * nm{.b, .w, .l} {addr}
979 */
980static int
54841ab5 981mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
3863585b 982{
27b207fd
WD
983 ulong addr, i;
984 int nbytes, size;
3863585b
WD
985 extern char console_buffer[];
986
47e26b1b
WD
987 if (argc != 2)
988 return cmd_usage(cmdtp);
3863585b
WD
989
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 */
27b207fd
WD
1003 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1004 return 1;
3863585b
WD
1005
1006 /* Address is specified since argc > 1
1007 */
1008 addr = simple_strtoul(argv[1], NULL, 16);
1009 addr += base_address;
1010 }
1011
2abbe075
WD
1012#ifdef CONFIG_HAS_DATAFLASH
1013 if (addr_dataflash(addr)){
4b9206ed 1014 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
2abbe075
WD
1015 return 0;
1016 }
1017#endif
1018
4c727c77
MF
1019#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
3863585b
WD
1026 /* 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
710b9938
MF
1082#ifdef CONFIG_CMD_CRC32
1083
c26e454d
WD
1084#ifndef CONFIG_CRC32_VERIFY
1085
54841ab5 1086int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 1087{
71f95118
WD
1088 ulong addr, length;
1089 ulong crc;
1090 ulong *ptr;
3863585b 1091
47e26b1b
WD
1092 if (argc < 3)
1093 return cmd_usage(cmdtp);
3863585b 1094
71f95118 1095 addr = simple_strtoul (argv[1], NULL, 16);
3863585b
WD
1096 addr += base_address;
1097
71f95118 1098 length = simple_strtoul (argv[2], NULL, 16);
3863585b 1099
39c6e039 1100 crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
3863585b
WD
1101
1102 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
71f95118 1103 addr, addr + length - 1, crc);
3863585b 1104
71f95118
WD
1105 if (argc > 3) {
1106 ptr = (ulong *) simple_strtoul (argv[3], NULL, 16);
1107 *ptr = crc;
1108 }
3863585b
WD
1109
1110 return 0;
1111}
1112
c26e454d
WD
1113#else /* CONFIG_CRC32_VERIFY */
1114
54841ab5 1115int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
c26e454d
WD
1116{
1117 ulong addr, length;
1118 ulong crc;
1119 ulong *ptr;
6e592385 1120 ulong vcrc;
c26e454d
WD
1121 int verify;
1122 int ac;
54841ab5 1123 char * const *av;
c26e454d
WD
1124
1125 if (argc < 3) {
47e26b1b
WD
1126usage:
1127 return cmd_usage(cmdtp);
c26e454d
WD
1128 }
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
39c6e039 1145 crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
c26e454d
WD
1146
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
710b9938
MF
1168#endif
1169
8bde7f77 1170/**************************************************/
0d498393 1171U_BOOT_CMD(
53677ef1 1172 md, 3, 1, do_mem_md,
2fb2604d 1173 "memory display",
a89c33db 1174 "[.b, .w, .l] address [# of objects]"
8bde7f77
WD
1175);
1176
1177
0d498393 1178U_BOOT_CMD(
53677ef1 1179 mm, 2, 1, do_mem_mm,
a89c33db
WD
1180 "memory modify (auto-incrementing address)",
1181 "[.b, .w, .l] address"
8bde7f77
WD
1182);
1183
1184
0d498393 1185U_BOOT_CMD(
53677ef1 1186 nm, 2, 1, do_mem_nm,
2fb2604d 1187 "memory modify (constant address)",
a89c33db 1188 "[.b, .w, .l] address"
8bde7f77
WD
1189);
1190
0d498393 1191U_BOOT_CMD(
53677ef1 1192 mw, 4, 1, do_mem_mw,
2fb2604d 1193 "memory write (fill)",
a89c33db 1194 "[.b, .w, .l] address value [count]"
8bde7f77
WD
1195);
1196
0d498393 1197U_BOOT_CMD(
53677ef1 1198 cp, 4, 1, do_mem_cp,
2fb2604d 1199 "memory copy",
a89c33db 1200 "[.b, .w, .l] source target count"
8bde7f77
WD
1201);
1202
0d498393 1203U_BOOT_CMD(
53677ef1 1204 cmp, 4, 1, do_mem_cmp,
2fb2604d 1205 "memory compare",
a89c33db 1206 "[.b, .w, .l] addr1 addr2 count"
8bde7f77
WD
1207);
1208
710b9938
MF
1209#ifdef CONFIG_CMD_CRC32
1210
c26e454d
WD
1211#ifndef CONFIG_CRC32_VERIFY
1212
0d498393 1213U_BOOT_CMD(
53677ef1 1214 crc32, 4, 1, do_mem_crc,
2fb2604d 1215 "checksum calculation",
a89c33db 1216 "address count [addr]\n - compute CRC32 checksum [save at addr]"
8bde7f77
WD
1217);
1218
c26e454d
WD
1219#else /* CONFIG_CRC32_VERIFY */
1220
1221U_BOOT_CMD(
53677ef1 1222 crc32, 5, 1, do_mem_crc,
2fb2604d 1223 "checksum calculation",
c26e454d 1224 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
a89c33db 1225 "-v address count crc\n - verify crc of memory area"
c26e454d
WD
1226);
1227
1228#endif /* CONFIG_CRC32_VERIFY */
1229
710b9938
MF
1230#endif
1231
0d498393 1232U_BOOT_CMD(
53677ef1 1233 base, 2, 1, do_mem_base,
2fb2604d 1234 "print or set address offset",
8bde7f77 1235 "\n - print address offset for memory commands\n"
a89c33db 1236 "base off\n - set address offset for memory commands to 'off'"
8bde7f77
WD
1237);
1238
0d498393 1239U_BOOT_CMD(
53677ef1 1240 loop, 3, 1, do_mem_loop,
2fb2604d 1241 "infinite loop on address range",
a89c33db 1242 "[.b, .w, .l] address number_of_objects"
8bde7f77
WD
1243);
1244
56523f12
WD
1245#ifdef CONFIG_LOOPW
1246U_BOOT_CMD(
53677ef1 1247 loopw, 4, 1, do_mem_loopw,
2fb2604d 1248 "infinite write loop on address range",
a89c33db 1249 "[.b, .w, .l] address number_of_objects data_to_write"
56523f12
WD
1250);
1251#endif /* CONFIG_LOOPW */
1252
0d498393 1253U_BOOT_CMD(
b6fc6fd4 1254 mtest, 5, 1, do_mem_mtest,
a89c33db
WD
1255 "simple RAM read/write test",
1256 "[start [end [pattern [iterations]]]]"
8bde7f77
WD
1257);
1258
4aaf29b2
SR
1259#ifdef CONFIG_MX_CYCLIC
1260U_BOOT_CMD(
53677ef1 1261 mdc, 4, 1, do_mem_mdc,
2fb2604d 1262 "memory display cyclic",
a89c33db 1263 "[.b, .w, .l] address count delay(ms)"
4aaf29b2
SR
1264);
1265
1266U_BOOT_CMD(
53677ef1 1267 mwc, 4, 1, do_mem_mwc,
2fb2604d 1268 "memory write cyclic",
a89c33db 1269 "[.b, .w, .l] address value delay(ms)"
4aaf29b2
SR
1270);
1271#endif /* CONFIG_MX_CYCLIC */
This page took 0.386854 seconds and 4 git commands to generate.