Skip to main content

Flash

Trait Flash 

pub trait Flash: Sealed {
    // Required methods
    fn erase(&self, block: u32) -> Result<(), DeviceError>;
    fn geometry(&self) -> Geometry;
    fn is_bad(&self, block: u32) -> Result<bool, DeviceError>;
    fn mark_bad(&self, block: u32) -> Result<(), DeviceError>;
    fn read(
        &self,
        block: u32,
        offset: u32,
        buf: &mut [u8],
    ) -> Result<(), DeviceError>;
    fn read_unchecked(
        &self,
        block: u32,
        offset: u32,
        buf: &mut [u8],
    ) -> Result<(), DeviceError>;
    fn write(&self, block: u32, data: &[u8]) -> Result<(), DeviceError>;
}
Expand description

Operations on physical blocks of NAND flash.

The methods don’t skip bad blocks. Use super::Reader and super::Writer to read and write data across good blocks, and super::GoodBlocks to find the good blocks.

super::Device implements this trait. It is sealed so that methods can be added without breaking the API.

Required Methods§

fn erase(&self, block: u32) -> Result<(), DeviceError>

Erases block.

§Errors

Returns an error if the block is out of range or the erase fails.

fn geometry(&self) -> Geometry

Returns the geometry of the flash.

fn is_bad(&self, block: u32) -> Result<bool, DeviceError>

Returns whether block has a bad block marker.

§Errors

Returns an error if the block is out of range or the check fails.

fn mark_bad(&self, block: u32) -> Result<(), DeviceError>

Writes a bad block marker to block.

Bootloaders and readers skip the block from then on. A marker can’t be removed.

§Errors

Returns an error if the block is out of range or the marker can’t be written.

fn read( &self, block: u32, offset: u32, buf: &mut [u8], ) -> Result<(), DeviceError>

Reads buf.len() bytes from block, starting offset bytes into it.

§Errors

Returns DeviceError::Uncorrectable if the data has bit errors that ECC can’t correct. buf then holds the data as read. Another reader of the same device can also trigger this error, because the kernel only reports ECC failures through statistics for the whole device. Returns another error if the block is out of range, the range doesn’t fit in the block or the read fails.

fn read_unchecked( &self, block: u32, offset: u32, buf: &mut [u8], ) -> Result<(), DeviceError>

Reads like Flash::read, but doesn’t check for ECC errors.

Use it when only the data counts, for example to compare it with data that was just written. The ECC check of Flash::read queries the ECC statistics twice, and some kernels scan the whole partition for each query.

§Errors

Returns an error if the block is out of range, the range doesn’t fit in the block or the read fails.

fn write(&self, block: u32, data: &[u8]) -> Result<(), DeviceError>

Writes data from the start of block.

The block must be erased first, and data must cover whole pages.

§Errors

Returns an error if the block is out of range, data isn’t a whole number of pages up to a block, or the write fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

§

impl Flash for Device