对于s3c2410/6410都是大家所熟习的开发板和学习板,最近看nand的ecc,看了6410的硬件ecc,其它没有什么问题,我之前看的2410的没有多大的区别,可是对于读,
就是一直不明白为什么在读完data后,有一个write_buf的操作,如下:
static int s3c_nand_read_page_4bit(struct mtd_info *mtd, struct nand_chip *chip, uint8_t *buf, int page) { int i, stat, eccsize = chip->ecc.size;//这个eccsize就是每一组ecc所校验的data的长度。 int eccbytes = chip->ecc.bytes; int eccsteps = chip->ecc.steps; int col = 0; uint8_t *p = buf; uint32_t *mecc_pos = chip->ecc.layout->eccpos; /* Step1: read whole oob */ col = mtd->writesize; chip->cmdfunc(mtd, NAND_CMD_RNDOUT, col, -1); chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);//读取所的oob区中的数据。这其中就包含data区的和spare区的数据 col = 0; for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { chip->cmdfunc(mtd, NAND_CMD_RNDOUT, col, -1); chip->ecc.hwctl(mtd, NAND_ECC_READ); chip->read_buf(mtd, p, eccsize);//读取data chip->write_buf(mtd, chip->oob_poi + mecc_pos[0] + ((chip->ecc.steps - eccsteps) * eccbytes), eccbytes);//向fash中写入 上面读出来的ecc,但是这个肯定是写不进nand的,但这里为什么要加一个写操作呢???? chip->ecc.calculate(mtd, 0, 0); stat = chip->ecc.correct(mtd, p, 0, 0); if (stat == -1) mtd->ecc_stats.failed++; col = eccsize * (chip->ecc.steps + 1 - eccsteps); } return 0; }