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