s3c2146 nandflash 8 bit ECC校验

来源:互联网 发布:python爬虫有什么用 编辑:程序博客网 时间:2024/06/06 06:41

s3c2146 8 bit ECC校验(一)


控制方案:s3c2416

NANDFLASH:K9GAG08U0D (4k+218 Bytes)

1、8-BIT ECC PROGRAMMING GUIDE(ENCODING)

(1) To use 8-bit ECC in software mode, set the MsgLength to 0(512-byte message length) and set the ECCType to '01'(enable 8-bit ECC). ECC module generates ECC parity code for 512-byte write data. In order to start the ECC module, you have to write '1' on the InitMECC(NFCONT[5]) bit after cleaning the MainECCLock(NFCONT[7]) bit to '0'(Unlock).

MainECCLock(NFCONT[7]) bit controls whether ECC Parity code is generated or not.

Note: In 8 bit ECC, MainECCLock should be cleared before initiating InitMECC.

(2) Whenever data is written, the 8 bit ECC module generates ECC parity code internally.

(3) After you finish writing 512-byte data(not include spare area data), the parity codes are automatically updated to NF8MECC0, NF8MECC1, NF8MECC2, NF8MECC3 register. If you use 512-byte NAND flash memory, you can program these values directly to spare area. However, if you use NAND flash memory more than 512-byte page, you can't program immediately. In this case, you have to copy these parity codes to other memory like DRAM. After writing all main data, you can write the copied ECC values to spare area.

(4) To generate spare area ECC parity code, set the MsgLength to 1(24-byte message length), and set the ECCType to "01" (enalbe 8 bit ECC). 8 bit ECC module generates the ECC parity code for 24-byte data. In order to initiating the module, you have to write '1' on the InitMECC(NFCONT[5]) bit after clearing the MainECCLock(NFCONT[7]) bit to '0'(Unlock).

MainECCLock(NFCONT[7]) bit controls whether ECC Parity code is generated or not.

NOTE:in 8 bit ECC ,MainECCLock should be cleared before initiating InitMECC.

(5) Whenever data is written, the 8 bit ECC module generates ECC parity code internally.

(6) When you finish writing 24-byte meta or extra data, the parity code are automatically updated to NF8MECC0, NF8MECC1, NF8MECC2, NF8MECC3 register. You can program these parity codes to spare area. The parity codes have self-correctable information parity code itself.

翻译:

(1)使用8位ECC校验,要将MsgLength位设置为0(message数据长度设为512字节),同时ECCType位设置为“01”(使能8位ECC校验)。设置完成后,每写入512字节,ECC模块就会产生ECC校验码。为了使ECC模块开始工作,首先要将MainECCLock位(NFCONT[7])设置为0,然后向InitMECC(NFCONT[5])位写‘1’。

MainECCLock位(NFCONT[7])可以控制是否产生ECC校验码。

(2)只要数据被写入,8位ECC模块就会产生ECC校验码。

(3)在写入了512字节数据之后(不包括spare区数据),ECC校验码就会自动更新到寄存器NF8MECC0, NFMECC1, NFMECC2, NFMECC3中。如果你使用的NAND flash一页只有512字节数据,那么你就可以将产生的ECC校验码立即写入对应的spare区。如果你使用的NAND flash一页为2k或者4k, 那么只能先将ECC校验码存到内存里(可以建立一个数组)。等到将整页的数据完全写完后,再将保存在内存里的ECC校验码写入对应的spare区。

(4)以上的步骤是产生main区数据所对应的ECC,下面讲的是怎么产生spare区数据对应的ECC校验码。要产生spare区ECC校验码,首先将MsgLength设置为1(选择24-byte message数据长度),然后设置ECCType 为“01”(使能8位ECC)。8位ECC校验模块为每24字节产生ECC校验码。为了使ECC模块开始工作,在将MainECCLock位(NFCONT[7])设置为0后,要向InitMECCa(NFCONT[5])位写入“1”。

MainECCLock(NFCONT[7])位决定了ECC校验码是否产生。

NOTE:在8位ECC校验中,MainECCLock位在每次初始化InitMECC位之前,应该先被清零。

(5)只要数据被写入,8位ECC模块就会产生ECC校验码。

(6)当你写入了24字节spare区数据后,校验码会自动更新到NF8MECC0、NF8MECC1、NF8MECC2、NF8MECC3寄存器中。你可以将这些校验码写入spare区对应的位置。

注:在查看SAMSUNG提供的WINCE BSP源码时发现,在对spare区的数据产生ECC时,它并没有采用每24字节产生一次校验码的方式,而是采用每512字节产生一次校验码的形式。

以K9GAG08U0D为例,8bit ECC校验spare区的数据保存格式为:

