Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Documentation/components/drivers/special/mtd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,29 @@ See include/nuttx/mtd/mtd.h for additional information.
#. Provide that instance to the initialization method of the
higher level device driver.

- **Registering MTD Drivers**. MTD partition can be registered as a
standard character device driver. This allows to perform standard
``open/read/write/ioctl`` calls directly on the MTD layer (and thus
directly on raw flash). This has some advantages compared to FTL
and BCH layers used to register flash device. FTL layer has to buffer
the entire erase page, because write operation leads to erase page
read, erase and then write the modified buffer. Apart from larger
RAM memory consumption, the data may be lost during power cut off,
because erase takes a considerable amount of time. On the other hand,
an access with FTL/BCH layer takes care of page erase if needed, thus
simplifying the application logic.

Direct access through MTD layer can be faster and lower RAM consumption,
but the application has to take care of page erase before write if needed.
The erase can be performed by ioctl call ``MTDIOC_ERASESECTORS``.
The driver is registered with ``mtd_partition_register`` function call.

Configuration option ``CONFIG_MTD_PARTITION_REGISTER`` has to be selected
to support this feature.

- **Examples**: ``drivers/mtd/m25px.c`` and ``drivers/mtd/ftl.c``


EEPROM
======

Expand Down
6 changes: 6 additions & 0 deletions Documentation/implementation/drivers_design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ on top of another MTD driver, it changes the apparent page size of the FLASH to
``drivers/mtd/mtd_partitions.c`` can be used to break up a large FLASH into
separate, independent partitions, each of which looks like another MTD driver.

It is possible to register the partition as a character device driver. This
provides a direct access to the raw flash, but doesn't ensure any logic
needed to operate the flash (page erase prior to write, wear leveling,
fault block detection). The driver is implemented in
``drivers/mtd/mtd_register.c``.

``drivers/mtd/ftl.c`` is also interesting. FTL stands for FLASH Translation Layer.
The FTL driver is an MTD driver that when layered on top of another MTD driver,
converts the MTD driver to a block driver. The permutations are endless.
Expand Down
4 changes: 4 additions & 0 deletions drivers/mtd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ if(CONFIG_MTD)
list(APPEND SRCS mtd_partition.c)
endif()

if(CONFIG_MTD_PARTITION_REGISTER)
list(APPEND SRCS mtd_register.c)
endif()

if(CONFIG_MTD_SECT512)
list(APPEND SRCS sector512.c)
endif()
Expand Down
19 changes: 19 additions & 0 deletions drivers/mtd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ config MTD_PARTITION
managing the sub-region of flash beginning at 'offset' (in blocks)
and of size 'nblocks' on the device specified by 'mtd'.

config MTD_PARTITION_REGISTER
bool "Register MTD partition as a driver"
default n
depends on MTD_PARTITION
---help---
This option allows to register created MTD partition as a device
driver and perform standard open/close/read/write/ioctl calls
directly on the MTD layer. This has some pros and cons compared
to the access through FTL or/and BCH layers. FTL layer buffers
the erase page, thus increasing RAM memory consumption. It also
means the data may be lost during power cutoff as flash write
means read, erase, write and erase operation may take time. On the
other hand, the access through FTL/BCH takes care of page erase
if needed, thus is easier to manage from an application.

Direct access to MTD layer can be faster and lower RAM memory
consumption, but the application has to take care of page erase
before writes if needed. This can be done with ioctl calls.

config FTL_WRITEBUFFER
bool "Enable write buffering in the FTL layer"
default n
Expand Down
4 changes: 4 additions & 0 deletions drivers/mtd/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ ifeq ($(CONFIG_MTD_PARTITION),y)
CSRCS += mtd_partition.c
endif

ifeq ($(CONFIG_MTD_PARTITION_REGISTER),y)
CSRCS += mtd_register.c
endif

ifeq ($(CONFIG_MTD_SECT512),y)
CSRCS += sector512.c
endif
Expand Down
Loading
Loading