-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LittleFS port as a component (IDFGH-3514) #5469
Conversation
@BrianPugh |
I'm thinking that my code will still allow the use of a SPIFFS partition if specified by name, this change would be just to support |
Thanks for your contribution. |
@BrianPugh What is your opinion on keeping this feature as a standalone component? We will soon announce a component manager for IDF, and will start moving many of IDF components out of the IDF repository. I think LittleFS is a good candidate The reason we can't accept the PR as is, is that we don't have the control over https://github.com/joltwallet/esp_littlefs.git repository. If we get an issue report for the LittleFS feature, we would depend on the owner of the repository to merge a fix. To support multiple IDF branches (release/v4.2, release/v4.3, future releases), we would also need to maintain corresponding branches in the submodule. Plus, as you correctly point out in the linked arduino-esp32 PR, we would also require an API reference page and some examples to be added for such feature — but this is something we could help with, provided that the other question is resolved. Another question, have you looked into whether it is possible to use LittleFS with flash encryption? |
I'm personally fine with it being a standalone component, but in the linked arduino discussion, it seems like it would clean a lot of duplicate code, and allow stuff to be properly submoduled so things like bug-fixes would propagate a lot faster/easier. As for control on the repo, we can of course always have Espressif fork my repo. Making sure LittleFS works with flash encryption is on my todo list. Currently I left in the same encryption assertions as SPIFFS just to be safe. I'll try and mess around with it this weekend. I haven't actually dived deep into flash encryption yet; whats the reason that SPIFFS cannot use flash encryption? |
@BrianPugh The reason for the PR here was mostly for the same reasons as @igrr is stating that it can't be accepted here (unfortunately). The current PR against arduino-esp32 duplicates your repository into arduino-esp32 and that will cause problems as the sources diverge over time. In the case of SPIFFS arduino-esp32 is leveraging the IDF SPIFFS component so as not to duplicate the code, similarly with most other FS types. |
SPIFFS relies on the "NAND write behavior" of NOR flash, which is that you can selectively program individual bits of flash from 1 to 0. This is not possible when flash encryption is enabled, because flash encryption works in 128-bit blocks. It is not possible to change a single bit from 1 to 0 in the plaintext, because this will result in a pseudo-random change of the ciphertext, with some bits changing from 0 to 1. The latter is not possible in normal NOR flash without an erase operation. But setting individual bits is used exactly for the purpose of avoiding additional erase operations, and is also an important part of power failure resistance and wear leveling. We will soon add a new API to esp_partition, which will allow doing non-encrypted writes to an encrypted partition. However this can only help if the data is structured such that "raw" writes and "encrypted" writes never land into the same 16-byte block.
I think for Arduino, the best option would be to register the original repository (https://github.com/joltwallet/esp_littlefs.git) as an Arduino library. I understand that @BrianPugh has no interest in maintaining Arduino support. In this case, another (wrapper) repository could be created, where esp_littlefs would be imported as a git submodule or subtree, in addition to Arduino-specific source/header/metadata files. I am not sure whether Arduino Library Manager supports repositories which contain submodules, thus mentioning subtree as a backup option. Both submodules and subtrees preserve the relation to the original repository, making it easy to update the library. |
Arduino Library Manager does not support sub-modules or trees. It is a flat repository setup only. |
Regarding subtrees — that's odd, from Git perspective a subtree is indistinguishable from regular files committed into the repository. Does this not work because the source directories need to be just one level deep, or something similar? |
Their requirements to list in the library manager are a bit odd to say the least. They won't list any library that includes a submodule, subtree, or anything that you won't get via a zip file download from github (which excludes all fancy bits that rely on .submodules or similar marker files that the git cli would reference) Is the long-term plan for IDF to not have many of the current components in the core deliverable? Is there a list of components that are going to externalized? |
The content of a subtree or a subrepo is included into a plain .zip download on Github — that I am pretty sure about, but perhaps there is an additional limitation on
There is no list of components which will be made standalone, yet. I can name a few components which are more likely to be moved out than the rest: expat, coap, cbor, freemodbus, libsodium, jsmn, mqtt, nghttp, plus the components maintained under the |
ok these make sense, what about the various VFS adapters (SPIFFS, SD, FFat, etc)? |
@igrr So i haven't really dived deep into the under workings of littlefs, but I just tested using flash encryption in DEVELOPMENT mode and everything worked. However, as part of my unit-tests I also have benchmark tests that compare performance against FAT and SPIFFS. In this configuration, SPIFFS still ran, which is a bit concerning. Basically, what further actions should i take to make sure this works with encryption? |
Just to check, have you marked the filesystem partition "encrypted" in the partition table, like it is done here?
|
@igrr I forgot to do that, so that would explain that. Related: it seems like I may have bricked my device (it's boot-looping). This is no big deal because I have a ton of spares, but just trying to figure out if I actually bricked it and how to prevent it in the future. I know flash encryption and stuff burns efuses, but I thought DEVELOPMENT mode was safe for reflashes and all that. Do I have any misunderstanding here? |
Could you please run |
Here's the output of
And, even though it's probably of no help, here's the output of my device bootlooping:
|
|
thanks! I'll mess around with this more later today. Hopefully this unblocks me, I'll test to see if my littlefs port still works with encryption, and I'll comment back on the results. |
@igrr So setting the baudrate to 115200 helped solve my boot-loader logging issue. It was reporting back I removed the portion of code that aborted if encryption is enabled, and all my unit-tests (which are mostly similar to the SPIFFS unit-tests) passed, so I think everything is fine. I've committed this to the master branch of the repo. Can you think of anything else I should test/look out for? I'm optimistic since my unit-tests work and the author of littlefs says that they make as little assumptions about the underlying storage as possible. |
@BrianPugh That's great news! Indeed it seems that setting the read and write sizes to be multiple of 32 bytes will make LittleFS compatible with the hardware flash encryption. I think the remaining questions to work out are:
|
@BrianPugh @igrr
https://github.com/lorol/LITTLEFS espressif/arduino-esp32#3765 |
@igrr Addressing your numbered comments:
|
I can confirm that one of the selling point of LittleFS compared to SPIFFS is that LittleFS does not make any assumption on the block device (just that it's a flash than need erasing before any write) see here. IMHO, littlefs is way better than SPIFFS in many points and I think it's bad to try to fit LittleFS into the limitations of SPIFFS. It also exist a FUSE wrapper for littlefs so you can manipulate your ESP's filesystem like a standard filesystem (without having to create a limited python tool). And for those without FUSE (like windows user), you can use a javascript wrapper directly in your browser (but it's more low level) so you don't even need a compiler on your machine. Also, the current virtual filesystem in ESP is limited to 64 files descriptors (IIRC) and leaks locks on those since it's calling |
Hello @BrianPugh It's been a while, since you posted this, but if you are still interested I'd love to help you to get your LittleFS to our new Espressif's idf-component-manager service, Idf-component-manager is a new function that allows ESP-IDF users to integrate software package into their project seamlessly. LittleFS could be one of the first external components hosted there. More information about idf-component manager can be found in Espressif API guide or PyPi registry. The component service itself is hosted here. Let me know if you agree and I can push a PR to LittleFS repository, so the sw package is deployed after you push to master branch. Or you can upload it manually whenever you see it fit. |
@tore-espressif sure! A PR would be lovely; in the PR just let me know what actions need to be taken on my end. |
Added my port of LittleFS for esp-idf. LittleFS significantly outperforms SPIFFS in most common tasks, and is much more robust when compared to FAT.
Benefits of my port:
Some potential areas for improvement:
README.md
)partition_label
required to be specified (instead of allowing it to beNULL
) in the configuration struct, this could be mitigated by adding alittlefs
subdatatype to the partition table. Other ports of LittleFS have done this.