-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
nrf: Add flash block device for VFS filesystems. #5472
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
Conversation
Quite a few of the questions in the forum and in the issue tracker relates to using I'm having some issues formatting the FAT partition using native block device functions. (When multipartition is enabled). It looks like |
Thank you glennrub for this PR. When adding MP_QSTR_ilistdir and MICROPY_PY_UERRNO (and of course MICROPY_VFS_VFAT, MICROPY_VFS_LFS1, MICROPY_VFS_LFS2 plus minor changes on moduos.c) all Fat and LittleFS tests are passing (with vfs_fat_ramdisklarge.py (way too large for Particle Xenon boards) and vfs_userfs (uio not available) skipping), which is fantastic. Using vfat seems to work pretty well, formatting and using the fs
Shouldnt modules under /lib be able to import?
Writing on /test.py will import correctly
The extended interface needed for littlefs seems to be missing so far, but maybe can be worked out in a future PR? I am happy to help.
In any case thank you again for this great addition (including the ability to use rshell ;) and happy New Year! |
You're using the Also, what is the block size and how many blocks are there? It may be that FATFS cannot format what you give it, eg too small. |
OK, I have add this pull to my local repo:
but after building I don't seem to see the included PR, do I need to do anything else other than the above to include a PR ? Do I need to change my make command ?? |
For my custom board, I added the following to mpconfigboard.h
and my make is:
And the build fails:
Similar thing happens with pca10056:
Would it be possible to provide some notes on how to implement this PR :-) |
Not sure what is the issue. The tests I mentioned above were done introducing the exact same changes you did in mpconfigboard.h into pca10059 and simply make BOARD=pca10059 MICROPY_VFS_FAT=1 as mention in https://github.com/micropython/micropython/tree/master/ports/nrf#enable-micropy_vfs_fat Hope it helps |
Thanks, I tried a fresh clone of micropython, but as soon as I un-comment: //#define MICROPY_VFS (1) The build fails, when commented the build is successful. I have done this a few times to be sure, did you also pull in PR5472 or ar you using the master branch ? |
I don't understand. I thought your repo was in this state From there make BOARD=pca10056 MICROPY_VFS_FAT=1 does compile and glennrub said its working there. |
Yes, but I don't know if this is the complete / only command to run to pull in the PR as I have never attempted that before. If i revert to the master, then the build is successful, however os shows no new FS functions:
|
OK, sunday morning and si I thought I would try this again:
and:
There just has to be some step missing, I have spent 2 days on this and made no progress whatsoever. Disable the 3 lines in mpconfigboard.h and it builds, enable them and it does not. How / where can I check that the following are correctly defined:
As these appear to be the vars / functions that is causing the errors ?? |
OK, finally found the cause, it was due to a typo in my config but not in my posts here: Which should have been: So the build now works and I can access the file system after:
But still unable to use rshell on the PCA10056:
on my custom board, everything works including rshell. |
OK, a new finding. If you set: Then you get the error I was seeing before:
|
Thanks a lot @mzdaniel and @pacmac for the great feedback. I've updated the branch with a second commit. @pacmac, i have added support for Pending work i'm looking at is to allow for I'm considering that none of the compiled in FS should auto format the flash partition, but only mount it if it is possible. In other words, this should should be an explicit documented action how to format the various VFS file systems. I'm also looking into splitting the Some stats on RAM/ROM usage collected:
|
@dpgeorge 256K flash, 4096 block size (which is also my page size on the nrf52840). I'll postpone this a bit, as it is always working with uos.VfsFat.mkfs(), and with |
Fantastic @glennrub! According to a very quick test, with this PR, littlefs works natively on xenon's flash and rshell with it. I'll do more extensive tests, including migrating a production device to littlefs. Re splitting mpconfigport.h: +1. This should make the code cleaner and improve reliability. Regarding VFS block size, 4K for a tiny FS of 256K seems really big. I didn't read littlefs specs (yet), but if a file takes a full block, this means the fs cannot host many files. |
Awesome @glennrub! Look forward to test them. BTW, I have a device continuously running on a lipo battery and using littleFS for a few months now with no issues. |
Updated the PR with a split of the earlier commits. In the process i also moved out the All target boards now have LittleFS2 activated (except nrf51 with s110) and 64K file system size as default. This is too small for FAT in order to format it, which i expect no-one will use on the internal flash file system. Also cherry-picked the commits from #5379 to freeze a manifest containing the file system formatting script. What's left:
|
7828207
to
0a678ef
Compare
Just add another entry in
stm32 supports both internal and external flash storage (the latter via an external SPI flash). It might make sense to follow that logic here, but not 100% sure. |
Is my interpretation of
I guess this should be similar in the nrf-port. In addition I'm thinking that it also makes sense to change |
Adding "nrf" module for port specific modules and objects. Adding "flashbdev" object exposed through the "nrf" module. The "flashbdev" expose a block device implementation to access internal SoC flash. Thanks to @aykevl aka Ayke van Laethem for the initial implementation.
Update flash.c to also be compiled in when MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE is enabled and SoftDevice is present. Updating bluetooth/ble_drv.c to forward flash events to flash.c when MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE is enabled.
Documenting parameters that can be passed to make to enable a specific file system to included in the build. Also, documenting the makefile override parameter "FS_SIZE" that can be used to tune the size of the flash region to use as internal flash file system.
Disabling MICROPY_FATFS_MULTI_PARTITION configuration. Also, setting MICROPY_FATFS_MAX_SS to the size of a flash page. For nrf51 the value 1024 is set. For nrf52/nrf91 the value 4096 is set.
Add posibility to override linker script "_fs_size" from make by adding the FS_SIZE parameter. The syntax of value is linker script syntax. For example, the value of 131072 bytes can be written as 128K like this: FS_SIZE=128K. If not set, default value for "_fs_size" from linker script will be used.
Enable MICROPY_PY_IO_FILEIO if MICROPY_VFS_FAT, MICROPY_VFS_LFS1 or MICROPY_VFS2 has been enabled.
Enable the following features for all boards except nrf51 boards with SoftDevice present: - MICROPY_VFS - MICROPY_PY_NRF - MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE And in case of LFS1 or LFS2: - MICROPY_HW_BDEV_READBLOCKS_EXT
Updating Makefile to handle FROZEN_MANIFEST. Updating README.md with some small samples on how to use freeze manifests. Adding BOARD_DIR to the Makefile which can be referenced in boards/<board>/mpconfigboard.mk to include a board specific manifest.
Adding the helper script _mkfs.py which automatically formats the file system if nrf.Flash() is located and a VFS file system has been included in the compilation. The precedence is; first LFS1, LFS2 then FAT.
Setting default manifest to "modules/manifest.py". This includes files from the folder "modules/scripts". The manifest default value is overriden by all nrf51 boards that has SoftDevice present (SD=s110). Adding "modules/manifest.py" which is set to freeze the "modules/scripts/_mkfs.py".
extmod/vfs_lfs.c needs to resolve `mp_hal_time_ns()` in order to calculate a timestamp from 1970 epoch. A wall clock is not available in the nrf-port. Hence, implementing the function needed to resolve compilation linkage error. The function always return 0.
Enable LittleFS v2 for all targets, except nrf51 targets when SoftDevice is present.
3dc17b5
to
0bc61cf
Compare
I succeeded in compiling the Not sure how to fix this though. It seems that both the defines for |
@glennrub, @dpgeorge. Could it be possible to merge this PR? It used to be in great shape for significant periods of time, but of course plenty of things keep changing underneath. Currently the PR rebased on top of master compiles (after solving trivial conflicts), formats the flash, and writing simple files with open seem to work, but trying to create directories or writiting files with mpremote freezes the microcontroller. Would it be easier to split the PR at this point? (eg: adding the flash device in itself would be a great incremental addition) And of course let me know if we need more testing, I have several nrf boards we can use. Thank you for keeping to push forward Micropython! |
I've rebased this PR on the latest master and submitted it as #7619. Would be good to get it merged. |
Fantastic. I'll add my findings there |
Update README in docs/
Follow up on @aykevl's work on providing a block device for the
nRF device's internal flash.
Updating the pca10056 target to use the block device for
VFS/FATFS.
Enabling MICROPY_PY_ARRAY_SLICE_ASSIGN, MICROPY_PY_SYS_STDFILES
and MICROPY_PY_UBINASCII to work with rshell.
Also updated the flash.c driver and ble_drv.c to support flash
access from the flash block device when SoftDevice is active.