1. Analysis of the Relationship between the ECC of yaffs and the ECC of mtd in the yaffs File System:
From this function in the yaffs_mtdif.c file, we can easily see their connection: int nandmtd_readchunkfromnand (yaffs_device * Dev, int chunkinnand, _ u8 * data, yaffs_spare * Spare)
{
Struct mtd_info * MTD = (struct mtd_info *) (Dev-> genericdevice );
Size_t dummy;
Int retval = 0;
Loff_t ADDR = (loff_t) chunkinnand) * Dev-> nbytesperchunk;
_ U8 * spareasbytes = (_ u8 *) Spare;
# Ifndef config_yaffs_use_old_mtd
If (Data & spare)
{
If (Dev-> usenandecc)/* If config_yaffs_use_nandecc is configured, this value is 1; otherwise, it is 0 */
{// Careful, this call adds 2 ints to the end of the spare data. Calling function shoshould
// Allocate enough memory for spare, I. e. [yaffs_bytes_per_spare + 2 * sizeof (INT)].
Retval = MTD-> read_ecc (MTD, ADDR, Dev-> nbytesperchunk, & dummy, Data, spareasbytes, & yaffs_oobinfo );
}
Else
{
Retval = MTD-> read_ecc (MTD, ADDR, Dev-> nbytesperchunk, & dummy, Data, spareasbytes, & yaffs_noeccinfo );
}
}
Else
{
# Endif
If (data)
Retval = MTD-> Read (MTD, ADDR, Dev-> nbytesperchunk, & dummy, data );
If (spare)
Retval = MTD-> read_oob (MTD, ADDR, yaffs_bytes_per_spare, & dummy, spareasbytes );
# Ifndef config_yaffs_use_old_mtd
}
# Endif if (retval = 0)
Return yaffs_ OK;
Else
Return yaffs_fail;
} The above MTD-> read_ecc and MTD-> write_ecc are defined in drivers/MTD/NAND. C. The ECC-related code is excerpted as follows:
// Use chip default if zero
If (oobsel = NULL)/* oobsel comes from the last parameter called by MTD-> read_ecc */
Oobsel = & MTD-> oobinfo;
/* If config_yaffs_use_nandecc is configured,
* Oobsel-> useecc passed from MTD-> read_ecc is 1, otherwise it is 0
* This-> the eccmode value is specified in NAND. C, which determines the ECC type used by the MTD device.
*/
Eccmode = oobsel-> useecc? This-> eccmode: nand_ecc_none;
......
Switch (eccmode ){
Case nand_ecc_none:
This-> read_buf (MTD, data_poi, end );
......
Break;
Case nand_ecc_soft:/* Software ECC 3/256: read in a page + OOB data */
This-> read_buf (MTD, data_poi, end );
/* Calculate the ECC Code */
This-> calculate_ecc (MTD, & data_poi [0], & ecc_calc [0]);
......
Break;
Case nand_ecc_hw3_256:
..........
Obtain the ECC code through hardware mechanism
..........
}
......
/* OOB contains ECC, if eccmode! = Nand_ecc_none,
* These ECC codes will be verified with the ECC codes calculated above.
*/
Read OOB
......
/* Skip ECC, if not active */
If (eccmode = nand_ecc_none)
Goto readdata;
......
Verification Based on ECC
The ECC code in ...... yaffs consists of two parts: an ECC code of 512 bytes of data and an ECC Code of 8 bytes of tags in OOB.
1. ECC code for 512 bytes of data:
Taking a chunk in flash as an example, the first 512 bytes of data are stored, and the following 16 bytes of OOB are based on the 512 bytes
The ECC code calculated from the data. When the yaffs file system needs to read a chunk data
You can use either of the following methods:
1.1 When config_yaffs_use_old_mtd is configured in yaffs, the following statement is used to read data without the ECC verification of MTD.
Whether ECC verification is performed depends on whether yaffs configures config_yaffs_use_nandecc:
If config_yaffs_use_nandecc is configured, the ECC function of yaffs is not used, so there is no ECC verification.
If config_yaffs_use_nandecc is not configured, use the ECC function of yaffs.
Retval = MTD-> Read (MTD, ADDR, Dev-> nbytesperchunk, & dummy, data );
If (spare)
Retval = MTD-> read_oob (MTD, ADDR, yaffs_bytes_per_spare, & dummy, spareasbytes );
1.2 When config_yaffs_use_old_mtd is not configured in yaffs, use the following statement to read data or use the mtd ecc function,
Either use the ECC function of yaffs, depending on whether to configure config_yaffs_use_nandecc:
If (Dev-> usenandecc)
{// Careful, this call adds 2 ints to the end of the spare data. Calling function shoshould
// Allocate enough memory for spare, I. e. [yaffs_bytes_per_spare + 2 * sizeof (INT)].
Retval = MTD-> read_ecc (MTD, ADDR, Dev-> nbytesperchunk, & dummy, Data, spareasbytes, & yaffs_oobinfo );
}
Else
{
Retval = MTD-> read_ecc (MTD, ADDR, Dev-> nbytesperchunk, & dummy, Data, spareasbytes, & yaffs_noeccinfo );
}
2. The eight-byte tags ECC code in OOB:
Use the ECC function of yaffs
ECC is summarized as follows:
1. Who uses ECC:
Config_yaffs_use_old_mtd config_yaffs_use_nandecc ECC of the 512-byte ECC tags
Y none yaffs
Y n yaffs
N y MTD yaffs
N yaffs
2. mtd ecc function type. You can specify the mtd ecc function used by a NAND flash in NAND. C:
2.1 nand_ecc_none/* do not use ECC */
2.2 nand_ecc_soft
2.3 nand_ecc_hw3_256
2.4 nand_ecc_hw3_512
2.5 nand_ecc_hw6_512
2.6 nand_ecc_diskonchip