mergeImage.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //-------------------------------------------------------------------------------
  2. #include "generateBin.h"
  3. #include "generateSave.h"
  4. #include "generateOutput.h"
  5. #include <dirent.h>
  6. //-------------------------------------------------------------------------------
  7. #ifdef _windows_
  8. #include <cstdlib>
  9. #endif
  10. //-------------------------------------------------------------------------------
  11. char miPacketName[FILENAME_SIZE];
  12. char miCodeBinName[FILENAME_SIZE];
  13. char miDataBinName[FILENAME_SIZE];
  14. char miBinWithInfo[FILENAME_SIZE];
  15. char miSaveInfoName[FILENAME_SIZE];
  16. char miConfigFile[FILENAME_SIZE];
  17. char miBaseImageName[FILENAME_SIZE];
  18. char miOutputPathName[FILENAME_SIZE];
  19. bool miGeneratePacketFlag = MI_DFT_GENERATE_PACKET;
  20. bool miDeleteTempFileFlag = MI_DFT_DELETE_TEMP_FILE;
  21. bool miGenerateOriginalBinFlag = MI_DFT_GENERATE_ORI_BIN;
  22. bool miJudgeDebugVersionFlag = MI_DFT_JUDGE_DBG_VERSION;
  23. //---------------------------------------------------------------------------
  24. #define DEBUG_VERSION_KEYWORD "_dbg"
  25. #if 0
  26. #ifdef RELEASE_VER
  27. const bool isDebugVersion = false;
  28. #else
  29. const bool isDebugVersion = true;
  30. #endif
  31. static inline bool checkVersionFormat( const char *fileName )
  32. {
  33. bool foundDebugString = false;
  34. if( strstr( fileName, DEBUG_VERSION_KEYWORD ) ) foundDebugString = true;
  35. if( foundDebugString == isDebugVersion ) return true;
  36. dbgMsg( "Check debug/release version failed!\n");
  37. return false;
  38. }
  39. static inline bool searchMatchFile( const char *dirName, const char* searchKey, char* matchFileName, bool judgeDebugVersion )
  40. {
  41. bool found = false;
  42. DIR *dir = opendir( dirName );
  43. if( dir == NULL ) return false;
  44. struct dirent * ptr;
  45. while( (ptr = readdir(dir)) != NULL )
  46. {
  47. if( ptr->d_name[0] == '.' ) continue;
  48. if( strstr( ptr->d_name, searchKey ) )
  49. {
  50. dbgMsg( "Found match file: %s\n", ptr->d_name );
  51. if( judgeDebugVersion && !checkVersionFormat( ptr->d_name ) ) continue;
  52. if( !found ) sprintf( matchFileName, "%s/%s", dirName, ptr->d_name );
  53. else showMsg( "\n[WARING] Find another file match search rule: %s!!!!\n\n", ptr->d_name );
  54. found = true;
  55. }
  56. }
  57. closedir(dir);
  58. return found;
  59. }
  60. #endif
  61. #if 0
  62. static inline bool copyAudioROM()
  63. {
  64. char searchKey[FILENAME_SIZE]; char fileName[FILENAME_SIZE];
  65. NorFlashModuleInfo *moduleInfo = searchModuleInfo( MODULENAME_AUDIOROM );
  66. NorFlashModulePathInfo* modulePathInfo = searchModulePathInfo( MODULENAME_AUDIOROM );
  67. if( (moduleInfo == NULL) || (modulePathInfo==NULL) ) return false;
  68. if( !moduleInfo->isValid ) return true; /* skip AudioROM */
  69. sprintf( searchKey, "%dK", ROUND_KB( SPI_AUDIOROM_FLASHSIZE ) );
  70. if( !searchMatchFile( modulePathInfo->pathName, searchKey, fileName, false ) )
  71. {
  72. showMsg( "copyAudioROM failed, directory: %s, searchKey: %s\n", modulePathInfo->pathName, searchKey );
  73. return false;
  74. }
  75. showMsg( "copyAudioROM: %s\n", fileName );
  76. return copyFile( moduleInfo->fileName, fileName, 0 );
  77. }
  78. static inline bool copyBootROM()
  79. {
  80. char searchKey[FILENAME_SIZE]; char fileName[FILENAME_SIZE];
  81. NorFlashModuleInfo *moduleInfo = &flashModuleInfo[MODULE_BOOTROM];//searchModuleInfo( MODULENAME_BOOTROM );
  82. NorFlashModulePathInfo* modulePathInfo = searchModulePathInfo( MODULENAME_BOOTROM );
  83. if( (moduleInfo == NULL) || (modulePathInfo==NULL) ) return false;
  84. if( !moduleInfo->isValid ) return true; /* skip BootROM */
  85. sprintf( searchKey, "C%dM_D%dM_A%dK", ROUND_KB( CONFIG_CODE_FLASH_SIZE ),
  86. ROUND_KB( CONFIG_DATA_FLASH_SIZE ), ROUND_KB( SPI_AUDIOROM_FLASHSIZE ) );
  87. if( !searchMatchFile( modulePathInfo->pathName, searchKey, fileName, miJudgeDebugVersionFlag ) )
  88. {
  89. showMsg( "copyBootROM failed, directory: %s, searchKey: \"%s\" \n", modulePathInfo->pathName, searchKey );
  90. return false;
  91. }
  92. showMsg( "copyBootROM: %s\n", fileName );
  93. return copyFile( moduleInfo->fileName, fileName, 0 );
  94. }
  95. #endif
  96. #if 0
  97. bool copyMergeSource()
  98. {
  99. // TODO: sync AudioROM & BootROM
  100. #if MI_COPY_MERGE_SOURCE
  101. dbgMsg( "\n== copyMergeSource ==\n" );
  102. if( miJudgeDebugVersionFlag )
  103. {
  104. showMsg( "Enable Judge debug/release Version feature : "
  105. "BootROM filename %s include \"%s\" string\n", isDebugVersion ? "must" : "can't", DEBUG_VERSION_KEYWORD );
  106. }
  107. if( !copyBootROM() ) return false;
  108. if( !copyAudioROM() ) return false;
  109. #endif
  110. return true;
  111. }
  112. #endif
  113. //---------------------------------------------------------------------------
  114. int main(int argc, char *argv[])
  115. {
  116. bool ret = true;
  117. showMsg( "\n**** MergeNorFlashImage ... Version: 2012/11/27 ****\n");
  118. if( parseProgArg( argc, argv ) )
  119. {
  120. if(ret) ret = loadNorFlashModuleInfo();
  121. // if(ret) ret = copyMergeSource();
  122. if(ret) ret = mergeImageMain();
  123. showMsg( "\n\"%s\" %s!!\n\n", miBinWithInfo, ret ? "Success" : "Failed" );
  124. }
  125. #ifdef _windows_
  126. system("PAUSE");
  127. #endif
  128. return (ret ? 0 : -1);
  129. }