6247b45c291411d60dccad010d1ab3579da6435d
[platform/kernel/u-boot.git] / board / Marvell / common / ecctest.c
1 indent: Standard input:49: Warning:old style assignment ambiguity in "=*".  Assuming "= *"
2
3 /*
4  * (C) Copyright 2001
5  *
6  * See file CREDITS for list of people who contributed to this
7  * project.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  */
24
25 #ifdef ECC_TEST
26 static inline void ecc_off (void)
27 {
28         *(volatile int *) (INTERNAL_REG_BASE_ADDR + 0x4b4) &= ~0x00200000;
29 }
30
31 static inline void ecc_on (void)
32 {
33         *(volatile int *) (INTERNAL_REG_BASE_ADDR + 0x4b4) |= 0x00200000;
34 }
35
36 static int putshex (const char *buf, int len)
37 {
38         int i;
39
40         for (i = 0; i < len; i++) {
41                 printf ("%02x", buf[i]);
42         }
43         return 0;
44 }
45
46 static int char_memcpy (void *d, const void *s, int len)
47 {
48         int i;
49         char *cd = d;
50         const char *cs = s;
51
52         for (i = 0; i < len; i++) {
53                 *(cd++) = *(cs++);
54         }
55         return 0;
56 }
57
58 static int memory_test (char *buf)
59 {
60         const char src[][16] = {
61                 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
62                 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
63                  0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
64                 {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
65                  0x02, 0x02, 0x02, 0x02, 0x02, 0x02},
66                 {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
67                  0x04, 0x04, 0x04, 0x04, 0x04, 0x04},
68                 {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
69                  0x08, 0x08, 0x08, 0x08, 0x08, 0x08},
70                 {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
71                  0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
72                 {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
73                  0x20, 0x20, 0x20, 0x20, 0x20, 0x20},
74                 {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
75                  0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
76                 {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
77                  0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
78                 {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
79                  0x55, 0x55, 0x55, 0x55, 0x55, 0x55},
80                 {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
81                  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa},
82                 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
83                  0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
84         };
85         const int foo[] = { 0 };
86         int i, j, a;
87
88         printf ("\ntest @ %d %p\n", foo[0], buf);
89         for (i = 0; i < 12; i++) {
90                 for (a = 0; a < 8; a++) {
91                         const char *s = src[i] + a;
92                         int align = (unsigned) (s) & 0x7;
93
94                         /* ecc_off(); */
95                         memcpy (buf, s, 8);
96                         /* ecc_on(); */
97                         putshex (s, 8);
98                         if (memcmp (buf, s, 8)) {
99                                 putc ('\n');
100                                 putshex (buf, 8);
101                                 printf (" [FAIL] (%p) align=%d\n", s, align);
102                                 for (j = 0; j < 8; j++) {
103                                         s[j] == buf[j] ? puts ("  ") :
104                                                 printf ("%02x",
105                                                         (s[j]) ^ (buf[j]));
106                                 }
107                                 putc ('\n');
108                         } else {
109                                 printf (" [PASS] (%p) align=%d\n", s, align);
110                         }
111                         /* ecc_off(); */
112                         char_memcpy (buf, s, 8);
113                         /* ecc_on(); */
114                         putshex (s, 8);
115                         if (memcmp (buf, s, 8)) {
116                                 putc ('\n');
117                                 putshex (buf, 8);
118                                 printf (" [FAIL] (%p) align=%d\n", s, align);
119                                 for (j = 0; j < 8; j++) {
120                                         s[j] == buf[j] ? puts ("  ") :
121                                                 printf ("%02x",
122                                                         (s[j]) ^ (buf[j]));
123                                 }
124                                 putc ('\n');
125                         } else {
126                                 printf (" [PASS] (%p) align=%d\n", s, align);
127                         }
128                 }
129         }
130
131         return 0;
132 }
133 #endif