Real files size on LFS partition | DIMI’s place

DIMI's place

My thoughts on different things

8 July 2021

Real files size on LFS partition

I’ve been trying to figure out how much space is used by files that are stored on littlefs.

TLDR:

How does platformio creates littlefs images

When you run pio run -t buildfs or pio run -t uploadfs it calls mklittlefs tool as follows:

#ESP8266: 
mklittlefs -c resources -p 256 -b 8192 -s 1024000 .pio/build/nodemcuv2/littlefs.bin

#ESP32: 

tools/mklittlefs -c resources -p 256 -b 4096 -s 1507328 .pio/build/esp32/spiffs.bin

Where:

So if your storage drive block size is 4096, and littlefs is 8192, then you’ll get different size.

There are few different tools that would allow to analyze generated image. Let’s take a look at some of them.

Folder size comparison approach (Linux FS & LittleFS-fuse):

It is possible to mount generated littlefs.bin image using littles-fuse, where you would get normal filesystem.

There’s great article that explains how to mount on linux.

Side-by side comparison gives different result.

Comment result Linux result LittleFS command
Original resource folder (ls) 90673 108665 ls -la
Original resource folder (du) 116K 176K du -h .

Platformio output / Other Tools

Data that is generated by platformio is not informative, it gives Image size & compression size during transfer. That roughly corresponds to what you would get by tar-gzip of resources folder:

Comment result command
Platformio upload size 1MB / 38511 compressed platformio run -t uploadfs
binwalk ???, see below python -m binwalk img.bin
tar & gzip res folder 38269 GZIP=-4 tar -zcf res2.tar img.bin

Binwalk output:

It is possible to see fs contents using binwalk using command python -m binwalk img.bin. But there’s no clear indication of size of each file (even if files are detected correctly), just an address and address of next file.

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
286736        0x46010         HTML document header
298549        0x48E35         HTML document footer
303104        0x4A000         XML document, version: "1.0"
303338        0x4A0EA         Copyright string: "copyright ownership."
335950        0x5204E         HTML document header
339610        0x52E9A         HTML document footer
345578        0x545EA         Boot section Start 0x42424242 End 0x42
345582        0x545EE         Boot section Start 0x42 End 0x0
368640        0x5A000         PNG image, 10 x 250, 8-bit/color RGBA, non-interlaced
376832        0x5C000         PNG image, 136 x 30, 8-bit/color RGBA, non-interlaced
376910        0x5C04E         Zlib compressed data, best compression
385184        0x5E0A0         HTML document header
386675        0x5E673         HTML document footer
393216        0x60000         PNG image, 10 x 50, 8-bit/color RGBA, non-interlaced
401408        0x62000         PNG image, 10 x 100, 8-bit/color RGBA, non-interlaced
409793        0x640C1         Copyright string: "copyright ownership."
415130        0x6559A         Copyright string: "copyright {"
417950        0x6609E         HTML document header
420443        0x66A5B         HTML document footer
425984        0x68000         PNG image, 146 x 92, 8-bit/color RGBA, non-interlaced
426046        0x6803E         Zlib compressed data, best compression

Few words about platformio size command.

It is just a wrapper for

xtensa-lx106-elf-size -B -d .pio/build/nodemcuv2/firmware.elf

I have absolutely no idea how to match numbers generated from this commands:

pio run:

RAM:   [======    ]  57.7% (used 47292 bytes from 81920 bytes)
Flash: [========  ]  81.1% (used 847512 bytes from 1044464 bytes)

pio size: 

text    data     bss     dec     hex   filename
833484   14084   33264  880832   d70c0 firmware.elf

Troubleshooting

Sometimes fuse-mount would complain that device is busy. See url for more info.

tags: esp8266 - esp32 - littlefs - platformio - github actions