Skip to main content

Crate flashkit_mtd

Crate flashkit_mtd 

Expand description

Raw access to MTD partitions on NAND flash.

use std::io::Read as _;

use flashkit_mtd::{Flash as _, Partition, Reader};

let device = Partition::find("boot")?.open_read_only()?;
let mut block = vec![0; device.geometry().block_size() as usize];
let mut image = Vec::new();
Reader::new(&device, &mut block)?.read_to_end(&mut image)?;

NAND flash is erased and written in blocks, and some blocks are bad. A bad block has a marker in its first page. Reader and Writer skip marked blocks. The n-th block of a partition is then its n-th good block. This is the layout that bootloaders such as LK read.

When a block fails to erase, write or verify, Writer marks it bad and writes the data to the next good block. Readers and the bootloader then skip the failed block as well. Both see the same layout. If the next block fails too, the writer stops with an error. Write protection makes every block fail, and this keeps it from marking the whole chip bad.

Flash gives access to single physical blocks without any of this.

Some platforms protect partitions that another processor, such as a modem, owns. Accessing them can reset the system without an error in Linux. Only open the partitions you need.

Modulesยง

device ๐Ÿ”’
device_error ๐Ÿ”’
flash ๐Ÿ”’
geometry ๐Ÿ”’
good_blocks ๐Ÿ”’
partition ๐Ÿ”’
reader ๐Ÿ”’
sys ๐Ÿ”’
ioctl interface of the MTD driver.
wear ๐Ÿ”’
writer ๐Ÿ”’

Structsยง

Device
Open MTD character device.
Geometry
Size, erase block size and page size of an MTD device.
GoodBlocks
Iterator over the physical indexes of the good blocks of a Flash.
Partition
MTD partition listed in /proc/mtd.
Reader
Reader over the good blocks of an MTD device.
Writer
Writer over the good blocks of an MTD device.

Enumsยง

DeviceError
Failure of an MTD operation.

Traitsยง

Flash
Operations on physical blocks of NAND flash.