27 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00,
28 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65,
29 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66,
30 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03,
31 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69,
32 0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c,
33 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f,
34 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a,
35 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a,
36 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f,
37 0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c,
38 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69,
39 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03,
40 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66,
41 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65,
42 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00
50 uint8_t idx, reg1, reg2, reg3, tmp1, tmp2;
54 reg1 = reg2 = reg3 = 0;
57 for (i = 0; i < 256; i++) {
65 reg2 ^= ~((uint8_t) i);
70 tmp1 = (reg3 & 0x80) >> 0;
71 tmp1 |= (reg2 & 0x80) >> 1;
72 tmp1 |= (reg3 & 0x40) >> 1;
73 tmp1 |= (reg2 & 0x40) >> 2;
74 tmp1 |= (reg3 & 0x20) >> 2;
75 tmp1 |= (reg2 & 0x20) >> 3;
76 tmp1 |= (reg3 & 0x10) >> 3;
77 tmp1 |= (reg2 & 0x10) >> 4;
79 tmp2 = (reg3 & 0x08) << 4;
80 tmp2 |= (reg2 & 0x08) << 3;
81 tmp2 |= (reg3 & 0x04) << 3;
82 tmp2 |= (reg2 & 0x04) << 2;
83 tmp2 |= (reg3 & 0x02) << 2;
84 tmp2 |= (reg2 & 0x02) << 1;
85 tmp2 |= (reg3 & 0x01) << 1;
86 tmp2 |= (reg2 & 0x01) << 0;
96 ecc_code[2] = ((~reg1) << 2) | 0x03;
114 u_char *read_ecc, u_char *calc_ecc)
119 s0 = calc_ecc[0] ^ read_ecc[0];
120 s1 = calc_ecc[1] ^ read_ecc[1];
121 s2 = calc_ecc[2] ^ read_ecc[2];
123 s1 = calc_ecc[0] ^ read_ecc[0];
124 s0 = calc_ecc[1] ^ read_ecc[1];
125 s2 = calc_ecc[2] ^ read_ecc[2];
131 if (((
s0 ^ (
s0 >> 1)) & 0x55) == 0x55 &&
132 ((
s1 ^ (
s1 >> 1)) & 0x55) == 0x55 &&
133 ((
s2 ^ (
s2 >> 1)) & 0x54) == 0x54) {
135 uint32_t byteoffs, bitnum;
137 byteoffs = (
s1 << 0) & 0x80;
138 byteoffs |= (
s1 << 1) & 0x40;
139 byteoffs |= (
s1 << 2) & 0x20;
140 byteoffs |= (
s1 << 3) & 0x10;
142 byteoffs |= (
s0 >> 4) & 0x08;
143 byteoffs |= (
s0 >> 3) & 0x04;
144 byteoffs |= (
s0 >> 2) & 0x02;
145 byteoffs |= (
s0 >> 1) & 0x01;
147 bitnum = (
s2 >> 5) & 0x04;
148 bitnum |= (
s2 >> 4) & 0x02;
149 bitnum |= (
s2 >> 3) & 0x01;
151 dat[byteoffs] ^= (1 << bitnum);
static int countbits(uint32_t b)
static const uint8_t nand_ecc_precalc_table[]
int nand_correct_data(struct nand_device *nand, u_char *dat, u_char *read_ecc, u_char *calc_ecc)
nand_correct_data - Detect and correct a 1 bit error for 256 byte block
int nand_calculate_ecc(struct nand_device *nand, const uint8_t *dat, uint8_t *ecc_code)
Upper level NOR flash interfaces.