-->
Page 1 of 1

Flashing ESP8266 with a LittleFS binary

PostPosted: Wed Oct 21, 2020 4:42 am
by trullock
I'm trying to build a LittleFS file system binary on my PC and flash it to my WeMos D1 Mini Pro (16MB) ESP8266.

I used the following code on the ESP

Code: Select all   LittleFS.begin()

   FSInfo info;

   LittleFS.info(info);

   Serial.print("LittleFS block size:");
   Serial.println(info.blockSize);

   Serial.print("LittleFS total bytes:");
   Serial.println(info.totalBytes);


To determine the block size and total bytes, which gave me `8192` and `14655488` respectively. `14655488 / 8192 = 1789` so I used `1789` as the block size in the below python:

Code: Select allfrom littlefs import LittleFS

fs = LittleFS(block_size=8192, block_count=1789)

with open( 'index.html', 'rb' ) as f:
   data = f.read()

with fs.open( '/index.html', 'w') as fh:
   fh.write( data )

with open('fs.bin', 'wb') as fh:
    fh.write(fs.context.buffer)


This creates a 14655488 bytes .bin file.

I then looked in `boards.txt` and found these lines:


Code: Select alld1_mini_pro.menu.eesz.16M14M=16MB (FS:14MB OTA:~1019KB)
d1_mini_pro.menu.eesz.16M14M.build.flash_size=16M
d1_mini_pro.menu.eesz.16M14M.build.flash_size_bytes=0x1000000
d1_mini_pro.menu.eesz.16M14M.build.flash_ld=eagle.flash.16m14m.ld
d1_mini_pro.menu.eesz.16M14M.build.spiffs_pagesize=256
d1_mini_pro.menu.eesz.16M14M.upload.maximum_size=1044464
d1_mini_pro.menu.eesz.16M14M.build.rfcal_addr=0xFFC000
d1_mini_pro.menu.eesz.16M14M.build.spiffs_start=0x200000
d1_mini_pro.menu.eesz.16M14M.build.spiffs_end=0xFFA000
d1_mini_pro.menu.eesz.16M14M.build.spiffs_blocksize=8192


This confirms the block size and gives the SPIFFS (but LittleFS is equivalent here, right?) start address as `0x200000`


So then I used:

`python upload.py --chip esp8266 --port COM6 --baud 460800 write_flash 0x200000 fs.bin`

which outputs:

Code: Select allesptool.py v2.8
Serial port COM6
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: ec:fa:bc:6e:19:90
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 16MB
Compressed 14655488 bytes to 215596...
Writing at 0x00234000... (100 %)
Wrote 14655488 bytes (215596 compressed) at 0x00200000 in 56.7 seconds (effective 2067.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...


However, when I then use code like the below


Code: Select allDir root = LittleFS.openDir("/");
while (root.next())
{
   Serial.print(root.fileName());
}



I get nothing, and

Code: Select allLittleFS.exists("/index.html")


returns false.

What am I doing wrong, or how do I debug this?

I'm uploading my firmware (not the filesystem) via Visual Studio Code, and the board configuration I'm using is

Code: Select all"xtal=80,vt=flash,exception=legacy,ssl=all,eesz=16M14M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=921600"


If I open the `bin` in a hex editor, I can see:
Image

Which is some javascript inside the html file.

If I do this:

Code: Select all   uint32_t b;
   ESP.flashRead(0x006C2800 + 0x200000, &b, 1);
   Serial.println(b);


then it returns `115`/`0x73`, so it looks like the binary has flashed successfully, so that leaves me with either the binary being flashed in the wrong place, or it being corrupted/invalid....