[cpp] view plain copy
  1. ///////////////////////////////////////////////  
  2. // Spare Area Layout (218 bytes) for 4KByte/Page : Read_Spare_8BitECC ( Total 184 Bytes are used )  
  3. ///////////////////////////////////////////////  
  4. // +-----+-------+----------+--------------+----------+----------+----------+----------+----------+----------+----------+----------+-----------+-----------+  
  5. // | 1B     | 1B        | 2B            | 20B               | 16B       | 16B       | 16B       | 16B       | 16B       | 16B       | 16B       | 16B       | 16B           | 16B(copy) |  
  6. // | Bad    | Clean     | Reserved  | SpareContext  | Sec0 ECC  | Sec1 ECC  | Sec2 ECC  | Sec3 ECC  | Sec4 ECC  | Sec5 ECC  | Sec6 ECC  | Sec7 ECC  | Spare ECC     | Spare ECC |  
  7. // +-----+-------+----------+--------------+----------+----------+----------+----------+----------+----------+----------+----------+-----------+-----------+  

首先,向spare写入1个字节的坏块标记、1个字节的clean标记、2个字节的Reserved值,然后初始化8bit ECC校验模块,打开8bit ECC校验,向spare区写入SpareContext数据(20字节)和Main区对应的ECC校验码(16*8字节),然后取消片选,依次向NFDATA寄存器传入(512-20-16*8=)364字节的0xff,凑够512字节,然后8bit ECC模块就会产生对应的ECC校验码,把ECC校验码存入spare区(16字节的spare ECC),并将该校验码备份一份(16字节的copy spare ECC)。


2、8-BIT ECC PROGRAMMING GUIDE(DECODING)

(1) To use 8 bit ECC in software mode ,set the MsgLenght to '0'(512-byte message length) and set the ECCType to "01"(enable 8 bit ECC). 8 bit ECC module generates ECC parity code for 512-byte read data. In order to initiating 8 bit ECC module, you have to write '1' on the InitMECC(NFCONT[5]) bit after clearing the MainECCLock(NFCONT[7]) bit to "0"(Unlock).

MainECCLock bitt  controls whether ECC Parity code is generated or not.

NOTE: In 8 bit ECC, MainECCLock should be cleared before InitMECC.

(2)Whenever data is read, the ECC module generates ECC parity code internally.

(3)After you complete the reading of 512-byte data(not including spare area data), you must set the MainECCLock(NFCONT[7]) bit to "1"(Lock) and have to read parity codes. 8 bit ECC module needs parity codes to detect whether error bits exists or not. So you have to read the ECC parity code of 512-byte main data right after reading the 512-byte data. Once the ECC parity code is read, 8 bit ECC engine starts searching any error internally. 8 bit ECC error searching engine needs minimum 372 cycles to find any error.During this time, you cna continue reading data from external NAND flash memory.

ECCDecDone(NFSTAT[6]) can be used to check whether ECC decoding is completed or not.

(4)When ECCDecDone(NFSTAT[6]) is set "1", NF8ECCERR0 indicates whether error bit exists or not. If any error exits, you can fix it by referencing NF8ECCERR0/1/2 and NFMLC8BITPT0/1 register.

(5)If you have more main data to read, continue doing from step 1.

(6)For meta data error check, set the MsgLength to "1"(24-byte message length) and set the ECCType to "01"(enable 8 bit ECC). ECC module generates the ECC parity code of 24-byte data. In order to initiating the 8 bit ECC module, you have to write "1" on the InitMECC(NFCON[5]) bit after clearing the MainECCLock(NFCONT[7]) bit to "0"(Unlock).

MainECCLock bit controls whether ECC parity code is generated or not.

(7)Whenever data is read, the 8 bit ECC module generates ECC parity code internally.

(8)After you comlete reading 24-byte, you must set the MainECCLock(NFCONT[7]) bit to "1"(Lock) and read the parity code of 24-byte data. MLC ECC module need parity codes to detect whether error bit exits or not. So you have to read ECC parity codes right after reading 24-data bytes. Once ECC parity code is read, 8 bit ECC engine starts searching any error internally. 8 bit ECC error searching engine need  minimum 372 cycles to find any error. During this time, you can continue reading main data from external NAND flash memory. ECCDecDone(NFSTAT[6]) can be used to check wether ECC decoding is completed or not.

(9)When ECCDecDone(NFSTAT[6]) is set "1", NF8ECCERR0 indicates whether error bit exit or not. If any error exists, you can fix it by referencing NF8ECCERR0/1/2 and NF8MLCBITPT register.

翻译:

(1)使用8位ECC校验,首先将MsgLength位设置为0(设置message数据长度为512字节),同时ECCType位设置为“01”(使能8位ECC校验)。每读512字节数据,8位ECC校验模块就会产生ECC校验码。为了初始化8位ECC校验模块,首先要将MainECCLock(NFCONT[7])清零,然后向InitMECC(NFCONT[5])位写1。

