author | jascui |
Wed, 17 Nov 2010 13:39:15 +0800 | |
changeset 687 | da9e6195bd8d |
parent 675 | 02e65118a746 |
child 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 |
||
1487 |
if (aKeyword!=EKeywordHideV2) { |
|
1488 |
||
1489 |
// check the PC file exists |
|
1490 |
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
|
1491 |
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
|
1492 |
{ |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1493 |
char* tempnname = strdup(nname); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1494 |
unsigned int namelen = 0; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1495 |
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
|
1496 |
{ |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1497 |
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
|
1498 |
free(tempnname); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1499 |
delete[] nname; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1500 |
return EFalse; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1501 |
} |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1502 |
free(tempnname); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
617
diff
changeset
|
1503 |
} |
606 | 1504 |
ifstream test(nname); |
1505 |
if (!test) { |
|
1506 |
Print(EError,"Cannot open file %s for input.\n",iReader.Word(1)); |
|
1507 |
iMissingFiles++; |
|
1508 |
} |
|
1509 |
test.close(); |
|
1510 |
delete []nname; |
|
1511 |
} |
|
1512 |
else |
|
1513 |
epocPathStart=1; |
|
1514 |
||
1515 |
iNumberOfFiles++; |
|
1516 |
||
1517 |
||
1518 |
TBool endOfName=EFalse; |
|
1519 |
const char *epocStartPtr=IsValidFilePath(iReader.Word(epocPathStart)); |
|
1520 |
char *epocEndPtr=const_cast<char*>(epocStartPtr); |
|
1521 |
if (epocStartPtr==NULL) { |
|
1522 |
Print(EError, "Invalid destination path on line %d\n",currentLine); |
|
1523 |
return EFalse; |
|
1524 |
} |
|
1525 |
if(warnFlag){ // Check for the std destination path(for executables) as per platsec. |
|
1526 |
if(strnicmp(aStdPath,epocStartPtr,sysBinLength) != 0) { |
|
1527 |
Print(EWarning,"Invalid destination path on line %d. \"%s\" \n",currentLine,epocStartPtr); |
|
1528 |
} |
|
1529 |
} |
|
1530 |
||
1531 |
TRomNode* dir=iRootDirectory; |
|
1532 |
TRomNode* subDir=0; |
|
1533 |
TRomBuilderEntry *file=0; |
|
1534 |
while (!endOfName) { |
|
1535 |
endOfName = GetNextBitOfFileName(epocEndPtr); |
|
1536 |
if (endOfName) {// file |
|
1537 |
TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr); |
|
1538 |
/* |
|
1539 |
* The EKeywordHideV2 keyword is used to indicate that: |
|
1540 |
* 1. if the file exists in the same image and then hidden, mark it hidden |
|
1541 |
* 2. if the file exists in another image, but in this (ROFS) image, it is |
|
1542 |
* required to hide that file, create a 0 length file entry setting the 'hide' |
|
1543 |
* flag so that at runtime, file gets hidden in the composite filesystem. |
|
1544 |
*/ |
|
1545 |
if ((aKeyword != EKeywordHideV2) && alreadyExists){ // duplicate file |
|
1546 |
if(gKeepGoing){ |
|
1547 |
Print(EWarning, "Duplicate file for %s on line %d, will be ignored\n",iReader.Word(1),iReader.CurrentLine()); |
|
1548 |
switch (aKeyword) |
|
1549 |
{ |
|
1550 |
case EKeywordData: |
|
1551 |
case EKeywordHideV2: |
|
1552 |
iNumberOfDataFiles--; |
|
1553 |
default: |
|
1554 |
break; |
|
1555 |
} |
|
1556 |
iNumberOfFiles--; |
|
1557 |
return ETrue; |
|
1558 |
} |
|
1559 |
else { |
|
1560 |
Print(EError, "Duplicate file for %s on line %d\n",iReader.Word(1),iReader.CurrentLine()); |
|
1561 |
return EFalse; |
|
1562 |
} |
|
1563 |
} |
|
1564 |
||
1565 |
TBool aHidden = aKeyword==EKeywordHideV2; |
|
1566 |
/* The file is only marked hidden and hence the source file name isn't known |
|
1567 |
* here as hide statement says : |
|
1568 |
* hide <filename as in ROM> |
|
1569 |
* Therefore, create TRomBuilderEntry with iFileName as 0 for hidden file when |
|
1570 |
* the file doesn't exist in the same ROM image. Otherwise, the src file name |
|
1571 |
* is known because of alreadyExists (which comes from the 'file'/'data' statement). |
|
1572 |
*/ |
|
1573 |
if(aHidden) |
|
1574 |
file = new TRomBuilderEntry(0, epocStartPtr); |
|
1575 |
else |
|
1576 |
file = new TRomBuilderEntry(iReader.Word(1), epocStartPtr); |
|
1577 |
file->iExecutable=isPeFile; |
|
1578 |
file->iHidden= aHidden; |
|
1579 |
if( aFileCompressOption ){ |
|
1580 |
file->iCompressEnabled = ECompressionCompress; |
|
1581 |
} |
|
1582 |
else if(aFileUncompressOption ) { |
|
1583 |
file->iCompressEnabled = ECompressionUncompress; |
|
1584 |
} |
|
1585 |
TRomNode* node=new TRomNode(epocStartPtr, file); |
|
1586 |
if (node==0) |
|
1587 |
return EFalse; |
|
1588 |
TInt r=ParseFileAttributes(node, file, aKeyword); |
|
1589 |
if (r!=KErrNone) |
|
1590 |
return EFalse; |
|
1591 |
||
1592 |
dir->AddFile(node); // to ROFS directory structure |
|
1593 |
AddFile(file); // to our list of files |
|
1594 |
} |
|
1595 |
else { // directory |
|
1596 |
subDir = dir->FindInDirectory(epocStartPtr); |
|
1597 |
if (!subDir) { // sub directory does not exist |
|
1598 |
subDir = dir->NewSubDir(epocStartPtr); |
|
1599 |
if (!subDir) |
|
1600 |
return EFalse; |
|
1601 |
} |
|
1602 |
dir=subDir; |
|
1603 |
epocStartPtr = epocEndPtr; |
|
1604 |
} |
|
1605 |
} |
|
1606 |
return ETrue; |
|
1607 |
} |
|
1608 |
||
1609 |
||
1610 |
TBool CObeyFile::ProcessRenaming(enum EKeyword aKeyword) { |
|
1611 |
||
1612 |
// find existing file |
|
1613 |
TBool endOfName=EFalse; |
|
1614 |
const char *epocStartPtr=IsValidFilePath(iReader.Word(1)); |
|
1615 |
||
1616 |
// Store the current name and new name to maintain renamed file map |
|
1617 |
string currentName=iReader.Word(1); |
|
1618 |
string newName=iReader.Word(2); |
|
1619 |
||
1620 |
char *epocEndPtr= const_cast<char*>(epocStartPtr); |
|
1621 |
if (epocStartPtr == NULL) { |
|
1622 |
Print(EError, "Invalid source path on line %d\n",iReader.CurrentLine()); |
|
1623 |
return EFalse; |
|
1624 |
} |
|
1625 |
||
1626 |
char saved_srcname[257]; |
|
1627 |
strncpy(saved_srcname, iReader.Word(1),257); |
|
1628 |
||
1629 |
TRomNode* dir=iRootDirectory; |
|
1630 |
TRomNode* existingFile=0; |
|
1631 |
while (!endOfName){ |
|
1632 |
endOfName = GetNextBitOfFileName(epocEndPtr); |
|
1633 |
if (endOfName) { // file |
|
1634 |
existingFile=dir->FindInDirectory(epocStartPtr); |
|
1635 |
if (existingFile) { |
|
1636 |
TInt fileCount=0; |
|
1637 |
TInt dirCount=0; |
|
1638 |
existingFile->CountDirectory(fileCount, dirCount); |
|
1639 |
if (dirCount != 0 || fileCount != 0) { |
|
1640 |
Print(EError, "Keyword %s not applicable to directories - line %d\n", |
|
1641 |
iReader.Word(0),iReader.CurrentLine()); |
|
1642 |
return EFalse; |
|
1643 |
} |
|
1644 |
} |
|
1645 |
} |
|
1646 |
else { // directory |
|
1647 |
TRomNode* subDir = dir->FindInDirectory(epocStartPtr); |
|
1648 |
if (!subDir) // sub directory does not exist |
|
1649 |
break; |
|
1650 |
dir=subDir; |
|
1651 |
epocStartPtr = epocEndPtr; |
|
1652 |
} |
|
1653 |
} |
|
1654 |
if (aKeyword == EKeywordHide) { |
|
1655 |
/* |
|
1656 |
* The EKeywordHide keyword is used to indicate that if the file exists in |
|
1657 |
* the primary ROFS image and then hidden in extension ROFS, mark it hidden. |
|
1658 |
*/ |
|
1659 |
if (!existingFile) { |
|
1660 |
Print(EWarning, "Hiding non-existent file %s on line %d\n", |
|
1661 |
saved_srcname, iReader.CurrentLine()); |
|
1662 |
// Just a warning, as we've achieved the right overall effect. |
|
1663 |
} |
|
1664 |
else if (existingFile->iFileStartOffset==(TUint)KFileHidden){ |
|
1665 |
Print(EWarning, "Hiding already hidden file %s on line %d\n", |
|
1666 |
saved_srcname, iReader.CurrentLine()); |
|
1667 |
// We will igrore this request, otherwise it will "undelete" it. |
|
1668 |
} |
|
1669 |
else { |
|
1670 |
//hidden files will not be placed to the image |
|
1671 |
existingFile->iHidden = ETrue; |
|
1672 |
} |
|
1673 |
return ETrue; |
|
1674 |
} |
|
1675 |
||
1676 |
if (!existingFile) { |
|
1677 |
Print(EError, "Can't %s non-existent source file %s on line %d\n", |
|
1678 |
iReader.Word(0), saved_srcname, iReader.CurrentLine()); |
|
1679 |
return EFalse; |
|
1680 |
} |
|
1681 |
||
1682 |
epocStartPtr = IsValidFilePath(iReader.Word(2)); |
|
1683 |
epocEndPtr = const_cast<char*>(epocStartPtr); |
|
1684 |
endOfName = EFalse; |
|
1685 |
if (epocStartPtr == NULL) { |
|
1686 |
Print(EError, "Invalid destination path on line %d\n",iReader.CurrentLine()); |
|
1687 |
return EFalse; |
|
1688 |
} |
|
1689 |
||
1690 |
TRomNode* newdir=iRootDirectory; |
|
1691 |
while (!endOfName) { |
|
1692 |
endOfName = GetNextBitOfFileName(epocEndPtr); |
|
1693 |
if (endOfName) {// file |
|
1694 |
TRomNode* alreadyExists=newdir->FindInDirectory(epocStartPtr); |
|
1695 |
if (alreadyExists && !(alreadyExists->iHidden)) {// duplicate file |
|
1696 |
if(gKeepGoing){ |
|
1697 |
Print(EWarning, "Duplicate file for %s on line %d, renaming will be skipped\n",saved_srcname,iReader.CurrentLine()); |
|
1698 |
return ETrue; |
|
1699 |
} |
|
1700 |
else { |
|
1701 |
Print(EError, "Duplicate file for %s on line %d\n",saved_srcname,iReader.CurrentLine()); |
|
1702 |
return EFalse; |
|
1703 |
} |
|
1704 |
} |
|
1705 |
} |
|
1706 |
else { // directory |
|
1707 |
TRomNode* subDir = newdir->FindInDirectory(epocStartPtr); |
|
1708 |
if (!subDir) {// sub directory does not exist |
|
1709 |
subDir = newdir->NewSubDir(epocStartPtr); |
|
1710 |
if (!subDir) |
|
1711 |
return EFalse; |
|
1712 |
} |
|
1713 |
newdir=subDir; |
|
1714 |
epocStartPtr = epocEndPtr; |
|
1715 |
} |
|
1716 |
} |
|
1717 |
||
1718 |
if (aKeyword == EKeywordRename) { |
|
1719 |
// rename => remove existingFile and insert into tree at new place |
|
1720 |
// has no effect on the iNextExecutable or iNextNodeForSameFile links |
|
1721 |
TInt r=ParseFileAttributes(existingFile, existingFile->iEntry, aKeyword); |
|
1722 |
if (r!=KErrNone) |
|
1723 |
return EFalse; |
|
1724 |
existingFile->Rename(dir, newdir, epocStartPtr); |
|
1725 |
// Store the current and new name of file in the renamed file map. |
|
1726 |
iPatchData->AddToRenamedFileMap(currentName, newName); |
|
1727 |
return ETrue; |
|
1728 |
} |
|
1729 |
||
1730 |
// alias => create new TRomNode entry and insert into tree |
|
1731 |
TRomNode* node = new TRomNode(epocStartPtr, 0); |
|
1732 |
if (node == 0) { |
|
1733 |
Print(EError, "Out of memory\n"); |
|
1734 |
return EFalse; |
|
1735 |
} |
|
1736 |
node->Alias(existingFile); |
|
1737 |
TInt r=ParseFileAttributes(node, 0, aKeyword); |
|
1738 |
if (r!=KErrNone) |
|
1739 |
return EFalse; |
|
1740 |
newdir->AddFile(node); // to ROFS directory structure, though possibly hidden |
|
1741 |
return ETrue; |
|
1742 |
} |
|
1743 |
||
1744 |
TInt ParsePagingPolicy(const char* policy){ |
|
1745 |
if(stricmp(policy,"NOPAGING") == 0) |
|
1746 |
return EKernelConfigPagingPolicyNoPaging; |
|
1747 |
else if (stricmp(policy,"ALWAYSPAGE") == 0) |
|
1748 |
return EKernelConfigPagingPolicyAlwaysPage; |
|
1749 |
else if(stricmp(policy,"DEFAULTUNPAGED") == 0) |
|
1750 |
return EKernelConfigPagingPolicyDefaultUnpaged; |
|
1751 |
else if(stricmp(policy,"DEFAULTPAGED") == 0) |
|
1752 |
return EKernelConfigPagingPolicyDefaultPaged; |
|
1753 |
return KErrArgument; |
|
1754 |
} |
|
1755 |
||
1756 |
TBool CObeyFile::ProcessKeyword(enum EKeyword aKeyword) { |
|
1757 |
||
1758 |
TBool success = ETrue; |
|
1759 |
switch (aKeyword) |
|
1760 |
{ |
|
1761 |
case EKeywordRofsName: |
|
1762 |
iRomFileName = iReader.DupWord(1); |
|
1763 |
break; |
|
1764 |
case EKeywordRofsSize: |
|
1765 |
Val(iRomSize,iReader.Word(1)); |
|
1766 |
break; |
|
1767 |
case EKeywordVersion: |
|
1768 |
{ |
|
1769 |
istringstream val(iReader.Word(1)); |
|
1770 |
val >> iVersion; |
|
1771 |
} |
|
1772 |
break; |
|
1773 |
case EKeywordRofsChecksum: |
|
1774 |
Val(iCheckSum,iReader.Word(1)); |
|
1775 |
break; |
|
1776 |
case EKeywordTime: |
|
1777 |
iReader.ProcessTime(iTime); |
|
1778 |
break; |
|
1779 |
case EKeywordPagingOverride: |
|
1780 |
{ |
|
1781 |
if(iPagingOverrideParsed) |
|
1782 |
Print(EWarning, "PagingOverride redefined - previous PagingOverride values lost\n"); |
|
1783 |
if(iCodePagingOverrideParsed) |
|
1784 |
Print(EWarning, "PagingOverride defined - previous CodePagingOverride values lost\n"); |
|
1785 |
iPagingOverrideParsed = true; |
|
1786 |
TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1787 |
if(policy < 0) { |
|
1788 |
Print(EError,"Unrecognized option for PAGINGOVERRIDE keyword\n"); |
|
1789 |
success = false; |
|
1790 |
} |
|
1791 |
else { |
|
1792 |
gCodePagingOverride = policy; |
|
1793 |
if((policy == EKernelConfigPagingPolicyNoPaging) || (policy == EKernelConfigPagingPolicyDefaultUnpaged)) |
|
1794 |
gDataPagingOverride = policy; |
|
1795 |
} |
|
1796 |
} |
|
1797 |
break; |
|
1798 |
case EKeywordCodePagingOverride: |
|
1799 |
{ |
|
1800 |
if(iCodePagingOverrideParsed) |
|
1801 |
Print(EWarning, "CodePagingOverride redefined - previous CodePagingOverride values lost\n"); |
|
1802 |
if(iPagingOverrideParsed) |
|
1803 |
Print(EWarning, "CodePagingOverride defined - previous PagingOverride values lost\n"); |
|
1804 |
iCodePagingOverrideParsed = true; |
|
1805 |
TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1806 |
if(policy<0) |
|
1807 |
{ |
|
1808 |
Print(EError,"Unrecognized option for CODEPAGINGOVERRIDE keyword\n"); |
|
1809 |
success = false; |
|
1810 |
} |
|
1811 |
else |
|
1812 |
gCodePagingOverride = policy; |
|
1813 |
} |
|
1814 |
break; |
|
1815 |
case EKeywordDataPagingOverride: |
|
1816 |
{ |
|
1817 |
if(iDataPagingOverrideParsed) |
|
1818 |
Print(EWarning, "DataPagingOverride redefined - previous DataPagingOverride values lost\n"); |
|
1819 |
/* if(iPagingOverrideParsed){ |
|
1820 |
Print(EError, "DataPagingOverride defined - previous PagingOverride values lost\n"); |
|
1821 |
success = false; |
|
1822 |
break; |
|
1823 |
} |
|
1824 |
*/ |
|
1825 |
iDataPagingOverrideParsed = true; |
|
1826 |
TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1827 |
if(policy < 0) { |
|
1828 |
Print(EError,"Unrecognized option for DATAPAGINGOVERRIDE keyword\n"); |
|
1829 |
success = false; |
|
1830 |
} |
|
1831 |
else |
|
1832 |
gDataPagingOverride = policy; |
|
1833 |
} |
|
1834 |
break; |
|
1835 |
case EKeywordRofsAutoSize: |
|
1836 |
iAutoSize = ETrue; |
|
1837 |
Val(iAutoPageSize,iReader.Word(1)); |
|
1838 |
break; |
|
1839 |
default: |
|
1840 |
// 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
|
1841 |
Print(EWarning, "Unexpected keyword '%s' on line %d.\n",iReader.Word(0),iReader.CurrentLine()); |
606 | 1842 |
break; |
1843 |
} |
|
1844 |
||
1845 |
return success; |
|
1846 |
} |
|
1847 |
// |
|
1848 |
// Checks that the obeyfile has supplied enough variables to continue |
|
1849 |
// |
|
1850 |
TBool CObeyFile::GotKeyVariables() { |
|
1851 |
||
1852 |
TBool retVal=ETrue; |
|
1853 |
// Mandatory keywords |
|
1854 |
if (iRomFileName == 0) { |
|
1855 |
Print(EAlways,"The name of the image file has not been supplied.\n"); |
|
1856 |
Print(EAlways,"Use the keyword \"rofsname\".\n"); |
|
1857 |
retVal = EFalse; |
|
1858 |
} |
|
1859 |
if (iRomSize == 0) { |
|
1860 |
Print(EAlways,"The size of the image has not been supplied.\n"); |
|
1861 |
Print(EAlways,"Use the keyword \"rofssize\".\n"); |
|
1862 |
retVal = EFalse; |
|
1863 |
} |
|
1864 |
// Apply defaults as necessary |
|
1865 |
if (iTime == 0) { |
|
1866 |
Print(ELog, "No timestamp specified. Using current time...\n"); |
|
1867 |
ObeyFileReader::TimeNow(iTime); |
|
1868 |
} |
|
1869 |
Print(ELog, "\nCreating Rofs image %s\n", iRomFileName); |
|
1870 |
return retVal; |
|
1871 |
} |
|
1872 |
||
1873 |
// |
|
1874 |
// Check the path is valid |
|
1875 |
// |
|
1876 |
const char* CObeyFile::IsValidFilePath(const char* aPath) { |
|
1877 |
// skip leading "\" |
|
1878 |
if (*aPath == '/' || *aPath == '\\') |
|
1879 |
aPath++; |
|
1880 |
if (*aPath == 0) |
|
1881 |
return NULL; // file ends in a backslash |
|
1882 |
||
1883 |
const char *p = aPath; |
|
1884 |
TInt len=0; |
|
1885 |
while(*p) { |
|
1886 |
if (*p == '/' || *p == '\\') { |
|
1887 |
if (len == 0) |
|
1888 |
return NULL; |
|
1889 |
len=0; |
|
1890 |
p++; |
|
1891 |
continue; |
|
1892 |
||
1893 |
} |
|
1894 |
len++; |
|
1895 |
p++; |
|
1896 |
} |
|
1897 |
return (len ? aPath : NULL); |
|
1898 |
} |
|
1899 |
||
1900 |
const char* CObeyFile::IsValidDirPath(const char* aPath) |
|
1901 |
{ |
|
1902 |
const char* walker = aPath; |
|
1903 |
||
1904 |
//validate path... |
|
1905 |
while(*walker) |
|
1906 |
{ |
|
1907 |
if(((*walker=='/') || (*walker=='\\')) && ((*(walker+1)=='/') || (*(walker+1)=='\\'))) |
|
1908 |
return (const char*)0; |
|
1909 |
walker++; |
|
1910 |
} |
|
1911 |
||
1912 |
if((*aPath=='/') || (*aPath=='\\')) |
|
1913 |
aPath++; |
|
1914 |
||
1915 |
return aPath; |
|
1916 |
} |
|
1917 |
||
1918 |
// |
|
1919 |
// Move the end pointer past the next directory separator, replacing it with 0 |
|
1920 |
// |
|
1921 |
TBool CObeyFile::GetNextBitOfFileName(char*& epocEndPtr) { |
|
1922 |
while (*epocEndPtr != '/' && *epocEndPtr != '\\'){ // until reach the directory separator |
|
1923 |
if (*epocEndPtr == 0) // if reach end of string, return TRUE, it's the filename |
|
1924 |
return ETrue; |
|
1925 |
epocEndPtr++; |
|
1926 |
} |
|
1927 |
*epocEndPtr = 0; // overwrite the directory separator with a 0 |
|
1928 |
epocEndPtr++; // point past the 0 ready for the next one |
|
1929 |
return EFalse; |
|
1930 |
} |
|
1931 |
||
1932 |
void CObeyFile::AddFile(TRomBuilderEntry* aFile) { |
|
1933 |
*iNextFilePtrPtr = aFile; |
|
1934 |
iNextFilePtrPtr = &(aFile->iNext); |
|
1935 |
} |
|
1936 |
||
1937 |
// |
|
1938 |
// First pass through the obey file to set up key variables |
|
1939 |
// |
|
1940 |
TInt CObeyFile::ProcessExtensionRofs(MRofsImage* aKernelRom) { |
|
1941 |
||
1942 |
iReader.Rewind(); |
|
1943 |
enum EKeyword keyword; |
|
1944 |
||
1945 |
// Deal with the "extensionrofs" keyword, which should be first |
|
1946 |
// however, you may've found "time" before it. |
|
1947 |
while(iReader.NextLine(1,keyword) != KErrEof) { |
|
1948 |
if(EKeywordExtensionRofs == keyword) |
|
1949 |
break ; |
|
1950 |
} |
|
1951 |
if(EKeywordExtensionRofs != keyword) return KErrEof; |
|
1952 |
iRomFileName = iReader.DupWord(1); |
|
1953 |
Print(ELog, "\n========================================================\n"); |
|
1954 |
Print(ELog, "Extension ROFS %s starting at line %d\n\n", iRomFileName, iReader.CurrentLine()); |
|
1955 |
||
1956 |
iReader.MarkNext(); // so that we rewind to the line after the extensionrom keyword |
|
1957 |
||
1958 |
while (iReader.NextLine(1,keyword) != KErrEof) { |
|
1959 |
if (keyword == EKeywordExtensionRofs) |
|
1960 |
break; |
|
1961 |
ProcessExtensionKeyword(keyword); |
|
1962 |
} |
|
1963 |
||
1964 |
if (!GotExtensionVariables(aKernelRom)) |
|
1965 |
return KErrGeneral; |
|
1966 |
||
1967 |
// second pass to process the file specifications in the obey file building |
|
1968 |
// up the TRomNode directory structure and the TRomBuilderEntry list |
|
1969 |
// |
|
1970 |
iReader.Rewind(); |
|
1971 |
||
1972 |
// |
|
1973 |
if (aKernelRom == 0) |
|
1974 |
return Print(EError, "Option to extend a kernel ROFS image not yet implemented\n"); |
|
1975 |
||
1976 |
iRootDirectory = new TRomNode(""); |
|
1977 |
||
1978 |
iLastExecutable = 0; |
|
1979 |
||
1980 |
(aKernelRom->RootDirectory())->deleteTheFirstNode(); |
|
1981 |
||
1982 |
||
1983 |
iRootDirectory = aKernelRom->CopyDirectory(iLastExecutable); |
|
1984 |
aKernelRom->SetRootDirectory(iRootDirectory); |
|
1985 |
||
1986 |
||
1987 |
TInt align=0; |
|
1988 |
while (iReader.NextLine(2,keyword)!=KErrEof) { |
|
1989 |
if (keyword == EKeywordExtensionRofs) |
|
1990 |
break; |
|
1991 |
||
1992 |
switch (keyword) |
|
1993 |
{ |
|
1994 |
case EKeywordHide: |
|
1995 |
case EKeywordAlias: |
|
1996 |
case EKeywordRename: |
|
1997 |
if (!ProcessRenaming(keyword)) |
|
1998 |
return KErrGeneral; |
|
1999 |
break; |
|
2000 |
||
2001 |
case EKeywordPatchDllData: |
|
2002 |
{ |
|
2003 |
// Collect patchdata statements to process at the end |
|
2004 |
StringVector patchDataTokens; |
|
2005 |
SplitPatchDataStatement(patchDataTokens); |
|
2006 |
iPatchData->AddPatchDataStatement(patchDataTokens); |
|
2007 |
break; |
|
2008 |
} |
|
2009 |
default: |
|
2010 |
if (!ProcessFile(align, keyword)) |
|
2011 |
return KErrGeneral; |
|
2012 |
align=0; |
|
2013 |
break; |
|
2014 |
} |
|
2015 |
} |
|
2016 |
||
2017 |
if(!ParsePatchDllData() ) |
|
2018 |
return KErrGeneral; |
|
2019 |
||
2020 |
iReader.MarkNext(); // ready for processing the next extension rom(s) |
|
2021 |
||
2022 |
if (iMissingFiles!=0) |
|
2023 |
return KErrGeneral; |
|
2024 |
if (iNumberOfFiles == 0) { |
|
2025 |
Print(EError, "No files specified.\n"); |
|
2026 |
return KErrGeneral; |
|
2027 |
} |
|
2028 |
return KErrNone; |
|
2029 |
} |
|
2030 |
void CObeyFile::ProcessExtensionKeyword(enum EKeyword aKeyword) { |
|
2031 |
||
2032 |
switch (aKeyword) |
|
2033 |
{ |
|
2034 |
case EKeywordCoreRofsName: |
|
2035 |
iKernelRofsName = iReader.DupWord(1); |
|
2036 |
return; |
|
2037 |
case EKeywordRofsSize: |
|
2038 |
Val(iRomSize,iReader.Word(1)); |
|
2039 |
return; |
|
2040 |
case EKeywordVersion: |
|
2041 |
{ |
|
2042 |
istringstream val(iReader.Word(1)); |
|
2043 |
val >> iVersion; |
|
2044 |
} |
|
2045 |
return; |
|
2046 |
case EKeywordRomChecksum: |
|
2047 |
Val(iCheckSum,iReader.Word(1)); //-- |
|
2048 |
return; |
|
2049 |
case EKeywordTime: |
|
2050 |
iReader.ProcessTime(iTime); |
|
2051 |
return; |
|
2052 |
case EKeywordRofsAutoSize: |
|
2053 |
iAutoSize = ETrue; |
|
2054 |
Val(iAutoPageSize , iReader.Word(1)); |
|
2055 |
return; |
|
2056 |
default: |
|
2057 |
Print(EError,"Keyword '%s' not valid in extension ROFS - line %d\n", iReader.Word(0), iReader.CurrentLine()); |
|
2058 |
break; |
|
2059 |
} |
|
2060 |
return; |
|
2061 |
} |
|
2062 |
// |
|
2063 |
// Checks that the obeyfile has supplied enough variables to continue |
|
2064 |
// |
|
2065 |
TBool CObeyFile::GotExtensionVariables(MRofsImage* aRom) { |
|
2066 |
||
2067 |
TBool retVal=ETrue; |
|
2068 |
const char* kernelRofsName = iKernelRofsName; |
|
2069 |
||
2070 |
// Mandatory keywords |
|
2071 |
||
2072 |
if (iRomSize == 0){ |
|
2073 |
Print(EAlways,"The size of the extension ROFS has not been supplied.\n"); |
|
2074 |
Print(EAlways,"Use the keyword \"rofssize\".\n"); |
|
2075 |
retVal = EFalse; |
|
2076 |
} |
|
2077 |
||
2078 |
// keywords we need if we don't already have a ROFS image to work from |
|
2079 |
if (aRom == 0) { |
|
2080 |
if (iKernelRofsName == 0) { |
|
2081 |
Print(EAlways,"The name of the core ROFS has not been supplied.\n"); |
|
2082 |
Print(EAlways,"Use the keyword \"rofsname\".\n"); |
|
2083 |
retVal = EFalse; |
|
2084 |
} |
|
2085 |
} |
|
2086 |
else { |
|
2087 |
if (iKernelRofsName != 0){ |
|
2088 |
Print(EWarning,"Keyword \"rofsname\" ignored.\n"); |
|
2089 |
} |
|
2090 |
kernelRofsName = aRom->RomFileName(); |
|
2091 |
} |
|
2092 |
||
2093 |
// validation |
|
2094 |
// Apply defaults as necessary |
|
2095 |
if (iTime == 0) { |
|
2096 |
Print(ELog, "No timestamp specified. Using current time...\n"); |
|
2097 |
ObeyFileReader::TimeNow(iTime); |
|
2098 |
} |
|
2099 |
||
2100 |
// fix up "*" in rofsname |
|
2101 |
char newname[256]; |
|
2102 |
char* p=newname; |
|
2103 |
char* q=iRomFileName; |
|
2104 |
char c; |
|
2105 |
||
2106 |
while ((c=*q++)!='\0'){ |
|
2107 |
if (c!='*') { |
|
2108 |
*p++=c; |
|
2109 |
continue; |
|
2110 |
} |
|
2111 |
const char *r = kernelRofsName; |
|
2112 |
while ((c=*r++)!='\0') |
|
2113 |
*p++=c; |
|
2114 |
} |
|
2115 |
*p++ = '\0'; |
|
2116 |
delete []iRomFileName; |
|
2117 |
size_t len = p - newname ; |
|
2118 |
iRomFileName = new char[len]; |
|
2119 |
memcpy(iRomFileName,newname,len); |
|
2120 |
Print(ELog, "\nCreating ROFS image %s\n", iRomFileName); |
|
2121 |
return retVal; |
|
2122 |
} |
|
2123 |
||
2124 |
// Fuction to split patchdata statement |
|
2125 |
void CObeyFile::SplitPatchDataStatement(StringVector& aPatchDataTokens) { |
|
2126 |
// Get the value of symbol size, address/ordinal and new value |
|
2127 |
// to be patched from the patchdata statement. |
|
2128 |
// Syntax of patchdata statements is as follows: |
|
2129 |
// 1) patchdata dll_name ordinal OrdinalNumber size_in_bytes new_value |
|
2130 |
// 2) patchdata dll_name addr Address size_in_bytes new_value |
|
2131 |
for(TInt count=1; count<=5; count++) { |
|
2132 |
aPatchDataTokens.push_back(iReader.Word(count)); |
|
2133 |
} |
|
2134 |
||
2135 |
// Store the the value of current line which will be used |
|
2136 |
// when displaying error messages. |
|
2137 |
ostringstream outStrStream; |
|
2138 |
outStrStream<<iReader.CurrentLine(); |
|
2139 |
aPatchDataTokens.push_back(outStrStream.str()); |
|
2140 |
} |
|
2141 |
||
2142 |
TBool CObeyFile::ParsePatchDllData() { |
|
2143 |
// Get the list of patchdata statements |
|
2144 |
VectorOfStringVector patchDataStatements=iPatchData->GetPatchDataStatements(); |
|
2145 |
// Get the list of renamed file map |
|
2146 |
MapOfString RenamedFileMap=iPatchData->GetRenamedFileMap(); |
|
2147 |
||
2148 |
for(TUint count=0; count < patchDataStatements.size(); count++) { |
|
2149 |
||
2150 |
StringVector strVector = patchDataStatements.at(count); |
|
2151 |
string filename=strVector.at(0); |
|
2152 |
string lineNoStr = strVector.at(5); |
|
2153 |
TUint lineNo = 0 ; |
|
2154 |
Val(lineNo,lineNoStr.c_str()); |
|
2155 |
TRomNode* existingFile = NULL; |
|
2156 |
||
2157 |
do { |
|
2158 |
TRomNode* dir=iRootDirectory; |
|
2159 |
TBool endOfName=EFalse; |
|
2160 |
||
2161 |
if (!IsValidFilePath(filename.c_str())) { |
|
2162 |
Print(EError, "Invalid source path on line %d\n",lineNo); |
|
2163 |
return EFalse; |
|
2164 |
} |
|
2165 |
char* epocStartPtr =NormaliseFileName(filename.c_str()); |
|
2166 |
char* savedPtr = epocStartPtr; |
|
2167 |
if(*epocStartPtr == '/' ||*epocStartPtr == '\\') |
|
2168 |
epocStartPtr++ ; |
|
2169 |
char* epocEndPtr = epocStartPtr; |
|
2170 |
||
2171 |
while (!endOfName) { |
|
2172 |
endOfName = GetNextBitOfFileName(epocEndPtr); |
|
2173 |
if (endOfName) {// file |
|
2174 |
existingFile=dir->FindInDirectory(epocStartPtr); |
|
2175 |
if (existingFile) { |
|
2176 |
TInt fileCount=0; |
|
2177 |
TInt dirCount=0; |
|
2178 |
existingFile->CountDirectory(fileCount, dirCount); |
|
2179 |
if (dirCount != 0 || fileCount != 0) { |
|
2180 |
Print(EError, "Keyword %s not applicable to directories - line %d\n","patchdata",lineNo); |
|
2181 |
return EFalse; |
|
2182 |
} |
|
2183 |
} |
|
2184 |
} |
|
2185 |
else {// directory |
|
2186 |
TRomNode* subDir = dir->FindInDirectory(epocStartPtr); |
|
2187 |
if (!subDir) // sub directory does not exist |
|
2188 |
break; |
|
2189 |
dir=subDir; |
|
2190 |
epocStartPtr = epocEndPtr; |
|
2191 |
} |
|
2192 |
} |
|
2193 |
delete []savedPtr; |
|
2194 |
||
2195 |
if(!existingFile) { |
|
2196 |
// If the E32Image file to be patched is not included then check if the |
|
2197 |
// file was renamed. |
|
2198 |
MapOfStringIterator RenamedFileMapIterator; |
|
2199 |
if ((RenamedFileMapIterator=RenamedFileMap.find(filename)) != RenamedFileMap.end()) |
|
2200 |
filename = (*RenamedFileMapIterator).second; |
|
2201 |
else { |
|
2202 |
Print(EError, "File %s not found - line %d\n", filename.c_str(), lineNo); |
|
2203 |
return EFalse; |
|
2204 |
} |
|
2205 |
} |
|
2206 |
}while(!existingFile); |
|
2207 |
||
2208 |
TUint32 aSize, aOrdinal, aNewValue, aOffset; |
|
2209 |
TLinAddr aDataAddr; |
|
2210 |
||
2211 |
aOrdinal = (TUint32)-1; |
|
2212 |
aDataAddr = (TUint32)-1; |
|
2213 |
aOffset = 0; |
|
2214 |
||
2215 |
string symbolSize=strVector.at(3); |
|
2216 |
Val(aSize,symbolSize.c_str()); |
|
2217 |
string aValue=strVector.at(4); |
|
2218 |
Val(aNewValue,aValue.c_str()); |
|
2219 |
||
2220 |
DllDataEntry *dataEntry = new DllDataEntry(aSize, aNewValue); |
|
2221 |
||
2222 |
// Set the address of the data or the ordinal number specified in OBY statement. |
|
2223 |
string keyword=strVector.at(1); |
|
2224 |
string keywordValue=strVector.at(2); |
|
2225 |
||
2226 |
/* Check for +OFFSET at the end of the ordinal number or address */ |
|
2227 |
TUint plus = keywordValue.find("+",0); |
|
2228 |
if (plus != string::npos) { |
|
2229 |
/* Get the offset that we found after the + sign */ |
|
2230 |
string offset = keywordValue.substr(plus+1); |
|
2231 |
Val(aOffset,offset.c_str()); |
|
2232 |
||
2233 |
keywordValue.resize(plus); |
|
2234 |
} |
|
2235 |
if(stricmp (keyword.c_str(), "addr") == 0) |
|
2236 |
Val(aDataAddr,keywordValue.c_str()); |
|
2237 |
||
2238 |
else |
|
2239 |
Val(aOrdinal,keywordValue.c_str()); |
|
2240 |
||
2241 |
dataEntry->iDataAddress = aDataAddr; |
|
2242 |
dataEntry->iOrdinal = aOrdinal; |
|
2243 |
dataEntry->iOffset = aOffset; |
|
2244 |
||
2245 |
existingFile->SetDllData(); |
|
2246 |
||
2247 |
DllDataEntry *aDllDataEntry= existingFile->iEntry->GetFirstDllDataEntry(); |
|
2248 |
if (aDllDataEntry == NULL) { |
|
2249 |
// Set the first node of the patchdata linked list |
|
2250 |
aDllDataEntry=dataEntry; |
|
2251 |
existingFile->iEntry->SetFirstDllDataEntry(aDllDataEntry); |
|
2252 |
} |
|
2253 |
else { |
|
2254 |
// Goto the last node |
|
2255 |
while((aDllDataEntry->NextDllDataEntry()) != NULL) { |
|
2256 |
aDllDataEntry = aDllDataEntry->NextDllDataEntry(); |
|
2257 |
} |
|
2258 |
// Add the new node at the end of linked list |
|
2259 |
aDllDataEntry->AddDllDataEntry(dataEntry); |
|
2260 |
} |
|
2261 |
} |
|
2262 |
return ETrue; |
|
2263 |
} |