]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/Marvell/common/ecctest.c
nand: remove CONFIG_SYS_NAND_PAGE_SIZE
[karo-tx-uboot.git] / board / Marvell / common / ecctest.c
1 /*
2  * (C) Copyright 2001
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #ifdef ECC_TEST
8 static inline void ecc_off (void)
9 {
10         *(volatile int *) (INTERNAL_REG_BASE_ADDR + 0x4b4) &= ~0x00200000;
11 }
12
13 static inline void ecc_on (void)
14 {
15         *(volatile int *) (INTERNAL_REG_BASE_ADDR + 0x4b4) |= 0x00200000;
16 }
17
18 static int putshex (const char *buf, int len)
19 {
20         int i;
21
22         for (i = 0; i < len; i++) {
23                 printf ("%02x", buf[i]);
24         }
25         return 0;
26 }
27
28 static int char_memcpy (void *d, const void *s, int len)
29 {
30         int i;
31         char *cd = d;
32         const char *cs = s;
33
34         for (i = 0; i < len; i++) {
35                 *(cd++) = *(cs++);
36         }
37         return 0;
38 }
39
40 static int memory_test (char *buf)
41 {
42         const char src[][16] = {
43                 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
44                 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
45                  0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
46                 {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
47                  0x02, 0x02, 0x02, 0x02, 0x02, 0x02},
48                 {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
49                  0x04, 0x04, 0x04, 0x04, 0x04, 0x04},
50                 {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
51                  0x08, 0x08, 0x08, 0x08, 0x08, 0x08},
52                 {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
53                  0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
54                 {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
55                  0x20, 0x20, 0x20, 0x20, 0x20, 0x20},
56                 {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
57                  0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
58                 {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
59                  0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
60                 {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
61                  0x55, 0x55, 0x55, 0x55, 0x55, 0x55},
62                 {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
63                  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa},
64                 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
65                  0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
66         };
67         const int foo[] = { 0 };
68         int i, j, a;
69
70         printf ("\ntest @ %d %p\n", foo[0], buf);
71         for (i = 0; i < 12; i++) {
72                 for (a = 0; a < 8; a++) {
73                         const char *s = src[i] + a;
74                         int align = (unsigned) (s) & 0x7;
75
76                         /* ecc_off(); */
77                         memcpy (buf, s, 8);
78                         /* ecc_on(); */
79                         putshex (s, 8);
80                         if (memcmp (buf, s, 8)) {
81                                 putc ('\n');
82                                 putshex (buf, 8);
83                                 printf (" [FAIL] (%p) align=%d\n", s, align);
84                                 for (j = 0; j < 8; j++) {
85                                         s[j] == buf[j] ? puts ("  ") :
86                                                 printf ("%02x",
87                                                         (s[j]) ^ (buf[j]));
88                                 }
89                                 putc ('\n');
90                         } else {
91                                 printf (" [PASS] (%p) align=%d\n", s, align);
92                         }
93                         /* ecc_off(); */
94                         char_memcpy (buf, s, 8);
95                         /* ecc_on(); */
96                         putshex (s, 8);
97                         if (memcmp (buf, s, 8)) {
98                                 putc ('\n');
99                                 putshex (buf, 8);
100                                 printf (" [FAIL] (%p) align=%d\n", s, align);
101                                 for (j = 0; j < 8; j++) {
102                                         s[j] == buf[j] ? puts ("  ") :
103                                                 printf ("%02x",
104                                                         (s[j]) ^ (buf[j]));
105                                 }
106                                 putc ('\n');
107                         } else {
108                                 printf (" [PASS] (%p) align=%d\n", s, align);
109                         }
110                 }
111         }
112
113         return 0;
114 }
115 #endif