Overview Hardware Preparations Hardware Settings Hardware Connection Download Procedure Transmission Protocol Packet Header Packet Body Firmware Image Format Appendix - Programming Examples Checksum Erase Flash References www.espressif.com ESP8266 Application Note Firmware Download Protocol Version 1.2 Espressif Systems Copyright © 2018 About This Guide This document introduces a downloading protocol for ESP8266 firmware. Release Notes Documentation Change Notification Espressif provides email notifications to keep customers updated on changes to technical documentation. Please subscribe at https://www.espressif.com/en/subscribe. Certification Download certificates for Espressif products from https://www.espressif.com/en/ certificates. Date Version Release notes 2016.05 V1.0 Initial release. 2017.06 V1.1 Added operation codes 09, 0a, 0b in Table 2-2. 2018.11 V1.2 • Updated Section A.3. References • Fixed format issues Table of Contents 1. Overview ................................................................................................................................1 1.1. Hardware Preparations! "..............................................................................................................1 1.1.1. Hardware Settings! "........................................................................................................1 1.1.2. Hardware Connection! "...................................................................................................1 1.2. Download Procedure! ".................................................................................................................2 2. Transmission Protocol ...........................................................................................................3 2.1. Packet Header! "...........................................................................................................................3 2.2. Packet Body! "...............................................................................................................................4 3. Firmware Image Format ........................................................................................................5 A. Appendix - Programming Examples .....................................................................................6 A.1. Checksum! "..................................................................................................................................6 A.2. Erase Flash! ".................................................................................................................................6 A.3. References!.................................................................................................................................7 1.Overview 1. Overview 1.1. Hardware Preparations When ESP8266 is in the UART downloading mode, users can download firmware from an external MCU to ESP8266. 1.1.1. Hardware Settings The hardware settings are shown in Table 1-1. 1.1.2. Hardware Connection The hardware connection is shown in Figure 1-1. Figure 1-1. Hardware Connection Table 1-1. Hardware Settings Item Settings UART download mode GPIO0 and GPIO15: pulled down GPIO2: pulled high Baud rate Auto-bauds Data bit 8 Stop bit 1 Parity bit None Flow control Disabled MCU ESP8266 Download Protocol Inner Download Protocol RXD TXD GND Espressif /81 2018.11 1.Overview 1.2. Download Procedure Figure 1-2. Download Procedure • Synchronization: transmit sync frame to synchronize the baud rate. • Erase data: erase the relevant flash sectors, according to the size and address of the firmware that will be downloaded into them. • Transmit data: encapsulate the firmware into multiple frames and transmit them to ESP8266. • Transmit finish frame: transmit the download-finish frame to ESP8266. Start Synchronization Success? Erase data Transmit data Finish? transmit finish frame Finish Yes Yes No (Timeout) No (Failure) Espressif /82 2018.11 2. Transmission Protocol 2. Transmission Protocol The transmission protocol uses the Serial Line Internet Protocol (SLIP) framing. • Each packet begins and ends with !"#!. • All occurrences of !"#! and !"$% inside the packet are replaced with !"$%&!"$# and !"$%&!"$, respectively. • Inside the frame, the packet consists of a header and a variable-length body, as shown in Figure 2-1. • All multi-byte fields are little-endian. Figure 2-1. Packet Format 2.1. Packet Header The format of the packet header is shown in Table 2-1. byte 0 1 2 3 4 5 6 7 8 9 A B C D E F 0h Header 1h Body ... Table 2-1. Packet Header Format Byte Data type Request Response 0 Type Always !"!!. Always !"!'. 1 Command Operation code. Please refer to Table 2-2 for details. 2~3 Data size The size of packet body. Note: The data size is the same as the length of the packet body before !"#! and !"$% are replaced. 4~7 Checksum/Response XOR checksum of payload (the firmware data stored after the 16th byte of the packet body). For the checksum algorithm, please refer to Appendix - Programming Examples. Response data. 8~n Body Depends on operation 8 Status - Status flag, success (0) or failure (1). 9 Error - Success (null) or failure (error code). Espressif /83 2018.11 2. Transmission Protocol 2.2. Packet Body The packet body format is shown in Figure 2-2. Figure 2-2. Packet Body Format The first 16 bytes (Word0 ~ Word3) are the description of the packet body, which is different when executing different commands. Table 2-2. Operation Code Codes Name Description 02 Flash Download Start Erase the data in the flash. • Word0: the number of flash sectors being erased. Each sector is 4096 bytes. • Word1: the number of packet(s) being transmitted. • Word2: packet size, e.g., !"(!!. • Word3: offset address. Note: For the sample codes of erasing data, please refer to Appendix - Programming Examples. 03 File Packet Send Transmit data. • Word0: the size of data being written (filled with !"(!!). • Word1: the sequence number of each transmitted packet. • Word2: !"! • Word3: !"! 04 Flash Download Stop Stop transmitting data. 08 Sync Frame Send )*+,-./0123456&7&8&!"!9:&!"!9:&!"';:&!";!:< !"==:&!"==:&!"==:&!"==:&!"==:&!"==:&!"==:&!"==:< !"==:&!"==:&!"==:&!"==:&!"==:&!"==:&!"==:&!"==:< !"==:&!"==:&!"==:&!"==:&!"==:&!"==:&!"==:&!"==:< !"==:&!"==:&!"==:&!"==:&!"==:&!"==:&!"==:& !"==&>? 09 Write register Four 32-bit words: address, value, mask and delay (in microseconds). 0a Read register Address as 32-bit word. 0b Configure SPI params 24 bytes of unidentified SPI parameters. 0 1 2 3 4 5 6 7 8 9 a b c d e f Word0 Word1 Word2 Word3 g…n Data Espressif /84 2018.11 3. Firmware Image Format 3. Firmware Image Format The firmware consists of a file header, and a number of data blocks (the size of blocks may be different), as shown in Figure 3-1. Multi-byte fields are little-endian. Figure 3-1. Firmware Image Format The format of the file header is shown in Table 3-1. Byte 0 1 2 3 4 5 6 7 8 9 A B C D E F 0h File Header 1h Data blocks ... Table 3-1. Firmware Format Description Byte Data type Description 0 Magic Code The value is always !@AB. 1 Block Number The number of blocks. 2 SPI Mode The SPI working mode. • !"!!: QIO mode • !"!': QOut mode • !"!;: DIO mode • !"!4: DOut mode 3 SPI Flash Info SPI flash size and frequency. • High 4 bits: !"! = 512 kB; !"' = 256 kB; !"; = 1 MB; !"4 = 2 MB; !"( = 4 MB • Low 4 bits: !"! = 40 MHz; !"' = 26 MHz; !"; = 20 MHz; !"C = 80 MHz 4~7 Entry Address CPU entry address. Espressif /85 2018.11 Appendix A A. Appendix - Programming Examples A.1. Checksum DE+F4;-F&2)G,H11-,0I,-,J2,K)D1LD+)EM+2N&,J0/&ON0F0:&DE+F'5-F&N0F0-)EP2Q< 8< &&&&DE+F'5-F&,+F?< &&&&DE+F4;-F&/2)DIF?< &&&&/2)DIF&7&!"AC?&< &&&&.H/L,+F&7&!?&,+F&R&N0F0-)EP2?&,+FSSQ< &&&&8< &&&&&&&&/2)DIF&T7&N0F03,+F6?< &&&&>< &&&&/2FD/+&/2)DIF?< >< A.2. Erase Flash UN2.E+2&&%VW#XYZ[A-CV\Y]&&!"(!!< UN2.E+2&&CV\Y]-$W^_VW\$-%A`Z_&&!"!;< DE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N-)2,FH/-,HD+F&7&LFHF0I-)2,FH/-,HD+F&h&;&O&J20N-)2,FH/-,HD+FQ&f< &&&LFHF0I-)2,FH/-,HD+F&g&J20N-)2,FH/-,HD+FQb< &&&LFHF0I-)2,FH/-,HD+F&S&'Q&a&;?< 2/0)2-)EP2&7&0NoD)F2N-)2,FH/-,HD+F&O&)2,FH/-)EP2?< .I0)J-G0,K2F3!6&7&2/0)2-)EP2?< .I0)J-G0,K2F3'6&7&L)EP2&S&%VW#XYZ[A-CV\Y]&g&'Q&a&%VW#XYZ[A-CV\Y]?< .I0)J-G0,K2F3;6&7&%VW#XYZ[A-CV\Y]?< .I0)J-G0,K2F346&7&0NN/2))?< 2)G,H11-)2+N-,H110+NLCV\Y]-$W^_VW\$-%A`Z_:&LD+)EM+2N&,J0/OQ&p.I0)J-G0,K2F:&'5Q?< >< A.3. References espressif/esptool: https://github.com/espressif/esptool Espressif /7 8 2018.11 Disclaimer and Copyright Notice Information in this document, including URL references, is subject to change without notice. THIS DOCUMENT IS PROVIDED AS IS WITH NO WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY, NON-INFRINGEMENT, FITNESS FOR ANY PARTICULAR PURPOSE, OR ANY WARRANTY OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. All liability, including liability for infringement of any proprietary rights, relating to use of information in this document is disclaimed. No licenses express or implied, by estoppel or otherwise, to any intellectual property rights are granted herein. The Wi-Fi Alliance Member logo is a trademark of the Wi-Fi Alliance. The Bluetooth logo is a registered trademark of Bluetooth SIG. All trade names, trademarks and registered trademarks mentioned in this document are property of their respective owners, and are hereby acknowledged. Copyright © 2018 Espressif Inc. All rights reserved. Espressif IoT Team" www.espressif.com