imgtools/romtools/rofsbuild/rofsbuild.cpp
changeset 606 30b30f9da0b7
parent 0 044383f39525
child 607 378360dbbdba
equal deleted inserted replaced
605:122d2b873fd1 606:30b30f9da0b7
     1 /*
     1 /*
     2 * Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: 
    14 * Description: 
    15 * @internalComponent * @released
       
    16 * Rofsbuild mainfile to generate both rofs and data drive image.
       
    17 *
    15 *
    18 */
    16 */
    19 
       
    20 
       
    21 #include <string.h>
    17 #include <string.h>
    22 #include <stdlib.h>
    18 #include <stdlib.h>
    23 #include <f32file.h>
    19 #include <f32file.h>
    24 #include "e32image.h"
    20 #include "e32image.h"
    25 #include "h_utl.h"
    21 #include "h_utl.h"
    28 #include "r_driveimage.h"
    24 #include "r_driveimage.h"
    29 #include "r_driveutl.h"
    25 #include "r_driveutl.h"
    30 #include "r_coreimage.h"
    26 #include "r_coreimage.h"
    31 #include "parameterfileprocessor.h"
    27 #include "parameterfileprocessor.h"
    32 #include "r_smrimage.h"
    28 #include "r_smrimage.h"
       
    29 //cache headers
       
    30 #include "cache/cacheexception.hpp"
       
    31 #include "cache/cacheentry.hpp"
       
    32 #include "cache/cache.hpp"
       
    33 #include "cache/cachegenerator.hpp"
       
    34 #include "cache/cachevalidator.hpp"
       
    35 #include "cache/cacheablelist.hpp"
       
    36 #include "cache/cachemanager.hpp"
       
    37 #include <malloc.h>
       
    38  
       
    39 #ifndef WIN32
       
    40 #include <unistd.h>
       
    41 #include <strings.h>
       
    42 #include <fstream>
       
    43 #define strnicmp strncasecmp
       
    44 #define stricmp strcasecmp
       
    45 #define _alloca alloca
       
    46 #endif
    33 
    47 
    34 static const TInt RofsbuildMajorVersion=2;
    48 static const TInt RofsbuildMajorVersion=2;
    35 static const TInt RofsbuildMinorVersion=6;
    49 static const TInt RofsbuildMinorVersion=12;
    36 static const TInt RofsbuildPatchVersion=5;
    50 static const TInt RofsbuildPatchVersion=0;
    37 static TBool SizeSummary=EFalse;
    51 static TBool SizeSummary=EFalse;
    38 static TPrintType SizeWhere=EAlways;
    52 static TPrintType SizeWhere=EAlways;
    39 
    53 
    40 static TInt gHeaderType=1;			// EPOC header
    54 static TInt gHeaderType=1;			// EPOC header
    41 static TInt MAXIMUM_THREADS = 128;
    55 static TInt MAXIMUM_THREADS = 128;
    42 static TInt DEFAULT_THREADS = 8;
    56 static TInt DEFAULT_THREADS = 8;
    43 ECompression gCompress=ECompressionUnknown;
    57 ECompression gCompress=ECompressionUnknown;
    44 TUint  gCompressionMethod=0;
    58 TUint  gCompressionMethod=0;
    45 TBool gFastCompress = EFalse;
       
    46 TInt gThreadNum = 0;
    59 TInt gThreadNum = 0;
    47 TInt gCPUNum = 0;
    60 TInt gCPUNum = 0;
    48 char* g_pCharCPUNum = NULL;
    61 TBool gGenSymbols = EFalse;
    49 TInt gCodePagingOverride = -1;
    62 TInt gCodePagingOverride = -1;
    50 TInt gDataPagingOverride = -1;
    63 TInt gDataPagingOverride = -1;
    51 TInt gLogLevel = 0;	// Information is logged based on logging level.
    64 TInt gLogLevel = 0;	// Information is logged based on logging level.
    52 					// The default is 0. So all the existing logs are generated as if gLogLevel = 0.
    65 // The default is 0. So all the existing logs are generated as if gLogLevel = 0.
    53 					// If any extra information required, the log level must be appropriately supplied.
    66 // If any extra information required, the log level must be appropriately supplied.
    54 					// Currrently, file details in ROM (like, file name in ROM & host, file size, whether 
    67 // Currrently, file details in ROM (like, file name in ROM & host, file size, whether
    55 					// the file is hidden etc) are logged when gLogLevel >= LOG_LEVEL_FILE_DETAILS.
    68 // the file is hidden etc) are logged when gLogLevel >= LOG_LEVEL_FILE_DETAILS.
    56 
    69 
    57 TBool gUseCoreImage=EFalse; // command line option for using core image file
    70 TBool gUseCoreImage = EFalse; // command line option for using core image file
    58 char* gImageFilename=NULL;	// instead of obey file
    71 string gImageFilename = "";	// instead of obey file
    59 TBool gEnableStdPathWarning=EFalse;// for in-correct destination path warning(executables).
    72 TBool gEnableStdPathWarning = EFalse;// for in-correct destination path warning(executables).
    60 TBool gLowMem=EFalse;
    73 TBool gLowMem = EFalse;
    61 
       
    62 extern TBool gDriveImage;		// to Support data drive image.
    74 extern TBool gDriveImage;		// to Support data drive image.
    63 TText* gDriveFilename=NULL;		// input drive oby filename.
    75 string gDriveFilename = "";		// input drive oby filename.
    64 
       
    65 string filename;				// to store oby filename passed to Rofsbuild.
    76 string filename;				// to store oby filename passed to Rofsbuild.
    66 TBool reallyHelp=EFalse;	
    77 TBool reallyHelp = EFalse;	
    67 
       
    68 TBool gSmrImage = EFalse;
    78 TBool gSmrImage = EFalse;
    69 TText* gSmrFileName = NULL;
    79 string gSmrFileName = "";
    70 
    80 
    71 void PrintVersion()
    81 //Cache global variables
    72 	{
    82 bool gCache = false;
    73 		Print(EAlways,"\nROFSBUILD - Rofs/Datadrive image builder");
    83 bool gCleanCache = false;
    74 		Print(EAlways, " V%d.%d.%d\n", RofsbuildMajorVersion, RofsbuildMinorVersion, RofsbuildPatchVersion);
    84 bool gNoCache = false;
    75 		Print(EAlways,Copyright);
    85 TBool gKeepGoing = EFalse;
    76 	}
    86 void PrintVersion() {
       
    87 	Print(EAlways,"\nROFSBUILD - Rofs/Datadrive image builder");
       
    88 	Print(EAlways, " V%d.%d.%d\n", RofsbuildMajorVersion, RofsbuildMinorVersion, RofsbuildPatchVersion);
       
    89 	Print(EAlways,Copyright);
       
    90 }
    77 
    91 
    78 char HelpText[] = 
    92 char HelpText[] = 
    79 	"Syntax: ROFSBUILD [options] obeyfilename(Rofs)\n"
    93 	"Syntax: ROFSBUILD [options] obeyfilename(Rofs)\n"
    80 	"Option: -v verbose,  -?,  -s[log|screen|both] size summary\n"
    94 	"Option: -v verbose,  -?,  -s[log|screen|both] size summary\n"
    81 	"        -d<bitmask> set trace mask (DEB build only)\n"
    95 	"        -d<bitmask> set trace mask (DEB build only)\n"
    82 	"        -compress   compress executable files where possible\n"
    96 	"        -compress   compress executable files where possible\n"
    83 	"        -fastcompress  compress files with faster bytepair and tradeoff of compress ratio\n"
       
    84 	"        -j<digit> do the main job with <digit> threads\n"
    97 	"        -j<digit> do the main job with <digit> threads\n"
       
    98 	"        -symbols generate symbol file\n"
    85 	"        -compressionmethod none|inflate|bytepair to set the compression\n"
    99 	"        -compressionmethod none|inflate|bytepair to set the compression\n"
    86 	"              none     uncompress the image.\n"
   100 	"              none     uncompress the image.\n"
    87 	"              inflate  compress the image.\n"
   101 	"              inflate  compress the image.\n"
    88 	"              bytepair compress the image.\n"
   102 	"              bytepair compress the image.\n"
    89 	"        -coreimage <core image file>\n"
   103 	"        -coreimage <core image file>\n"
       
   104 	"        -cache allow the ROFSBUILD to reuse/generate cached executable files\n"
       
   105 	"        -nocache force the ROFSBUILD not to reuse/generate cached executable files\n"
       
   106 	"        -cleancache permanently remove all cached executable files\n"
    90 	"        -datadrive=<drive obyfile1>,<drive obyfile2>,... for driveimage creation\n"
   107 	"        -datadrive=<drive obyfile1>,<drive obyfile2>,... for driveimage creation\n"
    91 	"              user can also input rofs oby file if required to generate both.\n"
   108 	"              user can also input rofs oby file if required to generate both.\n"
    92 	"        -smr=<SMR obyfile1>,<SMR obyfile2>,... for SMR partition creation\n"
   109 	"        -smr=<SMR obyfile1>,<SMR obyfile2>,... for SMR partition creation\n"
    93 	"        -loglevel<level>  level of information to log (valid levels are 0,1,2).\n"//Tools like Visual ROM builder need the host/ROM filenames, size & if the file is hidden.
   110 	"        -loglevel<level>  level of information to log (valid levels are 0,1,2).\n"//Tools like Visual ROM builder need the host/ROM filenames, size & if the file is hidden.
    94 	"        -wstdpath   warn if destination path provided for a file is not the standard path\n"
   111 	"        -wstdpath   warn if destination path provided for a file is not the standard path\n"
    95 	"        -argfile=<FileName>   specify argument-file name containing list of command-line arguments\n"
   112 	"        -argfile=<FileName>   specify argument-file name containing list of command-line arguments\n"
    96 	"        -lowmem     use memory-mapped file for image build to reduce physical memory consumption\n";
   113 "        -lowmem     use memory-mapped file for image build to reduce physical memory consumption\n"
       
   114 "        -k     to enable keepgoing when duplicate files exist in oby\n";
    97 
   115 
    98 char ReallyHelpText[] =
   116 char ReallyHelpText[] =
    99 	"Log Level:\n"
   117 "Log Level:\n"
   100 	"        0  produce the default logs\n"
   118 "        0  produce the default logs\n"
   101 	"        1  produce file detail logs in addition to the default logs\n"
   119 "        1  produce file detail logs in addition to the default logs\n"
   102 	"        2  logs e32 header attributes in addition to the level 1 details\n";
   120 "        2  logs e32 header attributes in addition to the level 1 details\n";
   103 
   121 void processParamfile(const string& aFileName);
   104 void processParamfile(string aFileName);
       
   105 
       
   106 /**
   122 /**
   107 Process the command line arguments and prints the helpful message if none are supplied.
   123 Process the command line arguments and prints the helpful message if none are supplied.
   108 @param argc    - No. of argument.
   124 @param argc    - No. of argument.
   109 @param *argv[] - Arguments value.
   125 @param *argv[] - Arguments value.
   110 */ 
   126 */ 
   111 void processCommandLine(int argc, char *argv[], TBool paramFileFlag=EFalse)
   127 void processCommandLine(int argc, char *argv[], TBool paramFileFlag = EFalse) {
   112 {
       
   113 	// If "-argfile" option is passed to rofsbuild, then process the parameters
   128 	// If "-argfile" option is passed to rofsbuild, then process the parameters
   114 	// specified in parameter-file first and then the options passed from the 
   129 	// specified in parameter-file first and then the options passed from the command-line.
   115 	// command-line.
   130 	
   116 	string ParamFileArg("-ARGFILE=");	
   131 	string ParamFileArg("-ARGFILE=");	
   117 	if(paramFileFlag == EFalse)
   132 	if(paramFileFlag == EFalse) {
   118 	{	
   133 		for (int count = 1; count<argc; count++) {
   119 		for (int count=1; count<argc; count++)
       
   120 		{
       
   121 			string paramFile;
   134 			string paramFile;
   122 			strupr(argv[count]);
   135 			//strupr(argv[count]);
   123 			if(strncmp(argv[count],ParamFileArg.c_str(),ParamFileArg.length())==0)
   136 			if(strnicmp(argv[count],ParamFileArg.c_str(),ParamFileArg.length()) == 0) {
   124 			{
       
   125 				paramFile.assign(&argv[count][ParamFileArg.length()]);									
   137 				paramFile.assign(&argv[count][ParamFileArg.length()]);									
   126 				processParamfile(paramFile);
   138 				processParamfile(paramFile);
   127 			}
   139 			}
   128 		}
   140 		}
   129 	}	
   141 	}	
   130 
   142 
   131 	int i=1;
   143 	int i = 1;
   132 	while (i<argc)
   144 	while (i<argc) {		 
   133 		{
   145 #ifdef __LINUX__	
   134 		strupr(argv[i]);
   146 		if (argv[i][0] == '-') 
       
   147 #else
   135 		if ((argv[i][0] == '-') || (argv[i][0] == '/'))
   148 		if ((argv[i][0] == '-') || (argv[i][0] == '/'))
   136 			{ // switch
   149 #endif
   137 			if (argv[i][1] == 'V')
   150 		{ 
       
   151 			// switch
       
   152 			if ((argv[i][1] & 0x20) == 'v')
   138 				H.iVerbose = ETrue;
   153 				H.iVerbose = ETrue;
   139 			else if(strncmp (argv[i], "-SMR=", 5) == 0)
   154 			else if(strnicmp (argv[i], "-SMR=", 5) == 0) {
   140 			{
   155 				if(argv[i][5]) {
   141 				if(argv[i][5])
   156 					gSmrImage = ETrue;
       
   157 					gSmrFileName.assign(&argv[i][5]);
       
   158 				}
       
   159 				else {
       
   160 					Print (EError, "SMR obey file is missing\n");
       
   161 				}
       
   162 			} else if (stricmp(argv[i], "-K") == 0) {
       
   163 				gKeepGoing = ETrue;
       
   164 			}else if (stricmp(argv[i], "-SYMBOLS") == 0) {
       
   165 				gGenSymbols = ETrue;
       
   166 			}
       
   167 			else if (((argv[i][1] | 0x20) == 's') &&  
       
   168 				(((argv[i][2]| 0x20) == 'l')||((argv[i][2] | 0x20) == 's'))) {
       
   169 					SizeSummary = ETrue;
       
   170 					if ((argv[i][2]| 0x20) == 'l')
       
   171 						SizeWhere = ELog;
       
   172 					else
       
   173 						SizeWhere = EScreen;
       
   174 			}
       
   175 			else if (strnicmp(argv[i],ParamFileArg.c_str(),ParamFileArg.length()) == 0) {
       
   176 				if (paramFileFlag){
       
   177 					string paramFile;
       
   178 					paramFile.assign(&argv[i][ParamFileArg.length()]);		
       
   179 					processParamfile(paramFile);
       
   180 				}
       
   181 				else {
       
   182 					i++;
       
   183 					continue;
       
   184 				}
       
   185 			}
       
   186 			else if (stricmp(argv[i], "-COMPRESS") == 0) {
       
   187 				gCompress = ECompressionCompress;
       
   188 				gCompressionMethod = KUidCompressionDeflate;
       
   189 			}
       
   190 			else if(stricmp(argv[i], "-CACHE") == 0) {
       
   191 				gCache = true;
       
   192 				if(gCleanCache || gNoCache) {
       
   193 					printf("Cache command line options are mutually exclusive, only one option can be used at a time\n");
       
   194 					exit(1);
       
   195 				}
       
   196 			}
       
   197 			else if(stricmp(argv[i], "-NOCACHE") == 0) {
       
   198 				gNoCache = true;
       
   199 				if(gCleanCache || gCache) {
       
   200 					printf("Cache command line options are mutually exclusive, only one option can be used at a time\n");
       
   201 					exit(1);
       
   202 				}
       
   203 			}
       
   204 			else if(stricmp(argv[i], "-CLEANCACHE") == 0) {
       
   205 				gCleanCache = true;
       
   206 				if(gCache || gNoCache)
   142 				{
   207 				{
   143 					gSmrImage = ETrue;
   208 					printf("Cache command line options are mutually exclusive, only one option can be used at a time\n");
   144 					gSmrFileName = (TText*)strdup(&argv[i][5]);
   209 					exit(1);
   145 				}
   210 				}
   146 				else
   211 			}
   147 				{
   212 			else if (strnicmp(argv[i], "-J",2) == 0) {
   148 					Print (EError, "SMR obey file is missing\n");
   213 				if(argv[i][2])
   149 				}
   214 					gThreadNum = atoi(&argv[i][2]);
   150 			}
   215 				else {
   151 			else if (argv[i][1] == 'S')
   216 					printf("WARNING: The option should be like '-j4'.\n");
   152 				{
   217 					gThreadNum = 0;
   153 				SizeSummary=ETrue;
   218 				}
   154 				if (argv[i][2] == 'L')
   219 				if(gThreadNum <= 0 || gThreadNum > MAXIMUM_THREADS) {
   155 					SizeWhere=ELog;
   220 					printf("WARNING: The number of concurrent jobs set by -j should be between 1 and 128. ");
   156 				if (argv[i][2] == 'S')
   221 					if(gCPUNum > 0) {
   157 					SizeWhere=EScreen;
   222 						printf("WARNING: The number of processors %d is used as the number of concurrent jobs.\n", gCPUNum);
   158 				}
   223 						gThreadNum = gCPUNum;
   159 			else if (strncmp(argv[i],ParamFileArg.c_str(),ParamFileArg.length())==0)
       
   160 				{
       
   161 					if (paramFileFlag)
       
   162 					{
       
   163 						String paramFile;
       
   164 						paramFile.assign(&argv[i][ParamFileArg.length()]);		
       
   165 						processParamfile(paramFile);
       
   166 					}
   224 					}
   167 					else
   225 					else {
   168 					{
   226 						printf("WARNING: Can't automatically get the valid number of concurrent jobs and %d is used.\n", DEFAULT_THREADS);
   169 						i++;
   227 						gThreadNum = DEFAULT_THREADS;
   170 						continue;
       
   171 					}
   228 					}
   172 				}
   229 				}
   173 			else if (strcmp(argv[i], "-COMPRESS")==0)
   230 			}
   174 				{
   231 			else if (stricmp(argv[i], "-UNCOMPRESS") == 0) {
   175 				gCompress=ECompressionCompress;
   232 				gCompress = ECompressionUncompress;
   176 				gCompressionMethod = KUidCompressionDeflate;
   233 			}
   177 				}
   234 			else if( stricmp(argv[i], "-COMPRESSIONMETHOD") == 0 ) {
   178 			else if (strcmp(argv[i], "-FASTCOMPRESS")==0)
   235 				// next argument should a be method
   179 				{
   236 				if( (i+1) >= argc || argv[i+1][0] == '-') {
   180 				gFastCompress=ETrue;
       
   181 				}
       
   182 			else if (strncmp(argv[i], "-J",2)==0)
       
   183 				{
       
   184 					if(argv[i][2])
       
   185 						gThreadNum = atoi(&argv[i][2]);
       
   186 					else
       
   187 						{
       
   188 						printf("WARNING: The option should be like '-j4'.\n");
       
   189 						gThreadNum = 0;
       
   190 						}
       
   191 					if(gThreadNum <= 0 || gThreadNum > MAXIMUM_THREADS)
       
   192 						{
       
   193 						if(gCPUNum > 0 && gCPUNum <= MAXIMUM_THREADS)
       
   194 							{
       
   195 							printf("WARNING: 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);
       
   196 							gThreadNum = gCPUNum;
       
   197 							}
       
   198 						else if(g_pCharCPUNum)
       
   199 							{
       
   200 							printf("WARNING: 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);
       
   201 							gThreadNum = DEFAULT_THREADS;
       
   202 							}
       
   203 						else
       
   204 							{
       
   205 							printf("WARNING: 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);
       
   206 							gThreadNum = DEFAULT_THREADS;
       
   207 							}
       
   208 						}
       
   209 				}
       
   210 			else if (strcmp(argv[i], "-UNCOMPRESS")==0)
       
   211 				{
       
   212 				gCompress=ECompressionUncompress;
       
   213 				}
       
   214 			else if( strcmp(argv[i], "-COMPRESSIONMETHOD") == 0 )
       
   215 				{
       
   216 					// next argument should a be method
       
   217 					if( (i+1) >= argc || argv[i+1][0] == '-') 
       
   218 					{
       
   219 					Print (EError, "Missing compression method! Set it to default (no compression)!");
   237 					Print (EError, "Missing compression method! Set it to default (no compression)!");
   220 					gCompressionMethod = 0;
   238 					gCompressionMethod = 0;
       
   239 				}
       
   240 				else {
       
   241 					i++;					
       
   242 					if( stricmp(argv[i], "NONE") == 0) {
       
   243 						gCompress = ECompressionUncompress;
       
   244 						gCompressionMethod = 0;	
   221 					}
   245 					}
   222 					else 
   246 					else if( stricmp(argv[i], "INFLATE") == 0) {
   223 					{
   247 						gCompress = ECompressionCompress;
       
   248 						gCompressionMethod = KUidCompressionDeflate;	
       
   249 					}	
       
   250 					else if( stricmp(argv[i], "BYTEPAIR") == 0) {
       
   251 						gCompress = ECompressionCompress;
       
   252 						gCompressionMethod = KUidCompressionBytePair;	
       
   253 					}
       
   254 					else {
       
   255 						Print (EError, "Unknown compression method! Set it to default (no compression)!");
       
   256 						gCompress = ECompressionUnknown;
       
   257 						gCompressionMethod = 0;		
       
   258 					}
       
   259 				}
       
   260 
       
   261 			}
       
   262 			else if (stricmp(argv[i], "-COREIMAGE") == 0) {
       
   263 				
       
   264 				gUseCoreImage = ETrue;
       
   265 				// next argument should be image filename
       
   266 				if ((i+1 >= argc) || argv[i+1][0] == '-')
       
   267 					Print (EError, "Missing image file name");
       
   268 				else {
   224 					i++;
   269 					i++;
   225 					strupr(argv[i]);
   270 					gImageFilename.assign(argv[i]);
   226 					if( strcmp(argv[i], "NONE") == 0)	
   271 				}
   227 						{
   272 			}
   228 						gCompress=ECompressionUncompress;
   273 			else if (strnicmp(argv[i], "-DATADRIVE=",11) == 0){  
   229 						gCompressionMethod = 0;	
   274 				if(argv[i][11])	{
   230 						}
   275 					gDriveImage = ETrue; 
   231 					else if( strcmp(argv[i], "INFLATE") == 0)
   276 					gDriveFilename.assign(&argv[i][11]);	
   232 						{
   277 				}
   233 						gCompress=ECompressionCompress;
   278 				else {
   234 						gCompressionMethod = KUidCompressionDeflate;	
   279 					Print (EError, "Drive obey file is missing\n"); 
   235 						}	
   280 				}
   236 					else if( strcmp(argv[i], "BYTEPAIR") == 0)
   281 			}
   237 						{
   282 			else if (argv[i][1] == '?') {
   238 						gCompress=ECompressionCompress;
   283 				reallyHelp = ETrue;
   239 						gCompressionMethod = KUidCompressionBytePair;	
   284 			}
   240 						}
   285 			else if (stricmp(argv[i], "-WSTDPATH") == 0)	{	// Warn if destination path provided for a executables are incorrect as per platsec.		
   241 					else
   286 				gEnableStdPathWarning = ETrue;						
   242 						{
   287 			}
   243 						Print (EError, "Unknown compression method! Set it to default (no compression)!");
   288 			else if( stricmp(argv[i], "-LOGLEVEL") == 0) {
   244 						gCompress=ECompressionUnknown;
       
   245 						gCompressionMethod = 0;		
       
   246 						}
       
   247 					}
       
   248 					
       
   249 				}
       
   250 			else if (strcmp(argv[i], "-COREIMAGE") ==0)
       
   251 				{
       
   252 					gUseCoreImage = ETrue;
       
   253 
       
   254 					// next argument should be image filename
       
   255 					if ((i+1 >= argc) || argv[i+1][0] == '-')
       
   256 						Print (EError, "Missing image file name");
       
   257 					else
       
   258 					{
       
   259 						i++;
       
   260 						gImageFilename = strdup(argv[i]);
       
   261 					}
       
   262 				}
       
   263 			else if (strncmp(argv[i], "-DATADRIVE=",11) ==0)
       
   264 				{  
       
   265 				   	if(argv[i][11])	
       
   266 						{
       
   267 						gDriveImage = ETrue; 
       
   268 						gDriveFilename = (TText*)strdup(&argv[i][11]);	
       
   269 						}
       
   270 					else
       
   271 						{
       
   272 						Print (EError, "Drive obey file is missing\n"); 
       
   273 						}
       
   274 				}
       
   275 			else if (argv[i][1] == '?')
       
   276 				{
       
   277 				reallyHelp=ETrue;
       
   278 				}
       
   279  			else if (strcmp(argv[i], "-WSTDPATH") ==0)		// Warn if destination path provided for a executables are incorrect as per platsec.		
       
   280  				{
       
   281  				gEnableStdPathWarning=ETrue;						
       
   282  				}
       
   283 			
       
   284 			else if( strcmp(argv[i], "-LOGLEVEL") == 0)
       
   285 				{
       
   286 				// next argument should a be loglevel
   289 				// next argument should a be loglevel
   287 				if( (i+1) >= argc || argv[i+1][0] == '-')
   290 				if( (i+1) >= argc || argv[i+1][0] == '-') {
   288 					{
       
   289 					Print (EError, "Missing loglevel!");
   291 					Print (EError, "Missing loglevel!");
   290 					gLogLevel = DEFAULT_LOG_LEVEL;
   292 					gLogLevel = DEFAULT_LOG_LEVEL;
   291 					}
   293 				}
   292 				else
   294 				else {
   293 					{
       
   294 					i++;
   295 					i++;
   295 					if (strcmp(argv[i], "2") == 0)
   296 					if (strcmp(argv[i], "2") == 0)
   296 						gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES);
   297 						gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES);
   297 					if (strcmp(argv[i], "1") == 0)
   298 					if (strcmp(argv[i], "1") == 0)
   298 						gLogLevel = LOG_LEVEL_FILE_DETAILS;
   299 						gLogLevel = LOG_LEVEL_FILE_DETAILS;
   299 					else if (strcmp(argv[i], "0") == 0)
   300 					else if (strcmp(argv[i], "0") == 0)
   300 						gLogLevel = DEFAULT_LOG_LEVEL;
   301 						gLogLevel = DEFAULT_LOG_LEVEL;
   301 					else
   302 					else
   302 						Print(EError, "Only loglevel 0, 1 or 2 is allowed!");
   303 						Print(EError, "Only loglevel 0, 1 or 2 is allowed!");
   303 					}
   304 				}
   304 				}
   305 			}
   305 			else if( strcmp(argv[i], "-LOGLEVEL2") == 0)
   306 			else if( stricmp(argv[i], "-LOGLEVEL2") == 0)
   306 				gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES);
   307 				gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES);
   307 			else if( strcmp(argv[i], "-LOGLEVEL1") == 0)
   308 			else if( stricmp(argv[i], "-LOGLEVEL1") == 0)
   308 				gLogLevel = LOG_LEVEL_FILE_DETAILS;
   309 				gLogLevel = LOG_LEVEL_FILE_DETAILS;
   309 			else if( strcmp(argv[i], "-LOGLEVEL0") == 0)
   310 			else if( stricmp(argv[i], "-LOGLEVEL0") == 0)
   310 				gLogLevel = DEFAULT_LOG_LEVEL;
   311 				gLogLevel = DEFAULT_LOG_LEVEL;
   311 			else if (strcmp(argv[i], "-LOWMEM") == 0)
   312 			else if (stricmp(argv[i], "-LOWMEM") == 0)
   312 				gLowMem = ETrue;
   313 				gLowMem = ETrue;
   313 			else 
   314 			else {
   314 				cout << "Unrecognised option " << argv[i] << "\n";
   315 #ifdef WIN32
   315 			}
   316 				Print (EWarning, "Unrecognised option %s\n",argv[i]);
       
   317 #else
       
   318 				if(0 == access(argv[i],R_OK)){
       
   319 					filename.assign(argv[i]);
       
   320 				}
       
   321 				else {
       
   322 					Print (EWarning, "Unrecognised option %s\n",argv[i]);
       
   323 				}
       
   324 #endif				
       
   325 
       
   326 			}
       
   327 		}
   316 		else // Must be the obey filename
   328 		else // Must be the obey filename
   317 			filename=argv[i];
   329 			filename.assign(argv[i]);
   318 		i++;
   330 		i++;
   319 		}
   331 	}
   320 	
   332 
   321 		if (paramFileFlag)
   333 	if (paramFileFlag)
   322 		return;
   334 		return;
   323 
   335 
   324 		if((gDriveImage == EFalse) && (gSmrImage ==  EFalse) && (filename.empty() || (gUseCoreImage && gImageFilename == NULL)))
   336 	if((gDriveImage == EFalse) && (gSmrImage ==  EFalse) && 
   325 		{
   337 		(filename.empty() || (gUseCoreImage && gImageFilename.length() == 0))){
   326 		PrintVersion();
   338 			Print (EAlways, HelpText);
   327 		cout << HelpText;
   339 			if (reallyHelp) {
   328 		if (reallyHelp)
   340 				ObeyFileReader::KeywordHelp();
   329 			{
   341 				Print (EAlways, ReallyHelpText);
   330 			ObeyFileReader::KeywordHelp();
   342 			}
   331 			cout << ReallyHelpText;
   343 			else if (filename.empty()){
   332 			}
   344 				Print(EAlways, "Obey filename is missing\n");
   333 		else if (filename.empty())
   345 			}
   334 			{
   346 	}	
   335 			Print(EError, "Obey filename is missing\n");
   347 }
   336 			}
       
   337 		}	
       
   338 	}
       
   339 
   348 
   340 /**
   349 /**
   341 Function to process parameter-file. 
   350 Function to process parameter-file.
   342 
       
   343 @param aFileName parameter-file name.
   351 @param aFileName parameter-file name.
   344 */
   352 */
   345 void processParamfile(string aFileName)
   353 void processParamfile(const string& aFileName) {
   346 {
   354 
   347 	CParameterFileProcessor parameterFile(aFileName);
   355 	CParameterFileProcessor parameterFile(aFileName);
   348 	
       
   349 	// Invoke fuction "ParameterFileProcessor" to process parameter-file.
   356 	// Invoke fuction "ParameterFileProcessor" to process parameter-file.
   350 	if(parameterFile.ParameterFileProcessor())
   357 	if(parameterFile.ParameterFileProcessor()) {
   351 	{
       
   352 		TUint noOfParameters = parameterFile.GetNoOfArguments();
   358 		TUint noOfParameters = parameterFile.GetNoOfArguments();
   353 		char** parameters = parameterFile.GetParameters();
   359 		char** parameters = parameterFile.GetParameters();
   354 		TBool paramFileFlag=ETrue;
   360 		TBool paramFileFlag = ETrue;
   355 
   361 
   356 		// Invoke function "processCommandLine" to process parameters read from parameter-file.
   362 		// Invoke function "processCommandLine" to process parameters read from parameter-file.
   357 		processCommandLine(noOfParameters,parameters,paramFileFlag);
   363 		processCommandLine(noOfParameters,parameters,paramFileFlag);
   358 	}	
   364 	}	
   359 }
   365 }
   361 /**
   367 /**
   362 Main logic for data drive image creation. Called many types depending on no. of drive obey files.
   368 Main logic for data drive image creation. Called many types depending on no. of drive obey files.
   363 
   369 
   364 @param aobeyFileName - Drive obey file.
   370 @param aobeyFileName - Drive obey file.
   365 @param alogfile      - log file name required for file system module.
   371 @param alogfile      - log file name required for file system module.
   366  
   372 
   367 @return - returns the status, after processing the drive obey file.
   373 @return - returns the status, after processing the drive obey file.
   368 */ 
   374 */ 
   369 TInt ProcessDataDriveMain(TText* aobeyFileName,TText* alogfile)
   375 TInt ProcessDataDriveMain(char* aobeyFileName,char* alogfile) {
   370 	{
   376 
   371 
   377 	ObeyFileReader *reader = new ObeyFileReader(aobeyFileName);
   372 	ObeyFileReader *reader=new ObeyFileReader(aobeyFileName);
       
   373 
   378 
   374 	if(!reader)
   379 	if(!reader)
   375 		return KErrNoMemory;
   380 		return KErrNoMemory;
   376 
   381 
   377 	if(!reader->Open())
   382 	if(!reader->Open())
   378     {
   383 		return KErrGeneral; 
   379         if (reader)
   384 		
   380         {
   385 	CObeyFile* mainObeyFile = new CObeyFile(*reader);    
   381             delete reader;
   386 	
   382         }
       
   383 		return KErrGeneral;
       
   384     }
       
   385 
       
   386 	TInt retstatus =0;		
       
   387 	CObeyFile* mainObeyFile=new CObeyFile(*reader);   
       
   388 	CDriveImage* userImage = 0; 
       
   389 
       
   390 	if(!mainObeyFile)
   387 	if(!mainObeyFile)
   391     {
       
   392         if (reader)
       
   393         {
       
   394             delete reader;
       
   395         }
       
   396 		return KErrNoMemory;
   388 		return KErrNoMemory;
   397     }
       
   398 
   389 
   399 	// Process data drive image.
   390 	// Process data drive image.
   400 	// let's clear the TRomNode::sDefaultInitialAttr first, 'cause data drive is different from rom image
   391 	// let's clear the TRomNode::sDefaultInitialAttr first, 'cause data drive is different from rom image
   401 	TRomNode::sDefaultInitialAttr = 0; 
   392 	TRomNode::sDefaultInitialAttr = 0; 
   402 	retstatus = mainObeyFile->ProcessDataDrive();
   393 	TInt retstatus = mainObeyFile->ProcessDataDrive();
   403 	if (retstatus == KErrNone)
   394 	if (retstatus == KErrNone) {
   404 		{
       
   405 		// Build a Data drive image using the description compiled into the CObeyFile object
   395 		// Build a Data drive image using the description compiled into the CObeyFile object
   406 		userImage = new CDriveImage(mainObeyFile);
   396 		CDriveImage* userImage = new CDriveImage(mainObeyFile);
   407 		if(userImage)
   397 		if(userImage) {	
   408 			{	
       
   409 			// Drive image creation.
   398 			// Drive image creation.
   410 			retstatus = userImage->CreateImage(alogfile);
   399 			retstatus = userImage->CreateImage(alogfile);
   411 			if(retstatus == KErrNone)
   400 			if(retstatus == KErrNone) {
   412 				{
   401 				Print (EAlways, "\nSuccessfully generated the Drive image : %s \n",mainObeyFile->iDriveFileName);
   413 				cout << "\nSuccessfully generated the Drive image : " << mainObeyFile->iDriveFileName << "\n";
   402 			}
   414 				}
   403 			else {
   415 			else
   404 				Print (EError, "Failed to generate the Image : %s\n",mainObeyFile->iDriveFileName);
   416 				{
   405 			}
   417 				cout << "\nFailed to generate the Image : " << mainObeyFile->iDriveFileName << "\n";
   406 			delete userImage; 
   418 				}
   407 		}
   419 
   408 		else {
   420 			delete userImage;
       
   421 			userImage = 0;
       
   422 			}
       
   423 		else
       
   424 			{
       
   425 			retstatus = KErrNoMemory;
   409 			retstatus = KErrNoMemory;
   426 			}
   410 		}
   427 		}
   411 	}
   428 	// restore
   412 	// restore
   429 	TRomNode::sDefaultInitialAttr = (TUint8)KEntryAttReadOnly;
   413 	TRomNode::sDefaultInitialAttr = (TUint8)KEntryAttReadOnly;
   430 	cout << "\n-----------------------------------------------------------\n";
   414 	cout << "\n-----------------------------------------------------------\n";
   431 	
   415 
   432 	delete mainObeyFile;
   416 	delete mainObeyFile;
   433 	delete reader;
   417 	delete reader;
   434 	return retstatus;
   418 	return retstatus;
   435 	}
   419 }
   436 
   420 
   437 TInt ProcessSmrImageMain(TText* aObeyFileName, TText* /* alogfile */)
   421 TInt ProcessSmrImageMain(char* aObeyFileName, char* /* alogfile */) {
   438 {
       
   439 	ObeyFileReader *reader = new ObeyFileReader(aObeyFileName);
   422 	ObeyFileReader *reader = new ObeyFileReader(aObeyFileName);
   440 	if(!reader)
   423 	if(!reader)
   441 		return KErrNoMemory;
   424 		return KErrNoMemory;
   442 	if(!reader->Open())
   425 	if(!reader->Open())
   443     {
       
   444         if (reader)
       
   445         {
       
   446             delete reader;
       
   447         }
       
   448 		return KErrGeneral;
   426 		return KErrGeneral;
   449     }
       
   450 	TInt retstatus = 0;
   427 	TInt retstatus = 0;
   451 	CObeyFile* mainObeyFile = new CObeyFile(*reader);
   428 	CObeyFile* mainObeyFile = new CObeyFile(*reader);
   452 	CSmrImage* smrImage = 0;
   429 	CSmrImage* smrImage = 0;
   453 	if(!mainObeyFile)
   430 	if(!mainObeyFile)
   454     {
       
   455         if (reader)
       
   456         {
       
   457             delete reader;
       
   458         }
       
   459 		return KErrNoMemory;
   431 		return KErrNoMemory;
   460     }
   432 	if(mainObeyFile->Process()) {
   461 
       
   462 	if(mainObeyFile->Process())
       
   463 	{
       
   464 		smrImage = new CSmrImage(mainObeyFile);
   433 		smrImage = new CSmrImage(mainObeyFile);
   465 		if(smrImage)
   434 		if(smrImage) {
   466 		{
   435 			if((retstatus = smrImage->Initialise()) == KErrNone) {
   467 			if((retstatus=smrImage->Initialise()) == KErrNone)
       
   468 			{
       
   469 				retstatus = smrImage->CreateImage();
   436 				retstatus = smrImage->CreateImage();
   470 			}
   437 			}
   471 			if(retstatus == KErrNone)
   438 			if(retstatus == KErrNone) {
   472 			{
   439 				Print (EAlways,  "\nSuccessfully generated the SMR image : %s\n" ,smrImage->GetImageName().c_str());
   473 				cout << "\nSuccessfully generated the SMR image : " << smrImage->GetImageName().c_str() << "\n";
   440 			}
   474 			}
   441 			else {
   475 			else
   442 				Print (EError, "\nFailed to generate the Image : %s\n" ,smrImage->GetImageName().c_str());
   476 			{
       
   477 				cout << "\nFailed to generate the Image : " << smrImage->GetImageName().c_str() << "\n";
       
   478 			}
   443 			}
   479 			delete smrImage;
   444 			delete smrImage;
   480 		}
   445 		}
   481 		else
   446 		else {
   482 		{
       
   483 			retstatus = KErrNoMemory;
   447 			retstatus = KErrNoMemory;
   484 		}
   448 		}
   485 	}
   449 	}
   486 	delete mainObeyFile;
   450 	delete mainObeyFile;
   487 	delete reader;
   451 	delete reader;
   491 /**
   455 /**
   492 Rofsbuild Main function, which creates both Rofs and Data drive image.
   456 Rofsbuild Main function, which creates both Rofs and Data drive image.
   493 
   457 
   494 @param argc    - No. of argument.
   458 @param argc    - No. of argument.
   495 @param *argv[] - Arguments value.
   459 @param *argv[] - Arguments value.
   496   
   460 
   497 @return - returns the status to caller.
   461 @return - returns the status to caller.
   498 */ 
   462 */ 
   499 TInt main(int argc, char *argv[])
   463 TInt main(int argc, char *argv[]){
   500 {
   464 	TInt r =0;
   501 	TInt r =0;	
   465 #ifdef __LINUX__
   502 
   466 	gCPUNum = sysconf(_SC_NPROCESSORS_CONF);
   503 	g_pCharCPUNum = getenv("NUMBER_OF_PROCESSORS");
   467 #else	
   504 	if(g_pCharCPUNum != NULL)
   468 	char* pCPUNum = getenv ("NUMBER_OF_PROCESSORS");
   505 		gCPUNum = atoi(g_pCharCPUNum);
   469 	if (pCPUNum != NULL)
   506 
   470 		gCPUNum = atoi(pCPUNum);
   507  	processCommandLine(argc, argv);
   471 #endif		
   508 
   472 	if(gCPUNum > MAXIMUM_THREADS)
   509  	TText *obeyFileName = NULL;	
   473 		gCPUNum = MAXIMUM_THREADS;
   510  	if(!filename.empty())
   474 	PrintVersion();
   511  		obeyFileName=(TText*)filename.c_str();	
   475 	processCommandLine(argc, argv);
   512 
   476 	//if the user wants to clean up the cache, do it only.
   513 	if ((obeyFileName==NULL) && (gDriveFilename==NULL) && (gSmrFileName == NULL))                   
   477 	if(gCleanCache){
       
   478 		try {
       
   479 			CacheManager::GetInstance()->CleanCache();
       
   480 			Print (EAlways, "Cache has been deleted successfully.\n");
       
   481 		}
       
   482 		catch(CacheException& ce){
       
   483 			Print (EError, "%s\n", ce.GetErrorMessage());
       
   484 			return (TInt)1;
       
   485 		}
       
   486 		return r;
       
   487 	}
       
   488 	//initialize cache if the user switches on.
       
   489 	if(gCache) {
       
   490 		try {
       
   491 			CacheManager::GetInstance();
       
   492 		}
       
   493 		catch(CacheException ce){
       
   494 			Print (EError, "%s\n", ce.GetErrorMessage());
       
   495 			return (TInt)1;
       
   496 		}
       
   497 	}
       
   498 	const char *obeyFileName = 0;	
       
   499 	if(!filename.empty())
       
   500 		obeyFileName = filename.c_str(); 
       
   501 	if ((!obeyFileName) && (!gDriveFilename.empty()) && (!gSmrFileName.empty())){
   514 		return KErrGeneral;
   502 		return KErrGeneral;
   515 	
   503 	}
   516 	if(gThreadNum == 0)
   504 	if(gThreadNum == 0) {
   517 	{
   505 		if(gCPUNum > 0) {
   518 		if(gCPUNum > 0 && gCPUNum <= MAXIMUM_THREADS)
   506 			Print (EWarning, "The number of processors (%d) is used as the number of concurrent jobs.\n", gCPUNum);
   519 		{
       
   520 			printf("The number of processors (%d) is used as the number of concurrent jobs.\n", gCPUNum);
       
   521 			gThreadNum = gCPUNum;
   507 			gThreadNum = gCPUNum;
   522 		}
   508 		}
   523 		else if(g_pCharCPUNum)
   509 		else {
   524 		{
   510 			Print (EWarning, "Can't automatically get the valid number of concurrent jobs and %d is used.\n", DEFAULT_THREADS);
   525 			printf("WARNING: The NUMBER_OF_PROCESSORS is invalid, and the default value %d will be used.\n", DEFAULT_THREADS);
       
   526 			gThreadNum = DEFAULT_THREADS;
   511 			gThreadNum = DEFAULT_THREADS;
   527 		}
   512 		}
   528 		else
   513 	}
   529 		{
       
   530 			printf("WARNING: The NUMBER_OF_PROCESSORS is not available, and the default value %d will be used.\n", DEFAULT_THREADS);
       
   531 			gThreadNum = DEFAULT_THREADS;
       
   532 		}
       
   533 	}
       
   534 
       
   535 	// Process drive obey files.
   514 	// Process drive obey files.
   536 	if(gDriveImage)
   515 	if(gDriveImage) {  
   537 	{  
   516 		char temp = 0;
   538 		TText temp = 0;
   517 		char *driveobeyFileName = (char*)_alloca(gDriveFilename.length() + 1);
   539 		TText *driveobeyFileName = gDriveFilename;
   518 		memcpy(driveobeyFileName,gDriveFilename.c_str(),gDriveFilename.length() + 1);
   540 		
   519 		char* ptr = driveobeyFileName;
   541 		do
   520 		do {
   542 		{
   521 			while(((temp = *ptr++) != ',') && (temp != 0));
   543 			while(((temp = *gDriveFilename++) != ',') && (temp != 0));
   522 			*(--ptr)++ = 0; 
   544 			*(--gDriveFilename)++ = 0;
   523 
   545 			
   524 			if(*driveobeyFileName) {
   546 			if(*driveobeyFileName)
   525 				char* logfile = 0;
   547 			{	
   526 				if(Getlogfile(driveobeyFileName,logfile) == KErrNone) {
   548 				TText* logfile = 0;
   527 					H.SetLogFile(logfile);
   549 				if(Getlogfile(driveobeyFileName,logfile)== KErrNone)
       
   550 				{
       
   551 					H.SetLogFile(logfile);	
       
   552 					PrintVersion();
       
   553 					GetLocalTime();
   528 					GetLocalTime();
   554 					r = ProcessDataDriveMain(driveobeyFileName,logfile);   
   529 					r = ProcessDataDriveMain(driveobeyFileName,logfile);   
   555 					H.CloseLogFile();
   530 					H.CloseLogFile();
   556 					delete[] logfile;
   531 					delete[] logfile;
   557 					if(r == KErrNoMemory)
   532 					if(r == KErrNoMemory)
   558 						return KErrNoMemory;
   533 						return KErrNoMemory;
   559 				}
   534 				}
   560 				else
   535 				else {
   561 				{
   536 					Print(EError,"Invalid obey file name : %s\n", driveobeyFileName);   
   562 					cout << "Error : Invalid obey file name : " << driveobeyFileName << "\n" ;   
   537 				}
   563 				}
   538 			}
   564 			}
   539 			driveobeyFileName = ptr;
   565 			driveobeyFileName = gDriveFilename;
   540 		} while(temp != 0); 
   566 		}
   541 		gDriveImage = EFalse;
   567 		while(temp != 0);   
       
   568 		
       
   569 		gDriveImage=EFalse;
       
   570 	} 
   542 	} 
   571 	if(gSmrImage)
   543 	if(gSmrImage){
   572 	{
   544 		char temp = 0;
   573 		TText temp = 0;
   545 		char *smrImageObeyFileName = (char*)_alloca(gSmrFileName.length() + 1);
   574 		TText *smrImageObeyFileName = gSmrFileName;
   546 		memcpy(smrImageObeyFileName,gSmrFileName.c_str(),gSmrFileName.length() + 1);
   575 		do
   547 		char* ptr = smrImageObeyFileName;
   576 		{
   548 		do {
   577 			while(((temp = *gSmrFileName++) != ',') && (temp != 0));
   549 			while(((temp = *ptr++) != ',') && (temp != 0));
   578 			*(--gSmrFileName)++ = 0;
   550 			*(--ptr)++ = 0;
   579 			if(*smrImageObeyFileName)
   551 
   580 			{	
   552 			if(*smrImageObeyFileName){	
   581 				TText * logfile = 0;
   553 				char * logfile = 0;
   582 				if(Getlogfile(smrImageObeyFileName,logfile) == KErrNone)
   554 				if(Getlogfile(smrImageObeyFileName,logfile) == KErrNone){
   583 				{
       
   584 					H.SetLogFile(logfile);
   555 					H.SetLogFile(logfile);
   585 					PrintVersion();
       
   586 					GetLocalTime();
   556 					GetLocalTime();
   587 					r = ProcessSmrImageMain(smrImageObeyFileName, logfile);
   557 					r = ProcessSmrImageMain(smrImageObeyFileName, logfile);
   588 					H.CloseLogFile();
   558 					H.CloseLogFile();
   589 					delete[] logfile;
   559 					delete[] logfile;
   590 					if(r == KErrNoMemory)
   560 					if(r == KErrNoMemory)
   591 						return KErrNoMemory;
   561 						return KErrNoMemory;
   592 				}
   562 				}
   593 				else
   563 				else {
   594 				{
   564 					Print(EError,"Invalid obey file name: %s", smrImageObeyFileName);
   595 					cout << "Error: Invalid obey file name: " << smrImageObeyFileName << "\n";
   565 				}
   596 				}
   566 			}
   597 			}
   567 			smrImageObeyFileName = ptr;
   598 			smrImageObeyFileName = gSmrFileName;
   568 		} while(temp != 0);
   599 		}
       
   600 		while(temp != 0);
       
   601 		gSmrImage = EFalse;
   569 		gSmrImage = EFalse;
   602 	}
   570 	}
   603 	// Process Rofs Obey files.
   571 	// Process Rofs Obey files.
   604 	if(obeyFileName)
   572 	if(obeyFileName) {
   605 	{
   573 		H.SetLogFile("ROFSBUILD.LOG");		
   606 		
   574 		ObeyFileReader *reader = new ObeyFileReader(obeyFileName); 
   607 		H.SetLogFile((unsigned char *)"ROFSBUILD.LOG");	
       
   608 		PrintVersion();
       
   609 		
       
   610 		ObeyFileReader *reader=new ObeyFileReader(obeyFileName);
       
   611 		if (!reader->Open())
   575 		if (!reader->Open())
   612 			return KErrGeneral;
   576 			return KErrGeneral;
   613 		
   577 
   614 		E32Rofs* RofsImage = 0;		// for image from obey file
   578 		E32Rofs* RofsImage = 0;		// for image from obey file
   615 		CCoreImage *core= 0;		// for image from core image file
   579 		CCoreImage *core = 0;		// for image from core image file
   616 		MRofsImage* imageInfo=0;
   580 		MRofsImage* imageInfo = 0;
   617 		CObeyFile *mainObeyFile=new CObeyFile(*reader);
   581 		CObeyFile *mainObeyFile = new CObeyFile(*reader);
   618 		
       
   619 		// need check if obey file has coreimage keyword
   582 		// need check if obey file has coreimage keyword
   620 		TText *file = mainObeyFile->ProcessCoreImage();
   583 		char *file = mainObeyFile->ProcessCoreImage();
   621 		if (file)
   584 		if (file) {
   622 		{
       
   623 			// hase coreimage keyword but only use if command line option
   585 			// hase coreimage keyword but only use if command line option
   624 			// for coreimage not already selected
   586 			// for coreimage not already selected
   625 			if (!gUseCoreImage)
   587 			if (!gUseCoreImage){
   626 			{
       
   627 				gUseCoreImage = ETrue;
   588 				gUseCoreImage = ETrue;
   628 				gImageFilename = (char *)file;
   589 				gImageFilename = file;
   629 			}
   590 			}
   630 		}
   591 			delete []file ;
   631 		
   592 		}
   632 		if (!gUseCoreImage)
   593 		if (!gUseCoreImage) {
   633 		{
   594 			r = mainObeyFile->ProcessRofs();
   634 			
   595 			if (r == KErrNone) {
   635 			r=mainObeyFile->ProcessRofs();
   596 				// Build a ROFS image using the description compiled into the CObeyFile object
   636 			if (r==KErrNone)
       
   637 			{
       
   638 				// Build a ROFS image using the description compiled into the
       
   639 				// CObeyFile object
       
   640 				
       
   641 				RofsImage = new E32Rofs( mainObeyFile );
   597 				RofsImage = new E32Rofs( mainObeyFile );
   642 				if( !RofsImage )
   598 				if( !RofsImage ) {
   643 				{
   599 					if(gCache || gCleanCache)
       
   600 						delete CacheManager::GetInstance();
   644 					return KErrNoMemory;
   601 					return KErrNoMemory;
   645 				}
   602 				}
   646 				
       
   647 				r = RofsImage->Create();
   603 				r = RofsImage->Create();
   648 				if( KErrNone == r )
   604 
   649 				{
   605 				if( KErrNone == r )	{
   650 					if(SizeSummary)
       
   651 						RofsImage->DisplaySizes(SizeWhere);
       
   652 					RofsImage->WriteImage( gHeaderType );
   606 					RofsImage->WriteImage( gHeaderType );
   653 				}
   607 				}
   654 				imageInfo = RofsImage;
   608 				imageInfo = RofsImage;
   655 				mainObeyFile->Release();
   609 				mainObeyFile->Release();
   656 			}
   610 				if(gCache || gCleanCache)
   657 			else if (r!=KErrNotFound)
   611 					delete CacheManager::GetInstance();
       
   612 			}
       
   613 			else if (r != KErrNotFound){
   658 				return r;
   614 				return r;
   659 		}
   615 			}
   660 		else
   616 		}
   661 		{
   617 		else {
   662 			
       
   663 			// need to use core image
   618 			// need to use core image
   664 			RCoreImageReader *reader = new RCoreImageReader(gImageFilename);
   619 			RCoreImageReader *reader = new RCoreImageReader(gImageFilename.c_str());
   665 			if (!reader)
   620 			if (!reader) {
   666 			{
       
   667 				return KErrNoMemory;
   621 				return KErrNoMemory;
   668 			}
   622 			}
   669 			core= new CCoreImage(reader);
   623 			core = new CCoreImage(reader);
   670 			if (!core)
   624 			if (!core) {
   671 			{
       
   672 				return KErrNoMemory;
   625 				return KErrNoMemory;
   673 			}
   626 			}
   674 			r = core->ProcessImage();
   627 			r = core->ProcessImage();
   675 			if (r != KErrNone)
   628 			if (r != KErrNone) {
   676 				return r;
   629 				return r;
       
   630 			}
   677 			imageInfo = core;
   631 			imageInfo = core;
   678 			mainObeyFile->SkipToExtension();
   632 			mainObeyFile->SkipToExtension();
   679 			
   633 		}
   680 		}
   634 
   681 		
   635 		do {
   682 		do 
   636 			CObeyFile* extensionObeyFile = new CObeyFile(*reader);
   683 		{
       
   684 			CObeyFile* extensionObeyFile = 0;
       
   685 			E32Rofs* extensionRofs = 0;
       
   686 			
       
   687 			extensionObeyFile = new CObeyFile(*reader);
       
   688 			r = extensionObeyFile->ProcessExtensionRofs(imageInfo);
   637 			r = extensionObeyFile->ProcessExtensionRofs(imageInfo);
   689 			if (r==KErrEof)
   638 			if (r == KErrEof){
   690 			{
   639 				if(RofsImage){
   691 				if(RofsImage)
       
   692 					delete RofsImage;
   640 					delete RofsImage;
   693 				if(core)
   641 				}
       
   642 				if(core){
   694 					delete core;
   643 					delete core;
       
   644 				}
   695 				delete extensionObeyFile;
   645 				delete extensionObeyFile;
   696 				return KErrNone;
   646 				return KErrNone;
   697 			}
   647 			}
   698 			if (r!=KErrNone)
   648 			if (r != KErrNone){
   699 				break;
   649 				break;
   700 			
   650 			}
   701 			extensionRofs = new E32Rofs(extensionObeyFile);
   651 			E32Rofs* extensionRofs = new E32Rofs(extensionObeyFile);
   702 			r=extensionRofs->CreateExtension(imageInfo);
   652 			r = extensionRofs->CreateExtension(imageInfo);
   703 			if (r!=KErrNone)
   653 			if (r!= KErrNone){
   704 			{
       
   705 				delete extensionRofs;
   654 				delete extensionRofs;
   706 				delete extensionObeyFile;
   655 				delete extensionObeyFile;
   707 				break;
   656 				break;
   708 			}
   657 			}
   709 			if(SizeSummary)
   658 			r = extensionRofs->WriteImage(0);	
   710 				RofsImage->DisplaySizes(SizeWhere);
   659 
   711 			r=extensionRofs->WriteImage(0);		
       
   712 			delete extensionRofs;
   660 			delete extensionRofs;
   713 			delete extensionObeyFile;
       
   714 			extensionRofs = 0;
   661 			extensionRofs = 0;
   715 			extensionObeyFile = 0;
   662 		} while (r == KErrNone);
   716 			
   663 		if(RofsImage) {
   717 		}
       
   718 		while (r==KErrNone);
       
   719 		
       
   720 		if(RofsImage) 
       
   721 			delete RofsImage;									
   664 			delete RofsImage;									
   722 		if(core)
   665 		}
       
   666 		if(core){
   723 			delete core;
   667 			delete core;
       
   668 		}
   724 		delete mainObeyFile;
   669 		delete mainObeyFile;
   725 		
       
   726 	}
   670 	}
   727 	return r;
   671 	return r;
   728 }//end of main.
   672 }//end of main.