spl mxc nand: Fix broken boot for correctable ECC errors
authorBenoît Thébaudeau <benoit.thebaudeau@advansee.com>
Mon, 13 Aug 2012 20:49:53 +0000 (22:49 +0200)
committerScott Wood <scottwood@freescale.com>
Tue, 18 Sep 2012 00:51:45 +0000 (19:51 -0500)
Do not stop boot as soon as an ECC error is detected. Only stop boot for
uncorrectable ECC errors.

This fixes boards no longer booting after some time because a NAND Flash bit has
flipped.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Scott Wood <scottwood@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Signed-off-by: Scott Wood <scottwood@freescale.com>
nand_spl/nand_boot_fsl_nfc.c

index 4c5a7feec1629aacc22d1c26ab1bd843339ea56c..ea05952eb5e1fd8c8617c742e8e1dc3f77e8332e 100644 (file)
@@ -140,9 +140,21 @@ static void nfc_nand_data_output(void)
 static int nfc_nand_check_ecc(void)
 {
 #if defined(MXC_NFC_V1)
-       return readw(&nfc->ecc_status_result);
+       u16 ecc_status = readw(&nfc->ecc_status_result);
+       return (ecc_status & 0x3) == 2 || (ecc_status >> 2) == 2;
 #elif defined(MXC_NFC_V1_1)
-       return readl(&nfc->ecc_status_result);
+       u32 ecc_status = readl(&nfc->ecc_status_result);
+       int ecc_per_page = CONFIG_SYS_NAND_PAGE_SIZE / 512;
+       int err_limit = CONFIG_SYS_NAND_SPARE_SIZE / ecc_per_page > 16 ? 8 : 4;
+       int subpages = CONFIG_SYS_NAND_PAGE_SIZE / 512;
+
+       do {
+               if ((ecc_status & 0xf) > err_limit)
+                       return 1;
+               ecc_status >>= 4;
+       } while (--subpages);
+
+       return 0;
 #endif
 }