|
@@ -1034,6 +1034,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 +1079,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)
|