5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
26 add following code to PIP405.c :
32 i = getenv_r ("testmem", s, 32);
34 i = (int) simple_strtoul (s, NULL, 10);
35 if ((i > 0) && (i < 0xf)) {
37 i = mem_test (0, ramsize, i);
50 #include <asm/processor.h>
51 #include <405gp_i2c.h>
57 #define TEST_SHOW_PROG 4
58 #define TEST_SHOW_ERR 2
59 #define TEST_SHOW_ALL 1
61 #define TESTPAT1 0xAA55AA55
62 #define TESTPAT2 0x55AA55AA
65 #define MEGABYTE (1024*1024)
69 volatile unsigned long pat1;
70 volatile unsigned long pat2;
71 } RAM_MEMTEST_PATTERN2;
74 volatile unsigned long addr;
75 } RAM_MEMTEST_ADDRLINE;
77 static __inline unsigned long Swap_32 (unsigned long val)
79 return (((val << 16) & 0xFFFF0000) | ((val >> 16) & 0x0000FFFF));
82 void testm_puts (int quiet, char *buf)
84 if ((quiet & TEST_SHOW_ALL) == TEST_SHOW_ALL)
89 void Write_Error (int mode, unsigned long addr, unsigned long expected,
95 sprintf (dispbuf, "\n ERROR @ 0x%08lX: (exp: 0x%08lX act: 0x%08lX) ",
96 addr, expected, actual);
97 testm_puts (((mode & TEST_SHOW_ERR) ==
98 TEST_SHOW_ERR) ? TEST_SHOW_ALL : mode, dispbuf);
103 * fills the memblock of <size> bytes from <startaddr> with pat1 and pat2
107 void RAM_MemTest_WritePattern2 (unsigned long startaddr,
108 unsigned long size, unsigned long pat1,
111 RAM_MEMTEST_PATTERN2 *p, *pe;
113 p = (RAM_MEMTEST_PATTERN2 *) startaddr;
114 pe = (RAM_MEMTEST_PATTERN2 *) (startaddr + size);
124 * checks the memblock of <size> bytes from <startaddr> with pat1 and pat2
125 * returns the address of the first error or NULL if all is well
128 void *RAM_MemTest_CheckPattern2 (int mode, unsigned long startaddr,
129 unsigned long size, unsigned long pat1,
132 RAM_MEMTEST_PATTERN2 *p, *pe;
133 unsigned long actual1, actual2;
135 p = (RAM_MEMTEST_PATTERN2 *) startaddr;
136 pe = (RAM_MEMTEST_PATTERN2 *) (startaddr + size);
142 if (actual1 != pat1) {
143 Write_Error (mode, (unsigned long) &(p->pat1), pat1, actual1);
144 return ((void *) &(p->pat1));
147 if (actual2 != pat2) {
148 Write_Error (mode, (unsigned long) &(p->pat2), pat2, actual2);
149 return ((void *) &(p->pat2));
159 * fills the memblock of <size> bytes from <startaddr> with the address
162 void RAM_MemTest_WriteAddrLine (unsigned long startaddr,
163 unsigned long size, int swapped)
165 RAM_MEMTEST_ADDRLINE *p, *pe;
167 p = (RAM_MEMTEST_ADDRLINE *) startaddr;
168 pe = (RAM_MEMTEST_ADDRLINE *) (startaddr + size);
172 p->addr = (unsigned long) p;
177 p->addr = Swap_32 ((unsigned long) p);
184 * checks the memblock of <size> bytes from <startaddr>
185 * returns the address of the error or NULL if all is well
188 void *RAM_MemTest_CheckAddrLine (int mode, unsigned long startaddr,
189 unsigned long size, int swapped)
191 RAM_MEMTEST_ADDRLINE *p, *pe;
192 unsigned long actual, expected;
194 p = (RAM_MEMTEST_ADDRLINE *) startaddr;
195 pe = (RAM_MEMTEST_ADDRLINE *) (startaddr + size);
200 expected = (unsigned long) p;
201 if (actual != expected) {
202 Write_Error (mode, (unsigned long) &(p->addr), expected,
204 return ((void *) &(p->addr));
211 expected = Swap_32 ((unsigned long) p);
212 if (actual != expected) {
213 Write_Error (mode, (unsigned long) &(p->addr), expected,
215 return ((void *) &(p->addr));
225 * checks the memblock of <size> bytes from <startaddr+size>
226 * returns the address of the error or NULL if all is well
229 void *RAM_MemTest_CheckAddrLineReverse (int mode, unsigned long startaddr,
230 unsigned long size, int swapped)
232 RAM_MEMTEST_ADDRLINE *p, *pe;
233 unsigned long actual, expected;
235 p = (RAM_MEMTEST_ADDRLINE *) (startaddr + size - sizeof (p->addr));
236 pe = (RAM_MEMTEST_ADDRLINE *) startaddr;
241 expected = (unsigned long) p;
242 if (actual != expected) {
243 Write_Error (mode, (unsigned long) &(p->addr), expected,
245 return ((void *) &(p->addr));
252 expected = Swap_32 ((unsigned long) p);
253 if (actual != expected) {
254 Write_Error (mode, (unsigned long) &(p->addr), expected,
256 return ((void *) &(p->addr));
266 * fills the memblock of <size> bytes from <startaddr> with walking bit pattern
269 void RAM_MemTest_WriteWalkBit (unsigned long startaddr, unsigned long size)
271 volatile unsigned long *p, *pe;
274 p = (unsigned long *) startaddr;
275 pe = (unsigned long *) (startaddr + size);
280 i = (i + 1 + (((unsigned long) p) >> 7)) % 32;
286 * checks the memblock of <size> bytes from <startaddr>
287 * returns the address of the error or NULL if all is well
290 void *RAM_MemTest_CheckWalkBit (int mode, unsigned long startaddr,
293 volatile unsigned long *p, *pe;
294 unsigned long actual, expected;
297 p = (unsigned long *) startaddr;
298 pe = (unsigned long *) (startaddr + size);
303 expected = (1UL << i);
304 if (actual != expected) {
305 Write_Error (mode, (unsigned long) p, expected, actual);
308 i = (i + 1 + (((unsigned long) p) >> 7)) % 32;
316 * fills the memblock of <size> bytes from <startaddr> with "random" pattern
319 void RAM_MemTest_WriteRandomPattern (unsigned long startaddr,
327 for (i = 0; i < (size / 4); i++) {
328 *(unsigned long *) (startaddr + i * 4) = p;
342 * checks the memblock of <size> bytes from <startaddr>
343 * returns the address of the error or NULL if all is well
346 void *RAM_MemTest_CheckRandomPattern (int mode, unsigned long startaddr,
351 unsigned long i, p, p1;
355 for (i = 0; i < (size / 4); i++) {
356 p1 = *(unsigned long *) (startaddr + i * 4);
359 Write_Error (mode, startaddr + i * 4, p, p1);
360 perr = (void *) (startaddr + i * 4);
379 void RAM_MemTest_WriteData1 (unsigned long startaddr, unsigned long size,
382 RAM_MemTest_WritePattern2 (startaddr, size, TESTPAT1, TESTPAT2);
385 void *RAM_MemTest_CheckData1 (int mode, unsigned long startaddr,
386 unsigned long size, unsigned long *pat)
388 return (RAM_MemTest_CheckPattern2
389 (mode, startaddr, size, TESTPAT1, TESTPAT2));
392 void RAM_MemTest_WriteData2 (unsigned long startaddr, unsigned long size,
395 RAM_MemTest_WritePattern2 (startaddr, size, TESTPAT2, TESTPAT1);
398 void *RAM_MemTest_CheckData2 (int mode, unsigned long startaddr,
399 unsigned long size, unsigned long *pat)
401 return (RAM_MemTest_CheckPattern2
402 (mode, startaddr, size, TESTPAT2, TESTPAT1));
405 void RAM_MemTest_WriteAddr1 (unsigned long startaddr, unsigned long size,
408 RAM_MemTest_WriteAddrLine (startaddr, size, FALSE);
411 void *RAM_MemTest_Check1Addr1 (int mode, unsigned long startaddr,
412 unsigned long size, unsigned long *pat)
414 return (RAM_MemTest_CheckAddrLine (mode, startaddr, size, FALSE));
417 void *RAM_MemTest_Check2Addr1 (int mode, unsigned long startaddr,
418 unsigned long size, unsigned long *pat)
420 return (RAM_MemTest_CheckAddrLineReverse
421 (mode, startaddr, size, FALSE));
424 void RAM_MemTest_WriteAddr2 (unsigned long startaddr, unsigned long size,
427 RAM_MemTest_WriteAddrLine (startaddr, size, TRUE);
430 void *RAM_MemTest_Check1Addr2 (int mode, unsigned long startaddr,
431 unsigned long size, unsigned long *pat)
433 return (RAM_MemTest_CheckAddrLine (mode, startaddr, size, TRUE));
436 void *RAM_MemTest_Check2Addr2 (int mode, unsigned long startaddr,
437 unsigned long size, unsigned long *pat)
439 return (RAM_MemTest_CheckAddrLineReverse
440 (mode, startaddr, size, TRUE));
445 void (*test_write) (unsigned long startaddr, unsigned long size,
447 char *test_write_desc;
448 void *(*test_check1) (int mode, unsigned long startaddr,
449 unsigned long size, unsigned long *pat);
450 void *(*test_check2) (int mode, unsigned long startaddr,
451 unsigned long size, unsigned long *pat);
455 #define TEST_STAGES 5
456 static RAM_MEMTEST_FUNC test_stage[TEST_STAGES] = {
457 {RAM_MemTest_WriteData1, "data test 1...\n", RAM_MemTest_CheckData1,
459 {RAM_MemTest_WriteData2, "data test 2...\n", RAM_MemTest_CheckData2,
461 {RAM_MemTest_WriteAddr1, "address line test...\n",
462 RAM_MemTest_Check1Addr1, RAM_MemTest_Check2Addr1},
463 {RAM_MemTest_WriteAddr2, "address line test (swapped)...\n",
464 RAM_MemTest_Check1Addr2, RAM_MemTest_Check2Addr2},
465 {RAM_MemTest_WriteRandomPattern, "random data test...\n",
466 RAM_MemTest_CheckRandomPattern, NULL}
469 void mem_test_reloc(void)
471 DECLARE_GLOBAL_DATA_PTR;
474 for (i=0; i< TEST_STAGES; i++) {
475 addr = (ulong) (test_stage[i].test_write) + gd->reloc_off;
476 test_stage[i].test_write=
477 (void (*) (unsigned long startaddr, unsigned long size,
478 unsigned long *pat))addr;
479 addr = (ulong) (test_stage[i].test_write_desc) + gd->reloc_off;
480 test_stage[i].test_write_desc=(char *)addr;
481 if(test_stage[i].test_check1) {
482 addr = (ulong) (test_stage[i].test_check1) + gd->reloc_off;
483 test_stage[i].test_check1=
484 (void *(*) (int mode, unsigned long startaddr,
485 unsigned long size, unsigned long *pat))addr;
487 if(test_stage[i].test_check2) {
488 addr = (ulong) (test_stage[i].test_check2) + gd->reloc_off;
489 test_stage[i].test_check2=
490 (void *(*) (int mode, unsigned long startaddr,
491 unsigned long size, unsigned long *pat))addr;
497 int mem_test (unsigned long start, unsigned long ramsize, int quiet, int reloc)
499 unsigned long errors, stage;
500 unsigned long startaddr, size, i;
501 const unsigned long blocksize = 0x80000; /* check in 512KB blocks */
503 unsigned long rdatapat;
505 int status = TEST_PASSED;
511 if ((quiet & TEST_SHOW_PROG) == TEST_SHOW_PROG) {
515 sprintf (dispbuf, "\nMemory Test: addr = 0x%lx size = 0x%lx\n",
517 testm_puts (quiet, dispbuf);
518 for (stage = 0; stage < TEST_STAGES; stage++) {
519 sprintf (dispbuf, test_stage[stage].test_write_desc);
520 testm_puts (quiet, dispbuf);
522 rdatapat = 0x12345678;
523 sprintf (dispbuf, "writing block: ");
524 testm_puts (quiet, dispbuf);
525 for (i = 0; i < size; i += blocksize) {
526 sprintf (dispbuf, "%04lX\b\b\b\b", i / blocksize);
527 testm_puts (quiet, dispbuf);
528 test_stage[stage].test_write (startaddr + i, blocksize,
531 sprintf (dispbuf, "\n");
532 testm_puts (quiet, dispbuf);
533 if ((quiet & TEST_SHOW_PROG) == TEST_SHOW_PROG) {
538 rdatapat = 0x12345678;
539 sprintf (dispbuf, "checking block: ");
540 testm_puts (quiet, dispbuf);
541 for (i = 0; i < size; i += blocksize) {
542 sprintf (dispbuf, "%04lX\b\b\b\b", i / blocksize);
543 testm_puts (quiet, dispbuf);
545 test_stage[stage].test_check1 (quiet, startaddr + i,
547 &rdatapat)) != NULL) {
548 status = TEST_FAILED;
551 sprintf (dispbuf, "\n");
552 testm_puts (quiet, dispbuf);
553 if ((quiet & TEST_SHOW_PROG) == TEST_SHOW_PROG) {
557 if (test_stage[stage].test_check2 != NULL) {
559 sprintf (dispbuf, "2nd checking block: ");
560 rdatapat = 0x12345678;
561 testm_puts (quiet, dispbuf);
562 for (i = 0; i < size; i += blocksize) {
563 sprintf (dispbuf, "%04lX\b\b\b\b", i / blocksize);
564 testm_puts (quiet, dispbuf);
566 test_stage[stage].test_check2 (quiet, startaddr + i,
568 &rdatapat)) != NULL) {
569 status = TEST_FAILED;
572 sprintf (dispbuf, "\n");
573 testm_puts (quiet, dispbuf);
574 if ((quiet & TEST_SHOW_PROG) == TEST_SHOW_PROG) {
581 if ((quiet & TEST_SHOW_PROG) == TEST_SHOW_PROG) {
586 if (status == TEST_FAILED)