zephyr: flash_area has no API to get flash block size
Is your enhancement proposal related to a problem? Please describe. I’m using the flash_area API to write on a device where the driver has write block size < flash block size. But it seems like nonetheless the driver doesn’t perform the necessary read-update-erase-write by itself, instead corrupting the flash pages.
Thus, I’m am using the flash_area_read, flash_area_erase, and flash_area_write APIs to read the current page contents to a buffer, change it, erase the page, and rewrite it. However, the flash_area module doesn’t provide an API to get block size (but only write block size), so the flash library must be used directly to get this information or it must be hard-coded, e.g.:
/* assume we want to write at offset 0 of block FLASH_OFFSET */
const struct flash_area *f = open_flash();
struct flash_pages_info info;
flash_get_page_info_by_offs(f->fa_dev, f->fa_off + FLASH_OFFSET, &info);
size_t bs = info.size; /* 4096 in my case */
assert(bs <= sizeof(flash_page_buffer));
flash_area_read(f, FLASH_OFFSET, &flash_page_buffer, bs);
flash_area_erase(f, FLASH_OFFSET, bs);
memcpy(&flash_page_buffer, &write_buffer, sizeof(write_buffer));
flash_area_write(f, FLASH_OFFSET, &flash_page_buffer, bs);
Describe the solution you’d like Since the flash_area module supports an erase operation, it should provide an API to get the flash block size, which is information necessary to perform the erase operation.
The flash_area module also already supports returning similar information (write block size), so it wouldn’t be unreasonable to add a similar operation to get the block size.
Describe alternatives you’ve considered Bypassing the flash_area module and using the flash module to get the information, or hardcoding the information.
Additional context I would be happy to submit a PR to support this new operation.
Do you think the driver behaviour I described above is also a bug that should be reported? I.e. write block size < block size, but the driver doesn’t really perform write block sized write operations.
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 20 (7 by maintainers)
@vmsh0 There was attempt to avoid “foreaching” flash layout to get page info that went through TSC twice but failed to gather reviews from platform maintainers: https://github.com/zephyrproject-rtos/zephyr/pull/36484 It was supposed to use direct knowledge on flash layout by driver to speed up getting info on page size by given offset. As you can imagine Flash Map API wrapper for such call would be quite simple.