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;
|
|
49 |
static const TInt RofsbuildMinorVersion=12;
|
617
|
50 |
static const TInt RofsbuildPatchVersion=4;
|
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 = "";
|
|
80 |
|
|
81 |
//Cache global variables
|
|
82 |
bool gCache = false;
|
|
83 |
bool gCleanCache = false;
|
|
84 |
bool gNoCache = false;
|
|
85 |
TBool gKeepGoing = EFalse;
|
|
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 |
}
|
|
91 |
|
|
92 |
char HelpText[] =
|
|
93 |
"Syntax: ROFSBUILD [options] obeyfilename(Rofs)\n"
|
|
94 |
"Option: -v verbose, -?, -s[log|screen|both] size summary\n"
|
|
95 |
" -d<bitmask> set trace mask (DEB build only)\n"
|
|
96 |
" -compress compress executable files where possible\n"
|
|
97 |
" -j<digit> do the main job with <digit> threads\n"
|
|
98 |
" -symbols generate symbol file\n"
|
|
99 |
" -compressionmethod none|inflate|bytepair to set the compression\n"
|
|
100 |
" none uncompress the image.\n"
|
|
101 |
" inflate compress the image.\n"
|
|
102 |
" bytepair compress the image.\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"
|
|
107 |
" -datadrive=<drive obyfile1>,<drive obyfile2>,... for driveimage creation\n"
|
|
108 |
" user can also input rofs oby file if required to generate both.\n"
|
|
109 |
" -smr=<SMR obyfile1>,<SMR obyfile2>,... for SMR partition creation\n"
|
|
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.
|
|
111 |
" -wstdpath warn if destination path provided for a file is not the standard path\n"
|
|
112 |
" -argfile=<FileName> specify argument-file name containing list of command-line arguments\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";
|
|
115 |
|
|
116 |
char ReallyHelpText[] =
|
|
117 |
"Log Level:\n"
|
|
118 |
" 0 produce the default logs\n"
|
|
119 |
" 1 produce file detail logs in addition to the default logs\n"
|
|
120 |
" 2 logs e32 header attributes in addition to the level 1 details\n";
|
|
121 |
void processParamfile(const string& aFileName);
|
|
122 |
/**
|
|
123 |
Process the command line arguments and prints the helpful message if none are supplied.
|
|
124 |
@param argc - No. of argument.
|
|
125 |
@param *argv[] - Arguments value.
|
|
126 |
*/
|
|
127 |
void processCommandLine(int argc, char *argv[], TBool paramFileFlag = EFalse) {
|
|
128 |
// If "-argfile" option is passed to rofsbuild, then process the parameters
|
|
129 |
// specified in parameter-file first and then the options passed from the command-line.
|
|
130 |
|
|
131 |
string ParamFileArg("-ARGFILE=");
|
|
132 |
if(paramFileFlag == EFalse) {
|
|
133 |
for (int count = 1; count<argc; count++) {
|
|
134 |
string paramFile;
|
|
135 |
//strupr(argv[count]);
|
|
136 |
if(strnicmp(argv[count],ParamFileArg.c_str(),ParamFileArg.length()) == 0) {
|
|
137 |
paramFile.assign(&argv[count][ParamFileArg.length()]);
|
|
138 |
processParamfile(paramFile);
|
|
139 |
}
|
|
140 |
}
|
|
141 |
}
|
|
142 |
|
|
143 |
int i = 1;
|
|
144 |
while (i<argc) {
|
|
145 |
#ifdef __LINUX__
|
|
146 |
if (argv[i][0] == '-')
|
|
147 |
#else
|
|
148 |
if ((argv[i][0] == '-') || (argv[i][0] == '/'))
|
|
149 |
#endif
|
|
150 |
{
|
|
151 |
// switch
|
|
152 |
if ((argv[i][1] & 0x20) == 'v')
|
|
153 |
H.iVerbose = ETrue;
|
|
154 |
else if(strnicmp (argv[i], "-SMR=", 5) == 0) {
|
|
155 |
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)
|
|
207 |
{
|
|
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 (strnicmp(argv[i], "-J",2) == 0) {
|
|
213 |
if(argv[i][2])
|
|
214 |
gThreadNum = atoi(&argv[i][2]);
|
|
215 |
else {
|
|
216 |
printf("WARNING: The option should be like '-j4'.\n");
|
|
217 |
gThreadNum = 0;
|
|
218 |
}
|
|
219 |
if(gThreadNum <= 0 || gThreadNum > MAXIMUM_THREADS) {
|
|
220 |
printf("WARNING: The number of concurrent jobs set by -j should be between 1 and 128. ");
|
|
221 |
if(gCPUNum > 0) {
|
|
222 |
printf("WARNING: The number of processors %d is used as the number of concurrent jobs.\n", gCPUNum);
|
|
223 |
gThreadNum = gCPUNum;
|
|
224 |
}
|
|
225 |
else {
|
|
226 |
printf("WARNING: Can't automatically get the valid number of concurrent jobs and %d is used.\n", DEFAULT_THREADS);
|
|
227 |
gThreadNum = DEFAULT_THREADS;
|
|
228 |
}
|
|
229 |
}
|
|
230 |
}
|
|
231 |
else if (stricmp(argv[i], "-UNCOMPRESS") == 0) {
|
|
232 |
gCompress = ECompressionUncompress;
|
|
233 |
}
|
|
234 |
else if( stricmp(argv[i], "-COMPRESSIONMETHOD") == 0 ) {
|
|
235 |
// next argument should a be method
|
|
236 |
if( (i+1) >= argc || argv[i+1][0] == '-') {
|
|
237 |
Print (EError, "Missing compression method! Set it to default (no compression)!");
|
|
238 |
gCompressionMethod = 0;
|
|
239 |
}
|
|
240 |
else {
|
|
241 |
i++;
|
|
242 |
if( stricmp(argv[i], "NONE") == 0) {
|
|
243 |
gCompress = ECompressionUncompress;
|
|
244 |
gCompressionMethod = 0;
|
|
245 |
}
|
|
246 |
else if( stricmp(argv[i], "INFLATE") == 0) {
|
|
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 {
|
|
269 |
i++;
|
|
270 |
gImageFilename.assign(argv[i]);
|
|
271 |
}
|
|
272 |
}
|
|
273 |
else if (strnicmp(argv[i], "-DATADRIVE=",11) == 0){
|
|
274 |
if(argv[i][11]) {
|
|
275 |
gDriveImage = ETrue;
|
|
276 |
gDriveFilename.assign(&argv[i][11]);
|
|
277 |
}
|
|
278 |
else {
|
|
279 |
Print (EError, "Drive obey file is missing\n");
|
|
280 |
}
|
|
281 |
}
|
|
282 |
else if (argv[i][1] == '?') {
|
|
283 |
reallyHelp = ETrue;
|
|
284 |
}
|
|
285 |
else if (stricmp(argv[i], "-WSTDPATH") == 0) { // Warn if destination path provided for a executables are incorrect as per platsec.
|
|
286 |
gEnableStdPathWarning = ETrue;
|
|
287 |
}
|
|
288 |
else if( stricmp(argv[i], "-LOGLEVEL") == 0) {
|
|
289 |
// next argument should a be loglevel
|
|
290 |
if( (i+1) >= argc || argv[i+1][0] == '-') {
|
|
291 |
Print (EError, "Missing loglevel!");
|
|
292 |
gLogLevel = DEFAULT_LOG_LEVEL;
|
|
293 |
}
|
|
294 |
else {
|
|
295 |
i++;
|
|
296 |
if (strcmp(argv[i], "2") == 0)
|
|
297 |
gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES);
|
|
298 |
if (strcmp(argv[i], "1") == 0)
|
|
299 |
gLogLevel = LOG_LEVEL_FILE_DETAILS;
|
|
300 |
else if (strcmp(argv[i], "0") == 0)
|
|
301 |
gLogLevel = DEFAULT_LOG_LEVEL;
|
|
302 |
else
|
|
303 |
Print(EError, "Only loglevel 0, 1 or 2 is allowed!");
|
|
304 |
}
|
|
305 |
}
|
|
306 |
else if( stricmp(argv[i], "-LOGLEVEL2") == 0)
|
|
307 |
gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES);
|
|
308 |
else if( stricmp(argv[i], "-LOGLEVEL1") == 0)
|
|
309 |
gLogLevel = LOG_LEVEL_FILE_DETAILS;
|
|
310 |
else if( stricmp(argv[i], "-LOGLEVEL0") == 0)
|
|
311 |
gLogLevel = DEFAULT_LOG_LEVEL;
|
|
312 |
else if (stricmp(argv[i], "-LOWMEM") == 0)
|
|
313 |
gLowMem = ETrue;
|
|
314 |
else {
|
|
315 |
#ifdef WIN32
|
|
316 |
Print (EWarning, "Unrecognised option %s\n",argv[i]);
|
|
317 |
#else
|
|
318 |
if(0 == access(argv[i],R_OK)){
|
|
319 |
filename.assign(argv[i]);
|
|
320 |
}
|
|
321 |
else {
|
|
322 |
Print (EWarning, "Unrecognised option %s\n",argv[i]);
|
|
323 |
}
|
|
324 |
#endif
|
|
325 |
|
|
326 |
}
|
|
327 |
}
|
|
328 |
else // Must be the obey filename
|
|
329 |
filename.assign(argv[i]);
|
|
330 |
i++;
|
|
331 |
}
|
|
332 |
|
|
333 |
if (paramFileFlag)
|
|
334 |
return;
|
|
335 |
|
|
336 |
if((gDriveImage == EFalse) && (gSmrImage == EFalse) &&
|
|
337 |
(filename.empty() || (gUseCoreImage && gImageFilename.length() == 0))){
|
|
338 |
Print (EAlways, HelpText);
|
|
339 |
if (reallyHelp) {
|
|
340 |
ObeyFileReader::KeywordHelp();
|
|
341 |
Print (EAlways, ReallyHelpText);
|
|
342 |
}
|
|
343 |
else if (filename.empty()){
|
|
344 |
Print(EAlways, "Obey filename is missing\n");
|
|
345 |
}
|
|
346 |
}
|
|
347 |
}
|
|
348 |
|
|
349 |
/**
|
|
350 |
Function to process parameter-file.
|
|
351 |
@param aFileName parameter-file name.
|
|
352 |
*/
|
|
353 |
void processParamfile(const string& aFileName) {
|
|
354 |
|
|
355 |
CParameterFileProcessor parameterFile(aFileName);
|
|
356 |
// Invoke fuction "ParameterFileProcessor" to process parameter-file.
|
|
357 |
if(parameterFile.ParameterFileProcessor()) {
|
|
358 |
TUint noOfParameters = parameterFile.GetNoOfArguments();
|
|
359 |
char** parameters = parameterFile.GetParameters();
|
|
360 |
TBool paramFileFlag = ETrue;
|
|
361 |
|
|
362 |
// Invoke function "processCommandLine" to process parameters read from parameter-file.
|
|
363 |
processCommandLine(noOfParameters,parameters,paramFileFlag);
|
|
364 |
}
|
|
365 |
}
|
|
366 |
|
|
367 |
/**
|
|
368 |
Main logic for data drive image creation. Called many types depending on no. of drive obey files.
|
|
369 |
|
|
370 |
@param aobeyFileName - Drive obey file.
|
|
371 |
@param alogfile - log file name required for file system module.
|
|
372 |
|
|
373 |
@return - returns the status, after processing the drive obey file.
|
|
374 |
*/
|
|
375 |
TInt ProcessDataDriveMain(char* aobeyFileName,char* alogfile) {
|
|
376 |
|
|
377 |
ObeyFileReader *reader = new ObeyFileReader(aobeyFileName);
|
|
378 |
|
|
379 |
if(!reader)
|
|
380 |
return KErrNoMemory;
|
|
381 |
|
|
382 |
if(!reader->Open())
|
|
383 |
return KErrGeneral;
|
|
384 |
|
|
385 |
CObeyFile* mainObeyFile = new CObeyFile(*reader);
|
|
386 |
|
|
387 |
if(!mainObeyFile)
|
|
388 |
return KErrNoMemory;
|
|
389 |
|
|
390 |
// Process data drive image.
|
|
391 |
// let's clear the TRomNode::sDefaultInitialAttr first, 'cause data drive is different from rom image
|
|
392 |
TRomNode::sDefaultInitialAttr = 0;
|
|
393 |
TInt retstatus = mainObeyFile->ProcessDataDrive();
|
|
394 |
if (retstatus == KErrNone) {
|
|
395 |
// Build a Data drive image using the description compiled into the CObeyFile object
|
|
396 |
CDriveImage* userImage = new CDriveImage(mainObeyFile);
|
|
397 |
if(userImage) {
|
|
398 |
// Drive image creation.
|
|
399 |
retstatus = userImage->CreateImage(alogfile);
|
|
400 |
if(retstatus == KErrNone) {
|
|
401 |
Print (EAlways, "\nSuccessfully generated the Drive image : %s \n",mainObeyFile->iDriveFileName);
|
|
402 |
}
|
|
403 |
else {
|
|
404 |
Print (EError, "Failed to generate the Image : %s\n",mainObeyFile->iDriveFileName);
|
|
405 |
}
|
|
406 |
delete userImage;
|
|
407 |
}
|
|
408 |
else {
|
|
409 |
retstatus = KErrNoMemory;
|
|
410 |
}
|
|
411 |
}
|
|
412 |
// restore
|
|
413 |
TRomNode::sDefaultInitialAttr = (TUint8)KEntryAttReadOnly;
|
|
414 |
cout << "\n-----------------------------------------------------------\n";
|
|
415 |
|
|
416 |
delete mainObeyFile;
|
|
417 |
delete reader;
|
|
418 |
return retstatus;
|
|
419 |
}
|
|
420 |
|
|
421 |
TInt ProcessSmrImageMain(char* aObeyFileName, char* /* alogfile */) {
|
|
422 |
ObeyFileReader *reader = new ObeyFileReader(aObeyFileName);
|
|
423 |
if(!reader)
|
|
424 |
return KErrNoMemory;
|
|
425 |
if(!reader->Open())
|
|
426 |
return KErrGeneral;
|
|
427 |
TInt retstatus = 0;
|
|
428 |
CObeyFile* mainObeyFile = new CObeyFile(*reader);
|
|
429 |
CSmrImage* smrImage = 0;
|
|
430 |
if(!mainObeyFile)
|
|
431 |
return KErrNoMemory;
|
|
432 |
if(mainObeyFile->Process()) {
|
|
433 |
smrImage = new CSmrImage(mainObeyFile);
|
|
434 |
if(smrImage) {
|
|
435 |
if((retstatus = smrImage->Initialise()) == KErrNone) {
|
|
436 |
retstatus = smrImage->CreateImage();
|
|
437 |
}
|
|
438 |
if(retstatus == KErrNone) {
|
|
439 |
Print (EAlways, "\nSuccessfully generated the SMR image : %s\n" ,smrImage->GetImageName().c_str());
|
|
440 |
}
|
|
441 |
else {
|
|
442 |
Print (EError, "\nFailed to generate the Image : %s\n" ,smrImage->GetImageName().c_str());
|
|
443 |
}
|
|
444 |
delete smrImage;
|
|
445 |
}
|
|
446 |
else {
|
|
447 |
retstatus = KErrNoMemory;
|
|
448 |
}
|
|
449 |
}
|
|
450 |
delete mainObeyFile;
|
|
451 |
delete reader;
|
|
452 |
return retstatus;
|
|
453 |
}
|
|
454 |
|
|
455 |
/**
|
|
456 |
Rofsbuild Main function, which creates both Rofs and Data drive image.
|
|
457 |
|
|
458 |
@param argc - No. of argument.
|
|
459 |
@param *argv[] - Arguments value.
|
|
460 |
|
|
461 |
@return - returns the status to caller.
|
|
462 |
*/
|
|
463 |
TInt main(int argc, char *argv[]){
|
|
464 |
TInt r =0;
|
|
465 |
#ifdef __LINUX__
|
|
466 |
gCPUNum = sysconf(_SC_NPROCESSORS_CONF);
|
|
467 |
#else
|
|
468 |
char* pCPUNum = getenv ("NUMBER_OF_PROCESSORS");
|
|
469 |
if (pCPUNum != NULL)
|
|
470 |
gCPUNum = atoi(pCPUNum);
|
|
471 |
#endif
|
|
472 |
if(gCPUNum > MAXIMUM_THREADS)
|
|
473 |
gCPUNum = MAXIMUM_THREADS;
|
|
474 |
PrintVersion();
|
|
475 |
processCommandLine(argc, argv);
|
|
476 |
//if the user wants to clean up the cache, do it only.
|
|
477 |
if(gCleanCache){
|
|
478 |
try {
|
|
479 |
CacheManager::GetInstance()->CleanCache();
|
|
480 |
Print (EAlways, "Cache has been deleted successfully.\n");
|
|
481 |
}
|
|
482 |
catch(CacheException& ce){
|
|
483 |
Print (EError, "%s\n", ce.GetErrorMessage());
|
|
484 |
return (TInt)1;
|
|
485 |
}
|
|
486 |
return r;
|
|
487 |
}
|
|
488 |
//initialize cache if the user switches on.
|
|
489 |
if(gCache) {
|
|
490 |
try {
|
|
491 |
CacheManager::GetInstance();
|
|
492 |
}
|
|
493 |
catch(CacheException ce){
|
|
494 |
Print (EError, "%s\n", ce.GetErrorMessage());
|
|
495 |
return (TInt)1;
|
|
496 |
}
|
|
497 |
}
|
|
498 |
const char *obeyFileName = 0;
|
|
499 |
if(!filename.empty())
|
|
500 |
obeyFileName = filename.c_str();
|
|
501 |
if ((!obeyFileName) && (!gDriveFilename.empty()) && (!gSmrFileName.empty())){
|
|
502 |
return KErrGeneral;
|
|
503 |
}
|
|
504 |
if(gThreadNum == 0) {
|
|
505 |
if(gCPUNum > 0) {
|
|
506 |
Print (EWarning, "The number of processors (%d) is used as the number of concurrent jobs.\n", gCPUNum);
|
|
507 |
gThreadNum = gCPUNum;
|
|
508 |
}
|
|
509 |
else {
|
|
510 |
Print (EWarning, "Can't automatically get the valid number of concurrent jobs and %d is used.\n", DEFAULT_THREADS);
|
|
511 |
gThreadNum = DEFAULT_THREADS;
|
|
512 |
}
|
|
513 |
}
|
|
514 |
// Process drive obey files.
|
|
515 |
if(gDriveImage) {
|
|
516 |
char temp = 0;
|
|
517 |
char *driveobeyFileName = (char*)_alloca(gDriveFilename.length() + 1);
|
|
518 |
memcpy(driveobeyFileName,gDriveFilename.c_str(),gDriveFilename.length() + 1);
|
|
519 |
char* ptr = driveobeyFileName;
|
|
520 |
do {
|
|
521 |
while(((temp = *ptr++) != ',') && (temp != 0));
|
|
522 |
*(--ptr)++ = 0;
|
|
523 |
|
|
524 |
if(*driveobeyFileName) {
|
|
525 |
char* logfile = 0;
|
|
526 |
if(Getlogfile(driveobeyFileName,logfile) == KErrNone) {
|
|
527 |
H.SetLogFile(logfile);
|
|
528 |
GetLocalTime();
|
|
529 |
r = ProcessDataDriveMain(driveobeyFileName,logfile);
|
|
530 |
H.CloseLogFile();
|
|
531 |
delete[] logfile;
|
|
532 |
if(r == KErrNoMemory)
|
|
533 |
return KErrNoMemory;
|
|
534 |
}
|
|
535 |
else {
|
|
536 |
Print(EError,"Invalid obey file name : %s\n", driveobeyFileName);
|
|
537 |
}
|
|
538 |
}
|
|
539 |
driveobeyFileName = ptr;
|
|
540 |
} while(temp != 0);
|
|
541 |
gDriveImage = EFalse;
|
|
542 |
}
|
|
543 |
if(gSmrImage){
|
|
544 |
char temp = 0;
|
|
545 |
char *smrImageObeyFileName = (char*)_alloca(gSmrFileName.length() + 1);
|
|
546 |
memcpy(smrImageObeyFileName,gSmrFileName.c_str(),gSmrFileName.length() + 1);
|
|
547 |
char* ptr = smrImageObeyFileName;
|
|
548 |
do {
|
|
549 |
while(((temp = *ptr++) != ',') && (temp != 0));
|
|
550 |
*(--ptr)++ = 0;
|
|
551 |
|
|
552 |
if(*smrImageObeyFileName){
|
|
553 |
char * logfile = 0;
|
|
554 |
if(Getlogfile(smrImageObeyFileName,logfile) == KErrNone){
|
|
555 |
H.SetLogFile(logfile);
|
|
556 |
GetLocalTime();
|
|
557 |
r = ProcessSmrImageMain(smrImageObeyFileName, logfile);
|
|
558 |
H.CloseLogFile();
|
|
559 |
delete[] logfile;
|
|
560 |
if(r == KErrNoMemory)
|
|
561 |
return KErrNoMemory;
|
|
562 |
}
|
|
563 |
else {
|
|
564 |
Print(EError,"Invalid obey file name: %s", smrImageObeyFileName);
|
|
565 |
}
|
|
566 |
}
|
|
567 |
smrImageObeyFileName = ptr;
|
|
568 |
} while(temp != 0);
|
|
569 |
gSmrImage = EFalse;
|
|
570 |
}
|
|
571 |
// Process Rofs Obey files.
|
|
572 |
if(obeyFileName) {
|
|
573 |
H.SetLogFile("ROFSBUILD.LOG");
|
|
574 |
ObeyFileReader *reader = new ObeyFileReader(obeyFileName);
|
|
575 |
if (!reader->Open())
|
|
576 |
return KErrGeneral;
|
|
577 |
|
|
578 |
E32Rofs* RofsImage = 0; // for image from obey file
|
|
579 |
CCoreImage *core = 0; // for image from core image file
|
|
580 |
MRofsImage* imageInfo = 0;
|
|
581 |
CObeyFile *mainObeyFile = new CObeyFile(*reader);
|
|
582 |
// need check if obey file has coreimage keyword
|
|
583 |
char *file = mainObeyFile->ProcessCoreImage();
|
|
584 |
if (file) {
|
|
585 |
// hase coreimage keyword but only use if command line option
|
|
586 |
// for coreimage not already selected
|
|
587 |
if (!gUseCoreImage){
|
|
588 |
gUseCoreImage = ETrue;
|
|
589 |
gImageFilename = file;
|
|
590 |
}
|
|
591 |
delete []file ;
|
|
592 |
}
|
|
593 |
if (!gUseCoreImage) {
|
|
594 |
r = mainObeyFile->ProcessRofs();
|
|
595 |
if (r == KErrNone) {
|
|
596 |
// Build a ROFS image using the description compiled into the CObeyFile object
|
|
597 |
RofsImage = new E32Rofs( mainObeyFile );
|
|
598 |
if( !RofsImage ) {
|
|
599 |
if(gCache || gCleanCache)
|
|
600 |
delete CacheManager::GetInstance();
|
|
601 |
return KErrNoMemory;
|
|
602 |
}
|
|
603 |
r = RofsImage->Create();
|
|
604 |
|
|
605 |
if( KErrNone == r ) {
|
|
606 |
RofsImage->WriteImage( gHeaderType );
|
|
607 |
}
|
|
608 |
imageInfo = RofsImage;
|
|
609 |
mainObeyFile->Release();
|
|
610 |
if(gCache || gCleanCache)
|
|
611 |
delete CacheManager::GetInstance();
|
|
612 |
}
|
|
613 |
else if (r != KErrNotFound){
|
|
614 |
return r;
|
|
615 |
}
|
|
616 |
}
|
|
617 |
else {
|
|
618 |
// need to use core image
|
|
619 |
RCoreImageReader *reader = new RCoreImageReader(gImageFilename.c_str());
|
|
620 |
if (!reader) {
|
|
621 |
return KErrNoMemory;
|
|
622 |
}
|
|
623 |
core = new CCoreImage(reader);
|
|
624 |
if (!core) {
|
|
625 |
return KErrNoMemory;
|
|
626 |
}
|
|
627 |
r = core->ProcessImage();
|
|
628 |
if (r != KErrNone) {
|
|
629 |
return r;
|
|
630 |
}
|
|
631 |
imageInfo = core;
|
|
632 |
mainObeyFile->SkipToExtension();
|
|
633 |
}
|
|
634 |
|
|
635 |
do {
|
|
636 |
CObeyFile* extensionObeyFile = new CObeyFile(*reader);
|
|
637 |
r = extensionObeyFile->ProcessExtensionRofs(imageInfo);
|
|
638 |
if (r == KErrEof){
|
|
639 |
if(RofsImage){
|
|
640 |
delete RofsImage;
|
|
641 |
}
|
|
642 |
if(core){
|
|
643 |
delete core;
|
|
644 |
}
|
|
645 |
delete extensionObeyFile;
|
|
646 |
return KErrNone;
|
|
647 |
}
|
|
648 |
if (r != KErrNone){
|
|
649 |
break;
|
|
650 |
}
|
|
651 |
E32Rofs* extensionRofs = new E32Rofs(extensionObeyFile);
|
|
652 |
r = extensionRofs->CreateExtension(imageInfo);
|
|
653 |
if (r!= KErrNone){
|
|
654 |
delete extensionRofs;
|
|
655 |
delete extensionObeyFile;
|
|
656 |
break;
|
|
657 |
}
|
|
658 |
r = extensionRofs->WriteImage(0);
|
|
659 |
|
|
660 |
delete extensionRofs;
|
|
661 |
extensionRofs = 0;
|
|
662 |
} while (r == KErrNone);
|
|
663 |
if(RofsImage) {
|
|
664 |
delete RofsImage;
|
|
665 |
}
|
|
666 |
if(core){
|
|
667 |
delete core;
|
|
668 |
}
|
|
669 |
delete mainObeyFile;
|
|
670 |
}
|
|
671 |
return r;
|
|
672 |
}//end of main.
|