imgtools/romtools/rofsbuild/rofsbuild.cpp
changeset 708 0757c2976f96
parent 698 e3ee96a3961c
child 714 e5a58c351011
equal deleted inserted replaced
707:ccd52fece6ff 708:0757c2976f96
    32 #include "cache/cache.hpp"
    32 #include "cache/cache.hpp"
    33 #include "cache/cachegenerator.hpp"
    33 #include "cache/cachegenerator.hpp"
    34 #include "cache/cachevalidator.hpp"
    34 #include "cache/cachevalidator.hpp"
    35 #include "cache/cacheablelist.hpp"
    35 #include "cache/cacheablelist.hpp"
    36 #include "cache/cachemanager.hpp"
    36 #include "cache/cachemanager.hpp"
    37 #include "logging/loggingexception.hpp"
    37 #include "logparser.h"
    38 #include "logging/logparser.hpp"
       
    39 #include <malloc.h>
    38 #include <malloc.h>
    40  
    39  
    41 #ifndef WIN32
    40 #ifndef WIN32
    42 #include <unistd.h>
    41 #include <unistd.h>
    43 #include <strings.h>
    42 #include <strings.h>
    46 #define stricmp strcasecmp
    45 #define stricmp strcasecmp
    47 #define _alloca alloca
    46 #define _alloca alloca
    48 #endif
    47 #endif
    49 
    48 
    50 static const TInt RofsbuildMajorVersion=2;
    49 static const TInt RofsbuildMajorVersion=2;
    51 static const TInt RofsbuildMinorVersion=16;
    50 static const TInt RofsbuildMinorVersion=17;
    52 static const TInt RofsbuildPatchVersion=3;
    51 static const TInt RofsbuildPatchVersion=3;
    53 static TBool SizeSummary=EFalse;
    52 static TBool SizeSummary=EFalse;
    54 static TPrintType SizeWhere=EAlways;
    53 static TPrintType SizeWhere=EAlways;
    55 
    54 
    56 static TInt gHeaderType=1;			// EPOC header
    55 static TInt gHeaderType=1;			// EPOC header
    59 ECompression gCompress=ECompressionUnknown;
    58 ECompression gCompress=ECompressionUnknown;
    60 TUint  gCompressionMethod=0;
    59 TUint  gCompressionMethod=0;
    61 TInt gThreadNum = 0;
    60 TInt gThreadNum = 0;
    62 TInt gCPUNum = 0;
    61 TInt gCPUNum = 0;
    63 TBool gGenSymbols = EFalse;
    62 TBool gGenSymbols = EFalse;
       
    63 TBool gGenBsymbols = EFalse;
    64 TInt gCodePagingOverride = -1;
    64 TInt gCodePagingOverride = -1;
    65 TInt gDataPagingOverride = -1;
    65 TInt gDataPagingOverride = -1;
    66 TInt gLogLevel = 0;	// Information is logged based on logging level.
    66 TInt gLogLevel = 0;	// Information is logged based on logging level.
    67 // The default is 0. So all the existing logs are generated as if gLogLevel = 0.
    67 // The default is 0. So all the existing logs are generated as if gLogLevel = 0.
    68 // If any extra information required, the log level must be appropriately supplied.
    68 // If any extra information required, the log level must be appropriately supplied.
    99 	"Option: -v verbose,  -?,  -s[log|screen|both] size summary\n"
    99 	"Option: -v verbose,  -?,  -s[log|screen|both] size summary\n"
   100 	"        -d<bitmask> set trace mask (DEB build only)\n"
   100 	"        -d<bitmask> set trace mask (DEB build only)\n"
   101 	"        -compress   compress executable files where possible\n"
   101 	"        -compress   compress executable files where possible\n"
   102 	"        -j<digit> do the main job with <digit> threads\n"
   102 	"        -j<digit> do the main job with <digit> threads\n"
   103 	"        -symbols generate symbol file\n"
   103 	"        -symbols generate symbol file\n"
       
   104 	"        -bsymbols generate binary symbol file\n"
   104 	"        -compressionmethod none|inflate|bytepair to set the compression\n"
   105 	"        -compressionmethod none|inflate|bytepair to set the compression\n"
   105 	"              none     uncompress the image.\n"
   106 	"              none     uncompress the image.\n"
   106 	"              inflate  compress the image.\n"
   107 	"              inflate  compress the image.\n"
   107 	"              bytepair compress the image.\n"
   108 	"              bytepair compress the image.\n"
   108 	"        -coreimage <core image file>\n"
   109 	"        -coreimage <core image file>\n"
   163 				if(argv[i][5]) {
   164 				if(argv[i][5]) {
   164 					gSmrImage = ETrue;
   165 					gSmrImage = ETrue;
   165 					gSmrFileName.assign(&argv[i][5]);
   166 					gSmrFileName.assign(&argv[i][5]);
   166 				}
   167 				}
   167 				else {
   168 				else {
   168 					Print (EError, "SMR obey file is missing\n");
   169 					printf ("ERROR: SMR obey file is missing\n");
   169 				}
   170 				}
   170 			} else if (stricmp(argv[i], "-K") == 0) {
   171 			} else if (stricmp(argv[i], "-K") == 0) {
   171 				gKeepGoing = ETrue;
   172 				gKeepGoing = ETrue;
   172 			}else if (stricmp(argv[i], "-SYMBOLS") == 0) {
   173 			}else if (stricmp(argv[i], "-SYMBOLS") == 0) {
   173 				gGenSymbols = ETrue;
   174 				gGenSymbols = ETrue;
       
   175 			}
       
   176 			else if (stricmp(argv[i], "-BSYMBOLS") == 0 ) {
       
   177 				gGenBsymbols = ETrue;
   174 			}
   178 			}
   175 			else if (((argv[i][1] | 0x20) == 's') &&  
   179 			else if (((argv[i][1] | 0x20) == 's') &&  
   176 				(((argv[i][2]| 0x20) == 'l')||((argv[i][2] | 0x20) == 's'))) {
   180 				(((argv[i][2]| 0x20) == 'l')||((argv[i][2] | 0x20) == 's'))) {
   177 					SizeSummary = ETrue;
   181 					SizeSummary = ETrue;
   178 					if ((argv[i][2]| 0x20) == 'l')
   182 					if ((argv[i][2]| 0x20) == 'l')
   239 			else if(strnicmp(argv[i], "-OBY-CHARSET=", 13) == 0)
   243 			else if(strnicmp(argv[i], "-OBY-CHARSET=", 13) == 0)
   240 			{
   244 			{
   241 				if((stricmp(&argv[i][13], "UTF8")==0) || (stricmp(&argv[i][13], "UTF-8")==0))
   245 				if((stricmp(&argv[i][13], "UTF8")==0) || (stricmp(&argv[i][13], "UTF-8")==0))
   242 					gIsOBYUTF8 = ETrue;
   246 					gIsOBYUTF8 = ETrue;
   243 				else
   247 				else
   244 					Print(EError, "Invalid encoding %s, default system internal encoding will be used.\n", &argv[i][13]);
   248 					printf("ERROR: Invalid encoding %s, default system internal encoding will be used.\n", &argv[i][13]);
   245 			}
   249 			}
   246 			else if (stricmp(argv[i], "-UNCOMPRESS") == 0) {
   250 			else if (stricmp(argv[i], "-UNCOMPRESS") == 0) {
   247 				gCompress = ECompressionUncompress;
   251 				gCompress = ECompressionUncompress;
   248 			}
   252 			}
   249 			else if( stricmp(argv[i], "-COMPRESSIONMETHOD") == 0 ) {
   253 			else if( stricmp(argv[i], "-COMPRESSIONMETHOD") == 0 ) {
   250 				// next argument should a be method
   254 				// next argument should a be method
   251 				if( (i+1) >= argc || argv[i+1][0] == '-') {
   255 				if( (i+1) >= argc || argv[i+1][0] == '-') {
   252 					Print (EError, "Missing compression method! Set it to default (no compression)!");
   256 					printf("ERROR: Missing compression method! Set it to default (no compression)!");
   253 					gCompressionMethod = 0;
   257 					gCompressionMethod = 0;
   254 				}
   258 				}
   255 				else {
   259 				else {
   256 					i++;					
   260 					i++;					
   257 					if( stricmp(argv[i], "NONE") == 0) {
   261 					if( stricmp(argv[i], "NONE") == 0) {
   265 					else if( stricmp(argv[i], "BYTEPAIR") == 0) {
   269 					else if( stricmp(argv[i], "BYTEPAIR") == 0) {
   266 						gCompress = ECompressionCompress;
   270 						gCompress = ECompressionCompress;
   267 						gCompressionMethod = KUidCompressionBytePair;	
   271 						gCompressionMethod = KUidCompressionBytePair;	
   268 					}
   272 					}
   269 					else {
   273 					else {
   270 						Print (EError, "Unknown compression method! Set it to default (no compression)!");
   274 						printf("ERROR: Unknown compression method! Set it to default (no compression)!");
   271 						gCompress = ECompressionUnknown;
   275 						gCompress = ECompressionUnknown;
   272 						gCompressionMethod = 0;		
   276 						gCompressionMethod = 0;		
   273 					}
   277 					}
   274 				}
   278 				}
   275 
   279 
   277 			else if (stricmp(argv[i], "-COREIMAGE") == 0) {
   281 			else if (stricmp(argv[i], "-COREIMAGE") == 0) {
   278 				
   282 				
   279 				gUseCoreImage = ETrue;
   283 				gUseCoreImage = ETrue;
   280 				// next argument should be image filename
   284 				// next argument should be image filename
   281 				if ((i+1 >= argc) || argv[i+1][0] == '-')
   285 				if ((i+1 >= argc) || argv[i+1][0] == '-')
   282 					Print (EError, "Missing image file name");
   286 					printf("ERROR: Missing image file name");
   283 				else {
   287 				else {
   284 					i++;
   288 					i++;
   285 					gImageFilename.assign(argv[i]);
   289 					gImageFilename.assign(argv[i]);
   286 				}
   290 				}
   287 			}
   291 			}
   289 				if(argv[i][11])	{
   293 				if(argv[i][11])	{
   290 					gDriveImage = ETrue; 
   294 					gDriveImage = ETrue; 
   291 					gDriveFilename.assign(&argv[i][11]);	
   295 					gDriveFilename.assign(&argv[i][11]);	
   292 				}
   296 				}
   293 				else {
   297 				else {
   294 					Print (EError, "Drive obey file is missing\n"); 
   298 					printf("ERROR: Drive obey file is missing\n"); 
   295 				}
   299 				}
   296 			}
   300 			}
   297 			else if (argv[i][1] == '?') {
   301 			else if (argv[i][1] == '?') {
   298 				reallyHelp = ETrue;
   302 				reallyHelp = ETrue;
   299 			}
   303 			}
   301 				gEnableStdPathWarning = ETrue;						
   305 				gEnableStdPathWarning = ETrue;						
   302 			}
   306 			}
   303 			else if( stricmp(argv[i], "-LOGLEVEL") == 0) {
   307 			else if( stricmp(argv[i], "-LOGLEVEL") == 0) {
   304 				// next argument should a be loglevel
   308 				// next argument should a be loglevel
   305 				if( (i+1) >= argc || argv[i+1][0] == '-') {
   309 				if( (i+1) >= argc || argv[i+1][0] == '-') {
   306 					Print (EError, "Missing loglevel!");
   310 					printf ("ERROR: Missing loglevel!");
   307 					gLogLevel = DEFAULT_LOG_LEVEL;
   311 					gLogLevel = DEFAULT_LOG_LEVEL;
   308 				}
   312 				}
   309 				else {
   313 				else {
   310 					i++;
   314 					i++;
   311 					if (strcmp(argv[i], "2") == 0)
   315 					if (strcmp(argv[i], "2") == 0)
   313 					if (strcmp(argv[i], "1") == 0)
   317 					if (strcmp(argv[i], "1") == 0)
   314 						gLogLevel = LOG_LEVEL_FILE_DETAILS;
   318 						gLogLevel = LOG_LEVEL_FILE_DETAILS;
   315 					else if (strcmp(argv[i], "0") == 0)
   319 					else if (strcmp(argv[i], "0") == 0)
   316 						gLogLevel = DEFAULT_LOG_LEVEL;
   320 						gLogLevel = DEFAULT_LOG_LEVEL;
   317 					else
   321 					else
   318 						Print(EError, "Only loglevel 0, 1 or 2 is allowed!");
   322 						printf("ERROR: Only loglevel 0, 1 or 2 is allowed!");
   319 				}
   323 				}
   320 			}
   324 			}
   321 			else if( stricmp(argv[i], "-LOGLEVEL2") == 0)
   325 			else if( stricmp(argv[i], "-LOGLEVEL2") == 0)
   322 				gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES);
   326 				gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES);
   323 			else if( stricmp(argv[i], "-LOGLEVEL1") == 0)
   327 			else if( stricmp(argv[i], "-LOGLEVEL1") == 0)
   332 			else if (strnicmp(argv[i], "-loginput=", 10) == 0) {
   336 			else if (strnicmp(argv[i], "-loginput=", 10) == 0) {
   333 				loginput = argv[i] + 10;
   337 				loginput = argv[i] + 10;
   334 			}
   338 			}
   335 			else {
   339 			else {
   336 #ifdef WIN32
   340 #ifdef WIN32
   337 				Print (EWarning, "Unrecognised option %s\n",argv[i]);
   341 				printf ("WARNING: Unrecognised option %s\n",argv[i]);
   338 #else
   342 #else
   339 				if(0 == access(argv[i],R_OK)){
   343 				if(0 == access(argv[i],R_OK)){
   340 					filename.assign(argv[i]);
   344 					filename.assign(argv[i]);
   341 				}
   345 				}
   342 				else {
   346 				else {
   343 					Print (EWarning, "Unrecognised option %s\n",argv[i]);
   347 					printf("WARNING: Unrecognised option %s\n",argv[i]);
   344 				}
   348 				}
   345 #endif				
   349 #endif				
   346 
   350 
   347 			}
   351 			}
   348 		}
   352 		}
   351 		i++;
   355 		i++;
   352 	}
   356 	}
   353 
   357 
   354 	if (paramFileFlag)
   358 	if (paramFileFlag)
   355 		return;
   359 		return;
       
   360 	if(gGenSymbols && gGenBsymbols)
       
   361 	{
       
   362 		printf("WARNING: Options symbols and bsymbols cannot be used at the same time, the common symbols file will be created this time!\n");
       
   363 		gGenBsymbols = EFalse;
       
   364 	}
   356 
   365 
   357 	if((gDriveImage == EFalse) && (gSmrImage ==  EFalse) && 
   366 	if((gDriveImage == EFalse) && (gSmrImage ==  EFalse) && 
   358 		(filename.empty() || (gUseCoreImage && gImageFilename.length() == 0)) && (loginput.length() == 0)){
   367 		(filename.empty() || (gUseCoreImage && gImageFilename.length() == 0)) && (loginput.length() == 0)){
   359 			Print (EAlways, HelpText);
   368 			Print (EAlways, HelpText);
   360 			if (reallyHelp) {
   369 			if (reallyHelp) {
   361 				ObeyFileReader::KeywordHelp();
   370 				ObeyFileReader::KeywordHelp();
   362 				Print (EAlways, ReallyHelpText);
   371 				Print (EAlways, ReallyHelpText);
   363 			}
   372 			}
   364 			else if (filename.empty()){
   373 			else if (filename.empty()){
   365 				Print(EAlways, "Obey filename is missing\n");
   374 				printf("WARNING: Obey filename is missing\n");
   366 			}
   375 			}
   367 	}	
   376 	}	
   368 }
   377 }
   369 
   378 
   370 /**
   379 /**
   494 		gCPUNum = MAXIMUM_THREADS;
   503 		gCPUNum = MAXIMUM_THREADS;
   495 	PrintVersion();
   504 	PrintVersion();
   496 	processCommandLine(argc, argv);
   505 	processCommandLine(argc, argv);
   497 	if(gThreadNum == 0) {
   506 	if(gThreadNum == 0) {
   498 		if(gCPUNum > 0) {
   507 		if(gCPUNum > 0) {
   499 			printf("WARNING: The number of processors (%d) is used as the number of concurrent jobs.\n", gCPUNum);
   508 			printf("The double number of processors (%d) is used as the number of concurrent jobs.\n", gCPUNum * 2);
   500 			gThreadNum = gCPUNum;
   509 			gThreadNum = gCPUNum * 2;
   501 		}
   510 		}
   502 		else {
   511 		else {
   503 			printf("WARNING: Can't automatically get the valid number of concurrent jobs and %d is used.\n", DEFAULT_THREADS);
   512 			printf("Can't automatically get the valid number of concurrent jobs and %d is used.\n", DEFAULT_THREADS);
   504 			gThreadNum = DEFAULT_THREADS;
   513 			gThreadNum = DEFAULT_THREADS;
   505 		}
   514 		}
   506 	}
   515 	}
   507 	if(loginput.length() >= 1)
   516 	if(loginput.length() >= 1)
   508 	{
   517 	{
   509 		try
   518 		try
   510 		{
   519 		{
   511 			LogParser::GetInstance()->ParseSymbol(loginput.c_str());
   520 			LogParser::GetInstance(ERofsImage)->ParseSymbol(loginput.c_str());
   512 		}
   521 		}
   513 		catch(LoggingException le)
   522 		catch(LoggingException le)
   514 		{
   523 		{
   515 			printf("ERROR: %s\r\n", le.GetErrorMessage());
   524 			printf("ERROR: %s\r\n", le.GetErrorMessage());
   516 			return 1;
   525 			return 1;