16
Nand Flash Interface Nand Flash Interface Represented by Sneeker Yeh 2010 March.

Introduction to Nand Flash interface (chinese)

Embed Size (px)

Citation preview

Nand Flash InterfaceNand Flash Interface

Represented by Sneeker Yeh

2010 March.

OutlineOutline• Introduction

• Nandflash operation

• WinCE image layout

• Case study 1

• Case study 2

IntroductionIntroduction• 下圖為下圖為 nand flashnand flash 的範例的範例 (K9F2G08X0A)(K9F2G08X0A)

• I/OI/O 腳位不只可將資料腳位不只可將資料 input or output, input or output, 也可以也可以 inputinput 命令與位址命令與位址 ..

• 若若 flashflash 結構為結構為 1616 位元位元 (16(16 支支 I/OI/O 腳)腳) , , 資料的運輸則以資料的運輸則以 1616 位元位元為單位為單位 ,, 命令與位址則仍然維持八位元的形式命令與位址則仍然維持八位元的形式 (( 似乎是約定俗成的規似乎是約定俗成的規則則 ))

IntroductionIntroduction• 將一筆資料寫入將一筆資料寫入 nand flash nand flash 的時序圖的時序圖

• 信號的信號的 pulse widthpulse width 由由 controllercontroller 來管理來管理 , programmer, programmer 只需準備只需準備命令命令 , , 位址資訊位址資訊 , , 資料資料 , controller, controller 會將這些訊息有條不紊地輸入會將這些訊息有條不紊地輸入到到 nand flash.nand flash.

• programmerprogrammer 只需注意每個命令與定址資訊的間隔只需注意每個命令與定址資訊的間隔 , , 會由專屬的會由專屬的status regstatus reg 或發出中斷兩種方法來表示或發出中斷兩種方法來表示 , , 等到該等到該 operationoperation 完成完成後後 , , 才能繼續操作才能繼續操作 controllercontroller 執行下一步動作執行下一步動作

IntroductionIntroduction

控制器會在 I/O 上寫入” 00h 讀取命令”並控制CLE, WE, CE, ALE, RE 來表示該操作為” input command”

Programmer 要注意該操作是否結束 ( 輪詢狀態暫存器或中斷發生 ), 才能進行下個操作

Nandflash operationNandflash operation

Buffer[0]Buffer[0](512 bytes)(512 bytes)

Buffer[1]Buffer[1](512 bytes)(512 bytes)

Buffer[2]Buffer[2](512 bytes)(512 bytes)

Buffer[3]Buffer[3](512 bytes)(512 bytes)

Spare_buf[0]Spare_buf[0](16 bytes)(16 bytes)

Spare_buf[1]Spare_buf[1](16 bytes)(16 bytes)

Spare_buf[2]Spare_buf[2](16 bytes)(16 bytes)

Spare_buf[3]Spare_buf[3](16 bytes)(16 bytes)

Page 4Page 4Page 5Page 5

Nand flashiMX31 controller buffer

Page read

Nandflash operation Nandflash operation • Nand flashNand flash 的寫入與讀取規則皆必須以一個的寫入與讀取規則皆必須以一個 pagepage 為單位為單位

• 然而寫入動作必須有額外的遊戲規則然而寫入動作必須有額外的遊戲規則 , , 要寫入的區域其要寫入的區域其內容必須皆為內容必須皆為 0xff. 0xff.

• Write 1 on 1 -> 1Write 1 on 1 -> 1

• Write 0 on 1 -> 0Write 0 on 1 -> 0

• Write 1 on 0 -> 0Write 1 on 0 -> 0

• Write 0 on 0 -> 0Write 0 on 0 -> 0

• Nand flash Nand flash 提供了提供了 erase commanderase command 讓讓programmerprogrammer 可以將內容轉變為可以將內容轉變為 0xff, erase0xff, erase 的單位為的單位為一個一個 block.block.

0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff0xffffffff

Nandflash operationNandflash operation

Buffer[0]Buffer[0](512 bytes)(512 bytes)

Buffer[1]Buffer[1](512 bytes)(512 bytes)

Buffer[2]Buffer[2](512 bytes)(512 bytes)

Buffer[3]Buffer[3](512 bytes)(512 bytes)

Spare_buf[0]Spare_buf[0](16 bytes)(16 bytes)

Spare_buf[1]Spare_buf[1](16 bytes)(16 bytes)

Spare_buf[2]Spare_buf[2](16 bytes)(16 bytes)

Spare_buf[3]Spare_buf[3](16 bytes)(16 bytes)

0xaaaaaaaa0xaaaaaaaa

Nand flashiMX31 controller buffer

Page 的寫入前如果不確定是不是 0xff, 要記得先操除 (erase)喔

Block 0

Case study 1 : Garbage Case study 1 : Garbage Collection – 1/3Collection – 1/3

File 1

File 1

File 3

File 3

File 3

File 2

File 3 (new)

