feat(spi_nand_flash): Add block device support#606
feat(spi_nand_flash): Add block device support#606RathiSonika wants to merge 8 commits intoespressif:masterfrom
Conversation
5e70c2f to
afd1301
Compare
69e8bbd to
422413c
Compare
b05a6d5 to
2d1b2a3
Compare
2d1b2a3 to
19bd12c
Compare
c335750 to
cc21a22
Compare
b8c5e19 to
c38ec01
Compare
| * the WEAR-LEVELING layer instead (see spi_nand_flash_wl_get_blockdev). | ||
| * | ||
| */ | ||
| esp_err_t nand_flash_get_blockdev(spi_nand_flash_config_t *config, |
There was a problem hiding this comment.
Can we create new BDL instance for existing NAND flash device driver?
There was a problem hiding this comment.
As discussed offline, we have a single BDL flash instance mapped to the WL layer. A single WL instance manages the entire flash.
Therefore, there is no need to create multiple BDL instances for the NAND flash driver. The flash BDL and WL BDL will be created once during flash initialization.
6cd97df to
2005e10
Compare
c8116cf to
d46bf54
Compare
- add block device support - refactor the component for improved structure and maintainability - remove the fatfs/vfs component dependency from the driver
…d_flash into new component
… esp_vfs_fat_register
…_DELETED for TRIM operation
d6c2cb1 to
be8255b
Compare
| .release = nand_flash_blockdev_release, | ||
| }; | ||
|
|
||
| esp_err_t nand_flash_get_blockdev(spi_nand_flash_config_t *config, esp_blockdev_handle_t *out_bdl_handle_ptr) |
There was a problem hiding this comment.
There is no device_flags initialization in this BDL getter. Please, use ESP_BLOCKDEV_FLAGS_INST_CONFIG_DEFAULT() at least
| return res; | ||
| } | ||
|
|
||
| static esp_err_t nand_flash_blockdev_erase(esp_blockdev_handle_t handle, uint64_t start_addr, size_t erase_len) |
There was a problem hiding this comment.
It seems you are deleting only one block here (!!!). erase_len is never used in this context.
Am I missing anything?
| } | ||
| uint32_t start_page = trim_arg->start_addr / page_size; | ||
| uint32_t page_count = trim_arg->erase_len / page_size; | ||
| for (uint32_t page_id = start_page; page_id <= (start_page + page_count); page_id++) { |
There was a problem hiding this comment.
This is wrong - off by one, you go out of range on the last page! Proper condition check is page_id < (start_page + page_count).
Such points should be easily detected by properly designed tests.
| uint32_t ecc_err_exceeding_threshold_count = 0; | ||
| uint32_t ecc_err_not_corrected_count = 0; | ||
| esp_err_t ret = ESP_OK; | ||
| for (uint32_t page = 0; page < num_pages; page++) { |
There was a problem hiding this comment.
Note: this can be very slow on large devices... any idea for performance improvement? Like continuous stats caching?
| esp_err_t res = ESP_OK; | ||
| return res; |
There was a problem hiding this comment.
| esp_err_t res = ESP_OK; | |
| return res; | |
| return ESP_OK; |
| memcpy(&flash_info->geometry, &dev->chip, sizeof(nand_flash_geometry_t)); | ||
| return ESP_OK; | ||
| } | ||
| break; |
| spi_nand_flash_device_t *dev_handle = (spi_nand_flash_device_t *)nand_handle->ctx; | ||
|
|
||
| #ifdef CONFIG_IDF_TARGET_LINUX | ||
| ret = nand_emul_deinit(dev_handle); |
There was a problem hiding this comment.
Just wondering: is this call consitent with nand_handle->ops->release(nand_handle) ? Why is this call needed? (haven't checked the details, it just looks suspicious)
| uint32_t num_pages; | ||
| bdl->ops->ioctl(bdl, ESP_BLOCKDEV_CMD_GET_AVAILABLE_SECTORS, &num_pages); | ||
|
|
||
| TEST_ESP_OK((start_page + page_count) > num_pages); |
There was a problem hiding this comment.
This is wrong check - TEST_ESP_OK verifies a value of esp_err_t, not a boolean value (which happens as 0/1 integer in your case)
|
Found few glitches, please, have a look |
|
Also, there are some test cases missing. AI generated overview: On-target (test_spi_nand_flash_bdl.c)1. BDL geometry and flags (Flash BDL)After
2. Multi-block erase (Flash BDL)
3. ESP_BLOCKDEV_CMD_MARK_DELETED (WL BDL)
4. Sync (WL BDL)
5. GET_NAND_FLASH_INFO ioctl (Flash BDL)
6. Error paths for get_blockdev
7. Invalid args in ops
8. Unsupported ioctl
Host (test_nand_flash_bdl.cpp)9. WL BDL on host
10. Flash BDL geometry and ops
11. COPY_PAGE ioctl (Flash BDL)
12. GET_NAND_FLASH_INFO and GET_BAD_BLOCKS_COUNT on host
13. Error path: NULL / invalid
14. Release and no use-after-free
Priority
|
Change description
Add block device support (nand_flash_bdl and nand_wl_bdl)
Please refer spi_nand_flash/layered_architecture.md for the details
Refactor the component for improved structure, maintainability and readability
Removed the fatfs/vfs component dependency; it will be relocated (along with examples) to another component in a different PR.
Add Kconfig option NAND_FLASH_ENABLE_BDL to enable/disable BDL support
Updated test_apps and host_tests to verify the same
OTP and OOB area handling are still missing. I’ll address them in a separate PR, as the scope of this one is already growing.