狠狠撸

狠狠撸Share a Scribd company logo
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 flashnand 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 4
Page 5Page 5
Nand flash
iMX31 controller buffer
Page read
Nandflash operationNandflash 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 flashNand flash 提供了提供了 erase commanderase command 讓讓
programmerprogrammer 可以將內容轉變為可以將內容轉變為 0xff, erase0xff, erase 的單位的單位
0xffffffff0xffffffff
0xffffffff0xffffffff
0xffffffff0xffffffff
0xffffffff0xffffffff
0xffffffff0xffffffff
0xffffffff0xffffffff
0xffffffff0xffffffff
0xffffffff0xffffffff
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 flash
iMX31 controller buffer
Page 的寫入前
如果不確定是不
是 0xff, 要記得
先操除 (erase)
喔
Block 0
Case study 1 : GarbageCase 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 : GarbageCase 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 : GarbageCase 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 伴隨一段伴隨一段 64byte64byte 的的
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 ecc
2.Column=0
3.Get 528 byte
Operation2:
1.Column=51
2
2.Get 528
byte
Operation3:
1.Column=1024
2.Get 528 byte
Operation4:
1.Column=15
36
2.Get 528
byteOperation5:
1.Column=2048
2.Get 528 byte
3.Ignore bytes
after 64th
byte in
main buffer

More Related Content

Similar to Introduction to Nand Flash interface (chinese) (20)

S1: InnoDB AIO原理及相关bug分析
S1: InnoDB AIO原理及相关bug分析S1: InnoDB AIO原理及相关bug分析
S1: InnoDB AIO原理及相关bug分析
Hui Liu
?
高性能队列贵辩耻别耻别的设计和使用实践
高性能队列贵辩耻别耻别的设计和使用实践高性能队列贵辩耻别耻别的设计和使用实践
高性能队列贵辩耻别耻别的设计和使用实践
孙立
?
鸟哥叁到六章
鸟哥叁到六章鸟哥叁到六章
鸟哥叁到六章
Edward Yi
?
Install Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 LInstall Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 L
heima911
?
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)
Kris Mok
?
嵌入式平台移植技巧概说
嵌入式平台移植技巧概说嵌入式平台移植技巧概说
嵌入式平台移植技巧概说
Joseph Lu
?
2, OCP - installing and creating a database
2, OCP - installing and creating a database2, OCP - installing and creating a database
2, OCP - installing and creating a database
ted-xu
?
Something about Kafka - Why Kafka is so fast
Something about Kafka - Why Kafka is so fastSomething about Kafka - Why Kafka is so fast
Something about Kafka - Why Kafka is so fast
ViSenze - Artificial Intelligence for the Visual Web
?
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
Angel Boy
?
系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統
鍾誠 陳鍾誠
?
基于厂测尘蹿辞苍测框架下的快速公司级应用开发
基于厂测尘蹿辞苍测框架下的快速公司级应用开发基于厂测尘蹿辞苍测框架下的快速公司级应用开发
基于厂测尘蹿辞苍测框架下的快速公司级应用开发
mysqlops
?
Youku arch qcon2009_beijing
Youku arch qcon2009_beijingYouku arch qcon2009_beijing
Youku arch qcon2009_beijing
drewz lin
?
优酷 Web网站架构案例分析
优酷   Web网站架构案例分析优酷   Web网站架构案例分析
优酷 Web网站架构案例分析
George Ang
?
Au698 x mp user's manual chinese
Au698 x mp user's manual chineseAu698 x mp user's manual chinese
Au698 x mp user's manual chinese
od1ner
?
诗檀软件 Oracle开发优化基础
诗檀软件 Oracle开发优化基础 诗檀软件 Oracle开发优化基础
诗檀软件 Oracle开发优化基础
maclean liu
?
分布式系统缓存设计
分布式系统缓存设计分布式系统缓存设计
分布式系统缓存设计
zhujiadun
?
SMACK Dev Experience
SMACK Dev ExperienceSMACK Dev Experience
SMACK Dev Experience
Chih-Hsuan Hsu
?
2016 nas 年會簡報
2016 nas 年會簡報2016 nas 年會簡報
2016 nas 年會簡報
Dao Hung Chang
?
S1: InnoDB AIO原理及相关bug分析
S1: InnoDB AIO原理及相关bug分析S1: InnoDB AIO原理及相关bug分析
S1: InnoDB AIO原理及相关bug分析
Hui Liu
?
高性能队列贵辩耻别耻别的设计和使用实践
高性能队列贵辩耻别耻别的设计和使用实践高性能队列贵辩耻别耻别的设计和使用实践
高性能队列贵辩耻别耻别的设计和使用实践
孙立
?
鸟哥叁到六章
鸟哥叁到六章鸟哥叁到六章
鸟哥叁到六章
Edward Yi
?
Install Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 LInstall Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 L
heima911
?
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)
Kris Mok
?
嵌入式平台移植技巧概说
嵌入式平台移植技巧概说嵌入式平台移植技巧概说
嵌入式平台移植技巧概说
Joseph Lu
?
2, OCP - installing and creating a database
2, OCP - installing and creating a database2, OCP - installing and creating a database
2, OCP - installing and creating a database
ted-xu
?
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
Angel Boy
?
系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統
鍾誠 陳鍾誠
?
基于厂测尘蹿辞苍测框架下的快速公司级应用开发
基于厂测尘蹿辞苍测框架下的快速公司级应用开发基于厂测尘蹿辞苍测框架下的快速公司级应用开发
基于厂测尘蹿辞苍测框架下的快速公司级应用开发
mysqlops
?
Youku arch qcon2009_beijing
Youku arch qcon2009_beijingYouku arch qcon2009_beijing
Youku arch qcon2009_beijing
drewz lin
?
优酷 Web网站架构案例分析
优酷   Web网站架构案例分析优酷   Web网站架构案例分析
优酷 Web网站架构案例分析
George Ang
?
Au698 x mp user's manual chinese
Au698 x mp user's manual chineseAu698 x mp user's manual chinese
Au698 x mp user's manual chinese
od1ner
?
诗檀软件 Oracle开发优化基础
诗檀软件 Oracle开发优化基础 诗檀软件 Oracle开发优化基础
诗檀软件 Oracle开发优化基础
maclean liu
?
分布式系统缓存设计
分布式系统缓存设计分布式系统缓存设计
分布式系统缓存设计
zhujiadun
?

