nand & fat presentation

83
NAND & FAT NAND & FAT Presentation Presentation 報報報 報報報 : : 報報報 報報報

Upload: talasi

Post on 15-Jan-2016

68 views

Category:

Documents


0 download

DESCRIPTION

NAND & FAT Presentation. 報告人 : 侯欽堅. Outline. NAND Flash SPEC NAND Flash Controller & Control Code Look up Table Mechanism NAND Flash Code Flow FAT SPEC FAT Code Flow FILE Process. NAND Flash Spec – Pin Configuration. NAND Flash Spec – Pin Description. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: NAND & FAT Presentation

NAND & FAT PresentationNAND & FAT Presentation NAND & FAT PresentationNAND & FAT Presentation

報告人報告人 : : 侯欽堅侯欽堅

Page 2: NAND & FAT Presentation

2PageExcel Your Idea to Silicon

OutlineOutline

.壹 NAND Flash SPEC

.貳 NAND Flash Controller & Control Code

.參 Look up Table Mechanism

.肆 NAND Flash Code Flow

.伍 FAT SPEC

.陸 FAT Code Flow

.柒 FILE Process

Page 3: NAND & FAT Presentation

3PageExcel Your Idea to Silicon

NAND Flash Spec – Pin Configuration

Page 4: NAND & FAT Presentation

4PageExcel Your Idea to Silicon

NAND Flash Spec – Pin Description

Page 5: NAND & FAT Presentation

5PageExcel Your Idea to Silicon

NAND Flash Spec – Array Organization

Small BlockK9K1G08U0A

Large BlockK9F1G08U0A

Page 6: NAND & FAT Presentation

6PageExcel Your Idea to Silicon

NAND Flash Spec – Functional Block Diagram

Small Block Large Block

  Pages/Block

Bytes/page

Small Block

32 512+16

Large Block

642048+6

4

Page 7: NAND & FAT Presentation

7PageExcel Your Idea to Silicon

NAND Flash Spec – Address assign

Large Block

Small Block

Page 8: NAND & FAT Presentation

8PageExcel Your Idea to Silicon

NAND Flash Spec – Plane Design

Small Block

K9K1G

Page 9: NAND & FAT Presentation

9PageExcel Your Idea to Silicon

NAND Flash Spec – Plane Design

Large Block

K9K8GU0M

Page 10: NAND & FAT Presentation

10PageExcel Your Idea to Silicon

NAND Flash Spec – Signal Diagram

Page 11: NAND & FAT Presentation

11PageExcel Your Idea to Silicon

NAND Flash Spec – Signal Diagram

Page 12: NAND & FAT Presentation

12PageExcel Your Idea to Silicon

NAND Flash Spec – Signal Diagram

Page 13: NAND & FAT Presentation

13PageExcel Your Idea to Silicon

NAND Flash Spec – Command Set

Small Block

Page 14: NAND & FAT Presentation

14PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing -- Read

Page 15: NAND & FAT Presentation

15PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing -- Program

Page 16: NAND & FAT Presentation

16PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing -- Erase

Page 17: NAND & FAT Presentation

17PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing -- Read ID

Page 18: NAND & FAT Presentation

18PageExcel Your Idea to Silicon

NAND Flash Spec – Command Set

Large Block

Page 19: NAND & FAT Presentation

19PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing -- Read

Page 20: NAND & FAT Presentation

20PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing

Random Data Output In a Page

Page 21: NAND & FAT Presentation

21PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing

Page Program Operation with Random Data Input

Page 22: NAND & FAT Presentation

22PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing

Cache Program Operation (available only within a block)

After writing the first set of data up to 2112byte into the selected cache registers, Cache Program command (15h) instead of actual Page Program (10h) is inputted to make cache registers free and to start internal program operation.

Page 23: NAND & FAT Presentation

23PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing -- Copy Back

同一 Plane 內,可以不用經過外部的 Memory ,就可以執行資料搬移。 限制 : 同奇或同偶

Page 24: NAND & FAT Presentation

24PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing

Copy-Back Operation with EDC & Sector Definition for EDC

功能:   If the source page has one bit error due to charge loss or charge gain, then without EDC, the copy-back program operation could also accumulate bit errors.

限制:1. To make EDC valid, the page program operation should be performed on either whole page(2112byte) or sector(528by

te).2. Modifying the data of a sector by Random Data Input before Copy-Back Program must be performed for the whole sec

tor and is allowed only once per each sector.

Page 25: NAND & FAT Presentation

25PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing

Two-Plane Program

Page 26: NAND & FAT Presentation

26PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing

Two-Plane Block Erase

Page 27: NAND & FAT Presentation

27PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing

Two-Plane Copy Back

Page 28: NAND & FAT Presentation

28PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing

Interleave Page Program

Page 29: NAND & FAT Presentation

29PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing

Interleave Block Erase

Page 30: NAND & FAT Presentation

30PageExcel Your Idea to Silicon

NAND Flash Spec – Command & Timing

Page 31: NAND & FAT Presentation