MainECCLock位决定了ECC校验码是否产生。

NOTE:在8位ECC校验中,应该先清除MainECCLock位,再清除InitMECC位。

(2)只要数据被读取,ECC模块就会产生ECC校验码

(3)在读取512字节数据之后(不包括spare区数据),你必须把MainECCLock位设置为“1”(禁止产生ECC)并读取NANDFlash中保存的针对此512字节数据的ECC校验值。 8位ECC校验模块需要读取这些校验码来验证读取的数据是否存在错误。所以,每次读取512字节数据之后,你都需要立即读取此512字节数据对应的的校验值。 ECC校验值被读取后,8 位ECC校验模块就会开始查错。这个过程至少需要372个时钟周期。在此期间,你可以继续从NANDFLASH中读取数据。

ECCDecDone(NFSTAT[6])位可以用来判断ECC解码是否完成。

(4)当ECCDecDone位被置为“1”时, NF8ECCERR0寄存器能够表明是否存在错误。如果错误存在,你可以通过寄存器NF8ECCERR0/1/2 和 NFMLCBITPT0/1 的值来矫正这些错误。

(5)如果你要读取更多的main区数据,继续从第一步开始执行。

(6)前面几步将的是校验main区的ECC,下面讲校验spare区的数据。校验spare区, 首先将Msglength位设置为“1”(设置为24-byte message数据长度),同时将ECCType位设置为“01”(使能8位ECC校验)。ECC模块在每读取24字节的数据是生成ECC校验码。为了初始化8位ECC校验模块,首先将MainECCLock位(NFCONT[7])清零,然后向InitMECC(NFCONT[5])写“1”。

(7)只要数据被读取,8位ECC校验模块就会产生ECC校验码。

(8)当你读取24字节数据后,你必须将MainECCLock位设置为“1”,禁止产生ECC校验码,同时,你需要从NANDFLASH读出此24字节数据所对应的ECC校验码。 ECC校验模块需要这些校验码来判断读取的数据是否出现错误。所以,每当你读取24字节的spare区数据,你都要读取出此24字节数据所对应的ECC校验码。只要ECC校验码被读取,ECC模块就会开始查错。这个过程至少需要372个时钟周期。在此期间,你可以继续从NANDFLASH中读取main区数据。

ECCDecDone(NFSTAT[6])位能被用来判断ECC解码是否完成。

(9)当ECCDecDone(NFSTAT[6])位被设置为“1”时,NF8ECCERR0 表明了读取的数据是否存在错误。如果错误存在,你可以借助寄存器NF8ECCERR0/1/2 和 NF8MLCBITPT0/1的值来矫正这些错误。

s3c2416 8 bit ECC校验(二)—— 纠正位错误


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

在8 bit ECC校验中,ECC Decoding完成后,ECC模块会把校验的结果保存在NFECCERR0寄存器中,通过该寄存器,可以判断读取的数据是否存在错误。如果存在错误,那么就要借助NF8ECCERR0/1/2 和 NFMLC8BITPT0 寄存器去纠正8位以内的错误。


NF8ECCERR0/1/2三个寄存器的值在ECCDecDone(NFSTAT[6])被置为“1”的时候更新。这三个寄存器的作用就是指示读取的数据存在多少位错误,同时还能指出8位(或8位以内)的为错误分别位于哪个字节。

例如,每读取512字节就进行一次ECC校验,校验完成后,通过NF8ECCERR0[28:25]位可以知道本次读取的512字节的数据中存在多少位错误。如果((NF8ECCERR0>>25)&0xf)大于8,那么表明出现了超过8位的数据错误,无法校正。如果出现的数据错误小于8位,那么可以通过MLCErrLocation1-8来确定到底是那个字节出现了ECC错误。


NFMLC8BITPT0/1能够指出某个字节的哪个位出现了错误。

假设读取的512字节数据中,ECC模块检测到1个位错误,位于第42字节的第5位,那么矫正的思路如下:

(1)假设读取的512字节数据放入名为pMainBuf[]数组中

(2)nErrCnt = (NF8ECCERR0>>25) & 0xf ; // nErrCnt位错误计数,此处应该为1;

(3)nErrByte = NF8ECCERR0 & 0x3ff;  // nErrbyte 表明了错误位所在的字节位置,即错误在pMainBuf[nErrByte]字节。

(4)nErrBitPat = NFMLC8BITPT0 & 0xff; // nErrBitPat 可以表明错误在哪一位

(5)pMainBuf[nErrByte] = pMainBuf[nErrByte] ^ nErrBitPat; // 矫正错误



0 0
原创粉丝点击