]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
spl, nand: add 4bit HW ecc oob first nand_read_page function
authorHeiko Schocher <hs@denx.de>
Sat, 16 Jul 2011 00:06:49 +0000 (00:06 +0000)
committerScott Wood <scottwood@freescale.com>
Mon, 3 Oct 2011 23:35:12 +0000 (18:35 -0500)
Signed-off-by: Heiko Schocher <hs@denx.de>
cc: Scott Wood <scottwood@freescale.com>
Signed-off-by: Scott Wood <scottwood@freescale.com>
nand_spl/nand_boot.c

index 4683c7c52c33e216d7c64a677ee9322250e16b23..615ef258a8c6e5715398d587ce71d65abf4c884d 100644 (file)
@@ -135,6 +135,47 @@ static int nand_is_bad_block(struct mtd_info *mtd, int block)
        return 0;
 }
 
+#if defined(CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST)
+static int nand_read_page(struct mtd_info *mtd, int block, int page, uchar *dst)
+{
+       struct nand_chip *this = mtd->priv;
+       u_char *ecc_calc;
+       u_char *ecc_code;
+       u_char *oob_data;
+       int i;
+       int eccsize = CONFIG_SYS_NAND_ECCSIZE;
+       int eccbytes = CONFIG_SYS_NAND_ECCBYTES;
+       int eccsteps = CONFIG_SYS_NAND_ECCSTEPS;
+       uint8_t *p = dst;
+       int stat;
+
+       /*
+        * No malloc available for now, just use some temporary locations
+        * in SDRAM
+        */
+       ecc_calc = (u_char *)(CONFIG_SYS_SDRAM_BASE + 0x10000);
+       ecc_code = ecc_calc + 0x100;
+       oob_data = ecc_calc + 0x200;
+
+       nand_command(mtd, block, page, 0, NAND_CMD_READOOB);
+       this->read_buf(mtd, oob_data, CONFIG_SYS_NAND_OOBSIZE);
+       nand_command(mtd, block, page, 0, NAND_CMD_READ0);
+
+       /* Pick the ECC bytes out of the oob data */
+       for (i = 0; i < CONFIG_SYS_NAND_ECCTOTAL; i++)
+               ecc_code[i] = oob_data[nand_ecc_pos[i]];
+
+
+       for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
+               this->ecc.hwctl(mtd, NAND_ECC_READ);
+               this->read_buf(mtd, p, eccsize);
+               this->ecc.calculate(mtd, p, &ecc_calc[i]);
+               stat = this->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
+       }
+
+       return 0;
+}
+#else
 static int nand_read_page(struct mtd_info *mtd, int block, int page, uchar *dst)
 {
        struct nand_chip *this = mtd->priv;
@@ -181,6 +222,7 @@ static int nand_read_page(struct mtd_info *mtd, int block, int page, uchar *dst)
 
        return 0;
 }
+#endif /* #if defined(CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST) */
 
 static int nand_load(struct mtd_info *mtd, unsigned int offs,
                     unsigned int uboot_size, uchar *dst)