Memory Technology Device

Low level Memory Technology Device interface.

Generic memory technology device interface

enum mtd_power_state
MTD_POWER_UP
Power up.
MTD_POWER_DOWN
Power down.
struct mtd_desc mtd_desc_t

MTD driver interface.

This define the functions to access a MTD.

A MTD is composed of pages combined into sectors. A sector is the smallest erasable unit. The number of pages in a sector must be constant for the whole MTD.

The erase operation is available only for entire sectors.

const vfs.h::vfs_file_ops_t mtd_vfs_ops

MTD driver for VFS.

int mtd_init(mtd_dev_t * mtd)

mtd_init Initialize a MTD device

Parameters

mtd:the device to initialize

Return values

int mtd_read(mtd_dev_t * mtd, void * dest, uint32_t addr, uint32_t count)

mtd_read Read data from a MTD device

No alignment is required on addr and count.

Parameters

mtd:the device to read from
dest:the buffer to fill in
addr:the start address to read from
count:the number of bytes to read

Return values

  • the number of byte actually read
  • < 0 if an error occured
  • -ENODEV if mtd is not a valid device
  • -ENOTSUP if operation is not supported on mtd
  • -EOVERFLOW if addr or count are not valid, i.e. outside memory
  • -EIO if I/O error occured
int mtd_write(mtd_dev_t * mtd, const void * src, uint32_t addr, uint32_t count)

mtd_read write data to a MTD device

addr + count must be inside a page boundary. addr can be anywhere but the buffer cannot overlap two pages.

Parameters

mtd:the device to write to
src:the buffer to write
addr:the start address to write to
count:the number of bytes to write

Return values

  • the number of byte actually written
  • < 0 if an error occured
  • -ENODEV if mtd is not a valid device
  • -ENOTSUP if operation is not supported on mtd
  • -EOVERFLOW if addr or count are not valid, i.e. outside memory, or overlapping two pages
  • -EIO if I/O error occured
int mtd_erase(mtd_dev_t * mtd, uint32_t addr, uint32_t count)

mtd_erase Erase sectors of a MTD device

addr must be aligned on a sector boundary. count must be a multiple of a sector size.

Parameters

mtd:the device to erase
addr:the address of the first sector to erase
count:the number of bytes to erase

Return values

  • 0 if erase successful
  • < 0 if an error occured
  • -ENODEV if mtd is not a valid device
  • -ENOTSUP if operation is not supported on mtd
  • -EOVERFLOW if addr or count are not valid, i.e. outside memory
  • -EIO if I/O error occured
int mtd_power(mtd_dev_t * mtd, enum mtd.h::mtd_power_state power)

mtd_power Set power mode on a MTD device

Parameters

mtd:the device to access
power:the power mode to set

Return values

  • 0 if power mode successfully set
  • < 0 if an error occured
  • -ENODEV if mtd is not a valid device
  • -ENOTSUP if operation or power state is not supported on mtd
  • -EIO if I/O error occured
struct mtd_dev_t

MTD device descriptor.

const mtd.h::mtd_desc_t * driver

MTD driver.

uint32_t sector_count

Number of sector in the MTD.

uint32_t pages_per_sector

Number of pages by sector in the MTD.

uint32_t page_size

Size of the pages in the MTD.

struct mtd_desc

MTD driver interface.

This define the functions to access a MTD.

A MTD is composed of pages combined into sectors. A sector is the smallest erasable unit. The number of pages in a sector must be constant for the whole MTD.

The erase operation is available only for entire sectors.

int(* init()

Initialize Memory Technology Device (MTD)

Parameters

dev:Pointer to the selected driver

Return values

  • 0 on success
  • < 0 value in error
int(* read()

Read from the Memory Technology Device (MTD)

No alignment is required on addr and size.

Parameters

dev:Pointer to the selected driver
buff:Pointer to the data buffer to store read data
addr:Starting address
size:Number of bytes

Return values

  • the number of bytes actually read
  • < 0 value on error
int(* write()

Write to the Memory Technology Device (MTD)

addr + size must be inside a page boundary. addr can be anywhere but the buffer cannot overlap two pages.

Parameters

dev:Pointer to the selected driver
buff:Pointer to the data to be written
addr:Starting address
size:Number of bytes

Return values

  • the number of bytes actually written
  • < 0 value on error
int(* erase()

Erase sector(s) over the Memory Technology Device (MTD)

addr must be aligned on a sector boundary. size must be a multiple of a sector size.

Parameters

dev:Pointer to the selected driver
addr:Starting address
size:Number of bytes

Return values

  • 0 on success
  • < 0 value on error
int(* power()

Control power of Memory Technology Device (MTD)

Parameters

dev:Pointer to the selected driver
power:Power state to apply (from mtd.h::mtd_power_state)

Return values

  • 0 on success
  • < 0 value on error