Rajeev Piyare
Published © GPL3+

ContikiNG over-the-air download for offchip (TI CC1310)

Over-the-air (OTA) firmware updates are a vital component of any IoT system.

IntermediateFull instructions provided-60 minutes617
ContikiNG over-the-air download for offchip (TI CC1310)

Things used in this project

Hardware components

LAUNCHXL-CC1310 SimpleLink CC1310 Sub-1GHz LaunchPad
Texas Instruments LAUNCHXL-CC1310 SimpleLink CC1310 Sub-1GHz LaunchPad
×2

Software apps and online services

ContikiNG

Story

Read more

Code

Code snippet #24

Writing to:
CC1310LP_oad-v2.bin
******************************************************************************************
Success
******************************************************************************************

The script has calculated the 16 Byte OAD Metadata vector below

Bytes: | 0 - 2  |  2 - 4   | 4 - 6  | 6 - 8  |  8-12    | 12 - 14 |   15    |  16  |
Desc : |  CRC   | CRC-SHDW | imgVer | imgLen |  usrId   | imgAddr | imgType | stat |
------------------------------------------------------------------------------------
Data : | 0xB2A3 |  0xFFFF  | 0x0200 | 0x3068 |  EEEE    | 0x0400  |  0x01   | 0xFF |
******************************************************************************************

Code snippet #5

Plain text
/*******************************************************************************
 * @fn     Bim_checkImages
 *
 * @brief  Check for new, valid images in external flash to copy into internal
 *         flash.
 *
 * @param  none
 *
 * @return none
 */
void Bim_checkImages(void)
{
  uint32_t metaDataAddr;

  // Initialize external flash driver.
  if (BLS_init() == -1)
  {
      return;
  }

  for (metaDataAddr = EFL_IMAGE_INFO_ADDR_APP;
       metaDataAddr <= EFL_IMAGE_INFO_ADDR_BLE; metaDataAddr += EFL_PAGE_SIZE)
  {
    // Check for the meta information on the image to see if a download is
    // required.
    Bim_extReadBuf(metaDataAddr, (uint32_t *)&imgInfo, sizeof(ExtImageInfo_t));

    // Check if we have a valid image in external flash.
    if (imgInfo.crc[0] != 0xFFFF && imgInfo.crc[0] != 0x0000 &&
        imgInfo.crc[0] == imgInfo.crc[1] && imgInfo.status == 0xFF)
    {
      while(1)
      {
        uint32_t startAddr;
        uint8_t startPage;

        // Find the image address in external flash.
        if (imgInfo.imgType == EFL_OAD_IMG_TYPE_APP)
        {
          startAddr = EFL_ADDR_IMAGE_APP;
        }
        else if (imgInfo.imgType == EFL_OAD_IMG_TYPE_STACK)
        {
          startAddr = EFL_ADDR_IMAGE_BLE;
        }
        else
        {
          // This is neither Application nor Stack image. Check the next one.
          break;
        }

        // Copy over the image. Note that failure cannot be handled.
        Bim_copyImage(startAddr, (uint32_t)imgInfo.len * EFL_OAD_ADDR_RESOLUTION,
                             (uint32_t)imgInfo.addr * EFL_OAD_ADDR_RESOLUTION);

        startPage = ((uint32_t)imgInfo.addr * EFL_OAD_ADDR_RESOLUTION) /
		            HAL_FLASH_PAGE_SIZE;

        // Check if the CRC of the internal image is valid.
        if (crcCheck(startPage, BIM_IMG_E_OSET, imgInfo.crc))
        {
          // Overwrite the status field of the meta data to reflect the contents of
          // internal flash.
          imgInfo.status = 0x80;

          Bim_extWriteBuf(metaDataAddr, (uint32_t *)&imgInfo,
                          sizeof(ExtImageInfo_t));

          break;
        }
      }
    }
  }

  // Close external flash driver.
  BLS_close();
}

Code snippet #6

/*******************************************************************************
 * @fn     Bim_checkImages
 *
 * @brief  Check for new, valid images in external flash to copy into internal
 *         flash.
 *
 * @param  none
 *
 * @return none
 */
