author | marvin shi <marvin.shi@nokia.com> |
Tue, 30 Nov 2010 17:14:57 +0800 | |
changeset 714 | e5a58c351011 |
parent 707 | ccd52fece6ff |
permissions | -rw-r--r-- |
606 | 1 |
/* |
2 |
* Copyright (c) 1995-2009 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 |
* @internalComponent * @released |
|
16 |
* Rofsbuild Obey file class and its reader class. |
|
17 |
* |
|
18 |
*/ |
|
19 |
||
20 |
#include <strstream> |
|
21 |
#include <iomanip> |
|
22 |
||
23 |
#include <string.h> |
|
24 |
#include <stdlib.h> |
|
25 |
#include <stdio.h> |
|
26 |
#include <time.h> |
|
27 |
#include <assert.h> |
|
28 |
#include <errno.h> |
|
29 |
||
30 |
#include <e32std.h> |
|
31 |
#include <e32std_private.h> |
|
32 |
#include <e32rom.h> |
|
33 |
#include <u32std.h> |
|
34 |
#include <f32file.h> |
|
35 |
||
36 |
#include "h_utl.h" |
|
37 |
#include "r_obey.h" |
|
38 |
#include "r_coreimage.h" |
|
39 |
#include "patchdataprocessor.h" |
|
40 |
#include "fatimagegenerator.h" |
|
41 |
#include "r_driveimage.h" |
|
42 |
||
647 | 43 |
#ifdef __LINUX__ |
44 |
#include <dirent.h> |
|
45 |
#include <sys/stat.h> |
|
46 |
#include <unistd.h> |
|
47 |
#else |
|
48 |
#include <io.h> |
|
675 | 49 |
#include <direct.h> |
647 | 50 |
#include <conio.h> |
51 |
#endif |
|
52 |
||
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
53 |
#include "uniconv.hpp" |
606 | 54 |
extern TInt gCodePagingOverride; |
55 |
extern TInt gDataPagingOverride; |
|
56 |
extern ECompression gCompress; |
|
57 |
extern TBool gEnableStdPathWarning; // Default to not warn if destination path provided for a file is not in standard path. |
|
58 |
extern TBool gKeepGoing; |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
59 |
extern TBool gIsOBYUTF8; |
606 | 60 |
|
61 |
||
62 |
#define _P(word) word, sizeof(word)-1 // match prefix, optionally followed by [HWVD] |
|
63 |
#define _K(word) word, 0 // match whole word |
|
64 |
static char* const NullString = "" ; |
|
65 |
const ObeyFileKeyword ObeyFileReader::iKeywords[] = |
|
66 |
{ |
|
67 |
{_K("file"), 2,-2, EKeywordFile, "File to be copied into ROFS"}, |
|
68 |
{_K("data"), 2,-2, EKeywordData, "same as file"}, |
|
69 |
{_K("dir"), 2,1, EKeywordDir, "Directory to be created into FAT image"}, |
|
647 | 70 |
{_K("dircopy"), 2,-2, EKeywordDirCpy, "Directory to be copied into FAT image"}, |
606 | 71 |
|
72 |
{_K("rofsname"), 1, 1, EKeywordRofsName, "output file for ROFS image"}, |
|
73 |
{_K("romsize"), 1, 1, EKeywordRomSize, "size of ROM image"}, |
|
74 |
{_P("hide"), 2, -1, EKeywordHide, "Exclude named file from ROM directory structure"}, |
|
75 |
{_P("alias"), 2, -2, EKeywordAlias, "Create alias for existing file in ROM directory structure"}, |
|
76 |
{_P("rename"), 2, -2, EKeywordRename, "Change the name of a file in the ROM directory structure"}, |
|
77 |
{_K("rofssize"), 1, 1, EKeywordRofsSize, "maximum size of ROFS image"}, |
|
78 |
{_K("romchecksum"), 1, 1, EKeywordRofsChecksum, "desired 32-bit checksum value for the whole image"}, |
|
79 |
{_K("version"), 1, 1, EKeywordVersion, "ROFS image version number"}, |
|
80 |
{_K("time"), 1,-1, EKeywordTime, "ROFS image timestamp"}, |
|
81 |
{_K("extensionrofs"),1+2, 1, EKeywordExtensionRofs, "Start of definition of optional Extension ROFS"}, |
|
82 |
{_K("extensionrofsname"),1, 1, EKeywordCoreRofsName, "ROFS image on which extension ROFS is based"}, |
|
83 |
{_K("rem"), 0, 0, EKeywordNone, "comment"}, |
|
84 |
{_K("stop"), 0, 0, EKeywordNone, "Terminates OBEY file prematurely"}, |
|
85 |
{_K("romchecksum"), 1, 1, EKeywordRomChecksum, "desired 32-bit checksum value for the whole ROFS image"}, |
|
86 |
{_K("coreimage"), 1, 1, EKeywordCoreImage, "Core image to be used for extension directory structure"}, |
|
87 |
{_K("autosize"), 1, 1, EKeywordRofsAutoSize, "Automatically adjust maximum image size to actual used"}, |
|
88 |
{_K("pagingoverride"), 1, 1, EKeywordPagingOverride, "Overide the demand paging attributes for every file in ROM, NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"}, |
|
89 |
{_K("codepagingoverride"), 1, 1, EKeywordCodePagingOverride, "Overide the code paging attributes for every file in ROM, NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"}, |
|
90 |
{_K("datapagingoverride"), 1, 1, EKeywordDataPagingOverride, "Overide the data paging attributes for every file in ROM, NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"}, |
|
91 |
{_K("dataimagename"),1, 1,EKeywordDataImageName, "Data Drive image file name"}, |
|
92 |
{_K("dataimagefilesystem"),1, 1,EKeywordDataImageFileSystem, "Drive image file system format"}, |
|
93 |
{_K("dataimagesize"),1, 1,EKeywordDataImageSize, "Maximum size of Data Drive image"}, |
|
654 | 94 |
{_K("volumeid"),1, 1,EKeywordDataImageVolumeID, "Volume ID of Data Drive image"}, |
606 | 95 |
{_K("volume"),1, -1,EKeywordDataImageVolume, "Volume Label of Data Drive image"}, |
96 |
{_K("sectorsize"),1, 1,EKeywordDataImageSectorSize, "Sector size(in bytes) of Data Drive image"}, |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
97 |
{_K("clustersize"),1, 1,EKeywordDataImageClusterSize, "Cluster size(in bytes) of Data Drive image"}, |
606 | 98 |
{_K("fattable"),1, 1,EKeywordDataImageNoOfFats, "Number of FATs in the Data Drive image"}, |
99 |
// things we don't normally report in the help information |
|
100 |
{_K("trace"), 1, 1, EKeywordTrace, "(ROMBUILD activity trace flags)"}, |
|
101 |
{_K("filecompress"),2, -2,EKeywordFileCompress,"Non-XIP Executable to be loaded into the ROM compressed" }, |
|
102 |
{_K("fileuncompress"),2, -2,EKeywordFileUncompress,"Non-XIP Executable to be loaded into the ROM uncompressed" }, |
|
103 |
{_K("patchdata"),2, 5,EKeywordPatchDllData, "Patch exported data"}, |
|
104 |
{_K("imagename"), 1, 1, EKeywordSmrImageName, "output file for SMR image"}, |
|
617 | 105 |
{_K("hcrdata"), 1, 1, EKeywordSmrFileData, "file data for HCR SMR image"}, |
106 |
{_K("smrdata"), 1, 1, EKeywordSmrFileData, "file data for general SMR image"}, |
|
606 | 107 |
{_K("formatversion"), 1, 1, EKeywordSmrFormatVersion, "format version for HCR SMR image"}, |
108 |
{_K("payloadflags"), 1, 1, EKeywordSmrFlags, "payload flags for the HCR SMR image"}, |
|
109 |
{_K("payloaduid"), 1, 1, EKeywordSmrUID, "payload UID for the HCR SMR image"}, |
|
110 |
{0,0,0,0,EKeywordNone,""} |
|
111 |
}; |
|
112 |
||
113 |
void ObeyFileReader::KeywordHelp() { // static |
|
114 |
||
115 |
cout << "Obey file keywords:\n"; |
|
116 |
||
117 |
const ObeyFileKeyword* k=0; |
|
118 |
for (k=iKeywords; k->iKeyword!=0; k++) |
|
119 |
{ |
|
120 |
if (k->iHelpText == 0) |
|
121 |
continue; |
|
122 |
if (k->iHelpText[0]=='(' && !H.iVerbose) |
|
123 |
continue; // don't normally report things in (parentheses) |
|
124 |
||
125 |
char buf[32]; |
|
126 |
sprintf(buf, "%-20s", k->iKeyword); |
|
127 |
if (k->iKeywordLength) |
|
128 |
memcpy(buf+k->iKeywordLength,"[HWVD]",6); |
|
129 |
if (H.iVerbose) |
|
130 |
sprintf(buf+20,"%2d",k->iNumArgs); |
|
131 |
cout << " " << buf << " " << k->iHelpText << endl; |
|
132 |
} |
|
133 |
cout << endl; |
|
134 |
||
135 |
cout << "File attributes:\n"; |
|
136 |
||
137 |
const FileAttributeKeyword* f=0; |
|
138 |
for (f=iAttributeKeywords; f->iKeyword!=0; f++) |
|
139 |
{ |
|
140 |
if (f->iHelpText == 0) |
|
141 |
continue; |
|
142 |
if (f->iHelpText[0]=='(' && !H.iVerbose) |
|
143 |
continue; // don't normally report things in (parentheses) |
|
144 |
||
145 |
char buf[32]; |
|
146 |
sprintf(buf, "%-20s", f->iKeyword); |
|
147 |
if (H.iVerbose) |
|
148 |
sprintf(buf+20,"%2d",k->iNumArgs); |
|
149 |
cout << " " << buf << " " << f->iHelpText << endl; |
|
150 |
} |
|
151 |
cout << endl; |
|
152 |
} |
|
153 |
||
154 |
ObeyFileReader::ObeyFileReader(const char* aFileName):iCurrentLine(0), |
|
155 |
iFileName(aFileName),iNumWords(0),iLine(0),iMarkLine(0),iCurrentObeyStatement(0) { |
|
156 |
for(TUint i = 0 ; i < KNumWords ; i++) |
|
157 |
iWord[i] = NullString; |
|
158 |
*iSuffix = 0 ; |
|
159 |
} |
|
160 |
||
161 |
ObeyFileReader::~ObeyFileReader() { |
|
162 |
if(iCurrentObeyStatement) { |
|
163 |
delete []iCurrentObeyStatement; |
|
164 |
iCurrentObeyStatement = 0 ; |
|
165 |
} |
|
166 |
if(iLine) { |
|
167 |
delete []iLine; |
|
168 |
iLine = 0 ; |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
// |
|
173 |
// Open the file & return a status |
|
174 |
// |
|
175 |
TBool ObeyFileReader::Open() { |
|
176 |
ifstream ifs(iFileName.c_str(),ios_base::in + ios_base::binary); |
|
177 |
if (!ifs.is_open()) { |
|
178 |
Print(EError,"Cannot open obey file %s\n",iFileName.c_str()); |
|
179 |
return EFalse; |
|
180 |
} |
|
181 |
iLines.clear(); |
|
182 |
if(iLine){ |
|
183 |
delete []iLine; |
|
184 |
iLine = 0 ; |
|
185 |
} |
|
186 |
ifs.seekg(0,ios_base::end); |
|
187 |
size_t length = ifs.tellg(); |
|
188 |
char* buffer = new char[length + 2]; |
|
189 |
if (0 == buffer) { |
|
190 |
Print(EError,"Insufficent Memory to Continue."); |
|
191 |
ifs.close(); |
|
192 |
return EFalse; |
|
193 |
} |
|
194 |
ifs.seekg(0,ios_base::beg); |
|
195 |
ifs.read(buffer,length); |
|
196 |
size_t readcout = ifs.gcount() ; |
|
197 |
if(readcout != length){ |
|
198 |
Print(EError,"Cannot Read All of File."); |
|
199 |
delete []buffer ; |
|
200 |
ifs.close(); |
|
201 |
return EFalse; |
|
202 |
} |
|
203 |
buffer[length] = '\n'; |
|
204 |
buffer[length + 1] = 0 ; |
|
205 |
ifs.close(); |
|
206 |
char* lineStart = buffer ; |
|
207 |
char* end = buffer + length ; |
|
208 |
string line ; |
|
209 |
size_t maxLengthOfLine = 0 ; |
|
210 |
while(lineStart < end){ |
|
211 |
while(*lineStart == ' ' || *lineStart == '\t') //trimleft |
|
212 |
lineStart ++ ; |
|
213 |
char* lineEnd = lineStart ; |
|
214 |
while(*lineEnd != '\r' && *lineEnd != '\n') |
|
215 |
lineEnd ++ ; |
|
216 |
if(strnicmp(lineStart,"REM",3) == 0){ |
|
217 |
line = "" ; // REMOVE "REM ... " |
|
218 |
} |
|
219 |
else { |
|
220 |
TInt lastIndex = lineEnd - lineStart - 1; |
|
221 |
while(lastIndex >= 0 && // trimright |
|
222 |
(lineStart[lastIndex] == ' ' || lineStart[lastIndex] == '\t')) |
|
223 |
lastIndex -- ; |
|
224 |
if(lastIndex >= 0) |
|
225 |
line.assign(lineStart,lastIndex + 1); |
|
226 |
else |
|
227 |
line = ""; |
|
228 |
} |
|
229 |
if(line.length() > maxLengthOfLine) |
|
230 |
maxLengthOfLine = line.length(); |
|
231 |
iLines.push_back(line); |
|
232 |
if(*lineEnd == '\r') { |
|
233 |
if(lineEnd[1] == '\n') |
|
234 |
lineStart = lineEnd + 2 ; |
|
235 |
else |
|
236 |
lineStart = lineEnd + 1 ; |
|
237 |
} |
|
238 |
else // '\n' |
|
239 |
lineStart = lineEnd + 1 ; |
|
240 |
} |
|
241 |
delete []buffer ; |
|
242 |
iLine = new char[maxLengthOfLine + 1]; |
|
243 |
iCurrentObeyStatement = new char[maxLengthOfLine + 1]; |
|
244 |
*iCurrentObeyStatement = 0 ; |
|
245 |
*iLine = 0 ; |
|
246 |
iCurrentLine = 0 ; |
|
247 |
iMarkLine = 0 ; |
|
248 |
return ETrue; |
|
249 |
} |
|
250 |
||
251 |
void ObeyFileReader::Mark() { |
|
252 |
iMarkLine = iCurrentLine - 1; |
|
253 |
} |
|
254 |
||
255 |
void ObeyFileReader::MarkNext() { |
|
256 |
iMarkLine = iCurrentLine; |
|
257 |
} |
|
258 |
||
259 |
void ObeyFileReader::Rewind() { |
|
260 |
iCurrentLine = iMarkLine; |
|
261 |
} |
|
262 |
||
263 |
char* ObeyFileReader::DupWord(TInt aIndex) const { |
|
264 |
char* retVal = 0 ; |
|
265 |
if(aIndex >= 0 && aIndex < (TInt)KNumWords){ |
|
266 |
size_t len = strlen(iWord[aIndex]) + 1; |
|
267 |
retVal = new char[len]; |
|
268 |
if(retVal) |
|
269 |
memcpy(retVal,iWord[aIndex],len); |
|
270 |
} |
|
271 |
return retVal ; |
|
272 |
} |
|
273 |
||
274 |
TInt ObeyFileReader::ReadAndParseLine() { |
|
275 |
if (iCurrentLine >= (TInt)iLines.size()) |
|
276 |
return KErrEof; |
|
277 |
iCurrentLine++; |
|
278 |
iNumWords = Parse(); |
|
279 |
return KErrNone; |
|
280 |
} |
|
281 |
||
282 |
TInt ObeyFileReader::NextLine(TInt aPass, enum EKeyword& aKeyword) { |
|
647 | 283 |
static int warnline = -1; |
606 | 284 |
NextLine: |
285 |
TInt err = ReadAndParseLine(); |
|
286 |
if (err == KErrEof) |
|
287 |
return KErrEof; |
|
288 |
if(iNumWords == 0) |
|
289 |
goto NextLine; |
|
290 |
if (stricmp(iWord[0], "stop")==0) |
|
291 |
return KErrEof; |
|
292 |
||
293 |
const ObeyFileKeyword* k=0; |
|
294 |
for (k=iKeywords; k->iKeyword!=0; k++) { |
|
295 |
if (k->iKeywordLength == 0) { |
|
296 |
// Exact case-insensitive match on keyword |
|
297 |
if (stricmp(iWord[0], k->iKeyword) != 0) |
|
298 |
continue; |
|
299 |
*iSuffix = 0; |
|
300 |
} |
|
301 |
else { |
|
302 |
// Prefix match |
|
303 |
if (strnicmp(iWord[0], k->iKeyword, k->iKeywordLength) != 0) |
|
304 |
continue; |
|
305 |
// Suffix must be empty, or a variant number in [] |
|
306 |
strncpy(iSuffix,iWord[0] + k->iKeywordLength,80); |
|
307 |
if (*iSuffix != '\0' && *iSuffix != '[') |
|
308 |
continue; |
|
309 |
} |
|
310 |
// found a match |
|
311 |
if ((k->iPass & aPass) == 0) |
|
312 |
goto NextLine; |
|
313 |
if (k->iNumArgs>=0 && (1+k->iNumArgs != iNumWords)) { |
|
314 |
Print(EError, "Incorrect number of arguments for keyword %s on line %d.\n", |
|
315 |
iWord[0], iCurrentLine); |
|
316 |
goto NextLine; |
|
317 |
} |
|
318 |
if (k->iNumArgs<0 && (1-k->iNumArgs > iNumWords)) { |
|
319 |
Print(EError, "Too few arguments for keyword %s on line %d.\n", |
|
320 |
iWord[0], iCurrentLine); |
|
321 |
goto NextLine; |
|
322 |
} |
|
323 |
||
324 |
aKeyword = k->iKeywordEnum; |
|
325 |
return KErrNone; |
|
326 |
} |
|
647 | 327 |
if (aPass == 1 && iCurrentLine > warnline){ |
328 |
warnline = iCurrentLine; |
|
606 | 329 |
Print(EWarning, "Unknown keyword '%s'. Line %d ignored\n", iWord[0], iCurrentLine); |
647 | 330 |
} |
606 | 331 |
goto NextLine; |
332 |
} |
|
333 |
||
334 |
// |
|
335 |
// splits a line into words, and returns the number of words found |
|
336 |
// |
|
337 |
TInt ObeyFileReader::Parse() { |
|
338 |
||
339 |
for (TUint i = 0; i < KNumWords; i++) |
|
340 |
iWord[i] = NullString; |
|
341 |
||
342 |
enum TState {EInWord, EInQuotedWord, EInGap}; |
|
343 |
TState state = EInGap; |
|
344 |
const string& line = iLines[iCurrentLine - 1]; |
|
345 |
size_t len = line.length(); |
|
346 |
memcpy(iLine,line.c_str(),len); |
|
347 |
memcpy(iCurrentObeyStatement,iLine,len); |
|
348 |
iLine[len] = 0 ; |
|
349 |
iCurrentObeyStatement[len] = 0 ; |
|
350 |
TUint i = 0; |
|
351 |
char* linestr = iLine; |
|
352 |
while (i < KNumWords && *linestr != 0) { |
|
353 |
switch (state) |
|
354 |
{ |
|
355 |
case EInGap: |
|
356 |
if (*linestr =='\"') { |
|
357 |
if (linestr[1] != 0 && linestr[1]!='\"') |
|
358 |
iWord[i++] = linestr + 1; |
|
359 |
state = EInQuotedWord; |
|
360 |
} |
|
361 |
else if (!IsGap(*linestr)) { |
|
362 |
iWord[i++] = linestr; |
|
363 |
state=EInWord; |
|
364 |
} |
|
365 |
else |
|
366 |
*linestr=0; |
|
367 |
break; |
|
368 |
case EInWord: |
|
369 |
if (*linestr == '\"') { |
|
370 |
*linestr = 0; |
|
371 |
if (linestr[1] != 0 && linestr[1] != '\"') |
|
372 |
iWord[i++] = linestr+1; |
|
373 |
state=EInQuotedWord; |
|
374 |
} |
|
375 |
else if (IsGap(*linestr)) { |
|
376 |
*linestr=0; |
|
377 |
state=EInGap; |
|
378 |
} |
|
379 |
break; |
|
380 |
case EInQuotedWord: |
|
381 |
if (*linestr == '\"'){ |
|
382 |
*linestr = 0; |
|
383 |
state = EInGap; |
|
384 |
} |
|
385 |
break; |
|
386 |
} |
|
387 |
linestr++; |
|
388 |
} |
|
389 |
return i; |
|
390 |
} |
|
391 |
||
392 |
// |
|
393 |
// Process the timestamp |
|
394 |
// |
|
395 |
void ObeyFileReader::ProcessTime(TInt64& aTime) { |
|
396 |
char timebuf[256]; |
|
397 |
if (iNumWords>2) |
|
398 |
sprintf(timebuf, "%s_%s", iWord[1], iWord[2]); |
|
399 |
else |
|
400 |
strncpy(timebuf, iWord[1],256); |
|
401 |
||
402 |
TInt r = StringToTime(aTime, timebuf); |
|
403 |
if (r==KErrGeneral) { |
|
404 |
Print(EError, "incorrect format for time keyword on line %d\n", iCurrentLine); |
|
405 |
exit(0x670); |
|
406 |
} |
|
407 |
if (r==KErrArgument){ |
|
408 |
Print(EError, "Time out of range on line %d\n", iCurrentLine); |
|
409 |
exit(0x670); |
|
410 |
} |
|
411 |
} |
|
412 |
||
413 |
TInt64 ObeyFileReader::iTimeNow = 0; |
|
414 |
void ObeyFileReader::TimeNow(TInt64& aTime) { |
|
415 |
if (iTimeNow==0) { |
|
416 |
TInt sysTime = time(0); // seconds since midnight Jan 1st, 1970 |
|
417 |
sysTime -= (30*365*24*60*60+7*24*60*60); // seconds since midnight Jan 1st, 2000 |
|
418 |
TInt64 daysTo2000AD=730497; |
|
419 |
TInt64 t=daysTo2000AD*24*3600+sysTime; // seconds since 0000 |
|
420 |
t = t+3600; // BST (?) |
|
421 |
iTimeNow=t*1000000; // milliseconds |
|
422 |
} |
|
423 |
aTime=iTimeNow; |
|
424 |
} |
|
425 |
||
426 |
||
427 |
||
428 |
// File attributes. |
|
429 |
||
430 |
||
431 |
const FileAttributeKeyword ObeyFileReader::iAttributeKeywords[] = |
|
432 |
{ |
|
433 |
{"attrib",3 ,0,1,EAttributeAtt, "File attributes in ROM file system"}, |
|
434 |
{"exattrib",3 ,0,1,EAttributeAttExtra, "File extra attributes in ROM file system"}, |
|
435 |
{"stack",3 ,1,1,EAttributeStack, "?"}, |
|
436 |
{"fixed",3 ,1,0,EAttributeFixed, "Relocate to a fixed address space"}, |
|
437 |
{"priority",3 ,1,1,EAttributePriority, "Override process priority"}, |
|
438 |
{_K("uid1") ,1,1,EAttributeUid1, "Override first UID"}, |
|
439 |
{_K("uid2") ,1,1,EAttributeUid2, "Override second UID"}, |
|
440 |
{_K("uid3") ,1,1,EAttributeUid3, "Override third UID"}, |
|
441 |
{_K("heapmin") ,1,1,EAttributeHeapMin, "Override initial heap size"}, |
|
442 |
{_K("heapmax") ,1,1,EAttributeHeapMax, "Override maximum heap size"}, |
|
443 |
{_K("capability") ,1,1,EAttributeCapability, "Override capabilities"}, |
|
444 |
{_K("unpaged") ,1,0,EAttributeUnpaged, "Don't page code or data for this file"}, |
|
445 |
{_K("paged") ,1,0,EAttributePaged, "Page code and data for this file"}, |
|
446 |
{_K("unpagedcode") ,1,0,EAttributeUnpagedCode, "Don't page code for this file"}, |
|
447 |
{_K("pagedcode") ,1,0,EAttributePagedCode, "Page code for this file"}, |
|
448 |
{_K("unpageddata") ,1,0,EAttributeUnpagedData, "Don't page data for this file"}, |
|
449 |
{_K("pageddata") ,1,0,EAttributePagedData, "Page data for this file"}, |
|
450 |
{0,0,0,0,EAttributeAtt,0} |
|
451 |
}; |
|
452 |
||
453 |
TInt ObeyFileReader::NextAttribute(TInt& aIndex, TInt aHasFile, enum EFileAttribute& aKeyword, char*& aArg) |
|
454 |
{ |
|
455 |
NextAttribute: |
|
456 |
if (aIndex >= iNumWords) |
|
457 |
return KErrEof; |
|
458 |
char* word=iWord[aIndex++]; |
|
459 |
const FileAttributeKeyword* k; |
|
460 |
for (k=iAttributeKeywords; k->iKeyword!=0; k++) |
|
461 |
{ |
|
462 |
if (k->iKeywordLength == 0) |
|
463 |
{ |
|
464 |
// Exact match on keyword |
|
465 |
if (stricmp(word, k->iKeyword) != 0) |
|
466 |
continue; |
|
467 |
} |
|
468 |
else |
|
469 |
{ |
|
470 |
// Prefix match |
|
471 |
if (strnicmp(word, k->iKeyword, k->iKeywordLength) != 0) |
|
472 |
continue; |
|
473 |
} |
|
474 |
// found a match |
|
475 |
if (k->iNumArgs>0) |
|
476 |
{ |
|
477 |
TInt argIndex = aIndex; |
|
478 |
aIndex += k->iNumArgs; // interface only really supports 1 argument |
|
479 |
if (aIndex>iNumWords) |
|
480 |
{ |
|
481 |
Print(EError, "Missing argument for attribute %s on line %d\n", word, iCurrentLine); |
|
482 |
return KErrArgument; |
|
483 |
} |
|
484 |
aArg=iWord[argIndex]; |
|
485 |
} |
|
486 |
if (k->iIsFileAttribute && !aHasFile) |
|
487 |
{ |
|
488 |
Print(EError, "File attribute %s applied to non-file on line %d\n", word, iCurrentLine); |
|
489 |
return KErrNotSupported; |
|
490 |
} |
|
491 |
aKeyword=k->iAttributeEnum; |
|
492 |
return KErrNone; |
|
493 |
} |
|
494 |
Print(EWarning, "Unknown attribute '%s' skipped on line %d\n", word, iCurrentLine); |
|
495 |
goto NextAttribute; |
|
496 |
} |
|
497 |
||
498 |
||
499 |
||
500 |
/** |
|
501 |
Constructor: |
|
502 |
1.Obey file instance. |
|
503 |
2.used by both rofs and datadrive image. |
|
504 |
||
505 |
@param aReader - obey file reader object. |
|
506 |
*/ |
|
507 |
CObeyFile::CObeyFile(ObeyFileReader& aReader): |
|
508 |
iRomFileName(NULL), |
|
509 |
iExtensionRofsName(0), |
|
510 |
iKernelRofsName(0), |
|
511 |
iRomSize(0), |
|
512 |
iVersion(0,0,0), |
|
513 |
iCheckSum(0), |
|
514 |
iNumberOfFiles(0), |
|
515 |
iTime(0), |
|
516 |
iRootDirectory(0), |
|
517 |
iNumberOfDataFiles(0), |
|
518 |
iDriveFileName(0), |
|
519 |
iDriveFileFormat(0), |
|
520 |
iReader(aReader), |
|
521 |
iMissingFiles(0), |
|
522 |
iLastExecutable(0), |
|
523 |
iFirstFile(0), |
|
524 |
iCurrentFile(0), |
|
525 |
iAutoSize(EFalse), |
|
526 |
iAutoPageSize(4096), |
|
527 |
iPagingOverrideParsed(0), |
|
528 |
iCodePagingOverrideParsed(0), |
|
529 |
iDataPagingOverrideParsed(0), |
|
530 |
iPatchData(new CPatchDataProcessor) |
|
531 |
{ |
|
532 |
iNextFilePtrPtr = &iFirstFile ; |
|
533 |
} |
|
534 |
||
535 |
/** |
|
536 |
Obey file Destructor. |
|
537 |
1.Release the tree memory. |
|
538 |
2.Release all allocated memory if any. |
|
539 |
*/ |
|
540 |
CObeyFile::~CObeyFile() { |
|
541 |
if(iDriveFileName){ |
|
542 |
delete[] iDriveFileName; |
|
543 |
iDriveFileName = 0 ; |
|
544 |
} |
|
545 |
if(iDriveFileFormat) { |
|
546 |
delete[] iDriveFileFormat; |
|
547 |
iDriveFileFormat = 0 ; |
|
548 |
} |
|
549 |
iRootDirectory->deleteTheFirstNode(); |
|
550 |
iRootDirectory->InitializeCount(); |
|
551 |
||
552 |
Release(); |
|
553 |
if(iRomFileName){ |
|
554 |
delete [] iRomFileName; |
|
555 |
iRomFileName = 0 ; |
|
556 |
} |
|
557 |
if (iRootDirectory) |
|
558 |
iRootDirectory->Destroy(); |
|
559 |
if(iPatchData) |
|
560 |
delete iPatchData; |
|
561 |
} |
|
562 |
||
563 |
// |
|
564 |
// Free resources not needed after building a ROM |
|
565 |
// |
|
566 |
void CObeyFile::Release() { |
|
567 |
iFirstFile = 0; |
|
568 |
iNextFilePtrPtr = &iFirstFile; |
|
569 |
} |
|
570 |
||
571 |
TRomBuilderEntry *CObeyFile::FirstFile() { |
|
572 |
iCurrentFile = iFirstFile; |
|
573 |
return iCurrentFile; |
|
574 |
} |
|
575 |
||
576 |
TRomBuilderEntry *CObeyFile::NextFile() { |
|
577 |
iCurrentFile = iCurrentFile ? iCurrentFile->iNext : 0; |
|
578 |
return iCurrentFile; |
|
579 |
} |
|
580 |
||
581 |
char* CObeyFile::ProcessCoreImage() const { |
|
582 |
// check for coreimage keyword and return filename |
|
583 |
enum EKeyword keyword; |
|
584 |
char* coreImageFileName = 0; |
|
585 |
iReader.Rewind(); |
|
586 |
while (iReader.NextLine(1,keyword) != KErrEof) { |
|
587 |
if (keyword == EKeywordCoreImage) { |
|
588 |
coreImageFileName = iReader.DupWord(1); |
|
589 |
iReader.MarkNext(); |
|
590 |
break; |
|
591 |
} |
|
592 |
} |
|
593 |
return coreImageFileName; |
|
594 |
} |
|
595 |
||
596 |
void CObeyFile::SkipToExtension() { |
|
597 |
iReader.Rewind(); |
|
598 |
enum EKeyword keyword; |
|
599 |
while (iReader.NextLine(1,keyword) != KErrEof) { |
|
600 |
if (keyword == EKeywordExtensionRofs) { |
|
601 |
iReader.Mark(); // ready for processing extension |
|
602 |
break; |
|
603 |
} |
|
604 |
} |
|
605 |
} |
|
606 |
||
607 |
TInt CObeyFile::ProcessRofs() { |
|
608 |
||
609 |
// |
|
610 |
// First pass through the obey file to set up key variables |
|
611 |
// |
|
612 |
||
613 |
iReader.Rewind(); |
|
614 |
||
615 |
TInt count=0; |
|
616 |
enum EKeyword keyword; |
|
617 |
while (iReader.NextLine(1,keyword) != KErrEof) { |
|
618 |
if (keyword == EKeywordExtensionRofs){ |
|
619 |
if (count==0) |
|
620 |
return KErrNotFound; // no core ROFS, just extension ROFSs. |
|
621 |
break; |
|
622 |
} |
|
623 |
||
624 |
count++; |
|
625 |
if (! ProcessKeyword(keyword)) |
|
626 |
return KErrGeneral; |
|
627 |
} |
|
628 |
||
629 |
if (!GotKeyVariables()) |
|
630 |
return KErrGeneral; |
|
631 |
||
632 |
// |
|
633 |
// second pass to process the file specifications in the obey file building |
|
634 |
// up the TRomNode directory structure and the TRomBuilderEntry list |
|
635 |
// |
|
636 |
iReader.Rewind(); |
|
637 |
||
638 |
iRootDirectory = new TRomNode(""); |
|
639 |
iLastExecutable = iRootDirectory; |
|
640 |
||
641 |
TInt align=0; |
|
642 |
while (iReader.NextLine(2,keyword)!=KErrEof) { |
|
643 |
if (keyword == EKeywordExtensionRofs) |
|
644 |
break; |
|
645 |
||
646 |
if (keyword == EKeywordHide) |
|
647 |
keyword = EKeywordHideV2; |
|
648 |
||
649 |
switch (keyword) |
|
650 |
{ |
|
651 |
case EKeywordHide: |
|
652 |
case EKeywordAlias: |
|
653 |
case EKeywordRename: |
|
654 |
if (!ProcessRenaming(keyword)) |
|
655 |
return KErrGeneral; |
|
656 |
break; |
|
657 |
case EKeywordPatchDllData: |
|
658 |
{ |
|
659 |
// Collect patchdata statements to process at the end |
|
660 |
StringVector patchDataTokens; |
|
661 |
SplitPatchDataStatement(patchDataTokens); |
|
662 |
iPatchData->AddPatchDataStatement(patchDataTokens); |
|
663 |
break; |
|
664 |
} |
|
665 |
default: |
|
666 |
if (!ProcessFile(align, keyword)) |
|
667 |
return KErrGeneral; |
|
668 |
align=0; |
|
669 |
break; |
|
670 |
} |
|
671 |
} |
|
672 |
||
673 |
if(!ParsePatchDllData()) |
|
674 |
return KErrGeneral; |
|
675 |
iReader.Mark(); // ready for processing the extension rom(s) |
|
676 |
||
677 |
if (iMissingFiles!=0) { |
|
678 |
return KErrGeneral; |
|
679 |
} |
|
680 |
if ( 0 == iNumberOfFiles ){ |
|
681 |
Print(EError, "No files specified.\n"); |
|
682 |
return KErrGeneral; |
|
683 |
} |
|
684 |
||
685 |
return KErrNone; |
|
686 |
} |
|
687 |
||
688 |
TBool CObeyFile::Process() { |
|
689 |
TBool result = ETrue; |
|
690 |
iReader.Rewind(); |
|
691 |
enum EKeyword keyword; |
|
692 |
while(iReader.NextLine(1, keyword) != KErrEof){ |
|
693 |
string key = iReader.Word(0); |
|
694 |
string value = iReader.Word(1); |
|
695 |
if(iKeyValues.find(key) != iKeyValues.end()){ |
|
696 |
iKeyValues[key].push_back(value); |
|
697 |
} |
|
698 |
else { |
|
699 |
StringVector values; |
|
700 |
values.push_back(value); |
|
701 |
iKeyValues[key]=values; |
|
702 |
} |
|
703 |
||
704 |
||
705 |
} |
|
706 |
return result; |
|
707 |
} |
|
708 |
StringVector CObeyFile::getValues(const string& aKey) { |
|
709 |
StringVector values; |
|
710 |
if(iKeyValues.find(aKey) != iKeyValues.end()){ |
|
711 |
values = iKeyValues[aKey]; |
|
712 |
} |
|
713 |
return values; |
|
714 |
} |
|
715 |
||
716 |
/** |
|
717 |
Process drive obey file and construct the tree. |
|
718 |
||
719 |
@return - Return the status, |
|
720 |
'KErrnone' for Success, |
|
721 |
'KErrGeneral' for failure (required keywords not there in obey file or failed |
|
722 |
to construct the tree). |
|
723 |
*/ |
|
724 |
TInt CObeyFile::ProcessDataDrive() { |
|
725 |
iReader.Rewind(); |
|
726 |
enum EKeyword keyword; |
|
727 |
||
728 |
// First pass through the obey file to set up key variables |
|
729 |
while (iReader.NextLine(1,keyword) != KErrEof) { |
|
730 |
if (!ProcessDriveKeyword(keyword)) |
|
731 |
return KErrGeneral; |
|
732 |
} |
|
733 |
||
734 |
if (!GotKeyDriveVariables()) |
|
735 |
return KErrGeneral; |
|
736 |
||
737 |
// Second pass to process the file specifications in the obey file. |
|
738 |
// Build the TRomNode directory structure and the TRomBuilderEntry list |
|
739 |
iReader.Rewind(); |
|
740 |
iRootDirectory = new TRomNode("//"); |
|
741 |
iLastExecutable = iRootDirectory; |
|
742 |
||
743 |
while(iReader.NextLine(2,keyword)!=KErrEof) { |
|
744 |
switch (keyword) |
|
745 |
{ |
|
746 |
case EKeywordPatchDllData: |
|
747 |
{ // Collect patchdata statements to process at the end |
|
748 |
StringVector patchDataTokens; |
|
749 |
SplitPatchDataStatement(patchDataTokens); |
|
750 |
iPatchData->AddPatchDataStatement(patchDataTokens); |
|
751 |
break; |
|
752 |
} |
|
753 |
||
754 |
case EKeywordHide: |
|
755 |
case EKeywordFile: |
|
756 |
case EKeywordDir: |
|
647 | 757 |
case EKeywordDirCpy: |
606 | 758 |
case EKeywordData: |
759 |
case EKeywordFileCompress: |
|
760 |
case EKeywordFileUncompress: |
|
761 |
if (!ProcessDriveFile(keyword)) |
|
762 |
return KErrGeneral; |
|
763 |
break; |
|
764 |
||
765 |
default: |
|
766 |
break; |
|
767 |
} |
|
768 |
} |
|
769 |
||
770 |
if(!ParsePatchDllData()) |
|
771 |
return KErrGeneral; |
|
772 |
if (iMissingFiles) { |
|
773 |
Print(EError, "Source Files Missing.\n"); |
|
774 |
return KErrGeneral; |
|
775 |
} |
|
776 |
if (!iNumberOfFiles) |
|
617 | 777 |
Print(EAlways,"No files specified.\n"); |
606 | 778 |
|
779 |
return KErrNone; |
|
780 |
} |
|
781 |
||
782 |
||
783 |
/** |
|
784 |
Process and stores the keyword information. |
|
785 |
||
786 |
@param aKeyword - keyword to update its value to variables. |
|
787 |
@return - Return the status i.e Success, |
|
788 |
*/ |
|
789 |
TBool CObeyFile::ProcessDriveKeyword(enum EKeyword aKeyword) { |
|
790 |
||
791 |
TBool success = ETrue; |
|
792 |
switch (aKeyword) |
|
793 |
{ |
|
794 |
case EKeywordDataImageName: |
|
795 |
iDriveFileName = iReader.DupWord(1); |
|
796 |
break; |
|
797 |
case EKeywordDataImageFileSystem: |
|
798 |
iDriveFileFormat = iReader.DupWord(1); |
|
799 |
break; |
|
800 |
case EKeywordDataImageSize: |
|
801 |
{ |
|
802 |
const char* bigString = iReader.Word(1); |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
803 |
TInt64 imagesize = 0; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
804 |
Val(imagesize,bigString); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
805 |
if(imagesize <= 0) |
606 | 806 |
{ |
807 |
Print(EWarning,"Not a valid Image Size. Default size is considered\n"); |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
808 |
}else |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
809 |
{ |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
810 |
iConfigurableFatAttributes.iImageSize = imagesize; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
811 |
} |
606 | 812 |
} |
813 |
break; |
|
814 |
case EKeywordDataImageVolume: |
|
815 |
{ |
|
816 |
// Get the volume label provided by using "volume" keyword. |
|
817 |
// e.g. vlolume = NO NAME |
|
818 |
string volumeLabel = iReader.GetCurrentObeyStatement(); |
|
819 |
string volumeLabelKeyword = "volume"; |
|
820 |
||
821 |
TUint position = volumeLabel.find(volumeLabelKeyword.c_str(),0,volumeLabelKeyword.size()); |
|
822 |
position += volumeLabelKeyword.size(); |
|
654 | 823 |
while (iReader.IsGap(volumeLabel[position])) |
824 |
position ++; |
|
825 |
volumeLabel = volumeLabel.substr(position); |
|
826 |
||
827 |
if (volumeLabel.find('=',0) != string::npos) { |
|
828 |
Print(EWarning,"Value for Volume Label includes illegel charactor. Default value is considered.\n"); |
|
829 |
break; |
|
606 | 830 |
} |
831 |
||
654 | 832 |
// Remove the new line character from the end |
833 |
position = volumeLabel.find_first_of("\n"); |
|
606 | 834 |
if (position != string::npos) { |
654 | 835 |
if (position != 0 && volumeLabel[position-1] == '\r') |
836 |
position --; |
|
837 |
volumeLabel = volumeLabel.substr(0,position); |
|
606 | 838 |
} |
654 | 839 |
size_t length = volumeLabel.length(); |
840 |
if (length == 0) { |
|
606 | 841 |
Print(EWarning,"Value for Volume Label is not provided. Default value is considered.\n"); |
654 | 842 |
break; |
606 | 843 |
} |
654 | 844 |
if(length > 11) |
845 |
length = 11 ; |
|
846 |
memcpy(iConfigurableFatAttributes.iDriveVolumeLabel,volumeLabel.c_str(),length) ; |
|
847 |
while(length != 11) |
|
848 |
iConfigurableFatAttributes.iDriveVolumeLabel[length++] = ' '; |
|
849 |
iConfigurableFatAttributes.iDriveVolumeLabel[length] = 0; |
|
606 | 850 |
break; |
851 |
} |
|
852 |
case EKeywordDataImageSectorSize: |
|
853 |
{ |
|
854 |
const char* bigString = iReader.Word(1); |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
855 |
TInt sectorSize = 0; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
856 |
Val(sectorSize,bigString); |
606 | 857 |
if(sectorSize <= 0) { |
858 |
Print(EWarning,"Invalid Sector Size value. Default value is considered.\n"); |
|
859 |
} |
|
860 |
else { |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
861 |
iConfigurableFatAttributes.iDriveSectorSize = sectorSize; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
862 |
} |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
863 |
} |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
864 |
break; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
865 |
case EKeywordDataImageClusterSize: |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
866 |
{ |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
867 |
const char* bigString = iReader.Word(1); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
868 |
TInt clusterSize = 0; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
869 |
Val(clusterSize,bigString); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
870 |
if(clusterSize <= 0) { |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
871 |
Print(EWarning,"Invalid Cluster Size value. Default value is considered.\n"); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
872 |
} |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
873 |
else { |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
874 |
iConfigurableFatAttributes.iDriveClusterSize = clusterSize; |
606 | 875 |
} |
876 |
} |
|
877 |
break; |
|
878 |
case EKeywordDataImageNoOfFats: |
|
879 |
{ |
|
880 |
const char* bigString = iReader.Word(1); |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
881 |
TInt noOfFats = 0; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
882 |
Val(noOfFats,bigString); |
606 | 883 |
if (noOfFats <=0) |
884 |
Print(EWarning,"Invalid No of FATs specified. Default value is considered.\n"); |
|
885 |
else |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
886 |
iConfigurableFatAttributes.iDriveNoOfFATs = noOfFats; |
606 | 887 |
} |
888 |
break; |
|
654 | 889 |
case EKeywordDataImageVolumeID: |
890 |
{ |
|
891 |
static bool isSet = false; |
|
892 |
if (isSet) |
|
893 |
Print(EWarning,"Duplicate setting for volume ID will be ignored.\n"); |
|
894 |
const char* bigString = iReader.Word(1); |
|
895 |
TUint32 volumeid = 0; |
|
896 |
TInt res = Val(volumeid,bigString); |
|
897 |
if (res != KErrNone || volumeid == 0xFFFFFFFF) |
|
898 |
Print(EWarning,"Invalid Volume ID specified. Default value is considered.\n"); |
|
899 |
else |
|
900 |
iConfigurableFatAttributes.iVolumeId = volumeid; |
|
901 |
isSet = true; |
|
902 |
} |
|
903 |
break; |
|
606 | 904 |
default: |
905 |
// unexpected keyword iReader.Word(0), keep going. |
|
906 |
break; |
|
907 |
} |
|
908 |
return success; |
|
909 |
} |
|
910 |
||
911 |
||
912 |
/** |
|
913 |
Checks whether obeyfile has supplied enough variables to continue. |
|
914 |
||
915 |
@return - Return the status |
|
916 |
ETrue - Supplied valid values, |
|
917 |
EFalse- Not valied values. |
|
918 |
*/ |
|
919 |
TBool CObeyFile::GotKeyDriveVariables() { |
|
920 |
||
921 |
TBool retVal=ETrue; |
|
922 |
||
923 |
// Mandatory keywords |
|
924 |
if (iDriveFileName==0) { |
|
925 |
Print(EError,"The name of the image file has not been supplied.\n"); |
|
926 |
Print(EError,"Use the keyword \"dataimagename\".\n"); |
|
927 |
retVal = EFalse; |
|
928 |
} |
|
929 |
// Check for '-'ve entered value. |
|
930 |
if(iConfigurableFatAttributes.iImageSize <= 0){ |
|
931 |
Print(EWarning,"Image Size should be positive. Default size is Considered.\n"); |
|
932 |
} |
|
933 |
||
934 |
// File system format. |
|
935 |
if(iDriveFileFormat==0) { |
|
936 |
Print(EError,"The name of the file system not been supplied.\n"); |
|
937 |
Print(EError,"Use the keyword \"dataimagefilesystem\".\n"); |
|
938 |
retVal = EFalse; |
|
939 |
} |
|
940 |
||
941 |
// Checking the validity of file system format. |
|
942 |
if(iDriveFileFormat){ |
|
943 |
if(stricmp(iDriveFileFormat,"FAT16") && stricmp(iDriveFileFormat,"FAT32")) { |
|
944 |
Print(EError,"The name of the file system not supported : %s\n",iDriveFileFormat); |
|
945 |
retVal = EFalse; |
|
946 |
} |
|
947 |
} |
|
948 |
if(retVal) |
|
949 |
Print(ELog,"\nCreating Data Drive image : %s\n", iDriveFileName); |
|
950 |
||
951 |
return retVal; |
|
952 |
} |
|
953 |
||
954 |
/** |
|
955 |
Process a parsed line to set up one or more new TRomBuilder entry objects. |
|
956 |
||
957 |
@param - obey file keyword. |
|
958 |
// iWord[0] = the keyword (file,) |
|
959 |
// iWord[1] = the PC pathname |
|
960 |
// iWord[2] = the EPOC pathname |
|
961 |
// iWord[3] = start of the file attributes |
|
962 |
||
963 |
@return - Return the status |
|
964 |
ETrue - Successful generation of tree. |
|
965 |
EFalse- Fail to generate the tree. |
|
966 |
*/ |
|
967 |
TBool CObeyFile::ProcessDriveFile(enum EKeyword aKeyword) { |
|
968 |
||
969 |
TBool aFileCompressOption, aFileUncompressOption; |
|
970 |
||
971 |
TInt epocPathStart=2; |
|
972 |
aFileCompressOption = aFileUncompressOption = EFalse; |
|
973 |
// do some validation of the keyword |
|
974 |
TInt currentLine = iReader.CurrentLine(); |
|
975 |
||
976 |
switch (aKeyword) |
|
977 |
{ |
|
978 |
case EKeywordData: |
|
979 |
case EKeywordDir: |
|
647 | 980 |
case EKeywordDirCpy: |
606 | 981 |
case EKeywordHide: |
982 |
break; |
|
983 |
||
984 |
case EKeywordFile: |
|
985 |
break; |
|
986 |
||
987 |
case EKeywordFileCompress: |
|
988 |
aFileCompressOption = ETrue; |
|
989 |
break; |
|
990 |
||
991 |
case EKeywordFileUncompress: |
|
992 |
aFileUncompressOption = ETrue; |
|
993 |
break; |
|
994 |
||
995 |
default: |
|
996 |
return EFalse; |
|
997 |
} |
|
998 |
||
647 | 999 |
if (aKeyword!=EKeywordHide && aKeyword!=EKeywordDir && aKeyword!=EKeywordDirCpy) { |
606 | 1000 |
// check the PC file exists |
1001 |
char* nname = NormaliseFileName(iReader.Word(1)); |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1002 |
if(gIsOBYUTF8 && !UniConv::IsPureASCIITextStream(nname)) |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1003 |
{ |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1004 |
char* tempnname = strdup(nname); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1005 |
unsigned int namelen = 0; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1006 |
if(UniConv::UTF82DefaultCodePage(tempnname, strlen(tempnname), &nname, &namelen) < 0) |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1007 |
{ |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1008 |
Print(EError, "Invalid filename encoding: %s\n", tempnname); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1009 |
free(tempnname); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1010 |
delete[] nname; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1011 |
iMissingFiles++; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1012 |
return EFalse; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1013 |
} |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1014 |
free(tempnname); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1015 |
} |
606 | 1016 |
ifstream test(nname); |
1017 |
if(!test.is_open()){ |
|
1018 |
Print(EError,"Cannot open file %s for input.\n",iReader.Word(1)); |
|
1019 |
iMissingFiles++; |
|
1020 |
} |
|
1021 |
test.close(); |
|
1022 |
delete []nname ; |
|
1023 |
||
1024 |
} |
|
647 | 1025 |
else if (aKeyword != EKeywordDirCpy) |
606 | 1026 |
epocPathStart=1; |
1027 |
||
1028 |
TBool endOfName=EFalse; |
|
1029 |
const char *epocStartPtr; |
|
647 | 1030 |
if(aKeyword != EKeywordDir && aKeyword != EKeywordDirCpy) |
606 | 1031 |
epocStartPtr = IsValidFilePath(iReader.Word(epocPathStart)); |
1032 |
else |
|
1033 |
epocStartPtr = IsValidDirPath(iReader.Word(epocPathStart)); |
|
1034 |
char *epocEndPtr = const_cast<char*>(epocStartPtr); |
|
1035 |
||
1036 |
if (epocStartPtr == NULL) { |
|
1037 |
Print(EError, "Invalid destination path on line %d\n",currentLine); |
|
1038 |
return EFalse; |
|
1039 |
} |
|
1040 |
||
1041 |
TRomNode* dir=iRootDirectory; |
|
1042 |
TRomNode* subDir=0; |
|
1043 |
||
1044 |
while (!endOfName) { |
|
1045 |
endOfName = GetNextBitOfFileName(epocEndPtr); |
|
647 | 1046 |
if (endOfName && (aKeyword!=EKeywordDir) && (aKeyword!=EKeywordDirCpy)) { // file |
1047 |
if (!AddFileToNodeTree(aKeyword, dir, epocStartPtr, iReader.Word(1), ETrue, aFileCompressOption, aFileUncompressOption)) |
|
606 | 1048 |
return EFalse; |
1049 |
} |
|
1050 |
else { |
|
1051 |
// directory |
|
1052 |
//for directory creation, given /sys/bin/, it's possible to reach 0 at the end, just ignore that... |
|
1053 |
if(!*epocStartPtr) |
|
1054 |
break; |
|
1055 |
||
647 | 1056 |
subDir = AddDirToNodeTree(aKeyword, dir, epocStartPtr); |
1057 |
if (!subDir) { |
|
1058 |
if (aKeyword != EKeywordHide) |
|
1059 |
return EFalse;//this is for memory alloc failed |
|
1060 |
else |
|
1061 |
return ETrue;//this is for hide a non-exist dir |
|
606 | 1062 |
} |
1063 |
dir=subDir; |
|
1064 |
epocStartPtr = epocEndPtr; |
|
1065 |
} // end of else. |
|
1066 |
} |
|
647 | 1067 |
|
1068 |
if (aKeyword == EKeywordDirCpy) { |
|
1069 |
if(!CreateFromFolder(iReader.Word(1), dir)) |
|
1070 |
return EFalse; |
|
1071 |
} |
|
1072 |
||
606 | 1073 |
return ETrue; |
1074 |
} |
|
1075 |
||
647 | 1076 |
TRomNode* CObeyFile::AddFileToNodeTree(enum EKeyword aKeyword, TRomNode* dir, const char* filename, const char* aPCSidename, const TBool aParseAttr, TBool aFileCompressOption, TBool aFileUncompressOption) { |
1077 |
TRomNode* alreadyExists=dir->FindInDirectory(filename); |
|
1078 |
if ((aKeyword != EKeywordHide) && alreadyExists) { // duplicate file |
|
1079 |
if (gKeepGoing) { |
|
1080 |
Print(EWarning, "Duplicate file for %s on line %d, will be ignored\n",aPCSidename,iReader.CurrentLine()); |
|
1081 |
return alreadyExists; |
|
1082 |
} |
|
1083 |
else { |
|
1084 |
Print(EError, "Duplicate file for %s on line %d\n",aPCSidename,iReader.CurrentLine()); |
|
1085 |
return 0; |
|
1086 |
} |
|
1087 |
} |
|
1088 |
else if((aKeyword == EKeywordHide) && (alreadyExists)) { |
|
1089 |
alreadyExists->iEntry->iHidden = ETrue; |
|
1090 |
alreadyExists->iHidden = ETrue; |
|
1091 |
return alreadyExists; |
|
1092 |
} |
|
1093 |
else if((aKeyword == EKeywordHide) && (!alreadyExists)) { |
|
1094 |
Print(EWarning, "Hiding non-existent file %s on line %d\n",aPCSidename,iReader.CurrentLine()); |
|
1095 |
return (TRomNode*)1; |
|
1096 |
} |
|
1097 |
||
1098 |
iNumberOfFiles++; |
|
1099 |
TRomBuilderEntry* file = new TRomBuilderEntry(aPCSidename, filename); |
|
1100 |
if( aFileCompressOption ) { |
|
1101 |
file->iCompressEnabled = ECompressionCompress; |
|
1102 |
} |
|
1103 |
else if(aFileUncompressOption ) { |
|
1104 |
file->iCompressEnabled = ECompressionUncompress; |
|
1105 |
} |
|
1106 |
||
1107 |
TRomNode* node=new TRomNode(filename, file); |
|
1108 |
if (node==0) |
|
1109 |
return 0; |
|
1110 |
||
1111 |
if (aParseAttr){ |
|
1112 |
TInt r=ParseFileAttributes(node, file, aKeyword); |
|
1113 |
if (r!=KErrNone) |
|
1114 |
return 0; |
|
1115 |
} |
|
1116 |
if(gCompress != ECompressionUnknown) { |
|
1117 |
node->iFileUpdate = ETrue; |
|
1118 |
} |
|
1119 |
||
1120 |
if((node->iOverride) || (aFileCompressOption) || (aFileUncompressOption)) { |
|
1121 |
node->iFileUpdate = ETrue; |
|
1122 |
} |
|
1123 |
||
1124 |
dir->AddFile(node); // to drive directory structure. |
|
1125 |
return node; |
|
1126 |
} |
|
1127 |
||
1128 |
TRomNode* CObeyFile::AddDirToNodeTree(enum EKeyword aKeyword, TRomNode* dir, const char* dirname) { |
|
1129 |
TRomNode* subDir = dir->FindInDirectory(dirname); |
|
1130 |
if (!subDir){ // sub directory does not exist |
|
1131 |
if(aKeyword==EKeywordHide) { |
|
1132 |
Print(EWarning, "Hiding non-existent file %s on line %d\n", |
|
1133 |
iReader.Word(1),iReader.CurrentLine()); |
|
1134 |
return 0; |
|
1135 |
} |
|
1136 |
subDir = dir->NewSubDir(dirname); |
|
1137 |
if (!subDir) |
|
1138 |
return 0; |
|
1139 |
} |
|
1140 |
return subDir; |
|
1141 |
} |
|
1142 |
||
1143 |
TBool CObeyFile::CreateFromFolder(const char* aPath,TRomNode* aParent) { |
|
1144 |
int len = strlen(aPath); |
|
1145 |
if(!aParent) |
|
1146 |
aParent = new TRomNode("//"); |
|
1147 |
#ifdef __LINUX__ |
|
1148 |
DIR* dir = opendir(aPath); |
|
1149 |
if(dir == NULL) { |
|
1150 |
Print(EError, "The directory %s does not exist.\n",aPath); |
|
1151 |
return EFalse; |
|
1152 |
} |
|
1153 |
dirent* entry; |
|
1154 |
struct stat statbuf ; |
|
1155 |
char* fileName = new(nothrow) char[len + 200]; |
|
1156 |
if(!fileName) return EFalse ; |
|
1157 |
memcpy(fileName,aPath,len); |
|
1158 |
fileName[len] = '/'; |
|
1159 |
while ((entry = readdir(dir)) != NULL) { |
|
1160 |
if(strcmp(entry->d_name,".") == 0 || strcmp(entry->d_name,"..") == 0) |
|
1161 |
continue ; |
|
1162 |
strcpy(&fileName[len+1],entry->d_name); |
|
1163 |
stat(fileName , &statbuf); |
|
1164 |
if (S_ISDIR(statbuf.st_mode)){ |
|
1165 |
TRomNode* subdir = AddDirToNodeTree(EKeywordDirCpy, aParent, entry->d_name); |
|
1166 |
if (!subdir){ |
|
1167 |
delete []fileName; |
|
1168 |
return EFalse; |
|
1169 |
} |
|
1170 |
if (!CreateFromFolder(fileName, subdir)){ |
|
1171 |
delete []fileName; |
|
1172 |
return EFalse; |
|
1173 |
} |
|
1174 |
}else{ |
|
1175 |
if (!AddFileToNodeTree(EKeywordDirCpy, aParent, entry->d_name, fileName, EFalse)){ |
|
1176 |
delete []fileName; |
|
1177 |
return EFalse; |
|
1178 |
} |
|
1179 |
} |
|
1180 |
} |
|
1181 |
delete []fileName ; |
|
1182 |
closedir(dir); |
|
1183 |
#else |
|
1184 |
struct _finddata_t data ; |
|
1185 |
memset(&data, 0, sizeof(data)); |
|
1186 |
char* fileName = new(nothrow) char[len + 200]; |
|
1187 |
if(!fileName) return EFalse ; |
|
1188 |
memcpy(fileName,aPath,len); |
|
1189 |
fileName[len] = '\\'; |
|
1190 |
fileName[len+1] = '*'; |
|
1191 |
fileName[len+2] = 0; |
|
1192 |
intptr_t hFind = _findfirst(fileName,&data); |
|
1193 |
||
1194 |
if(hFind == (intptr_t)-1 ) { |
|
1195 |
Print(EError, "The directory %s does not exist.\n",aPath); |
|
1196 |
delete []fileName; |
|
1197 |
return EFalse; |
|
1198 |
} |
|
1199 |
||
1200 |
do { |
|
1201 |
if(strcmp(data.name,".") == 0 || strcmp(data.name,"..") == 0) |
|
1202 |
continue ; |
|
1203 |
||
1204 |
strcpy(&fileName[len+1],data.name); |
|
1205 |
if(data.attrib & _A_SUBDIR){ |
|
1206 |
TRomNode* subDir = AddDirToNodeTree(EKeywordDirCpy, aParent, data.name); |
|
1207 |
if (!subDir){ |
|
1208 |
delete []fileName; |
|
1209 |
return EFalse; |
|
1210 |
} |
|
1211 |
if(data.attrib & _A_RDONLY) |
|
1212 |
subDir->iAtt |= KEntryAttReadOnly; |
|
1213 |
if(data.attrib & _A_HIDDEN){ |
|
1214 |
subDir->iAtt |= KEntryAttHidden; |
|
1215 |
} |
|
1216 |
if(data.attrib & _A_SYSTEM) |
|
1217 |
subDir->iAtt |= KEntryAttSystem; |
|
1218 |
if (!CreateFromFolder(fileName, subDir)){ |
|
1219 |
delete []fileName; |
|
1220 |
return EFalse; |
|
1221 |
} |
|
1222 |
}else{ |
|
1223 |
TRomNode* node = AddFileToNodeTree(EKeywordDirCpy, aParent, data.name, fileName, EFalse); |
|
1224 |
if (!node){ |
|
1225 |
delete []fileName; |
|
1226 |
return EFalse; |
|
1227 |
} |
|
1228 |
if(data.attrib & _A_RDONLY) |
|
1229 |
node->iAtt |= KEntryAttReadOnly; |
|
1230 |
if(data.attrib & _A_HIDDEN){ |
|
1231 |
node->iAtt |= KEntryAttHidden; |
|
1232 |
node->iEntry->iHidden = ETrue; |
|
1233 |
node->iHidden = ETrue; |
|
1234 |
} |
|
1235 |
if(data.attrib & _A_SYSTEM) |
|
1236 |
node->iAtt |= KEntryAttSystem; |
|
1237 |
} |
|
1238 |
} while(-1 != _findnext(hFind, &data)); |
|
1239 |
delete []fileName ; |
|
1240 |
_findclose(hFind); |
|
1241 |
#endif |
|
1242 |
||
1243 |
return ETrue; |
|
1244 |
} |
|
606 | 1245 |
|
1246 |
TInt CObeyFile::SetStackSize(TRomNode *aNode, const char* aStr) { |
|
1247 |
if (EFalse == IsValidNumber(aStr)) |
|
1248 |
return Print(EError, "Number required as argument for keyword 'stack'.\n"); |
|
1249 |
TInt size ; |
|
1250 |
TInt err = Val(size,aStr); |
|
1251 |
if(KErrNone == err){ |
|
1252 |
aNode->SetStackSize(size ); |
|
1253 |
} |
|
1254 |
return err; |
|
1255 |
} |
|
1256 |
||
1257 |
TInt CObeyFile::SetHeapSizeMin(TRomNode *aNode, const char* aStr) { |
|
1258 |
if (EFalse == IsValidNumber(aStr)) |
|
1259 |
return Print(EError, "Number required as argument for keyword 'heapmin'.\n"); |
|
1260 |
TInt size ; |
|
1261 |
TInt err = Val(size,aStr); |
|
1262 |
if(KErrNone == err){ |
|
1263 |
aNode->SetHeapSizeMin(size ); |
|
1264 |
} |
|
1265 |
return err; |
|
1266 |
} |
|
1267 |
||
1268 |
TInt CObeyFile::SetHeapSizeMax(TRomNode *aNode, const char* aStr) { |
|
1269 |
if (EFalse == IsValidNumber(aStr)) |
|
1270 |
return Print(EError, "Number required as argument for keyword 'heapmax'.\n"); |
|
1271 |
TInt size ; |
|
1272 |
TInt err = Val(size,aStr); |
|
1273 |
if(KErrNone == err){ |
|
1274 |
aNode->SetHeapSizeMax(size ); |
|
1275 |
} |
|
1276 |
return err; |
|
1277 |
||
1278 |
} |
|
1279 |
||
1280 |
TInt CObeyFile::SetCapability(TRomNode *aNode, const char* aStr) { |
|
1281 |
if ( IsValidNumber(aStr)){ |
|
1282 |
Print(EDiagnostic,"Old style numeric CAPABILTY specification ignored.\n"); |
|
1283 |
return KErrNone; |
|
1284 |
} |
|
1285 |
SCapabilitySet cap; |
|
1286 |
TInt r = ParseCapabilitiesArg(cap, (char*)aStr); |
|
1287 |
if( KErrNone == r ) { |
|
1288 |
aNode->SetCapability( cap ); |
|
1289 |
} |
|
1290 |
return r; |
|
1291 |
} |
|
1292 |
||
1293 |
TInt CObeyFile::SetPriority(TRomNode *aNode, const char* aStr) { |
|
1294 |
TProcessPriority priority; |
|
1295 |
||
1296 |
if ( IsValidNumber(aStr)) { |
|
1297 |
TUint32 temp = 0; |
|
1298 |
Val(temp,aStr) ; |
|
1299 |
priority = (TProcessPriority)temp ; |
|
1300 |
} |
|
1301 |
else { |
|
1302 |
if (stricmp(aStr, "low")==0) |
|
1303 |
priority=EPriorityLow; |
|
1304 |
else if (strnicmp(aStr, "background", 4)==0) |
|
1305 |
priority=EPriorityBackground; |
|
1306 |
else if (strnicmp(aStr, "foreground", 4)==0) |
|
1307 |
priority=EPriorityForeground; |
|
1308 |
else if (stricmp(aStr, "high")==0) |
|
1309 |
priority=EPriorityHigh; |
|
1310 |
else if (strnicmp(aStr, "windowserver",3)==0) |
|
1311 |
priority=EPriorityWindowServer; |
|
1312 |
else if (strnicmp(aStr, "fileserver",4)==0) |
|
1313 |
priority=EPriorityFileServer; |
|
1314 |
else if (strnicmp(aStr, "realtimeserver",4)==0) |
|
1315 |
priority=EPriorityRealTimeServer; |
|
1316 |
else if (strnicmp(aStr, "supervisor",3)==0) |
|
1317 |
priority=EPrioritySupervisor; |
|
1318 |
else |
|
1319 |
return Print(EError, "Unrecognised priority keyword.\n"); |
|
1320 |
} |
|
1321 |
if (priority<EPriorityLow || priority>EPrioritySupervisor) |
|
1322 |
return Print(EError, "Priority out of range.\n"); |
|
1323 |
||
1324 |
aNode->SetPriority( priority ); |
|
1325 |
return KErrNone; |
|
1326 |
} |
|
1327 |
||
1328 |
TInt CObeyFile::SetUid1(TRomNode *aNode, const char* aStr){ |
|
1329 |
if (EFalse == IsValidNumber(aStr)) |
|
1330 |
return Print(EError, "Number required as argument for keyword 'uid1'.\n"); |
|
1331 |
TInt size ; |
|
1332 |
TInt err = Val(size,aStr); |
|
1333 |
if(KErrNone == err){ |
|
1334 |
aNode->SetUid1(size ); |
|
1335 |
} |
|
1336 |
return err; |
|
1337 |
} |
|
1338 |
TInt CObeyFile::SetUid2(TRomNode *aNode, const char* aStr) { |
|
1339 |
if (EFalse == IsValidNumber(aStr)) |
|
1340 |
return Print(EError, "Number required as argument for keyword 'uid2'.\n"); |
|
1341 |
TInt size ; |
|
1342 |
TInt err = Val(size,aStr); |
|
1343 |
if(KErrNone == err){ |
|
1344 |
aNode->SetUid2(size ); |
|
1345 |
} |
|
1346 |
return err; |
|
1347 |
} |
|
1348 |
TInt CObeyFile::SetUid3(TRomNode *aNode, const char* aStr) { |
|
1349 |
if (EFalse == IsValidNumber(aStr)) |
|
1350 |
return Print(EError, "Number required as argument for keyword 'uid3'.\n"); |
|
1351 |
TInt size ; |
|
1352 |
TInt err = Val(size,aStr); |
|
1353 |
if(KErrNone == err){ |
|
1354 |
aNode->SetUid3(size ); |
|
1355 |
} |
|
1356 |
return err; |
|
1357 |
} |
|
1358 |
||
1359 |
// |
|
1360 |
// Process any inline keywords |
|
1361 |
// |
|
1362 |
TInt CObeyFile::ParseFileAttributes(TRomNode *aNode, TRomBuilderEntry* aFile, enum EKeyword aKeyword) { |
|
1363 |
TInt currentLine = iReader.CurrentLine(); |
|
1364 |
enum EFileAttribute attribute; |
|
1365 |
TInt r=KErrNone; |
|
1366 |
TInt index=3; |
|
1367 |
char* arg=0; |
|
1368 |
||
1369 |
while(r==KErrNone) { |
|
1370 |
r=iReader.NextAttribute(index,(aFile!=0),attribute,arg); |
|
1371 |
if (r!=KErrNone) |
|
1372 |
break; |
|
1373 |
switch(attribute) |
|
1374 |
{ |
|
1375 |
case EAttributeAtt: |
|
1376 |
r=aNode->SetAtt(arg); |
|
1377 |
break; |
|
1378 |
case EAttributeAttExtra: |
|
1379 |
r=aNode->SetAttExtra(arg, aFile, aKeyword); |
|
1380 |
break; |
|
1381 |
case EAttributeStack: |
|
1382 |
r=SetStackSize(aNode, arg); |
|
1383 |
break; |
|
1384 |
case EAttributeFixed: |
|
1385 |
aNode->SetFixed(); |
|
1386 |
r = KErrNone; |
|
1387 |
break; |
|
1388 |
case EAttributeUid1: |
|
1389 |
r=SetUid1(aNode, arg); |
|
1390 |
break; |
|
1391 |
case EAttributeUid2: |
|
1392 |
r=SetUid2(aNode, arg); |
|
1393 |
break; |
|
1394 |
case EAttributeUid3: |
|
1395 |
r=SetUid3(aNode, arg); |
|
1396 |
break; |
|
1397 |
case EAttributeHeapMin: |
|
1398 |
r=SetHeapSizeMin(aNode, arg); |
|
1399 |
break; |
|
1400 |
case EAttributeHeapMax: |
|
1401 |
r=SetHeapSizeMax(aNode, arg); |
|
1402 |
break; |
|
1403 |
case EAttributePriority: |
|
1404 |
r=SetPriority(aNode, arg); |
|
1405 |
break; |
|
1406 |
case EAttributeCapability: |
|
1407 |
r=SetCapability(aNode, arg); |
|
1408 |
break; |
|
1409 |
case EAttributeUnpaged: |
|
1410 |
aNode->iOverride |= KOverrideCodeUnpaged|KOverrideDataUnpaged; |
|
1411 |
aNode->iOverride &= ~(KOverrideCodePaged|KOverrideDataPaged); |
|
1412 |
break; |
|
1413 |
case EAttributePaged: |
|
1414 |
aNode->iOverride |= KOverrideCodePaged; |
|
1415 |
aNode->iOverride &= ~(KOverrideCodeUnpaged); |
|
1416 |
break; |
|
1417 |
case EAttributeUnpagedCode: |
|
1418 |
aNode->iOverride |= KOverrideCodeUnpaged; |
|
1419 |
aNode->iOverride &= ~KOverrideCodePaged; |
|
1420 |
break; |
|
1421 |
case EAttributePagedCode: |
|
1422 |
aNode->iOverride |= KOverrideCodePaged; |
|
1423 |
aNode->iOverride &= ~KOverrideCodeUnpaged; |
|
1424 |
break; |
|
1425 |
case EAttributeUnpagedData: |
|
1426 |
aNode->iOverride |= KOverrideDataUnpaged; |
|
1427 |
aNode->iOverride &= ~KOverrideDataPaged; |
|
1428 |
break; |
|
1429 |
case EAttributePagedData: |
|
1430 |
aNode->iOverride |= KOverrideDataPaged; |
|
1431 |
aNode->iOverride &= ~KOverrideDataUnpaged; |
|
1432 |
break; |
|
1433 |
default: |
|
1434 |
return Print(EError, "Unrecognised keyword in file attributes on line %d.\n",currentLine); |
|
1435 |
} |
|
1436 |
} |
|
1437 |
||
1438 |
if (r==KErrEof) |
|
1439 |
return KErrNone; |
|
1440 |
return r; |
|
1441 |
} |
|
1442 |
||
1443 |
// |
|
1444 |
// Process a parsed line to set up one or more new TRomBuilder entry objects. |
|
1445 |
// iWord[0] = the keyword (file, primary or secondary) |
|
1446 |
// iWord[1] = the PC pathname |
|
1447 |
// iWord[2] = the EPOC pathname |
|
1448 |
// iWord[3] = start of the file attributes |
|
1449 |
// |
|
1450 |
TBool CObeyFile::ProcessFile(TInt /*aAlign*/, enum EKeyword aKeyword){ |
|
1451 |
||
1452 |
TBool isPeFile = ETrue; |
|
1453 |
TBool aFileCompressOption, aFileUncompressOption; |
|
1454 |
TInt epocPathStart=2; |
|
1455 |
aFileCompressOption = aFileUncompressOption = EFalse; |
|
1456 |
TBool warnFlag = EFalse; |
|
1457 |
static const char aStdPath[] = "SYS\\BIN\\"; |
|
1458 |
static const int sysBinLength = sizeof(aStdPath)-1; |
|
1459 |
||
1460 |
// do some validation of the keyword |
|
1461 |
TInt currentLine = iReader.CurrentLine(); |
|
1462 |
switch (aKeyword) |
|
1463 |
{ |
|
1464 |
case EKeywordData: |
|
1465 |
case EKeywordHideV2: |
|
1466 |
iNumberOfDataFiles++; |
|
1467 |
isPeFile = EFalse; |
|
1468 |
break; |
|
1469 |
||
1470 |
case EKeywordFile: |
|
1471 |
warnFlag = gEnableStdPathWarning; |
|
1472 |
break; |
|
1473 |
case EKeywordFileCompress: |
|
1474 |
aFileCompressOption = ETrue; |
|
1475 |
warnFlag = gEnableStdPathWarning; |
|
1476 |
break; |
|
1477 |
case EKeywordFileUncompress: |
|
1478 |
aFileUncompressOption = ETrue; |
|
1479 |
warnFlag = gEnableStdPathWarning; |
|
1480 |
break; |
|
1481 |
||
1482 |
default: |
|
1483 |
Print(EError,"Unexpected keyword '%s' on line %d.\n",iReader.Word(0),currentLine); |
|
1484 |
return EFalse; |
|
1485 |
} |
|
1486 |
||
707
ccd52fece6ff
Remove "repeated" file existence checking from ROFSBUILD
jascui
parents:
675
diff
changeset
|
1487 |
if (aKeyword==EKeywordHideV2) { |
ccd52fece6ff
Remove "repeated" file existence checking from ROFSBUILD
jascui
parents:
675
diff
changeset
|
1488 |
epocPathStart=1; |
606 | 1489 |
} |
1490 |
||
1491 |
iNumberOfFiles++; |
|
1492 |
||
1493 |
||
1494 |
TBool endOfName=EFalse; |
|
1495 |
const char *epocStartPtr=IsValidFilePath(iReader.Word(epocPathStart)); |
|
1496 |
char *epocEndPtr=const_cast<char*>(epocStartPtr); |
|
1497 |
if (epocStartPtr==NULL) { |
|
1498 |
Print(EError, "Invalid destination path on line %d\n",currentLine); |
|
1499 |
return EFalse; |
|
1500 |
} |
|
1501 |
if(warnFlag){ // Check for the std destination path(for executables) as per platsec. |
|
1502 |
if(strnicmp(aStdPath,epocStartPtr,sysBinLength) != 0) { |
|
1503 |
Print(EWarning,"Invalid destination path on line %d. \"%s\" \n",currentLine,epocStartPtr); |
|
1504 |
} |
|
1505 |
} |
|
1506 |
||
1507 |
TRomNode* dir=iRootDirectory; |
|
1508 |
TRomNode* subDir=0; |
|
1509 |
TRomBuilderEntry *file=0; |
|
1510 |
while (!endOfName) { |
|
1511 |
endOfName = GetNextBitOfFileName(epocEndPtr); |
|
1512 |
if (endOfName) {// file |
|
1513 |
TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr); |
|
1514 |
/* |
|
1515 |
* The EKeywordHideV2 keyword is used to indicate that: |
|
1516 |
* 1. if the file exists in the same image and then hidden, mark it hidden |
|
1517 |
* 2. if the file exists in another image, but in this (ROFS) image, it is |
|
1518 |
* required to hide that file, create a 0 length file entry setting the 'hide' |
|
1519 |
* flag so that at runtime, file gets hidden in the composite filesystem. |
|
1520 |
*/ |
|
1521 |
if ((aKeyword != EKeywordHideV2) && alreadyExists){ // duplicate file |
|
1522 |
if(gKeepGoing){ |
|
1523 |
Print(EWarning, "Duplicate file for %s on line %d, will be ignored\n",iReader.Word(1),iReader.CurrentLine()); |
|
1524 |
switch (aKeyword) |
|
1525 |
{ |
|
1526 |
case EKeywordData: |
|
1527 |
case EKeywordHideV2: |
|
1528 |
iNumberOfDataFiles--; |
|
1529 |
default: |
|
1530 |
break; |
|
1531 |
} |
|
1532 |
iNumberOfFiles--; |
|
1533 |
return ETrue; |
|
1534 |
} |
|
1535 |
else { |
|
1536 |
Print(EError, "Duplicate file for %s on line %d\n",iReader.Word(1),iReader.CurrentLine()); |
|
1537 |
return EFalse; |
|
1538 |
} |
|
1539 |
} |
|
1540 |
||
1541 |
TBool aHidden = aKeyword==EKeywordHideV2; |
|
1542 |
/* The file is only marked hidden and hence the source file name isn't known |
|
1543 |
* here as hide statement says : |
|
1544 |
* hide <filename as in ROM> |
|
1545 |
* Therefore, create TRomBuilderEntry with iFileName as 0 for hidden file when |
|
1546 |
* the file doesn't exist in the same ROM image. Otherwise, the src file name |
|
1547 |
* is known because of alreadyExists (which comes from the 'file'/'data' statement). |
|
1548 |
*/ |
|
1549 |
if(aHidden) |
|
1550 |
file = new TRomBuilderEntry(0, epocStartPtr); |
|
1551 |
else |
|
1552 |
file = new TRomBuilderEntry(iReader.Word(1), epocStartPtr); |
|
1553 |
file->iExecutable=isPeFile; |
|
1554 |
file->iHidden= aHidden; |
|
1555 |
if( aFileCompressOption ){ |
|
1556 |
file->iCompressEnabled = ECompressionCompress; |
|
1557 |
} |
|
1558 |
else if(aFileUncompressOption ) { |
|
1559 |
file->iCompressEnabled = ECompressionUncompress; |
|
1560 |
} |
|
1561 |
TRomNode* node=new TRomNode(epocStartPtr, file); |
|
1562 |
if (node==0) |
|
1563 |
return EFalse; |
|
1564 |
TInt r=ParseFileAttributes(node, file, aKeyword); |
|
1565 |
if (r!=KErrNone) |
|
1566 |
return EFalse; |
|
1567 |
||
1568 |
dir->AddFile(node); // to ROFS directory structure |
|
1569 |
AddFile(file); // to our list of files |
|
1570 |
} |
|
1571 |
else { // directory |
|
1572 |
subDir = dir->FindInDirectory(epocStartPtr); |
|
1573 |
if (!subDir) { // sub directory does not exist |
|
1574 |
subDir = dir->NewSubDir(epocStartPtr); |
|
1575 |
if (!subDir) |
|
1576 |
return EFalse; |
|
1577 |
} |
|
1578 |
dir=subDir; |
|
1579 |
epocStartPtr = epocEndPtr; |
|
1580 |
} |
|
1581 |
} |
|
1582 |
return ETrue; |
|
1583 |
} |
|
1584 |
||
1585 |
||
1586 |
TBool CObeyFile::ProcessRenaming(enum EKeyword aKeyword) { |
|
1587 |
||
1588 |
// find existing file |
|
1589 |
TBool endOfName=EFalse; |
|
1590 |
const char *epocStartPtr=IsValidFilePath(iReader.Word(1)); |
|
1591 |
||
1592 |
// Store the current name and new name to maintain renamed file map |
|
1593 |
string currentName=iReader.Word(1); |
|
1594 |
string newName=iReader.Word(2); |
|
1595 |
||
1596 |
char *epocEndPtr= const_cast<char*>(epocStartPtr); |
|
1597 |
if (epocStartPtr == NULL) { |
|
1598 |
Print(EError, "Invalid source path on line %d\n",iReader.CurrentLine()); |
|
1599 |
return EFalse; |
|
1600 |
} |
|
1601 |
||
1602 |
char saved_srcname[257]; |
|
1603 |
strncpy(saved_srcname, iReader.Word(1),257); |
|
1604 |
||
1605 |
TRomNode* dir=iRootDirectory; |
|
1606 |
TRomNode* existingFile=0; |
|
1607 |
while (!endOfName){ |
|
1608 |
endOfName = GetNextBitOfFileName(epocEndPtr); |
|
1609 |
if (endOfName) { // file |
|
1610 |
existingFile=dir->FindInDirectory(epocStartPtr); |
|
1611 |
if (existingFile) { |
|
1612 |
TInt fileCount=0; |
|
1613 |
TInt dirCount=0; |
|
1614 |
existingFile->CountDirectory(fileCount, dirCount); |
|
1615 |
if (dirCount != 0 || fileCount != 0) { |
|
1616 |
Print(EError, "Keyword %s not applicable to directories - line %d\n", |
|
1617 |
iReader.Word(0),iReader.CurrentLine()); |
|
1618 |
return EFalse; |
|
1619 |
} |
|
1620 |
} |
|
1621 |
} |
|
1622 |
else { // directory |
|
1623 |
TRomNode* subDir = dir->FindInDirectory(epocStartPtr); |
|
1624 |
if (!subDir) // sub directory does not exist |
|
1625 |
break; |
|
1626 |
dir=subDir; |
|
1627 |
epocStartPtr = epocEndPtr; |
|
1628 |
} |
|
1629 |
} |
|
1630 |
if (aKeyword == EKeywordHide) { |
|
1631 |
/* |
|
1632 |
* The EKeywordHide keyword is used to indicate that if the file exists in |
|
1633 |
* the primary ROFS image and then hidden in extension ROFS, mark it hidden. |
|
1634 |
*/ |
|
1635 |
if (!existingFile) { |
|
1636 |
Print(EWarning, "Hiding non-existent file %s on line %d\n", |
|
1637 |
saved_srcname, iReader.CurrentLine()); |
|
1638 |
// Just a warning, as we've achieved the right overall effect. |
|
1639 |
} |
|
1640 |
else if (existingFile->iFileStartOffset==(TUint)KFileHidden){ |
|
1641 |
Print(EWarning, "Hiding already hidden file %s on line %d\n", |
|
1642 |
saved_srcname, iReader.CurrentLine()); |
|
1643 |
// We will igrore this request, otherwise it will "undelete" it. |
|
1644 |
} |
|
1645 |
else { |
|
1646 |
//hidden files will not be placed to the image |
|
1647 |
existingFile->iHidden = ETrue; |
|
1648 |
} |
|
1649 |
return ETrue; |
|
1650 |
} |
|
1651 |
||
1652 |
if (!existingFile) { |
|
1653 |
Print(EError, "Can't %s non-existent source file %s on line %d\n", |
|
1654 |
iReader.Word(0), saved_srcname, iReader.CurrentLine()); |
|
1655 |
return EFalse; |
|
1656 |
} |
|
1657 |
||
1658 |
epocStartPtr = IsValidFilePath(iReader.Word(2)); |
|
1659 |
epocEndPtr = const_cast<char*>(epocStartPtr); |
|
1660 |
endOfName = EFalse; |
|
1661 |
if (epocStartPtr == NULL) { |
|
1662 |
Print(EError, "Invalid destination path on line %d\n",iReader.CurrentLine()); |
|
1663 |
return EFalse; |
|
1664 |
} |
|
1665 |
||
1666 |
TRomNode* newdir=iRootDirectory; |
|
1667 |
while (!endOfName) { |
|
1668 |
endOfName = GetNextBitOfFileName(epocEndPtr); |
|
1669 |
if (endOfName) {// file |
|
1670 |
TRomNode* alreadyExists=newdir->FindInDirectory(epocStartPtr); |
|
1671 |
if (alreadyExists && !(alreadyExists->iHidden)) {// duplicate file |
|
1672 |
if(gKeepGoing){ |
|
1673 |
Print(EWarning, "Duplicate file for %s on line %d, renaming will be skipped\n",saved_srcname,iReader.CurrentLine()); |
|
1674 |
return ETrue; |
|
1675 |
} |
|
1676 |
else { |
|
1677 |
Print(EError, "Duplicate file for %s on line %d\n",saved_srcname,iReader.CurrentLine()); |
|
1678 |
return EFalse; |
|
1679 |
} |
|
1680 |
} |
|
1681 |
} |
|
1682 |
else { // directory |
|
1683 |
TRomNode* subDir = newdir->FindInDirectory(epocStartPtr); |
|
1684 |
if (!subDir) {// sub directory does not exist |
|
1685 |
subDir = newdir->NewSubDir(epocStartPtr); |
|
1686 |
if (!subDir) |
|
1687 |
return EFalse; |
|
1688 |
} |
|
1689 |
newdir=subDir; |
|
1690 |
epocStartPtr = epocEndPtr; |
|
1691 |
} |
|
1692 |
} |
|
1693 |
||
1694 |
if (aKeyword == EKeywordRename) { |
|
1695 |
// rename => remove existingFile and insert into tree at new place |
|
1696 |
// has no effect on the iNextExecutable or iNextNodeForSameFile links |
|
1697 |
TInt r=ParseFileAttributes(existingFile, existingFile->iEntry, aKeyword); |
|
1698 |
if (r!=KErrNone) |
|
1699 |
return EFalse; |
|
1700 |
existingFile->Rename(dir, newdir, epocStartPtr); |
|
1701 |
// Store the current and new name of file in the renamed file map. |
|
1702 |
iPatchData->AddToRenamedFileMap(currentName, newName); |
|
1703 |
return ETrue; |
|
1704 |
} |
|
1705 |
||
1706 |
// alias => create new TRomNode entry and insert into tree |
|
1707 |
TRomNode* node = new TRomNode(epocStartPtr, 0); |
|
1708 |
if (node == 0) { |
|
1709 |
Print(EError, "Out of memory\n"); |
|
1710 |
return EFalse; |
|
1711 |
} |
|
1712 |
node->Alias(existingFile); |
|
1713 |
TInt r=ParseFileAttributes(node, 0, aKeyword); |
|
1714 |
if (r!=KErrNone) |
|
1715 |
return EFalse; |
|
1716 |
newdir->AddFile(node); // to ROFS directory structure, though possibly hidden |
|
1717 |
return ETrue; |
|
1718 |
} |
|
1719 |
||
1720 |
TInt ParsePagingPolicy(const char* policy){ |
|
1721 |
if(stricmp(policy,"NOPAGING") == 0) |
|
1722 |
return EKernelConfigPagingPolicyNoPaging; |
|
1723 |
else if (stricmp(policy,"ALWAYSPAGE") == 0) |
|
1724 |
return EKernelConfigPagingPolicyAlwaysPage; |
|
1725 |
else if(stricmp(policy,"DEFAULTUNPAGED") == 0) |
|
1726 |
return EKernelConfigPagingPolicyDefaultUnpaged; |
|
1727 |
else if(stricmp(policy,"DEFAULTPAGED") == 0) |
|
1728 |
return EKernelConfigPagingPolicyDefaultPaged; |
|
1729 |
return KErrArgument; |
|
1730 |
} |
|
1731 |
||
1732 |
TBool CObeyFile::ProcessKeyword(enum EKeyword aKeyword) { |
|
1733 |
||
1734 |
TBool success = ETrue; |
|
1735 |
switch (aKeyword) |
|
1736 |
{ |
|
1737 |
case EKeywordRofsName: |
|
1738 |
iRomFileName = iReader.DupWord(1); |
|
1739 |
break; |
|
1740 |
case EKeywordRofsSize: |
|
1741 |
Val(iRomSize,iReader.Word(1)); |
|
1742 |
break; |
|
1743 |
case EKeywordVersion: |
|
1744 |
{ |
|
1745 |
istringstream val(iReader.Word(1)); |
|
1746 |
val >> iVersion; |
|
1747 |
} |
|
1748 |
break; |
|
1749 |
case EKeywordRofsChecksum: |
|
1750 |
Val(iCheckSum,iReader.Word(1)); |
|
1751 |
break; |
|
1752 |
case EKeywordTime: |
|
1753 |
iReader.ProcessTime(iTime); |
|
1754 |
break; |
|
1755 |
case EKeywordPagingOverride: |
|
1756 |
{ |
|
1757 |
if(iPagingOverrideParsed) |
|
1758 |
Print(EWarning, "PagingOverride redefined - previous PagingOverride values lost\n"); |
|
1759 |
if(iCodePagingOverrideParsed) |
|
1760 |
Print(EWarning, "PagingOverride defined - previous CodePagingOverride values lost\n"); |
|
1761 |
iPagingOverrideParsed = true; |
|
1762 |
TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1763 |
if(policy < 0) { |
|
1764 |
Print(EError,"Unrecognized option for PAGINGOVERRIDE keyword\n"); |
|
1765 |
success = false; |
|
1766 |
} |
|
1767 |
else { |
|
1768 |
gCodePagingOverride = policy; |
|
1769 |
if((policy == EKernelConfigPagingPolicyNoPaging) || (policy == EKernelConfigPagingPolicyDefaultUnpaged)) |
|
1770 |
gDataPagingOverride = policy; |
|
1771 |
} |
|
1772 |
} |
|
1773 |
break; |
|
1774 |
case EKeywordCodePagingOverride: |
|
1775 |
{ |
|
1776 |
if(iCodePagingOverrideParsed) |
|
1777 |
Print(EWarning, "CodePagingOverride redefined - previous CodePagingOverride values lost\n"); |
|
1778 |
if(iPagingOverrideParsed) |
|
1779 |
Print(EWarning, "CodePagingOverride defined - previous PagingOverride values lost\n"); |
|
1780 |
iCodePagingOverrideParsed = true; |
|
1781 |
TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1782 |
if(policy<0) |
|
1783 |
{ |
|
1784 |
Print(EError,"Unrecognized option for CODEPAGINGOVERRIDE keyword\n"); |
|
1785 |
success = false; |
|
1786 |
} |
|
1787 |
else |
|
1788 |
gCodePagingOverride = policy; |
|
1789 |
} |
|
1790 |
break; |
|
1791 |
case EKeywordDataPagingOverride: |
|
1792 |
{ |
|
1793 |
if(iDataPagingOverrideParsed) |
|
1794 |
Print(EWarning, "DataPagingOverride redefined - previous DataPagingOverride values lost\n"); |
|
1795 |
/* if(iPagingOverrideParsed){ |
|
1796 |
Print(EError, "DataPagingOverride defined - previous PagingOverride values lost\n"); |
|
1797 |
success = false; |
|
1798 |
break; |
|
1799 |
} |
|
1800 |
*/ |
|
1801 |
iDataPagingOverrideParsed = true; |
|
1802 |
TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1803 |
if(policy < 0) { |
|
1804 |
Print(EError,"Unrecognized option for DATAPAGINGOVERRIDE keyword\n"); |
|
1805 |
success = false; |
|
1806 |
} |
|
1807 |
else |
|
1808 |
gDataPagingOverride = policy; |
|
1809 |
} |
|
1810 |
break; |
|
1811 |
case EKeywordRofsAutoSize: |
|
1812 |
iAutoSize = ETrue; |
|
1813 |
Val(iAutoPageSize,iReader.Word(1)); |
|
1814 |
break; |
|
1815 |
default: |
|
1816 |
// unexpected keyword iReader.Word(0) |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1817 |
Print(EWarning, "Unexpected keyword '%s' on line %d.\n",iReader.Word(0),iReader.CurrentLine()); |
606 | 1818 |
break; |
1819 |
} |
|
1820 |
||
1821 |
return success; |
|
1822 |
} |
|
1823 |
// |
|
1824 |
// Checks that the obeyfile has supplied enough variables to continue |
|
1825 |
// |
|
1826 |
TBool CObeyFile::GotKeyVariables() { |
|
1827 |
||
1828 |
TBool retVal=ETrue; |
|
1829 |
// Mandatory keywords |
|
1830 |
if (iRomFileName == 0) { |
|
1831 |
Print(EAlways,"The name of the image file has not been supplied.\n"); |
|
1832 |
Print(EAlways,"Use the keyword \"rofsname\".\n"); |
|
1833 |
retVal = EFalse; |
|
1834 |
} |
|
1835 |
if (iRomSize == 0) { |
|
1836 |
Print(EAlways,"The size of the image has not been supplied.\n"); |
|
1837 |
Print(EAlways,"Use the keyword \"rofssize\".\n"); |
|
1838 |
retVal = EFalse; |
|
1839 |
} |
|
1840 |
// Apply defaults as necessary |
|
1841 |
if (iTime == 0) { |
|
1842 |
Print(ELog, "No timestamp specified. Using current time...\n"); |
|
1843 |
ObeyFileReader::TimeNow(iTime); |
|
1844 |
} |
|
1845 |
Print(ELog, "\nCreating Rofs image %s\n", iRomFileName); |
|
1846 |
return retVal; |
|
1847 |
} |
|
1848 |
||
1849 |
// |
|
1850 |
// Check the path is valid |
|
1851 |
// |
|
1852 |
const char* CObeyFile::IsValidFilePath(const char* aPath) { |
|
1853 |
// skip leading "\" |
|
1854 |
if (*aPath == '/' || *aPath == '\\') |
|
1855 |
aPath++; |
|
1856 |
if (*aPath == 0) |
|
1857 |
return NULL; // file ends in a backslash |
|
1858 |
||
1859 |
const char *p = aPath; |
|
1860 |
TInt len=0; |
|
1861 |
while(*p) { |
|
1862 |
if (*p == '/' || *p == '\\') { |
|
1863 |
if (len == 0) |
|
1864 |
return NULL; |
|
1865 |
len=0; |
|
1866 |
p++; |
|
1867 |
continue; |
|
1868 |
||
1869 |
} |
|
1870 |
len++; |
|
1871 |
p++; |
|
1872 |
} |
|
1873 |
return (len ? aPath : NULL); |
|
1874 |
} |
|
1875 |
||
1876 |
const char* CObeyFile::IsValidDirPath(const char* aPath) |
|
1877 |
{ |
|
1878 |
const char* walker = aPath; |
|
1879 |
||
1880 |
//validate path... |
|
1881 |
while(*walker) |
|
1882 |
{ |
|
1883 |
if(((*walker=='/') || (*walker=='\\')) && ((*(walker+1)=='/') || (*(walker+1)=='\\'))) |
|
1884 |
return (const char*)0; |
|
1885 |
walker++; |
|
1886 |
} |
|
1887 |
||
1888 |
if((*aPath=='/') || (*aPath=='\\')) |
|
1889 |
aPath++; |
|
1890 |
||
1891 |
return aPath; |
|
1892 |
} |
|
1893 |
||
1894 |
// |
|
1895 |
// Move the end pointer past the next directory separator, replacing it with 0 |
|
1896 |
// |
|
1897 |
TBool CObeyFile::GetNextBitOfFileName(char*& epocEndPtr) { |
|
1898 |
while (*epocEndPtr != '/' && *epocEndPtr != '\\'){ // until reach the directory separator |
|
1899 |
if (*epocEndPtr == 0) // if reach end of string, return TRUE, it's the filename |
|
1900 |
return ETrue; |
|
1901 |
epocEndPtr++; |
|
1902 |
} |
|
1903 |
*epocEndPtr = 0; // overwrite the directory separator with a 0 |
|
1904 |
epocEndPtr++; // point past the 0 ready for the next one |
|
1905 |
return EFalse; |
|
1906 |
} |
|
1907 |
||
1908 |
void CObeyFile::AddFile(TRomBuilderEntry* aFile) { |
|
1909 |
*iNextFilePtrPtr = aFile; |
|
1910 |
iNextFilePtrPtr = &(aFile->iNext); |
|
1911 |
} |
|
1912 |
||
1913 |
// |
|
1914 |
// First pass through the obey file to set up key variables |
|
1915 |
// |
|
1916 |
TInt CObeyFile::ProcessExtensionRofs(MRofsImage* aKernelRom) { |
|
1917 |
||
1918 |
iReader.Rewind(); |
|
1919 |
enum EKeyword keyword; |
|
1920 |
||
1921 |
// Deal with the "extensionrofs" keyword, which should be first |
|
1922 |
// however, you may've found "time" before it. |
|
1923 |
while(iReader.NextLine(1,keyword) != KErrEof) { |
|
1924 |
if(EKeywordExtensionRofs == keyword) |
|
1925 |
break ; |
|
1926 |
} |
|
1927 |
if(EKeywordExtensionRofs != keyword) return KErrEof; |
|
1928 |
iRomFileName = iReader.DupWord(1); |
|
1929 |
Print(ELog, "\n========================================================\n"); |
|
1930 |
Print(ELog, "Extension ROFS %s starting at line %d\n\n", iRomFileName, iReader.CurrentLine()); |
|
1931 |
||
1932 |
iReader.MarkNext(); // so that we rewind to the line after the extensionrom keyword |
|
1933 |
||
1934 |
while (iReader.NextLine(1,keyword) != KErrEof) { |
|
1935 |
if (keyword == EKeywordExtensionRofs) |
|
1936 |
break; |
|
1937 |
ProcessExtensionKeyword(keyword); |
|
1938 |
} |
|
1939 |
||
1940 |
if (!GotExtensionVariables(aKernelRom)) |
|
1941 |
return KErrGeneral; |
|
1942 |
||
1943 |
// second pass to process the file specifications in the obey file building |
|
1944 |
// up the TRomNode directory structure and the TRomBuilderEntry list |
|
1945 |
// |
|
1946 |
iReader.Rewind(); |
|
1947 |
||
1948 |
// |
|
1949 |
if (aKernelRom == 0) |
|
1950 |
return Print(EError, "Option to extend a kernel ROFS image not yet implemented\n"); |
|
1951 |
||
1952 |
iRootDirectory = new TRomNode(""); |
|
1953 |
||
1954 |
iLastExecutable = 0; |
|
1955 |
||
1956 |
(aKernelRom->RootDirectory())->deleteTheFirstNode(); |
|
1957 |
||
1958 |
||
1959 |
iRootDirectory = aKernelRom->CopyDirectory(iLastExecutable); |
|
1960 |
aKernelRom->SetRootDirectory(iRootDirectory); |
|
1961 |
||
1962 |
||
1963 |
TInt align=0; |
|
1964 |
while (iReader.NextLine(2,keyword)!=KErrEof) { |
|
1965 |
if (keyword == EKeywordExtensionRofs) |
|
1966 |
break; |
|
1967 |
||
1968 |
switch (keyword) |
|
1969 |
{ |
|
1970 |
case EKeywordHide: |
|
1971 |
case EKeywordAlias: |
|
1972 |
case EKeywordRename: |
|
1973 |
if (!ProcessRenaming(keyword)) |
|
1974 |
return KErrGeneral; |
|
1975 |
break; |
|
1976 |
||
1977 |
case EKeywordPatchDllData: |
|
1978 |
{ |
|
1979 |
// Collect patchdata statements to process at the end |
|
1980 |
StringVector patchDataTokens; |
|
1981 |
SplitPatchDataStatement(patchDataTokens); |
|
1982 |
iPatchData->AddPatchDataStatement(patchDataTokens); |
|
1983 |
break; |
|
1984 |
} |
|
1985 |
default: |
|
1986 |
if (!ProcessFile(align, keyword)) |
|
1987 |
return KErrGeneral; |
|
1988 |
align=0; |
|
1989 |
break; |
|
1990 |
} |
|
1991 |
} |
|
1992 |
||
1993 |
if(!ParsePatchDllData() ) |
|
1994 |
return KErrGeneral; |
|
1995 |
||
1996 |
iReader.MarkNext(); // ready for processing the next extension rom(s) |
|
1997 |
||
1998 |
if (iMissingFiles!=0) |
|
1999 |
return KErrGeneral; |
|
2000 |
if (iNumberOfFiles == 0) { |
|
2001 |
Print(EError, "No files specified.\n"); |
|
2002 |
return KErrGeneral; |
|
2003 |
} |
|
2004 |
return KErrNone; |
|
2005 |
} |
|
2006 |
void CObeyFile::ProcessExtensionKeyword(enum EKeyword aKeyword) { |
|
2007 |
||
2008 |
switch (aKeyword) |
|
2009 |
{ |
|
2010 |
case EKeywordCoreRofsName: |
|
2011 |
iKernelRofsName = iReader.DupWord(1); |
|
2012 |
return; |
|
2013 |
case EKeywordRofsSize: |
|
2014 |
Val(iRomSize,iReader.Word(1)); |
|
2015 |
return; |
|
2016 |
case EKeywordVersion: |
|
2017 |
{ |
|
2018 |
istringstream val(iReader.Word(1)); |
|
2019 |
val >> iVersion; |
|
2020 |
} |
|
2021 |
return; |
|
2022 |
case EKeywordRomChecksum: |
|
2023 |
Val(iCheckSum,iReader.Word(1)); //-- |
|
2024 |
return; |
|
2025 |
case EKeywordTime: |
|
2026 |
iReader.ProcessTime(iTime); |
|
2027 |
return; |
|
2028 |
case EKeywordRofsAutoSize: |
|
2029 |
iAutoSize = ETrue; |
|
2030 |
Val(iAutoPageSize , iReader.Word(1)); |
|
2031 |
return; |
|
2032 |
default: |
|
2033 |
Print(EError,"Keyword '%s' not valid in extension ROFS - line %d\n", iReader.Word(0), iReader.CurrentLine()); |
|
2034 |
break; |
|
2035 |
} |
|
2036 |
return; |
|
2037 |
} |
|
2038 |
// |
|
2039 |
// Checks that the obeyfile has supplied enough variables to continue |
|
2040 |
// |
|
2041 |
TBool CObeyFile::GotExtensionVariables(MRofsImage* aRom) { |
|
2042 |
||
2043 |
TBool retVal=ETrue; |
|
2044 |
const char* kernelRofsName = iKernelRofsName; |
|
2045 |
||
2046 |
// Mandatory keywords |
|
2047 |
||
2048 |
if (iRomSize == 0){ |
|
2049 |
Print(EAlways,"The size of the extension ROFS has not been supplied.\n"); |
|
2050 |
Print(EAlways,"Use the keyword \"rofssize\".\n"); |
|
2051 |
retVal = EFalse; |
|
2052 |
} |
|
2053 |
||
2054 |
// keywords we need if we don't already have a ROFS image to work from |
|
2055 |
if (aRom == 0) { |
|
2056 |
if (iKernelRofsName == 0) { |
|
2057 |
Print(EAlways,"The name of the core ROFS has not been supplied.\n"); |
|
2058 |
Print(EAlways,"Use the keyword \"rofsname\".\n"); |
|
2059 |
retVal = EFalse; |
|
2060 |
} |
|
2061 |
} |
|
2062 |
else { |
|
2063 |
if (iKernelRofsName != 0){ |
|
2064 |
Print(EWarning,"Keyword \"rofsname\" ignored.\n"); |
|
2065 |
} |
|
2066 |
kernelRofsName = aRom->RomFileName(); |
|
2067 |
} |
|
2068 |
||
2069 |
// validation |
|
2070 |
// Apply defaults as necessary |
|
2071 |
if (iTime == 0) { |
|
2072 |
Print(ELog, "No timestamp specified. Using current time...\n"); |
|
2073 |
ObeyFileReader::TimeNow(iTime); |
|
2074 |
} |
|
2075 |
||
2076 |
// fix up "*" in rofsname |
|
2077 |
char newname[256]; |
|
2078 |
char* p=newname; |
|
2079 |
char* q=iRomFileName; |
|
2080 |
char c; |
|
2081 |
||
2082 |
while ((c=*q++)!='\0'){ |
|
2083 |
if (c!='*') { |
|
2084 |
*p++=c; |
|
2085 |
continue; |
|
2086 |
} |
|
2087 |
const char *r = kernelRofsName; |
|
2088 |
while ((c=*r++)!='\0') |
|
2089 |
*p++=c; |
|
2090 |
} |
|
2091 |
*p++ = '\0'; |
|
2092 |
delete []iRomFileName; |
|
2093 |
size_t len = p - newname ; |
|
2094 |
iRomFileName = new char[len]; |
|
2095 |
memcpy(iRomFileName,newname,len); |
|
2096 |
Print(ELog, "\nCreating ROFS image %s\n", iRomFileName); |
|
2097 |
return retVal; |
|
2098 |
} |
|
2099 |
||
2100 |
// Fuction to split patchdata statement |
|
2101 |
void CObeyFile::SplitPatchDataStatement(StringVector& aPatchDataTokens) { |
|
2102 |
// Get the value of symbol size, address/ordinal and new value |
|
2103 |
// to be patched from the patchdata statement. |
|
2104 |
// Syntax of patchdata statements is as follows: |
|
2105 |
// 1) patchdata dll_name ordinal OrdinalNumber size_in_bytes new_value |
|
2106 |
// 2) patchdata dll_name addr Address size_in_bytes new_value |
|
2107 |
for(TInt count=1; count<=5; count++) { |
|
2108 |
aPatchDataTokens.push_back(iReader.Word(count)); |
|
2109 |
} |
|
2110 |
||
2111 |
// Store the the value of current line which will be used |
|
2112 |
// when displaying error messages. |
|
2113 |
ostringstream outStrStream; |
|
2114 |
outStrStream<<iReader.CurrentLine(); |
|
2115 |
aPatchDataTokens.push_back(outStrStream.str()); |
|
2116 |
} |
|
2117 |
||
2118 |
TBool CObeyFile::ParsePatchDllData() { |
|
2119 |
// Get the list of patchdata statements |
|
2120 |
VectorOfStringVector patchDataStatements=iPatchData->GetPatchDataStatements(); |
|
2121 |
// Get the list of renamed file map |
|
2122 |
MapOfString RenamedFileMap=iPatchData->GetRenamedFileMap(); |
|
2123 |
||
2124 |
for(TUint count=0; count < patchDataStatements.size(); count++) { |
|
2125 |
||
2126 |
StringVector strVector = patchDataStatements.at(count); |
|
2127 |
string filename=strVector.at(0); |
|
2128 |
string lineNoStr = strVector.at(5); |
|
2129 |
TUint lineNo = 0 ; |
|
2130 |
Val(lineNo,lineNoStr.c_str()); |
|
2131 |
TRomNode* existingFile = NULL; |
|
2132 |
||
2133 |
do { |
|
2134 |
TRomNode* dir=iRootDirectory; |
|
2135 |
TBool endOfName=EFalse; |
|
2136 |
||
2137 |
if (!IsValidFilePath(filename.c_str())) { |
|
2138 |
Print(EError, "Invalid source path on line %d\n",lineNo); |
|
2139 |
return EFalse; |
|
2140 |
} |
|
2141 |
char* epocStartPtr =NormaliseFileName(filename.c_str()); |
|
2142 |
char* savedPtr = epocStartPtr; |
|
2143 |
if(*epocStartPtr == '/' ||*epocStartPtr == '\\') |
|
2144 |
epocStartPtr++ ; |
|
2145 |
char* epocEndPtr = epocStartPtr; |
|
2146 |
||
2147 |
while (!endOfName) { |
|
2148 |
endOfName = GetNextBitOfFileName(epocEndPtr); |
|
2149 |
if (endOfName) {// file |
|
2150 |
existingFile=dir->FindInDirectory(epocStartPtr); |
|
2151 |
if (existingFile) { |
|
2152 |
TInt fileCount=0; |
|
2153 |
TInt dirCount=0; |
|
2154 |
existingFile->CountDirectory(fileCount, dirCount); |
|
2155 |
if (dirCount != 0 || fileCount != 0) { |
|
2156 |
Print(EError, "Keyword %s not applicable to directories - line %d\n","patchdata",lineNo); |
|
2157 |
return EFalse; |
|
2158 |
} |
|
2159 |
} |
|
2160 |
} |
|
2161 |
else {// directory |
|
2162 |
TRomNode* subDir = dir->FindInDirectory(epocStartPtr); |
|
2163 |
if (!subDir) // sub directory does not exist |
|
2164 |
break; |
|
2165 |
dir=subDir; |
|
2166 |
epocStartPtr = epocEndPtr; |
|
2167 |
} |
|
2168 |
} |
|
2169 |
delete []savedPtr; |
|
2170 |
||
2171 |
if(!existingFile) { |
|
2172 |
// If the E32Image file to be patched is not included then check if the |
|
2173 |
// file was renamed. |
|
2174 |
MapOfStringIterator RenamedFileMapIterator; |
|
2175 |
if ((RenamedFileMapIterator=RenamedFileMap.find(filename)) != RenamedFileMap.end()) |
|
2176 |
filename = (*RenamedFileMapIterator).second; |
|
2177 |
else { |
|
2178 |
Print(EError, "File %s not found - line %d\n", filename.c_str(), lineNo); |
|
2179 |
return EFalse; |
|
2180 |
} |
|
2181 |
} |
|
2182 |
}while(!existingFile); |
|
2183 |
||
2184 |
TUint32 aSize, aOrdinal, aNewValue, aOffset; |
|
2185 |
TLinAddr aDataAddr; |
|
2186 |
||
2187 |
aOrdinal = (TUint32)-1; |
|
2188 |
aDataAddr = (TUint32)-1; |
|
2189 |
aOffset = 0; |
|
2190 |
||
2191 |
string symbolSize=strVector.at(3); |
|
2192 |
Val(aSize,symbolSize.c_str()); |
|
2193 |
string aValue=strVector.at(4); |
|
2194 |
Val(aNewValue,aValue.c_str()); |
|
2195 |
||
2196 |
DllDataEntry *dataEntry = new DllDataEntry(aSize, aNewValue); |
|
2197 |
||
2198 |
// Set the address of the data or the ordinal number specified in OBY statement. |
|
2199 |
string keyword=strVector.at(1); |
|
2200 |
string keywordValue=strVector.at(2); |
|
2201 |
||
2202 |
/* Check for +OFFSET at the end of the ordinal number or address */ |
|
2203 |
TUint plus = keywordValue.find("+",0); |
|
2204 |
if (plus != string::npos) { |
|
2205 |
/* Get the offset that we found after the + sign */ |
|
2206 |
string offset = keywordValue.substr(plus+1); |
|
2207 |
Val(aOffset,offset.c_str()); |
|
2208 |
||
2209 |
keywordValue.resize(plus); |
|
2210 |
} |
|
2211 |
if(stricmp (keyword.c_str(), "addr") == 0) |
|
2212 |
Val(aDataAddr,keywordValue.c_str()); |
|
2213 |
||
2214 |
else |
|
2215 |
Val(aOrdinal,keywordValue.c_str()); |
|
2216 |
||
2217 |
dataEntry->iDataAddress = aDataAddr; |
|
2218 |
dataEntry->iOrdinal = aOrdinal; |
|
2219 |
dataEntry->iOffset = aOffset; |
|
2220 |
||
2221 |
existingFile->SetDllData(); |
|
2222 |
||
2223 |
DllDataEntry *aDllDataEntry= existingFile->iEntry->GetFirstDllDataEntry(); |
|
2224 |
if (aDllDataEntry == NULL) { |
|
2225 |
// Set the first node of the patchdata linked list |
|
2226 |
aDllDataEntry=dataEntry; |
|
2227 |
existingFile->iEntry->SetFirstDllDataEntry(aDllDataEntry); |
|
2228 |
} |
|
2229 |
else { |
|
2230 |
// Goto the last node |
|
2231 |
while((aDllDataEntry->NextDllDataEntry()) != NULL) { |
|
2232 |
aDllDataEntry = aDllDataEntry->NextDllDataEntry(); |
|
2233 |
} |
|
2234 |
// Add the new node at the end of linked list |
|
2235 |
aDllDataEntry->AddDllDataEntry(dataEntry); |
|
2236 |
} |
|
2237 |
} |
|
2238 |
return ETrue; |
|
2239 |
} |