-
-
Notifications
You must be signed in to change notification settings - Fork 34
Description
embedded_storage seems to be a converging HAL for block/byte-level storage I/O. Just looking at the reverse dependencies gives a good idea of how many HALs and peripheral drives provide an implementation of embedded_storage.
Looking deeper into it, it seems like littlefs2’s storage API is practically identical to embedded_storage::NorFlash (block-sized reads and writes, erase support), which makes a lot of sense given that LittleFS is designed for flash. The only difference are:
CACHE_SIZEandLOOKAHEAD_SIZEvalues, which are related to LittleFS itself, rather than the driver. It seems possible to split this out so that the user has to configure this on the LittleFS instance itself (filesystem, not driver). It may create const parameter hell though, I don’t know :)- The error types are distinct.
embedded_storageallows for arbitrary driver errors, while littlefs2 requires a predefined set. Most of the errors are for higher-level FS issues and unrelated to driver operations, so this doesn’t seem like a significant thing to change, given that the FS is already generic over the driver (and therefore theoretically over its error type too). - On success, functions return the amount of data written/read/erased.
embedded_storageforces drivers to always write as much data as requested, which also seems like a reasonable approach for littlefs2 and not like a hassle for driver implementations given thatembedded_storageis doing just fine. (This might even reduce the size of that Result type depending on how large the error enum is.) capacityis a dynamic value, rather than a static constant (BLOCK_SIZEin combination withBLOCK_COUNT). Looking at the code that passes this to the C library config, it doesn’t seem like this actually needs to be a constant and making the capacity dynamic appears to be trivial. However, the concept of block sizes is still foreign toNorFlash(so probably many real devices), unfortunately. It seems like a reasonable approach to calculate the block size asLCM(READ_SIZE, WRITE_SIZE, ERASE_SIZE), after all, drivers can always choose to fake their sizes to be larger than required by hardware (and e.g. perform multiple data transfers).
Once I have time next week I’ll hack up an adapter struct for plugging any NorFlash implementation into littlefs2::Storage and report back if there’s any other issues. Otherwise, I’d like for Storage to be replaced, as it is simply unnecessarily cumbersome for users on common platforms that already have robust embedded_storage::NorFlash implementations.