File 3 (new)

File 3 (new)

Invalid

Invalid

Invalid

File 4

Invalid

Invalid

Invalid

Block 0 Block 1 Block 2 Block 3

• 原由原由 :read/write:read/write 與與 eraseerase 的單位是不一樣的的單位是不一樣的 ..

• 因此在資料讀寫的操作上會有因此在資料讀寫的操作上會有 invalid pageinvalid page 的觀念的觀念 , , 若要將一筆資料刪除若要將一筆資料刪除 , , 只只要在記憶體準備一個要在記憶體準備一個 tabletable 並將資料所佔用的並將資料所佔用的 page markpage mark 成成 invalidinvalid 即可即可 ..

• 若要將一筆資料如若要將一筆資料如 file 3file 3 更新更新 flash, flash, 只要尋找足夠的只要尋找足夠的 free pagefree page 寫入寫入 ,, 再將舊再將舊的的 file 3file 3 區域區域 markmark 成成 invalidinvalid 即可即可 , , 過程只需耗費過程只需耗費 33 個個 page writepage write 動作動作 ..

• 若沒有若沒有 tabletable 機制機制 , , 則必須先搬移出則必須先搬移出 file2(1*read), file2(1*read), 將將 block2block2 擦除擦除(1*erase), (1*erase), 將將 file2file2 及新的及新的 file3file3 寫入寫入 (4*write):(4*write):

• WriteWrite 操作比原先的機制還多了一次操作比原先的機制還多了一次 (write(write 是最耗時間的動作是最耗時間的動作 ))

File 5

File 5

File 5

File 5Invalid

Case study 1 : Garbage Case study 1 : Garbage Collection – 2/3Collection – 2/3• 接續上一個接續上一個 scenario, scenario, 若要寫入一個若要寫入一個 4page4page 大小的大小的 file5:file5:

• 執行執行 garbage collection: garbage collection: 搬移搬移 file4file4 到到 block3(1*read,1*write), block3(1*read,1*write), 擦除擦除 block0(1*erase).block0(1*erase).

• 將將 file5file5 寫入寫入 block0(4*write).block0(4*write).

File 1

File 1

File 2

File 3 (new)

File 3 (new)

File 3 (new)

Invalid

Invalid

Invalid

File 4

Invalid

Invalid

Invalid

Block 0 Block 1 Block 2 Block 3

File 4

Case study 1 : Garbage Case study 1 : Garbage Collection - 3/3Collection - 3/3• Garbage collectionGarbage collection 的演算法的演算法 issue: issue:

• garbage collectiongarbage collection 是很耗費時間是很耗費時間 . .

• 如何如何 mergemerge 出一個出一個 total freetotal free 的的 block(block( 盡量要有效率且不要有太盡量要有效率且不要有太多的碎裂情形多的碎裂情形 , for ex, , for ex, 將將 file4file4 搬至搬至 block1block1 碎裂情形較嚴重碎裂情形較嚴重 ).).

File 1

File 1

File 2

File 3 (new)

File 3 (new)

File 3 (new)

Invalid

Invalid

Invalid

File 4

Invalid

Invalid

Invalid

Block 0 Block 1 Block 2 Block 3

Case study 2 :Case study 2 : 模擬燒錄器模擬燒錄器的寫入與讀取 的寫入與讀取 – – 1/51/5

• 模擬燒錄器的寫入與讀取模擬燒錄器的寫入與讀取 ::

• 在在 iMX31 controlleriMX31 controller 具備硬體具備硬體 eccecc 產生產生 , , 硬體硬體 eccecc 偵錯偵錯 , , 硬體硬體eccecc 更正能力更正能力 , , 因此在操作上會帶來一些限制:因此在操作上會帶來一些限制:

• 在在 spare area bufferspare area buffer 有預留一塊有預留一塊 ecc codeecc code 區域區域 , , programmerprogrammer 所寫入的值將會被硬體忽略所寫入的值將會被硬體忽略 , , 因為硬體會自動產生因為硬體會自動產生偵錯所需的偵錯所需的 ecc codeecc code 寫入對應的寫入對應的 spare area.spare area.

• 當硬體讀取一個當硬體讀取一個 pagepage 時時 , , 並不會將並不會將 ecc codeecc code 放置對應的放置對應的spare area buffer, spare area buffer, 而且讀入其他邏輯電路並且執行錯誤偵測與而且讀入其他邏輯電路並且執行錯誤偵測與更正更正 ..

模擬燒錄器的寫入 模擬燒錄器的寫入 – – 2/52/5• 因此在預設情況下因此在預設情況下 , , 一個一個 pagepage 的的 2112 bytes2112 bytes 中中 , , 有少許作為有少許作為 eccecc

存放的區域是無法讓存放的區域是無法讓 programmerprogrammer 寫值進去的寫值進去的 ::

