Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
NAND FlashNAND support in Linux
NAND/MTD support under Linux
Matthieu CASTET - www.parrot.com
12 July 2012
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
1 NAND Flash
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Flash is everywhere
non-volatile computer storage chip that can be electricallyerased and reprogrammed
usb flash drivesmemory cardssolid-state drives
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Flash is everywhere
smartphoneaudio playerdigital cameracar-kit...
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Type of flash : NOR vs NAND
NOR NANDInterface memory Bus I/OCell Size Large SmallCell Cost High Low
Read Time Fast SlowProgram Time single Byte Fast SlowProgram Time multi Byte Slow Fast
Erase Time Slow FastPower consumption High LowCan execute code Yes No
Bit twiddling Yes 1-4 timesBad blocks at ship time No Allowed
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
1 NAND FlashNAND Features
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
BUS
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
BUS
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Memory organisation
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Memory organisation
read/write unit : pageerase unit : blocktypical block size
64 pages of 512 (32 KB)64 pages of 2,048 (128 KB)64 pages of 4,096 (256 KB)128 pages of 4,096 (512 KB)
erase : all block set to 0xFFprogram : switch bit from 1 to 0
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
SLC
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
MLC
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Bad block
block can be bad at ship timeblock can become bad (Erase/Write failure)A marker is needed to detect them : bad block marker
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Ecc
bitflip corruption can happen : Read/Write disturb, cell wearneed to protect data with error correcting code (ECC)done on host sidefor SLC
1 bit per 512 B (43 nm - 350 nm)4 bits per 512 B (32 nm)8 bits per 512 B (24 nm)12? bits per 512 B (19 nm)
for MLC4 bits per 512 B (43 nm)
need to do bit scrubbingbitflips can accumulate over time
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Ecc
bitflip corruption can happen : Read/Write disturb, cell wearneed to protect data with error correcting code (ECC)done on host sidefor SLC
1 bit per 512 B (43 nm - 350 nm)4 bits per 512 B (32 nm)8 bits per 512 B (24 nm)12? bits per 512 B (19 nm)
for MLC4 bits per 512 B (43 nm)
need to do bit scrubbingbitflips can accumulate over time
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Ecc
bitflip corruption can happen : Read/Write disturb, cell wearneed to protect data with error correcting code (ECC)done on host sidefor SLC
1 bit per 512 B (43 nm - 350 nm)4 bits per 512 B (32 nm)8 bits per 512 B (24 nm)12? bits per 512 B (19 nm)
for MLC4 bits per 512 B (43 nm)
need to do bit scrubbingbitflips can accumulate over time
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Ecc
bitflip corruption can happen : Read/Write disturb, cell wearneed to protect data with error correcting code (ECC)done on host sidefor SLC
1 bit per 512 B (43 nm - 350 nm)4 bits per 512 B (32 nm)8 bits per 512 B (24 nm)12? bits per 512 B (19 nm)
for MLC4 bits per 512 B (43 nm)
need to do bit scrubbingbitflips can accumulate over time
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Ecc Algorithm
Hamming1 bit correction2 bits error detectionrequires 24 bits for 512 B
Reed Solomonused in cdromexisting hardware IPwell suited to correct burstexample for ba315 controller
4 bits correction5 bits error detectionrequires 80 bits for 512 B
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Ecc Algorithm
Hamming1 bit correction2 bits error detectionrequires 24 bits for 512 B
BCH (Bose, Ray-Chaudhuri and Hocquenghem)t bits correctionrequires t*13 bits for 512 Bextra parity bit needed for error detectionmore complex to compute than Hamming (crc like)
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Spare area
Also called "out of band" (OOB) areaextra memory for each page (about 1/32 of page size)store BBMstore ECC checksumcan be used for some filesystem metadata
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Spare area and ECC
512 B of dataBCH for 4 bits : 52 bitsBCH for 8 bits : 104 bitsBCH for 12 bits : 156 bitswe are out of 512/32 = 16 B = 128 bitsno space left for filesystem metadata
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Write constraints
Number of operation (NOP) : 1-4 timescan’t rewrite ECC !
subpage : 4 * 512 Bspare area only modification
Program pages in a block sequentiallycan’t program pagei if pagen is programmed, i < ncan’t update marker in OOB area later
Minimize partial-page programming operations
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Endurance
measured in program/erease cycle1M-100K NOR100k SLC NAND10K MLC NAND500-100 TLC NAND
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Data retention
5-10 yearschosse between endurance / data retention
Retention required Block Cycles10 yr 10 cyc5 yr 10000 cyc1 yr 100000 cyc
for improving data retentionLimit program/eraseLimit read (read disturb)
photos won’t be readable for eternity on SDCard/SSD
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Data retention
5-10 yearschosse between endurance / data retention
Retention required Block Cycles10 yr 10 cyc5 yr 10000 cyc1 yr 100000 cyc
for improving data retentionLimit program/eraseLimit read (read disturb)
photos won’t be readable for eternity on SDCard/SSD
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
ONFI
Open NAND Flash Interface Working Groupstandard physical interfacestandard command setmechanism for self-identificationnot followed by Samsung, Thoshiba, ... !
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Booting on NAND
does not support execute in place (XIP)needed hardware/software loader
NAND controller with boot modeROM code
load 1 block (512 - 128 KB) in internal RAMsmall bootloader or 2 stages (x-load/u-boot)Block 0 is not bad
difficult to support future NANDidentification/geometryerror correction
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
NAND Features
Booting on NAND : example
s3c24124 KB of data without ECC
ba315512 B of data without ECC
omap3630ROM4 first blocks60 KB with hamming ECC32 KB with BCH ECC
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
2 NAND support in Linux
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
2 NAND support in LinuxMTDUBIFS
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Flash device vs block device 1/2
Block device Flash deviceConsists of sectors Consists of eraseblocksSectors are small (512, 1024 B) Eraseblocks are larger ( typically
128KB)Maintains 2 main operations:
read sector
write sector
Maintains 3 main operations:
read from eraseblock
write to eraseblock
erase eraseblock
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Flash device vs block device 2/2
Block device Flash deviceBad sectors are re-mapped andhidden by hardware (at least inmodern LBA hard drives)
Bad eraseblocks are not hiddenand should be dealt with in soft-ware
Sectors are devoid of the wear-outproperty
Eraseblocks wear-out and becomebad and unusable after about 103
(for MLC NAND) - 105 (NOR, SLCNAND) erase cycles
Flash device is more difficult to handle
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
FTL devices
Flash Translation Layeremulation of block interface over flashfirmware is a black box (Good/Bad FTL)
robust to power failure ?Bad block management ?Wear leveling ok ?read disturb handling ?
optimized for FATabstraction over a standard interface
does not need to handle all aspects of NANDSSD : mix of SLC/MLC, I/O in parallel.
Patented
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
FTL devices
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
MTD
MTD stands for "Memory Technology Devices"Provides an abstraction of flash devicesHides many aspects specific to particular flashtechnologiesProvides uniform API to access various types of flashesE.g., MTD supports NAND, NOR, ECC-ed NOR,DataFlash, OneNAND, etcProvides partitioning capabilities
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
MTD API
In-kernel API (struct mdt_device) and user-space API(/dev/mtd0)
Information (device size, min. I/O unit size, etc)Read from and write to eraseblocksErase an eraseblockMark an eraseblock as badCheck if an eraseblock is bad
Does not hide bad eraseblocksDoes not do any wear-leveling
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
MTD NAND support
MTD started with NOR supportAPI was limited to 4GB flash (32 bits offset)first NAND controller were dummy/pio
new controllers are smarter and need a high level interfacedmawork at page/block level
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
MTD evolution : NAND ECC
bitflips happen quicklyresults in new, previously untested cases/situationscorruption in bad block marker/bad block table
protect bad block table with ECCbe robust to bit-flip in bad block marker
corruption of fs data in OOB areaavoid using OOB area or protect data
empty page not all 0xFFuse ECC that works on empty page or empty marker
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
MTD evolution : NAND ECC
bitflips are more frequentneed stronger (software) ECC algorithm
BCHfrequent bit scrubbing
bitflip_thresholdmtd report bitflip only if nb_bitflip >= bitflip_threshold
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
MTD evolution : ONFI
some new flash devices do not support legacyidentification
add ONFI identificationsave complex heuristic
speed optimization : auto-detect NAND timings
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Smart NAND
support of new generation NAND is complexneed software modificationneed hardware modification (software BCH ECC is slow)
NAND with internal ECC managementstatus command report ECC statusoptional enable/disablefree or used OOB area
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
2 NAND support in LinuxMTDUBIFS
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Linux flash filesystem
JFFS2Linux 2.4.10 (2001-09)RAM usageslow mountsummary
YAFFS/YAFFS2not mainlineuse OOB areaused by android
UBIFSLinux 2.6.27 (2008-10)next generation of the JFFS2
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Linux flash filesystem
JFFS2Linux 2.4.10 (2001-09)RAM usageslow mountsummary
YAFFS/YAFFS2not mainlineuse OOB areaused by android
UBIFSLinux 2.6.27 (2008-10)next generation of the JFFS2
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Linux flash filesystem
JFFS2Linux 2.4.10 (2001-09)RAM usageslow mountsummary
YAFFS/YAFFS2not mainlineuse OOB areaused by android
UBIFSLinux 2.6.27 (2008-10)next generation of the JFFS2
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
UBI/UBIFS stack
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
UBI
Stands for "Unsorted Block Images"Provides an abstraction of "UBI volume"Has kernel API (include/mtd/ubi-user.h) and user spaceAPI (/dev/ubi0)Provides wear-levelingHides bad eraseblocksAllows run-time volume creation, deletion, and re-sizeIs somewhat similar to LVM, but for MTD devices
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
UBI volume vs MTD device
MTD device UBI deviceConsists of physical eraseblocks(PEB), typically 128 KB
Consists of logical eraseblocks (LEB),slightly smaller than PEB (e.g 126/124KB)
Has 3 main operations
read from PEB
write to PEB
erase PEB
Has 3 main operations
read from LEB
write to LEB
erase LEB
May have bad PEBs Does not have bad LEB (handle a cer-tain amount of bad PEB)
PEBs wear out LEBs do not wear out - UBI spread theI/O load across the whole flash
MTD devices are static UBI volumes are dynamic
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Main idea behind UBI
Maps LEBs to PEBsAny LEB may be mapped to any PEBEraseblock headers store mapping information and erasecount
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Other
Handle bit-flips by moving data to a different PEBConfigurable wear-leveling thresholdAtomic LEB changeVolume update/rename operationSuitable for MLC NANDPerforms operations in backgroundWorks on NAND, NOR and other flash typesTolerant to power cutsSimple and robust designeasy support in bootloader
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
UBIFS relies on UBI
UBIFS does not care about bad eraseblocks and relies onUBIUBIFS does not care about wear-leveling and relies on UBIUBIFS exploits the atomic LEB change feature
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Requirements
Good scalabilityData structures are treesOnly journal has to be replayed
High performanceWrite-backBackground commitRead/write is allowed during commitMulti-head journal minimizes amount of GCTNC makes look-ups fastLPT caches make LEB searches fast
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Requirements
On-the-flight compressionPower-cut tolerance
All updates are out-of-placeWas extensively tested
High reliabilityAll data is protected by CRC32 checksumChecksum may be disabled for data
RecoverabilityAll nodes have a header which fully describes the nodeThe index may be fully re-constructed from the headersNo tool to rebuild it at the moment
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
TODO
UBI scales linearlyRead all eraseblock headers on attach1 or 2 page per eraseblock
UBI fastmap patch in progress
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
TODO
UBIFS do not handle MLCneed background flash scanning for bitflipspaired pages problem
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
TODO
UBI/UBIFS do not handle unstable bitspower cut just before the end of page programpower cut just after the start of page erase
page can be read, but randomly fails after a few times
power cut just after the start of page programpower cut just before the end of page erase
not a full-erased page. Contains 0xFF, but data written tothis page randomly fails
need to track program/erase operation and restartinterrupted one
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux
NAND FlashNAND support in Linux
MTDUBIFS
Questions ?
Merci pour votre attention !Thanks for your attention!Questions?
Matthieu CASTET - www.parrot.com NAND/MTD support under Linux