littlefs - advantages & disadvantages

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
jedie
Posts: 252
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

Re: littlefs - advantages & disadvantages

Post by jedie » Mon Dec 30, 2019 2:51 pm

jedie wrote:
Fri Dec 06, 2019 2:34 pm

Code: Select all

ESP module with ESP8266 2.2.0-dev(9422289)
MicroPython v1.11-8-g48dcbbe60 on 2019-05-29

flashbdev.size....: 1048576
reserved sectors..: 1
start sector......: 153
sector size.......: 4096
num blocks........: 106
0000 - 000f - eb fe 90 4d 53 44 4f 53 35 2e 30 00 10 01 01 00 - ..MSDOS5.0.....
0010 - 001f - f8 ff ff 00 f0 ff ff 0f 00 ff 0f 00 ff ff ff ff - ................
0020 - 002f - 42 4f 4f 54 20 20 20 20 50 59 20 20 18 00 51 b6 - BOOT....PY....Q.
0030 - 003f - e5 41 54 43 48 44 4f 47 4d 50 59 20 18 00 19 86 - .ATCHDOGMPY....†
0040 - 004f - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 - ................
0050 - 005f - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 - ................
0060 - 006f - 4d 04 02 1f 20 82 00 03 00 30 00 00 00 07 07 00 - M....‚...0......
0070 - 007f - 4d 04 02 1f 20 84 28 08 00 00 00 00 00 07 07 00 - M....„(.........
0080 - 008f - 4d 04 02 1f 20 81 04 02 00 30 00 00 00 07 07 00 - M.......0......
0090 - 009f - 4d 04 02 1f 20 81 14 02 00 30 00 00 00 07 07 00 - M.......0......
littlefs filesystem looks like this:

Code: Select all

ESP module with ESP8266 2.2.0-dev(9422289)
MicroPython 1070984 on 2019-12-30

flashbdev.size....: 1048576
reserved sectors..: 1
start sector......: 153
sector size.......: 4096
num blocks........: 106
0000 - 000f - f9 ff ff ff f0 0f ff f7 6c 69 74 74 6c 65 66 73 - ........littlefs
0010 - 001f - fa ff ff ff f0 0f ff f7 6c 69 74 74 6c 65 66 73 - ........littlefs
0020 - 002f - 42 4f 4f 54 20 20 20 20 50 59 20 20 18 00 16 00 - BOOT....PY......
0030 - 003f - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 - ................
0040 - 004f - 3c 66 69 65 6c 64 73 65 74 3e 3c 6c 65 67 65 6e - <fieldset><legen
Seems that 0x0040 contains already user data...

Ricardo
Posts: 11
Joined: Mon Dec 09, 2019 9:49 pm

Re: littlefs - advantages & disadvantages

Post by Ricardo » Thu Jun 18, 2020 5:39 pm

I lost my LittleFS partition.

It seems it isn't resilient to power failure after all, at least on the ESP32 with firmware esp32-idf3-20200509-unstable-v1.12-447-gab4e19770.

Everything was working fine for a few days, including powering the system up and down several times. Today I disconnected the power from the ESP32 and connected it to the PC to update a script. Rshell couldn't get a REPL prompt and got stuck after displaying "Testing if ubinascii.unhexlify exists ...". When I opened the Thonny editor, it was showing this message in a loop:
FAT filesystem appears to be corrupted. If you had important data there, you
may want to make a flash snapshot to try to recover it. Otherwise, perform
factory reprogramming of MicroPython firmware (completely erase flash, followed
by firmware programming).
I still could press [CTRL]+[C] to break from that loop and get a REPL prompt. No files were listed with os.listdir().

Fortunately, I didn't lose any important data, but now I'm worried about how to avoid this in the future.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

There is a bit more to it, I'm afraid

Post by pythoncoder » Fri Jun 19, 2020 6:08 am

If a system is to be tolerant of power failure it needs to be considered as a system: a resilient filesystem is necessary but not sufficient to guarantee this.

When power fails, the voltage on the chip can suffer spikes or a gradual drop. Power can also fail gradually, known as a brownout. Under these conditions the processor can execute arbitrary code, possibly scribbling on the filesystem. A properly resilient system has electronics to detect power failure or low supply voltage. When the circuit triggers the processor's voltage is maintained within spec (from charge stored in capacitors) while the chip is shut down cleanly.
Peter Hinch
Index to my micropython libraries.

2e0byo
Posts: 2
Joined: Tue May 04, 2021 4:41 pm

Re: littlefs - advantages & disadvantages

Post by 2e0byo » Sat Oct 09, 2021 6:02 pm

This is an old thread and thus things have changed: to check for littlefs on recent micropython builds this works:

Code: Select all

def check_for_littlefs():
    from flashbdev import bdev
    buf = bytearray(16)
    bdev.readblocks(0, buf)
    return buf[8:16] == b"littlefs"
check_for_littlefs()

I expect this has been the standard for quite some time, but it was quicker to check than to read the logs and work out when that happened.

Post Reply