Widen page count field in blockinfo to allow lots of pages per block
[yaffs/.git] / utils / gen-ecc.c
1 // Program to generate a  column parity table for yaffs_ecc.c
2
3
4
5 // Generate a column parity byte for a byte.
6 // This byte is already aligned for the ecc.
7 // The output byte has the form:
8 // bit 7: p4
9 // bit 6: p4'
10 // bit 5: p2
11 // bit 4: p2'
12 // bit 3: p1
13 // bit 2: p1'
14 // bit 1: unused.
15 // bit 0 of the output byte holds the line parity.
16 unsigned char entry(unsigned char x)
17 {
18         unsigned char b0, b1, b2, b3, b4, b5, b6, b7;
19         unsigned char p4, p2, p1, p4p, p2p, p1p;
20         unsigned char linep;
21         unsigned char result;
22         
23         b0 = (x & 0x01) ? 1 : 0;
24         b1 = (x & 0x02) ? 1 : 0;
25         b2 = (x & 0x04) ? 1 : 0;
26         b3 = (x & 0x08) ? 1 : 0;
27         b4 = (x & 0x10) ? 1 : 0;
28         b5 = (x & 0x20) ? 1 : 0;
29         b6 = (x & 0x40) ? 1 : 0;
30         b7 = (x & 0x80) ? 1 : 0;
31         
32         p4 = b7 ^ b6 ^ b5 ^ b4;     p4p = b3 ^ b2 ^ b1 ^ b0;
33         p2 = b7 ^ b6 ^ b3 ^ b2;     p2p = b5 ^ b4 ^ b1 ^ b0;
34         p1 = b7 ^ b5 ^ b3 ^ b1;     p1p = b6 ^ b4 ^ b2 ^ b0;
35         
36         linep = p1 ^ p1p;
37         
38         result = 0;
39         if(p4)    result |= 0x80;
40         if(p4p)   result |= 0x40;
41         if(p2)    result |= 0x20;
42         if(p2p)   result |= 0x10;
43         if(p1)    result |= 0x08;
44         if(p1p)   result |= 0x04;
45         if(linep) result |= 0x01;
46         
47         //result >>= 2;
48         //if(linep) result |= 0x40;
49         
50         return result;
51         
52 }
53
54
55 int main(int argc, char *argv[])
56 {
57         unsigned i;
58         
59         printf("const unsigned char column_parity_table[] = {");
60         for(i = 0; i < 256; i++)
61         {
62                 if((i & 0xf) == 0) printf("\n");
63                 printf("0x%02x, ",entry((unsigned char) i));
64         }
65         printf("\n};\n");
66 }
67
68