31PageExcel Your Idea to Silicon

NAND Flash Spec – Initial Invalid block

Page 32: NAND & FAT Presentation

32PageExcel Your Idea to Silicon

OutlineOutline

.壹 NAND Flash SPEC

.貳 NAND Flash Controller & Control Code

.參 Look up Table Mechanism

.肆 NAND Flash Code Flow

.伍 FAT SPEC

.陸 FAT Code Flow

.柒 FILE Process

Page 33: NAND & FAT Presentation

33PageExcel Your Idea to Silicon

NAND Flash Controller & Control Code – SPEC

A. Block Diagram

Data FIFO: The data FIFO stores data intended to be written into and read from the memory module. The data does not include spare area data and instead the spare area is automatically generated while performing write operation. Address FIFO: The Address FIFO stores the read / write address which CPU intends to read data from or write data to. The AHB slave pushes the addresses into the address FIFO. Then, the memory interface block pops them and translates them into address latch commands. Control Registers: The Address FIFO stores the read / write address which CPU intends to read data from or write data to. The AHB slave pushes the addresses into the address FIFO. Then, the memory interface block pops them and translates them into address latch commands.

APB Slave : This block acts as an interface between APB bus and the smart media card host controller. The APB slave receives the address and data from the APB bus. It decodes the address and writes the data into the control Registers, address FIFO and data FIFO.

Memory Interface Control : The memory interface control block issues commands to the memory modules according to the content of the control registers.

Page 34: NAND & FAT Presentation

34PageExcel Your Idea to Silicon

NAND Flash Controller & Control Code – SPEC

B. Features

Page 35: NAND & FAT Presentation

35PageExcel Your Idea to Silicon

NAND Flash Controller & Control Code – SPEC

C. Command Set Support

Page 36: NAND & FAT Presentation

36PageExcel Your Idea to Silicon

NAND Flash Controller & Control Code – SPEC

D. Register

Page 37: NAND & FAT Presentation

37PageExcel Your Idea to Silicon

Page 38: NAND & FAT Presentation

38PageExcel Your Idea to Silicon

NAND Flash Controller & Control Code – SPEC

D. Register

Page 39: NAND & FAT Presentation

39PageExcel Your Idea to Silicon

NAND Flash Controller & Control Code – APB

//a FLASH_CTL register is 32bits width, u8FlashCtlDataReg[4] is used to store it.void vReadFlashCtlReg(INT8U u8addr){ PortDMAIAPBControl = 0x1; //select FLASH_CTL PortDMAIAPBAddress = u8addr; PortDMAIControl = DMAI_CONTROL_APB_RD;//4}

volatile INT8U xdata PortDMAIAPBControl _at_ 0xF2E5;

volatile INT8U xdata PortDMAIAPBAddress _at_ 0xF2E6;

volatile INT8U xdata PortDMAIControl _at_ 0xF2EB;

Page 40: NAND & FAT Presentation

40PageExcel Your Idea to Silicon

NAND Flash Controller & Control Code – Code

