If power down mode is set, trying to read ID ends in an infinite loop
because w25_waitwritecomplete never returns as status register never
signalizes write complete. Therefore ensure the device is not in a
power down mode before trying to read from it.
This can be an issue if the board is trying to check for more NOR
memories on one SPI bus and one chip select. For example GD25 driver
returns the memory to power down state after read id is finished,
therefore board initialization is stuck in an infinite loop if it first
checks for GD25 and then fallbacks to W25.
The commit fixes the possible issue by ensuring W25 is brought back
to normal operation mode before trying to obtain the manufacturer ID.
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
ftl_write() unconditionally routes writes through rwb_write() when
FTL_HAVE_RWBUFFER is defined, ignoring the O_DIRECT flag stored in
dev->oflags. This means callers that open with O_DIRECT expecting
unbuffered writes still get their data buffered in RAM.
The O_DIRECT flag is already checked in ftl_flush() to select
between direct and read-modify-write paths, but the buffering
decision in ftl_write() never consults it.
Add O_DIRECT checks in both ftl_write() and ftl_read() to bypass
rwbuffer entirely when the flag is set. For writes, go directly to
ftl_flush() and normalize the return value to match the block
driver convention (nsectors on success). For reads, go directly to
ftl_reload(), bypassing any read-ahead cache.
This gives O_DIRECT callers a complete bypass of the rwbuffer layer
for both reads and writes, matching the documented contract.
Signed-off-by: Neil Berkman <neil@xuku.com>
Invalid data is cleared during garbage collection rather than
deleted during initialization, thus accelerating the
initialization speed.
Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
When key string found corrupted during garbage collection,
then remove key-value pair from the flash.
Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
mtd_config/mtd_config_nvs should all support
mtdconfig_register_by_path/mtdconfig_unregister_by_path api
Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
change filename mtd/mtd_config_fs.c to mtd/mtd_config_nvs.c
and optimize the configuration related to mtdconfig
Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
We have added a defconfig configuration to set the page size of the flash.
According to the CFI protocol, the flash supports a single write operation
with a data volume ranging from byte size up to the maximum number of bytes.
However, the MTD device structure requires defining a page size, which serves
as the minimum write unit of the flash. Hence, this configuration is introduced.
Any page size within the range of 1 to the maximum number of bytes is considered
valid.
Signed-off-by: jingfei <jingfei@xiaomi.com>
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 <jingfei@xiaomi.com>
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 <jingfei@xiaomi.com>
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 <jingfei@xiaomi.com>
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 <jingfei@xiaomi.com>
1. In cfi_write_unalign(): Add additional check to ensure nbytes is
at least bankwidth size before skipping unaligned start handling.
This prevents incorrect behavior when writing small amounts of
data that are less than bankwidth.
2. In cfi_write(): Align down the write size to bankwidth boundary
when the remaining nbytes is less than the buffer write size.
This ensures the buffer write operation always works with properly
aligned data size, preventing write failures.))
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Add MTD driver for Winbond W25N series SPI NAND flash.
Currently supports W25N01GV (1Gbit/128MB).
Features:
- Standard SPI interface with configurable frequency (up to 104 MHz)
- Hardware ECC enabled by default
- Block erase with sleep-based wait (releases SPI bus)
- Page read/write with busy-wait for fast operations
Limitations:
- No bad block management (BBM). Factory bad blocks and runtime bad
blocks are not tracked.
- No bad block table (BBT) scanning at initialization.
- No Quad SPI support (standard SPI only).
- No access to spare area (64 bytes/page) or OTP region.
Tested using:
- Board with STM32H743
- W25N01GV on SPI at 96 MHz with DMA enabled
- Flash mounted using littlefs
- Tested using sdbench:
- Sequential write speed of 1760 KB/s
- Sequential read speed of 4900 KB/s
Signed-off-by: Julian Oes <julian@oes.ch>
In order to reduce code duplication, use the eeprom/spi_xx25xx
driver within mtd/at25ee.
The eeprom/xxx.h includes have been merged into eeprom/eeprom.h, to
provide a common include file like mtd/mtd.h.
Signed-off-by: Antoine Juckler <6445757+ajuckler@users.noreply.github.com>
This commit adds SPI_SETDELAY interface if CONFIG_SPI_DELAY_CONTROL
option is set. This allows to set custom delay between SPI transfers,
chip selects and so on.
Default values are set to 0. W25 SPI NOR flash works with them and
I haven't found any other values in the datasheet.
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
Adds a device ID to at25ee_initialize, which is stored in the
at25ee_dev_s structure. This ID is used when calling SPI_SELECT.
The implementation is based on the handling of the chip select in
mtd/ramtron.c
This change is NOT backward compatible: the function signature has changed
Signed-off-by: Antoine Juckler <6445757+ajuckler@users.noreply.github.com>
Nuttx currently has 2 types of sleep interfaces:
1. Signal-scheduled sleep: nxsig_sleep() / nxsig_usleep() / nxsig_nanosleep()
Weaknesses:
a. Signal-dependent: The signal-scheduled sleep method is bound to the signal framework, while some driver sleep operations do not depend on signals.
b. Timespec conversion: Signal-scheduled sleep involves timespec conversion, which has a significant impact on performance.
2. Busy sleep: up_mdelay() / up_udelay()
Weaknesses:
a. Does not actively trigger scheduling, occupy the CPU loading.
3. New interfaces: Scheduled sleep: nxsched_sleep() / nxsched_usleep() / nxsched_msleep() / nxsched_ticksleep()
Strengths:
a. Does not depend on the signal framework.
b. Tick-based, without additional computational overhead.
Currently, the Nuttx driver framework extensively uses nxsig_* interfaces. However, the driver does not need to rely on signals or timespec conversion.
Therefore, a new set of APIs is added to reduce dependencies on other modules.
(This PR also aims to make signals optional, further reducing the code size of Nuttx.)
Signed-off-by: chao an <anchao.archer@bytedance.com>
This patch will report events in the following scenarios:
1. Events that have changed but not been waited for before being added to
the interest list.
2. Events that occur after `epoll_wait()` returns and before it is called
again.
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
NVBLK provides a block device that operates on top of a non volatile
memory (as a mtd device) that enables wear levelling for non volatile
memory. It's operation is similar to the dhara wear levelling library,
but nvblk is meant to be used on smaller (nor, mram, rram) memory.
I am also the author and maintainer of the nvblk library.
A block device can be created during startup by using:
```
nvblk_initialize(0, mtd, CONFIG_MTD_NVBLK_DEFAULT_LBS,
CONFIG_MTD_NVBLK_DEFAULT_IOBS,
CONFIG_MTD_NVBLK_DEFAULT_SPEB);
```
and a fat filesystem on top of this as:
```
nsh> mkfatfs /dev/mtdblock0
nsh> mount -t vfat /dev/mtdblock0 /mnt
```
this fat filesystem can then be used:
```
nsh> echo "test" > /mnt/test.txt
nsh> cat test.txt
test
nsh>
```
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
To save more space (equivalent to the size of one erase sector of
MTD device) and to achieve faster read and write speeds, a method
for direct writing was introduced at the FTL layer.
This can be accomplished simply by using the following oflags during
the open operation:
1. O_DIRECT. when this flag is passed in, ftl internally uses
the direct write strategy and no read cache is used in ftl;
otherwise, each write will be executed with the minimum
granularity of flash erase sector size which means a
"sector read back - erase sector - write sector" operation
is performed by using a read cache buffer in heap.
2. O_SYNC. When this flag is passed in, we assume that the
flash has been erased in advance and no erasure operation
will be performed internally within ftl. O_SYNC will take
effect only when both O_DIRECT and O_SYNC are passed in
simultaneously.
3. For uniformity, we remapped the mount flag in mount.h and
unified it with the open flag in fcntl.h. The repetitive
parts of their definitions were reused, and the remaining
part of the mount flag redefine to the unused bit of open
flags.
Signed-off-by: jingfei <jingfei@xiaomi.com>
This reverts commit 20fcdcf905f279a9c4527be399a90590f458db1f.
The reason is that the erase buffer isn't always used in most cases.
Signed-off-by: jingfei <jingfei@xiaomi.com>
mtd/mtd_rwbuffer.c:42:
mtd/mtd_rwbuffer.c: In function 'mtd_erase':
mtd/mtd_rwbuffer.c:189:9: warning: format '%zx' expects argument of type 'size_t', but argument 3 has type 'long long int' [-Wformat=]
189 | finfo("block: %08zx nsectors: %zu\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190 | (intmax_t)block, nsectors);
| ~~~~~~~~~~~~~~~
| |
| long long int
mtd/mtd_rwbuffer.c:189:21: note: format string is defined here
189 | finfo("block: %08zx nsectors: %zu\n",
| ~~~~^
| |
| unsigned int
| %08llx
mtd/mtd_rwbuffer.c: In function 'mtd_ioctl':
mtd/mtd_rwbuffer.c:298:21: warning: format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=]
298 | finfo("blocksize: %d erasesize: %d neraseblocks: %d\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
299 | geo->blocksize, geo->erasesize, geo->neraseblocks);
| ~~~~~~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
...
Signed-off-by: chao an <anchao.archer@bytedance.com>
Adds a device ID to ramtron_initialize, which is stored in the ramtron_dev_s structure.
This ID is used when calling SPI_SELECT to board specific logic to allow chip select on the SPI bus.
This change is NOT backwards compatible, as it changes the function signature of ramtron_initialize.
This implementation is based on the handling of chip select in nuttx/drivers/mtd/sst26.c:sst26_initialize_spi().
Additional Changes:
- Add MB85RS64V to ramtron supported parts list.
Using the FTL driver over a MTD flash device, when writing to flash, eventually the ftl_flush function is called and it does an erase (MTD_ERASE) and then the write (MTD_BWRITE). Currently, the at45db driver (at45db.c), uses a write command 0x82 ("Main Memory Page Program through Buffer 1 with Built-In Erase") that also performs a built-in erase before the write. In summary, each time a write to flash is performed, the page is erased twice before it is written, first in the FTL driver and then in the MTD driver.
This PR is to change the page writes to not use that built-in command.
Signed-off-by: Javier Casas <javiercasas@geotab.com>
Function w25qxxxjv_erase wasn't correctly handling an error in
w25qxxxjv_erase_sector call and was returning success even on failure.
Moreover this change does not immediately return EBUSY but waits for
the previous operation to finish. If the timeout is significant (more
than erase time of the entire flash), then it returns EBUSY.
Signed-off-by: Michal Lenc <michallenc@seznam.cz>