• 然而然而 , , 若我們擁有若我們擁有 raw image (raw image ( 包含所有包含所有 spare area, include ecc), spare area, include ecc), 並且我們想要將模擬燒錄器燒錄並且我們想要將模擬燒錄器燒錄 nandflashnandflash 行為行為 , , 將整個將整個 imageimage 燒入燒入flash:flash:

• 我們可以設定我們可以設定 controllercontroller 為為 ecc disable, ecc disable, 則此時則此時 spare areaspare area bufferbuffer 的的 eccecc 區域則可以讓區域則可以讓 programmerprogrammer 自由運用自由運用 , , 並進而寫值並進而寫值 ..

• 此時我們可以完全對此時我們可以完全對 pagepage 中所有的中所有的 2112 bytes2112 bytes 寫進所需要的值寫進所需要的值 ..

模擬燒錄器的讀取 模擬燒錄器的讀取 – – 3/53/5• iMX31 controlleriMX31 controller 的缺陷的缺陷 ::

• 即使即使 disable ecc, disable ecc, 則硬體在讀取則硬體在讀取 pagepage 時時 , , 仍會將仍會將 ecc codeecc code 讀入讀入其他邏輯電路並且執行錯誤偵測其他邏輯電路並且執行錯誤偵測 ,, 並不會將並不會將 ecc codeecc code 放置對應的放置對應的spare area buffer(spare area buffer( 此時此時 disabledisable 的是更正能力的是更正能力 ). ).

• 所以我們必須要有額外的策略將所以我們必須要有額外的策略將 pagepage 中所有的中所有的 2112byte2112byte 讀取出讀取出來來 , , 否則我們無法製作出燒錄器所需要的否則我們無法製作出燒錄器所需要的 raw data.raw data.

模擬燒錄器的讀取 模擬燒錄器的讀取 – – 4/54/5• ControllerController 對對 nand flashnand flash 上上 pagepage 的觀點的觀點 , , 每每 512byte512byte伴隨一段伴隨一段 64byte 64byte 的的

spare area(ecc, and other metadata).spare area(ecc, and other metadata).

• controllercontroller 會進行四次會進行四次 get dataget data 的動作的動作 (( 每次抓取每次抓取 528bytes), 528bytes), 才可以完成一次才可以完成一次pagepage 的讀取的讀取 Buffer[0]Buffer[0]

(512 bytes)(512 bytes)

Buffer[1]Buffer[1](512 bytes)(512 bytes)

Buffer[2]Buffer[2](512 bytes)(512 bytes)

Buffer[3]Buffer[3](512 bytes)(512 bytes)

Spare_buf[0]Spare_buf[0](16 bytes)(16 bytes)

Spare_buf[1]Spare_buf[1](16 bytes)(16 bytes)

Spare_buf[2]Spare_buf[2](16 bytes)(16 bytes)

Spare_buf[3]Spare_buf[3](16 bytes)(16 bytes)

Buffer[0]Buffer[0](512 bytes)(512 bytes)

Buffer[1]Buffer[1](512 bytes)(512 bytes)

Buffer[2]Buffer[2](512 bytes)(512 bytes)

Buffer[3]Buffer[3](512 bytes)(512 bytes)

Spare_buf[0]Spare_buf[0](16 bytes)(16 bytes)

Spare_buf[1]Spare_buf[1](16 bytes)(16 bytes)

Spare_buf[2]Spare_buf[2](16 bytes)(16 bytes)

Spare_buf[3]Spare_buf[3](16 bytes)(16 bytes)

Controller buffer

Nand flash structure

模擬燒錄器的讀取 模擬燒錄器的讀取 – – 5/55/5• 我們可以將四次我們可以將四次 get dataget data 的動作之間加入的動作之間加入””定址定址””操作操作 ,, 在加上在加上

最後一次最後一次 get data(get data( 只有只有 64bytes, 64bytes, 其餘忽略其餘忽略 ))

Buffer[0]Buffer[0](512 bytes)(512 bytes)

Spare_buf[0]Spare_buf[0](16 bytes)(16 bytes)

Buffer[0]Buffer[0](512 bytes)(512 bytes)

Buffer[1]Buffer[1](512 bytes)(512 bytes)

Buffer[2]Buffer[2](512 bytes)(512 bytes)

Buffer[3]Buffer[3](512 bytes)(512 bytes)

Spare_buf[0]Spare_buf[0](16 bytes)(16 bytes)

Spare_buf[1]Spare_buf[1](16 bytes)(16 bytes)

Spare_buf[2]Spare_buf[2](16 bytes)(16 bytes)

Spare_buf[3]Spare_buf[3](16 bytes)(16 bytes)

Controller buffer

Nand flash structure

Operation1:1.Disable ecc2.Column=03.Get 528 byteOperation2:1.Column=5122.Get 528 byte

Operation3:1.Column=10242.Get 528 byte

Operation4:1.Column=15362.Get 528 byteOperation5:1.Column=20482.Get 528 byte3.Ignore bytes after 64th byte in main buffer