Skip to content

Conversation

@jingfei195887
Copy link
Contributor

Summary

This PR contains a series of optimizations and compatibility adjustments for the FTL (Flash Translation Layer) and MTD (Memory Technology Device) subsystems, primarily to:

  1. Enable seamless compatibility with non-erase-required storage devices (e.g., RRAM/MRAM)
  2. Improve the robustness of MTD erase operation return value judgment
  3. Optimize resource usage by removing unnecessary erase buffers for devices without an erase interface

Impact

  1. Enables FTL/MTD subsystems to support non-traditional storage devices (RRAM/MRAM) that do not require erase operations, expanding the applicable scenario of the system.

  2. Unifies the return value judgment standard of the MTD erase interface, avoiding potential errors caused by inconsistent return values; adds pre-check of the erase interface to prevent invalid operations.

Testing

We have actually tested RRAM/MRAM devices, confirming that no errors are reported when accessing them via the FTL interface, and the write/read functions work normally as expected.

When there's no erase function for mtd, we decide if we
need erase_buffer based on this:

1. If we've got bad block marking, we still need the erase buffer.
   If a write fails, it's used to read back the entire bad block's
   contents before writing to a new block.
2. If we don't have bad block marking, the erase buffer isn't
   needed and can be skipped.

Signed-off-by: jingfei <[email protected]>
Accessing RRAM/MRAM from the FTL interface can
cause errors because RRAM lacks an erase interface.
To make RRAM/MRAM compatible with FTL, the FTL layer
erase interface needs to be modified.

Signed-off-by: jingfei <[email protected]>
Since there is a storage device like RRAM that doesn't
require erasing, the MTD erase function may not exist.
Here, we should first check whether the erase interface
exists before performing the erasing operation.

Signed-off-by: jingfei <[email protected]>
the MTD ERASE interface has inconsistent return values.
Some implementations return the number of erased sectors,
while others return OK (0). It is currently recommended
to uniformly treat ERASE success as OK. Therefore, the
logic for judging the return value of MTD_ERASE in the
FTL erase interface should be changed to check if it is
greater than 0.

Signed-off-by: jingfei <[email protected]>
Copilot AI review requested due to automatic review settings January 12, 2026 15:35
@github-actions github-actions bot added Area: Drivers Drivers issues Size: S The size of the change in this PR is small labels Jan 12, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for non-erase-required storage devices (RRAM/MRAM) to the FTL and MTD subsystems by making erase operations optional and improving error handling for devices that don't support erase operations.

Changes:

  • Modified MTD partition layer to conditionally assign erase function based on parent device capability
  • Enhanced FTL erase function to handle -ENOSYS return code for devices without erase support
  • Added fast path in FTL flush function for devices without erase capability and bad block management

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
drivers/mtd/mtd_partition.c Conditionally assigns erase function pointer only if parent MTD device supports erase
drivers/mtd/ftl.c Adds -ENOSYS handling to ftl_mtd_erase and implements direct write path for non-erase devices in ftl_flush

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jerpelea jerpelea changed the title FTL & MTD Optimizations for RRAM/MRAM Compatibility and Erase Logic Robustness drivers/mtd: Optimizations for RRAM/MRAM Compatibility and Erase Logic Robustness Jan 14, 2026
@xiaoxiang781216 xiaoxiang781216 merged commit 36e5752 into apache:master Jan 14, 2026
45 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants