nand_calculate_ecc_kw() function
Reed-Solomon code This implements a (1023,1015) Reed-Solomon ECC code over GF(2^10) mod x^10 + x^3 + 1, shortened to (520,512). The ECC data consists of 8 10-bit symbols, or 10 8-bit bytes. Given 512 bytes of data, computes 10 bytes of ECC. This is done by converting the 512 bytes to 512 10-bit symbols (elements of F), interpreting those symbols as a polynomial in F[X] by taking symbol 0 as the coefficient of X^8 and symbol 511 as the coefficient of X^519, and calculating the residue of that polynomial divided by the generator polynomial, which gives us the 8 ECC symbols as the remainder. Finally, we convert the 8 10-bit ECC symbols to 10 8-bit bytes. The generator polynomial is hardcoded, as that is faster, but it can be computed by taking the primitive element a = x (in F), and constructing a polynomial in F[X] with roots a, a^2, a^3, ..., a^8 by multiplying the minimal polynomials for those roots (which are just 'x - a^i' for each i). Note: due to unfortunate circumstances, the bootrom in the Kirkwood SOC expects the ECC to be computed backward, i.e. from the last byte down to the first one.