Z-Stack OTA Upgrade User's Guide
Z-Stack OTA Upgrade User's Guide
OTA Upgrade
User’s Guide
TABLE OF CONTENTS
1. INTRODUCTION ..............................................................................................................................................1
1.1 HOW TO READ THIS DOCUMENT ...................................................................................................................1
1.2 DEFINITIONS, ABBREVIATIONS, ACRONYMS .................................................................................................1
1.3 REFERENCES .................................................................................................................................................1
2. OTA OVERVIEW .............................................................................................................................................1
2.1 OTA THEORY OF OPERATION .......................................................................................................................2
2.2 OTASERVER PC TOOL ..................................................................................................................................3
2.3 OTA IMAGE CONVERTER .............................................................................................................................3
2.4 Z-STACK IMPLEMENTATION OF THE OTA UPGRADE CLUSTER .....................................................................5
3. USING THE SAMPLE OTA APPLICATIONS ........................................................................................... 11
3.1 REQUIRED MATERIALS ............................................................................................................................... 11
3.2 BUILDING AND DOWNLOADING TARGET APPLICATIONS ............................................................................ 11
3.3 PERFORMING AN IMAGE UPDATE ................................................................................................................ 33
4. ADDING CLIENT FUNCTIONALITY TO AN APPLICATION .............................................................. 37
4.1 ADDING OTA CLIENT SOURCE CODE ......................................................................................................... 37
4.2 ADD THE OTA LINKER CONFIGURATION FILE ............................................................................................ 37
4.3 ADD OTA\SOURCE TO THE INCLUDES DIRECTORIES .................................................................................. 38
4.4 ADDING CONDITIONAL COMPILE TIME CONFIGURATION ........................................................................... 38
4.5 ADD OSAL INITIALIZE AND TASK FUNCTIONS FOR THE OTA TASK .......................................................... 38
5. CREATING A COMBINED HEX FILE ....................................................................................................... 39
5.1 CC2530 ...................................................................................................................................................... 39
5.2 CC2538 ...................................................................................................................................................... 43
1. Introduction
This document is a Developer’s Guide for the Over the Air (OTA), Upgrade Cluster in Texas Instruments’ Z-Stack
ZigBee platform.
Term Definition
The IEEE 802.15.4 protocol specifies the physical and medium access layers for
IEEE 802.15.4
wireless Personal Area Networks targeted at low power, low data rate applications.
OTA Over the Air
A device capable of down loading an image using the OTA cluster from an OTA
OTA Client
Server.
A device capable of hosting an image for download via the OTA cluster by an OTA
OTA Server
Client.
PAN Personal Area Network
SoC System on Chip – processor core and radio are integrated on same device
1.3 References
[1] ZigBee Alliance Document 095264, ZigBee OTA Upgrade Cluster Specification.
2. OTA Overview
The OTA, Over the Air, Upgrade Cluster provides a standard mechanism for wirelessly upgrading a ZigBee
device’s firmware. Over the air upgrade sessions take place between a client and server. The OTA Client
downloads an OTA Upgrade Image. The OTA Server hosts OTA Upgrade Images.
Texas Instruments’ Z-Stack ZCL, ZigBee Cluster Library, provides support for client and server operation of the
OTA Upgrade Cluster. The Texas Instruments Z-Stack implementation of the OTA Upgrade Cluster consists of the
following components:
OtaServer PC Application
OTA Image Converter Application
ZCL Implementation of the OTA Protocol
Boot loaders for the supported platforms
Sample OTA Application
Communication via the OTA Upgrade Cluster takes place using the following command messages shown in the
simple message chart below:
The Image Notify message is sent unicast or is broadcast by an OTA Server to notify OTA Clients that new images
are available. The Image Notify does not contain information about the new images. The Image Notify only
indicates new images are available. OTA Clients determine if these new images apply to them using the Query Next
Image request and response messages.
Periodically, or after receipt of an Image Notify message, an OTA Client sends a Query Next Image Request
message to an OTA Server. The Query Next Image Request message contains the version of the firmware currently
running on the client. On receipt of the Query Next Image Request, the server decides if an image update should
take place and which image the client should update to. The server responds to the query next image request with a
Query Next Image Response message.
The Query Next Image Response message may instruct the client to download new firmware, or it may inform the
client that no firmware is available. Should a download take place, the client controls the download. During the
download, the client sends Image Block Request messages to the server and receives Image Block Response
messages from the server with chunks of the upgrade image. The client writes the received image blocks to a
secondary storage location. In the Z-Stack sample applications, this secondary storage can be on-chip or off-chip
flash memory, depending on the hardware platform.
After the client has downloaded the entire upgrade image, the client sends the Upgrade End Request message to the
server. The server then responds with an Upgrade End Response message. The Upgrade End Response message
contains information about when the client should switch to the new firmware. The client may switch to the new
firmware immediately or it may be instructed to wait a specified period of time.
In the Z-Stack sample applications, when it is time for a client to switch to the new image, the client writes a non-
volatile, NV, memory location indicating new firmware is available. Then the client reboots. A boot loader on the
client sees that the new image is available. Then the boot loader copies the new image from secondary storage to
the operational memory space. Then the new firmware is started. On some platforms, such as the Cortex-M3 based
CC2538, only a boot manager is required since the OTA images can be run in-place.
It’s worth noting that the OTA cluster support is instantiated on an end point separate from the sample application.
This can be observed in the declaration of the simple descriptor zclOTA_SimpleDesc and end point
zclOTA_Ep global variables in zcl_ota.c. In this implementation, the OTA end point = ZCL_OTA_ENDPOINT
(0xE).
OTA_INITIAL_IMAGE: Used for CC2538. For specifics associated with a combined image that includes
both the OTA bootloader and the ZigBee application with OTA client capabilities. See section 3.2.2 for
more information.
HAL_IMG_AREA=0 : Used for CC2538. Specifies IMAGE A properties.
HAL_IMG_AREA=1 : Used for CC2538. Specifies IMAGE B properties.
typedef struct
{
osal_event_hdr_t hdr;
uint8 ota_event;
} zclOTA_CallbackMsg_t;
The ZCL_OTA_START_CALLBACK is sent to indicate a successful or failed attempt to start a download. The
ZCL_OTA_DL_COMPLETE_CALLBACK is sent when a download completes indicating the download completed
successfully or failed to complete.
2.4.6.2 zclOTA_RequestNextUpdate
The zclOTA_RequestNextUpdate function is called by applications to send an OTA Query Next Image message to
an OTA Server.
The method of discovering servers and determining when to query the server is left up to the application. In the Z-
Stack sample applications, the application performs a match descriptor request on the OTA Upgrade Cluster to
discover a Server. The application then calls zclOTA_RequestNextUpdate on all discovered servers until the
application receives a successful ZCL_OTA_START_CALLBACK event.
2.4.6.3 zclOTA_SendImageNotify
The zclOTA_SendImageNotify function can be called on an OTA Server to send an Image Notify message.
2.4.6.4 zclOTA_PermitOta
The zclOTA_PermitOta function can be called to enable or disable OTA Upgrades. When OTA is disabled, the
OTA Client ignores Image Notify messages and the OTA Server sends no image available responses to Query Next
Image Request messages.
0x00200000
0x002001EB
0x002001EC CRC
0x002001F3
0x002001F4 Preamble
0x002001FF
0x00200200
INTVEC
0x002003FF
FLASH
253459
Bytes
Run Code
0x0023DFFF
Flash /
Run Code
505856 Bytes
0x0023E1EC CRC
0x0023E1F3
0x0023E1F4 Preamble
0x0023E1FF
0x0023E200
INTVEC
0x0023E3FF
0x002003FF
FLASH
253459
Bytes
Run Code
0x0027B800
247
0x0027BFFF
0x0027C000
248 LEDGER
0x0027C7FF
0x0027C800
6 pages NV MEM
(249-254)
0x0027F7FF
Lock Bits 0x0027F800
Page 255 Boot Manager INTVEC
0x0027F8FF
0x0027F900
(0x0027f900 - 0x0027fba0)
0x0027FED4
Suite 2 Implicit Certificate
0x0027FF1F
0x0027FF20
Suite 2 Certificate Authority Public Key
0x0027FF47
0x0027FF48
Suite 2 Device Private Key
0x0027FF6B
0x0027FF6C
Implicit Certificate
0x0027FF9B
0x0027FF9C
Certificate Authority Public Key
0x0027FFB3
0x0027FFB4
Device Private Key
0x0027FFCB
0x0027FFCC
IEEE address
0x0027FFD3
0x0027FFD4
FLASH_CCA Reserved
0x0027FFD6
0x0027FFD7 Bootloader Backdoor
0x0027FFD8
Image Valid
0x0027FFDB
0x0027FFDC
Application Entry Point
0x0027FFDF
0x0027FFE0
Lock Bits
0x0027FFFF
CC2538 Memory Map
Note that the Image Boot Manager (OTA boot loader), for CC2538, resides in the Lock Bits page. Also note the
special “Ledger” page. This is used by the Boot Manager to maintain a record of the latest downloaded image and
to determine which image in flash to execute at boot time. A ledger entry consists of two CRCs values for a
particular image (shadow and actual) and a pointer to the top of the image’s Interrupt Vector Table (INTVEC)
which contains, among other things, an initial stack pointer and the list of interrupt handlers including the reset
handler for that image.
Although the default settings are to evenly divide, in half, the flash not used by the NV and the Ledger, this is not
mandator. The Image-A and Image-B code areas can be re-sized as desired by changing the definitions in the board-
specific hal_board_cfg.h file as well as making corresponding changes to the two image linker control files):
Components\hal\target\CC2538\hal_board_cfg.h
Projects\zstack\Tools\CC2538DB\ CC2538-OTA-Image-A.icf
Projects\zstack\Tools\CC2538DB\ CC2538-OTA-Image-B.icf
To program the OTA Image Boot Manager, a combined binary image must be built that integrates the OTA Image
Boot Manager, the OTA Client Application (eg. Z-Stack Home SampleSwitch or Z-Stack Energy SampleApp) and
the optional certificates in the case of an SE OTA Client Application. This process is described in more detail in
section 3.2.2 .
In the case of the Cortex-M3 targets, the boot manager simply looks in the ledger page for the run-in-place image to
run.
Neither boot application can be upgraded wirelessly.
c. Click the Debugger category. Verify the Driver is set to Texas Instruments:
d. Click the Texas Instruments category. Verify the flash WILL be erased, and the download will be
verified:
The second type of image we need to build is either an “A” or “B” version of our OTA client-enabled sample
application. This image A or B will be built with a specific linker control file designed to place the image in either
the upper (A) or lower (B) half of the flash memory as depicted in the memory diagram above. These images are
specifically intended to be transferred via OTA
4) Go to Step 2
4) Go to Step 2
Step 2: Configure the linker options to incorporate the Boot Image Manger built above.
1) Click Project>Options from the menu.
2) Click on Linker Compiler category
3) Select the “Input” tab and verify the following:
a) In the “Keep symbols” panel the following symbol should be defined:
bootloader
b) In the “Raw binary image” section, verify the following:
File: $PROJ_DIR$\..\..\..\OTA\Boot\CC2538\Image Boot
Manager\Exe\Boot.bin
Symbol: bootloader
Section: .bootloader
Align: 4
4) Select the “Config” tab and verify the following in the Linker configuration file section:
a) The Override default check box should be checked.
b) The specified linker configuration file should be:
$PROJ_DIR$\..\..\..\Tools\CC2538DB\CC2538-OTA-Image-A.icf
Your platform is now programmed with an initial Image A including the Boot Image Manager and optional
certificate data.
5) Verify the project’s post-build action is set properly to post process the binary file to convert/prepare it for
OTA transfer.
a. Click Project>Options from the menu.
"$PROJ_DIR$\..\..\..\..\tools\OTA\OtaConverter\Release\OtaConverter.exe"
"$PROJ_DIR$\EndDevice - OTAClient - ImageB\Exe\EndDevice-OTAClient-
ImageB.bin" -o"$PROJ_DIR$\EndDevice - OTAClient - ImageB\Exe" -t0x2538 -
m0xBEBE -vBBBB0000 -pCC2538
Note: The values specified for the “-m” and “-v” options are just examples.
Projects\zstack\HomeAutomation\SampleSwitch\CC2538\EndDeviceSrc
- OTAClient - ImageB\Exe\BEBE-2538-BBBB0000.zigbee
OTA_CLIENT=TRUE
HAL_IMG_AREA=1
Important: HAL_IMG_AREA=1 refers to Image B.
Very Important: Ensure that OTA_INITIAL_IMAGE is NOT defined.
5) Verify the project’s post-build action is set properly to post process the binary file to convert/prepare it for
OTA transfer.
a. Click Project>Options from the menu.
b. Click on Build Actions category
c. Verify that the following in the Post-build command line:
"$PROJ_DIR$\..\..\..\..\tools\OTA\OtaConverter\Release\OtaConverter.exe"
"$PROJ_DIR$\In Premise Display - End Device - OTAClient -
ImageB\Exe\SampleApp.bin" -o"$PROJ_DIR$\In Premise Display - End Device -
OTAClient - ImageB\Exe" -t0x2538 -m0xBEBE -pCC2538 -vBBBB0000 -
s"$PROJ_DIR$\..\Source\OTA Cert\cert.txt"
Note: The values specified for the “-m” and “-v” options are just examples.
Note: For the conversion of an SE OTA image, the converted file is signed. The example certificate
data, used by the conversion tool to include a signature with the converted file, is specified by
the “-s” option.
These settings are available as pre-sets in the corresponding build configuration ending in “… OTAClient –
ImageA” for both the HA SampleSwitch workspace and the SE SampleApp workspace.
4) From here on, follow instructions starting from 4) of the In Premise Display – OTA SE SampleApp
instructions below.
e. Click the Debugger category. For the CC2530DB platform, verify the Driver is set to Texas
Instruments:
f. For the CC2530DB platform, click the Texas Instruments category. Make sure that the “Erase
flash” box is unchecked and download will be verified:
Note: By selecting the “Retain Unchanged pages” setting, the OTA Boot application download
only used the first page of memory on the CC2530. This page was not used by the IPD – OTA
Client application. Subsequently both the IPD – OTA Client and OTA Boot are present on the
Client device.
g. For the EXP5438 platform, verify the Driver is set to FET Debugger:
h. Verify the project’s post-build action is set properly to post process the binary file to
convert/prepare it for OTA transfer.
i. Click Project>Options from the menu.
ii. Click on Build Actions category
iii. Verify that the following in the Post-build command line:
"$PROJ_DIR$\..\..\..\..\tools\OTA\OtaConverter\Release\OtaConverter.e
xe" "$PROJ_DIR$\EndDeviceEB - OTAClient\Exe\EndDeviceEB-
OTAClient.sim" -o"$PROJ_DIR$\EndDeviceEB - OTAClient\Exe" -t0x1234 -
m0x5678 -v0000ABCD -pCC2530DB
"$PROJ_DIR$\..\..\..\..\tools\OTA\OtaConverter\Release\OtaConv
erter.exe" "$PROJ_DIR$\EndDevice - OTAClient\Exe\EndDevice-
OTAClient.sim" -o"$PROJ_DIR$\EndDevice - OTAClient\Exe" -
t0x1234 -m0x5678 -pEXP5438
"$PROJ_DIR$\..\..\..\..\tools\OTA\OtaConverter\Release\OtaConverter.e
xe" "$PROJ_DIR$\In Premise Display - End Device -
OTA\Exe\SampleApp.sim" -o"$PROJ_DIR$\In Premise Display - End Device
"$PROJ_DIR$\..\..\..\..\tools\OTA\OtaConverter\Release\OtaConverter.e
xe" "$PROJ_DIR$\In Premise Display - End Device -
OTA\Exe\SampleApp.sim" -o"$PROJ_DIR$\In Premise Display - End Device
- OTA\Exe" -t0x1234 -m0x5678 -v0xabcd1234 -pEXP5438 -
s"$PROJ_DIR$\..\Source\OTA Cert\cert.txt"
Note: The values specified for the “-m” and “-v” options are just examples.
Note: For the conversion of an SE OTA image, the converted file is signed. The example
certificate data, used by the conversion tool to include a signature with the converted file, is
specified by the “-s” option.
3.2.4 Dongle
The dongle runs OTA Dongle, application. The OTA Dongle application is located in:
\ Projects\zstack\OTA\Dongle\<platform>\
To build and download the OTA Dongle application:
1) Open OTA_Dongle.eww with IAR Embedded Workbench
2) Verify the project’s definitions are configured properly for the profile being used.
c. Click Project>Options from the menu.
d. Click on C/C++ Compiler category
e. For HA profile verify that the following symbols are defined:
OTA_HA
f. For SE profile verify that the following symbols are NOT defined
OTA_HA
b. For the CC2530DB platform, verify the Driver is set to Texas Instruments:
c. For the EXP5430 platform, verify the Driver is set to FET Debugger:
3. The File List display area will now show the available image(s) for the updating of OTA devices.
Expanding the plus sign on each image provides extra information about the image. It is not possible to
select image files in the File List display area.
4. Check and modify the Port Settings as necessary. Pressing the Open button will open the port and
OtaServer will begin monitoring the OtaDongle. If OtaServer does not see a proper regular message from
OtaDongle, it will automatically close the port and report the issue to the user.
The default baud rate for OtaServer and the OTA server application (Dongle) is 38400 8-N-1.
NOTE: For a CC2538 hosted OTA Server (Dongle), you will need to disable flow control.
5. Optionally disable Image Version Checking in the OTA Server.
Options -> Uncheck “Version Check Image File”
This can be used to allow more flexible image selection including download older revision files.
3. If that is not the desired PAN ID or you wish to see all the PAN IDs available: Right click on the “In
Network” PAN ID, and then select "Leave PAN". It may take up to a minute for the device to reset and
scan for PANs. Right click on one of the displayed PAN IDs and select "Join PAN". When the PAN ID
shows “In Network” you are ready to proceed to the next step.
4. Right click on the “In Network” PAN ID and select Device Scan.
5. As nodes respond to the request they will appear in the device list. Note that only OtaClient coordinators
and routers will respond. OtaClients that are end devices will only appear as they join the network.
If your OtaDongle is a coordinator, follow these steps:
1. The Device List will update within 5 seconds with your coordinators PAN ID.
2. Any nodes that have already joined the pan will not be displayed. Any nodes that join after OtaServer
displays the PAN ID will be displayed. The easiest thing to get all the nodes displayed is to right click on
the PAN ID that is “In Network”. Selecting “Leave PAN” causes the OtaDongle to reset. It may take a
number of minutes for all the nodes to rejoin..
3. As each node joins OtaServer will automatically read the attributes of each node. Press the plus next to the
node name to see the information.
OtaServer <-p Port Name> <-s Port Settings> [<-ch Channel Number>] [<-pa PAN ID>] <-de Device Id> <-e
Endpoint> <-f Ota Image File> <-d Ota Image Directory> [<-l Log File>] [<-NoVersionCheck>] [<-help>]
Example:
OtaServer -p "COM1" -s "38400,CTS/RTS,None,One,8" -ch 0x0B -pa 0xFFFF -de 0xFFFF -e 0xff -f "c:\my ota
files\ota image.zigbee" -l "logfilename” -NoVersionCheck
Options:
<-p Port Name> Required. The Communications Port Name As Displayed In The OtaServer GUI
Example: -p "COM1"
<-s Port Settings> Required. The Communications Port Settings As Displayed In The OtaServer GUI Field
Breakdown: "baudrate,flowofcontrol,parity,stopbits,databits"
Example: -s "38400,CTS/RTS,None,One,8"
[<-ch Channel Number>] Optional Only If OtaServer Is A Coordinator. The Channel Number
Example: -ch 0x0B
<-f Ota Image File> Required If No Image Directory Is Provided. The Image File Name With Full Path
Information
Example: -f “c:\my ota files\ota image.zigbee”
[<-l Log File>] Optional. The Log File Name With Full Path Information And Without A File Extension
Example: -l "C:\my ota files\logfilename
[<-NoVersionCheck>] Optional And Cannot Be Used With An Image Directory. Supresses Image File
Version Number Checking
Example: -NoVersionCheck
Returns:
0 = success & 1 = failure
After the download completes, the Client device will copy the new firmware to the operational program space. This
may take several minutes. Then the new firmware will start running.
$PROJ_DIR$\..\..\..\Tools\CC2530DB\ota.xcl
$PROJ_DIR$\..\..\..\Tools\MSP5438\ota.xcl
$PROJ_DIR$\..\..\..\Tools\CC2538DB\CC2538-OTA-Image-A.icf
Or
$PROJ_DIR$\..\..\..\Tools\CC2538DB\CC2538-OTA-Image-B.icf
4.5 Add OSAL Initialize and Task Functions for the OTA Task
1) Open the project workspace in IAR Embedded Workbench
2) Add zclOTA_event_loop to the tasksArr array:
a. Press CTRL-SHIFT-F.
b. Enter tasksArr as the search term.
c. In the Find in Files dialog, double click on the line containing the definition for tasksArr.
d. Add zclOTA_event_loop to the bottom of the list.
3) Add zclOTA_Init to the osalInitTasks
a. osalInitTasks should be a few lines below the taskArr.
b. Add: zclOTA_Init ( taskID++ ); to the end of the osalInitTask function.
5.1 CC2530
The following instructions detail the steps to create and combine OTA Boot and Client application hex images for
the CC2530. The basic process will involve creating hex images for each and then, with some very minor edits, the
two images can be concatenated with a simple text editor.
5.1.1 Create Hex File Output for OTA Boot Application
We’ll basically repeat the steps outlined in section 3.2.1.1 with the following changes:
1) Generate extra output from the linker.
With the boot.eww workspace open in IAR:
a) Click Project>Options from the menu.
b) Click the Linker category.
c) Select the “Output” tab and check the “Allow C-SPY-specific extra output file” check box:
2) Click Project>Rebuild All from the menu to rebuild the project and generate the new hex file for the OTA Boot
application.
After:
3) Click Project>Rebuild All from the menu to rebuild the project and generate the new hex file.
5.2 CC2538
The CC2538 Home Automation Sample Switch IAR workspace contains two build configurations that produce a
combined (OTA Boot and OTA Client applications) image. These are:
Router – OTA Client – Image A – withBootloader
EndDevice – OTA Client – Image A – withBootloader
To produce a combined .hex image, suitable for the programming with the SmartRF Flash Programmer 2 tool, we
need to make a very minor change to the build configuration in IAR:
1) Enable extra output from the linker.
With the SampleSwitch.eww workspace open in IAR and one of the above build configurations selected:
a) Click Project>Options from the menu.
b) Click the Output Converter category.
c) On the Output tab, check the “Generate additional output” check box.
d) Select “Intel extended” for the Output format.
e) Check the “Override default” check box for the Output file and enter any name you prefer: e.g.
“SampleSwitch_Combined.hex”
2) Click Project>Rebuild All from the menu to rebuild the project and generate the new hex file. NOTE: the new
hex file will be located here: Projects\zstack\HomeAutomation\SampleSwitch\CC2538\<selected build
configuration>\Exe