|
@@ -14,17 +14,17 @@
|
|
|
#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 NB_Fota_update_flag = FALSE; //NB可以升级标志
|
|
|
volatile bool BMS_Fota_update_flag = FALSE; //NB可以升级标志
|
|
|
void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
{
|
|
|
+ Fota_Type Fota_S;
|
|
|
UINT8 Fota_Answer[43];
|
|
|
UINT8 Fota_Cmd;
|
|
|
INT8 ret;
|
|
|
- UINT8* Data_Read_Buffer;
|
|
|
+ UINT8* Data_Read_Buffer=PNULL;
|
|
|
UINT8 Data_Read_Crc;
|
|
|
if(*(DataPtr+30)==0x01)
|
|
|
{
|
|
@@ -46,7 +46,7 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
else
|
|
|
{
|
|
|
Fota_Answer[3] = 0x01;
|
|
|
- BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,Fota_S.Fota_All_Data_Len + 4 - (Fota_S.Fota_All_Data_Len%4)); //512k-32k = 480k -> 0x75300 0x78000
|
|
|
+ BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,(FLASH_BMS_FOTA_START_ADDR - FLASH_FOTA_REGION_START)); //512k-32k = 480k -> 0x75300 0x78000
|
|
|
}
|
|
|
memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
@@ -65,26 +65,25 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
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);
|
|
|
- if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42))
|
|
|
+ Data_Read_Buffer = malloc(Fota_S.Fota_Recv_Data_Len+1);
|
|
|
+ if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42)||Data_Read_Buffer!=PNULL)
|
|
|
{
|
|
|
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);
|
|
|
}
|
|
|
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);
|
|
|
- Data_Read_Buffer = malloc(Fota_S.Fota_Recv_Data_Len);
|
|
|
+ memset(Data_Read_Buffer,0x00,Fota_S.Fota_Recv_Data_Len);
|
|
|
BSP_QSPI_Read_Safe(Data_Read_Buffer,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
Data_Read_Crc = Fota_crc_chk(Data_Read_Buffer,Fota_S.Fota_Recv_Data_Len);
|
|
|
#ifdef USING_PRINTF
|
|
|
- printf("\n\n\n");
|
|
|
- UINT8 temp[1];
|
|
|
+ printf("Data_Read_Buffer:\n");
|
|
|
for(int i=0;i<Fota_S.Fota_Recv_Data_Len;i++)
|
|
|
{
|
|
|
printf("%x ",*(Data_Read_Buffer+i));
|
|
|
}
|
|
|
- printf("\n\n\n");
|
|
|
+ printf("\n");
|
|
|
#endif
|
|
|
- free(Data_Read_Buffer);
|
|
|
if(Data_Read_Crc==Fota_S.Fota_CRC )
|
|
|
{
|
|
|
Fota_Answer[3] = 0x01;
|
|
@@ -99,6 +98,9 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
{
|
|
|
Fota_Answer[3] = 0x02;
|
|
|
}
|
|
|
+ if(Data_Read_Buffer!=PNULL)
|
|
|
+ free(Data_Read_Buffer);
|
|
|
+ Data_Read_Buffer =PNULL;
|
|
|
memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
|
Fota_Answer[22] = 0x00;
|
|
@@ -175,7 +177,7 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
if(Fota_Answer[3] == 0x01)
|
|
|
{
|
|
|
- BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,Fota_S.Fota_All_Data_Len + 4 - (Fota_S.Fota_All_Data_Len%4)); //512k-32k = 480k -> 0x75300 0x78000
|
|
|
+ BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,(FLASH_BMS_FOTA_END_ADDR - FLASH_BMS_FOTA_START_ADDR)); //512k-32k = 480k -> 0x75300 0x78000
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -187,14 +189,15 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
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);
|
|
|
- if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42))
|
|
|
+ Data_Read_Buffer = malloc(Fota_S.Fota_Recv_Data_Len);
|
|
|
+ if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42)||Data_Read_Buffer!=PNULL)
|
|
|
{
|
|
|
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);
|
|
|
}
|
|
|
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);
|
|
|
- Data_Read_Buffer = malloc(Fota_S.Fota_Recv_Data_Len);
|
|
|
+
|
|
|
BSP_QSPI_Read_Safe(Data_Read_Buffer,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
Data_Read_Crc = Fota_crc_chk(Data_Read_Buffer,Fota_S.Fota_Recv_Data_Len);
|
|
|
#ifdef USING_PRINTF1
|
|
@@ -206,7 +209,6 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
}
|
|
|
printf("\n\n\n");
|
|
|
#endif
|
|
|
- free(Data_Read_Buffer);
|
|
|
if(Data_Read_Crc==Fota_S.Fota_CRC )
|
|
|
{
|
|
|
Fota_Answer[3] = 0x01;
|
|
@@ -221,6 +223,9 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
{
|
|
|
Fota_Answer[3] = 0x02;
|
|
|
}
|
|
|
+ if(Data_Read_Buffer!=PNULL)
|
|
|
+ free(Data_Read_Buffer);
|
|
|
+ Data_Read_Buffer =PNULL;
|
|
|
memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
|
Fota_Answer[22] = 0x00;
|