Nandflash驅動移植系列文章導航:
Nandflash 驅動移植 (一)
Nandflash 驅動移植 (二)
Nandflash 驅動移植 (三)
Nandflash 驅動移植 (四)
Nandflash 驅動移植 (五)
Nandflash 驅動移植 (六)
一共六篇
這裡將會介紹一下S3C6410CPU中的NFCON,Nandflash控制寄存器
8.1 OVERVIEW
Recently NOR flash memory price has increased and pr ice for SDRAM and a NAND flash memory is moderatly placed.
The 6410 is equipped with an internal SRAM buffer called ‘Steppingstone’.
Generally, the boot code will copy NAND flash content to SDRAM. Using hardware ECC, the NAND flash data
validity will be checked. After the NAND flash content is copied to SDRAM, main program will be executed on SDRAM.
To use NAND Flash, 'XSELNAND' pin must be connected to High Level.
8.2 FEATURES
NAND flash controller features include:
1. NAND Flash memory I/F: Support 512Bytes and 2KB Page .
2. Software mode: User can directly access NAND flash memory. for example this feature can be used in read/erase/program NAND flash memory.
3. Interface: 8-bit NAND flash memory interface bus.
4. Hardware ECC generation, detection and indication (Software correction).
硬體產生ECC,軟體矯正
5. Support both SLC and MLC NAND flash memory : 1-bit ECC, 4-bit and 8-bit ECC for NAND flash.
(Recommend: 1bit ECC for SLC, 4bit and 8bit ECC for MLC NAND Flash)
同時支援SLC和MLC的Nandflash:1bit ECC用於SLC Nandflash, 4bit和8bit ECC用於MLC Nandflash
6. SFR I/F: Support Byte/half word/word access to Data and ECC Data register, and Word access to other registers
7. SteppingStone I/F: Support Byte/half word/word access.
8. The Steppingstone 8-KB internal SRAM buffer can be used for another purpose .
其他的這裡就不廢話了,大家看迴文檔吧。
其中要注意的地方:
Both 4bit and 8bit ECC modules can be used for only 512 bytes ECC parity code generation.
4bit和8bit的ECC模組同時能夠用於產生每讀寫512位元組資料對應的ECC校正值。
4 bit and 8bit ECC modules generate the parity codes for each 512 byte. However, 1 bit ECC modules generate
parity code per byte lane separately.
4bit ECC modules generate max 7byte parity codes and 8 bit ECC modules generate 13byte parity codes at each
512/24 bytes.
在每讀寫512或24位元組的資料時,4bit的ECC模組產生最多7個位元組的ECC校正碼,而8bit的ECC模組產生最多13位元組的校正碼
下面直接來看8bit ECC的編解碼:
8.8.5 8-BIT ECC PROGRAMMING GUIDE (ENCODING)
1. To use 8-bit ECC in software mode, set the Ms gLength to 0(512-byte message length) and set the ECCType
to “01”(enable 8-bit ECC). ECC module generates ECC parit y code for 512-byte write data. In order to start
the ECC module, you have to write ‘1’ on the Init MECC (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 8bit ECC, MainECCLock should be cleared before initiating InitMECC.
2. Whenever data is written, the 8bit 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, NFMECC1, NF8MECC2, NF8MECC3 regi ster. You have to check encoding done at NFSTAT
register. And set the MainECCLock bit to ‘1’(lock). If you use 512-byte page size 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 par ity codes to other memory
like DRAM. After writing all main data, you c an write the copied ECC values to spare area.
The parity codes have self-correctable information include parity code itself.
4. To generate spare area ECC parity code, set the MsgLength to 1(24-byte message length), and set the
ECCType to “01”(enable 8bit ECC). 8bit 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 8bit ECC, MainECCLock should be cleared before initiating InitMECC.
5. Whenever data is written, the 8bit ECC module generates ECC parity code internally.
6. When you finish writing 24-byte meta or extra data, the parity codes are automatically updated to
NF8MECC0, NFMECC1, NF8MECC2, NF8MECC3 register. you have to check encoding done at NFSTAT
register. And set the MainECCLock bit to ‘1’(lock) . You can program these parity codes to spare area. The
parity codes have self-correctable information include parity code itself.
部分譯文:(僅供參考)
8bit ECC編碼:1、要用8bit的ECC,需要設定MsgLength 為0(512-byte message length) 和設定ECCTypet為 “01”(enable 8bit ECC)。8bit ECC模組會在讀取512位元組主要資料之後產生對應的ECC校正碼。要8bit的ECC模組開始工作,你必須在設定InitMECC (NFCONT[5])為1之前把MainECCLock (NFCONT[7]) 清0進行解鎖。MainECCLock (NFCONT[7]) 位控制著是否要產生對應的ECC校正碼。注意:在8bit ECC中,MainECCLock必須先清0,然後在對InitMECC置12、資料一旦寫完,MLC的ECC模組就會產生對應的ECC校正碼。3、當你完成了512位元組的主要資料的寫操作(不包括備用區資料),對應的ECC校正碼將會自動的更新到NFM8ECC0, NFM8ECC1, NFM8ECC2, NFM8ECC3寄存器中。你必須在NFSTAT寄存器中檢測編碼是否完成(在這裡應該是NFSTAT[7],不知道為什麼文檔中的NFSTAT寄存器中的7bit為保留位,而三星的MLC
bsp中卻有用到這個位,這個情況大家可以推敲下)。同時,設定MainECCLock 為1加鎖。如果你用的是512位元組頁大小的Nandflash儲存,你可以直接把這些產生的ECC校正碼寫到備用區中。如果你使用的Nandflash儲存超過了512位元組的頁大小,你不能夠直接把產生的ECC校正碼寫到備用區中。在這種情況,你必須把每寫512位元組主要資料產生的ECC校正碼拷貝到其他儲存空間中,如DRAM。當寫完所有的主要資料(即一頁大小的主要資料),你可以把拷貝到其他儲存空間的ECC校正碼寫到備用區中。這個校正碼帶有自身矯正的資訊和校正碼值。
剩下的ECC讀寫基本雷同,這裡就不翻譯了。
8.8.6 8-BIT ECC PROGRAMMING GUIDE (DECODING)
1. To use 8bit ECC in software mode, set the MsgLength to 0(512-byte message length) and set the ECCType
to “01”(enable 8bit ECC). 8bit ECC module generates E CC parity code for 512-byte read data. In order to
initiating 8bit ECC 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 8bit ECC, MainECCLock should be cleared before InitMECC
2. Whenever data is read, the MLC ECC m odule generates ECC parity code internally.
3. After you complete reading 512-byte data (not including spare area data), you must set the MainECCLock
(NFCONT[7]) bit to ‘1’(Lock) after reading parity codes. 8bit 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, 8bit ECC engine starts searching any error
internally. 8bit ECC error searching engine needs mini mum 372 cycles to find any error. And set the
MainECCLock bit to ‘1’(lock). 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 exists, 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 8bit ECC). ECC module generates the ECC parity code for 24-byte data. In order to initiating the
8bit ECC 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 8bit ECC, MainECCLock should be cleared before InitMECC
7. Whenever data is read, the 8bit ECC module generates ECC parity code internally.
8. After you complete reading 24-byte, you must set the MainECCLock (NFCONT[7]) bit to ‘1’(Lock) after read
ing the parity code for 24-byte data. MLC ECC module needs parity codes to detect w hether error bits exists
or not. So you have to read ECC parity codes right after reading 24-byte data. Once ECC parity code is read,
8bit ECC engine starts searching any error internally. 8bit ECC error searching engine needs minimum 372
cycles to find any error. And set the MainECCLock bit to ‘1’(lock). ECCDecDone(NFSTAT[6]) can be used to
check whether ECC decoding is completed or not.
9. When ECCDecDone (NFSTAT[6]) is set (‘1’), NF8ECCERR0 indicates whether error bit exist or not. If any
error exists, you can fix it by referencing NF8ECCERR0/1/2 and NF8MLCBITPT register.
部分譯文:(僅供參考)
8bit ECC解碼:1、要用8bit的ECC,需要設定MsgLength 為0(512-byte message length) 和設定ECCTypet為 “01”(enable 8bit ECC)。8bit ECC模組會在讀取512位元組主要資料之後產生對應的ECC校正碼。要8bit的ECC模組開始工作,你必須在設定InitMECC (NFCONT[5])為1之前把MainECCLock (NFCONT[7]) 清0進行解鎖。MainECCLock (NFCONT[7]) 位控制著是否要產生對應的ECC校正碼。注意:在8bit ECC中,MainECCLock必須先清0,然後在對InitMECC置12、資料一旦被讀取,MLC的ECC模組就會產生對應的ECC校正碼。3、在完成讀取512位元組的主要資料後(不包括備用區資料),讀取對應的主要資料區的校正碼,然後必須設定MainECCLock(NFCONT[7])位為1,鎖住ECC的產生。8bit 的ECC模組需要這個校正碼來確定是否有錯誤位的存在。所以你必須在讀取完512位元組的主要資料之後,把對應的主要資料區的ECC校正碼讀取出來。一旦主要資料區對應的ECC校正碼被讀,8bit的ECC引擎就會開始尋找錯誤。8bit的ECC錯誤尋找引擎需要最少372個周期去尋找存在的錯誤。同時設定MainECCLock位為1,加鎖。ECCDecDone(NFSTAT[6])
可以用於檢測ECC解碼是否完成。4、當ECCDecDone (NFSTAT[6])設定為1,NF8ECCERR0會指出是否有錯誤位的存在。如果有錯誤存在,你可以用NF8ECCERR0/1/2和NFMLC8BITPT0/1去修正相應的錯誤。5、如果你有更多的主要資料要讀取,則從第一步開始重複操作。
PS: 原文中有些寄存器是寫錯的,大家在看的時候要注意。
吐槽一下,三星這個文檔實在是簡陋的可以,而且錯誤的地方還很多,想不BS一下都不成。
在這裡有個地方要注意的是:
在寫資料到Nandflash的時候,每寫512位元組就會產生一次ECC,我們這裡用的是4K頁,大於512位元組,所以必須把產生的ECC校正值儲存起來,等到一頁(4k)寫完,再把這些ECC寫入到備用區中。
而在讀取資料的時候,卻是每讀取512位元組的主要資料,就會產生一次ECC,這時就要進行ECC校正、矯正了。和寫的時候不大一樣,需要注意這一點。
寄存器部分:
紅色框住是主要使用的寄存器和8bit ECC所用到的寄存器。
主要用到的寄存器就到這了,下一篇將開始代碼部分。