ESP8266 FOTA Introduction: Espressif Systems IOT Team
ESP8266 FOTA Introduction: Espressif Systems IOT Team
Version 1.6
All trade names, trademarks and registered trademarks mentioned in this document are property of
their respective owners, and are hereby acknowledged.
Table of Contents
1. Preambles ...................................................................................................4
4. User Guide...................................................................................................9
4.1. How to generate user1.bin and user2.bin ...............................................9
6. Appendix....................................................................................................18
6.1. Naming Template ...................................................................................18
1. Preambles
Herein, we introduce how to upgrade firmware through WiFi (FOTA: Firmware Over The Air) base on
Espressif Cloud.
It contains the storage of firmware in flash, FOTA procedure and APIs introduction, as a reference for
software developer.
For firmware support FOTA, we need to compile to generate images as below and burn them into flash
to run:
2. Flash Layout
We only introduce load region layout of firmware which support FOTA here.
User App1 and User App2 are two images generated by compiling the same application code
(user1.bin and user2.bin when downloading).
The original flash.bin and irom0text.bin are combined to user1.bin (or user2.bin) for upgrading. One of the
user.bin is also a backup for the other in case of upgrading failure.
Bootloader (boot.bin) will check the flag in System param area to decide whether execute User App1
(user1.bin) or User App2 (user2.bin).
Example:
(1) We download boot.bin and user1.bin (Version 1.0.0) to flash. Flag in system param area also be
marked as user1.bin by default. In this case, after power up, it will always execute from user1.bin.
(3) The server will push a message of new SW available. If device got this message, it will check the
flag first, flag sets as user1, so download user2.bin of v1.0.1 to flash region 260KB~496KB to
upgrade.
(4) After download finish, end user will get FOTA message, decide whether they accept firmware
upgrade. If they accept, then we'll modify the flag to user2 and reboot to run user2.bin. Otherwise
nothing will happen.
(5) Next upgrade, starts at step 2, and download user1.bin of v1.0.2 to flash region 4KB~240KB
covering the original user1.bin of v1.0.0 .
NOTE:
• We need to generate both user1.bin and user2.bin during compiling time and upload both to server.
Device will determine which bin it need to download.
• user1.bin and user2.bin are same software placed to different regions of flash. The only difference is
address mapping on flash.
• We usually do not burn user2.bin into flash, we burn user1.bin into flash first, and upgrade to
user2.bin through WiFi (FOTA).
• User Data area ( green area in pictures below ) means the flash area that may be available, if
program area ( user1.bin and user2.bin) doesn’t reach the maximum size, remaining area can be
used to save user data.
1. 1024KB flash
If choose 1 boot_v1.2+ in STEP 1, choose 2 1024KB in STEP 5, flash map will be as below
User1.bin User2.bin
(max 492KB) (max 492KB)
Boot User param Reserved System param
(4KB) (16KB) (4KB) (16KB)
2. 2048KB flash
If choose 1 boot_v1.2+ in STEP 1, choose 3 2048KB in STEP 5, only the first 1024KB to be the program
area ( 512KB + 512KB ), flash map will be as below
User1.bin User2.bin
(max 492KB) (max 492KB)
Boot User param Reserved System param
(4KB) (16KB) (4KB) (16KB)
If choose 1 boot_v1.2+ in STEP 1, choose 5 2048KB in STEP 5 (only be supported since sdk_v1.1.0 +
boot 1.4 and later version), the program area is 1024KB + 1024KB, flash map will be as below
User1.bin User2.bin
(max 1004KB) (max 1004KB)
Boot User param Reserved System param
(4KB) (16KB) (4KB) (16KB)
3. 4096KB flash
If choose 1 boot_v1.2+ in STEP 1, choose 4 4096KB in STEP 5, only the first 1024KB to be the program
area ( 512KB + 512KB ), flash map will be as below
User1.bin User2.bin
(max 492KB) (max 492KB)
Boot User param Reserved System param
(4KB) (16KB) (4KB) (16KB)
If choose 1 boot_v1.2+ in STEP 1, choose 6 4096KB in STEP 5 (only be supported since sdk_v1.1.0 +
boot 1.4 and later version), the first 2048KB to be the program area (1024KB + 1024KB), flash map will
be as below
User1.bin User2.bin
(max 1004KB) (max 1004KB)
Boot User param Reserved System param
(4KB) (16KB) (4KB) (16KB)
3. FOTA procedure
FOTA procedure will be executed after new firmware bin files are uploaded to server and "upgrade"
button is pressed. FOTA procedure is only executed if server firmware version is newer then device
firmware version.
1 4 6
2
3 5 7 9
1. during device activation, device will upload its version information to server. Server will record
device version information;
2. normal usage;
4. device request firmware according to its device key and upload path (user1.bin or user2.bin).
7. server will push this message to APP, APP display this information to end user.
The communication between device, service and APP can be encrypted by SSL. Device key is
required from Step4. Therefore upgrade procedure is secure.
Note:
Some device (e.g. the sensor device) will enter sleep mode in idle state. Such device do not support
remote control. Our FOTA feature is only available on those device support remote control. For devices
that don't support remote control, FOTA will be supported later.
4. User Guide
4.1. How to generate user1.bin and user2.bin
user1.bin and user2.bin are two images generated by compiling the same application code, they are
same software placed to different regions of flash. The only difference is address mapping on flash.
We compile them by choosing a boot:
Note:
MUST upload both user1.bin and user2.bin to server. Device will decide which one it will download.
If FOTA is not supported, please refer to " Espressif IoT SDK User Manual " for compile and download
operations.
boot.bin 0x00000 Boot loader, provided in SDK, recommend to use the latest
version
user2.bin need not to be burned into flash, it can be download through WiFi as upgrade.
For future updates, please upload both user1.bin and user2.bin to the server and the server will send
update information to users. If users choose to update, then the device will select and download
user1.bin or user2.bin, whichever is necessary for cloud update.
(1) Login into http://iot.espressif.cn/#/ , click “Product”. It will list all your products.
(2) Click a product which need to update firmware, find “ROM Deploy” at the right side of webpage.
For example, we click “dev-controller” at above picture, and find “ROM Deploy”.
(3) Click “+ Deploy” to upload a new version of firmware. Follow steps showing below. ROM version
format as “v1.0.1t23701(a)” according to appendix.
(4) After “Save”, we can find it on this page. Click “Set as Current” to use the new firmware. Then
server will notify all devices of product “dev-controller” that there is a new version of firmware,
users can choose to upgrade or not.
(7) Click “Device”, choose a device of product “dev-controller”, find “ROM Deploy” in the device’s
page, choose the version of firmware, click “Upgrade”.
(8) Then device will download the new firmware. If device is running user1.bin right now, it will
(9) After finish downloading, we can send command from website to device, to make device reboot
and run the new firmware. In the page of device, find “RPC Request”, follow “action=” with
“sys_reboot”, then click “Request”, this device will receive the request and reboot to run new
firmware.
(10) Device receives the request and reboots to run new firmware.
“Device " refers to the operation which that the device runs by itself and needs no user intervention.
"PC” refers to the commands that users can send to the device to run.
1. Request to upgrade
◇ PC
Linux/Cygwin curl:
Windows curl:
◇ Device
{"body": {}, "nonce": 855881582, "get": {"action": "sys_upgrade", "version": "v1.0.1t23701(a)", "deliver_to_device":
2. Download Finish
◇ Device
When device receives request to upgrade, it starts to download the new version of firmware (bin file)
from server. While finish downloading, device will send data below to server, notify that download
succeed.
3. Restart to update
◇ PC
While device notifies that download succeed, PC send a command to control device restart to use the
new firmware.
Linux/Cygwin curl:
Windows curl:
◇ Device
{"body": {}, "nonce": 856543282, "get": {"action": "sys_reboot", "deliver_to_device": "true"}, "token":
Device get this “sys_reboot”, it will restart and run the new firmware.
5. Software APIs
5.1. struct upgrade_server_info
struct upgrade_server_info{
uint8 *url;
upgrade_states_check_callback check_cb;
};
1. system_upgrade_userbin_check
If running user1.bin right now, we will download user2.bin from server to update.
If running user2.bin right now, we will download user1.bin from server to update.
2. system_upgrade_start
3. system_upgrade_reboot
If download user bin succeed, call api to restart and run new firmware.
Return: none
4. system_upgrade_flag_set
Note: If you using system_upgrade_start to upgrade, this API need not be called.
new firmware.
Return: none
6. user_esp_platform_upgrade_begin
Return: none
7. user_esp_platform_upgrade_rsp
Return: none
Note:
Users can build their own server, call APIs listed here and download firmware according to HTTP, refer
to IOT_Demo.
6. Appendix
When you upload device SDK firmware (user bin) to Espressif Cloud, you have to name it according to
the rule, or it will be an illegal name and upgrade fail.
Example: v1.0.2t45772(a)
1. Software Type: v or b
v: means official version
Note: The same version number cannot have both official version and beta version. For example, there
can’t be both v1.0.2 and b1.0.2.
2. Version Number:NUM1.NUM2.NUM3
Num: Range from 0 to 999
Example: 1.0.2
3. Tag:t
t: Type Tag, followed by device’s product type number (PTYPE)
4. Device Type:PTYPE
PTYPE: ptype (product type) number, get from Espressif Cloud, as follow
Enter http://iot.espressif.cn/#/api/#api-product-create
Example:
Get ptype number of device “Light” being 45772 on Espressif Cloud, and device “Switch” is 23701. So
SDK v1.0.2t45772(a) is an official software of device “Light” of version 1.0.2, it supports both online
and local upgrade; value of version number is 1*1000*1000+0*1000+2 = 1000002
SDK b1.0.3t23701(l) is a beta software of device “Switch” of version 1.0.2, it supports only local
upgrade; value of version number is 1*1000*1000+0*1000+3 = 1000003
(2) Same ptype, same version value, can only have one non-upgrade type version (n)
(3) Same ptype with version (n), cannot have more than one upgrade type version (o,l,a)