This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2652R: External flash related functions not defined in cc2652 sdk v2.30 in Z-STACK zed_switch_ota project

Guru 14805 points
Part Number: CC2652R
Other Parts Discussed in Thread: Z-STACK

What is the use of below code in "ota_client_app.c", because if I enable   "FACTORY_IMAGE" and  "EXTERNAL_IMAGE_CHECK", it has some functions related to external flash which are not defined.

#ifdef FACTORY_IMAGE
/******************************************************************************
 * @fn          SampleApp_hasFactoryImage
 *
 * @brief       Is the factory image available?
 *
 * @param       none
 *
 * @return      none
 */
static bool OTA_hasFactoryImage(void)
{
#if defined(EXTERNAL_IMAGE_CHECK)
  bool  valid;
  valid = extFlashOpen();

  if(valid)
  {
    uint16_t  buffer[2];

    // 1. Check reset vector
    valid = extFlashRead(EFL_ADDR_RECOVERY, sizeof(buffer),
                         (uint8_t *) buffer);
    if(valid)
    {
      valid = (buffer[0] != 0xFFFF && buffer[1] != 0xFFFF) &&
              (buffer[0] != 0x0000 && buffer[1] != 0x0000);
    }

    extFlashClose();
  }

  return valid;
#else
  return (true);
#endif
}


/*******************************************************************************
 * @fn      SampleAppSaveFactoryImage
 *
 * @brief   Save the current image to external flash as a factory image
 *
 * @return  none
 */
static bool OTA_saveFactoryImage(void)
{
  bool success;
  
  success = extFlashOpen();
  
  if (success)
  {
    uint32_t address;

    // Erase external flash
    for (address= 0; address<EFL_FLASH_SIZE; address+=EFL_PAGE_SIZE)
    {
      extFlashErase(address,EFL_PAGE_SIZE);
    }

    // Install factory image
    for (address=0; address<EFL_SIZE_RECOVERY && success; address+=EFL_PAGE_SIZE)
    {
      success = extFlashErase(EFL_ADDR_RECOVERY+address, EFL_PAGE_SIZE);
      if (success)
      {
        size_t offset;
        static uint8_t buf[256];  // RAM storage needed due to SPI/DMA limitation
        
        for (offset=0; offset<EFL_PAGE_SIZE; offset+=sizeof(buf))
        {
          const uint8_t *pIntFlash;
          
          // Copy from internal to external flash
          pIntFlash = (const uint8_t*)address + offset;
          memcpy(buf,pIntFlash,sizeof(buf));
          success = extFlashWrite(EFL_ADDR_RECOVERY+address+offset, sizeof(buf), buf);
          
          // Verify first few bytes
          if (success)
          {
            extFlashRead(EFL_ADDR_RECOVERY+address+offset, sizeof(buf), buf);
            success = buf[2] == pIntFlash[2] && buf[3] == pIntFlash[3];
          }
        }
      }
      
      
    }
    
    extFlashClose();
  }

  return success;
}
#endif

  • Hi Dhanraj,

    Perhaps you are aware of the off-chip BIM which is available: dev.ti.com/.../bim.html

    There are plans to include on-chip OAD but there is not any support available in the current SimpleLink SDK. The flags mentioned indicate preliminary work which is not yet completed, they were copied from functions that restore the factory image that is on external flash which is standard on all LaunchPads. Otherwise you'll notice that the flags are not used or supported anywhere else in Z-Stack so you will have to implement your own solution if your application cannot wait until mid-2019.

    Regards,
    Ryan