Patchwork [U-Boot,07/13] spl mxc nand: Fix broken boot for correctable ECC errors

login
register
mail settings
Submitter Benoît Thébaudeau
Date Aug. 13, 2012, 8:49 p.m.
Message ID <1653384007.2374995.1344890993855.JavaMail.root@advansee.com>
Download mbox | patch
Permalink /patch/177091/
State Accepted
Commit b8fea2b27d7aeabd2e0bc4242277ff2787c7c622
Delegated to: Scott Wood
Headers show

Comments

Benoît Thébaudeau - Aug. 13, 2012, 8:49 p.m.
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>
---
 .../nand_spl/nand_boot_fsl_nfc.c                   |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Patch

diff --git u-boot-4d3c95f.orig/nand_spl/nand_boot_fsl_nfc.c u-boot-4d3c95f/nand_spl/nand_boot_fsl_nfc.c
index 4c5a7fe..ea05952 100644
--- u-boot-4d3c95f.orig/nand_spl/nand_boot_fsl_nfc.c
+++ u-boot-4d3c95f/nand_spl/nand_boot_fsl_nfc.c
@@ -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
 }