FWUpdate.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. /*===========================================================================
  2. Combined Charging System (CCS): SECC
  3. FWUpdate.c
  4. initiated by Vern, Joseph
  5. (since 2019/07/19)
  6. =============================================================================*/
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10. #include <linux/termios.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <time.h>
  14. #include <stdlib.h>
  15. #include <sys/ipc.h>
  16. #include <sys/shm.h>
  17. #include <sys/mman.h>
  18. #include <linux/sockios.h>
  19. #include <linux/socket.h>
  20. #include <sys/socket.h>
  21. #include <netinet/in.h>
  22. #include <sys/time.h>
  23. #include <sys/timeb.h>
  24. #include <math.h>//for pow
  25. #include "define.h"
  26. #include "FWUpdate.h"
  27. #include <unistd.h>
  28. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  29. struct StatusCodeData *ShmStatusCodeData;
  30. struct CcsData *ShmCcsData;
  31. struct InternalComm *ShmInternalComm;
  32. struct InternalCommAC *ShmInternalCommAC;
  33. unsigned char buf_log_fwupdate[SIZE_OF_LOG_BUFFER];
  34. /*===========================================================================
  35. FUNCTION: Check_V2G_Flow_Status
  36. DESCRIPTION:
  37. PRE-CONDITION:
  38. INPUT:
  39. OUTPUT:
  40. GLOBAL VARIABLES:
  41. =============================================================================*/
  42. unsigned char Check_V2G_Flow_Status()
  43. {
  44. unsigned char result = 0;
  45. switch (ShmCcsData->CommProtocol)
  46. {
  47. case V2GT_MSG_PROTOCOL_DIN70121: //0
  48. {
  49. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  50. break;
  51. }
  52. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  53. {
  54. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  55. break;
  56. }
  57. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  58. {
  59. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  60. break;
  61. }
  62. default:
  63. break;
  64. }
  65. return result;
  66. }
  67. /*===========================================================================
  68. FUNCTION: StoreLogMsg
  69. DESCRIPTION:
  70. PRE-CONDITION:
  71. INPUT:
  72. OUTPUT:
  73. GLOBAL VARIABLES:
  74. =============================================================================*/
  75. #if SAVE_SYS_LOG_MSG_FWUPDATE_SWITCH == ENABLE
  76. int StoreLogMsg(unsigned char *DataString)
  77. {
  78. static unsigned char Buf[1024];
  79. static time_t CurrentTime;
  80. static struct tm *tm;
  81. static struct timeval tv;
  82. memset(Buf, 0, sizeof(Buf));
  83. CurrentTime = time(NULL);
  84. tm = localtime(&CurrentTime);
  85. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  86. sprintf(Buf, "echo \"[%04d%02d%02d: %02d:%02d:%02d.%06d][FWUpdate][%d][%02d]%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  87. tm->tm_year + 1900,
  88. tm->tm_mon + 1,
  89. tm->tm_mday,
  90. tm->tm_hour,
  91. tm->tm_min,
  92. tm->tm_sec,
  93. tv.tv_usec,
  94. EVCOMM_SYS_INFO.CpState,
  95. Check_V2G_Flow_Status(),
  96. DataString,
  97. tm->tm_year + 1900,
  98. tm->tm_mon + 1);
  99. system(Buf);
  100. DEBUG_PRINTF_FWUPDATE_SYSTEM_LOG("[%02d:%02d:%02d.%06d][FWUpdate][%d][%02d]%s \n",
  101. tm->tm_hour,
  102. tm->tm_min,
  103. tm->tm_sec,
  104. tv.tv_usec,
  105. EVCOMM_SYS_INFO.CpState,
  106. Check_V2G_Flow_Status(),
  107. DataString);
  108. //Reset the buf_log_fwupdate Buffer, i.e. DataString
  109. memset(buf_log_fwupdate, 0, SIZE_OF_LOG_BUFFER);
  110. }
  111. #endif
  112. /*===========================================================================
  113. FUNCTION: fsize
  114. DESCRIPTION:
  115. PRE-CONDITION:
  116. INPUT:
  117. OUTPUT:
  118. GLOBAL VARIABLES:
  119. =============================================================================*/
  120. unsigned long fsize(char* filename)
  121. {
  122. SAVE_SYS_LOG_MSG_FWUPDATE("[fsize]image size: caculating...");
  123. unsigned long length = 0;
  124. FILE *file;
  125. file = fopen(filename, "rb");
  126. if (file == NULL)
  127. {
  128. SAVE_SYS_LOG_MSG_FWUPDATE("[fsize]fopen: fail");
  129. return 0;
  130. }
  131. else
  132. {
  133. SAVE_SYS_LOG_MSG_FWUPDATE("[fsize]fopen: OK");
  134. fseek(file, 0, SEEK_END);
  135. length = (unsigned long) ftell(file);
  136. }
  137. fclose(file);
  138. sprintf(buf_log_fwupdate, "[fsize]image size: %ld bytes", length);
  139. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  140. return length;
  141. }
  142. /*===========================================================================
  143. FUNCTION: crc32
  144. DESCRIPTION:
  145. PRE-CONDITION:
  146. INPUT:
  147. OUTPUT:
  148. GLOBAL VARIABLES:
  149. =============================================================================*/
  150. uint32_t crc32(uint8_t *data, unsigned int length)
  151. {
  152. SAVE_SYS_LOG_MSG_FWUPDATE("[crc32]ongoing...");
  153. uint8_t i;
  154. uint32_t cnt = 0;
  155. uint32_t crc = 0xffffffff; // Initial value
  156. while(length--)
  157. {
  158. if(cnt > 33 && cnt < 48)
  159. {
  160. data++;
  161. }
  162. else
  163. {
  164. crc ^= *data++; // crc ^= *data; data++;
  165. for (i = 0; i < 8; ++i)
  166. {
  167. if (crc & 1)
  168. crc = (crc >> 1) ^ 0xEDB88320;// 0xEDB88320= reverse 0x04C11DB7
  169. else
  170. crc = (crc >> 1);
  171. }
  172. }
  173. cnt++;
  174. }
  175. return ~crc;
  176. }
  177. /*===========================================================================
  178. FUNCTION: ShareMemory_Init
  179. DESCRIPTION
  180. Initialize all share memories.
  181. PRE-CONDITION:
  182. INPUT:
  183. OUTPUT:
  184. GLOBAL VARIABLES:
  185. =============================================================================*/
  186. int ShareMemory_Init()
  187. {
  188. int MeterSMId;
  189. //[1/5] create ShmSysConfigAndInfo
  190. if((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  191. {
  192. SAVE_SYS_LOG_MSG_FWUPDATE("ShareMemory_Init:shmget ShmSysConfigAndInfo NG");
  193. return 0;
  194. }
  195. else if((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *)-1)
  196. {
  197. SAVE_SYS_LOG_MSG_FWUPDATE("ShareMemory_Init:shmat ShmSysConfigAndInfo NG");
  198. return 0;
  199. }
  200. //[2/5] create ShmStatusCodeData
  201. if((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  202. {
  203. SAVE_SYS_LOG_MSG_FWUPDATE("ShareMemory_Init:shmget ShmStatusCodeData NG");
  204. return 0;
  205. }
  206. else if((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *)-1)
  207. {
  208. SAVE_SYS_LOG_MSG_FWUPDATE("ShareMemory_Init:shmat ShmStatusCodeData NG");
  209. return 0;
  210. }
  211. //[3/5] create ShmCcsData
  212. if((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), 0777)) < 0)
  213. {
  214. SAVE_SYS_LOG_MSG_FWUPDATE("ShareMemory_Init:shmget ShmCcsData NG");
  215. return 0;
  216. }
  217. else if((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *)-1)
  218. {
  219. SAVE_SYS_LOG_MSG_FWUPDATE("ShareMemory_Init:shmat ShmCcsData NG");
  220. return 0;
  221. }
  222. //[4/5] create ShmInternalComm
  223. if((MeterSMId = shmget(ShmInternalCommKey, sizeof(struct InternalComm), IPC_CREAT | 0777)) < 0)
  224. {
  225. SAVE_SYS_LOG_MSG_FWUPDATE("ShareMemory_Init:shmget ShmInternalComm NG");
  226. return 0;
  227. }
  228. else if((ShmInternalComm = shmat(MeterSMId, NULL, 0)) == (void *)-1)
  229. {
  230. SAVE_SYS_LOG_MSG_FWUPDATE("ShareMemory_Init:shmat ShmInternalComm NG");
  231. return 0;
  232. }
  233. //[5/5] create ShmInternalCommAC
  234. if((MeterSMId = shmget(ShmInternalCommACKey, sizeof(struct InternalCommAC), IPC_CREAT | 0777)) < 0)
  235. {
  236. SAVE_SYS_LOG_MSG_FWUPDATE("ShareMemory_Init:shmget ShmInternalCommAC NG");
  237. return 0;
  238. }
  239. else if((ShmInternalCommAC = shmat(MeterSMId, NULL, 0)) == (void *)-1)
  240. {
  241. SAVE_SYS_LOG_MSG_FWUPDATE("ShareMemory_Init:shmat ShmInternalCommAC NG");
  242. return 0;
  243. }
  244. return 1;
  245. }
  246. /*===========================================================================
  247. FUNCTION: Update_MLO
  248. DESCRIPTION:
  249. PRE-CONDITION:
  250. INPUT:
  251. OUTPUT:
  252. GLOBAL VARIABLES:
  253. =============================================================================*/
  254. unsigned char Update_MLO()
  255. {
  256. SAVE_SYS_LOG_MSG_FWUPDATE("-------- [MLO]start --------");
  257. unsigned char result = PASS;
  258. long int MaxLen = 48*1024*1024;
  259. unsigned long file_length = 0;
  260. unsigned char *ptr = malloc(MaxLen);
  261. if(ptr == NULL)
  262. {
  263. return FAIL;
  264. }
  265. memset(ptr, 0, MaxLen);
  266. file_length = fsize("/root/MLO");
  267. int fd = 0;
  268. int wrd = 0;
  269. FILE *file;
  270. fd = open("/dev/mtdblock0", O_RDWR);
  271. file = fopen("/root/MLO", "rb");
  272. if (fd < 0)
  273. {
  274. SAVE_SYS_LOG_MSG_FWUPDATE("[MLO]Can not open mtdblock0\n");
  275. free(ptr);
  276. return FAIL;
  277. }
  278. else if (file == NULL)
  279. {
  280. SAVE_SYS_LOG_MSG_FWUPDATE("[MLO]Can not open or find the downloaded image file\n");
  281. free(ptr);
  282. return FAIL;
  283. }
  284. else
  285. {
  286. //[VITAL] Closing unneccesary task to supoort rapid CAN data receving..
  287. SAVE_SYS_LOG_MSG_FWUPDATE("[MLO] closing SeccComm...");
  288. system("killall SeccComm");
  289. // Write image to flash
  290. SAVE_SYS_LOG_MSG_FWUPDATE("[MLO]Writing image to mtdblock0...");
  291. fread(ptr, sizeof(unsigned char), file_length, file);
  292. wrd = write(fd, ptr, file_length);
  293. close(fd);
  294. fclose(file);
  295. sprintf(buf_log_fwupdate, "[MLO]mtdblock0 - written length: %d bytes\n", wrd);
  296. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  297. if(wrd != file_length)
  298. {
  299. free(ptr);
  300. return FAIL;
  301. }
  302. }
  303. free(ptr);
  304. return result;
  305. }
  306. /*===========================================================================
  307. FUNCTION: IMAGE_TYPE_BOOTLOADER_UBOOT
  308. DESCRIPTION:
  309. PRE-CONDITION:
  310. INPUT:
  311. OUTPUT:
  312. GLOBAL VARIABLES:
  313. =============================================================================*/
  314. unsigned char Update_uboot()
  315. {
  316. SAVE_SYS_LOG_MSG_FWUPDATE("-------- [uboot]start --------");
  317. unsigned char result = PASS;
  318. long int MaxLen = 48*1024*1024;
  319. unsigned long file_length = 0;
  320. unsigned char *ptr = malloc(MaxLen);
  321. if(ptr == NULL)
  322. {
  323. return FAIL;
  324. }
  325. memset(ptr, 0, MaxLen);
  326. file_length = fsize("/root/u-boot.img");
  327. int fd = 0;
  328. int wrd = 0;
  329. FILE *file;
  330. fd = open("/dev/mtdblock1", O_RDWR);
  331. file = fopen("/root/u-boot.img", "rb");
  332. if (fd < 0)
  333. {
  334. SAVE_SYS_LOG_MSG_FWUPDATE("[uboot]Can not open mtdblock1\n");
  335. free(ptr);
  336. return FAIL;
  337. }
  338. else if (file == NULL)
  339. {
  340. SAVE_SYS_LOG_MSG_FWUPDATE("[uboot]Can not open the downloaded image file\n");
  341. free(ptr);
  342. return FAIL;
  343. }
  344. else
  345. {
  346. //[VITAL] Closing unneccesary task to supoort rapid CAN data receving..
  347. SAVE_SYS_LOG_MSG_FWUPDATE("[uboot] closing SeccComm...");
  348. system("killall SeccComm");
  349. // Write image to flash
  350. SAVE_SYS_LOG_MSG_FWUPDATE("[uboot]Writing image to mtdblock1...");
  351. fread(ptr, sizeof(unsigned char), file_length, file);
  352. wrd = write(fd, ptr, file_length);
  353. close(fd);
  354. fclose(file);
  355. sprintf(buf_log_fwupdate, "[uboot]mtdblock1 - written length: %d bytes\n", wrd);
  356. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  357. if(wrd != file_length)
  358. {
  359. free(ptr);
  360. return FAIL;
  361. }
  362. else
  363. {
  364. // Open flash target mtdblock
  365. fd = open("/dev/mtdblock3", O_RDWR);
  366. if (fd < 0)
  367. {
  368. SAVE_SYS_LOG_MSG_FWUPDATE("[uboot]Can not open mtdblock3\n");
  369. free(ptr);
  370. return FAIL;
  371. }
  372. else if (file == NULL)
  373. {
  374. SAVE_SYS_LOG_MSG_FWUPDATE("[uboot]Can not open the downloaded image file\n");
  375. free(ptr);
  376. return FAIL;
  377. }
  378. else
  379. {
  380. // Write image to flash
  381. SAVE_SYS_LOG_MSG_FWUPDATE("[uboot]Writing image to mtdblock3...");
  382. wrd = write(fd, ptr, file_length);
  383. close(fd);
  384. sprintf(buf_log_fwupdate, "[uboot]mtdblock3 - written length: %d bytes\n", wrd);
  385. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  386. if(wrd != file_length)
  387. {
  388. free(ptr);
  389. return FAIL;
  390. }
  391. }
  392. }
  393. }
  394. return result;
  395. }
  396. /*===========================================================================
  397. FUNCTION: Update_DTB
  398. DESCRIPTION:
  399. PRE-CONDITION:
  400. INPUT:
  401. OUTPUT:
  402. GLOBAL VARIABLES:
  403. =============================================================================*/
  404. unsigned char Update_DTB()
  405. {
  406. SAVE_SYS_LOG_MSG_FWUPDATE("-------- [DTB]start --------");
  407. unsigned char result = PASS;
  408. long int MaxLen = 48*1024*1024;
  409. unsigned long file_length = 0;
  410. unsigned char *ptr = malloc(MaxLen);
  411. if(ptr == NULL)
  412. {
  413. return FAIL;
  414. }
  415. memset(ptr, 0, MaxLen);
  416. file_length = fsize("/root/am335x-evm.dtb");
  417. int fd = 0;
  418. int wrd = 0;
  419. FILE *file;
  420. fd = open("/dev/mtdblock4", O_RDWR);
  421. file = fopen("/root/am335x-evm.dtb", "rb");
  422. if (fd < 0)
  423. {
  424. SAVE_SYS_LOG_MSG_FWUPDATE("[DTB]Can not open mtdblock4\n");
  425. free(ptr);
  426. return FAIL;
  427. }
  428. else if (file == NULL)
  429. {
  430. SAVE_SYS_LOG_MSG_FWUPDATE("[DTB]Can not open the downloaded image file\n");
  431. free(ptr);
  432. return FAIL;
  433. }
  434. else
  435. {
  436. //[VITAL] Closing unneccesary task to supoort rapid CAN data receving..
  437. SAVE_SYS_LOG_MSG_FWUPDATE("[DTB] closing SeccComm...");
  438. system("killall SeccComm");
  439. // Write image to flash
  440. SAVE_SYS_LOG_MSG_FWUPDATE("[DTB]Writing image to mtdblock4...");
  441. fread(ptr, sizeof(unsigned char), file_length, file);
  442. wrd = write(fd, ptr, file_length);
  443. close(fd);
  444. fclose(file);
  445. sprintf(buf_log_fwupdate, "[DTB]mtdblock4 - written length: %d bytes\n", wrd);
  446. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  447. if(wrd != file_length)
  448. {
  449. free(ptr);
  450. return FAIL;
  451. }
  452. else
  453. {
  454. // Open flash target mtdblock
  455. fd = open("/dev/mtdblock5", O_RDWR);
  456. if (fd < 0)
  457. {
  458. SAVE_SYS_LOG_MSG_FWUPDATE("[DTB]Can not open mtdblock5");
  459. free(ptr);
  460. return FAIL;
  461. }
  462. else
  463. {
  464. // Write image to flash
  465. SAVE_SYS_LOG_MSG_FWUPDATE("[DTB]Writing image to mtdblock5...");
  466. wrd=write(fd, ptr, file_length);
  467. close(fd);
  468. sprintf(buf_log_fwupdate, "[DTB]mtdblock5 - written length: %d bytes\n", wrd);
  469. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  470. if(wrd != file_length)
  471. {
  472. free(ptr);
  473. return FAIL;
  474. }
  475. }
  476. }
  477. }
  478. return result;
  479. }
  480. /*===========================================================================
  481. FUNCTION: Update_zImage
  482. DESCRIPTION:
  483. PRE-CONDITION:
  484. INPUT:
  485. OUTPUT:
  486. GLOBAL VARIABLES:
  487. =============================================================================*/
  488. unsigned char Update_zImage()
  489. {
  490. SAVE_SYS_LOG_MSG_FWUPDATE("-------- [zImage]start --------");
  491. unsigned char result = PASS;
  492. long int MaxLen = 48*1024*1024;
  493. unsigned long file_length = 0;
  494. unsigned char *ptr = malloc(MaxLen);
  495. if(ptr == NULL)
  496. {
  497. return FAIL;
  498. }
  499. memset(ptr, 0, MaxLen);
  500. file_length = fsize("/root/zImage");
  501. int fd = 0;
  502. int wrd = 0;
  503. FILE *file;
  504. fd = open("/dev/mtdblock6", O_RDWR);
  505. file = fopen("/root/zImage", "rb");
  506. if (fd < 0)
  507. {
  508. SAVE_SYS_LOG_MSG_FWUPDATE("[zImage]Can not open mtdblock6\n");
  509. free(ptr);
  510. return FAIL;
  511. }
  512. else if (file == NULL)
  513. {
  514. SAVE_SYS_LOG_MSG_FWUPDATE("[zImage]Can not open the downloaded image file\n");
  515. free(ptr);
  516. return FAIL;
  517. }
  518. else
  519. {
  520. //[VITAL] Closing unneccesary task to supoort rapid CAN data receving..
  521. SAVE_SYS_LOG_MSG_FWUPDATE("[zImage] closing SeccComm...");
  522. system("killall SeccComm");
  523. // Write image to flash
  524. SAVE_SYS_LOG_MSG_FWUPDATE("[zImage]Writing image to mtdblock6...");
  525. fread(ptr, sizeof(unsigned char), file_length, file);
  526. wrd = write(fd, ptr, file_length);
  527. close(fd);
  528. fclose(file);
  529. sprintf(buf_log_fwupdate, "[zImage]mtdblock6 - written length: %d bytes\n", wrd);
  530. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  531. if(wrd != file_length)
  532. {
  533. free(ptr);
  534. return FAIL;
  535. }
  536. else
  537. {
  538. // Open flash target mtdblock
  539. fd = open("/dev/mtdblock7", O_RDWR);
  540. if (fd < 0)
  541. {
  542. SAVE_SYS_LOG_MSG_FWUPDATE("[zImage]Can not open mtdblock7");
  543. free(ptr);
  544. return FAIL;
  545. }
  546. else
  547. {
  548. // Write image to flash
  549. SAVE_SYS_LOG_MSG_FWUPDATE("[zImage]Writing image to mtdblock7...");
  550. wrd = write(fd, ptr, file_length);
  551. close(fd);
  552. sprintf(buf_log_fwupdate, "[zImage]mtdblock7 - written length: %d bytes\n", wrd);
  553. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  554. if(wrd != file_length)
  555. {
  556. free(ptr);
  557. return FAIL;
  558. }
  559. }
  560. }
  561. }
  562. return result;
  563. }
  564. /*===========================================================================
  565. FUNCTION: Update_ramdisk
  566. DESCRIPTION:
  567. PRE-CONDITION:
  568. INPUT:
  569. OUTPUT:
  570. GLOBAL VARIABLES:
  571. =============================================================================*/
  572. unsigned char Update_ramdisk()
  573. {
  574. SAVE_SYS_LOG_MSG_FWUPDATE("-------- [ramdisk]start --------");
  575. unsigned char result = PASS;
  576. long int MaxLen = 48*1024*1024;
  577. unsigned long file_length = 0;
  578. unsigned char *ptr = malloc(MaxLen);
  579. if(ptr == NULL)
  580. {
  581. return FAIL;
  582. }
  583. memset(ptr, 0, MaxLen);
  584. file_length = fsize("/root/ramdisk.gz");
  585. int fd = 0;
  586. int wrd = 0;
  587. FILE *file;
  588. fd = open("/dev/mtdblock8", O_RDWR);
  589. file = fopen("/root/ramdisk.gz", "rb");
  590. if(fd < 0)
  591. {
  592. SAVE_SYS_LOG_MSG_FWUPDATE("[ramdisk]UpdateRootfs NG - can not open rootfs\n");
  593. return FAIL;
  594. }
  595. else if (file == NULL)
  596. {
  597. SAVE_SYS_LOG_MSG_FWUPDATE("[ramdisk]Can not open the downloaded image file\n");
  598. return FAIL;
  599. }
  600. else
  601. {
  602. //[VITAL] Closing unneccesary task to supoort rapid CAN data receving..
  603. SAVE_SYS_LOG_MSG_FWUPDATE("[ramdisk] closing SeccComm...");
  604. system("killall SeccComm");
  605. SAVE_SYS_LOG_MSG_FWUPDATE("[ramdisk]Writing image to mtdblock8...");
  606. fread(ptr, sizeof(unsigned char), file_length, file);
  607. wrd = write(fd, ptr, file_length);
  608. close(fd);
  609. fclose(file);
  610. sprintf(buf_log_fwupdate, "[ramdisk]mtdblock8 - written length: %d bytes\n", wrd);
  611. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  612. if(wrd != file_length)
  613. {
  614. free(ptr);
  615. return FAIL;
  616. }
  617. else
  618. {
  619. fd = open("/dev/mtdblock9", O_RDWR);
  620. if(fd < 0)
  621. {
  622. SAVE_SYS_LOG_MSG_FWUPDATE("[ramdisk]UpdateRootfs NG - can not open rootfs");
  623. free(ptr);
  624. return FAIL;
  625. }
  626. SAVE_SYS_LOG_MSG_FWUPDATE("[ramdisk]Writing image to mtdblock9...");
  627. wrd = write(fd, ptr, file_length);
  628. close(fd);
  629. sprintf(buf_log_fwupdate, "[ramdisk]mtdblock9 - written length: %d bytes\n", wrd);
  630. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  631. if(wrd != file_length)
  632. {
  633. free(ptr);
  634. return FAIL;
  635. }
  636. else
  637. {
  638. //result = PASS;
  639. SAVE_SYS_LOG_MSG_FWUPDATE("[ramdisk]deleting Storage-root files.\n");
  640. system("cd /Storage;rm -rf root/*");
  641. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  642. {
  643. SAVE_SYS_LOG_MSG_FWUPDATE("[ramdisk]sync...");
  644. system("sync");
  645. }
  646. #endif
  647. }
  648. }
  649. }
  650. return result;
  651. }
  652. /*===========================================================================
  653. FUNCTION: Update_user_config
  654. DESCRIPTION:
  655. PRE-CONDITION:
  656. INPUT:
  657. OUTPUT:
  658. GLOBAL VARIABLES:
  659. =============================================================================*/
  660. unsigned char Update_user_config()
  661. {
  662. SAVE_SYS_LOG_MSG_FWUPDATE("-------- [user_config]start --------");
  663. unsigned char result = PASS;
  664. long int MaxLen = 48*1024*1024;
  665. unsigned long file_length = 0;
  666. unsigned char *ptr = malloc(MaxLen);
  667. if(ptr == NULL)
  668. {
  669. return FAIL;
  670. }
  671. memset(ptr, 0, MaxLen);
  672. file_length = fsize("/root/FactoryConfig.bin");
  673. // Open flash target mtdblock
  674. int fd = 0;
  675. int wrd = 0;
  676. FILE *file;
  677. fd = open("/dev/mtdblock10", O_RDWR);
  678. file = fopen("/root/FactoryConfig.bin", "rb");
  679. if (fd < 0)
  680. {
  681. SAVE_SYS_LOG_MSG_FWUPDATE("[user_config]Can not open mtdblock10\n");
  682. free(ptr);
  683. return FAIL;
  684. }
  685. else if (file == NULL)
  686. {
  687. SAVE_SYS_LOG_MSG_FWUPDATE("[user_config]Can not open the downloaded image file\n");
  688. free(ptr);
  689. return FAIL;
  690. }
  691. else
  692. {
  693. //[VITAL] Closing unneccesary task to supoort rapid CAN data receving..
  694. SAVE_SYS_LOG_MSG_FWUPDATE("[user_config] closing SeccComm...");
  695. system("killall SeccComm");
  696. // Write image to flash
  697. SAVE_SYS_LOG_MSG_FWUPDATE("[user_config]Writing image to mtdblock10...");
  698. fread(ptr, sizeof(unsigned char), file_length, file);
  699. wrd = write(fd, ptr, file_length);
  700. close(fd);
  701. fclose(file);
  702. sprintf(buf_log_fwupdate,
  703. "[user_config]mtdblock10 - written length: %d bytes\n",
  704. wrd);
  705. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  706. if(wrd != file_length)
  707. {
  708. free(ptr);
  709. return FAIL;
  710. }
  711. else
  712. {
  713. // Open flash target mtdblock
  714. fd = open("/dev/mtdblock11", O_RDWR);
  715. if (fd < 0)
  716. {
  717. SAVE_SYS_LOG_MSG_FWUPDATE("[user_config]Can not open mtdblock11");
  718. free(ptr);
  719. return FAIL;
  720. }
  721. else
  722. {
  723. // Write image to flash
  724. SAVE_SYS_LOG_MSG_FWUPDATE("[user_config]Writing image to mtdblock11...");
  725. wrd = write(fd, ptr, file_length);
  726. close(fd);
  727. sprintf(buf_log_fwupdate,
  728. "[user_config]mtdblock11 - written length: %d bytes\n",
  729. wrd);
  730. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  731. if(wrd != file_length)
  732. {
  733. free(ptr);
  734. return FAIL;
  735. }
  736. }
  737. }
  738. }
  739. return result;
  740. }
  741. /*===========================================================================
  742. FUNCTION: Update_root_app
  743. DESCRIPTION:
  744. PRE-CONDITION:
  745. INPUT:
  746. OUTPUT:
  747. GLOBAL VARIABLES:
  748. =============================================================================*/
  749. unsigned char Update_root_app()
  750. {
  751. SAVE_SYS_LOG_MSG_FWUPDATE("-------- [root_app]start --------");
  752. unsigned char result = 0;
  753. //STEP 1: Unzip tmp (.tar.gz) (also checking the file completion)
  754. system("tar -C /Storage/ -zxvf /Storage/tmp"); //.tar.gz
  755. //[zip command] tar -zcvf tmp image/
  756. //STEP 2: Checking File Existance (to-be enhanced)
  757. FILE *file;
  758. file = fopen("/root/ramdisk_app_type_5.tar.gz", "rb");
  759. if (file == NULL)
  760. {
  761. result = 0; //Failed on update
  762. SAVE_SYS_LOG_MSG_FWUPDATE("[root_app]checking downloaded file: FAIL");
  763. system("rm -rf /Storage/image/");
  764. return 0;
  765. }
  766. else
  767. {
  768. fclose(file);
  769. SAVE_SYS_LOG_MSG_FWUPDATE("[root_app]checking downloaded file: OK");
  770. SAVE_SYS_LOG_MSG_FWUPDATE("[root_app]updtating...");
  771. system("cp -rfv /Storage/image/* /Storage/root/");
  772. system("rm -rf /Storage/image/");
  773. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  774. {
  775. SAVE_SYS_LOG_MSG_FWUPDATE("[root_app]sync...");
  776. system("sync");
  777. }
  778. #endif
  779. SAVE_SYS_LOG_MSG_FWUPDATE("[root_app]update: done");
  780. result = 1; //Successful on update
  781. }
  782. return result;
  783. }
  784. /*===========================================================================
  785. FUNCTION: Update_ALL
  786. DESCRIPTION:
  787. PRE-CONDITION:
  788. INPUT:
  789. OUTPUT:
  790. GLOBAL VARIABLES:
  791. =============================================================================*/
  792. int Update_ALL()
  793. {
  794. char result;
  795. result = FAIL;
  796. //[VITAL] Closing unneccesary task to supoort rapid CAN data receving..
  797. SAVE_SYS_LOG_MSG_FWUPDATE("[Update_ALL] closing SeccComm...");
  798. system("killall SeccComm");
  799. if (Update_MLO() == FAIL)
  800. {
  801. SAVE_SYS_LOG_MSG_FWUPDATE("[Update]MLO: fail");
  802. }
  803. else if (Update_uboot() == FAIL)
  804. {
  805. SAVE_SYS_LOG_MSG_FWUPDATE("[Update]MLO: fail");
  806. }
  807. else if (Update_DTB() == FAIL)
  808. {
  809. SAVE_SYS_LOG_MSG_FWUPDATE("[Update]DTB: fail");
  810. }
  811. else if (Update_zImage() == FAIL)
  812. {
  813. SAVE_SYS_LOG_MSG_FWUPDATE("[Update]zImage: fail");
  814. }
  815. else if (Update_ramdisk() == FAIL)
  816. {
  817. SAVE_SYS_LOG_MSG_FWUPDATE("[Update]ramdisk: fail");
  818. }
  819. /*
  820. else if (Update_user_config() == FAIL)
  821. {
  822. SAVE_SYS_LOG_MSG_FWUPDATE("[Update]configuration: fail");
  823. }
  824. */
  825. //else if (Update_root_app() == FAIL)
  826. //{
  827. //}
  828. else
  829. {
  830. result = PASS;
  831. }
  832. SAVE_SYS_LOG_MSG_FWUPDATE("-------------[FW Update Summary]-----------");
  833. if (result == FAIL)
  834. {
  835. SAVE_SYS_LOG_MSG_FWUPDATE("[ALL]Fail");
  836. CSUCOMMDC_TASK_FLAG.FW_Update_result = FAIL;
  837. }
  838. else if (result == PASS)
  839. {
  840. SAVE_SYS_LOG_MSG_FWUPDATE("[ALL]Pass");
  841. CSUCOMMDC_TASK_FLAG.FW_Update_result = PASS;
  842. }
  843. else
  844. {
  845. CSUCOMMDC_TASK_FLAG.FW_Update_result = FAIL;
  846. sprintf(buf_log_fwupdate, "[ALL]unexpected response content (0x%X)", result);
  847. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  848. }
  849. CSUCOMMDC_TASK_FLAG.FW_Update_Done = TRUE; //sending CAN Res msg to CSU and reboot
  850. return result;
  851. }
  852. /*===========================================================================
  853. FUNCTION: FWImage_HeaderParser
  854. DESCRIPTION:
  855. PRE-CONDITION:
  856. INPUT:
  857. OUTPUT:
  858. GLOBAL VARIABLES:
  859. =============================================================================*/
  860. int FWImage_HeaderParser(struct FwImageDataType *image)
  861. {
  862. SAVE_SYS_LOG_MSG_FWUPDATE("[HeaderParser]starting...");
  863. //Step 0: Initialize
  864. unsigned char result = 0;
  865. long int MaxLen = 48*1024*1024;
  866. unsigned char *ptr = malloc(MaxLen);
  867. if(ptr == NULL)
  868. {
  869. SAVE_SYS_LOG_MSG_FWUPDATE("[HeaderParser]malloc: fail");
  870. free(ptr);
  871. return FAIL;
  872. }
  873. else
  874. {
  875. SAVE_SYS_LOG_MSG_FWUPDATE("[HeaderParser]malloc: OK");
  876. }
  877. memset(ptr, 0, MaxLen);
  878. FILE *file;
  879. file = fopen(image->path, "rb");
  880. if (file == NULL)
  881. {
  882. SAVE_SYS_LOG_MSG_FWUPDATE("[HeaderParser]fopen: fail");
  883. free(ptr);
  884. return FAIL;
  885. }
  886. else
  887. {
  888. SAVE_SYS_LOG_MSG_FWUPDATE("[HeaderParser]fopen: OK");
  889. }
  890. fread(ptr, sizeof(unsigned char), image->size, file);
  891. fclose(file);
  892. //Step 1: Check FW Image Type
  893. image->type = (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19]));
  894. if (image->type != FW_IMAGE_TYPE_CCS_DTB &&
  895. image->type != FW_IMAGE_TYPE_CCS_UBOOT &&
  896. image->type != FW_IMAGE_TYPE_CCS_ZIMAGE &&
  897. image->type != FW_IMAGE_TYPE_CCS_RAMDISK)
  898. {
  899. sprintf(buf_log_fwupdate,
  900. "[HeaderParser]incorrect type (0x%X)",
  901. image->type);
  902. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  903. free(ptr);
  904. return FAIL;
  905. }
  906. //Step 2: Check FW Image Length
  907. unsigned long size_header = 0;
  908. size_header = (((unsigned int)ptr[20])<<24 | ((unsigned int)ptr[21])<<16 | ((unsigned int)ptr[22])<<8 | ((unsigned int)ptr[23]));
  909. if(image->size != (size_header + 48))
  910. {
  911. sprintf(buf_log_fwupdate,
  912. "[HeaderParser]image length is not matched (header = %d, calculated = %d, bytes)",
  913. size_header,
  914. image->size);
  915. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  916. free(ptr);
  917. return FAIL;
  918. }
  919. //Step 3: Check CRC
  920. unsigned int crc_cal = 0;
  921. image->crc = ((unsigned int)ptr[34])<<24 | ((unsigned int)ptr[35])<<16 | ((unsigned int)ptr[36])<<8 | ((unsigned int)ptr[37]);
  922. crc_cal = crc32(ptr, image->size);
  923. if(image->crc != crc_cal)
  924. {
  925. sprintf(buf_log_fwupdate,
  926. "[HeaderParser]CRC error (header = 0x%X, calculated = 0x%X)",
  927. image->crc,
  928. crc_cal);
  929. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  930. free(ptr);
  931. return FAIL;
  932. }
  933. else
  934. {
  935. SAVE_SYS_LOG_MSG_FWUPDATE("[HeaderParser]CRC: OK");
  936. }
  937. free(ptr);
  938. return PASS;
  939. }
  940. /*===========================================================================
  941. FUNCTION: FWImage_Normalize
  942. DESCRIPTION:
  943. PRE-CONDITION:
  944. INPUT:
  945. OUTPUT:
  946. GLOBAL VARIABLES:
  947. =============================================================================*/
  948. int FWImage_Normalize(struct FwImageDataType *image)
  949. {
  950. //Step 0: Initialize
  951. unsigned char result = 0;
  952. long int MaxLen = 48*1024*1024;
  953. unsigned char *ptr = malloc(MaxLen);
  954. if(ptr == NULL)
  955. {
  956. SAVE_SYS_LOG_MSG_FWUPDATE("[Normalize] malloc fail");
  957. free(ptr);
  958. return FAIL;
  959. }
  960. memset(ptr, 0, MaxLen);
  961. FILE *file;
  962. file = fopen(image->path, "rb");
  963. if (file == NULL)
  964. {
  965. SAVE_SYS_LOG_MSG_FWUPDATE("[Normalize] fopen fail");
  966. free(ptr);
  967. return FAIL;
  968. }
  969. fread(ptr, sizeof(unsigned char), image->size, file);
  970. fclose(file);
  971. //Step 1: Delete the original image
  972. char buf[64];
  973. memset(buf, 0, 64);
  974. sprintf(buf, "rm -rf %s", image->path);
  975. system(buf);
  976. //Step 2: Remove header and create a renamed image accoring to its firmware type
  977. struct FwImageDataType image_new;
  978. switch (image->type)
  979. {
  980. case FW_IMAGE_TYPE_CCS_UBOOT: //0x10000007
  981. {
  982. sprintf(image_new.path, "/root/u-boot.img");
  983. break;
  984. }
  985. case FW_IMAGE_TYPE_CCS_DTB: //0x10000008
  986. {
  987. sprintf(image_new.path, "/root/am335x-evm.dtb");
  988. break;
  989. }
  990. case FW_IMAGE_TYPE_CCS_ZIMAGE: //0x10000009
  991. {
  992. sprintf(image_new.path, "/root/zImage");
  993. break;
  994. }
  995. case FW_IMAGE_TYPE_CCS_RAMDISK: //0x1000000A
  996. {
  997. sprintf(image_new.path, "/root/ramdisk.gz");
  998. break;
  999. }
  1000. default:
  1001. {
  1002. break;
  1003. }
  1004. }
  1005. memset(buf, 0, 64);
  1006. sprintf(buf, "rm -rf %s", image_new.path);
  1007. system(buf);
  1008. SAVE_SYS_LOG_MSG_FWUPDATE("[Normalize]creating new image: ongoing...");
  1009. image_new.size = image->size - 48;
  1010. file = fopen(image_new.path, "wb+");
  1011. fwrite(&ptr[48], image_new.size, 1, file); //48: header size
  1012. fclose(file);
  1013. free(ptr);
  1014. SAVE_SYS_LOG_MSG_FWUPDATE("[Normalize]creating new image: done");
  1015. return PASS;
  1016. }
  1017. /*===========================================================================
  1018. FUNCTION: FWImage_Init
  1019. DESCRIPTION:
  1020. PRE-CONDITION:
  1021. INPUT:
  1022. 1. image file name: "ccs.image"
  1023. OUTPUT:
  1024. 1. type: FW image type
  1025. - 0: file is not exist or error occours
  1026. - 0x10000007: FW_IMAGE_TYPE_CCS_UBOOT
  1027. - 0x10000008: FW_IMAGE_TYPE_CCS_DTB
  1028. - 0x10000009: FW_IMAGE_TYPE_CCS_ZIMAGE
  1029. - 0x1000000A: FW_IMAGE_TYPE_CCS_RAMDISK
  1030. GLOBAL VARIABLES:
  1031. =============================================================================*/
  1032. unsigned int FWImage_Init()
  1033. {
  1034. struct FwImageDataType image;
  1035. sprintf(image.path, "/root/ccs.image");
  1036. //STEP 1: Check if image exist?
  1037. image.size = fsize(image.path);
  1038. if (image.size == 0)
  1039. {
  1040. SAVE_SYS_LOG_MSG_FWUPDATE("[Init][Error]image does not exist.");
  1041. return FAIL; //FAIL: 0
  1042. }
  1043. //STEP 2: Check FW image type = ?
  1044. if (FWImage_HeaderParser(&image) != PASS)
  1045. {
  1046. return FAIL; //FAIL: 0
  1047. }
  1048. //STEP 4: Remove header and rename the image file accoring to its firmware type
  1049. if (FWImage_Normalize(&image) != PASS)
  1050. {
  1051. return FAIL; //FAIL: 0
  1052. }
  1053. //Step 5: return result
  1054. return image.type;
  1055. }
  1056. /*===========================================================================
  1057. FUNCTION: Update_viaWebService
  1058. DESCRIPTION:
  1059. PRE-CONDITION:
  1060. INPUT:
  1061. OUTPUT:
  1062. GLOBAL VARIABLES:
  1063. =============================================================================*/
  1064. int Update_viaWebService()
  1065. {
  1066. SAVE_SYS_LOG_MSG_FWUPDATE("-------- [viaWebService]start --------");
  1067. unsigned char result = FAIL;
  1068. unsigned int type = 0;
  1069. type = FWImage_Init();
  1070. switch (type)
  1071. {
  1072. case FW_IMAGE_TYPE_CCS_UBOOT:
  1073. {
  1074. result = Update_uboot();
  1075. break;
  1076. }
  1077. case FW_IMAGE_TYPE_CCS_DTB:
  1078. {
  1079. result = Update_DTB();
  1080. break;
  1081. }
  1082. case FW_IMAGE_TYPE_CCS_ZIMAGE:
  1083. {
  1084. result = Update_zImage();
  1085. break;
  1086. }
  1087. case FW_IMAGE_TYPE_CCS_RAMDISK:
  1088. {
  1089. result = Update_ramdisk();
  1090. break;
  1091. }
  1092. default:
  1093. {
  1094. result = FAIL;
  1095. sprintf(buf_log_fwupdate,
  1096. "[Error]undefined FW image type or file not exist.(0x%X)",
  1097. type
  1098. );
  1099. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1100. break;
  1101. }
  1102. }
  1103. if (result == PASS)
  1104. {
  1105. CSUCOMMDC_TASK_FLAG.FW_Update_result = PASS;
  1106. }
  1107. else
  1108. {
  1109. CSUCOMMDC_TASK_FLAG.FW_Update_result = FAIL;
  1110. }
  1111. CSUCOMMDC_TASK_FLAG.FW_Update_Done = TRUE; //sending CAN Res msg to CSU and reboot
  1112. }
  1113. /*===========================================================================
  1114. FUNCTION: main
  1115. DESCRIPTION:
  1116. PRE-CONDITION:
  1117. INPUT:
  1118. OUTPUT:
  1119. GLOBAL VARIABLES:
  1120. =============================================================================*/
  1121. int main(int argc, char *argv[])
  1122. {
  1123. // ======== [STEP 1/5] Initialize Share Memory ========
  1124. if(ShareMemory_Init() == 0)
  1125. {
  1126. SAVE_SYS_LOG_MSG_FWUPDATE("[main]ShareMemory_Init NG");
  1127. if(ShmStatusCodeData != NULL)
  1128. {
  1129. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  1130. }
  1131. sleep(5);
  1132. return 0;
  1133. }
  1134. //Arguments Parsing for Commands
  1135. if (argv[1][0] == '-' )
  1136. {
  1137. switch (argv[1][1])
  1138. {
  1139. case 'h': //help
  1140. {
  1141. sprintf(buf_log_fwupdate,
  1142. " ================= [HELP] CCS FW Update ==============");
  1143. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1144. sprintf(buf_log_fwupdate,
  1145. " -h \t :help");
  1146. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1147. sprintf(buf_log_fwupdate,
  1148. " -w \t :image update from WebService (with header, named as ccs.image)");
  1149. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1150. sprintf(buf_log_fwupdate,
  1151. " -a \t :full images update \t(no header, named as original names)");
  1152. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1153. sprintf(buf_log_fwupdate,
  1154. " -m \t :MLO update \t\t(no header, named as MLO)");
  1155. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1156. sprintf(buf_log_fwupdate,
  1157. " -u \t :uboot update \t\t(no header, named as u-boot.img)");
  1158. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1159. sprintf(buf_log_fwupdate,
  1160. " -d \t :dtb update \t\t(no header, named as am335x-evm.dtb)");
  1161. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1162. sprintf(buf_log_fwupdate,
  1163. " -z \t :zImage update \t(no header, named as zImage)");
  1164. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1165. sprintf(buf_log_fwupdate,
  1166. " -r \t :ramdisk update \t(no header, named as ramdisk.gz)");
  1167. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1168. break;
  1169. }
  1170. case 'w': //image update from WebService
  1171. {
  1172. Update_viaWebService();
  1173. break;
  1174. }
  1175. case 'a': //all image update
  1176. {
  1177. Update_ALL();
  1178. break;
  1179. }
  1180. case 'm': //MLO update
  1181. {
  1182. Update_MLO();
  1183. break;
  1184. }
  1185. case 'u': //uboot update
  1186. {
  1187. Update_uboot();
  1188. break;
  1189. }
  1190. case 'd': //dtb update
  1191. {
  1192. Update_DTB();
  1193. break;
  1194. }
  1195. case 'z': //zImage update
  1196. {
  1197. Update_zImage();
  1198. break;
  1199. }
  1200. case 'r': //ramdisk update
  1201. {
  1202. Update_ramdisk();
  1203. break;
  1204. }
  1205. default:
  1206. {
  1207. sprintf(buf_log_fwupdate, "Unknown option -%c\n\n", argv[1][1]);
  1208. SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
  1209. break;
  1210. }
  1211. }
  1212. }
  1213. }