-
Notifications
You must be signed in to change notification settings - Fork 935
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 flexible file system and POSIX file API support #1715
base: develop
Are you sure you want to change the base?
Conversation
It is worth referencing the discussion: https://forums.raspberrypi.com/viewtopic.php?t=368898 |
this looks great, thank you. one initial question from a quick skip read; how does overriding I'm putting this in 1.7.0 for now as we are looking at reworking our C library API (so we don't just support newlib), and we should think about how to "inject" mutliple FILE back ends (though arguably once you have a VFS, perhaps it is only the stdin/stdout/stderr that you care about, so the "replacement" APIs could just call back for those |
Thank you for your comment, pico_filesystem VFS linked I think |
…ct with STDIN/OUT/ERR
…conflict with STDIN/OUT/ERR
This problem has been fixed and the VFS file descriptor for pico_filesystem is now issued from |
To avoid inhibiting pico_stdio, file descriptors |
This is the |
Thanks for the 2.0.0 release! This is a good hook point. I'll modify it to fit this API and test it. |
Aligned with pico-sdk v2.0.0 build layout
I finally got my hands on Pico 2 and have made the following fixes and verifications
Onboard Flash and SPI SD card operation is also no longer a problem. |
This awesome stuff and I'm looking forward using it. Thanks for sharing. How do you define the range of flash being used by the file system? The end of the flash is notably used by btstack to store paired devices' keys, we don't want those to be overwritten. Do you check and assert if the firmware overlaps with the flash file system specified? Can I check how much space is currently used and how much is available on the file system? |
So it looks like the default configuration is not taking care of leaving the Bluetooth storage alone. |
It is possible to change where bluetooth stores its keys by defining PICO_FLASH_BANK_STORAGE_OFFSET and PICO_FLASH_BANK_TOTAL_SIZE. |
Does each flash file use at least a 4K sector or is it somehow managed at the flash page level? Answer: |
I'm planning to do it the other way around. I'll define a FS configuration that leaves enough space for my firmware and BT storage. |
I got it working fine it seems. For those interested on how it looks for real take a look at that: oyama/pico-vfs#59 Basically the above samples forgot to mention you need to format your file system before it can be mounted and used. |
Why do we need the littlefs submodule in pico-sdk when it is already present in pico-vfs? |
Worth noting that this also works through C++ fstream. |
Thank you for your comment. My response is delayed as I was on a long business trip. The reason for registering the littlefs submodule in both pico-vfs and pico-sdk is to avoid modifying the pico-sdk installation instructions. As you pointed out, a more natural layout would be to register littlefs as a submodule only once under pico-vfs. However, since git does not clone submodules recursively by default, we would need to adjust the pico-sdk installation process. To avoid this, I added littlefs directly as a submodule in pico-sdk as well, creating a flat submodule structure for the pull request. |
This pull request adds flexible file system and POSIX file API support to pico-sdk. This PR fixes the following Issue:
#531
#767
#1663
The file system consists of several libraries, starting with the pico_filesystem library. Users are free to build the file system they need for their embedded projects using the familiar POSIX and C standard file API.
The pico_filesystem library contains two block devices with on-board flash memory and SPI connection SD card support. The file systems available are FAT and littlefs. The pico_filesystem library is enabled by simply appending the following function to
CMakeLists.txt
in the user project:pico_enable_filesystem(${CMAKE_PROJECT_NAME})
Users can programmatically
#include <pico/filesystem.h>
and callfs_init()
to manipulate files with the familiar POSIX file API:In the default configuration, littlefs with onboard flash memory as block device is mounted in
/
. I have prepared a sample project pico-filesystem-examples repository that uses this actual diff, see also here.Libraries to be added
The pico_filesystem consists of the block device abstraction library, the file system abstraction library and the virtual file system library pico_filesystem, which integrates these as Newlib system calls.
Any block device can be combined with any file system. Users can select only the libraries they need and add them to their projects.
Configuration filesystem
Block devices and file systems are each abstracted and can be freely combined. For example, the following combinations are possible:.
/
for littlefs on flash and/sd
for FAT on SD cards.To set a non-default file system, write
CMakeLists.txt
as follows:.pico_enable_filesystem(${CMAKE_PROJECT_NAME} FS_INIT my_fs_init.c)
You can freely design your own file system with your own fs_init() function.
Of course, blockdevice_t and/or filesystem_t objects can also be implemented by users themselves and added to the system.
Program size per library combination
Supported POSIX and C standard file API
The pico_filesystem library implements basic Newlib "system calls", allowing users to
#include <stdio.h>
and use a wide range of POSIX and C standard file APIs. The familiar success is set to 0, failure to -1 and errno. A list of tested APIs is available.Testing
The pico-filesystem-examples project contains unit and integration tests for pico_filesystem.
This library is BSD-3-Clause licensed. See also the pico-vfs repository for more information.
Regards,