Skip to content

OTA Update Configuration

HacK edited this page Mar 7, 2020 · 11 revisions

OTA (Over-The Air) Updates allow the ESP8266 to update itself via the WiFi connection.

esp-open-rtos currently supports OTA updates via TFTP, using a built-in TFTP server.

Note that HomeACcessoryKid/life-cycle-manager offers a very friendly way to securely update OTA. It also extended rboot to use power cycles to change behaviour. 20000+ devices out there already used it...

Important: TFTP updating is not secure and is not suitable for distribution to end users or use over insecure networks where other parties may have access. Do not use this mechanism for production systems! This issue explains the current challenges to having a production-safe OTA update mechanism using TLS.

Using rboot Bootloader

OTA updates use the open source rboot bootloader by raburton. This bootloader is used for the default non-OTA firmware images built by esp-open-rtos.

Note that esp-open-rtos is not a configuration officially supported by esp-open-rtos, so please report bugs to us not to raburton!

"Big flash" mode

rboot supports having multiple "slots" (two slots by default) for firmware, where a valid image can be contained in any slot. A field in the rboot configuration sector (located near the beginning of the flash) tells it which slot to boot from. During an OTA, the update mechanism will write to an alternative slot (ie if firmware runs from slot 1 then it will write to slot 0), and then update the config sector to boot from this slot.

rboot support "big flash" and "non-big-flash" modes. esp-open-rtos only supports using rboot in "big flash" mode. In "big flash" mode every firmware image is flashed at the same offset, modulo 1 megabyte, in the flash. This is handy because the ESP8266 can only map up to 1 megabyte of flash into the execution space at a time, so we can compile one binary image and flash it to any slot. The bootloader switches the flash mapping so a constant address range will point to the current slot.

"Big flash" mode is the default.

Steps to support OTA updates

1. Build and flash an OTA-enabled firmware

Any esp-open-rtos firmware can be OTA-enabled if you include extras/rboot-ota component to the Makefile. And run TFTP server task with ota_tftp_init_server(TFTP_PORT);.

If you're just getting started, try the ota_basic example in the esp-open-rtos source tree:

cd examples/ota_basic
make flash

... reset the ESP8266 and the ota_basic example should print a message indicating that it is currently running at slot 0/2, offset 0x2000:

OTA Basic demo.
Currently running on flash slot 0 / 2.

Image addresses in flash:
*0: offset 0x00002000
 1: offset 0x00102000
Starting TFTP server...

2. OTA Updating over TFTP

The ota_basic example uses the built-in OTA TFTP server task to update. To flash a new image, look for the IP of the ESP8266 (printed on serial) then use the TFTP command line tool to upload the image:

tftp -v -m octet 192.168.0.20 -c put firmware/ota_basic.bin firmware.bin

... replace the IP with the IP of your ESP8266.

Repeat flashing should swap the boot offset between slot 0 and slot 1 (ie 0x2000 and 0x102000)

Troubleshooting

  • A crash when booting from slot 1 and flashing into slot 0, which then apparently "bricks" the device, indicates that BOOT_BIG_FLASH was not enabled in the rboot config.