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