Backup & Restore ESP8266

Download esptool.py, and ensure you have the python-serial dependency installed:

# apt-get install python-serial

Now you can backup the RAM via:

python ./esptool.py --port /dev/ttyUSB4 --baud 115200 read_flash 0x00000 0x400000 backup.img

And upload to the device again:

deagol ~ $ python esptool.py --port /dev/ttyUSB4 write_flash -fm qio 0x00000 backup.img
esptool.py v2.0-beta3
Connecting....
Detecting chip type... ESP8266
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0040
Compressed 4194304 bytes to 295183...
Writing at 0x00048000... (100 %)
A fatal error occurred: Timed out waiting for packet header

That "fatal error" seems to be no such thing, but you do need to powercycle the board before your (restored) program will launch, or see below for scripting that.

NOTE: In the command above we specified the flash-mode, via "-fm qio. If you see checksum errors or failures you might wish to use the dout method instead with "-fm dout". (Valid choices for flash-mode are 'qio', 'qout', 'dio', & 'dout'.)

Other Options

You can do more with this tool, the most useful two things I've found are:

Reading the MAC address

deagol ~ $ python esptool.py  --port /dev/ttyUSB4  --baud 115200 read_mac
esptool.py v2.0-beta3
Connecting....
Detecting chip type... ESP8266
Uploading stub...
Running stub...
Stub running...
MAC: a0:20:a6:16:45:d2
Hard resetting...

Resetting the board

deagol ~ $ python esptool.py --port /dev/ttyUSB4 run
esptool.py v2.0-beta3
Connecting....
Detecting chip type... ESP8266
Uploading stub...
Running stub...
Stub running...
Hard resetting...

Uploading Binary Program

You can use the Arduino IDE to export your sketch to a binary (".bin") file, via the menu-item: "Sketch | Export Compiled Binary".

If you do that you can then upload the program:

deagol ~ $ python ~/esptool.py --port /dev/ttyUSB4 --baud 115200 write_flash 0x00000 ~/Blink/Blink.ino.d1_mini.bin
esptool.py v2.0-beta3
Connecting....
Detecting chip type... ESP8266
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0040
Compressed 226272 bytes to 164301...
Wrote 226272 bytes (164301 compressed) at 0x00000000 in 14.4 seconds (effective 125.8 kbit/s)...
Hash of data verified.

Leaving...

See-Also

See also performing OTA uploads via the command-line, which doesn't require the Arduino-studio.