|
@@ -94,6 +94,7 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
|
{
|
|
|
int result = FAIL;
|
|
|
|
|
|
+ char cmdBuf[128];
|
|
|
long int MaxLen=48*1024*1024, ImageLen=0;
|
|
|
unsigned int ImageCRC=0, DataLength=0;
|
|
|
int wrd,fd;
|
|
@@ -104,23 +105,23 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
|
{
|
|
|
case CSU_BOOTLOADER:
|
|
|
MaxLen = 1*1024*1024;
|
|
|
- //DEBUG_INFO("Image type: U-Boot\r\n");
|
|
|
+ //DEBUG_INFO("Image type: U-Boot\n");
|
|
|
break;
|
|
|
case CSU_KERNEL_CONFIGURATION:
|
|
|
MaxLen = 0.5*1024*1024;
|
|
|
- DEBUG_INFO("Image type: DTB\r\n");
|
|
|
+ DEBUG_INFO("Image type: DTB\n");
|
|
|
break;
|
|
|
case CSU_KERNEL_IMAGE:
|
|
|
MaxLen = 10*1024*1024;
|
|
|
- DEBUG_INFO("Image type: Kernel\r\n");
|
|
|
+ DEBUG_INFO("Image type: Kernel\n");
|
|
|
break;
|
|
|
case CSU_ROOT_FILE_SYSTEM:
|
|
|
MaxLen = 48*1024*1024;
|
|
|
- DEBUG_INFO("Image type: Root fs\r\n");
|
|
|
+ DEBUG_INFO("Image type: Root fs\n");
|
|
|
break;
|
|
|
case CSU_USER_CONFIGURATION:
|
|
|
MaxLen = 6*1024*1024+48;
|
|
|
- DEBUG_INFO("Image type: Config\r\n");
|
|
|
+ DEBUG_INFO("Image type: Config\n");
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
@@ -152,7 +153,7 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
|
|
|
|
if(isModelNameOK == FAIL)
|
|
|
{
|
|
|
- DEBUG_ERROR("Model name mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Model name mismatch.\n");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -167,260 +168,214 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
|
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 image: 0x%08X\r\n",ImageCRC);
|
|
|
- DEBUG_INFO("CRC32 by calculation: 0x%08X\r\n",crc32(ptr,ImageLen));
|
|
|
+ DEBUG_INFO("CRC32 in image: 0x%08X\n",ImageCRC);
|
|
|
+ DEBUG_INFO("CRC32 by calculation: 0x%08X\n",crc32(ptr,ImageLen));
|
|
|
if(crc32(ptr,ImageLen) == ImageCRC)
|
|
|
{
|
|
|
// Write image to target flash block
|
|
|
switch(Type)
|
|
|
{
|
|
|
case FLASH_IMAGE_TYPE_SPL:
|
|
|
- fd = open("/dev/mtdblock0", O_RDWR);
|
|
|
+ fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
|
|
|
if (fd < 0)
|
|
|
{
|
|
|
- DEBUG_ERROR("Can not open mtdblock0\r\n");
|
|
|
+ DEBUG_ERROR("Can not create SPL image buffer file.\n");
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// Write image to flash
|
|
|
- DEBUG_INFO("Writing image to mtdblock0...\n");
|
|
|
+ DEBUG_INFO("Writing image to image buffer file...\n");
|
|
|
wrd=write(fd, ptr+48, DataLength);
|
|
|
close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock0 Written length: 0x%x\r\n", wrd);
|
|
|
+ DEBUG_INFO(">> imgBuffer Written length: 0x%x\n", wrd);
|
|
|
if(wrd != DataLength)
|
|
|
{
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- result = PASS;
|
|
|
+ DEBUG_INFO("Erase /dev/mtd0.\n");
|
|
|
+ system("flash_erase /dev/mtd0 0 1");
|
|
|
+ DEBUG_INFO("Write /dev/mtd0.\n");
|
|
|
+ system("nandwrite -p /dev/mtd0 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ system("rm -f /mnt/imgBuffer");
|
|
|
+ result = PASS;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case CSU_BOOTLOADER:
|
|
|
- fd = open("/dev/mtdblock1", O_RDWR);
|
|
|
+ fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
|
|
|
if (fd < 0)
|
|
|
{
|
|
|
- DEBUG_ERROR("Can not open mtdblock1\r\n");
|
|
|
+ DEBUG_ERROR("Can not create uboot image buffer file.\n");
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// Write image to flash
|
|
|
- DEBUG_INFO("Writing image to mtdblock1...\n");
|
|
|
+ DEBUG_INFO("Writing image to image buffer file...\n");
|
|
|
wrd=write(fd, ptr+48, DataLength);
|
|
|
close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock1 written length: 0x%x\r\n", wrd);
|
|
|
+ DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
|
if(wrd != DataLength)
|
|
|
{
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // Open flash target mtdblock
|
|
|
- fd = open("/dev/mtdblock3", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- DEBUG_ERROR("Can not open mtdblock3\r\n");
|
|
|
- result = FAIL;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Write image to flash
|
|
|
- DEBUG_INFO("Writing image to mtdblock3...\n");
|
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
- close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock3 written length: 0x%x\r\n", wrd);
|
|
|
- if(wrd != DataLength)
|
|
|
- {
|
|
|
- result = FAIL;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- result = PASS;
|
|
|
- }
|
|
|
- }
|
|
|
+ DEBUG_INFO("Erase /dev/mtd1.\n");
|
|
|
+ system("flash_erase /dev/mtd1 0 2");
|
|
|
+ DEBUG_INFO("Write /dev/mtd1.\n");
|
|
|
+ system("nandwrite -p /dev/mtd1 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ DEBUG_INFO("Erase /dev/mtd3.\n");
|
|
|
+ system("flash_erase /dev/mtd3 0 2");
|
|
|
+ DEBUG_INFO("Write /dev/mtd3.\n");
|
|
|
+ system("nandwrite -p /dev/mtd3 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ system("rm -f /mnt/imgBuffer");
|
|
|
+ result = PASS;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case CSU_KERNEL_CONFIGURATION:
|
|
|
- fd = open("/dev/mtdblock4", O_RDWR);
|
|
|
+ fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
|
|
|
if (fd < 0)
|
|
|
{
|
|
|
- DEBUG_ERROR("Can not open mtdblock4\r\n");
|
|
|
+ DEBUG_ERROR("Can not create DTB image buffer file.\n");
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// Write image to flash
|
|
|
- DEBUG_INFO("Writing image to mtdblock4...\n");
|
|
|
+ DEBUG_INFO("Writing image to image buffer file...\n");
|
|
|
wrd=write(fd, ptr+48, DataLength);
|
|
|
close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock4 written length: 0x%x\r\n", wrd);
|
|
|
+ DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
|
if(wrd != DataLength)
|
|
|
{
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // Open flash target mtdblock
|
|
|
- fd = open("/dev/mtdblock5", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- DEBUG_ERROR("Can not open mtdblock5\r\n");
|
|
|
- result = FAIL;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Write image to flash
|
|
|
- DEBUG_INFO("Writing image to mtdblock5...\n");
|
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
- close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock5 written length: 0x%x\r\n", wrd);
|
|
|
- if(wrd != DataLength)
|
|
|
- {
|
|
|
- result = FAIL;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- result = PASS;
|
|
|
- }
|
|
|
- }
|
|
|
+ DEBUG_INFO("Erase /dev/mtd4.\n");
|
|
|
+ system("flash_erase /dev/mtd4 0 1");
|
|
|
+ DEBUG_INFO("Write /dev/mtd4.\n");
|
|
|
+ system("nandwrite -p /dev/mtd4 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ DEBUG_INFO("Erase /dev/mtd5.\n");
|
|
|
+ system("flash_erase /dev/mtd5 0 1");
|
|
|
+ DEBUG_INFO("Write /dev/mtd5.\n");
|
|
|
+ system("nandwrite -p /dev/mtd5 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ system("rm -f /mnt/imgBuffer");
|
|
|
+ result = PASS;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case CSU_KERNEL_IMAGE:
|
|
|
- fd = open("/dev/mtdblock6", O_RDWR);
|
|
|
+ fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
|
|
|
if (fd < 0)
|
|
|
{
|
|
|
- DEBUG_ERROR("Can not open mtdblock6\r\n");
|
|
|
+ DEBUG_ERROR("Can not create kernel image buffer file.\n");
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// Write image to flash
|
|
|
- DEBUG_INFO("Writing image to mtdblock6...\n");
|
|
|
+ DEBUG_INFO("Writing image to image buffer file...\n");
|
|
|
wrd=write(fd, ptr+48, DataLength);
|
|
|
close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock6 written length: 0x%x\r\n", wrd);
|
|
|
+ DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
|
if(wrd != DataLength)
|
|
|
{
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // Open flash target mtdblock
|
|
|
- fd = open("/dev/mtdblock7", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- DEBUG_ERROR("Can not open mtdblock7\r\n");
|
|
|
- result = FAIL;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Write image to flash
|
|
|
- DEBUG_INFO("Writing image to mtdblock7...\n");
|
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
- close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock7 written length: 0x%x\r\n", wrd);
|
|
|
- if(wrd != DataLength)
|
|
|
- {
|
|
|
- result = FAIL;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- result = PASS;
|
|
|
- }
|
|
|
- }
|
|
|
+ DEBUG_INFO("Erase /dev/mtd6.\n");
|
|
|
+ system("flash_erase /dev/mtd6 0 20");
|
|
|
+ DEBUG_INFO("Write /dev/mtd6.\n");
|
|
|
+ system("nandwrite -p /dev/mtd6 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ DEBUG_INFO("Erase /dev/mtd7.\n");
|
|
|
+ system("flash_erase /dev/mtd7 0 20");
|
|
|
+ DEBUG_INFO("Write /dev/mtd7.\n");
|
|
|
+ system("nandwrite -p /dev/mtd7 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ system("rm -f /mnt/imgBuffer");
|
|
|
+ result = PASS;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case CSU_ROOT_FILE_SYSTEM:
|
|
|
- fd = open("/dev/mtdblock8", O_RDWR);
|
|
|
+ fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
|
|
|
if(fd < 0)
|
|
|
{
|
|
|
- DEBUG_ERROR("UpdateRootfs NG - can not open rootfs\n");
|
|
|
+ DEBUG_ERROR("UpdateRootfs NG - can not create rootfs image buffer file\n");
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DEBUG_INFO("Writing image to mtdblock8...\n");
|
|
|
+ DEBUG_INFO("Writing image to image buffer file...\n");
|
|
|
wrd=write(fd, ptr+48, DataLength);
|
|
|
close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock8 written length: 0x%x\r\n", wrd);
|
|
|
+ DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
|
if(wrd!=DataLength)
|
|
|
{
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- fd = open("/dev/mtdblock9", O_RDWR);
|
|
|
- if(fd < 0)
|
|
|
- {
|
|
|
- DEBUG_ERROR("UpdateRootfs NG - can not open rootfs\n");
|
|
|
- result = FAIL;
|
|
|
- }
|
|
|
-
|
|
|
- DEBUG_INFO("Writing image to mtdblock9...\n");
|
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
- close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock9 written length: 0x%x\r\n", wrd);
|
|
|
- if(wrd!=DataLength)
|
|
|
- {
|
|
|
- result = FAIL;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- result = PASS;
|
|
|
- }
|
|
|
+ DEBUG_INFO("Erase /dev/mtd8.\n");
|
|
|
+ system("flash_erase /dev/mtd8 0 96");
|
|
|
+ DEBUG_INFO("Write /dev/mtd8.\n");
|
|
|
+ system("nandwrite -p /dev/mtd8 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ DEBUG_INFO("Erase /dev/mtd9.\n");
|
|
|
+ system("flash_erase /dev/mtd9 0 96");
|
|
|
+ DEBUG_INFO("Write /dev/mtd9.\n");
|
|
|
+ system("nandwrite -p /dev/mtd9 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ system("rm -f /mnt/imgBuffer");
|
|
|
+ result = PASS;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case CSU_USER_CONFIGURATION:
|
|
|
- // Open flash target mtdblock
|
|
|
- fd = open("/dev/mtdblock10", O_RDWR);
|
|
|
+ fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
|
|
|
if (fd < 0)
|
|
|
{
|
|
|
- DEBUG_ERROR("Can not open mtdblock10\r\n");
|
|
|
+ DEBUG_ERROR("Can not create configuration image buffer file\n");
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// Write image to flash
|
|
|
- DEBUG_INFO("Writing image to mtdblock10...\n");
|
|
|
+ DEBUG_INFO("Writing image to image buffer file...\n");
|
|
|
wrd=write(fd, ptr+48, DataLength);
|
|
|
close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock10 written length: 0x%x\r\n", wrd);
|
|
|
+ DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
|
|
|
if(wrd != DataLength)
|
|
|
{
|
|
|
result = FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // Open flash target mtdblock
|
|
|
- fd = open("/dev/mtdblock11", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- DEBUG_ERROR("Can not open mtdblock11\r\n");
|
|
|
- result = FAIL;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Write image to flash
|
|
|
- DEBUG_INFO("Writing image to mtdblock11...\n");
|
|
|
- wrd=write(fd, ptr+48, DataLength);
|
|
|
- close(fd);
|
|
|
- DEBUG_INFO(">> mtdblock11 written length: 0x%x\r\n", wrd);
|
|
|
- if(wrd != DataLength)
|
|
|
- {
|
|
|
- result = FAIL;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- result = PASS;
|
|
|
- }
|
|
|
- }
|
|
|
+ DEBUG_INFO("Erase /dev/mtd10.\n");
|
|
|
+ system("flash_erase /dev/mtd10 0 12");
|
|
|
+ DEBUG_INFO("Write /dev/mtd10.\n");
|
|
|
+ system("nandwrite -p /dev/mtd10 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ DEBUG_INFO("Erase /dev/mtd11.\n");
|
|
|
+ system("flash_erase /dev/mtd11 0 12");
|
|
|
+ DEBUG_INFO("Write /dev/mtd11.\n");
|
|
|
+ system("nandwrite -p /dev/mtd11 /mnt/imgBuffer");
|
|
|
+
|
|
|
+ system("rm -f /mnt/imgBuffer");
|
|
|
+ result = PASS;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -429,20 +384,23 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
- DEBUG_ERROR("Firmware image CRC32 mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image CRC32 mismatch.\n");
|
|
|
}
|
|
|
else
|
|
|
- DEBUG_ERROR("Firmware image length mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image length mismatch.\n");
|
|
|
}
|
|
|
else
|
|
|
- DEBUG_ERROR("Firmware image type mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image type mismatch.\n");
|
|
|
}
|
|
|
free(ptr);
|
|
|
|
|
|
if(result == PASS)
|
|
|
- DEBUG_INFO("Update image success\r\n");
|
|
|
+ DEBUG_INFO("Update image success\n");
|
|
|
else
|
|
|
- DEBUG_ERROR("Update image fail\r\n");
|
|
|
+ DEBUG_ERROR("Update image fail\n");
|
|
|
+
|
|
|
+ sprintf(cmdBuf, "rm -f %s", SourcePath);
|
|
|
+ system(cmdBuf);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
@@ -636,7 +594,7 @@ unsigned char uart_update_finish(unsigned char fd, unsigned char targetAddr)
|
|
|
int Upgrade_UART(unsigned char uartfd,unsigned int Type,unsigned char TargetAddr,char *SourcePath,char *ModelName)
|
|
|
{
|
|
|
int result = FAIL;
|
|
|
-
|
|
|
+ char cmdBuf[128];
|
|
|
long int MaxLen=48*1024*1024, ImageLen=0;
|
|
|
unsigned int ImageCRC=0, DataLength=0;
|
|
|
int fd;
|
|
@@ -682,8 +640,8 @@ int Upgrade_UART(unsigned char uartfd,unsigned int Type,unsigned char TargetAddr
|
|
|
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 image: 0x%08X\r\n",ImageCRC);
|
|
|
- DEBUG_INFO("CRC32 by calculation: 0x%08X\r\n",crc32(ptr,ImageLen));
|
|
|
+ DEBUG_INFO("CRC32 in image: 0x%08X\n",ImageCRC);
|
|
|
+ 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)
|
|
@@ -696,18 +654,18 @@ int Upgrade_UART(unsigned char uartfd,unsigned int Type,unsigned char TargetAddr
|
|
|
{
|
|
|
CNT_Fail = 0;
|
|
|
CNT_Trans++;
|
|
|
- DEBUG_INFO("Upgrade progress:%.2f%%\r\n", ((float)(CNT_Trans*1024))/(DataLength)*100);
|
|
|
+ DEBUG_INFO("Upgrade progress:%.2f%%\n", ((float)(CNT_Trans*1024))/(DataLength)*100);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DEBUG_WARN("Data transfer fail, retry %d \r\n", ++CNT_Fail);
|
|
|
+ DEBUG_WARN("Data transfer fail, retry %d \n", ++CNT_Fail);
|
|
|
}
|
|
|
}while(DataLength-(CNT_Trans*1024)>0 && CNT_Fail<3);
|
|
|
|
|
|
if(CNT_Fail>=3)
|
|
|
{
|
|
|
uart_update_abord(uartfd, TargetAddr);
|
|
|
- DEBUG_ERROR("UART upgrade retry > limits, aboard upgrade.\r\n");
|
|
|
+ DEBUG_ERROR("UART upgrade retry > limits, aboard upgrade.\n");
|
|
|
}
|
|
|
else if(uart_update_finish(uartfd, TargetAddr)==PASS)
|
|
|
{
|
|
@@ -718,15 +676,18 @@ int Upgrade_UART(unsigned char uartfd,unsigned int Type,unsigned char TargetAddr
|
|
|
DEBUG_ERROR("UART upgrade request failed.\n");
|
|
|
}
|
|
|
else
|
|
|
- DEBUG_ERROR("Firmware image CRC32 mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image CRC32 mismatch.\n");
|
|
|
}
|
|
|
else
|
|
|
- DEBUG_ERROR("Firmware image length mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image length mismatch.\n");
|
|
|
}
|
|
|
else
|
|
|
- DEBUG_ERROR("Firmware image type mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image type mismatch.\n");
|
|
|
}
|
|
|
free(ptr);
|
|
|
+
|
|
|
+ sprintf(cmdBuf, "rm -f %s", SourcePath);
|
|
|
+ system(cmdBuf);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -889,6 +850,7 @@ int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
|
|
|
{
|
|
|
int result = FAIL;
|
|
|
|
|
|
+ char cmdBuf[128];
|
|
|
long int MaxLen=48*1024*1024, ImageLen=0;
|
|
|
unsigned int ImageCRC=0, DataLength=0;
|
|
|
int fd;
|
|
@@ -933,8 +895,8 @@ int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
|
|
|
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 image: 0x%08X\r\n",ImageCRC);
|
|
|
- DEBUG_INFO("CRC32 by calculation: 0x%08X\r\n",crc32(ptr,ImageLen));
|
|
|
+ DEBUG_INFO("CRC32 in image: 0x%08X\n",ImageCRC);
|
|
|
+ DEBUG_INFO("CRC32 by calculation: 0x%08X\n",crc32(ptr,ImageLen));
|
|
|
if(crc32(ptr,ImageLen) == ImageCRC)
|
|
|
{
|
|
|
unsigned int Checksum[16];
|
|
@@ -954,7 +916,7 @@ int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
|
|
|
{
|
|
|
CAN_Data_Trans(canfd, TargetAddr, ((block - 1) * 24576 + times * 8), ptr + 48);
|
|
|
}
|
|
|
- DEBUG_INFO(" \r\n\r\n");
|
|
|
+ DEBUG_INFO(" \n\n");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -970,16 +932,20 @@ int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
|
|
|
DEBUG_ERROR("CANBUS upgrade request failed.\n");
|
|
|
}
|
|
|
else
|
|
|
- DEBUG_ERROR("Firmware image CRC32 mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image CRC32 mismatch.\n");
|
|
|
}
|
|
|
else
|
|
|
- DEBUG_ERROR("Firmware image length mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image length mismatch.\n");
|
|
|
}
|
|
|
else
|
|
|
- DEBUG_ERROR("Firmware image type mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image type mismatch.\n");
|
|
|
|
|
|
}
|
|
|
free(ptr);
|
|
|
+
|
|
|
+ sprintf(cmdBuf, "rm -f %s", SourcePath);
|
|
|
+ system(cmdBuf);
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -1036,7 +1002,7 @@ int Check_CCS_image_header(unsigned int Type,char *SourcePath,char *ModelName)
|
|
|
{
|
|
|
if(ModelName[i] != ptr[i])
|
|
|
{
|
|
|
- DEBUG_ERROR("Model name mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Model name mismatch.\n");
|
|
|
return FAIL;
|
|
|
}
|
|
|
}
|
|
@@ -1050,27 +1016,27 @@ int Check_CCS_image_header(unsigned int Type,char *SourcePath,char *ModelName)
|
|
|
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\r\n",ImageCRC);
|
|
|
- DEBUG_INFO("CRC32 by calculation: 0x%08X\r\n",crc32(ptr,ImageLen));
|
|
|
+ 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.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image CRC32 mismatch.\n");
|
|
|
return FAIL;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DEBUG_ERROR("Firmware image length mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image length mismatch.\n");
|
|
|
return FAIL;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DEBUG_ERROR("Firmware image type mismatch.\r\n");
|
|
|
+ DEBUG_ERROR("Firmware image type mismatch.\n");
|
|
|
return FAIL;
|
|
|
}
|
|
|
}
|
|
@@ -1145,6 +1111,8 @@ int Send_CCS_download_finish(int canfd,unsigned int Slave_Addr)
|
|
|
|
|
|
int Upgrade_CCS(int canfd,unsigned int Type,unsigned char TargetAddr,char *SourcePath,char *ModelName)
|
|
|
{
|
|
|
+ char cmdBuf[128];
|
|
|
+
|
|
|
if(Check_CCS_image_header(Type, SourcePath, ModelName) == FAIL)
|
|
|
{
|
|
|
return FAIL;
|
|
@@ -1161,5 +1129,9 @@ int Upgrade_CCS(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
|
|
|
}
|
|
|
|
|
|
DEBUG_INFO("Upgrade CCS board %d complete.\n", TargetAddr);
|
|
|
+
|
|
|
+ sprintf(cmdBuf, "rm -f %s", SourcePath);
|
|
|
+ system(cmdBuf);
|
|
|
+
|
|
|
return PASS;
|
|
|
}
|