void vWriteFlashCtlReg32(INT8U u8addr, INT32U u32data){ PortDMAIAPBControl = 0x1; //select SMM0 PortDMAIAPBAddress = u8addr; PortDMAIData0 = u32data & 0xFF; PortDMAIData1 = (u32data & 0xFF00) >> 8; PortDMAIData2 = (u32data & 0xFF0000) >> 16; PortDMAIData3 = (u32data & 0xFF000000) >> 24; //highest PortDMAIControl = DMAI_CONTROL_APB_WR;}

Page 41: NAND & FAT Presentation

41PageExcel Your Idea to Silicon

Flash Initial Sequence --BOOLEAN bFlashCfgInit()

Start

Set bit 0 of Memory module 0 configuration register

Issue “ Read ID” to Identify NAND Flash Device ID

Fill value to DMA and FIFO control register and Interrupt enable and mask register if need

Fill Correct Information to Memory module 0 configuration register

Repeat step2&3 for two memory modules

Configuration register

Page 42: NAND & FAT Presentation

42PageExcel Your Idea to Silicon

Command Issue Sequence

Start

Fill Spare area write data register0/1 for Main Area 1/2/3/4 if need

Fill correct read/write cycle value to AC Timing register depends on which memory module

Wait for command complete (bit [15] Access Control register of change to zero)

Fill data length to Data Length register if need

Fill correct opcode and control information to Access Control register

Read Spare area read data register0/1/2 for Main Area 1/2/3/4 if need

Read Status register if need

Spare area write data register 0/1

Access Control register

Status register

Page 43: NAND & FAT Presentation

43PageExcel Your Idea to Silicon

DMA Control Sequence

Need DMA

Initial DMA controller (source address, destination address, burst length …)

Set DMA and FIFO Register (0x18) bit [15] to 1, bit [2:0] depends on DMA controller burst length

Wait for DMA controller transaction done

Wait for Command complete (polling Access Control Register bit[15] = 0 or set interrupt)

Issue Read/Write Command

(set Access Control Register bit[15] to 1)

DMA & FIFO register

Access Control register

Page 44: NAND & FAT Presentation

44PageExcel Your Idea to Silicon

OutlineOutline

.壹 NAND Flash SPEC

.貳 NAND Flash Controller & Control Code

.參 Look up Table Mechanism

.肆 NAND Flash Code Flow

.伍 FAT SPEC

.陸 FAT Code Flow

.柒 FILE Process

Page 45: NAND & FAT Presentation

45PageExcel Your Idea to Silicon

Look Up table Mechanism NAND Flash 特性 --- Program 之前必須 Block Erase

1->0 0->1 所以若只 Program Block 中的部分資料 , 必須使用以下步驟以避免資料遺失

Need to Program

原始Block

Program New Data

Program New Block

Erase原始Block

New Data

New Block

Page 46: NAND & FAT Presentation

46PageExcel Your Idea to Silicon

Look Up table Mechanism

1 NAND Flash 1Disk n Zone

0

1

2

1024

PhysicalLogical

0

1

2

1000

1 Zone = 1024 Physical Block = 1000 Logical Block , 其餘有三功能

1. Bad Block 替換用

2. 資料搬移用

3. 存放 Look Up Table & Use Table

Page 47: NAND & FAT Presentation

47PageExcel Your Idea to Silicon

Look Up table Mechanism Look Up Table : 需要 1000 個

10bit, 一般用 1000 個 2Bytes,所以佔 2048Bytes

0

1

2

1024

PhysicalLogical

0x0002

0xFFFF

0x37F

0x0001

0

1

2

999

Use Table : 需要 1024 個 1bit = 128Bytes, 有用或 Bad Block set to 1.

For Search Free Block

1

0

1

0

0123

1

0

1

1

1020102110221023

Page 48: NAND & FAT Presentation

48PageExcel Your Idea to Silicon

Look Up table Mechanism

Logical Address to Physical Address

Zone Number = (Logical Address / PagePerBlock)/1000

Load Look up Table In this Zone

由Offset Determine Physical Address from Look up Table

PS: 另外整個 Disk 還有一個 Table 紀錄 Lookup Table Address in each Zone

Page 49: NAND & FAT Presentation

49PageExcel Your Idea to Silicon

OutlineOutline

.壹 NAND Flash SPEC

.貳 NAND Flash Controller & Control Code

.參 Look up Table Mechanism

.肆 NAND Flash Code Flow

.伍 FAT SPEC

.陸 FAT Code Flow

.柒 FILE Process

Page 50: NAND & FAT Presentation

50PageExcel Your Idea to Silicon

Write Logical寫入資料是利用 Swap Block ,先將資料寫入 Swap Block 中,再將其與原先應

寫入的 Block 作對調( Look Up Table 上的對調),由於是整個 Block 的互換故

需考慮下列的特殊情形:•First Block :

•起始於 Page0 :資料完整可直接 Change

•起始非 Page0 :需將起始 Page 前的 Page 資料 ( 沒有 Write 的部分 ) 複製至 Swap Block ,然後才 Change

•Last Block:

•寫至 Last Page :資料完整可直接 Change

•未寫至 Last Page :需將後面的原本資料複製至 Swap Block ,然後才 Change

Page 51: NAND & FAT Presentation

51PageExcel Your Idea to Silicon

Write LogicalWrite Logical

判斷傳送到DSP or CPU

判斷是否是接續著上一次的位置

準備New Block將寫入點前資料複製

No

bFlashPgWriteLogicPrepare(INT32U u32logpg, INT8U u8logst)

BOOLEAN bFlashGetLKT(INT8U u8zone)

bFlashPgWriteLogicUpdate(void)

bFlashConvMediaAddr(INT16U u16logblk, INT16U * pu16phy)

bFlashAllocateNewBlk(INT16U * pu16phyblk_abs)

bFlashEraseBlk(INT16U u16blkaddr)

Update之前資料

Get correct LookUp Table

Get the original physical block number

get the new free blk number

erase the new blk

Data Move

if cover the last page ? if yes, release the original block & update Lookup Table & Use

Table

Yes

Program DatabFlashPgProg(INT32U u32pgaddr,

INT16U u16blk_rec, INT16U u16SourAddr, INT8U u8DestDir)

End

Page 52: NAND & FAT Presentation

52PageExcel Your Idea to Silicon

Read LogicalRead Logical page

判斷傳送到DSP or CPU

BOOLEAN bFlashGetLKT(INT8U u8zone)

bFlashPgWriteLogicUpdate(void)

bFlashConvMediaAddr(INT16U u16logblk, INT16U * pu16phy)

bFlashPgRead(INT32U u32pgaddr, INT16U u16DestAddr, INT8U u8DestDir, INT8U

u8DSPmemType, INT8U u8Overlay)

Update之前資料 If need

Get correct LookUp Table

Get the original physical block number

Read Data

End

Page 53: NAND & FAT Presentation

53PageExcel Your Idea to Silicon

OutlineOutline

.壹 NAND Flash SPEC

.貳 NAND Flash Controller & Control Code

.參 Look up Table Mechanism

.肆 NAND Flash Code Flow

.伍 FAT SPEC

.陸 FAT Code Flow

.柒 FILE Process

Page 54: NAND & FAT Presentation

54PageExcel Your Idea to Silicon

磁碟邏輯架構

MBR(Partition Table)Disk

Boot Sector

Data Area

2nd FAT

Root FDB Block

1st FAT

Partition Partition

Logical Driver

Logical Driver

Logical Driver Extend MBR

硬碟邏輯架構圖

開始位元 說明 大小 (Byte)

000h(0) 啟動程式執行碼 446

1BEh(446)第一個分割表 (Partition Tabl

e)16

1CEh(462)第二個分割表 (Partition Tabl

e)16

1DEh(478)第三個分割表 (Partition Tabl

e)16

1EEh(494)第四個分割表 (Partition Tabl

e)16

1FEh(510) 結束符號 0x55 0xAA 2MBR 結構表

Page 55: NAND & FAT Presentation

55PageExcel Your Idea to Silicon

偏移位置 長度 說明 附記

0h(0) 3

jmpBoot[0] = 0xEB, jmpBoot[1] = 0x??, jmpBoot[2] = 0x90 and

jmpBoot[0] = 0xE9, jmpBoot[1] = 0x??, jmpBoot[2] = 0x??

3h(3) 8 Format 軟体的名稱和版本 ( 廠商名稱與編號 )

Bh(11) 2每個 Sector 有多少個 Bytes(512,1024,2048,4096)BPB_Byt

sPerSec

BPB

Dh(13) 1每 Cluster 有多少 Sector BPB_SecPerClus(SectorsClusterSize)(1,2,4,8,16,32,64,128)BytPerSec*SecPerClus <=32K

Eh(14) 2保留磁區數 ( 保留區 sector size) BPB_RsvdSecCntFAT12,FAT16 (1)

10h(16) 1 FAT 有幾份 (typically 2) BPB_NumFATs

11h(17) 2根目錄最多幾項 FDB (Root FDB Block Size) BPB_RootEntCnt

13h(19) 2 磁區總數 ( 第一欄 ) BPB_TotSec16

15h(21) 1Media descriptor

(For removable media, 0xF0 is frequently used.)

16h(22) 2 每份 FAT 使用幾個 Sectors (FAT Size) BPB_FATSz16

18h(24) 2 每軌有幾個 Sectors

1Ah(26) 2 磁頭的數目

1Ch(28) 4 隱藏磁區的數目 (MBR)

20h(32) 4 磁區總數 ( 第二欄 )

24h(36) 1磁碟編號 0x00 for Floppy

0x80 for hard disk

25h(37) 1 保留

26h(38) 1 延伸啟動磁區特徵碼 (0x29)

27h(39) 4 磁碟序號 (Volume Serial Number)

2Bh(43) 11 磁碟標籤 (Volume Label)

36h(54) 8檔案系統型別 (“FAT12” or“FAT16”)

PS: 與 FAT 型別決定無關 char

1FEh(510) 2 結束符號 0x55 0xAA

FAT SPEC –Boot Sector(FAT16)

Boot Sector

Data Area

2nd FAT

Root FDB Block

1st FAT

Page 56: NAND & FAT Presentation

56PageExcel Your Idea to Silicon

偏移位置

長度 說明 附記

0h(0) 3 跳到啟動程式開始位址

3h(3) 8 Format 軟体的名稱和版本 ( 廠商名稱與編號 )

Bh(11) 2 每個 Sector 有多少個 Bytes (512)

BPB

Dh(13) 1 每個 Cluster 有多少個 Sectors (ClusterSize)

Eh(14) 2保留磁區數 ( 保留區 size, 啟動磁區的 sector

數 )FAT32 (typically 32)

10h(16) 1 FAT 有幾份 (2)

11h(17) 2 根目錄最多幾項 FDB (FAT32 不使用此欄 )

13h(19) 2 磁區總數 (FAT32 不使用此欄 )

15h(21) 1 Media descriptor

16h(22) 2每份 FAT 使用幾個 Sectors (FAT32 不使用此

欄 )

18h(24) 2 每軌有幾個 Sectors

1Ah(26) 2 磁頭的數目

1Ch(28) 4 隱藏磁區的數目 (MBR)

20h(32) 4磁區總數 FAT32 才有使用到 (FAT12/16 有時

用 )

FAT SPEC –Boot Sector(FAT32)

24h(36) 4 每份 FAT 使用幾個 Sectors (FAT Size)

BPB

28h(40) 2 延伸旗標

2Ah(42) 2 檔案系統版本

2Ch(44) 4存放根目錄的第一個 Cluster Number(Ro

otAddr)

30h(48) 2 存放檔案系統資訊的磁區編號

32h(50) 2 備份啟動磁區的磁區編號

34h(52) 12 保留 for future expansion

40h(64) 1 磁碟編號

41h(65) 1 保留

42h(66) 1 延伸啟動磁區特徵碼 (0x29)

43h(67) 4 磁碟序號 (Volume Serial Number)

47h(71) 11 磁碟標籤 (Volume Label)

52h(82) 8 檔案系統型別 (“FAT32” ) char

1FEh(510) 2 結束符號 0x55 0xAA

Page 57: NAND & FAT Presentation

57PageExcel Your Idea to Silicon

FAT SPEC – Cluster 2 Address & FAT Determine

RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec – 1)) / BPB_BytsPerSec;

