jingfei195887 opened a new pull request, #22019:
URL: https://github.com/apache/nuttx/pull/22019
## Summary
- **mtd/cfi: add rwsem to serialize CFI command sequences.**
CFI command sequences were not serialized, so a read, write or erase on
one partition could interleave with a write on another partition of the
same flash and corrupt both: a write or erase leaves the chip out of
read-array mode until it completes. Add a per-device read-write lock
(`rw_semaphore_t`) to `struct cfi_dev_s`: reads are shared, write and
erase are exclusive until the chip is back in read-array mode.
## Impact
- New feature / API change: NO.
- Behavior: CFI reads may run in parallel; a write or erase now excludes
every other access to the same device.
- Build, hardware, documentation, security, compatibility: NO.
## Testing
Host: Ubuntu 22.04 x86_64, Arm GNU Toolchain 13.2.rel1.
`qemu-armv7a:full` (`CONFIG_MTD_CFI`, littlefs mounted on
`/dev/cfi-flash1` at `/data`), run with
`qemu-system-arm -cpu cortex-a7 -machine
virt,highmem=off,virtualization=off,gic-version=2`:
```
nsh> echo cfi-test > /data/a.txt
nsh> cat /data/a.txt
cfi-test
nsh> dd if=/dev/zero of=/data/big bs=4096 count=64
nsh> ls -l /data
/data:
-rw-rw-rw- 9 2023-04-25 00:00 a.txt
-rw-r--r-- 262144 2023-04-25 00:00 big
nsh> rm /data/big
nsh> ls /data
/data:
a.txt
```
The output is identical on master fc8d354f9a and with this change. The
concurrent interleaving was not reproduced on QEMU; the test shows that
reads, writes and erases through the lock still work.
- `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
- `sim:nsh` with `CONFIG_MTD` and `CONFIG_MTD_CFI`: Make and CMake builds
pass with no new warnings in the changed files; `ostest` exits with
status 0.
- `qemu-armv7a:full`: build passes, run log above.
- Verified on QEMU and sim only.
## PR verification Self-Check
* [x] This PR introduces only one functional change.
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
* [ ] My PR is still work in progress (not ready for review).
* [x] My PR is ready for review and can be safely merged into a codebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]