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=10; |
36 static const TInt RofsbuildPatchVersion=5; |
50 static const TInt RofsbuildPatchVersion=4; |
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 { |
|
315 #ifdef WIN32 |
314 cout << "Unrecognised option " << argv[i] << "\n"; |
316 cout << "Unrecognised option " << argv[i] << "\n"; |
315 } |
317 #else |
|
318 if(0 == access(argv[i],R_OK)){ |
|
319 filename.assign(argv[i]); |
|
320 } |
|
321 else { |
|
322 cout << "Unrecognised option " << argv[i] << "\n"; |
|
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 PrintVersion(); |
327 cout << HelpText; |
339 cout << HelpText; |
328 if (reallyHelp) |
340 if (reallyHelp) { |
329 { |
341 ObeyFileReader::KeywordHelp(); |
330 ObeyFileReader::KeywordHelp(); |
342 cout << ReallyHelpText; |
331 cout << ReallyHelpText; |
343 } |
332 } |
344 else if (filename.empty()){ |
333 else if (filename.empty()) |
345 Print(EError, "Obey filename is missing\n"); |
334 { |
346 } |
335 Print(EError, "Obey filename is missing\n"); |
347 } |
336 } |
348 } |
337 } |
|
338 } |
|
339 |
349 |
340 /** |
350 /** |
341 Function to process parameter-file. |
351 Function to process parameter-file. |
342 |
|
343 @param aFileName parameter-file name. |
352 @param aFileName parameter-file name. |
344 */ |
353 */ |
345 void processParamfile(string aFileName) |
354 void processParamfile(const string& aFileName) { |
346 { |
355 |
347 CParameterFileProcessor parameterFile(aFileName); |
356 CParameterFileProcessor parameterFile(aFileName); |
348 |
|
349 // Invoke fuction "ParameterFileProcessor" to process parameter-file. |
357 // Invoke fuction "ParameterFileProcessor" to process parameter-file. |
350 if(parameterFile.ParameterFileProcessor()) |
358 if(parameterFile.ParameterFileProcessor()) { |
351 { |
|
352 TUint noOfParameters = parameterFile.GetNoOfArguments(); |
359 TUint noOfParameters = parameterFile.GetNoOfArguments(); |
353 char** parameters = parameterFile.GetParameters(); |
360 char** parameters = parameterFile.GetParameters(); |
354 TBool paramFileFlag=ETrue; |
361 TBool paramFileFlag = ETrue; |
355 |
362 |
356 // Invoke function "processCommandLine" to process parameters read from parameter-file. |
363 // Invoke function "processCommandLine" to process parameters read from parameter-file. |
357 processCommandLine(noOfParameters,parameters,paramFileFlag); |
364 processCommandLine(noOfParameters,parameters,paramFileFlag); |
358 } |
365 } |
359 } |
366 } |
491 /** |
456 /** |
492 Rofsbuild Main function, which creates both Rofs and Data drive image. |
457 Rofsbuild Main function, which creates both Rofs and Data drive image. |
493 |
458 |
494 @param argc - No. of argument. |
459 @param argc - No. of argument. |
495 @param *argv[] - Arguments value. |
460 @param *argv[] - Arguments value. |
496 |
461 |
497 @return - returns the status to caller. |
462 @return - returns the status to caller. |
498 */ |
463 */ |
499 TInt main(int argc, char *argv[]) |
464 TInt main(int argc, char *argv[]){ |
500 { |
465 TInt r =0; |
501 TInt r =0; |
466 #ifdef __LINUX__ |
502 |
467 gCPUNum = sysconf(_SC_NPROCESSORS_CONF); |
503 g_pCharCPUNum = getenv("NUMBER_OF_PROCESSORS"); |
468 #else |
504 if(g_pCharCPUNum != NULL) |
469 char* pCPUNum = getenv ("NUMBER_OF_PROCESSORS"); |
505 gCPUNum = atoi(g_pCharCPUNum); |
470 if (pCPUNum != NULL) |
506 |
471 gCPUNum = atoi(pCPUNum); |
507 processCommandLine(argc, argv); |
472 #endif |
508 |
473 if(gCPUNum > MAXIMUM_THREADS) |
509 TText *obeyFileName = NULL; |
474 gCPUNum = MAXIMUM_THREADS; |
510 if(!filename.empty()) |
475 processCommandLine(argc, argv); |
511 obeyFileName=(TText*)filename.c_str(); |
476 //if the user wants to clean up the cache, do it only. |
512 |
477 if(gCleanCache){ |
513 if ((obeyFileName==NULL) && (gDriveFilename==NULL) && (gSmrFileName == NULL)) |
478 try { |
|
479 CacheManager::GetInstance()->CleanCache(); |
|
480 printf("Cache has been deleted successfully.\r\n"); |
|
481 } |
|
482 catch(CacheException& ce){ |
|
483 printf("%s\r\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 printf("%s\r\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) |
|
519 { |
|
520 printf("The number of processors (%d) is used as the number of concurrent jobs.\n", gCPUNum); |
506 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 printf("WARNING: 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(); |
528 PrintVersion(); |
553 GetLocalTime(); |
529 GetLocalTime(); |
554 r = ProcessDataDriveMain(driveobeyFileName,logfile); |
530 r = ProcessDataDriveMain(driveobeyFileName,logfile); |
555 H.CloseLogFile(); |
531 H.CloseLogFile(); |
556 delete[] logfile; |
532 delete[] logfile; |
557 if(r == KErrNoMemory) |
533 if(r == KErrNoMemory) |
558 return KErrNoMemory; |
534 return KErrNoMemory; |
559 } |
535 } |
560 else |
536 else { |
561 { |
|
562 cout << "Error : Invalid obey file name : " << driveobeyFileName << "\n" ; |
537 cout << "Error : Invalid obey file name : " << driveobeyFileName << "\n" ; |
563 } |
538 } |
564 } |
539 } |
565 driveobeyFileName = gDriveFilename; |
540 driveobeyFileName = ptr; |
566 } |
541 } while(temp != 0); |
567 while(temp != 0); |
542 gDriveImage = EFalse; |
568 |
|
569 gDriveImage=EFalse; |
|
570 } |
543 } |
571 if(gSmrImage) |
544 if(gSmrImage){ |
572 { |
545 char temp = 0; |
573 TText temp = 0; |
546 char *smrImageObeyFileName = (char*)_alloca(gSmrFileName.length() + 1); |
574 TText *smrImageObeyFileName = gSmrFileName; |
547 memcpy(smrImageObeyFileName,gSmrFileName.c_str(),gSmrFileName.length() + 1); |
575 do |
548 char* ptr = smrImageObeyFileName; |
576 { |
549 do { |
577 while(((temp = *gSmrFileName++) != ',') && (temp != 0)); |
550 while(((temp = *ptr++) != ',') && (temp != 0)); |
578 *(--gSmrFileName)++ = 0; |
551 *(--ptr)++ = 0; |
579 if(*smrImageObeyFileName) |
552 |
580 { |
553 if(*smrImageObeyFileName){ |
581 TText * logfile = 0; |
554 char * logfile = 0; |
582 if(Getlogfile(smrImageObeyFileName,logfile) == KErrNone) |
555 if(Getlogfile(smrImageObeyFileName,logfile) == KErrNone){ |
583 { |
|
584 H.SetLogFile(logfile); |
556 H.SetLogFile(logfile); |
585 PrintVersion(); |
557 PrintVersion(); |
586 GetLocalTime(); |
558 GetLocalTime(); |
587 r = ProcessSmrImageMain(smrImageObeyFileName, logfile); |
559 r = ProcessSmrImageMain(smrImageObeyFileName, logfile); |
588 H.CloseLogFile(); |
560 H.CloseLogFile(); |
589 delete[] logfile; |
561 delete[] logfile; |
590 if(r == KErrNoMemory) |
562 if(r == KErrNoMemory) |
591 return KErrNoMemory; |
563 return KErrNoMemory; |
592 } |
564 } |
593 else |
565 else { |
594 { |
|
595 cout << "Error: Invalid obey file name: " << smrImageObeyFileName << "\n"; |
566 cout << "Error: Invalid obey file name: " << smrImageObeyFileName << "\n"; |
596 } |
567 } |
597 } |
568 } |
598 smrImageObeyFileName = gSmrFileName; |
569 smrImageObeyFileName = ptr; |
599 } |
570 } while(temp != 0); |
600 while(temp != 0); |
|
601 gSmrImage = EFalse; |
571 gSmrImage = EFalse; |
602 } |
572 } |
603 // Process Rofs Obey files. |
573 // Process Rofs Obey files. |
604 if(obeyFileName) |
574 if(obeyFileName) { |
605 { |
575 H.SetLogFile("ROFSBUILD.LOG"); |
606 |
|
607 H.SetLogFile((unsigned char *)"ROFSBUILD.LOG"); |
|
608 PrintVersion(); |
576 PrintVersion(); |
609 |
577 ObeyFileReader *reader = new ObeyFileReader(obeyFileName); |
610 ObeyFileReader *reader=new ObeyFileReader(obeyFileName); |
|
611 if (!reader->Open()) |
578 if (!reader->Open()) |
612 return KErrGeneral; |
579 return KErrGeneral; |
613 |
580 |
614 E32Rofs* RofsImage = 0; // for image from obey file |
581 E32Rofs* RofsImage = 0; // for image from obey file |
615 CCoreImage *core= 0; // for image from core image file |
582 CCoreImage *core = 0; // for image from core image file |
616 MRofsImage* imageInfo=0; |
583 MRofsImage* imageInfo = 0; |
617 CObeyFile *mainObeyFile=new CObeyFile(*reader); |
584 CObeyFile *mainObeyFile = new CObeyFile(*reader); |
618 |
|
619 // need check if obey file has coreimage keyword |
585 // need check if obey file has coreimage keyword |
620 TText *file = mainObeyFile->ProcessCoreImage(); |
586 char *file = mainObeyFile->ProcessCoreImage(); |
621 if (file) |
587 if (file) { |
622 { |
|
623 // hase coreimage keyword but only use if command line option |
588 // hase coreimage keyword but only use if command line option |
624 // for coreimage not already selected |
589 // for coreimage not already selected |
625 if (!gUseCoreImage) |
590 if (!gUseCoreImage){ |
626 { |
|
627 gUseCoreImage = ETrue; |
591 gUseCoreImage = ETrue; |
628 gImageFilename = (char *)file; |
592 gImageFilename = file; |
629 } |
593 } |
630 } |
594 delete []file ; |
631 |
595 } |
632 if (!gUseCoreImage) |
596 if (!gUseCoreImage) { |
633 { |
597 r = mainObeyFile->ProcessRofs(); |
634 |
598 if (r == KErrNone) { |
635 r=mainObeyFile->ProcessRofs(); |
599 // 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 ); |
600 RofsImage = new E32Rofs( mainObeyFile ); |
642 if( !RofsImage ) |
601 if( !RofsImage ) { |
643 { |
602 if(gCache || gCleanCache) |
|
603 delete CacheManager::GetInstance(); |
644 return KErrNoMemory; |
604 return KErrNoMemory; |
645 } |
605 } |
646 |
|
647 r = RofsImage->Create(); |
606 r = RofsImage->Create(); |
648 if( KErrNone == r ) |
607 |
649 { |
608 if( KErrNone == r ) { |
650 if(SizeSummary) |
|
651 RofsImage->DisplaySizes(SizeWhere); |
|
652 RofsImage->WriteImage( gHeaderType ); |
609 RofsImage->WriteImage( gHeaderType ); |
653 } |
610 } |
654 imageInfo = RofsImage; |
611 imageInfo = RofsImage; |
655 mainObeyFile->Release(); |
612 mainObeyFile->Release(); |
656 } |
613 if(gCache || gCleanCache) |
657 else if (r!=KErrNotFound) |
614 delete CacheManager::GetInstance(); |
|
615 } |
|
616 else if (r != KErrNotFound){ |
658 return r; |
617 return r; |
659 } |
618 } |
660 else |
619 } |
661 { |
620 else { |
662 |
|
663 // need to use core image |
621 // need to use core image |
664 RCoreImageReader *reader = new RCoreImageReader(gImageFilename); |
622 RCoreImageReader *reader = new RCoreImageReader(gImageFilename.c_str()); |
665 if (!reader) |
623 if (!reader) { |
666 { |
|
667 return KErrNoMemory; |
624 return KErrNoMemory; |
668 } |
625 } |
669 core= new CCoreImage(reader); |
626 core = new CCoreImage(reader); |
670 if (!core) |
627 if (!core) { |
671 { |
|
672 return KErrNoMemory; |
628 return KErrNoMemory; |
673 } |
629 } |
674 r = core->ProcessImage(); |
630 r = core->ProcessImage(); |
675 if (r != KErrNone) |
631 if (r != KErrNone) { |
676 return r; |
632 return r; |
|
633 } |
677 imageInfo = core; |
634 imageInfo = core; |
678 mainObeyFile->SkipToExtension(); |
635 mainObeyFile->SkipToExtension(); |
679 |
636 } |
680 } |
637 |
681 |
638 do { |
682 do |
639 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); |
640 r = extensionObeyFile->ProcessExtensionRofs(imageInfo); |
689 if (r==KErrEof) |
641 if (r == KErrEof){ |
690 { |
642 if(RofsImage){ |
691 if(RofsImage) |
|
692 delete RofsImage; |
643 delete RofsImage; |
693 if(core) |
644 } |
|
645 if(core){ |
694 delete core; |
646 delete core; |
|
647 } |
695 delete extensionObeyFile; |
648 delete extensionObeyFile; |
696 return KErrNone; |
649 return KErrNone; |
697 } |
650 } |
698 if (r!=KErrNone) |
651 if (r != KErrNone){ |
699 break; |
652 break; |
700 |
653 } |
701 extensionRofs = new E32Rofs(extensionObeyFile); |
654 E32Rofs* extensionRofs = new E32Rofs(extensionObeyFile); |
702 r=extensionRofs->CreateExtension(imageInfo); |
655 r = extensionRofs->CreateExtension(imageInfo); |
703 if (r!=KErrNone) |
656 if (r!= KErrNone){ |
704 { |
|
705 delete extensionRofs; |
657 delete extensionRofs; |
706 delete extensionObeyFile; |
658 delete extensionObeyFile; |
707 break; |
659 break; |
708 } |
660 } |
709 if(SizeSummary) |
661 r = extensionRofs->WriteImage(0); |
710 RofsImage->DisplaySizes(SizeWhere); |
662 |
711 r=extensionRofs->WriteImage(0); |
|
712 delete extensionRofs; |
663 delete extensionRofs; |
713 delete extensionObeyFile; |
664 delete extensionObeyFile; |
714 extensionRofs = 0; |
665 extensionRofs = 0; |
715 extensionObeyFile = 0; |
666 extensionObeyFile = 0; |
716 |
667 } while (r == KErrNone); |
717 } |
668 if(RofsImage) { |
718 while (r==KErrNone); |
|
719 |
|
720 if(RofsImage) |
|
721 delete RofsImage; |
669 delete RofsImage; |
722 if(core) |
670 } |
|
671 if(core){ |
723 delete core; |
672 delete core; |
|
673 } |
724 delete mainObeyFile; |
674 delete mainObeyFile; |
725 |
|
726 } |
675 } |
727 return r; |
676 return r; |
728 }//end of main. |
677 }//end of main. |