FirstDataSector = BPB_ResvdSecCnt + (BPB_NumFATs * FATSz) + RootDirSectors;

Cluster 2 Address

FAT Type Determine -- Determined by the count of clusters on the volume

DataSec = TotSec – (BPB_ResvdSecCnt + (BPB_NumFATs * FATSz) + RootDirSectors);

CountofClusters = DataSec / BPB_SecPerClus;

If(CountofClusters < 4085) {/* Volume is FAT12 */} else if(CountofClusters < 65525) {/* Volume is FAT16 */} else {/* Volume is FAT32 */}

Boot Sector

Data Area

2nd FAT

Root FDB Block

1st FAT

Page 58: NAND & FAT Presentation

58PageExcel Your Idea to Silicon

FAT SPEC –FAT Table

Cluster 0 1 2 3 4 5 6 7

Content

保留 保留 4 5 60xFFF

F

FAT12 FAT16 FAT32

未使用 0x000 0x0000 0x?000 0000

使用中 2~4086 2~65526 2~4294967294

檔案 link 結束End of Cluster-chain

(EOC)0xFF8~0xFFF 0xFFF8~F 0x?FFF FFF8~F

故障 0xFF7 0xFFF7 0x?FFF FFF7

保留 0xFF0~0xFF6 0xFFF0~0xFFF6 0x?FFF FFF0~6