void Bim_checkImages(void)
{
  uint32_t metaDataAddr;

  // Initialize external flash driver.
  if (BLS_init() == -1)
  {
      return;
  }

  for (metaDataAddr = EFL_IMAGE_INFO_ADDR_APP;
       metaDataAddr <= EFL_IMAGE_INFO_ADDR_BLE; metaDataAddr += EFL_PAGE_SIZE)
  {
    // Check for the meta information on the image to see if a download is
    // required.
    Bim_extReadBuf(metaDataAddr, (uint32_t *)&imgInfo, sizeof(ExtImageInfo_t));

    // Check if we have a valid image in external flash.
    if (imgInfo.crc[0] != 0xFFFF && imgInfo.crc[0] != 0x0000 &&
        imgInfo.crc[0] == imgInfo.crc[1] && imgInfo.status == 0xFF)
    {
      while(1)
      {
        uint32_t startAddr;
        uint8_t startPage;

        // Find the image address in external flash.
        if (imgInfo.imgType == EFL_OAD_IMG_TYPE_APP)
        {
          startAddr = EFL_ADDR_IMAGE_APP;
        }
        else if (imgInfo.imgType == EFL_OAD_IMG_TYPE_STACK)
        {
          startAddr = EFL_ADDR_IMAGE_BLE;
        }
        else
        {
          // This is neither Application nor Stack image. Check the next one.
          break;
        }

        // Copy over the image. Note that failure cannot be handled.
        Bim_copyImage(startAddr, (uint32_t)imgInfo.len * EFL_OAD_ADDR_RESOLUTION,
                             (uint32_t)imgInfo.addr * EFL_OAD_ADDR_RESOLUTION);

        startPage = ((uint32_t)imgInfo.addr * EFL_OAD_ADDR_RESOLUTION) /
		            HAL_FLASH_PAGE_SIZE;

        // Check if the CRC of the internal image is valid.
        if (crcCheck(startPage, BIM_IMG_E_OSET, imgInfo.crc))
        {
          // Overwrite the status field of the meta data to reflect the contents of
          // internal flash.
          imgInfo.status = 0x80;

          Bim_extWriteBuf(metaDataAddr, (uint32_t *)&imgInfo,
                          sizeof(ExtImageInfo_t));

          break;
        }
      }
    }
  }

  // Close external flash driver.
  BLS_close();
}

Code snippet #7

Plain text
EFL_OAD_IMG_TYPE_APP                : Application image
EFL_OAD_IMG_TYPE_STACK    		    : stack image
EFL_OAD_IMG_TYPE_NP        		    : network processor image
EFL_OAD_IMG_TYPE_FACTORY		    : factory reset image
EFL_OAD_IMG_TYPE_REMOTE_APP         : remote application image

Code snippet #8

EFL_OAD_IMG_TYPE_APP                : Application image
EFL_OAD_IMG_TYPE_STACK    		    : stack image
EFL_OAD_IMG_TYPE_NP        		    : network processor image
EFL_OAD_IMG_TYPE_FACTORY		    : factory reset image
EFL_OAD_IMG_TYPE_REMOTE_APP         : remote application image

Code snippet #13

Plain text
Writing to:
rfWsnNodeExtFlashOadClient_CC1310_LAUNCHXL_app_v2.bin
***********************************************************************************
Success
***********************************************************************************
The script has calculated the 16 Byte OAD Metadata vector below

Bytes: | 0 - 2  |  2 - 4   | 4 - 6  | 6 - 8  |  8-12    | 12 - 14 |   15    |  16  |
Desc : |  CRC   | CRC-SHDW | imgVer | imgLen |  usrId   | imgAddr | imgType | stat |
------------------------------------------------------------------------------------
Data : | 0x79C4 |  0xFFFF  | 0x0200 | 0x4588 |  EEEE    | 0x0400  |  0x01   | 0xFF |
***********************************************************************************

Code snippet #14

Writing to:
rfWsnNodeExtFlashOadClient_CC1310_LAUNCHXL_app_v2.bin
***********************************************************************************
Success
***********************************************************************************
The script has calculated the 16 Byte OAD Metadata vector below

Bytes: | 0 - 2  |  2 - 4   | 4 - 6  | 6 - 8  |  8-12    | 12 - 14 |   15    |  16  |
Desc : |  CRC   | CRC-SHDW | imgVer | imgLen |  usrId   | imgAddr | imgType | stat |
------------------------------------------------------------------------------------
Data : | 0x79C4 |  0xFFFF  | 0x0200 | 0x4588 |  EEEE    | 0x0400  |  0x01   | 0xFF |
***********************************************************************************

Code snippet #23

Plain text
Writing to:
CC1310LP_oad-v2.bin
******************************************************************************************
Success
******************************************************************************************

The script has calculated the 16 Byte OAD Metadata vector below

Bytes: | 0 - 2  |  2 - 4   | 4 - 6  | 6 - 8  |  8-12    | 12 - 14 |   15    |  16  |
Desc : |  CRC   | CRC-SHDW | imgVer | imgLen |  usrId   | imgAddr | imgType | stat |
------------------------------------------------------------------------------------
Data : | 0xB2A3 |  0xFFFF  | 0x0200 | 0x3068 |  EEEE    | 0x0400  |  0x01   | 0xFF |
******************************************************************************************

Github file

https://github.com/rajeev1986/contikNG-offchip-oad-cc1310/tree/main/oad-tools

Github file

https://github.com/contiki-ng/contiki-ng/wiki

Credits

Rajeev Piyare
11 projects • 7 followers
Founder of Conexio Technologies | Wireless Systems Engineer | Research Scientist
Contact

Comments

Please log in or sign up to comment.