|
@@ -484,7 +484,7 @@ int uart_tranceive(int fd, unsigned char* cmd, unsigned char* rx, int len, unsig
|
|
|
return rxLen;
|
|
|
}
|
|
|
|
|
|
-unsigned char uart_update_start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
|
|
|
+unsigned char uart_update_start(int fd, unsigned char targetAddr, unsigned int crc32)
|
|
|
{
|
|
|
unsigned char result = FAIL;
|
|
|
unsigned char tx[11] = {0xaa, 0x00, targetAddr, UART_CMD_UPDATE_START, 0x04, 0x00, (crc32>>0)&0xff, (crc32>>8)&0xff, (crc32>>16)&0xff, (crc32>>24)&0xff, 0x00};
|
|
@@ -525,7 +525,7 @@ unsigned char uart_update_start(unsigned char fd, unsigned char targetAddr, unsi
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-unsigned char uart_update_abord(unsigned char fd, unsigned char targetAddr)
|
|
|
+unsigned char uart_update_abord(int fd, unsigned char targetAddr)
|
|
|
{
|
|
|
unsigned char result = FAIL;
|
|
|
unsigned char tx[7] = {0xaa, 0x00, targetAddr, UART_CMD_UPDATE_ABORD, 0x00, 0x00, 0x00};
|
|
@@ -562,7 +562,7 @@ unsigned char uart_update_abord(unsigned char fd, unsigned char targetAddr)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-unsigned char uart_update_transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
|
|
|
+unsigned char uart_update_transfer(int fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
|
|
|
{
|
|
|
unsigned char result = FAIL;
|
|
|
unsigned char tx[11 + length];
|
|
@@ -610,7 +610,7 @@ unsigned char uart_update_transfer(unsigned char fd, unsigned char targetAddr, u
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-unsigned char uart_update_finish(unsigned char fd, unsigned char targetAddr)
|
|
|
+unsigned char uart_update_finish(int fd, unsigned char targetAddr)
|
|
|
{
|
|
|
unsigned char result = FAIL;
|
|
|
unsigned char tx[7] = {0xaa, 0x00, targetAddr, UART_CMD_UPDATE_FINISH, 0x00, 0x00, 0x00};
|
|
@@ -647,7 +647,7 @@ unsigned char uart_update_finish(unsigned char fd, unsigned char targetAddr)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-unsigned char uart_config_timeout(unsigned char uartfd)
|
|
|
+unsigned char uart_config_timeout(int uartfd)
|
|
|
{
|
|
|
struct termios tios;
|
|
|
|
|
@@ -712,52 +712,70 @@ int Upgrade_UART(int uartfdOrd,unsigned int Type,unsigned char TargetAddr,char *
|
|
|
DEBUG_INFO("CRC32 by calculation: 0x%08X\n",crc32(ptr,ImageLen));
|
|
|
if(crc32(ptr,ImageLen) == ImageCRC)
|
|
|
{
|
|
|
- if(uart_update_start(uartfd, TargetAddr, crc32(ptr+48,DataLength))==PASS)
|
|
|
+ if(YES)
|
|
|
{
|
|
|
int CNT_Fail = 0;
|
|
|
int CNT_Trans = 0;
|
|
|
+
|
|
|
do
|
|
|
{
|
|
|
- if(uart_update_transfer(uartfd, TargetAddr, CNT_Trans*1024, ptr+48+(CNT_Trans*1024), 1024)==PASS)
|
|
|
- {
|
|
|
- CNT_Fail = 0;
|
|
|
- CNT_Trans++;
|
|
|
- DEBUG_INFO("Upgrade progress:%.2f%%\n", ((float)(CNT_Trans*1024))/(DataLength)*100);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DEBUG_WARN("Data transfer fail, retry %d \n", ++CNT_Fail);
|
|
|
- sleep(1);
|
|
|
- }
|
|
|
- }while(DataLength-(CNT_Trans*1024)>0 && CNT_Fail<10);
|
|
|
+ if(uart_update_start(uartfd, TargetAddr, crc32(ptr+48,DataLength))==PASS)
|
|
|
+ break;
|
|
|
+ else
|
|
|
+ DEBUG_WARN("Upgrade start fail, retry %d \n", ++CNT_Fail);
|
|
|
+ }while(CNT_Fail<10);
|
|
|
|
|
|
if(CNT_Fail>=10)
|
|
|
- {
|
|
|
- uart_update_abord(uartfd, TargetAddr);
|
|
|
- DEBUG_ERROR("UART upgrade transfer retry > limits, aboard upgrade.\n");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- do
|
|
|
- {
|
|
|
- if(uart_update_finish(uartfd, TargetAddr)==PASS)
|
|
|
- break;
|
|
|
- else
|
|
|
- DEBUG_WARN("Upgrade finish fail, retry %d \n", ++CNT_Fail);
|
|
|
- }while(CNT_Fail<10);
|
|
|
-
|
|
|
- if(CNT_Fail>=10)
|
|
|
- {
|
|
|
- uart_update_abord(uartfd, TargetAddr);
|
|
|
- DEBUG_ERROR("UART upgrade finish retry > limits, aboard upgrade.\n");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- result = PASS;
|
|
|
- printf("UART upgrade success.\n");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ {
|
|
|
+ uart_update_abord(uartfd, TargetAddr);
|
|
|
+ DEBUG_ERROR("UART upgrade start retry > limits, aboard upgrade.\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CNT_Fail = 0;
|
|
|
+ do
|
|
|
+ {
|
|
|
+ if(uart_update_transfer(uartfd, TargetAddr, CNT_Trans*1024, ptr+48+(CNT_Trans*1024), 1024)==PASS)
|
|
|
+ {
|
|
|
+ CNT_Fail = 0;
|
|
|
+ CNT_Trans++;
|
|
|
+ DEBUG_INFO("Upgrade progress:%.2f%%\n", ((float)(CNT_Trans*1024))/(DataLength)*100);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_WARN("Data transfer fail, retry %d \n", ++CNT_Fail);
|
|
|
+ sleep(1);
|
|
|
+ }
|
|
|
+ }while(DataLength-(CNT_Trans*1024)>0 && CNT_Fail<10);
|
|
|
+
|
|
|
+ if(CNT_Fail>=10)
|
|
|
+ {
|
|
|
+ uart_update_abord(uartfd, TargetAddr);
|
|
|
+ DEBUG_ERROR("UART upgrade transfer retry > limits, aboard upgrade.\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CNT_Fail = 0;
|
|
|
+ do
|
|
|
+ {
|
|
|
+ if(uart_update_finish(uartfd, TargetAddr)==PASS)
|
|
|
+ break;
|
|
|
+ else
|
|
|
+ DEBUG_WARN("Upgrade finish fail, retry %d \n", ++CNT_Fail);
|
|
|
+ }while(CNT_Fail<10);
|
|
|
+
|
|
|
+ if(CNT_Fail>=10)
|
|
|
+ {
|
|
|
+ uart_update_abord(uartfd, TargetAddr);
|
|
|
+ DEBUG_ERROR("UART upgrade finish retry > limits, aboard upgrade.\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result = PASS;
|
|
|
+ printf("UART upgrade success.\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
DEBUG_ERROR("UART upgrade request failed.\n");
|
|
@@ -1034,6 +1052,7 @@ int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
|
|
|
//================================================
|
|
|
int Check_CCS_image_header(unsigned int Type,char *SourcePath,char *ModelName)
|
|
|
{
|
|
|
+ int result = FAIL;
|
|
|
long int MaxLen=48*1024*1024, ImageLen=0;
|
|
|
unsigned int ImageCRC=0;
|
|
|
int fd;
|
|
@@ -1078,47 +1097,54 @@ int Check_CCS_image_header(unsigned int Type,char *SourcePath,char *ModelName)
|
|
|
close(fd);
|
|
|
//read out the header
|
|
|
int i;
|
|
|
- for(i=0;i<16;i++)
|
|
|
- {
|
|
|
- if(ModelName[i] != ptr[i])
|
|
|
- {
|
|
|
- DEBUG_ERROR("Model name mismatch.\n");
|
|
|
- return FAIL;
|
|
|
- }
|
|
|
- }
|
|
|
+ int isModelNameOK = PASS;
|
|
|
+ for(i=0;i<16;i++)
|
|
|
+ {
|
|
|
+ if(ModelName[i] != ptr[i])
|
|
|
+ {
|
|
|
+ isModelNameOK = FAIL;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // check if the firmware type is correct
|
|
|
- if(Type == (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19])))
|
|
|
- {
|
|
|
- if((ImageLen-48) == (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23])))
|
|
|
- {
|
|
|
- // get CRC in the header
|
|
|
- ImageCRC = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
|
|
|
+ if(isModelNameOK == FAIL)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("Model name mismatch.\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // check if the firmware type is correct
|
|
|
+ if(Type == (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19])))
|
|
|
+ {
|
|
|
+ if((ImageLen-48) == (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23])))
|
|
|
+ {
|
|
|
+ // get CRC in the header
|
|
|
+ ImageCRC = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
|
|
|
+
|
|
|
+ // calculate the image CRC
|
|
|
+ DEBUG_INFO("CRC32 in CCS image: 0x%08X\n",ImageCRC);
|
|
|
+ DEBUG_INFO("CRC32 by calculation: 0x%08X\n",crc32(ptr,ImageLen));
|
|
|
+ if(crc32(ptr,ImageLen) == ImageCRC)
|
|
|
+ {
|
|
|
+ result = PASS;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("Firmware image CRC32 mismatch.\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("Firmware image length mismatch.\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("Firmware image type mismatch.\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ free(ptr);
|
|
|
|
|
|
- // calculate the image CRC
|
|
|
- DEBUG_INFO("CRC32 in CCS image: 0x%08X\n",ImageCRC);
|
|
|
- DEBUG_INFO("CRC32 by calculation: 0x%08X\n",crc32(ptr,ImageLen));
|
|
|
- if(crc32(ptr,ImageLen) == ImageCRC)
|
|
|
- {
|
|
|
- return PASS;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DEBUG_ERROR("Firmware image CRC32 mismatch.\n");
|
|
|
- return FAIL;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DEBUG_ERROR("Firmware image length mismatch.\n");
|
|
|
- return FAIL;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DEBUG_ERROR("Firmware image type mismatch.\n");
|
|
|
- return FAIL;
|
|
|
- }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
int Put_CCS_image(char *SourcePath, unsigned char TargetAddr)
|
|
@@ -1162,7 +1188,7 @@ int Send_CCS_download_finish(int canfd,unsigned int Slave_Addr)
|
|
|
|
|
|
struct timeval timer;
|
|
|
gettimeofday(&timer, NULL);
|
|
|
- unsigned long ack_timeout = 30 * 60 * 1000 * 1000; //30 minutes
|
|
|
+ unsigned long ack_timeout = 5 * 60 * 1000 * 1000; //5 minutes
|
|
|
|
|
|
while (getTimeoutValue(timer) < ack_timeout)
|
|
|
{
|