If you are using the NAND ECC engine with BCH4 or BCH8, there is a common pitfall you want to avoid:
In case of an EMPTY PAGE (Content==FF, ECC==FF), there is NO VALID ECC in this page.
So the most simplyfied code to check the ECC in your page_read() function is:
if (ECC == FFFFFF....FF) ecc_valid = 1; else if (check(ECC) == VALID) ecc_valid = 1; else if (correct(ECC) == OK) ecc_valid = 1; else error():
This check for ECC == FF has a serious drawback: what if there is a single bit error in the ECC area? Remember: we have a NAND flash! Single bit errors are common! This single bit error will give you an uncorrectable ECC failure. Not good in production devices...
So a better check is:
if (ECC == FFFFFF....FF) ecc_valid = 1; else if (check(ECC) == VALID) ecc_valid = 1; else if (number_of_0_bits_in_ecc() < acceptable_wrong_ecc_bits) ecc_valid = 1; else .....
I choose acceptable_wrong_ecc_bits == 4 for BCH8.
This will give your code a certain degree of immunity against single bit errors.
regards
Wolfgang