如何計算某個 Cluster N 的 Sector Number 與 offsetIf(FATType == FAT16)

FATOffset = N * 2;else if (FATType == FAT32)

FATOffset = N * 4;ThisFATSecNum = BPB_ResvdSecCnt + (FATOffset / BPB_BytsPerSec);ThisFATEntOffset = REM(FATOffset / BPB_BytsPerSec);

PS: CountofClusters+1

Boot Sector

Data Area

2nd FAT

Root FDB Block

1st FAT

Page 59: NAND & FAT Presentation

59PageExcel Your Idea to Silicon

FAT SPEC –FAT Volume Initialization

struct DSKSZTOSECPERCLUS {DWORD DiskSize;BYTE SecPerClusVal;};

DSKSZTOSECPERCLUS DskTableFAT16 [] = {{ 8400, 0}, /* disks up to 4.1 MB, the 0 value for SecPerClusVal trips an error */{ 32680, 2}, /* disks up to 16 MB, 1k cluster */{ 262144, 4}, /* disks up to 128 MB, 2k cluster */{ 524288, 8}, /* disks up to 256 MB, 4k cluster */{ 1048576, 16}, /* disks up to 512 MB, 8k cluster *//* The entries after this point are not used unless FAT16 is forced */{ 2097152, 32}, /* disks up to 1 GB, 16k cluster */{ 4194304, 64}, /* disks up to 2 GB, 32k cluster */{ 0xFFFFFFFF, 0} /* any disk greater than 2GB, 0 value for SecPerClusVal trips an error */};

DSKSZTOSECPERCLUS DskTableFAT32 [] = {{ 66600, 0}, /* disks up to 32.5 MB, the 0 value for SecPerClusVal trips an error */{ 532480, 1}, /* disks up to 260 MB, .5k cluster */{ 16777216, 8}, /* disks up to 8 GB, 4k cluster */{ 33554432, 16}, /* disks up to 16 GB, 8k cluster */{ 67108864, 32}, /* disks up to 32 GB, 16k cluster */{ 0xFFFFFFFF, 64}/* disks greater than 32GB, 32k cluster */};

For 512 bytes per sector only

Page 60: NAND & FAT Presentation

60PageExcel Your Idea to Silicon

FAT SPEC –FDB(FAT Directory Block)( 各 32Bytes)偏移位置 長

度 名稱 説明

0h(0) 8 主檔名

BYTE[0] 00h 未使用 (dir 結束搜尋判別 ) E5h 表該檔案或目錄被刪除 05h 第一個字元為 E5h ( 為了防止日文檔名被誤判 )若為長檔名則第一個字元為長檔名之流水編號 (1,2,3….4xh 最後一個要加 40h)

8h(8) 3 副檔名 ASCII

Bh(11) 1 屬性Bit0 唯讀 , Bit1 隱藏 , Bit2 系統 , Bit3 標籤 , Bit4 目錄 , Bit5 檔案有更動Bit6 Bit7 保留若此欄的值為 0x0F 表此為長檔名之 FDB

Ch(12) 6 保留 All set to 0x00

12h(18) 2 Date 上次存取日期 ( 格式參照建檔日期 )

14h(20) 2FAT16 : 保留此欄 ,set 0FAT32 : 開始磁簇(Cluster Number High Word)

16h(22) 2 建檔時間15

