parseConfig.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. //-------------------------------------------------------------------------------
  2. #include "parseConfig.h"
  3. #include "loadBasicPacket.h"
  4. //-------------------------------------------------------------------------------
  5. const char* ACTION_NAME[ACTION_MAX] = { "FileName", "Protected", "MaxSize", "NVMData", "PathName", "Output", "BasicPacket", "END" };
  6. enum {
  7. ACTION_FILENAME = 0,
  8. ACTION_PROTECTED,
  9. ACTION_MAXSIZE,
  10. ACTION_NVMDATA,
  11. ACTION_PATHNAME,
  12. ACTION_OUTPUT,
  13. ACTION_BASICPACKET,
  14. ACTION_ENDFILE
  15. };
  16. int parseAction;
  17. //u32 flashModuleInfoNum;
  18. NorFlashModuleInfo flashModuleInfo[MODULE_MAX];
  19. NorFlashModulePathInfo flashModulePathInfo[PATHINFO_MAX];
  20. char DEFAULT_FILE_NAME[] = "S2.code.bin";
  21. char BIN_FILENAME[128];
  22. NVMData gNVMData[MODULE_MAX];
  23. u32 gNVMData_count = 0;
  24. #ifndef CONFIG_BIN_FILENAME
  25. #define CONFIG_BIN_FILENAME DEFAULT_FILE_NAME
  26. #endif
  27. //---------------------------------------------------------------------------
  28. static inline int check_keyword( const char *keyword, const char* tempString )
  29. { //return (!strncmp(keyword, tempString, strlen(keyword))) ;gaia fixed
  30. char tmp[FILENAME_SIZE];
  31. char *ptr = NULL;
  32. memset(tmp ,'\0', FILENAME_SIZE);
  33. strcpy(tmp ,tempString);
  34. ptr = strstr(tmp, "=" );
  35. if (ptr != NULL)
  36. {
  37. *ptr = '\0';
  38. }
  39. if(!strncmp(keyword, "CONFIG_", (int)7)) //parse string CONFIG_
  40. return false;
  41. return (strlen(keyword)==0)?false:(!strncmp(keyword, tmp, strlen(tmp))) ;
  42. }
  43. //---------------------------------------------------------------------------
  44. static bool copy_settingString( char* dstString, const char* tempString )
  45. {
  46. char* tmp = strstr( tempString, "=" );
  47. if (tmp == NULL)
  48. return false;
  49. tempString = tmp + 1;
  50. strcpy( dstString, tempString );
  51. return true;
  52. }
  53. //---------------------------------------------------------------------------
  54. static bool copy_settingYesNo( bool* dstValue, const char* tempString )
  55. {
  56. char* tmp = strstr( tempString, "=" );
  57. if (tmp == NULL)
  58. return false;
  59. tempString = tmp + 1;
  60. switch( tempString[0] )
  61. {
  62. case 'y': case 'Y': *dstValue = true; break;
  63. case 'n': case 'N': *dstValue = false; break;
  64. default: return false;
  65. }
  66. return true;
  67. }
  68. //---------------------------------------------------------------------------
  69. char* fgetLine( char *s, int size, FILE *fpIn )
  70. {
  71. int i = 0;
  72. while( i == 0 )
  73. {
  74. if( fgets( s, size, fpIn ) == NULL ) return NULL;
  75. i = strlen( s );
  76. if( s[i-1] == '\n' )
  77. {
  78. i--;
  79. if( (i != 0) && s[i-1] == '\r' ) i--;
  80. s[i] = '\0';
  81. }
  82. }
  83. return s;
  84. }
  85. //---------------------------------------------------------------------------
  86. // Search ModuleInfo & ActionIndex
  87. //---------------------------------------------------------------------------
  88. NorFlashModuleInfo* searchModuleInfo( const char *moduleName )
  89. {
  90. int i = 0;
  91. for( i = 0; i < MODULE_MAX; i++ )
  92. {
  93. if( check_keyword( flashModuleInfo[i].moduleName, moduleName ) ) {
  94. //printFlashModuleInfo( &flashModuleInfo[i] );
  95. return &flashModuleInfo[i];
  96. }
  97. }
  98. //showMsg( "warning! searchModuleInfo failed (%s)\n", moduleName );
  99. return NULL;
  100. }
  101. NorFlashModulePathInfo* searchModulePathInfo( const char *moduleName )
  102. {
  103. int i = 0;
  104. for( i = 0; i < PATHINFO_MAX; i++ )
  105. {
  106. if( check_keyword( flashModulePathInfo[i].moduleName, moduleName ) )
  107. return &flashModulePathInfo[i];
  108. }
  109. errMsg( "searchModulePathInfo failed (%s)\n", moduleName );
  110. return NULL;
  111. }
  112. static inline int searchActionIndex( const char *actionName )
  113. {
  114. int i = 0;
  115. for( i = 0; i <ACTION_MAX; i++ )
  116. {
  117. if( check_keyword( ACTION_NAME[i], actionName ) ) return i;
  118. }
  119. return -1;
  120. }
  121. #if 0//ndef RELEASE_VER
  122. static inline void bootrom_append_dbg_string(NorFlashModuleInfo *moduleInfo)
  123. {
  124. static char* bootrom_str = "BootROM";
  125. static char* dbg_str = "_dbg.bin";
  126. if(!strncmp(moduleInfo->moduleName , bootrom_str, strlen(bootrom_str))){
  127. //hard coding.....carefully
  128. int tmp_str_len = strlen(moduleInfo->fileName);
  129. showMsg( "bootrom_append_dbg_string: %s ->", moduleInfo->fileName);
  130. memcpy(&moduleInfo->fileName[tmp_str_len-4], dbg_str, strlen(dbg_str)+1);
  131. //moduleInfo->fileName[tmp_str_len+4]='\0';
  132. showMsg( " %s \n", moduleInfo->fileName);
  133. }
  134. }
  135. #endif
  136. void initFlashModuleInfo(int moduleIndex, const char *moduleName, u32 flashAddr1, u32 flashSize1)
  137. {
  138. //initSingleNorFlashModuleInfoCrossFlash( moduleName, flashAddr1, flashSize1, 0, 0 );
  139. NorFlashModuleInfo *info;
  140. info = &flashModuleInfo[moduleIndex];
  141. //flashModuleInfoNum++
  142. info->isValid = false;
  143. info->isProtected = false;
  144. info->isInitModuleNameByUser = false;
  145. info->isInitProtectedByUser = false;
  146. info->flashAddr1 = flashAddr1;
  147. info->flashSize1 = flashSize1;
  148. info->max_module_size = 0;
  149. // info->flashAddr2 = 0;
  150. // info->flashSize2 = 0;
  151. info->fileName[0] = '\0';
  152. strcpy( info->moduleName, moduleName );
  153. printf("info->moduleName %s\n", info->moduleName);
  154. }
  155. //---------------------------------------------------------------------------
  156. // Parse mergeImage.cfg
  157. //---------------------------------------------------------------------------
  158. static inline bool parseMIC_FileName( const char* tempString )
  159. {
  160. bool ret = false;
  161. #ifdef CONFIG_APPEND_NAME_TO_CIKEY_HDCPKEY
  162. char *token;
  163. char tokenfileName[FILENAME_SIZE];
  164. char tname[FILENAME_SIZE];
  165. #endif
  166. NorFlashModuleInfo *moduleInfo = searchModuleInfo( tempString );
  167. if( moduleInfo == NULL ) return false;
  168. if( moduleInfo->isInitModuleNameByUser )
  169. {
  170. errMsg( "[%s] re-assign fileName\n", moduleInfo->moduleName );
  171. return false;
  172. }
  173. if( copy_settingString( moduleInfo->fileName, tempString ) )
  174. {
  175. moduleInfo->isInitModuleNameByUser = true;
  176. if( moduleInfo->fileName[0] != '\0' ) moduleInfo->isValid = true;
  177. ret = true;
  178. }
  179. #ifdef CONFIG_APPEND_NAME_TO_CIKEY_HDCPKEY
  180. memset(tname, 0, FILENAME_SIZE);
  181. strcpy(tokenfileName, moduleInfo->fileName );
  182. token = strtok(tokenfileName,"/"); /*There are two delimiters here*/
  183. while (token != NULL){
  184. strcpy(tname, token);
  185. token = strtok(NULL," /");
  186. }
  187. strcpy(moduleInfo->eachfileName, tname);
  188. #endif
  189. #if 0//ndef RELEASE_VER
  190. /*special take care bootrom debug/release version */
  191. bootrom_append_dbg_string(moduleInfo);
  192. #endif
  193. return ret;
  194. }
  195. static inline bool parseMIC_Protected( const char* tempString )
  196. {
  197. NorFlashModuleInfo *moduleInfo = searchModuleInfo( tempString );
  198. if( moduleInfo == NULL ) return false;
  199. if( moduleInfo->isInitProtectedByUser )
  200. {
  201. errMsg( "[%s] re-assign protect\n", moduleInfo->moduleName );
  202. return false;
  203. }
  204. if( copy_settingYesNo( &moduleInfo->isProtected, tempString ) )
  205. {
  206. moduleInfo->isInitProtectedByUser = true;
  207. return true;
  208. }
  209. return false;
  210. }
  211. static inline bool parseMIC_MaxSize( const char* tempString )
  212. {
  213. char max_size[12];
  214. NorFlashModuleInfo *moduleInfo = searchModuleInfo( tempString );
  215. memset(max_size, '\0', 12);
  216. if( moduleInfo == NULL ) return false;
  217. if(copy_settingString(max_size, tempString ) )
  218. {
  219. moduleInfo->max_module_size = atoi(max_size);
  220. return true;
  221. }
  222. return false;
  223. }
  224. static inline bool parseMIC_NVMdata( const char* tempString )
  225. {
  226. char tmp[FILENAME_SIZE];
  227. char *ptr;
  228. memset(tmp, 0, FILENAME_SIZE);
  229. strcpy(tmp, tempString);
  230. ptr = strstr(tmp, "=" );
  231. if (ptr == NULL)
  232. return false;
  233. *ptr = '\0';
  234. gNVMData[gNVMData_count].id = atoi(tmp);
  235. strcpy(gNVMData[gNVMData_count].pathName, ptr+1);
  236. gNVMData_count++;
  237. return true;
  238. }
  239. #if 0
  240. static inline bool parseMIC_PathName( const char* tempString )
  241. {
  242. NorFlashModulePathInfo *modulePathInfo = searchModulePathInfo( tempString );
  243. if( modulePathInfo == NULL ) return false;
  244. return copy_settingString( modulePathInfo->pathName, tempString );
  245. }
  246. #endif
  247. static inline bool parseMIC_Output( const char* tempString )
  248. {
  249. if( check_keyword( "Folder", tempString ) )
  250. return copy_settingString( miOutputPathName, tempString );
  251. else if( check_keyword( "judgeDebugVersion", tempString ) )
  252. return copy_settingYesNo( &miJudgeDebugVersionFlag, tempString );
  253. return false;
  254. }
  255. static inline bool parseMIC_BasicPacket( const char* tempString )
  256. {
  257. if( check_keyword( "BasicPacket", tempString ) )
  258. {
  259. if( !copy_settingString( miBaseImageName, tempString ) ) return false;
  260. return loadBasicPacket();
  261. }
  262. return false;
  263. }
  264. //---------------------------------------------------------------------------
  265. static inline bool parseMIC_Action( const char* tempString )
  266. {
  267. int index = searchActionIndex( tempString );
  268. if( index < 0 ) return false;
  269. parseAction = index;
  270. return true;
  271. }
  272. static inline bool parseMIC_Setting( const char* tempString )
  273. {
  274. switch( parseAction )
  275. {
  276. case ACTION_FILENAME: return parseMIC_FileName( tempString );
  277. case ACTION_PROTECTED: return parseMIC_Protected( tempString );
  278. case ACTION_MAXSIZE: return parseMIC_MaxSize( tempString );
  279. case ACTION_NVMDATA: return parseMIC_NVMdata( tempString );
  280. // case ACTION_PATHNAME: return parseMIC_PathName( tempString );
  281. case ACTION_OUTPUT: return parseMIC_Output( tempString );
  282. case ACTION_BASICPACKET: return parseMIC_BasicPacket( tempString );
  283. case ACTION_ENDFILE: return true;
  284. default:
  285. errMsg( "parseAction (%d) not define\n", parseAction ); return false;
  286. }
  287. }
  288. static inline bool parseMergeImageConfigString( const char* tempString )
  289. {
  290. switch( tempString[0] )
  291. {
  292. case '@': return parseMIC_Action( tempString+1 );
  293. case '#': return true;
  294. default: return parseMIC_Setting( tempString );
  295. }
  296. }
  297. // ivan
  298. char *parseQuota(char *str)
  299. {
  300. int i, n=strlen(str);
  301. char *p=str;
  302. for(i=0;i<n;)
  303. {
  304. if(*p!='"')
  305. str[i++] = *p;
  306. p++;
  307. }
  308. return str;
  309. }
  310. bool parseMergeImageConfigFile( const char *filename)
  311. {
  312. int parseLine; bool ret = true;
  313. char tempString[TMP_BUFFER_SIZE];
  314. FILE *fpIn = fopen( filename, "rt" );
  315. if( fpIn == NULL )
  316. {
  317. errMsg( "MergeImageConfig (%s) not found!\n", filename );
  318. return false;
  319. }
  320. for( parseLine = 1; !feof(fpIn); parseLine++ )
  321. {
  322. if( fgetLine( tempString, TMP_BUFFER_SIZE, fpIn ) != NULL )
  323. {
  324. #if DBG_SHOW_CONFIG_LINE
  325. dbgMsg( "line%d: %s\n",parseLine, tempString );
  326. #endif
  327. // ivan
  328. strcpy(tempString, parseQuota( tempString ));
  329. ret = parseMergeImageConfigString( tempString );
  330. }
  331. if( !ret )
  332. {
  333. showMsg( "\nwarning!Parse config failed , line:%d , string: \n\"%s\"\n\n", parseLine, tempString );
  334. ret = true;//gaia
  335. //break;
  336. }
  337. if( parseAction == ACTION_ENDFILE ) break;
  338. }
  339. fclose( fpIn );
  340. return ret;
  341. }
  342. //---------------------------------------------------------------------------
  343. // Parse BasicSaveInfo
  344. //---------------------------------------------------------------------------
  345. static inline bool parseBasicSaveInfoString( const char* tempString )
  346. {
  347. u32 searchSize;
  348. const char *endString;
  349. char searchName[32];
  350. NorFlashModuleInfo* info;
  351. if( tempString[0] != '[' ) return true;
  352. tempString += 1;
  353. if( check_keyword( "CODE", tempString ) ) return true;
  354. else if( check_keyword( "DATA", tempString ) ) return true;
  355. else if( check_keyword( "MODEL", tempString ) ) return true;
  356. endString = strstr( tempString, "]" );
  357. if( endString == NULL ) return false;
  358. searchSize = endString - tempString;
  359. strncpy( searchName, tempString, searchSize );
  360. searchName[searchSize] = '\0';
  361. info = searchModuleInfo( searchName );
  362. if( info == NULL ) return true;
  363. if( info->isInitModuleNameByUser ) return true;
  364. if( info->isInitProtectedByUser ) return true;
  365. info->isProtected = true;
  366. dbgMsg( "BasicSaveInfo: set %s protected\n", info->moduleName );
  367. return true;
  368. }
  369. static inline bool parseBasicSaveInfo( const char *filename)
  370. {
  371. int parseLine; bool ret = true;
  372. char tempString[TMP_BUFFER_SIZE];
  373. FILE *fpIn = fopen( filename, "rt" );
  374. if( fpIn == NULL )
  375. {
  376. errMsg( "BasicSaveInfo (%s) not found!\n", filename );
  377. return false;
  378. }
  379. dbgMsg( "\nparseBasicSaveInfo =>\n" );
  380. for( parseLine = 1; !feof(fpIn); parseLine++ )
  381. {
  382. if( fgetLine( tempString, TMP_BUFFER_SIZE, fpIn ) != NULL )
  383. {
  384. #if DBG_SHOW_CONFIG_LINE
  385. dbgMsg( "line%d: %s\n",parseLine, tempString );
  386. #endif
  387. if( check_keyword( "#END", tempString ) ) break;
  388. ret = parseBasicSaveInfoString( tempString );
  389. }
  390. if( !ret )
  391. {
  392. errMsg( "Parse config failed\n, line:%d , string: %s\n", parseLine, tempString );
  393. break;
  394. }
  395. }
  396. fclose( fpIn );
  397. return ret;
  398. }
  399. //---------------------------------------------------------------------------
  400. // init & load moduleInfo
  401. //---------------------------------------------------------------------------
  402. #if 0
  403. void initSingleNorFlashModuleInfoCrossFlash(
  404. const char *moduleName, u32 flashAddr1, u32 flashSize1, u32 flashAddr2, u32 flashSize2 )
  405. {
  406. NorFlashModuleInfo *info;
  407. info = &flashModuleInfo[flashModuleInfoNum++];
  408. info->isValid = false;
  409. info->isProtected = false;
  410. info->isInitModuleNameByUser = false;
  411. info->isInitProtectedByUser = false;
  412. info->flashAddr1 = flashAddr1;
  413. info->flashSize1 = flashSize1;
  414. info->flashAddr2 = flashAddr2;
  415. info->flashSize2 = flashSize2;
  416. info->fileName[0] = '\0';
  417. strcpy( info->moduleName, moduleName );
  418. }
  419. #endif
  420. inline void printFlashModuleInfo( NorFlashModuleInfo *info )
  421. {
  422. #if DBG_SHOW_PARSE_RESULT
  423. showMsg( "[Module] %s\n", info->moduleName );
  424. showMsg( "isValid=%s\n", info->isValid ? "true" : "false" );
  425. showMsg( "isProtected=%s\n", info->isProtected ? "true" : "false" );
  426. showMsg( "isInitModuleNameByUser=%s\n", info->isInitModuleNameByUser ? "true" : "false" );
  427. showMsg( "isInitProtectedByUser=%s\n", info->isInitProtectedByUser ? "true" : "false" );
  428. showMsg( "flashAddr1=0x%08x\n", info->flashAddr1 );
  429. showMsg( "flashSize1=0x%08x\n", info->flashSize1 );
  430. showMsg( "flashAddr2=0x%08x\n", info->flashAddr2 );
  431. showMsg( "flashSize2=0x%08x\n", info->flashSize2 );
  432. showMsg( "fileName=%s\n", info->fileName );
  433. #endif
  434. }
  435. static inline void reviewFlashModuleInfoFlag(int index)
  436. {
  437. //NorFlashModuleInfo *info
  438. if( isLoadBasicPacket() ) return;
  439. #if MI_PROTECT_INVALID_MODULE
  440. if( (flashModuleInfo[index].isInitModuleNameByUser) && (!flashModuleInfo[index].isValid) )
  441. {
  442. #if defined(OP_IRCommandType)
  443. if( MODULE_OPTION == index) return;
  444. #endif
  445. flashModuleInfo[index].isProtected= true;
  446. showMsg( "[%s] Auto force set protect=y\n", flashModuleInfo[index].moduleName );
  447. }
  448. #endif
  449. }
  450. /* remove space after filename */
  451. static inline void reviewFlashModuleFileName( NorFlashModuleInfo *info )
  452. {
  453. int max = strlen(info->fileName);
  454. for( ; max > 0 ; max-- )
  455. {
  456. if( info->fileName[max-1] != ' ' ) break;
  457. }
  458. info->fileName[max] = '\0';
  459. }
  460. static inline void reviewFolderString( const char *folderName, char *folderString, const char *defaultFolder )
  461. {
  462. u32 strLen = strlen(folderString);
  463. while( strLen && (folderString[strLen-1] == '/' ) ) folderString[--strLen] = '\0';
  464. if( strLen == 0 ) strcpy( folderString, defaultFolder );
  465. dbgMsg( "%s : %s\n", folderName, folderString );
  466. }
  467. #include "init_flash_module.h"
  468. //---------------------------------------------------------------------------
  469. static inline void initSingleNorFlashModulePathInfo(
  470. NorFlashModulePathInfo *info, const char *moduleName, const char *pathName )
  471. {
  472. strcpy( info->moduleName, moduleName );
  473. strcpy( info->pathName, pathName );
  474. }
  475. #if 0
  476. static inline void initNorFlashModulePathInfo()
  477. {
  478. initSingleNorFlashModulePathInfo( &flashModulePathInfo[0], "BootROM", PATHNAME_BOOTROM );
  479. initSingleNorFlashModulePathInfo( &flashModulePathInfo[1], "AudioROM", PATHNAME_AUDIOROM );
  480. }
  481. #endif
  482. //---------------------------------------------------------------------------
  483. bool loadNorFlashModuleInfo()
  484. {
  485. int index;
  486. //initNorFlashModulePathInfo();
  487. initNorFlashModuleInfo();
  488. parseAction = -1;
  489. flashModuleInfo[MODULE_OPTION].isValid = true; //force Option = valid
  490. flashModuleInfo[MODULE_END].isValid = true; //force END = valid
  491. #ifdef CONFIG_SUPPORT_NVM_PRELOAD
  492. flashModuleInfo[MODULE_NVM].isValid = true; //force END = valid
  493. #endif
  494. if( !parseMergeImageConfigFile(miConfigFile) ) return false;
  495. for( index = 0; index < MODULE_MAX; index++ )
  496. {
  497. reviewFlashModuleInfoFlag(index);
  498. reviewFlashModuleFileName( &flashModuleInfo[index] );
  499. printFlashModuleInfo( &flashModuleInfo[index] );
  500. }
  501. reviewFolderString( "OutputFolder", miOutputPathName, PATHNAME_OUTPUT );
  502. //reviewFolderString( "BootROMFolder", searchModulePathInfo( MODULENAME_BOOTROM )->pathName, PATHNAME_BOOTROM );
  503. //reviewFolderString( "AudioROMFolder", searchModulePathInfo( MODULENAME_AUDIOROM )->pathName, PATHNAME_AUDIOROM );
  504. //if( isLoadBasicPacket() ) parseBasicSaveInfo( BASEIMAGE_SAVE );
  505. return true;
  506. }
  507. //---------------------------------------------------------------------------
  508. // parse Program Argument ...
  509. //---------------------------------------------------------------------------
  510. static inline void showProgramUsageHint()
  511. {
  512. showMsg( "\nUsage: mergeImage targetDir targetName <option(s)>\n\n" );
  513. showMsg( "=> targetDir: The directory of source files.\n");
  514. showMsg( "=> targetName: Final production file-name. Don't need to include the file extension. (*.packet *.bin)\n\n");
  515. showMsg( "The options are:\n" );
  516. showMsg( "=> -Config=<configFile>: Re-specified the mergeImage configuration file.\n" );
  517. showMsg( "=> -deleteTempFile=<Y/N>: Re-specified delete intermediate files or not.\n" );
  518. showMsg( "=> -generatePacket=<Y/N>: Re-specified generate packet or not.\n" );
  519. showMsg( "=> -generateOriginalBin=<Y/N>: Re-specified generate original-bin or not.\n" );
  520. showMsg( "\n" );
  521. }
  522. static inline void showFlashMapItemInfo( const char* s, u32 addr, u32 size )
  523. {
  524. showMsg( "%8s: 0x%08x, %d KB\n", s, addr, ROUND_KB( size ) );
  525. }
  526. #if 0
  527. static inline void showDynamicItemOfFlashMap() /* debug for sisspi_flashalloc.h*/
  528. {
  529. showMsg( "\nDynamicItemOfFlashMap=>\n" );
  530. showFlashMapItemInfo( "RRTTable", SPI_RRTTABLE_FLASHADDR, SPI_RRTTABLE_FLASHSIZE );
  531. // showFlashMapItemInfo( "RRTTable2", SPI_RRTTABLE2_FLASHADDR, SPI_RRTTABLE2_FLASHSIZE );
  532. showFlashMapItemInfo( "Logo", SPI_LOGO_FLASHADDR, SPI_LOGO_FLASHSIZE );
  533. // showFlashMapItemInfo( "Logo2", SPI_LOGO2_FLASHADDR, SPI_LOGO2_FLASHSIZE );
  534. showFlashMapItemInfo( "Backup64K", SPI_MEMALLOCBACKUP_FLASHADDR, 64*1024 );
  535. showFlashMapItemInfo( "MultiTable", SPI_MULTITABLE_FLASHADDR, SPI_MULTITABLE_FLASHSIZE );
  536. showFlashMapItemInfo( "AudioROM", SPI_AUDIOROM_FLASHADDR, SPI_AUDIOROM_FLASHSIZE );
  537. showFlashMapItemInfo( "Kernel", SPI_KERNEL_FLASHADDR, SPI_KERNEL_FLASHSIZE );
  538. showMsg( "\n" );
  539. }
  540. #endif
  541. static inline bool parseProgArg_Option( const char *optionArgument )
  542. {
  543. if( check_keyword( "-Config=", optionArgument ) )
  544. {
  545. if( copy_settingString( miConfigFile, optionArgument ) ) return true;
  546. }
  547. else if( check_keyword( "-deleteTempFile=", optionArgument ) )
  548. {
  549. if( copy_settingYesNo( &miDeleteTempFileFlag, optionArgument ) ) return true;
  550. }
  551. else if( check_keyword( "-generatePacket=", optionArgument ) )
  552. {
  553. if( copy_settingYesNo( &miGeneratePacketFlag, optionArgument ) ) return true;
  554. }
  555. else if( check_keyword( "-generateOriginalBib=", optionArgument ) )
  556. {
  557. if( copy_settingYesNo( &miGenerateOriginalBinFlag, optionArgument ) ) return true;
  558. }
  559. return false;
  560. }
  561. static inline bool parseProgArg_Necessary( const char *targetDir, const char *targetName )
  562. {
  563. if( chdir( targetDir ) != 0 )
  564. {
  565. errMsg( "Cannot find the specified folder: %s\n", targetDir );
  566. return false;
  567. }
  568. strcpy( miPacketName, targetName );
  569. strcat( miPacketName, ".packet" );
  570. #if 0
  571. strcpy( miCodeBinName, targetName );
  572. strcat( miCodeBinName, ".code.bin" );
  573. strcpy( miDataBinName, targetName );
  574. strcat( miDataBinName, ".data.bin" );
  575. #endif
  576. strcpy( miBinWithInfo, targetName );
  577. //strcat( miBinWithInfo, ".code.bin" );
  578. strcpy( miSaveInfoName, targetName );
  579. strcat( miSaveInfoName, ".save" );
  580. #ifdef MERGEFEATURE
  581. strcpy( miConfigFile , MERGEFEATURE );
  582. #else
  583. showMsg( "[Waring] No define MERGEFEATURE in Project.h\n" );
  584. strcpy( miConfigFile , FILENAME_MICONFIG );
  585. #endif
  586. miBaseImageName[0] = '\0';
  587. strcpy( miOutputPathName, PATHNAME_OUTPUT );
  588. showMsg( "TargetDirectory: %s\n", targetDir );
  589. showMsg( "TargetName: %s\n", targetName );
  590. return true;
  591. }
  592. bool parseProgArg( int argc, char *argv[] )
  593. {
  594. int i;
  595. if( argc < 2 )
  596. {
  597. showProgramUsageHint();
  598. return false;
  599. }
  600. #if 0
  601. if( argc == 2 )
  602. {
  603. if( check_keyword( "-printmap", argv[1] ) ) showDynamicItemOfFlashMap( );
  604. return false;
  605. }
  606. #endif
  607. strcpy( BIN_FILENAME , CONFIG_BIN_FILENAME );
  608. if( !parseProgArg_Necessary( argv[1], BIN_FILENAME ) ) return false;
  609. for( i = 3; i < argc; i++ )
  610. {
  611. if( !parseProgArg_Option( argv[i] ) )
  612. {
  613. errMsg( "parse Argument Option failed : %s\n", argv[i] );
  614. return false;
  615. }
  616. }
  617. showMsg( "miConfigFile: %s\n", miConfigFile );
  618. showMsg( "miDeleteTempFileFlag: %d\n", miDeleteTempFileFlag );
  619. showMsg( "miGeneratePacketFlag: %d\n", miGeneratePacketFlag );
  620. showMsg( "miGenerateOriginalBinFlag: %d\n", miGenerateOriginalBinFlag );
  621. return true;
  622. }