jkearins / ESP32_mkfatfs

Prepare FAT image on host and flash to ESP32.
Apache License 2.0
43 stars 12 forks source link

Latest esp-idf (VFS V2?) cannot be mounted after reboot #7

Open paulreimer opened 6 years ago

paulreimer commented 6 years ago

Noticed that esp-idf has made some updates to VFS, or at least this component now behaves differently with the latest esp-idf master.

The filesystem seems to work (all files read as expected) after a fresh erase_flash and then flashing the fatfs image to the partition offset. But it does not persist a reboot (e.g. it cannot be mounted after reset button is toggled, or after a software triggered reboot)

There is some new logging here on the first boot here:

I (105) wl_flash: updateV1_V2 Update from V1 to V2, crc=0x69c05153,
I (107) wl_flash: updateV1_V2 max_pos=29, pos=25, state.ver=1, state2.ver=1

Upon reboot I get the following error when mounting:

W (521) vfs_fat_spiflash: f_mount failed (13)

This makes me think esp-idf has changed upstream, and this repo should update the esp-idf components to be generating images in this new "V2" format? At least, in my case I do not need to support both formats -- preferably only the latest one.

TobleMiner commented 6 years ago

I'm running into this issue, too. There seems to be a v2 (https://github.com/espressif/esp-idf/commit/a6d6c58ecadb9759a0bacf35cd7332ac641e598d#diff-56bcb985916387b5e0fcebb24c6b0c7c) of the wear leveling algorithm which is incompatible with the v1 wear leveling storage format. Although there is code to transition v1 wear leveling storage to v2 wear leveling storage it fails to update fat filesystems created via ESP32_mkfatfs to the new wear leveling format.

TobleMiner commented 6 years ago

@paulreimer I've created a new tool with a much cleaner code base at https://github.com/TobleMiner/mk_esp32fat . It works great with the latest esp-idf master branch. Please feel free to check it out.

The only donwside is that my tool does currently not support 512 byte sector size.

paulreimer commented 6 years ago

@TobleMiner regretfully I am using 512 byte sector size at this time. If you add support for that (or maybe there's another way I wouldn't need it -- for long file names / verified writes), please let me know!

paulreimer commented 6 years ago

I'll note that this recent esp-idf commit: https://github.com/espressif/esp-idf/commit/cd38970ef9bb501d1f20c5ccf76b0b86416a499b

Appears to have partially addressed this issue. Reboots on a valid V1 filesystem (after V2 conversion) are no longer an issue. If the filesystem boots the first time, it seems to upgrade V1->V2 and works on subsequent V2 reboots. Great!

But, now it seems a little flaky when flashing the FATFS the first time. I've had a couple times where it didn't flash successfully, and no initial mount happened (so before the V1->V2 conversion, I think). Re-flashing it seems to work, but I can't explain why it wouldn't work 100%.