14

13

12

11

10

9 8 7 6 5 4 3 2 1 0

時 分 秒

18h(24) 2 建檔日期15

14

13

12

11

10

9 8 7 6 5 4 3 2 1 0

年 -1980 月 日

1Ah(26) 2 開始磁簇 Cluster Number(即在 FAT 表中的 index)(FAT32 的 Cluster Number Low Word)

1Ch(28) 4 檔案大小 若為目錄 則此欄為 0

Boot Sector

Data Area

2nd FAT

Root FDB Block

1st FAT

Page 61: NAND & FAT Presentation

61PageExcel Your Idea to Silicon

FAT SPEC –FDB

FDB 的分類FDB類別的判別,主要以 FDB 32bytes 中的 FDB[0] 與 FDB[11]的內含值為分類( 一 ) Dir FDB: FDB[11]&0x10==0x10( 二 ) File FDB: FDB[11]&0x10==0x00( 三 ) Long File Name FDB: FDB[11]=0x0F( 四 ) Delete FDB: FDB[0]=0xE5(五 ) Null FDB: FDB[0]=0x00(六 ) 0x05 FDB:FDB[0]=0x05, 原檔名第一個 BYTE 為 0xE5

Page 62: NAND & FAT Presentation

62PageExcel Your Idea to Silicon

FAT SPEC – Long File Name

長檔名 FDB 架構圖

BYTE[0] 0x42

其它欄位存放長檔名之 unicode

BYTE[0] 0x01

其它欄位存放長檔名之 unicode

檔名 (THEQUI~1)

( 存傳統 8.3 格式的資料 )

"The quick brown.fox".

Page 63: NAND & FAT Presentation

63PageExcel Your Idea to Silicon

OutlineOutline

.壹 NAND Flash SPEC

.貳 NAND Flash Controller & Control Code

.參 Look up Table Mechanism

.肆 NAND Flash Code Flow

.伍 FAT SPEC

.陸 FAT Code Flow

.柒 FILE Process

Page 64: NAND & FAT Presentation

64PageExcel Your Idea to Silicon

FAT Code Flow -- FAT.*

bFATInit (void) FAT Initial

bFAT_FileInfo (FILE_INFO * ptfinfo) 從 "ptfinfo" 的 EntryAddr 去讀 FDB 得到其他 Information存回 "ptfinfo"

bFatEraseEntryCurrentClus (INT32U u32currentclus) 清掉 "u32currentclus" 內這個 Cluster 的值

bFatFillFileEntry (FILE_INO * ptfinfo) 填 "ptfinfo" 的 Information 回 FDB

bFatFindFreeClustor (INT32U * pu32Freeclus) 回 Free Cluster 位置到 "pu32Freeclus"

bFatGetFreeEntryInDir

(INT32U * pu32FreeEntry, INT32U u32search_clus)

FAT32 用 從 "u32search_clus"(FDB Cluster) 開始找一個 Free的 Entry

bFatGetFreeEntryInRootDir (INT32U * pu32FreeEntry) FAT16 用 從 Root Dir 開始找一個 Free 的 Entry

bFatMarkNewChain (INT32U u32ClusLocate, INT32U u32value)

在 FDB 的 "u32ClusLocate" 位置 填 u32value

bFatReleaseAllChain (INT32U u32startclus) Delete File 時 清除 "u32startclus" 的 FAT Cluster Chain

eCheckEntryType (INT8U * pu8buf) Return 此 Entry 點 (32bytes) 的 type

eNextClus (INT32U * pu32clus) 把下一個 Cluster 的位置放在 "pu32clus" 並回傳 Cluster type

u32FatCalcFreeClustor

(void) 由 FAT 表計算 Free Cluster 數回傳

u32GetFileSize (INT8U * pu8xdata) 回傳 "pu8xdata"offset 28 29 30 31 組合 也就是此 File 的容量

u32GetFileStart (INT8U * pu8xdata)將 "pu8xdata" offset 21 20 27 26 組合回傳 也就是 Start Cluster 的位置

Page 65: NAND & FAT Presentation

65PageExcel Your Idea to Silicon

FAT Code Flow -- ContinuebFATInit()

Start--vSysInit()

OK

bFlashPgReadLogic(0,buffer)

OK

Buffer[0] = E9 orBuffer[0], Buffer[2]= EB,90

Buffer[510] = 0x55Buffer[511] = 0xAA

Fail(No FAT)

No

Buff[11],Buff[12] = BytePerSec

Buff[13] = SecPerClus

Buff[14],Buff[15] = RsvSecCnt

Buff[16] = NumFATs

Buff[17],Buff[18] = RootEntCnt

Buff[19],Buff[20] = TotSec Buff[32],Buff[33] Buff[34],Buff[35]= TotSec

Buff[22],Buff[23] = FATSz Buff[36],Buff[37] Buff[38],Buff[39]= FATSz

Buff[44],Buff[45] Buff[46],Buff[47]= RootClus

calculate SecNumInClus2 , DataSecCnt , DataClusCnt

DataClusCnt <65525

