Used for bootstrapping the replacement of the default Espressif ESP8266 bootloader, replacing it with the Arduino bootloader and a custom rom.
This was designed specifically to replace the stock sonoff itead firmware by intercepting firmware update requests and serving these binary images. More info on how to intercept and stream this firmware to a device is here and here
The process works like this:
Current Limitations:
This is very much alpha quality at the moment, don't use this process on any devices you don't/can't manually flash if they don't boot.
From the Arduino Folder replace boards.txt and the additional ld scripts into the appropriate place for your instance of Arduino.
Update OTA URLs:
In Arduino IDE first select the Flash Size "1M (Espressif OTA Rom 1)" and build.
From your build directory run the following command and save the resulting output
esptool.py elf2image --version 2 Espressif2Arduino.ino.elf
Repeat for Flash Size "1M (Espressif OTA Rom 2)"
You should now have three files ready for serving over HTTP:
Note there are also DIO URLs for the ESP8285, these can be left blank if only flashing ESP8266 devices
Although it is intended you would flash these images OTA you can simulate the process by directly flashing Espressif2Arduino onto the currently active Espressif rom slot.
First take a backup image of your flash by running
esptool.py -p COM5 read_flash 0x0 0x100000 backup-0x00000.bin (note this is slow ~2 mins)
If rom 1 is active
esptool.py -p COM5 -b 921600 write_flash 0x01000 Espressif2Arduino.ino-0x01000.bin
If rom 2 is active
esptool.py -p COM5 -b 921600 write_flash 0x01000 Espressif2Arduino.ino-0x81000.bin
To restore your backup
esptool.py -p COM5 -b 921600 write_flash 0x0 backup-0x00000.bin
Note - there is a bug with the ESP8266 that it will stay in flash mode the first reboot after flashing by serial. Best thing to do is to flash, then immediately pull power when finished and reboot it - with this code as standard you have 5 seconds before it will try update so you can pull power in this window without an issue.
GPIO 13 is used by default as a status indicator
If you connect the serial port you should also see output like this:
Current rom: 2
Rom 1 magic byte: 0xEA
Reflashing rom: 1
Attemping to read Sonoff Wifi credentials... Done
SSID: xxx
Password: xxx
Connecting to Wifi..................Done
192.168.1.19
Flash Mode: 3
Flashing rom 1 (retry:0): http://sunlocker.khc.net.nz/static/8266/sonoff-1024.bin
HTTP response Code: 200
HTTP response length: 483088
Magic byte from stream: 0xE9
Downloading 4096 byte bootloader..Done
Erasing flash sectors 1-128................................................Done
Downloading rom to 0x001000-0x075F10 in 1024 byte blocks...................Done
Erasing bootloader sector 0..Done
Writing bootloader to 0x000000-0x001000..Done