Module_Upgrade.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  1. /*
  2. * Module_Upgrade.c
  3. *
  4. * Created on: 2020-01-21
  5. * Author: Jerry Wang
  6. * Version: D0.03
  7. */
  8. #include "Module_Upgrade.h"
  9. //==================================
  10. // PRINT OUT LOG FORMAT
  11. //==================================
  12. #define DEBUG_INFO(format, args...) storeLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  13. #define DEBUG_WARN(format, args...) storeLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  14. #define DEBUG_ERROR(format, args...) storeLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  15. #define SystemLogMessage
  16. //#define ConsloePrintLog
  17. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  18. #define PASS 1
  19. #define FAIL -1
  20. #define YES 1
  21. #define NO 0
  22. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  23. struct StatusCodeData *ShmStatusCodeData;
  24. struct FanModuleData *ShmFanModuleData;
  25. int storeLogMsg(const char *fmt, ...)
  26. {
  27. char Buf[4096+256];
  28. char buffer[4096];
  29. time_t CurrentTime;
  30. struct tm *tm;
  31. struct timeval tv;
  32. va_list args;
  33. va_start(args, fmt);
  34. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  35. va_end(args);
  36. memset(Buf,0,sizeof(Buf));
  37. CurrentTime = time(NULL);
  38. tm=localtime(&CurrentTime);
  39. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  40. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_UpgradeLog",
  41. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  42. buffer,
  43. tm->tm_year+1900,tm->tm_mon+1);
  44. #ifdef SystemLogMessage
  45. system(Buf);
  46. #endif
  47. #ifdef ConsloePrintLog
  48. printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
  49. #endif
  50. return rc;
  51. }
  52. int DiffTimebByUpgrade(struct timeb ST, struct timeb ET)
  53. {
  54. //return milli-second
  55. unsigned int StartTime,StopTime;
  56. StartTime=(unsigned int)ST.time;
  57. StopTime=(unsigned int)ET.time;
  58. return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  59. }
  60. unsigned char *memcat(unsigned char *dest, unsigned int dest_len, unsigned char *src, unsigned int src_len)
  61. {
  62. memcpy(dest+dest_len, src, src_len);
  63. return dest;
  64. }
  65. uint32_t crc32(uint8_t *data, unsigned int length)
  66. {
  67. uint8_t i;
  68. uint32_t cnt = 0;
  69. uint32_t crc = 0xffffffff; // Initial value
  70. while(length--)
  71. {
  72. if(cnt>33 && cnt<48) {
  73. data++;
  74. }else {
  75. crc ^= *data++; // crc ^= *data; data++;
  76. for (i = 0; i < 8; ++i)
  77. {
  78. if (crc & 1)
  79. crc = (crc >> 1) ^ 0xEDB88320;// 0xEDB88320= reverse 0x04C11DB7
  80. else
  81. crc = (crc >> 1);
  82. }
  83. }
  84. cnt++;
  85. }
  86. return ~crc;
  87. }
  88. int runShellCmd(const char*cmd)
  89. {
  90. int result = FAIL;
  91. char buf[256];
  92. FILE *fp;
  93. fp = popen(cmd, "r");
  94. if(fp != NULL)
  95. {
  96. while(fgets(buf, sizeof(buf), fp) != NULL)
  97. {
  98. DEBUG_INFO("%s\n", buf);
  99. }
  100. result = PASS;
  101. }
  102. pclose(fp);
  103. return result;
  104. }
  105. int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
  106. {
  107. int result = FAIL;
  108. char cmdBuf[128];
  109. long int MaxLen=48*1024*1024, ImageLen=0;
  110. unsigned int ImageCRC=0, DataLength=0;
  111. int wrd,fd;
  112. // space max size set
  113. switch(Type)
  114. {
  115. case CSU_BOOTLOADER:
  116. MaxLen = 1*1024*1024;
  117. //DEBUG_INFO("Image type: U-Boot\n");
  118. break;
  119. case CSU_KERNEL_CONFIGURATION:
  120. MaxLen = 0.5*1024*1024;
  121. DEBUG_INFO("Image type: DTB\n");
  122. break;
  123. case CSU_KERNEL_IMAGE:
  124. MaxLen = 10*1024*1024;
  125. DEBUG_INFO("Image type: Kernel\n");
  126. break;
  127. case CSU_ROOT_FILE_SYSTEM:
  128. MaxLen = 48*1024*1024;
  129. DEBUG_INFO("Image type: Root fs\n");
  130. break;
  131. case CSU_USER_CONFIGURATION:
  132. MaxLen = 6*1024*1024+48;
  133. DEBUG_INFO("Image type: Config\n");
  134. break;
  135. default:
  136. break;
  137. }
  138. fd = open(SourcePath, O_RDONLY);
  139. if(fd < 0)
  140. {
  141. DEBUG_ERROR("UpdateRootfs NG - can not open rootfs\n");
  142. return result;
  143. }
  144. unsigned char *ptr = malloc(MaxLen);
  145. memset(ptr,0xFF,MaxLen);
  146. //get the image length
  147. ImageLen = read(fd,ptr,MaxLen);
  148. close(fd);
  149. // Delete source file, in order to down size ram disk usage
  150. sprintf(cmdBuf, "rm -f %s", SourcePath);
  151. system(cmdBuf);
  152. DEBUG_INFO("Delete source file.\n");
  153. //read out the header
  154. int i;
  155. int isModelNameOK = PASS;
  156. for(i=0;i<16;i++)
  157. {
  158. if(ModelName[i] != ptr[i])
  159. {
  160. isModelNameOK = FAIL;
  161. }
  162. }
  163. if(isModelNameOK == FAIL)
  164. {
  165. DEBUG_ERROR("Model name mismatch.\n");
  166. }
  167. else
  168. {
  169. // check if the firmware type is correct
  170. if(Type == (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19])))
  171. {
  172. if((ImageLen-48) == (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23])))
  173. {
  174. DataLength = ImageLen-48;
  175. // get CRC in the header
  176. ImageCRC = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
  177. // calculate the image CRC
  178. DEBUG_INFO("CRC32 in image: 0x%08X\n",ImageCRC);
  179. DEBUG_INFO("CRC32 by calculation: 0x%08X\n",crc32(ptr,ImageLen));
  180. if(crc32(ptr,ImageLen) == ImageCRC)
  181. {
  182. // Write image to target flash block
  183. switch(Type)
  184. {
  185. case FLASH_IMAGE_TYPE_SPL:
  186. fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
  187. if (fd < 0)
  188. {
  189. DEBUG_ERROR("Can not create SPL image buffer file.\n");
  190. result = FAIL;
  191. }
  192. else
  193. {
  194. // Write image to flash
  195. DEBUG_INFO("Writing image to image buffer file...\n");
  196. wrd=write(fd, ptr+48, DataLength);
  197. close(fd);
  198. DEBUG_INFO(">> imgBuffer Written length: 0x%x\n", wrd);
  199. if(wrd != DataLength)
  200. {
  201. result = FAIL;
  202. }
  203. else
  204. {
  205. DEBUG_INFO("Erase /dev/mtd0.\n");
  206. runShellCmd("flash_erase /dev/mtd0 0 1");
  207. DEBUG_INFO("Write /dev/mtd0.\n");
  208. runShellCmd("nandwrite -p /dev/mtd0 /mnt/imgBuffer");
  209. system("rm -f /mnt/imgBuffer");
  210. result = PASS;
  211. }
  212. }
  213. break;
  214. case CSU_BOOTLOADER:
  215. fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
  216. if (fd < 0)
  217. {
  218. DEBUG_ERROR("Can not create uboot image buffer file.\n");
  219. result = FAIL;
  220. }
  221. else
  222. {
  223. // Write image to flash
  224. DEBUG_INFO("Writing image to image buffer file...\n");
  225. wrd=write(fd, ptr+48, DataLength);
  226. close(fd);
  227. DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
  228. if(wrd != DataLength)
  229. {
  230. result = FAIL;
  231. }
  232. else
  233. {
  234. DEBUG_INFO("Erase /dev/mtd1.\n");
  235. runShellCmd("flash_erase /dev/mtd1 0 2");
  236. DEBUG_INFO("Write /dev/mtd1.\n");
  237. runShellCmd("nandwrite -p /dev/mtd1 /mnt/imgBuffer");
  238. DEBUG_INFO("Erase /dev/mtd3.\n");
  239. runShellCmd("flash_erase /dev/mtd3 0 2");
  240. DEBUG_INFO("Write /dev/mtd3.\n");
  241. runShellCmd("nandwrite -p /dev/mtd3 /mnt/imgBuffer");
  242. system("rm -f /mnt/imgBuffer");
  243. result = PASS;
  244. }
  245. }
  246. break;
  247. case CSU_KERNEL_CONFIGURATION:
  248. fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
  249. if (fd < 0)
  250. {
  251. DEBUG_ERROR("Can not create DTB image buffer file.\n");
  252. result = FAIL;
  253. }
  254. else
  255. {
  256. // Write image to flash
  257. DEBUG_INFO("Writing image to image buffer file...\n");
  258. wrd=write(fd, ptr+48, DataLength);
  259. close(fd);
  260. DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
  261. if(wrd != DataLength)
  262. {
  263. result = FAIL;
  264. }
  265. else
  266. {
  267. DEBUG_INFO("Erase /dev/mtd4.\n");
  268. runShellCmd("flash_erase /dev/mtd4 0 1");
  269. DEBUG_INFO("Write /dev/mtd4.\n");
  270. runShellCmd("nandwrite -p /dev/mtd4 /mnt/imgBuffer");
  271. DEBUG_INFO("Erase /dev/mtd5.\n");
  272. runShellCmd("flash_erase /dev/mtd5 0 1");
  273. DEBUG_INFO("Write /dev/mtd5.\n");
  274. runShellCmd("nandwrite -p /dev/mtd5 /mnt/imgBuffer");
  275. system("rm -f /mnt/imgBuffer");
  276. result = PASS;
  277. }
  278. }
  279. break;
  280. case CSU_KERNEL_IMAGE:
  281. fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
  282. if (fd < 0)
  283. {
  284. DEBUG_ERROR("Can not create kernel image buffer file.\n");
  285. result = FAIL;
  286. }
  287. else
  288. {
  289. // Write image to flash
  290. DEBUG_INFO("Writing image to image buffer file...\n");
  291. wrd=write(fd, ptr+48, DataLength);
  292. close(fd);
  293. DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
  294. if(wrd != DataLength)
  295. {
  296. result = FAIL;
  297. }
  298. else
  299. {
  300. DEBUG_INFO("Erase /dev/mtd6.\n");
  301. runShellCmd("flash_erase /dev/mtd6 0 20");
  302. DEBUG_INFO("Write /dev/mtd6.\n");
  303. runShellCmd("nandwrite -p /dev/mtd6 /mnt/imgBuffer");
  304. DEBUG_INFO("Erase /dev/mtd7.\n");
  305. runShellCmd("flash_erase /dev/mtd7 0 20");
  306. DEBUG_INFO("Write /dev/mtd7.\n");
  307. runShellCmd("nandwrite -p /dev/mtd7 /mnt/imgBuffer");
  308. system("rm -f /mnt/imgBuffer");
  309. result = PASS;
  310. }
  311. }
  312. break;
  313. case CSU_ROOT_FILE_SYSTEM:
  314. fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
  315. if(fd < 0)
  316. {
  317. DEBUG_ERROR("UpdateRootfs NG - can not create rootfs image buffer file\n");
  318. result = FAIL;
  319. }
  320. else
  321. {
  322. DEBUG_INFO("Writing image to image buffer file...\n");
  323. wrd=write(fd, ptr+48, DataLength);
  324. close(fd);
  325. DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
  326. if(wrd!=DataLength)
  327. {
  328. result = FAIL;
  329. }
  330. else
  331. {
  332. DEBUG_INFO("Erase /dev/mtd8.\n");
  333. runShellCmd("flash_erase /dev/mtd8 0 96");
  334. DEBUG_INFO("Write /dev/mtd8.\n");
  335. runShellCmd("nandwrite -p /dev/mtd8 /mnt/imgBuffer");
  336. DEBUG_INFO("Erase /dev/mtd9.\n");
  337. runShellCmd("flash_erase /dev/mtd9 0 96");
  338. DEBUG_INFO("Write /dev/mtd9.\n");
  339. runShellCmd("nandwrite -p /dev/mtd9 /mnt/imgBuffer");
  340. system("rm -f /mnt/imgBuffer");
  341. result = PASS;
  342. }
  343. }
  344. break;
  345. case CSU_USER_CONFIGURATION:
  346. fd = open("/mnt/imgBuffer", O_RDWR | O_CREAT | O_EXCL);
  347. if (fd < 0)
  348. {
  349. DEBUG_ERROR("Can not create configuration image buffer file\n");
  350. result = FAIL;
  351. }
  352. else
  353. {
  354. // Write image to flash
  355. DEBUG_INFO("Writing image to image buffer file...\n");
  356. wrd=write(fd, ptr+48, DataLength);
  357. close(fd);
  358. DEBUG_INFO(">> imgBuffer written length: 0x%x\n", wrd);
  359. if(wrd != DataLength)
  360. {
  361. result = FAIL;
  362. }
  363. else
  364. {
  365. DEBUG_INFO("Erase /dev/mtd10.\n");
  366. runShellCmd("flash_erase /dev/mtd10 0 12");
  367. DEBUG_INFO("Write /dev/mtd10.\n");
  368. runShellCmd("nandwrite -p /dev/mtd10 /mnt/imgBuffer");
  369. DEBUG_INFO("Erase /dev/mtd11.\n");
  370. runShellCmd("flash_erase /dev/mtd11 0 12");
  371. DEBUG_INFO("Write /dev/mtd11.\n");
  372. runShellCmd("nandwrite -p /dev/mtd11 /mnt/imgBuffer");
  373. system("rm -f /mnt/imgBuffer");
  374. result = PASS;
  375. }
  376. }
  377. break;
  378. default:
  379. break;
  380. }
  381. }
  382. else
  383. DEBUG_ERROR("Firmware image CRC32 mismatch.\n");
  384. }
  385. else
  386. DEBUG_ERROR("Firmware image length mismatch.\n");
  387. }
  388. else
  389. DEBUG_ERROR("Firmware image type mismatch.\n");
  390. }
  391. free(ptr);
  392. if(result == PASS)
  393. DEBUG_INFO("Update image success\n");
  394. else
  395. DEBUG_ERROR("Update image fail\n");
  396. return result;
  397. }
  398. //================================================
  399. // UART update function
  400. //================================================
  401. void displayMessage(uint8_t *data, uint16_t len, uint8_t isRX)
  402. {
  403. uint8_t output[8192];
  404. memset(output, 0x00, ARRAY_SIZE(output));
  405. sprintf((char*)output, "%s", (isRX?"RX: ":"TX: "));
  406. for(uint16_t idx = 0;idx<len;idx++)
  407. {
  408. sprintf((char*)output, "%s%02x ", output, data[idx]);
  409. }
  410. DEBUG_INFO("%s\n", output);
  411. }
  412. int uart_tranceive(int fd, unsigned char* cmd, unsigned char* rx, int len, unsigned char needErase)
  413. {
  414. uint16_t rxLen = 0;
  415. tcflush(fd,TCIOFLUSH);
  416. //displayMessage(cmd, 6, NO);
  417. if(write(fd, cmd, len) >= len)
  418. {
  419. rxLen = read(fd, rx, 8);
  420. /*
  421. if(rxLen > 0)
  422. displayMessage(rx, rxLen, YES);
  423. else
  424. DEBUG_INFO("RX: NULL\n");*/
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("Serial command %s response fail.\n", cmd);
  429. }
  430. return rxLen;
  431. }
  432. unsigned char uart_update_start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
  433. {
  434. unsigned char result = FAIL;
  435. 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};
  436. unsigned char rx[8] = {0};
  437. unsigned char chksum = 0x00;
  438. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  439. chksum ^= tx[6+idx];
  440. tx[10] = chksum;
  441. if(uart_tranceive(fd, tx, rx, 11, 0x01) >= 8)
  442. {
  443. chksum = 0x00;
  444. for(int idx=0;idx<((rx[4] | rx[5]<<8)>1?1:(rx[4] | rx[5]<<8));idx++)
  445. {
  446. chksum ^= rx[6+idx];
  447. }
  448. if((chksum == rx[6+((rx[4] | rx[5]<<8)>1?1:(rx[4] | rx[5]<<8))]) &&
  449. (rx[2] == tx[1]) &&
  450. (rx[1] == tx[2]) &&
  451. (rx[3] == tx[3]) &&
  452. (rx[6] == 0x01))
  453. {
  454. result = PASS;
  455. DEBUG_INFO("UART target is ready for upgrade.\n");
  456. }
  457. else
  458. {
  459. DEBUG_INFO("UART target is not ready...\n");
  460. }
  461. }
  462. else
  463. {
  464. DEBUG_ERROR("UART receiving update start ack failed...\n");
  465. }
  466. return result;
  467. }
  468. unsigned char uart_update_abord(unsigned char fd, unsigned char targetAddr)
  469. {
  470. unsigned char result = FAIL;
  471. unsigned char tx[7] = {0xaa, 0x00, targetAddr, UART_CMD_UPDATE_ABORD, 0x00, 0x00, 0x00};
  472. unsigned char rx[8] = {0};
  473. unsigned char chksum = 0x00;
  474. if(uart_tranceive(fd, tx, rx, 7, 0x00) >= 8)
  475. {
  476. for(int idx=0;idx<((rx[4] | rx[5]<<8)>1?1:(rx[4] | rx[5]<<8));idx++)
  477. {
  478. chksum ^= rx[6+idx];
  479. }
  480. if((chksum == rx[6+((rx[4] | rx[5]<<8)>1?1:(rx[4] | rx[5]<<8))]) &&
  481. (rx[2] == tx[1]) &&
  482. (rx[1] == tx[2]) &&
  483. (rx[3] == tx[3]) &&
  484. (rx[6] == 0x01))
  485. {
  486. result = PASS;
  487. DEBUG_INFO("UART target abord update OK.\n");
  488. }
  489. else
  490. {
  491. DEBUG_ERROR("UART target abord update failed.\n");
  492. }
  493. }
  494. else
  495. {
  496. DEBUG_ERROR("UART receiving update abord ack failed...\n");
  497. }
  498. return result;
  499. }
  500. unsigned char uart_update_transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
  501. {
  502. unsigned char result = FAIL;
  503. unsigned char tx[11 + length];
  504. unsigned char rx[8] = {0};
  505. unsigned char chksum = 0x00;
  506. tx[0] = 0xaa;
  507. tx[1] = 0x00;
  508. tx[2] = targetAddr;
  509. tx[3] = UART_CMD_UPDATE_TRANSFER;
  510. tx[4] = (4 + length) & 0xff;
  511. tx[5] = ((4 + length)>>8) & 0xff;
  512. tx[6] = (startAddr>>0) & 0xff;
  513. tx[7] = (startAddr>>8) & 0xff;
  514. tx[8] = (startAddr>>16) & 0xff;
  515. tx[9] = (startAddr>>24) & 0xff;
  516. memcpy(tx+10, data, length);
  517. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  518. chksum ^= tx[6+idx];
  519. tx[sizeof(tx)-1] = chksum;
  520. if(uart_tranceive(fd, tx, rx, (11 + length), 0x00) >= 8)
  521. {
  522. chksum = 0;
  523. for(int idx=0;idx<((rx[4] | rx[5]<<8)>1?1:(rx[4] | rx[5]<<8));idx++)
  524. {
  525. chksum ^= rx[6+idx];
  526. }
  527. if((chksum == rx[6+((rx[4] | rx[5]<<8)>1?1:(rx[4] | rx[5]<<8))]) &&
  528. (rx[2] == tx[1]) &&
  529. (rx[1] == tx[2]) &&
  530. (rx[3] == tx[3]) &&
  531. (rx[6] == 0x01))
  532. {
  533. result = PASS;
  534. }
  535. }
  536. else
  537. {
  538. DEBUG_ERROR("UART receiving update transfer ack failed...\n");
  539. }
  540. return result;
  541. }
  542. unsigned char uart_update_finish(unsigned char fd, unsigned char targetAddr)
  543. {
  544. unsigned char result = FAIL;
  545. unsigned char tx[7] = {0xaa, 0x00, targetAddr, UART_CMD_UPDATE_FINISH, 0x00, 0x00, 0x00};
  546. unsigned char rx[8] = {0};
  547. unsigned char chksum = 0x00;
  548. if(uart_tranceive(fd, tx, rx, 7, 0x00) >= 8)
  549. {
  550. for(int idx=0;idx<((rx[4] | rx[5]<<8)>1?1:(rx[4] | rx[5]<<8));idx++)
  551. {
  552. chksum ^= rx[6+idx];
  553. }
  554. if((chksum == rx[6+((rx[4] | rx[5]<<8)>1?1:(rx[4] | rx[5]<<8))]) &&
  555. (rx[2] == tx[1]) &&
  556. (rx[1] == tx[2]) &&
  557. (rx[3] == tx[3]) &&
  558. (rx[6] == 0x01))
  559. {
  560. result = PASS;
  561. DEBUG_INFO("UART update finish check OK...\n");
  562. }
  563. else
  564. {
  565. DEBUG_ERROR("UART update finish check failed...\n");
  566. }
  567. }
  568. else
  569. {
  570. DEBUG_ERROR("UART receiving update finish ack failed...\n");
  571. }
  572. return result;
  573. }
  574. unsigned char uart_config_timeout(unsigned char uartfd)
  575. {
  576. struct termios tios;
  577. ioctl (uartfd, TCGETS, &tios);
  578. tios.c_cc[VTIME]=(unsigned char)50; // timeout 5 secod
  579. tcflush(uartfd, TCIFLUSH);
  580. ioctl (uartfd, TCSETS, &tios);
  581. return uartfd;
  582. }
  583. int Upgrade_UART(int uartfdOrd,unsigned int Type,unsigned char TargetAddr,char *SourcePath,char *ModelName)
  584. {
  585. int result = FAIL;
  586. char cmdBuf[128];
  587. long int MaxLen=48*1024*1024, ImageLen=0;
  588. unsigned int ImageCRC=0, DataLength=0;
  589. int fd;
  590. int uartfd = uart_config_timeout(uartfdOrd);
  591. fd = open(SourcePath, O_RDONLY);
  592. if(fd < 0)
  593. {
  594. DEBUG_ERROR("UpdateRootfs NG - can not open rootfs\n");
  595. return result;
  596. }
  597. unsigned char *ptr = malloc(MaxLen);
  598. memset(ptr,0xFF,MaxLen);
  599. //get the image length
  600. ImageLen = read(fd,ptr,MaxLen);
  601. close(fd);
  602. //read out the header
  603. int i;
  604. int isModelNameOK = PASS;
  605. for(i=0;i<16;i++)
  606. {
  607. if(ModelName[i] != ptr[i])
  608. {
  609. isModelNameOK = FAIL;
  610. }
  611. }
  612. if(isModelNameOK == FAIL)
  613. {
  614. DEBUG_ERROR("Model name mismatch...\n");
  615. }
  616. else
  617. {
  618. // check if the firmware type is correct
  619. if(Type == (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19])))
  620. {
  621. if((ImageLen-48) == (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23])))
  622. {
  623. DataLength = ImageLen-48;
  624. // get CRC in the header
  625. ImageCRC = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
  626. // calculate the image CRC
  627. DEBUG_INFO("CRC32 in image: 0x%08X\n",ImageCRC);
  628. DEBUG_INFO("CRC32 by calculation: 0x%08X\n",crc32(ptr,ImageLen));
  629. if(crc32(ptr,ImageLen) == ImageCRC)
  630. {
  631. if(uart_update_start(uartfd, TargetAddr, crc32(ptr+48,DataLength))==PASS)
  632. {
  633. int CNT_Fail = 0;
  634. int CNT_Trans = 0;
  635. do
  636. {
  637. if(uart_update_transfer(uartfd, TargetAddr, CNT_Trans*1024, ptr+48+(CNT_Trans*1024), 1024)==PASS)
  638. {
  639. CNT_Fail = 0;
  640. CNT_Trans++;
  641. DEBUG_INFO("Upgrade progress:%.2f%%\n", ((float)(CNT_Trans*1024))/(DataLength)*100);
  642. }
  643. else
  644. {
  645. DEBUG_WARN("Data transfer fail, retry %d \n", ++CNT_Fail);
  646. sleep(1);
  647. }
  648. }while(DataLength-(CNT_Trans*1024)>0 && CNT_Fail<10);
  649. if(CNT_Fail>=10)
  650. {
  651. uart_update_abord(uartfd, TargetAddr);
  652. DEBUG_ERROR("UART upgrade retry > limits, aboard upgrade.\n");
  653. printf("UART upgrade retry > limits, aboard upgrade.\n");
  654. }
  655. else if(uart_update_finish(uartfd, TargetAddr)==PASS)
  656. {
  657. result = PASS;
  658. printf("UART upgrade success.\n");
  659. }
  660. }
  661. else
  662. DEBUG_ERROR("UART upgrade request failed.\n");
  663. }
  664. else
  665. DEBUG_ERROR("Firmware image CRC32 mismatch.\n");
  666. }
  667. else
  668. DEBUG_ERROR("Firmware image length mismatch.\n");
  669. }
  670. else
  671. DEBUG_ERROR("Firmware image type mismatch.\n");
  672. }
  673. free(ptr);
  674. sprintf(cmdBuf, "rm -f %s", SourcePath);
  675. system(cmdBuf);
  676. return result;
  677. }
  678. //================================================
  679. // CANBUS update function
  680. //================================================
  681. unsigned long getTimeoutValue(struct timeval _sour_time)
  682. {
  683. struct timeval _end_time;
  684. gettimeofday(&_end_time, NULL);
  685. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  686. }
  687. int CAN_Download_REQ(int canfd,unsigned int Slave_Addr, unsigned int imageSize)
  688. {
  689. struct can_frame frame;
  690. frame.can_id = (0x00000E00 + Slave_Addr) | 0x80000000; //extended frame
  691. frame.can_dlc = 0x07;
  692. frame.data[0] = 0x04; //0x01:Configuration file, 0x02:Bootloader of primary side MCU, 0x03:Firmware (main code) of primary side MCU, 0x04:Bootloader of secondary side MCU, 0x05:Firmware (main code) of secondary side MCU
  693. frame.data[1] = (imageSize>>0)&0xff; //Total 384 KBytes
  694. frame.data[2] = (imageSize>>8)&0xff; //Total 384 KBytes
  695. frame.data[3] = (imageSize>>16)&0xff; //Total 384 KBytes
  696. frame.data[4] = (imageSize>>24)&0xff; //Total 384 KBytes
  697. frame.data[5] = 0x10; //16 blocks
  698. frame.data[6] = 0x18; //24 KBytes
  699. DEBUG_INFO( "File size = %x, %d \n", imageSize, imageSize);
  700. write(canfd, &frame, sizeof(struct can_frame));
  701. if (canfd > 0)
  702. {
  703. struct timeval timer;
  704. gettimeofday(&timer, NULL);
  705. while (getTimeoutValue(timer) < 5000000)
  706. {
  707. struct can_frame frame;
  708. int len;
  709. len = read(canfd, &frame, sizeof(struct can_frame));
  710. if (len >= 0)
  711. {
  712. DEBUG_INFO( "*****************************CAN_Download_REQ Get***************************** \n");
  713. DEBUG_INFO("data = %x \n", frame.can_id & CAN_EFF_MASK);
  714. if (((int)(frame.can_id & CAN_EFF_MASK & 0xFFFFFF00) == 0x08000E00) && frame.data[0] == 1)
  715. {
  716. DEBUG_INFO("PASS \n");
  717. return PASS;
  718. }
  719. }
  720. }
  721. }
  722. return FAIL;
  723. }
  724. int CAN_Start_BLK_Trans(int canfd,unsigned int Slave_Addr,unsigned int Block_No,unsigned int Block_Checksum)
  725. {
  726. struct can_frame frame;
  727. frame.can_id = (0x00000F00 + Slave_Addr) | 0x80000000; //extended frame
  728. frame.can_dlc = 0x02;
  729. frame.data[0] = Block_No;
  730. frame.data[1] = Block_Checksum;
  731. DEBUG_INFO("Block_No = %x, Block_Checksum = %x \n", Block_No, Block_Checksum);
  732. write(canfd, &frame, sizeof(struct can_frame));
  733. usleep(100000);
  734. if (canfd > 0)
  735. {
  736. struct timeval timer;
  737. gettimeofday(&timer, NULL);
  738. while (getTimeoutValue(timer) < 1000000)
  739. {
  740. struct can_frame frame;
  741. int len;
  742. len = read(canfd, &frame, sizeof(struct can_frame));
  743. if(len >= 0)
  744. {
  745. DEBUG_INFO("*****************************CAN_Start_BLK_Trans Get***************************** \n");
  746. DEBUG_INFO("data = %x \n", frame.can_id & CAN_EFF_MASK); // extended frame CAN_EFF_MASK
  747. if(((int)(frame.can_id & CAN_EFF_MASK & 0xFFFFFF00) == 0x08000F00) &&frame.data[0] == 1)
  748. {
  749. DEBUG_INFO("CAN_Start_BLK_Trans PASS \n");
  750. return PASS;
  751. }
  752. }
  753. }
  754. }
  755. return FAIL;
  756. }
  757. void CAN_Data_Trans(int canfd,unsigned int Slave_Addr,long Data_num,unsigned char Data[])
  758. {
  759. struct can_frame frame;
  760. frame.can_id = (0x00001000 + Slave_Addr) | 0x80000000; //extended frame
  761. frame.can_dlc = 0x08;
  762. frame.data[0] = Data[Data_num+0];
  763. frame.data[1] = Data[Data_num+1];
  764. frame.data[2] = Data[Data_num+2];
  765. frame.data[3] = Data[Data_num+3];
  766. frame.data[4] = Data[Data_num+4];
  767. frame.data[5] = Data[Data_num+5];
  768. frame.data[6] = Data[Data_num+6];
  769. frame.data[7] = Data[Data_num+7];
  770. // DEBUG_INFO("%02x %02x %02x %02x %02x %02x %02x %02x \n", frame.data[0], frame.data[1], frame.data[2], frame.data[3],
  771. // frame.data[4], frame.data[5], frame.data[6], frame.data[7]);
  772. write(canfd, &frame, sizeof(struct can_frame));
  773. usleep(2000);
  774. }
  775. int CAN_Download_FIN(int canfd,unsigned int Slave_Addr)
  776. {
  777. struct can_frame frame;
  778. frame.can_id = (0x00001100 + Slave_Addr) | 0x80000000; //extended frame
  779. frame.can_dlc = 0x00;
  780. write(canfd, &frame, sizeof(struct can_frame));
  781. usleep(10000);
  782. if (canfd > 0)
  783. {
  784. struct timeval timer;
  785. gettimeofday(&timer, NULL);
  786. while (getTimeoutValue(timer) < 1000000)
  787. {
  788. struct can_frame frame;
  789. int len;
  790. len = read(canfd, &frame, sizeof(struct can_frame));
  791. if(len >= 0)
  792. {
  793. DEBUG_INFO("data = %x \n", frame.can_id & CAN_EFF_MASK); // extended frame
  794. if(((int)(frame.can_id & CAN_EFF_MASK & 0xFFFFFF00) == 0x08001100) && frame.data[0] == 1)
  795. {
  796. DEBUG_INFO("CAN_Download_FIN PASS \n");
  797. return PASS;
  798. }
  799. }
  800. }
  801. }
  802. return FAIL;
  803. }
  804. int Checksum_Cal(unsigned int StartAdress,unsigned int length, unsigned char Data[])
  805. {
  806. unsigned char checksum = 0x00;
  807. for(unsigned int i = 0; i < length; i++)
  808. {
  809. //DEBUG_INFO("value = %x \n", Data[StartAdress + i]);
  810. checksum ^= Data[StartAdress + i];
  811. //DEBUG_INFO("checksum = %x \n", checksum);
  812. }
  813. return checksum;
  814. }
  815. int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *SourcePath,char *ModelName)
  816. {
  817. int result = FAIL;
  818. char cmdBuf[128];
  819. long int MaxLen=48*1024*1024, ImageLen=0;
  820. unsigned int ImageCRC=0, DataLength=0;
  821. int fd;
  822. fd = open(SourcePath, O_RDONLY);
  823. if(fd < 0)
  824. {
  825. DEBUG_ERROR("UpdateRootfs NG - can not open rootfs\n");
  826. return result;
  827. }
  828. unsigned char *ptr = malloc(MaxLen);
  829. memset(ptr,0xFF,MaxLen);
  830. //get the image length
  831. ImageLen = read(fd,ptr,MaxLen);
  832. close(fd);
  833. //read out the header
  834. int i;
  835. int isModelNameOK = PASS;
  836. for(i=0;i<16;i++) {
  837. if(ModelName[i] != ptr[i]){
  838. isModelNameOK = FAIL;
  839. }
  840. }
  841. if(isModelNameOK == FAIL)
  842. {
  843. DEBUG_ERROR("Model name mismatch...\n");
  844. return result;
  845. }
  846. else
  847. {
  848. // check if the firmware type is correct
  849. if(Type == (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19])))
  850. {
  851. if((ImageLen-48) == (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23])))
  852. {
  853. DataLength = ImageLen-48;
  854. // get CRC in the header
  855. ImageCRC = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
  856. // calculate the image CRC
  857. DEBUG_INFO("CRC32 in image: 0x%08X\n",ImageCRC);
  858. DEBUG_INFO("CRC32 by calculation: 0x%08X\n",crc32(ptr,ImageLen));
  859. if(crc32(ptr,ImageLen) == ImageCRC)
  860. {
  861. unsigned int Checksum[16];
  862. for(int i=0;i<16;i++)
  863. {
  864. Checksum[i] = Checksum_Cal(i * 24576, 24576, ptr + 48);
  865. }
  866. if(CAN_Download_REQ(canfd, TargetAddr, DataLength) == PASS)
  867. {
  868. for(int block = 1; block <= 16; block++)
  869. {
  870. if(CAN_Start_BLK_Trans(canfd, TargetAddr, block, Checksum[block - 1]) == PASS)
  871. {
  872. for(int times = 0; times < 3072; times++)
  873. {
  874. CAN_Data_Trans(canfd, TargetAddr, ((block - 1) * 24576 + times * 8), ptr + 48);
  875. }
  876. DEBUG_INFO(" \n\n");
  877. }
  878. else
  879. {
  880. free(ptr);
  881. return result;
  882. }
  883. }
  884. if (CAN_Download_FIN(canfd, TargetAddr) == PASS)
  885. result = PASS;
  886. }
  887. else
  888. DEBUG_ERROR("CANBUS upgrade request failed.\n");
  889. }
  890. else
  891. DEBUG_ERROR("Firmware image CRC32 mismatch.\n");
  892. }
  893. else
  894. DEBUG_ERROR("Firmware image length mismatch.\n");
  895. }
  896. else
  897. DEBUG_ERROR("Firmware image type mismatch.\n");
  898. }
  899. free(ptr);
  900. sprintf(cmdBuf, "rm -f %s", SourcePath);
  901. system(cmdBuf);
  902. return result;
  903. }
  904. //================================================
  905. // CCS update function
  906. //================================================
  907. int Check_CCS_image_header(unsigned int Type,char *SourcePath,char *ModelName)
  908. {
  909. long int MaxLen=48*1024*1024, ImageLen=0;
  910. unsigned int ImageCRC=0;
  911. int fd;
  912. // space max size set
  913. fd = open(SourcePath, O_RDONLY);
  914. if(fd < 0)
  915. {
  916. DEBUG_ERROR("Update CCS NG - can not open upgrade image\n");
  917. return FAIL;
  918. }
  919. switch(Type)
  920. {
  921. case CCS_BOARD_BOOTLOADER:
  922. MaxLen = 1*1024*1024;
  923. DEBUG_INFO("Prepare to upgrade CCS BOOTLOADER\n");
  924. break;
  925. case CCS_BOARD_KERNEL_CONFIGURATION:
  926. MaxLen = 0.5*1024*1024;
  927. DEBUG_INFO("Prepare to upgrade CCS KERNEL CONFIGURATION\n");
  928. break;
  929. case CCS_BOARD_KERNEL_IMAGE:
  930. MaxLen = 10*1024*1024;
  931. DEBUG_INFO("Prepare to upgrade CCS KERNEL\n");
  932. break;
  933. case CCS_BOARD_FILE_SYSTEM:
  934. MaxLen = 48*1024*1024;
  935. DEBUG_INFO("Prepare to upgrade CCS FILE SYSTEM\n");
  936. break;
  937. default:
  938. DEBUG_ERROR("Wrong image type for CCS upgrade\n");
  939. return FAIL;
  940. break;
  941. }
  942. unsigned char *ptr = malloc(MaxLen);
  943. memset(ptr,0xFF,MaxLen);
  944. //get the image length
  945. ImageLen = read(fd,ptr,MaxLen);
  946. close(fd);
  947. //read out the header
  948. int i;
  949. for(i=0;i<16;i++)
  950. {
  951. if(ModelName[i] != ptr[i])
  952. {
  953. DEBUG_ERROR("Model name mismatch.\n");
  954. return FAIL;
  955. }
  956. }
  957. // check if the firmware type is correct
  958. if(Type == (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19])))
  959. {
  960. if((ImageLen-48) == (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23])))
  961. {
  962. // get CRC in the header
  963. ImageCRC = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
  964. // calculate the image CRC
  965. DEBUG_INFO("CRC32 in CCS image: 0x%08X\n",ImageCRC);
  966. DEBUG_INFO("CRC32 by calculation: 0x%08X\n",crc32(ptr,ImageLen));
  967. if(crc32(ptr,ImageLen) == ImageCRC)
  968. {
  969. return PASS;
  970. }
  971. else
  972. {
  973. DEBUG_ERROR("Firmware image CRC32 mismatch.\n");
  974. return FAIL;
  975. }
  976. }
  977. else
  978. {
  979. DEBUG_ERROR("Firmware image length mismatch.\n");
  980. return FAIL;
  981. }
  982. }
  983. else
  984. {
  985. DEBUG_ERROR("Firmware image type mismatch.\n");
  986. return FAIL;
  987. }
  988. }
  989. int Put_CCS_image(char *SourcePath, unsigned char TargetAddr)
  990. {
  991. unsigned char ftpcmdbuf[256];
  992. unsigned char CCSIpAddress[16];
  993. //If ID of target EV board is 1, the IP address will be 192.168.0.21,
  994. //if ID of target EV board is 2, the IP address will be 192.168.0.22.
  995. sprintf((char*)CCSIpAddress,"192.168.0.2%d", TargetAddr);
  996. //Using ftpput command to transfer CCS upgrade image,
  997. //User name : root
  998. //User password : y42j/4cj84
  999. //Destination : /root/ccs.image
  1000. sprintf((char*)ftpcmdbuf,"ftpput -u root -p y42j/4cj84 %s /root/ccs.image %s",
  1001. CCSIpAddress, SourcePath);
  1002. if(system((char*)ftpcmdbuf) != 0)
  1003. {
  1004. DEBUG_ERROR("Update CCS NG - FTP put CCS upgrade image to CCS board %d fail\n", TargetAddr);
  1005. return FAIL;
  1006. }
  1007. else
  1008. {
  1009. DEBUG_INFO("FTP put %s to CCS board %d finish\n", SourcePath, TargetAddr);
  1010. return PASS;
  1011. }
  1012. }
  1013. int Send_CCS_download_finish(int canfd,unsigned int Slave_Addr)
  1014. {
  1015. if (canfd > 0)
  1016. {
  1017. struct can_frame frame;
  1018. frame.can_id = (CANBUS_MESSAGE_ID_UPGRADE_FINISH + Slave_Addr) | 0x80000000; //extended frame
  1019. frame.can_dlc = 0x00;
  1020. write(canfd, &frame, sizeof(struct can_frame));
  1021. usleep(10000);
  1022. struct timeval timer;
  1023. gettimeofday(&timer, NULL);
  1024. unsigned long ack_timeout = 30 * 60 * 1000 * 1000; //30 minutes
  1025. while (getTimeoutValue(timer) < ack_timeout)
  1026. {
  1027. struct can_frame frame;
  1028. int len;
  1029. len = read(canfd, &frame, sizeof(struct can_frame));
  1030. if(len >= 0)
  1031. {
  1032. if(((int)(frame.can_id & CAN_EFF_MASK) == (CANBUS_MESSAGE_ID_UPGRADE_FINISH | Slave_Addr | 0x08000000)) && frame.data[0] == 1)
  1033. {
  1034. return PASS;
  1035. }
  1036. }
  1037. }
  1038. DEBUG_ERROR("Wait for download finish ack from CCS %d timeout\n", Slave_Addr);
  1039. return FAIL;
  1040. }
  1041. else
  1042. {
  1043. DEBUG_ERROR("Send CCS download finish command fail, CAN fd is null\n");
  1044. return FAIL;
  1045. }
  1046. }
  1047. int Upgrade_CCS(int canfd,unsigned int Type,unsigned char TargetAddr,char *SourcePath,char *ModelName)
  1048. {
  1049. char cmdBuf[128];
  1050. if(Check_CCS_image_header(Type, SourcePath, ModelName) == FAIL)
  1051. {
  1052. return FAIL;
  1053. }
  1054. if(Put_CCS_image(SourcePath, TargetAddr) == FAIL)
  1055. {
  1056. return FAIL;
  1057. }
  1058. if(Send_CCS_download_finish(canfd, TargetAddr) == FAIL)
  1059. {
  1060. return FAIL;
  1061. }
  1062. DEBUG_INFO("Upgrade CCS board %d complete.\n", TargetAddr);
  1063. sprintf(cmdBuf, "rm -f %s", SourcePath);
  1064. system(cmdBuf);
  1065. return PASS;
  1066. }