FAT16 FAT32

Yes No

Page 66: NAND & FAT Presentation

66PageExcel Your Idea to Silicon

FAT Code Flow -- Continue

Construct new file In FAT system

Start

bFatEraseEntryCurrentClus(INT32U u32currentclus)

bFatGetFreeEntryInRootDir(INT32U * pu32FreeEntry)

bFatFindFreeClustor(INT32U * pu32Freeclus)

bFatGetFreeEntryInDir(INT32U * pu32FreeEntry, INT32U

u32search_clus)

找到一個Free Cluster

若是要新增Directory清除此Cluster的Data

變數u32FatLastFreeClustor從FAT表中找尋0x00000000填0x0FFFFFF8(EOC)回FAT

Write 0x00

在FDB中 找到Free Entry

填File Information to FDBbFatFillFileEntry

(FILE_INFO * ptfinfo)

End

FAT32用

FAT16用

eCheckEntryType(INT8U * pu8buf)

Check FDB Value

Read FDB

Return Free Entry

Read FDB SectorWrite File Information to FDB Address

eNextClus(INT32U * pu32clus)

整個Cluster都找不到FreeFind next Cluster from FAT

bFatFindFreeClustor(INT32U * pu32Freeclus)

bFatEraseEntryCurrentClus(INT32U u32currentclus)

若FAT Table為EOC要新增下一個FDB Cluster

bFatMarkNewChain(INT32U u32ClusLocate,

INT32U u32value)

將EOC改為此New Cluster的位置

Page 67: NAND & FAT Presentation

67PageExcel Your Idea to Silicon

FAT Code Flow -- Continue

Delete file In FAT system

Start

bFatReleaseAllChain(INT32U u32startclus)

清除此File的FAT Chain

填0xE5(已刪檔案)到FDB

Read FAT Sector & 紀錄內含值(下一個Cluster位置)清除FAT為0x00000000

填0xE5(已刪檔案)到FDB(Long file name)

bFatFillFileEntry(FILE_INFO * ptfinfo)

End

Read FDB SectorWrite File Information to FDB Address

Next Cluster & Clear until EOC

Page 68: NAND & FAT Presentation

68PageExcel Your Idea to Silicon

OutlineOutline

.壹 NAND Flash SPEC

.貳 NAND Flash Controller & Control Code

.參 Look up Table Mechanism

.肆 NAND Flash Code Flow

.伍 FAT SPEC

.陸 FAT Code Flow

.柒 FILE Process

Page 69: NAND & FAT Presentation

69PageExcel Your Idea to Silicon

File Process

Seek Close Open Read Write Search File Delete Create

typedef struct { INT8U u8filenameMain[9]; // 主檔名 INT8U u8filenameExt[4]; // 副檔名 INT32U u32startclus; //Start Cluster address INT32U u32size; //File size INT32U u32EntryAddr; //FDB Entry address ENTRY_TYPE etype; //Entry type } FILE_INFO; typedef struct{ FILE_INFO * ptfinfo; INT32U u32CurrClus; INT32U u32CurrOffset;}FILE_t;

File Action File Struct

Page 70: NAND & FAT Presentation

70PageExcel Your Idea to Silicon

File Process File_op.C

Function Name Input Variable Function Description

bFileSeek (FILE_t * stream, INT32S s32offset, SeekOpt whence)

Seek File from "whence" and offset "s32offset", New u32CurrClus & u32CurrOffset in "stream"

FileClose (FILE_t* stream) Clear u32CurrClus & u32CurrOffset in "stream"

FileOpen (INT8U *filename)Search "filename" in File system and Record the information to "tCurrOpenFontFile"

u16FileRead

(void *ptr, INT16U u16size, FILE_t* stream) Read "Stream" "u16size" bytes to memory pointer "ptr"

u16FileWrite

(INT32U u32SourAddr, INT16U u16size, FILE_t* stream, INT8U bUpdateClusChain)

Write "Stream" "u16size" bytes from memory address "u32SourAddr“ , "bUpdateClusChain" control whether write to new cluster or not

File.C

bFileCreateFileInDir (FILE_INFO * ptfinfo, INT32U u32SearchEntry_startclus)

Construct a new file or directory with file information in "ptfinfo",u32SearchEntry_startclus is FDB Clus when FAT32

bFileDeleteFile (FILE_INFO * ptfinfo) Clear "ptfinfo"'s FAT Table position,remark 0xE5 to its FDB

bFileFindFile_withFileName (FILE_INFO * ptfinfo) Find file with filename in "ptfinfo" only in root dirctory,and Record file information

bFileRegister (INT32U u32entry_base)

add u32entry_base to u32FileRegEntry[]

bFileSearchFileInDir (INT32U u32clus)Search all file in file system for FAT32,u32clus means FDB cluster

bFileSearchFileInRootDir (void) Search all file in file system for FAT16

bFileSearchSongs (INT8U* ptFileExt) Search file with "ptFileExt" & Put their Entry in u32FileRegEntry[] , calculate number in u16TotalFile

Seek

Close

Open

Read

Write

Search File

Delete

Create

Search File

Search File

Search File

Page 71: NAND & FAT Presentation

71PageExcel Your Idea to Silicon

File OpenFile Open

Need To Open File “ xxx.xxx”

FILE_t* FileOpen(INT8U *filename)

Transfer String to file name

bFileFindFile_withFileName(FILE_INFO * ptfinfo)

Get File Information

From System Section or api_bFileOpen()_

FILE_t* FileOpen(INT8U *filename)

// input: ptfinfo->filename// output: ptfinfo->etype// output: ptfinfo->u32startclus// output: ptfinfo->u32size;// output: ptfinfo->u32EntryAddr;

Page 72: NAND & FAT Presentation

72PageExcel Your Idea to Silicon

bfileSeek(FILE_t * stream, INT32S s32offset, SeekOpt whence))

