|
@@ -12,18 +12,20 @@
|
|
|
#include "MainTask.h"
|
|
|
#include "TcpTask.h"
|
|
|
#include "os_exception.h"
|
|
|
+#include "flash_ec616_rt.h"
|
|
|
extern AppNVMDataType AppNVMData;
|
|
|
static Fota_Type Fota_S;
|
|
|
static UINT8 bcc_chk_fota(UINT8* data, UINT8 length);
|
|
|
static UINT8 Fota_crc_chk(UINT8* data,UINT8 length);
|
|
|
+volatile bool Fota_update_flag = FALSE; //可以升级标志
|
|
|
void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
{
|
|
|
UINT8 Fota_Answer[42];
|
|
|
UINT8 Fota_Cmd;
|
|
|
+ INT8 ret;
|
|
|
Fota_S.Fota_Flash_Addres = Fota_Addres_Begin;
|
|
|
if(*(DataPtr+30)==0x01)
|
|
|
{
|
|
|
- Fota_S.Fota_update_flag = true;
|
|
|
Fota_Cmd = *(DataPtr+31);
|
|
|
Fota_Answer[0] = TCP_START_SYM1;
|
|
|
Fota_Answer[1] = TCP_START_SYM2;
|
|
@@ -41,7 +43,8 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
Fota_Answer[23] = 0x12;
|
|
|
memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
Fota_Answer[42] = bcc_chk_fota(Fota_Answer,41);
|
|
|
- tcpipConnectionSend(connectId,Fota_Answer,42,0,0,0);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
+ BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START, 0x78000); //512k-32k = 480k -> 0x75300
|
|
|
break;
|
|
|
}
|
|
|
case 0x02:
|
|
@@ -49,13 +52,59 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
|
|
|
Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
|
|
|
Fota_S.Fota_Recv_Data_Len = *(DataPtr+41);
|
|
|
+ memset(Fota_S.Fota_Recv_Data,0x00,100);
|
|
|
memcpy(Fota_S.Fota_Recv_Data,(DataPtr+42),*(DataPtr+41));
|
|
|
Fota_S.Fota_CRC = Fota_crc_chk(Fota_S.Fota_Recv_Data,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ #ifdef USING_PRINTF1
|
|
|
+ printf("\Data_Add:%x,Crc:%x,%x\n",Fota_S.Fota_Current_Addres,Fota_S.Fota_CRC,*(DataPtr+Fota_S.Fota_Recv_Data_Len+42));
|
|
|
+ UINT8 temp[5] = {0x01,0x02,0x03,0x04,0x05};
|
|
|
+ ret = BSP_QSPI_Write_Safe(temp,Fota_S.Fota_Flash_Addres+0xffe,5);
|
|
|
+ UINT8 tPtr[1];
|
|
|
+ printf("test:\n");
|
|
|
+ for(UINT32 i = 0;i<5;i++)
|
|
|
+ {
|
|
|
+ BSP_QSPI_Read_Safe(tPtr,Fota_S.Fota_Flash_Addres+0xffe+i,1);
|
|
|
+ printf("%x ",tPtr[0]);
|
|
|
+ }
|
|
|
+ printf("\ndata end\n");
|
|
|
+ #endif
|
|
|
if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42))
|
|
|
{
|
|
|
- BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
- BSP_QSPI_Write_Safe(Fota_S.Fota_Recv_Data,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
- Fota_Answer[3] = 0x01;
|
|
|
+ if(Fota_S.Fota_Recv_Data_Len%4!=0)
|
|
|
+ {
|
|
|
+ Fota_S.Fota_Recv_Data_Len = Fota_S.Fota_Recv_Data_Len + 4-(Fota_S.Fota_Recv_Data_Len%4);
|
|
|
+ }
|
|
|
+
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("\nlen:%x,%xFota_Data_Recv :",Fota_S.Fota_Recv_Data_Len,Fota_S.Fota_Current_Addres);
|
|
|
+ for(UINT32 i = 0;i<Fota_S.Fota_Recv_Data_Len;i++)
|
|
|
+ {
|
|
|
+ printf("%x ",Fota_S.Fota_Recv_Data[i]);
|
|
|
+ }
|
|
|
+ printf("\ndata Recv end\n");
|
|
|
+ #endif
|
|
|
+ ret = BSP_QSPI_Write_Safe(Fota_S.Fota_Recv_Data,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("\nret:%d\n",ret);
|
|
|
+ #endif
|
|
|
+ if(ret==QSPI_OK)
|
|
|
+ {
|
|
|
+ Fota_Answer[3] = 0x01;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Fota_Answer[3] = 0x02;
|
|
|
+ }
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ UINT8 Ptr[1];
|
|
|
+ printf("\nlen:%x,%xFota_Data :",Fota_S.Fota_Recv_Data_Len,Fota_S.Fota_Current_Addres);
|
|
|
+ for(UINT32 i = 0;i<Fota_S.Fota_Recv_Data_Len;i++)
|
|
|
+ {
|
|
|
+ BSP_QSPI_Read_Safe(Ptr,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres+i,1);
|
|
|
+ printf("%x ",Ptr[0]);
|
|
|
+ }
|
|
|
+ printf("\ndata end\n");
|
|
|
+ #endif
|
|
|
}
|
|
|
else//数据校验失败
|
|
|
{
|
|
@@ -67,23 +116,45 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
Fota_Answer[23] = 0x12;
|
|
|
memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
Fota_Answer[42] = bcc_chk_fota(Fota_Answer,41);
|
|
|
- tcpipConnectionSend(connectId,Fota_Answer,42,0,0,0);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
break;
|
|
|
}
|
|
|
case 0x03:
|
|
|
{
|
|
|
+ Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
|
|
|
+ Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
|
|
|
+ Fota_Answer[3] = 0x01;
|
|
|
+ memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
+ Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
|
+ Fota_Answer[22] = 0x00;
|
|
|
+ Fota_Answer[23] = 0x12;
|
|
|
+ memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
+ Fota_Answer[42] = bcc_chk_fota(Fota_Answer,41);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
+ if(Fota_S.Fota_All_Data_Len==Fota_S.Fota_Current_Addres)
|
|
|
+ {
|
|
|
+ Fota_update_flag = TRUE;
|
|
|
+ #ifdef USING_PRINTF1
|
|
|
+ UINT8 *Ptr;
|
|
|
+ printf("\nlen:%x,%xFota_Data :",Fota_S.Fota_All_Data_Len,Fota_S.Fota_Current_Addres);
|
|
|
+ for(UINT32 i = 0;i<Fota_S.Fota_All_Data_Len;i++)
|
|
|
+ {
|
|
|
+ BSP_QSPI_Read_Safe(Ptr,Fota_Addres_Begin+i,1);
|
|
|
+ printf("%x ",*(Ptr));
|
|
|
+ }
|
|
|
+ printf("\ndata end\n");
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Fota_update_flag = FALSE;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- Fota_S.Fota_update_flag = false;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
static UINT8 bcc_chk_fota(UINT8* data, UINT8 length)
|
|
|
{
|