|
@@ -21,6 +21,7 @@
|
|
#define FAIL -1
|
|
#define FAIL -1
|
|
#define YES 1
|
|
#define YES 1
|
|
#define NO 0
|
|
#define NO 0
|
|
|
|
+#define HEADER_LENGTH 48
|
|
|
|
|
|
struct SysConfigAndInfo *ShmSysConfigAndInfo;
|
|
struct SysConfigAndInfo *ShmSysConfigAndInfo;
|
|
struct StatusCodeData *ShmStatusCodeData;
|
|
struct StatusCodeData *ShmStatusCodeData;
|
|
@@ -154,7 +155,7 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
DEBUG_INFO("Image type: Root fs\n");
|
|
DEBUG_INFO("Image type: Root fs\n");
|
|
break;
|
|
break;
|
|
case CSU_USER_CONFIGURATION:
|
|
case CSU_USER_CONFIGURATION:
|
|
- MaxLen = 6*1024*1024+48;
|
|
|
|
|
|
+ MaxLen = 6*1024*1024;
|
|
DEBUG_INFO("Image type: Config\n");
|
|
DEBUG_INFO("Image type: Config\n");
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
@@ -168,11 +169,11 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- unsigned char *ptr = malloc(MaxLen);
|
|
|
|
- memset(ptr,0xFF,MaxLen);
|
|
|
|
|
|
+ unsigned char *ptr = malloc(MaxLen+HEADER_LENGTH);
|
|
|
|
+ memset(ptr,0xFF,MaxLen+HEADER_LENGTH);
|
|
|
|
|
|
//get the image length
|
|
//get the image length
|
|
- ImageLen = read(fd,ptr,MaxLen);
|
|
|
|
|
|
+ ImageLen = read(fd,ptr,MaxLen+HEADER_LENGTH);
|
|
close(fd);
|
|
close(fd);
|
|
|
|
|
|
// Delete source file, in order to down size ram disk usage
|
|
// Delete source file, in order to down size ram disk usage
|
|
@@ -205,9 +206,9 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
// check if the firmware type is correct
|
|
// 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(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])))
|
|
|
|
|
|
+ if((ImageLen-HEADER_LENGTH) == (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23])))
|
|
{
|
|
{
|
|
- DataLength = ImageLen-48;
|
|
|
|
|
|
+ DataLength = ImageLen-HEADER_LENGTH;
|
|
|
|
|
|
// get CRC in the header
|
|
// 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]);
|
|
ImageCRC = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
|
|
@@ -231,7 +232,7 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
{
|
|
{
|
|
// Write image to flash
|
|
// Write image to flash
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
|
|
|
+ wrd=write(fd, ptr+HEADER_LENGTH, DataLength);
|
|
close(fd);
|
|
close(fd);
|
|
DEBUG_INFO(">> imgBuffer Written length: 0x%x\n", wrd);
|
|
DEBUG_INFO(">> imgBuffer Written length: 0x%x\n", wrd);
|
|
if(wrd != DataLength)
|
|
if(wrd != DataLength)
|
|
@@ -262,7 +263,7 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
{
|
|
{
|
|
// Write image to flash
|
|
// Write image to flash
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
|
|
|
+ wrd=write(fd, ptr+HEADER_LENGTH, DataLength);
|
|
close(fd);
|
|
close(fd);
|
|
DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
if(wrd != DataLength)
|
|
if(wrd != DataLength)
|
|
@@ -299,7 +300,7 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
{
|
|
{
|
|
// Write image to flash
|
|
// Write image to flash
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
|
|
|
+ wrd=write(fd, ptr+HEADER_LENGTH, DataLength);
|
|
close(fd);
|
|
close(fd);
|
|
DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
if(wrd != DataLength)
|
|
if(wrd != DataLength)
|
|
@@ -336,7 +337,7 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
{
|
|
{
|
|
// Write image to flash
|
|
// Write image to flash
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
|
|
|
+ wrd=write(fd, ptr+HEADER_LENGTH, DataLength);
|
|
close(fd);
|
|
close(fd);
|
|
DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
if(wrd != DataLength)
|
|
if(wrd != DataLength)
|
|
@@ -370,7 +371,7 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
else
|
|
else
|
|
{
|
|
{
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
|
|
|
+ wrd=write(fd, ptr+HEADER_LENGTH, DataLength);
|
|
close(fd);
|
|
close(fd);
|
|
DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
if(wrd!=DataLength)
|
|
if(wrd!=DataLength)
|
|
@@ -405,7 +406,7 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
{
|
|
{
|
|
// Write image to flash
|
|
// Write image to flash
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
DEBUG_INFO("Writing image to image buffer file...\n");
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
|
|
|
+ wrd=write(fd, ptr+HEADER_LENGTH, DataLength);
|
|
close(fd);
|
|
close(fd);
|
|
DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
if(wrd != DataLength)
|
|
if(wrd != DataLength)
|
|
@@ -683,11 +684,11 @@ int Upgrade_UART(int uartfdOrd,unsigned int Type,unsigned char TargetAddr,char *
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- unsigned char *ptr = malloc(MaxLen);
|
|
|
|
- memset(ptr,0xFF,MaxLen);
|
|
|
|
|
|
+ unsigned char *ptr = malloc(MaxLen+HEADER_LENGTH);
|
|
|
|
+ memset(ptr,0xFF,MaxLen+HEADER_LENGTH);
|
|
|
|
|
|
//get the image length
|
|
//get the image length
|
|
- ImageLen = read(fd,ptr,MaxLen);
|
|
|
|
|
|
+ ImageLen = read(fd,ptr,MaxLen+HEADER_LENGTH);
|
|
close(fd);
|
|
close(fd);
|
|
//read out the header
|
|
//read out the header
|
|
int isModelNameOK = PASS;
|
|
int isModelNameOK = PASS;
|
|
@@ -714,9 +715,9 @@ int Upgrade_UART(int uartfdOrd,unsigned int Type,unsigned char TargetAddr,char *
|
|
// check if the firmware type is correct
|
|
// 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(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])))
|
|
|
|
|
|
+ if((ImageLen-HEADER_LENGTH) == (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23])))
|
|
{
|
|
{
|
|
- DataLength = ImageLen-48;
|
|
|
|
|
|
+ DataLength = ImageLen-HEADER_LENGTH;
|
|
|
|
|
|
// get CRC in the header
|
|
// 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]);
|
|
ImageCRC = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
|
|
@@ -733,7 +734,7 @@ int Upgrade_UART(int uartfdOrd,unsigned int Type,unsigned char TargetAddr,char *
|
|
|
|
|
|
do
|
|
do
|
|
{
|
|
{
|
|
- if(uart_update_start(uartfd, TargetAddr, crc32(ptr+48,DataLength))==PASS)
|
|
|
|
|
|
+ if(uart_update_start(uartfd, TargetAddr, crc32(ptr+HEADER_LENGTH,DataLength))==PASS)
|
|
break;
|
|
break;
|
|
else
|
|
else
|
|
DEBUG_WARN("Upgrade start fail, retry %d \n", ++CNT_Fail);
|
|
DEBUG_WARN("Upgrade start fail, retry %d \n", ++CNT_Fail);
|
|
@@ -749,7 +750,7 @@ int Upgrade_UART(int uartfdOrd,unsigned int Type,unsigned char TargetAddr,char *
|
|
CNT_Fail = 0;
|
|
CNT_Fail = 0;
|
|
do
|
|
do
|
|
{
|
|
{
|
|
- if(uart_update_transfer(uartfd, TargetAddr, CNT_Trans*1024, ptr+48+(CNT_Trans*1024), 1024)==PASS)
|
|
|
|
|
|
+ if(uart_update_transfer(uartfd, TargetAddr, CNT_Trans*1024, ptr+HEADER_LENGTH+(CNT_Trans*1024), 1024)==PASS)
|
|
{
|
|
{
|
|
CNT_Fail = 0;
|
|
CNT_Fail = 0;
|
|
CNT_Trans++;
|
|
CNT_Trans++;
|
|
@@ -977,11 +978,11 @@ int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- unsigned char *ptr = malloc(MaxLen);
|
|
|
|
- memset(ptr,0xFF,MaxLen);
|
|
|
|
|
|
+ unsigned char *ptr = malloc(MaxLen+HEADER_LENGTH);
|
|
|
|
+ memset(ptr,0xFF,MaxLen+HEADER_LENGTH);
|
|
|
|
|
|
//get the image length
|
|
//get the image length
|
|
- ImageLen = read(fd,ptr,MaxLen);
|
|
|
|
|
|
+ ImageLen = read(fd,ptr,MaxLen+HEADER_LENGTH);
|
|
close(fd);
|
|
close(fd);
|
|
//read out the header
|
|
//read out the header
|
|
int isModelNameOK = PASS;
|
|
int isModelNameOK = PASS;
|
|
@@ -1009,9 +1010,9 @@ int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
|
|
// check if the firmware type is correct
|
|
// 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(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])))
|
|
|
|
|
|
+ if((ImageLen-HEADER_LENGTH) == (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23])))
|
|
{
|
|
{
|
|
- DataLength = ImageLen-48;
|
|
|
|
|
|
+ DataLength = ImageLen-HEADER_LENGTH;
|
|
|
|
|
|
// get CRC in the header
|
|
// 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]);
|
|
ImageCRC = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
|
|
@@ -1025,7 +1026,7 @@ int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
|
|
|
|
|
|
for(int i=0;i<16;i++)
|
|
for(int i=0;i<16;i++)
|
|
{
|
|
{
|
|
- Checksum[i] = Checksum_Cal(i * 24576, 24576, ptr + 48);
|
|
|
|
|
|
+ Checksum[i] = Checksum_Cal(i * 24576, 24576, ptr + HEADER_LENGTH);
|
|
}
|
|
}
|
|
|
|
|
|
if(CAN_Download_REQ(canfd, TargetAddr, DataLength) == PASS)
|
|
if(CAN_Download_REQ(canfd, TargetAddr, DataLength) == PASS)
|
|
@@ -1036,7 +1037,7 @@ int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
|
|
{
|
|
{
|
|
for(int times = 0; times < 3072; times++)
|
|
for(int times = 0; times < 3072; times++)
|
|
{
|
|
{
|
|
- CAN_Data_Trans(canfd, TargetAddr, ((block - 1) * 24576 + times * 8), ptr + 48);
|
|
|
|
|
|
+ CAN_Data_Trans(canfd, TargetAddr, ((block - 1) * 24576 + times * 8), ptr + HEADER_LENGTH);
|
|
}
|
|
}
|
|
DEBUG_INFO(" \n\n");
|
|
DEBUG_INFO(" \n\n");
|
|
}
|
|
}
|
|
@@ -1114,11 +1115,11 @@ int Check_CCS_image_header(unsigned int Type,char *SourcePath,char *ModelName)
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- unsigned char *ptr = malloc(MaxLen);
|
|
|
|
- memset(ptr,0xFF,MaxLen);
|
|
|
|
|
|
+ unsigned char *ptr = malloc(MaxLen+HEADER_LENGTH);
|
|
|
|
+ memset(ptr,0xFF,MaxLen+HEADER_LENGTH);
|
|
|
|
|
|
//get the image length
|
|
//get the image length
|
|
- ImageLen = read(fd,ptr,MaxLen);
|
|
|
|
|
|
+ ImageLen = read(fd,ptr,MaxLen+HEADER_LENGTH);
|
|
close(fd);
|
|
close(fd);
|
|
//read out the header
|
|
//read out the header
|
|
int isModelNameOK = PASS;
|
|
int isModelNameOK = PASS;
|
|
@@ -1144,7 +1145,7 @@ int Check_CCS_image_header(unsigned int Type,char *SourcePath,char *ModelName)
|
|
// check if the firmware type is correct
|
|
// 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(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])))
|
|
|
|
|
|
+ if((ImageLen-HEADER_LENGTH) == (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23])))
|
|
{
|
|
{
|
|
// get CRC in the header
|
|
// 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]);
|
|
ImageCRC = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
|