Introduction to Nand Flash interface (chinese)

  • 1. Nand Flash InterfaceNand Flash Interface Represented by Sneeker Yeh 2010 March.
  • 2. OutlineOutline ? Introduction ? Nandflash operation ? WinCE image layout ? Case study 1 ? Case study 2
  • 3. IntroductionIntroduction ? 下圖為下圖為 nand flashnand flash 的範例的範例 (K9F2G08X0A)(K9F2G08X0A) ? I/OI/O 腳位不只可將資料腳位不只可將資料 input or output,input or output, 也可以也可以 inputinput 命令與位址命令與位址 .. ? 若若 flashflash 結構為結構為 1616 位元位元 (16(16 支支 I/OI/O 腳)腳) ,, 資料的運輸則以資料的運輸則以 1616 位元為位元為 單位單位 ,, 命令與位址則仍然維持八位元的形式命令與位址則仍然維持八位元的形式 (( 似乎是約定俗成的規則似乎是約定俗成的規則 ))
  • 4. IntroductionIntroduction ? 將一筆資料寫入將一筆資料寫入 nand flashnand flash 的時序圖的時序圖 ? 信號的信號的 pulse widthpulse width 由由 controllercontroller 來管理來管理 , programmer, programmer 只需準備只需準備 命令命令 ,, 位址資訊位址資訊 ,, 資料資料 , controller, controller 會將這些訊息有條不紊地輸入到會將這些訊息有條不紊地輸入到 nand flash.nand flash. ? programmerprogrammer 只需注意每個命令與定址資訊的間隔只需注意每個命令與定址資訊的間隔 ,, 會由專屬的會由專屬的 status regstatus reg 或發出中斷兩種方法來表示或發出中斷兩種方法來表示 ,, 等到該等到該 operationoperation 完成後完成後 ,, 才能繼續操作才能繼續操作 controllercontroller 執行下一步動作執行下一步動作
  • 5. IntroductionIntroduction 控制器會在 I/O 上寫 ”入 00h ”讀取命令 並控制 CLE, WE, CE, ALE, RE 來 ”表示該操作為 input command” Programmer 要注意該 操作是否結束 ( 輪詢狀態 暫存器或中斷發生 ), 才 能進行下個操作
  • 6. 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 4 Page 5Page 5 Nand flash iMX31 controller buffer Page read
  • 7. Nandflash operationNandflash 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 flashNand flash 提供了提供了 erase commanderase command 讓讓 programmerprogrammer 可以將內容轉變為可以將內容轉變為 0xff, erase0xff, erase 的單位的單位
  • 8. 0xffffffff0xffffffff 0xffffffff0xffffffff 0xffffffff0xffffffff 0xffffffff0xffffffff 0xffffffff0xffffffff 0xffffffff0xffffffff 0xffffffff0xffffffff 0xffffffff0xffffffff 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 flash iMX31 controller buffer Page 的寫入前 如果不確定是不 是 0xff, 要記得 先操除 (erase) 喔 Block 0
  • 9. Case study 1 : GarbageCase 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 是最耗時間的動作是最耗時間的動作 ))
  • 10. File 5 File 5 File 5 File 5Invalid Case study 1 : GarbageCase 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
  • 11. Case study 1 : GarbageCase 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
  • 12. 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, 而且讀入其他邏輯電路並且執行錯誤偵測與而且讀入其他邏輯電路並且執行錯誤偵測與 更正更正 ..
  • 13. –模擬燒錄器的寫入 –模擬燒錄器的寫入 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 寫進所需要的值寫進所需要的值 ..
  • 14. –模擬燒錄器的讀取 –模擬燒錄器的讀取 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.
  • 15. –模擬燒錄器的讀取 –模擬燒錄器的讀取 4/54/5 ? ControllerController 對對 nand flashnand flash 上上 pagepage 的觀點的觀點 ,, 每每 512byte512byte 伴隨一段伴隨一段 64byte64byte 的的 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
  • 16. –模擬燒錄器的讀取 –模擬燒錄器的讀取 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 ecc 2.Column=0 3.Get 528 byte Operation2: 1.Column=51 2 2.Get 528 byte Operation3: 1.Column=1024 2.Get 528 byte Operation4: 1.Column=15 36 2.Get 528 byteOperation5: 1.Column=2048 2.Get 528 byte 3.Ignore bytes after 64th byte in main buffer