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