imgtools/romtools/rombuild/rombuild.cpp
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 // 
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <string.h>
       
    17 #include <stdlib.h>
       
    18 
       
    19 #include "h_utl.h"
       
    20 #include "h_ver.h"
       
    21 
       
    22 #include "r_global.h"
       
    23 #include "r_rom.h"
       
    24 #include "r_obey.h"
       
    25 #include "parameterfileprocessor.h"
       
    26 
       
    27 #include "r_dir.h"
       
    28 #include "r_coreimage.h"
       
    29 
       
    30 const TInt KRomLoaderHeaderNone=0;
       
    31 const TInt KRomLoaderHeaderEPOC=1;
       
    32 const TInt KRomLoaderHeaderCOFF=2;
       
    33 
       
    34 static const TInt RombuildMajorVersion=2;
       
    35 static const TInt RombuildMinorVersion=14;
       
    36 static const TInt RombuildPatchVersion=0;
       
    37 static TBool SizeSummary=EFalse;
       
    38 static TPrintType SizeWhere=EAlways;
       
    39 static char *CompareRom=NULL;
       
    40 static TInt MAXIMUM_THREADS = 128;
       
    41 static TInt DEFAULT_THREADS = 8;
       
    42 
       
    43 string filename;			// to store oby filename passed to Rombuild.
       
    44 TBool reallyHelp=EFalse;
       
    45 TInt gCPUNum = 0;
       
    46 TInt gThreadNum = 0;
       
    47 char* g_pCharCPUNum = NULL;
       
    48 TBool gGenDepGraph = EFalse;
       
    49 char* gDepInfoFile = NULL;
       
    50 
       
    51 void PrintVersion()
       
    52 	{
       
    53 	Print(EAlways,"\nROMBUILD - Rom builder");
       
    54   	Print(EAlways, " V%d.%d.%d\n", RombuildMajorVersion, RombuildMinorVersion, RombuildPatchVersion);
       
    55   	Print(EAlways,Copyright);
       
    56 	}
       
    57 
       
    58 char HelpText[] = 
       
    59 	"Syntax: ROMBUILD [options] obeyfilename\n"
       
    60 	"Option: -v verbose,  -?  \n"
       
    61 	"        -type-safe-link  \n"
       
    62 	"        -s[log|screen|both]           size summary\n"
       
    63 	"        -r<FileName>                  compare a sectioned Rom image\n"
       
    64 	"        -no-header                    suppress the image loader header\n"
       
    65 	"        -gendep                       generate the dependence graph for paged part\n"
       
    66 	"        -coff-header                  use a PE-COFF header rather than an EPOC header\n"
       
    67 	"        -d<bitmask>                   set trace mask (DEB build only)\n"
       
    68 	"        -compress[[=]paged|unpaged]   compress the ROM Image\n"
       
    69 	"									   without any argumentum compress both sections\n"
       
    70 	"									   paged 	compress paged section only\n"
       
    71 	"									   unpaged 	compress unpaged section only\n"	
       
    72 	"        -fastcompress  compress files with faster bytepair and tradeoff of compress ratio\n"
       
    73 	"        -j<digit> do the main job with <digit> threads\n"
       
    74 	"        -compressionmethod <method>   method one of none|inflate|bytepair to set the compression\n"
       
    75 	"        -no-sorted-romfs              do not add sorted entries arrays (6.1 compatible)\n"
       
    76 	"        -geninc                       to generate include file for licensee tools to use\n"			// DEF095619
       
    77 	"        -loglevel<level>              level of information to log (valid levels are 0,1,2,3,4).\n" //Tools like Visual ROM builder need the host/ROM filenames, size & if the file is hidden.
       
    78 	"        -wstdpath                     warn if destination path provided for a file is not a standard path\n"
       
    79 	"        -argfile=<fileName>           specify argument-file name containing list of command-line arguments to rombuild\n"
       
    80 	"        -lowmem                       use memory-mapped file for image build to reduce physical memory consumption\n"
       
    81 	"        -coreimage=<core image file>  to pass the core image as input for extension ROM image generation\n";
       
    82 
       
    83 
       
    84 char ReallyHelpText[] =
       
    85 	"Priorities:\n"
       
    86 	"        low background foreground high windowserver\n"
       
    87 	"        fileserver realtimeserver supervisor\n"
       
    88 	"Languages:\n"
       
    89 	"        Test English French German Spanish Italian Swedish Danish\n"
       
    90 	"        Norwegian Finnish American SwissFrench SwissGerman Portuguese\n"
       
    91 	"        Turkish Icelandic Russian Hungarian Dutch BelgianFlemish\n"
       
    92 	"        Australian BelgianFrench\n"
       
    93 	"Compression methods:\n"
       
    94 	"        none     no compression on the individual executable image.\n"
       
    95 	"        inflate  compress the individual executable image.\n"
       
    96 	"        bytepair compress the individual executable image.\n"
       
    97 	"Log Level:\n"
       
    98 	"        0  produce the default logs\n"
       
    99 	"        1  produce file detail logs in addition to the default logs\n"
       
   100 	"        2  logs e32 header attributes(same as default log) in addition to the level 1 details\n";
       
   101 
       
   102 void processParamfile(string aFileName);
       
   103 
       
   104 void processCommandLine(int argc, char *argv[], TBool paramFileFlag=EFalse)
       
   105 //
       
   106 // Process the command line arguments, printing a helpful message if none are supplied
       
   107 //
       
   108 	{
       
   109 
       
   110 	// If "-argfile" option is passed to Rombuild, then process the parameters
       
   111 	// specified in parameter-file first and then the options passed from the 
       
   112 	// command-line.
       
   113 	string ParamFileArg("-ARGFILE=");	
       
   114 	if(paramFileFlag == EFalse)
       
   115 	{	
       
   116 		for (int count=1; count<argc; count++)
       
   117 		{
       
   118 			string paramFile;
       
   119 			strupr(argv[count]);
       
   120 			if(strncmp(argv[count],ParamFileArg.c_str(),ParamFileArg.length())==0)
       
   121 			{
       
   122 				paramFile.assign(&argv[count][ParamFileArg.length()]);					
       
   123 				processParamfile(paramFile);
       
   124 			}
       
   125 		}
       
   126 	}	
       
   127 	
       
   128 	for (int i=1; i<argc; i++)
       
   129 		{
       
   130 		strupr(argv[i]);
       
   131 		if ((argv[i][0] == '-') || (argv[i][0] == '/'))
       
   132 			{ // switch
       
   133 			if (argv[i][1] == 'V')
       
   134 				H.iVerbose = ETrue;
       
   135 			else if (argv[i][1] == 'S')
       
   136 				{
       
   137 				SizeSummary=ETrue;
       
   138 				if (argv[i][2] == 'L')
       
   139 					SizeWhere=ELog;
       
   140 				if (argv[i][2] == 'S')
       
   141 					SizeWhere=EScreen;
       
   142 				}
       
   143 			else if (strcmp(argv[i], "-FASTCOMPRESS")==0)
       
   144 				gFastCompress = ETrue;
       
   145 			else if (strcmp(argv[i], "-GENDEP")==0)
       
   146 				gGenDepGraph = ETrue;
       
   147 			else if (strncmp(argv[i], "-J", 2)==0)
       
   148 				{
       
   149 					if(argv[i][2])
       
   150 						gThreadNum = atoi(&argv[i][2]);
       
   151 					else
       
   152 						{
       
   153 						Print(EWarning, "The option should be like '-j4'.\n");
       
   154 						gThreadNum = 0;
       
   155 						}
       
   156 					if(gThreadNum <= 0 || gThreadNum > MAXIMUM_THREADS)
       
   157 						{
       
   158 						if(gCPUNum > 0 && gCPUNum <= MAXIMUM_THREADS)
       
   159 							{
       
   160 							Print(EWarning, "The number of concurrent jobs set by -j should be between 1 and 128. And the number of processors %d will be used as the number of concurrent jobs.\n", gCPUNum);
       
   161 							gThreadNum = gCPUNum;
       
   162 							}
       
   163 						else if(g_pCharCPUNum)
       
   164 							{
       
   165 							Print(EWarning, "The number of concurrent jobs set by -j should be between 1 and 128. And the NUMBER_OF_PROCESSORS is invalid, so the default value %d will be used.\n", DEFAULT_THREADS);
       
   166 							gThreadNum = DEFAULT_THREADS;
       
   167 							}
       
   168 						else
       
   169 							{
       
   170 							Print(EWarning, "The number of concurrent jobs set by -j should be between 1 and 128. And the NUMBER_OF_PROCESSORS is not available, so the default value %d will be used.\n", DEFAULT_THREADS);
       
   171 							gThreadNum = DEFAULT_THREADS;
       
   172 							}
       
   173 						}	
       
   174 				}
       
   175 			else if (strncmp(argv[i],ParamFileArg.c_str(),ParamFileArg.length())==0)
       
   176 			{
       
   177 				// If "-argfile" option is specified within parameter-file then process it 
       
   178 				// otherwise ignore the option.
       
   179 				if (paramFileFlag)
       
   180 				{
       
   181 					String paramFile;
       
   182 					paramFile.assign(&argv[i][ParamFileArg.length()]);		
       
   183 					processParamfile(paramFile);
       
   184 				}
       
   185 				else
       
   186 				{
       
   187 					continue;
       
   188 				}
       
   189 			}
       
   190 			else if (argv[i][1] == 'T')
       
   191 				TypeSafeLink=ETrue;
       
   192 			else if (argv[i][1] == '?')
       
   193 				reallyHelp=ETrue;
       
   194 			else if (argv[i][1] == 'R')
       
   195 				CompareRom=strdup(&argv[i][2]);
       
   196 			else if (strcmp(argv[i], "-NO-HEADER")==0)
       
   197 				gHeaderType=KRomLoaderHeaderNone;
       
   198 			else if (strcmp(argv[i], "-EPOC-HEADER")==0)
       
   199 				gHeaderType=KRomLoaderHeaderEPOC;
       
   200 			else if (strcmp(argv[i], "-COFF-HEADER")==0)
       
   201 				gHeaderType=KRomLoaderHeaderCOFF;
       
   202 			else if (strcmp(argv[i], "-COMPRESS")==0)
       
   203 				{				
       
   204 				if( (i+1) >= argc || argv[i+1][0] == '-')
       
   205 					{
       
   206 					// No argument, compress both parts with default compression method
       
   207 					// un-paged part compressed by Deflate
       
   208 					gCompressUnpaged = ETrue;
       
   209 					gCompressUnpagedMethod = KUidCompressionDeflate;					
       
   210 					// paged part compressed by the Bytepiar
       
   211 					gEnableCompress=ETrue;
       
   212 					gCompressionMethod = KUidCompressionBytePair;
       
   213 					}
       
   214 				else 
       
   215 					{
       
   216 					// An argument exists
       
   217 					i++;
       
   218 					strupr(argv[i]);
       
   219 					if( strcmp(argv[i], "PAGED") == 0)
       
   220 						{
       
   221 						gEnableCompress=ETrue;
       
   222 						gCompressionMethod = KUidCompressionBytePair;	
       
   223 						}	
       
   224 					else if( strcmp(argv[i], "UNPAGED") == 0)
       
   225 						{
       
   226 						gCompressUnpaged=ETrue;
       
   227 						gCompressUnpagedMethod = KUidCompressionDeflate;	
       
   228 						}	
       
   229 					else
       
   230 						{
       
   231  						Print (EError, "Unknown -compression argument! Set it to default (no compression)!");
       
   232  						gEnableCompress=EFalse;
       
   233 						gCompressionMethod = 0;
       
   234 						gCompressUnpaged = EFalse;
       
   235 						gCompressUnpagedMethod = 0;					
       
   236 						}
       
   237 					}
       
   238 				}	
       
   239 			else if( strcmp(argv[i], "-COMPRESSIONMETHOD") == 0 )
       
   240 				{
       
   241 				// next argument should be a method
       
   242 				if( (i+1) >= argc || argv[i+1][0] == '-')
       
   243 					{
       
   244 					Print (EError, "Missing compression method! Set it to default (no compression)!");
       
   245 					gEnableCompress=EFalse;
       
   246 					gCompressionMethod = 0;
       
   247 					}
       
   248 				else 
       
   249 					{
       
   250 					i++;
       
   251 					strupr(argv[i]);
       
   252 					if( strcmp(argv[i], "INFLATE") == 0)
       
   253 						{
       
   254 						gEnableCompress=ETrue;
       
   255 						gCompressionMethod = KUidCompressionDeflate;	
       
   256 						}	
       
   257 					else if( strcmp(argv[i], "BYTEPAIR") == 0)
       
   258 						{
       
   259 						gEnableCompress=ETrue;
       
   260 						gCompressionMethod = KUidCompressionBytePair;	
       
   261 						}	
       
   262 					else
       
   263 						{
       
   264  						if( strcmp(argv[i], "NONE") != 0)
       
   265  							{
       
   266  							Print (EError, "Unknown compression method! Set it to default (no compression)!");
       
   267  							}
       
   268  						gEnableCompress=EFalse;
       
   269 						gCompressionMethod = 0;
       
   270 						}
       
   271 					}
       
   272 					
       
   273 				}
       
   274 			else if (strcmp(argv[i], "-NO-SORTED-ROMFS")==0)
       
   275 				gSortedRomFs=EFalse;
       
   276 			else if (strcmp(argv[i], "-GENINC")==0)				// DEF095619
       
   277 				gGenInc=ETrue;
       
   278  			else if (strcmp(argv[i], "-WSTDPATH")==0)			// Warn if destination path provided for a file		
       
   279  				gEnableStdPathWarning=ETrue;					// is not a standard path as per platsec
       
   280 			else if( strcmp(argv[i], "-LOGLEVEL") == 0)
       
   281 				{
       
   282 				// next argument should a be loglevel
       
   283 				if( (i+1) >= argc || argv[i+1][0] == '-')
       
   284 					{
       
   285 					Print (EError, "Missing loglevel!");
       
   286 					gLogLevel = DEFAULT_LOG_LEVEL;
       
   287 					}
       
   288 				else
       
   289 					{
       
   290 					i++;
       
   291 					if (strcmp(argv[i], "4") == 0)
       
   292 						gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO | LOG_LEVEL_SMP_INFO);
       
   293 					else if (strcmp(argv[i], "3") == 0)
       
   294 						gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO);
       
   295 					else if (strcmp(argv[i], "2") == 0)
       
   296 						gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES);
       
   297 					else if (strcmp(argv[i], "1") == 0)
       
   298 						gLogLevel = LOG_LEVEL_FILE_DETAILS;
       
   299 					else if (strcmp(argv[i], "0") == 0)
       
   300 						gLogLevel = DEFAULT_LOG_LEVEL;
       
   301 					else
       
   302 						Print(EError, "Only loglevel 0, 1, 2, 3 or 4 is allowed!");
       
   303 					}
       
   304 				}
       
   305 			else if( strcmp(argv[i], "-LOGLEVEL4") == 0)
       
   306 				gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO | LOG_LEVEL_SMP_INFO);
       
   307 			else if( strcmp(argv[i], "-LOGLEVEL3") == 0)
       
   308 				gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO);
       
   309 			else if( strcmp(argv[i], "-LOGLEVEL2") == 0)
       
   310 				gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES);
       
   311 			else if( strcmp(argv[i], "-LOGLEVEL1") == 0)
       
   312 				gLogLevel = LOG_LEVEL_FILE_DETAILS;
       
   313 			else if( strcmp(argv[i], "-LOGLEVEL0") == 0)
       
   314 				gLogLevel = DEFAULT_LOG_LEVEL;
       
   315 			else if (argv[i][1] == 'D')
       
   316 				{
       
   317 				TraceMask=strtoul(argv[i]+2, 0, 0);
       
   318 				}
       
   319 			else if (strcmp(argv[i], "-LOWMEM") == 0)
       
   320 				gLowMem = ETrue;
       
   321 			else if (strncmp(argv[i], "-COREIMAGE=",11) ==0)
       
   322 			{  
       
   323 				if(argv[i][11])	
       
   324 				{
       
   325 					gUseCoreImage = ETrue; 
       
   326 					gImageFilename = (TText*)strdup(&argv[i][11]);	
       
   327 				}
       
   328 				else
       
   329 				{
       
   330 					Print (EError, "Core ROM image file is missing\n"); 
       
   331 				}
       
   332 			}
       
   333 			else 
       
   334 				cout << "Unrecognised option " << argv[i] << "\n";
       
   335 			}	
       
   336 		else // Must be the obey filename
       
   337 			filename=argv[i];
       
   338 		}
       
   339 	if (paramFileFlag)
       
   340 		return;
       
   341 	if (filename.empty())
       
   342 		{
       
   343 		PrintVersion();
       
   344 		cout << HelpText;
       
   345 		if (reallyHelp)
       
   346 			{
       
   347 			ObeyFileReader::KeywordHelp();
       
   348 			cout << ReallyHelpText;
       
   349 			}
       
   350 		else
       
   351 			Print(EError, "Obey filename is missing\n");
       
   352 		}	
       
   353 	}
       
   354 
       
   355 /**
       
   356 Function to process parameter-file. 
       
   357 
       
   358 @param aFileName parameter-file name.
       
   359 */
       
   360 void processParamfile(string aFileName)
       
   361 {
       
   362 	CParameterFileProcessor parameterFile(aFileName);
       
   363 	
       
   364 	// Invoke fuction "ParameterFileProcessor" to process parameter-file.
       
   365 	if(parameterFile.ParameterFileProcessor())
       
   366 	{		
       
   367 		TUint noOfParameters = parameterFile.GetNoOfArguments();
       
   368 		char** parameters = parameterFile.GetParameters();
       
   369 		TBool paramFileFlag=ETrue;
       
   370 		
       
   371 		// Invoke function "processCommandLine" to process parameters read from parameter-file.
       
   372 		processCommandLine(noOfParameters, parameters, paramFileFlag);
       
   373 	}	
       
   374 }
       
   375 
       
   376 void GenerateIncludeFile(char* aRomName, TInt aUnpagedSize, TInt aPagedSize )
       
   377 	{
       
   378 	
       
   379 	const char * incFileNameExt = ".inc";
       
   380 	
       
   381 	TText* incFileName;
       
   382 	incFileName=new TText[strlen(aRomName) + strlen(incFileNameExt) + 1];  // Place for include file name and ".inc" extension and '\0'
       
   383 	strcpy((char *)incFileName, aRomName);
       
   384 	
       
   385 	char *p = (char*)strrchr((const char *)incFileName, '.');
       
   386 	if( NULL != p)
       
   387 		{
       
   388 		strncpy(p, incFileNameExt, strlen(incFileNameExt) + 1);				// copy extension and the '\0'
       
   389 		}
       
   390 	else
       
   391 		{
       
   392 		strcat((char *)incFileName, incFileNameExt);		//Doesn't cotains extension, add to it.
       
   393 		}
       
   394 		
       
   395 	Print(EAlways," (%s)\n", (const char *)incFileName);
       
   396 	
       
   397 	ofstream incFile((const char*)incFileName, ios::out);
       
   398 	if(!incFile)
       
   399 		{
       
   400 		Print(EError,"Cannot open include file %s for output\n",(const char *)incFileName);		
       
   401 		}
       
   402 	else
       
   403 		{
       
   404 		const char * incContent = 
       
   405 					"/** Size of the unpaged part of ROM.\n"
       
   406 	    			"This part is at the start of the ROM image. */\n"
       
   407 					"#define SYMBIAN_ROM_UNPAGED_SIZE 0x%08x\n"
       
   408 					"\n"
       
   409 					"/** Size of the demand paged part of ROM.\n"
       
   410 	    			"This part is stored immediately after the unpaged part in the ROM image. */\n"
       
   411 					"#define SYMBIAN_ROM_PAGED_SIZE 0x%08x\n";
       
   412 		
       
   413 		TText* temp = new TText[strlen(incContent)+ 2 * 8 + 1]; 	// for place of two hex representated values and '\0'
       
   414 		
       
   415 		sprintf((char *)temp,incContent, aUnpagedSize, aPagedSize);
       
   416 		incFile.write((const char *)temp, strlen((const char *)temp));
       
   417 		
       
   418 		incFile.close();
       
   419 		delete[]  temp;
       
   420 		}
       
   421 	delete[]  incFileName;
       
   422 		
       
   423 	}
       
   424 
       
   425 int main(int argc, char *argv[]) 
       
   426 {
       
   427 	H.SetLogFile((unsigned char *)"ROMBUILD.LOG");
       
   428 	TInt r = 0;
       
   429 	g_pCharCPUNum = getenv("NUMBER_OF_PROCESSORS");
       
   430 	if(g_pCharCPUNum != NULL)
       
   431 		gCPUNum = atoi(g_pCharCPUNum);
       
   432 		
       
   433 	// initialise set of all capabilities
       
   434 	ParseCapabilitiesArg(gPlatSecAllCaps, "all");
       
   435 
       
   436  	processCommandLine(argc, argv);
       
   437  	if(filename.empty())
       
   438    		return KErrGeneral;
       
   439 		
       
   440     if(gThreadNum == 0)
       
   441 	{
       
   442 		if(gCPUNum > 0 && gCPUNum <= MAXIMUM_THREADS)
       
   443 		{
       
   444 			Print(EAlways, "The number of processors (%d) is used as the number of concurrent jobs.\n", gCPUNum);
       
   445 			gThreadNum = gCPUNum;
       
   446 		}
       
   447 		else if(g_pCharCPUNum)
       
   448 		{
       
   449 			Print(EWarning, "The NUMBER_OF_PROCESSORS is invalid, and the default value %d will be used.\n", DEFAULT_THREADS);
       
   450 			gThreadNum = DEFAULT_THREADS;
       
   451 		}
       
   452 		else
       
   453 		{
       
   454 			Print(EWarning, "The NUMBER_OF_PROCESSORS is not available, and the default value %d will be used.\n", DEFAULT_THREADS);
       
   455 			gThreadNum = DEFAULT_THREADS;
       
   456 		}
       
   457 	}
       
   458  	TText *obeyFileName= (TText*)filename.c_str();	
       
   459  
       
   460 	PrintVersion();
       
   461 	
       
   462 	ObeyFileReader *reader=new ObeyFileReader(obeyFileName);
       
   463 	if (!reader->Open())
       
   464 	{
       
   465 		delete reader;
       
   466 		return KErrGeneral;
       
   467 	}
       
   468 	
       
   469 	E32Rom* kernelRom=0;		// for image from obey file
       
   470 	CoreRomImage *core= 0;		// for image from core image file
       
   471 	MRomImage* imageInfo=0;
       
   472 	CObeyFile *mainObeyFile=new CObeyFile(*reader);
       
   473 
       
   474 	// need check if obey file has coreimage keyword
       
   475 	TText *file = mainObeyFile->ProcessCoreImage();
       
   476 	if (file)
       
   477 	{
       
   478 		// hase coreimage keyword but only use if command line option
       
   479 		// for coreimage not already selected
       
   480 		if (!gUseCoreImage)
       
   481 		{
       
   482 			gUseCoreImage = ETrue;
       
   483 			gImageFilename = file;
       
   484 		}
       
   485 	}
       
   486 
       
   487 	if (!gUseCoreImage)
       
   488 	{
       
   489 		r=mainObeyFile->ProcessKernelRom();
       
   490 		if (r==KErrNone)
       
   491 		{
       
   492 				// Build a kernel ROM using the description compiled into the
       
   493 				// CObeyFile object
       
   494 				
       
   495 				kernelRom = new E32Rom(mainObeyFile);
       
   496 				if (kernelRom == 0 || kernelRom->iData == 0)
       
   497 					return KErrNoMemory;
       
   498 				
       
   499 				r=kernelRom->Create();
       
   500 				if (r!=KErrNone)
       
   501 				{
       
   502 					delete kernelRom;
       
   503 					delete mainObeyFile;
       
   504 					return r;
       
   505 				}
       
   506 				if (SizeSummary)
       
   507 					kernelRom->DisplaySizes(SizeWhere);
       
   508 				
       
   509 				r=kernelRom->WriteImages(gHeaderType);
       
   510 				if (r!=KErrNone)
       
   511 				{
       
   512 					delete kernelRom;
       
   513 					delete mainObeyFile;
       
   514 					return r;
       
   515 				}
       
   516 				
       
   517 				if (CompareRom)
       
   518 				{
       
   519 					r=kernelRom->Compare(CompareRom, gHeaderType);
       
   520 					if (r!=KErrNone)
       
   521 					{
       
   522 						delete kernelRom;
       
   523 						delete mainObeyFile;
       
   524 						return r;
       
   525 					}
       
   526 				}
       
   527 				imageInfo = kernelRom;
       
   528 				mainObeyFile->Release();
       
   529 		}
       
   530 		else if (r!=KErrNotFound)
       
   531 			return r;
       
   532 	}
       
   533 	else
       
   534 	{
       
   535 		// need to use core image
       
   536 		core = new CoreRomImage((char*)gImageFilename);
       
   537 		if (!core)
       
   538 		{
       
   539 			return KErrNoMemory;
       
   540 		}
       
   541 		if (!core->ProcessImage(gLowMem))
       
   542 		{
       
   543 			delete core;
       
   544 			delete mainObeyFile;
       
   545 			return KErrGeneral;
       
   546 		}
       
   547 		
       
   548 		NumberOfVariants = core->VariantCount();
       
   549 		TVariantList::SetNumVariants(NumberOfVariants);
       
   550 		TVariantList::SetVariants(core->VariantList());
       
   551 		
       
   552 		core->SetRomAlign(mainObeyFile->iRomAlign);
       
   553 		core->SetDataRunAddress(mainObeyFile->iDataRunAddress);
       
   554 
       
   555 		gCompressionMethod = core->CompressionType();
       
   556 		if(gCompressionMethod)
       
   557 		{
       
   558 			gEnableCompress = ETrue;
       
   559 		}
       
   560 		
       
   561 		imageInfo = core;
       
   562 		if(!mainObeyFile->SkipToExtension())
       
   563 		{
       
   564 			delete core;
       
   565 			delete mainObeyFile;
       
   566 			return KErrGeneral;
       
   567 		}
       
   568 	}
       
   569 	
       
   570 	if(gGenInc)
       
   571 	{
       
   572 		Print(EAlways,"Generating include file for ROM image post-processors ");
       
   573 		if( gPagedRom )
       
   574 		{
       
   575 			Print(EAlways,"Paged ROM");
       
   576 			GenerateIncludeFile((char*)mainObeyFile->iRomFileName, kernelRom->iHeader->iPageableRomStart, kernelRom->iHeader->iPageableRomSize);
       
   577 		}
       
   578 		else
       
   579 		{
       
   580 			Print(EAlways,"Unpaged ROM");
       
   581 			int headersize=(kernelRom->iExtensionRomHeader ? sizeof(TExtensionRomHeader) : sizeof(TRomHeader)) - sizeof(TRomLoaderHeader);
       
   582 			GenerateIncludeFile((char*)mainObeyFile->iRomFileName, kernelRom->iHeader->iCompressedSize + headersize, kernelRom->iHeader->iPageableRomSize);
       
   583 		}
       
   584 	}
       
   585 	
       
   586 	do
       
   587 	{
       
   588 		CObeyFile* extensionObeyFile = 0;
       
   589 		E32Rom* extensionRom = 0;
       
   590 
       
   591 		extensionObeyFile = new CObeyFile(*reader);
       
   592 		r = extensionObeyFile->ProcessExtensionRom(imageInfo);
       
   593 		if (r==KErrEof)
       
   594 		{
       
   595 			delete imageInfo;
       
   596 			delete mainObeyFile;
       
   597 			delete extensionObeyFile;
       
   598 			return KErrNone;
       
   599 		}
       
   600 		if (r!=KErrNone)
       
   601 		{
       
   602 			delete extensionObeyFile;
       
   603 			break;
       
   604 		}
       
   605 		
       
   606 		extensionRom = new E32Rom(extensionObeyFile);
       
   607 		r=extensionRom->CreateExtension(imageInfo);
       
   608 		if (r!=KErrNone)
       
   609 		{
       
   610 			delete extensionRom;
       
   611 			delete extensionObeyFile;
       
   612 			break;
       
   613 		}
       
   614 		if (SizeSummary)
       
   615 			extensionRom->DisplaySizes(SizeWhere);
       
   616 		
       
   617 		r=extensionRom->WriteImages(0);		// always a raw image
       
   618 		
       
   619 		delete extensionRom;
       
   620 		delete extensionObeyFile;
       
   621 	}
       
   622 	while (r==KErrNone);
       
   623 
       
   624 	delete imageInfo;
       
   625 	delete mainObeyFile;
       
   626 	free(gDepInfoFile); 
       
   627 	return r;
       
   628 }