//------------------------------------------------------------------------------- #include "generateBin.h" #include "generateSave.h" #include "generateOutput.h" #include //------------------------------------------------------------------------------- #ifdef _windows_ #include #endif //------------------------------------------------------------------------------- char miPacketName[FILENAME_SIZE]; char miCodeBinName[FILENAME_SIZE]; char miDataBinName[FILENAME_SIZE]; char miBinWithInfo[FILENAME_SIZE]; char miSaveInfoName[FILENAME_SIZE]; char miConfigFile[FILENAME_SIZE]; char miBaseImageName[FILENAME_SIZE]; char miOutputPathName[FILENAME_SIZE]; bool miGeneratePacketFlag = MI_DFT_GENERATE_PACKET; bool miDeleteTempFileFlag = MI_DFT_DELETE_TEMP_FILE; bool miGenerateOriginalBinFlag = MI_DFT_GENERATE_ORI_BIN; bool miJudgeDebugVersionFlag = MI_DFT_JUDGE_DBG_VERSION; //--------------------------------------------------------------------------- #define DEBUG_VERSION_KEYWORD "_dbg" #if 0 #ifdef RELEASE_VER const bool isDebugVersion = false; #else const bool isDebugVersion = true; #endif static inline bool checkVersionFormat( const char *fileName ) { bool foundDebugString = false; if( strstr( fileName, DEBUG_VERSION_KEYWORD ) ) foundDebugString = true; if( foundDebugString == isDebugVersion ) return true; dbgMsg( "Check debug/release version failed!\n"); return false; } static inline bool searchMatchFile( const char *dirName, const char* searchKey, char* matchFileName, bool judgeDebugVersion ) { bool found = false; DIR *dir = opendir( dirName ); if( dir == NULL ) return false; struct dirent * ptr; while( (ptr = readdir(dir)) != NULL ) { if( ptr->d_name[0] == '.' ) continue; if( strstr( ptr->d_name, searchKey ) ) { dbgMsg( "Found match file: %s\n", ptr->d_name ); if( judgeDebugVersion && !checkVersionFormat( ptr->d_name ) ) continue; if( !found ) sprintf( matchFileName, "%s/%s", dirName, ptr->d_name ); else showMsg( "\n[WARING] Find another file match search rule: %s!!!!\n\n", ptr->d_name ); found = true; } } closedir(dir); return found; } #endif #if 0 static inline bool copyAudioROM() { char searchKey[FILENAME_SIZE]; char fileName[FILENAME_SIZE]; NorFlashModuleInfo *moduleInfo = searchModuleInfo( MODULENAME_AUDIOROM ); NorFlashModulePathInfo* modulePathInfo = searchModulePathInfo( MODULENAME_AUDIOROM ); if( (moduleInfo == NULL) || (modulePathInfo==NULL) ) return false; if( !moduleInfo->isValid ) return true; /* skip AudioROM */ sprintf( searchKey, "%dK", ROUND_KB( SPI_AUDIOROM_FLASHSIZE ) ); if( !searchMatchFile( modulePathInfo->pathName, searchKey, fileName, false ) ) { showMsg( "copyAudioROM failed, directory: %s, searchKey: %s\n", modulePathInfo->pathName, searchKey ); return false; } showMsg( "copyAudioROM: %s\n", fileName ); return copyFile( moduleInfo->fileName, fileName, 0 ); } static inline bool copyBootROM() { char searchKey[FILENAME_SIZE]; char fileName[FILENAME_SIZE]; NorFlashModuleInfo *moduleInfo = &flashModuleInfo[MODULE_BOOTROM];//searchModuleInfo( MODULENAME_BOOTROM ); NorFlashModulePathInfo* modulePathInfo = searchModulePathInfo( MODULENAME_BOOTROM ); if( (moduleInfo == NULL) || (modulePathInfo==NULL) ) return false; if( !moduleInfo->isValid ) return true; /* skip BootROM */ sprintf( searchKey, "C%dM_D%dM_A%dK", ROUND_KB( CONFIG_CODE_FLASH_SIZE ), ROUND_KB( CONFIG_DATA_FLASH_SIZE ), ROUND_KB( SPI_AUDIOROM_FLASHSIZE ) ); if( !searchMatchFile( modulePathInfo->pathName, searchKey, fileName, miJudgeDebugVersionFlag ) ) { showMsg( "copyBootROM failed, directory: %s, searchKey: \"%s\" \n", modulePathInfo->pathName, searchKey ); return false; } showMsg( "copyBootROM: %s\n", fileName ); return copyFile( moduleInfo->fileName, fileName, 0 ); } #endif #if 0 bool copyMergeSource() { // TODO: sync AudioROM & BootROM #if MI_COPY_MERGE_SOURCE dbgMsg( "\n== copyMergeSource ==\n" ); if( miJudgeDebugVersionFlag ) { showMsg( "Enable Judge debug/release Version feature : " "BootROM filename %s include \"%s\" string\n", isDebugVersion ? "must" : "can't", DEBUG_VERSION_KEYWORD ); } if( !copyBootROM() ) return false; if( !copyAudioROM() ) return false; #endif return true; } #endif //--------------------------------------------------------------------------- int main(int argc, char *argv[]) { bool ret = true; showMsg( "\n**** MergeNorFlashImage ... Version: 2012/11/27 ****\n"); if( parseProgArg( argc, argv ) ) { if(ret) ret = loadNorFlashModuleInfo(); // if(ret) ret = copyMergeSource(); if(ret) ret = mergeImageMain(); showMsg( "\n\"%s\" %s!!\n\n", miBinWithInfo, ret ? "Success" : "Failed" ); } #ifdef _windows_ system("PAUSE"); #endif return (ret ? 0 : -1); }