Start

由Input參數計算offset幾個Cluster

由FAT表中從頭找到 Current Cluster

紀錄Current Cluster與在此Cluster的offset

End

File Seek

Page 73: NAND & FAT Presentation

73PageExcel Your Idea to Silicon

File SearchStart

End

計算FDB位置

讀取FDB Data

Check Entry Type

Read FAT

EOC

Not Eoc

If need to find file In directoryè R ecursive

Page 74: NAND & FAT Presentation

74PageExcel Your Idea to Silicon

End~~

Page 75: NAND & FAT Presentation

75PageExcel Your Idea to Silicon

Appendix

Back

Page 76: NAND & FAT Presentation

76PageExcel Your Idea to Silicon

Appendix Back

Page 77: NAND & FAT Presentation

77PageExcel Your Idea to Silicon

Appendix Back Back2

Page 78: NAND & FAT Presentation

78PageExcel Your Idea to Silicon

Appendix Back

Page 79: NAND & FAT Presentation

79PageExcel Your Idea to Silicon

1. Small Block 的 Page Program如何指向 255 以後的位置 ? Ans: 請見下圖 00,01,50 除了當 Read Command 之外還可以當 Pointer,指向 page program 要操作的位置 , 當然 ,這時候就不是 Read 的操作了       

補充

Page 80: NAND & FAT Presentation

80PageExcel Your Idea to Silicon

補充

    2. Page address 在 Block Erase 內的影響 ?

Ans: 如下圖 Erase Block Command 只有 Block Address A14~A26是 Valid, 其他 A9~A13是 Invalid. 所以即使 page address(A9~A13) 不同也沒有差 . 同樣都是 Erase 整個 Block.

Page 81: NAND & FAT Presentation

81PageExcel Your Idea to Silicon

補充

3. 支援 Interleave Command 的 Flash CE 與 R/nB 的 Pin 數 ?Ans:其實如果各有兩個 CE及 R/nB腳,我們就可以自己來做 Interleave。所以所謂 Flash支援 Interleave Command 就是代表這個 Flash 只靠各一根 CE 與 R/nB腳就可以在它內部的兩個 chip 中做 Interleave。以報告中是以 Samasung K9K8G08U0M 為例,他的 CE 與 R/nB腳都各只有一根,我們可以分三點來看。第一 :它會靠 A30( 最高 bit)來判斷是給那個 Chip ,所以下圖會標 A30:Low 或 High。第二 :如果我們有兩個 CE腳可以控的話,就可以決定 Read Status Command是下給哪一個 Chip , 但因為只有一根所以需要 F1 與 F2這兩個 Interleave Read Status Command來 Read 不同 Chip 的 Stat

us。第三 :R/nB 只有一根,所以代表它可以在 R/nB 為 Low(Busy) 的時候下內部另一個 Chips 的 Page Program Command。 

Page 82: NAND & FAT Presentation

82PageExcel Your Idea to Silicon

補充 4. Two Flash Interleave? 

Page 83: NAND & FAT Presentation

83PageExcel Your Idea to Silicon

補充 1. FTNDNDC010 只支援 8bit  另有一個 IP FTNANDC020 可支援 16bit  2. 最初 NAND Flash 只有 page program command 是確定會支援的。 接著 Small Block 中有些 Flash 有多個 Plane 的架構 , 所以可以做 Multi Plane 的 Page program 。 然後 Large block 的 page program 看起就類似 Small Block 的 Multi plane page program  因為最大都是一 次 2K 。

在 Large Block 中如果硬體有支援 Cache 的就會支援 Cache Program 的 Command 。 後來又發展出支援 Two plane 的 Large Block Flash(4Gb 以上 ), 不過我還沒有看到有 Plane 架構的 Flash 有 同時支援 Cache Command 。 可能是這樣會需要太多的 page register 和 Cache 了。 報告中之所以看到 Large Block 有四個 Plane, 其實只是容量越來越大 , 變成 N 個 Two Plane 而已 . 3. 理論上 Read Transfer rate ( 以 Samsung K9K8G08U0A 為例 )   ,最快在二十幾 MB 左右吧。 不過若是 K9K1G08U0B(small block) , tRC 為 50ns ,效能極限應該只有十出頭MB。                        

back