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