doudar / SmartSpin2k

Transform your spin bike into a Smart Trainer!
GNU General Public License v2.0
187 stars 38 forks source link

[BUG] Unable to mount LittleFS after flashing firmware on new PCB, mounts fine after re-flashing with mobile app instead. #559

Closed jrbarrick closed 3 months ago

jrbarrick commented 3 months ago

Description

Unable to mount LittleFS after flashing firmware on new PCB, mounts fine after re-flashing with mobile app. Reproduced on 3 new PCBs. Once the issue is fixed by flashing with the mobile app, flashing later on over USB works fine.

Steps to reproduce

  1. Flashed latest firmware (24.7.9) to ESP32 over USB using the SmartSpin2kFlasher tool. Flash reports that it works fine and hashes verify. Device reboots fine, however errors are thrown related to LittleFS:
    
    Using 'COM12' as serial port.
    Connecting.....
    Detecting chip type... Unsupported detection protocol, switching and trying again...
    Connecting..........
    Detecting chip type... ESP32
    Connecting....

Chip Info:

Leaving... Hard Resetting... Hard resetting via RTS pin... Done! Flashing is complete!

Showing logs: [15:14:10][ 30]E: Compiled Apr 28 202401:49:10 [15:14:10][ 31]E: Current Board Revision is: Revision Two [15:14:10][ 33]E: Mounting Filesystem [15:14:10]./components/esp_littlefs/src/littlefs/lfs.c:1229:error: Corrupted dir pair at {0x0, 0x1} [15:14:10]E (28) esp_littlefs: mount failed, (-84) [15:14:10]E (28) esp_littlefs: Failed to initialize LittleFS [15:14:10][ 36][E][LittleFS.cpp:95] begin(): Mounting LittleFS failed! Error: -1 [15:14:10][ 38]E: An Error has occurred while mounting LittleFS. [15:14:10][ 41]E: Stopping LittleFS [15:14:10]E (34) SPIFFS: mount failed, -10025 [15:14:10][ 42][E][SPIFFS.cpp:89] begin(): Mounting SPIFFS failed! Error: -1 [15:14:10][ 42]E: SPIFFS Not Found - Could not upgrade FS [15:14:10]./components/esp_littlefs/src/littlefs/lfs.c:1229:error: Corrupted dir pair at {0x0, 0x1} [15:14:10]E (139) esp_littlefs: mount failed, (-84) [15:14:10]E (139) esp_littlefs: Failed to initialize LittleFS [15:14:11][ 653]E: Reading File: /config.txt [15:14:11][ 655][E][vfs_api.cpp:105] open(): /littlefs/config.txt does not exist, no permits for creation [15:14:11][ 655]E: Couldn't find configuration file. [15:14:11][ 658]E: Contents of file: /config.txt [15:14:11][ 659][E][vfs_api.cpp:105] open(): /littlefs/config.txt does not exist, no permits for creation [15:14:11][ 659]E: Failed to read file [15:14:11][ 662][E][vfs_api.cpp:182] remove(): /config.txt does not exists or is directory [15:14:11][ 663]E: Writing File: /config.txt [15:14:11][ 678]E: Reading File: /userPWC.txt [15:14:11][ 681][E][vfs_api.cpp:105] open(): /littlefs/userPWC.txt does not exist, no permits for creation [15:14:11][ 682]E: Couldn't find configuration file. Loading Defaults [15:14:11][ 684]E: Contents of file: /userPWC.txt [15:14:11][ 687][E][vfs_api.cpp:105] open(): /littlefs/userPWC.txt does not exist, no permits for creation [15:14:11][ 687]E: Failed to read file [15:14:11][ 692][E][vfs_api.cpp:182] remove(): /userPWC.txt does not exists or is directory [15:14:11][ 692]E: Writing File: /userPWC.txt

3. Can connect just fine with BT, and app connects to device fine.  Settings can be "saved" in the app, however they aren't saved and are lost at reboot.
4. Can retry flashing firmware over USB with no change, and also tried 24.4.28 over USB.
5. However, flashing 24.4.28 using the Firmware Update option in the mobile app seems to work different, as partition mounts fine when rebooting after flash using the app, and settings can be saved without any issues:

[15:17:39]1. BeginOTA2. Running partition type 0 subtype 16 (offset 0x00010000) [15:17:39]3. Writing to partition subtype 17 at offset 0x1f0000 ... [15:20:20]..................................................................................4. Final byte arrivedSet Boot partionRestarting... [15:20:20][ 31]E: Current Board Revision is: Revision Two [15:20:20][ 33]E: Mounting Filesystem [15:20:20][ 38]E: Reading File: /config.txt [15:20:20][ 60]E: Config File Loaded: /config.txt [15:20:20][ 61]E: Contents of file: /config.txt [15:20:20][ 86]E: Writing File: /config.txt [15:20:20][ 110]E: Reading File: /userPWC.txt [15:20:20][ 135]E: Config File Loaded: /userPWC.txt [15:20:20][ 135]E: Contents of file: /userPWC.txt [15:20:20][ 171]E: Writing File: /userPWC.txt



**Expected behavior**
Firmware boots and mounts LittleFS

**Actual behavior**
Firmware boots and fails to mount LittleFS

### Additional Information
Full log:
https://pastebin.com/eMT0VqZS
doudar commented 3 months ago

This might be just as much as an issue with documentation.

On initial installs, in PlatformIO, you need to select "upload file system image" as well.

The upgrade probably works because there's a littlefs.format() in order to fix errors like this.

In new branches (close to being merged) I removed the spiffs upgrader (firmwares that were over two years old used spiffs). Instead of the upgrader, I should probably place a format() on boot if the files cannot be accessed.

Fwiw, using "reset to defaults" in the app or settings web page should work as well.

Thanks for the report!

jrbarrick commented 3 months ago

Read the LittleFS docs a bit as well, looks like you can just call LittleFS.begin(true) instead of LittleFS.begin(false) and it will format the LittleFS partition if it doesn't exist. Did some testing on my end and it seems like that does the trick.

doudar commented 3 months ago

I'm guessing it was set to (false) previously for the upgrade logic to work correctly. I think for now I slightly prefer keeping the format() inside of the if statement, just for readability.

I'd love any more insight you might have! Thanks for the help!