/**
* @brief Pro_W2D_UpdateDataHandle
* update Piece Handle , Judge Last Piece
* @param[in] indata : Piece Data
* @param[in] dataLen : Piece Length
* @param[in] formatType : Piece Data Format
* @param[out]
* @return 0,Handle Success
* -1,Input Param Illegal
* -2,Last Piece , MD5 Check Faild
**/int8_t Pro_W2D_UpdateDataHandle(uint8_t*inData , uint32_t dataLen , otaDataType formatType)
{
uint16_t piecenum= 0;
uint16_t piececount= 0;
uint32_t tempWFlashAddr= 0;
updataPieceData_TypeDef pieceData;
uint8_t md5_calc[SSL_MAX_LEN];//MD5 Calculate Fact
if(NULL ==inData)
{return -1;
}
memcpy((uint8_t*)&pieceData, inData, dataLen);
piecenum=exchangeBytes(pieceData.piecenum);
piececount=exchangeBytes(pieceData.piececount);
GIZWITS_LOG("******piecenum = %d , piececount = %d, pieceSize = %d******** \r\n",piecenum,piececount,dataLen - 4);
GIZWITS_LOG("\r\n write data to bkt\r\n");
ef_write_data_to_bak(pieceData.piececontent,dataLen- 4,&cur_size,romUpdate.updateFileSize);
GIZWITS_LOG("\r\n write data ok cur_size =%d -- %d \r\n",cur_size,romUpdate.updateFileSize);//tempWFlashAddr = SYS_APP_BAK_SAVE_ADDR_BASE + (piecenum-1) * PIECE_MAX_LEN;//wFlashData((uint8_t *)pieceData.piececontent , dataLen - 4, tempWFlashAddr);
GAgent_MD5Update(&romUpdate.ctx, (uint8_t *)pieceData.piececontent, dataLen - 4);/*updata package data ,ack*/
if(piecenum ==piececount)
{
memset(md5_calc,0,SSL_MAX_LEN);
GAgent_MD5Final(&romUpdate.ctx, md5_calc);
GIZWITS_LOG("MD5 Calculate Success , Will Check The MD5 ..\n");if(0 !=memcmp(romUpdate.update_param.ssl_data, md5_calc, SSL_MAX_LEN))
{
GIZWITS_LOG("Md5_Cacl Check Faild ,MCU OTA Faild\r\n");
#ifdef PROTOCOL_DEBUG
GIZWITS_LOG("Calc MD5:");for(uint16_t i=0; i
{
GIZWITS_LOG("%02x", md5_calc[i]);
}
GIZWITS_LOG("\r\n");#endif#ifdef PROTOCOL_DEBUG
GIZWITS_LOG("SSL MD5:");for(uint16_t i=0; i
{
GIZWITS_LOG("%02x", romUpdate.update_param.ssl_data[i]);
}
GIZWITS_LOG("\r\n");#endifmemset((uint8_t*)&romUpdate.update_param,0,sizeof(updateParamSave_t));return -2;
}else{/*OTA成功*/GIZWITS_LOG("MD5 Check Success ,Storage ROM Success , Write Update Flag\n");//flash_erase(sizeof(updateParamSave_t) , UPDATE_PARAM_SAVE_ADDR_BASE);
romUpdate.update_param.rom_statue= 0xEEEE;*((unsigned char*)(0x200000ff)) = 0xAA; /*传升级标志*/
*((size_t*)(0x200000f0)) = romUpdate.updateFileSize; /*传升级长度*/
//wFlashData((uint8_t *)&romUpdate.update_param, sizeof(updateParamSave_t), UPDATE_PARAM_SAVE_ADDR_BASE);//romUpdate.update_param.rom_statue = 0x1234;//printf("\n\romUpdate.update_param.rom_statue = %04X \r\n\n",romUpdate.update_param.rom_statue);//memset((uint8_t *)&romUpdate, 0 , sizeof(romUpdate));//rFlashData((uint8_t *)&romUpdate, sizeof(romUpdate), UPDATE_PARAM_SAVE_ADDR_BASE);//printf("\n\romUpdate.update_param.rom_statue = %04X \r\n\n",romUpdate.update_param.rom_statue);
GIZWITS_LOG("System Will Restart... \n");/****************************MCU RESTART****************************/mcuRestart();/******************************************************************************/
//last package , updata ok//MD5 checkout :Failed clear updata,Success , write flash ,begin updata
}
}return 0;
}