Using the Gecko Standalone Bootloaders#
A Gecko Bootloader-based standalone bootloader receives an application image onto a target device by serial transfer via SPI or UART. If using UART, you can establish a serial connection between a source device and a target device’s serial interface and upload a new software image to it using the XModem protocol. If you need information on the XModem protocol, a good place to start is http://en.wikipedia.org/wiki/XMODEM, which should have a brief description and up-to-date links to protocol documentation.
Performing a Serial Upload – UART XMODEM Bootloader#
Serial upload can be performed with any source device that provides the expected serial interface method. This can be a Windows-based PC, a Linux or Mac OS-based device, or an embedded MCU with no operating system. UART transfer can be done with a third-party serial terminal program like TeraTerm on Windows or Linux minicom or with user-compiled host code. However, drivers for SPI Master or UART may vary with operating systems, and serial terminal programs may vary in timing and performance, so if you are unsure about what driver or program to use on your source code, please consult Silicon Labs technical support.
To open a serial connection over UART, the source device connects to the target device at 115,200 baud, 8 data bits, no parity bit, and 1 stop bit (8-N-1), with no flow control by default. These options may be changed using the component options in the Bootloader project.
Note: The UART-based serial bootloader configurations do not employ any flow control in the communication channel by default, because the XModem protocol used for image transfer already has built-in flow control mechanisms. However, Silicon Labs’ normally-supplied NCP firmware does utilize either hardware-based (RTS/CTS) or software-based (XON/XOFF) flow control, so a host device must take care to temporarily disable the flow control when placing its NCP into serial bootloading mode. Alternatively, application designers can change the options in the provided bootloader project and customize the serial bootloader’s handling of the UART to add hardware flow control at their discretion.
Once the connection with a UART-based serial bootloader is established:
The target device’s bootloader sends output over its serial port after it receives a carriage return from the source device at the expected baud rate. This prevents the bootloader from prematurely sending commands that might be misinterpreted by other devices that are connected to the serial port. Note that serial bootloaders typically don’t enforce any timeout when awaiting the initial serial handshake via carriage return, so the bootloader will wait indefinitely in this mode until guided by the source device or until the chip is reset.
After the bootloader receives a carriage return from the target device, it displays a menu with the following ASCII-based output, (where X.Y.A corresponds to the major, minor, and sub-minor fields of the bootloader version number, respectively):
Gecko Bootloader vX.Y.A
1. upload gbl
2. run
3. ebl info
BL >
Note:The third menu option has no effect. While current menu options should remain functionally unchanged, the menu title and options text is liable to change, and new options might be added.
After listing the menu options, the bootloader's “BL >” prompt displays, and the ASCII character corresponding to the number of each option can then be entered by the source to select the described action, such as ‘2’ (ASCII code 0x32) to run the firmware presently loaded in the application area. Here again, no timeout is enforced by the bootloader, so it will wait indefinitely until a character is received or the chip is reset. Note that while the menu interface is designed for human interaction, the transfer can still be performed programmatically or through a scripted interface, provided the source device sends the expected ASCII characters to the target at appropriate times.
Note: Scripts that interact with the bootloader should use only the “BL >” prompt to determine when the bootloader is ready for input.
Selecting menu option 1 initiates upload of a new software image to the target device, which unfolds as follows:
The target device awaits an XModem CRC upload of a GBL file over the expected serial interface, as indicated by the stream of C characters that its bootloader transmits.
If no transaction is initiated within 60 seconds, the bootloader times out and returns to the menu.
Once uploading begins (first XModem SOH data packet received), the bootloader expects each successive XModem SOH packet within 1 second, or else a timeout error will be generated and the session will abort.
After an image successfully uploads, the XModem transaction completes and the bootloader displays ‘Serial upload complete’ before redisplaying the menu.
Errors and Status Codes#
If an error occurs during the upload, the UART serial bootloader displays the message ‘Serial upload aborted,’ followed by a more detailed message and a hex error code. Some of the more common errors are shown in the following table. The UART serial bootloader then redisplays the bootloader menu.
The following tables describe the normal status codes, error conditions, and special characters or enumerations used by the Gecko Bootloader. For additional status codes, see the Gecko Bootloader API documentation installed with your SDK in the platform/bootloader/documentation folder.
Serial Uploading Statuses and Error Messages
Hex code | Constant | Description |
---|---|---|
0x00 | BL_SUCCESS | Default success status. |
0x01 | BL_ERR | General error processing packet. |
0x1C | BLOCK_TIMEOUT | The bootloader timed out waiting for some part of the XModem frame. |
0x21 | BLOCKERR_SOH | The bootloader did not find the expected start of header (SOH) character at the beginning of the XModem frame. |
0x22 | BLOCKERR_CHK | The bootloader detected the sequence check byte of the XModem frame was not the inverse of the sequence byte. |
0x23 | BLOCKERR_CRCH | The bootloader encountered an error while comparing the high bytes of the received and calculated CRCx of the XModem frame. |
0x24 | BLOCKERR_CRCL | The bootloader encountered an error while comparing the low bytes of the received and calculated CRCs of the XModem frame. |
0x25 | BLOCKERR_SEQUENCE | The bootloader did not receive the expected sequence number in the current XModem frame. |
0x26 | BLOCKERR_PARTIAL | The frame that the bootloader was trying to parse was deemed incomplete (some bytes missing or lost). |
0x27 | BLOCKERR_DUPLICATE | The bootloader encountered a duplicate of the previous XModem frame. |
0x40 | BL_ERR_MASK | Bitmask for any bootloader error codes returned in CAN or NAK frame. |
0x41 | BL_ERR_HEADER_EXP | No GBL header was received when expected. |
0x42 | BL_ERR_HEADER_WRITE_CRC | Failed to write header or CRC. |
0x43 | BL_ERR_CRC | File or written image failed CRC check. |
0x44 | BL_ERR_UNKNOWN_TAG | Unknown tag detected in GBL image. |
0x45 | BL_ERR_SIG | Invalid GBL header contents. |
0x46 | BL_ERR_ODD_LEN | Trying to flash odd number of bytes. |
0x47 | BL_ERR_BLOCK_INDEX | Indexed past end of block buffer. |
0x48 | BL_ERR_OVWR_BL | Attempt to overwrite bootloader flash. |
0x49 | BL_ERR_OVWR_SIMEE | Attempt to overwrite SIMEE flash. |
0x4A | BL_ERR_ERASE_FAIL | Flash erase failed. |
0x4B | BL_ERR_WRITE_FAIL | Flash write failed. |
0x4C | BL_ERR_CRC_LEN | End tag CRC wrong length. |
0x4D | BL_ERR_NO_QUERY | Received data before query request/response. |
0x4E | BL_ERR_BAD_LEN | An invalid length was detected in the upgrade image file. |
0x4F | BL_ERR_TAGBUF | Insufficient tag buffer size or an invalid length was found in the GBL image. |
Special Characters Used in Packet Types
Hex code | Constant | Description |
---|---|---|
0x01 | SOH | Start of Header. |
0x03 | CTRL_C | Cancel (from sender). |
0x04 | EOT | End of Transmission. |
0x06 | ACK | Acknowledged. |
0x15 | NAK | Not acknowledged. |
0x18 | CAN | Cancel |
0x43 | C | ASCII ‘C’. |
0x51 | QUERY | ASCII ‘Q’. |
0x52 | QRESP | ASCII ‘R’. |
Status Codes Returned in a Synchronous Response
Hex code | Constant | Description |
---|---|---|
0x16 | TIMEOUT | Bootloader timed out expecting characters. |
0x17 | FILEDONE | EOT process successfully. |
0x18 | FILEABORT | Transfer aborted prematurely. |
0x19 | BLOCKOK | Data block processed OK. |
0x1A | QUERYFOUND | Successful query. |
Running the Application Image#
For standalone bootloader variants that utilize an interactive menu, bootloader menu option 2 (run) resets the target device into the uploaded application image. If no application image is present, or an error occurred during a previous upload, the bootloader returns to the menu. For SPI-based variants, which don’t use a menu, the application starts up immediately upon ACKing the EOT frame from the source device.
Performing a Bootloader Upgrade#
To perform a bootloader upgrade with the standalone bootloaders, simply transmit two GBL files in succession. The first GBL file should contain a main bootloader upgrade image. After upload is completed, the device resets to upgrade the main bootloader. For standalone bootloader variants that utilize an interactive menu, bootloader menu option 2 (run) resets the target device into the first stage bootloader to perform the upgrade, before returning to the upgraded main bootloader. The second GBL file, containing an application upgrade image, can then be uploaded.
Upload Recovery#
If an image upload fails, the target node is left without a valid application image. The standalone bootloader will re-enter firmware upgrade mode if it determines that the application image isn’t valid. However, the application image may have a valid structure, but contain a bug preventing normal operation. Regardless of the serial interface supported by your standalone bootloader, a GPIO-based trigger can be used to facilitate recovery via serial upload.
You can configure your standalone bootloader to use a software-based GPIO pin check or other schemes of recovery mode activation such as button recovery by configuring the GPIO Activation component.