|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <string.h> |
|
20 |
|
21 #ifdef __VC32__ |
|
22 #ifdef __MSVCDOTNET__ |
|
23 #include <strstream> |
|
24 #include <iomanip> |
|
25 #else //!__MSVCDOTNET__ |
|
26 #include <strstrea.h> |
|
27 #include <iomanip.h> |
|
28 #endif //__MSVCDOTNET__ |
|
29 #else //!__VC32__ |
|
30 #ifdef __TOOLS2__ |
|
31 #include <sstream> |
|
32 #include <iomanip> |
|
33 #else |
|
34 #include <strstream.h> |
|
35 #include <iomanip.h> |
|
36 #endif |
|
37 #endif //__VC32__ |
|
38 |
|
39 #include <stdlib.h> |
|
40 #include <stdio.h> |
|
41 #include <time.h> |
|
42 #include <assert.h> |
|
43 |
|
44 #include "e32std.h" |
|
45 #include "e32std_private.h" |
|
46 #include "e32rom.h" |
|
47 #include "u32std.h" |
|
48 |
|
49 #include "r_rom.h" |
|
50 #include "r_obey.h" |
|
51 #include "r_global.h" |
|
52 #include "h_utl.h" |
|
53 #include "patchdataprocessor.h" |
|
54 #include "r_coreimage.h" |
|
55 |
|
56 #define _P(word) word, sizeof(word)-1 // match prefix, optionally followed by [HWVD] |
|
57 #define _K(word) word, 0 // match whole word |
|
58 |
|
59 const ObeyFileKeyword ObeyFileReader::iKeywords[] = |
|
60 { |
|
61 {_P("file"), 2,-2, EKeywordFile, "Executable file to be loaded into the ROM"}, |
|
62 {_P("data"), 2,-2, EKeywordData, "Data file to be copied into the ROM"}, |
|
63 {_P("primary"), 1+2,-2, EKeywordPrimary, "An EPOC Kernel"}, |
|
64 {_P("secondary"), 2,-2, EKeywordSecondary, "?"}, |
|
65 {_P("variant"), 1+2,-2, EKeywordVariant, "?"}, |
|
66 {_P("extension"), 1+2,-2, EKeywordExtension, "Kernel extension loaded before the secondary"}, |
|
67 {_P("device"), 1+2,-2, EKeywordDevice, "Kernel extension loaded from the ROM file system"}, |
|
68 {_P("dll"), 2,-2, EKeywordDll, "Executable file whose entry point must be called"}, |
|
69 {_P("filecompress"), 2,-2, EKeywordFileCompress, "Non-XIP Executable to be loaded into the ROM compressed"}, |
|
70 {_P("fileuncompress"), 2,-2, EKeywordFileUncompress, "Non-XIP Executable to be loaded into the ROM uncompressed"}, |
|
71 {_K("area"), 1, 3, EKeywordArea, "Declare a relocation area"}, |
|
72 {_K("align"), 2, 1, EKeywordAlign, "Override default alignment for following file"}, |
|
73 {_P("hide"), 2, -1, EKeywordHide, "Exclude named file from ROM directory structure"}, |
|
74 {_P("alias"), 2, -2, EKeywordAlias, "Create alias for existing file in ROM directory structure"}, |
|
75 {_P("rename"), 2, -2, EKeywordRename, "Change the name of a file in the ROM directory structure"}, |
|
76 {_K("singlekernel"),1, 0, EKeywordSingleKernel, "Single Kernel"}, |
|
77 {_K("multikernel"), 1, 0, EKeywordMultiKernel, "Multiple Kernels"}, |
|
78 {_K("bootbinary"), 1, 1, EKeywordBootBinary, "file containing the bootstrap"}, |
|
79 {_K("romname"), 1, 1, EKeywordRomName, "output file for ROM image"}, |
|
80 {_K("romsize"), 1, 1, EKeywordRomSize, "size of ROM image"}, |
|
81 {_K("romlinearbase"), 1, 1, EKeywordRomLinearBase, "linear address of ROM image"}, |
|
82 {_K("romalign"), 1, 1, EKeywordRomAlign, "default alignment of files in ROM image"}, |
|
83 {_K("romchecksum"), 1, 1, EKeywordRomChecksum, "desired 32-bit checksum value for the whole ROM image"}, |
|
84 {_K("kerneldataaddress"), 1, 1, EKeywordKernelDataAddress, "?"}, |
|
85 {_K("kernelheapmin"), 1, 1, EKeywordKernelHeapMin, "Inital size of the kernel heap"}, |
|
86 {_K("kernelheapmax"), 1, 1, EKeywordKernelHeapMax, "Maximum size of the kernel heap"}, |
|
87 {_K("dataaddress"), 1, 1, EKeywordDataAddress, "?"}, |
|
88 {_K("defaultstackreserve"), 1, 1, EKeywordDefaultStackReserve, "?"}, |
|
89 {_K("version"), 1, 1, EKeywordVersion, "ROM version number"}, |
|
90 {_K("romnameodd"), 1, 1, EKeywordRomNameOdd, "output file containing odd halfwords of ROM image"}, |
|
91 {_K("romnameeven"), 1, 1, EKeywordRomNameEven, "output file containing even halfwords of ROM image"}, |
|
92 {_K("srecordfilename"), 1, 1, EKeywordSRecordFileName, "output file containing ROM image in S-Record format"}, |
|
93 {_K("srecordbase"), 1, 1, EKeywordSRecordBase, "Destination address for S-Record download"}, |
|
94 {_K("kerneltrace"), 1, -1, EKeywordKernelTrace, "Initial value for Kernel tracing flags"}, |
|
95 {_K("btrace"), 1, -1, EKeywordBTrace, "Initial value for fast-trace filter"}, |
|
96 {_K("btracemode"), 1, 1, EKeywordBTraceMode, "Initial value for fast-trace mode"}, |
|
97 {_K("btracebuffer"), 1, 1, EKeywordBTraceBuffer, "Initial size for fast-trace buffer"}, |
|
98 {_K("collapse"), 1, 3, EKeywordCollapse, "Additional ROM optimisations"}, |
|
99 {_K("time"), 1,-1, EKeywordTime, "ROM timestamp"}, |
|
100 {_K("section"), 2, 1, EKeywordSection, "Start of replaceable section in old-style 2 section ROM"}, |
|
101 {_K("extensionrom"),1+2, 1, EKeywordExtensionRom, "Start of definition of optional Extension ROM"}, |
|
102 {_K("kernelromname"),1, 1, EKeywordKernelRomName, "ROM image on which extension ROM is based"}, |
|
103 {_K("files"), 0, 0, EKeywordNone, 0}, // backwards compatibility, but now ignored |
|
104 {_K("rem"), 0, 0, EKeywordNone, "comment"}, |
|
105 {_K("stop"), 0, 0, EKeywordNone, "Terminates OBEY file prematurely"}, |
|
106 {_K("dlldatatop"), 1, 1, EKeywordDllDataTop, "Specify top of DLL data region"}, |
|
107 {_K("memmodel"), 1, -1, EKeywordMemModel, "Specifies the memory model to be used at runtime"}, |
|
108 {_K("nowrapper"), 1, 0, EKeywordNoWrapper, "Specifies that no ROM wrapper is required"}, |
|
109 {_K("epocwrapper"), 1, 0, EKeywordEpocWrapper, "Specifies that an EPOC ROM wrapper is required"}, |
|
110 {_K("coffwrapper"), 1, 0, EKeywordCoffWrapper, "Specifies that a COFF ROM wrapper is required"}, |
|
111 {_K("platsecenforcement"), 1, 1, EKeywordPlatSecEnforcement, "Set Platform Security enforment on/off"}, |
|
112 {_K("platsecdiagnostics"), 1, 1, EKeywordPlatSecDiagnostics, "Set Platform Security diagnostics on/off"}, |
|
113 {_K("platsecprocessisolation"), 1, 1, EKeywordPlatSecProcessIsolation, "Set Platform Security process isolation on/off"}, |
|
114 {_K("platsecenforcesysbin"), 1, 1, EKeywordPlatSecEnforceSysBin, "Set Platform Security process isolation on/off"}, |
|
115 {_K("platsecdisabledcaps"), 1, 1, EKeywordPlatSecDisabledCaps, "Disable the listed Platform Security capabilities"}, |
|
116 {_K("pagingpolicy"), 1, 1, EKeywordPagingPolicy, "Set the demand paging policy NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"}, |
|
117 {_K("codepagingpolicy"), 1, 1, EKeywordCodePagingPolicy, "Set the code paging policy NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"}, |
|
118 {_K("datapagingpolicy"), 1, 1, EKeywordDataPagingPolicy, "Set the data paging policy NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"}, |
|
119 {_K("pagingoverride"), 1, 1, EKeywordPagingOverride, "Overide the demand paging attributes for every file in ROM, NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"}, |
|
120 {_K("codepagingoverride"), 1, 1, EKeywordCodePagingOverride, "Overide the code paging attributes for every file in ROM, NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"}, |
|
121 {_K("datapagingoverride"), 1, 1, EKeywordDataPagingOverride, "Overide the data paging attributes for every file in ROM, NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"}, |
|
122 {_K("patchdata"), 2, 5, EKeywordPatchDllData, "Patch exported data"}, |
|
123 {_K("coreimage"), 1, 1, EKeywordCoreImage, "Core image to be used for extension directory structure"}, |
|
124 |
|
125 // things we don't normally report in the help information |
|
126 {_K("trace"), 1, 1, EKeywordTrace, "(ROMBUILD activity trace flags)"}, |
|
127 {_K("unicode"), 1, 0, EKeywordUnicode, "(UNICODE rom - the default)"}, |
|
128 {_K("ascii"), 1, 0, EKeywordAscii, "(Narrow rom)"}, |
|
129 {_K("languages"), 1,-1, EKeywordLanguages, "(List of supported languages (for test))"}, |
|
130 {_K("hardware"), 1, 1, EKeywordHardware, "(32-bit Hardware identifier (for test))"}, |
|
131 {_K("debugport"), 1, 1, EKeywordDebugPort, "(Debug trace sink (magic cookie passed to ASSP/variant))"}, |
|
132 {_K("compress"), 1, 0, EKeywordCompress, "Compress the ROM image"}, |
|
133 {_K("demandpagingconfig"), 1, -1, EKeywordDemandPagingConfig, "Demand Paging Config [minPages] [maxPages] [ageRatio]"}, |
|
134 {_K("pagedrom"), 1, 0, EKeywordPagedRom, "Build ROM immage suitable for demand paging"}, |
|
135 {_K("filecompressnone"), 2, -2, EKeywordExecutableCompressionMethodNone, "No compress the individual executable image."}, |
|
136 {_K("filecompressinflate"), 2, -2, EKeywordExecutableCompressionMethodInflate, "Inflate compression method for the individual executable image."}, |
|
137 {_K("filecompressbytepair"), 2, -2, EKeywordExecutableCompressionMethodBytePair, "Byte pair compresion method for the individual executable image."}, |
|
138 {_K("kernelconfig"), 1, 2, EKeywordKernelConfig, "Set an arbitrary bit of the kernel config flags to on/off)"}, |
|
139 {_K("maxunpagedsize"), 1, 1, EKeywordMaxUnpagedMemSize, "Maxinum unpaged size in ROM image. Default is no limited."}, |
|
140 {_K("hcrdata") , 2, 2,EKeywordHardwareConfigRepositoryData,"HCR image data"}, |
|
141 {0,0,0,0,EKeywordNone,""} |
|
142 |
|
143 }; |
|
144 |
|
145 void ObeyFileReader::KeywordHelp() // static |
|
146 { |
|
147 cout << "Obey file keywords:\n"; |
|
148 |
|
149 const ObeyFileKeyword* k=0; |
|
150 for (k=iKeywords; k->iKeyword!=0; k++) |
|
151 { |
|
152 if (k->iHelpText==0) |
|
153 continue; |
|
154 if (k->iHelpText[0]=='(' && !H.iVerbose) |
|
155 continue; // don't normally report things in (parentheses) |
|
156 |
|
157 char buf[32]; |
|
158 sprintf(buf, "%-20s", k->iKeyword); |
|
159 if (k->iKeywordLength) |
|
160 memcpy(buf+k->iKeywordLength,"[HWVD]",6); |
|
161 if (H.iVerbose) |
|
162 sprintf(buf+20,"%2d",k->iNumArgs); |
|
163 cout << " " << buf << " " << k->iHelpText << endl; |
|
164 } |
|
165 cout << endl; |
|
166 |
|
167 cout << "File attributes:\n"; |
|
168 |
|
169 const FileAttributeKeyword* f=0; |
|
170 for (f=iAttributeKeywords; f->iKeyword!=0; f++) |
|
171 { |
|
172 if (f->iHelpText==0) |
|
173 continue; |
|
174 if (f->iHelpText[0]=='(' && !H.iVerbose) |
|
175 continue; // don't normally report things in (parentheses) |
|
176 |
|
177 char buf[32]; |
|
178 sprintf(buf, "%-20s", f->iKeyword); |
|
179 if (H.iVerbose) |
|
180 sprintf(buf+20,"%2d",k->iNumArgs); |
|
181 cout << " " << buf << " " << f->iHelpText << endl; |
|
182 } |
|
183 cout << endl; |
|
184 } |
|
185 |
|
186 TInt NumberOfVariants=0; |
|
187 |
|
188 ObeyFileReader::ObeyFileReader(TText* aFileName): |
|
189 // |
|
190 // Constructor |
|
191 // |
|
192 iMark(0), iMarkLine(0), iCurrentMark(0), iCurrentLine(0), imaxLength(0),iSuffix(0),iLine(0) |
|
193 { |
|
194 |
|
195 iFileName = new TText[strlen((const char *)aFileName)+1]; |
|
196 strcpy((char *)iFileName,(const char *)aFileName); |
|
197 } |
|
198 |
|
199 ObeyFileReader::~ObeyFileReader() |
|
200 { |
|
201 if (iObeyFile) |
|
202 fclose(iObeyFile); |
|
203 iObeyFile=0; |
|
204 delete [] iFileName; |
|
205 delete [] iLine; |
|
206 } |
|
207 |
|
208 TBool ObeyFileReader::Open() |
|
209 // |
|
210 // Open the file & return a status |
|
211 // |
|
212 { |
|
213 |
|
214 iObeyFile = fopen((const char *)iFileName,"r"); |
|
215 if (!iObeyFile) |
|
216 { |
|
217 Print(EError,"Cannot open obey file %s\n",iFileName); |
|
218 return EFalse; |
|
219 } |
|
220 if (SetLineLengthBuffer() != KErrNone) |
|
221 { |
|
222 Print(EError,"Insufficent Memory to Continue."); |
|
223 return EFalse; |
|
224 } |
|
225 return ETrue; |
|
226 } |
|
227 |
|
228 TInt ObeyFileReader::SetLineLengthBuffer() |
|
229 // Get the Max Line length for the given obey file and allocate the buffer. |
|
230 { |
|
231 char ch = '\0'; |
|
232 TInt length = 0; |
|
233 |
|
234 Rewind(); |
|
235 while ((ch = (char)fgetc(iObeyFile)) != EOF) |
|
236 { |
|
237 length++; |
|
238 if (ch == '\n') |
|
239 { |
|
240 if (length > imaxLength) |
|
241 imaxLength = length; |
|
242 length = 0; |
|
243 } |
|
244 } |
|
245 |
|
246 if (length > imaxLength) |
|
247 imaxLength = length; |
|
248 |
|
249 if (0 == imaxLength) |
|
250 { |
|
251 Print(EError,"Empty obey file passed as input."); |
|
252 exit(-1); |
|
253 } |
|
254 else if (imaxLength < 2) |
|
255 { |
|
256 Print(EError,"Invalid obey file passed as input."); |
|
257 exit(-1); |
|
258 } |
|
259 |
|
260 Rewind(); |
|
261 iLine = new TText[imaxLength+1]; |
|
262 |
|
263 if(!iLine) |
|
264 return KErrNoMemory; |
|
265 |
|
266 return KErrNone; |
|
267 } |
|
268 |
|
269 void ObeyFileReader::Mark() |
|
270 { |
|
271 |
|
272 iMark = iCurrentMark; |
|
273 iMarkLine = iCurrentLine-1; |
|
274 } |
|
275 |
|
276 void ObeyFileReader::MarkNext() |
|
277 { |
|
278 |
|
279 iMark = ftell(iObeyFile); |
|
280 iMarkLine = iCurrentLine; |
|
281 } |
|
282 |
|
283 void ObeyFileReader::Rewind() |
|
284 { |
|
285 |
|
286 fseek(iObeyFile,iMark,SEEK_SET); |
|
287 iCurrentMark = iMark; |
|
288 iCurrentLine = iMarkLine; |
|
289 } |
|
290 |
|
291 void ObeyFileReader::CopyWord(TInt aIndex, TText*& aString) |
|
292 { |
|
293 aString = new TText[strlen((const char *)iWord[aIndex])+1]; |
|
294 strcpy((char *)aString, (const char *)iWord[aIndex]); |
|
295 } |
|
296 |
|
297 TInt ObeyFileReader::ReadAndParseLine() |
|
298 { |
|
299 if (feof(iObeyFile)) |
|
300 return KErrEof; |
|
301 iCurrentLine++; |
|
302 iCurrentMark = ftell(iObeyFile); |
|
303 iLine[0]='\0'; |
|
304 char * cp = fgets((char*)iLine,imaxLength+1,iObeyFile); (void)cp; |
|
305 iNumWords = Parse(); |
|
306 return KErrNone; |
|
307 } |
|
308 |
|
309 TInt ObeyFileReader::NextLine(TInt aPass, enum EKeyword& aKeyword) |
|
310 { |
|
311 |
|
312 NextLine: |
|
313 TInt err = ReadAndParseLine(); |
|
314 if (err == KErrEof) |
|
315 return KErrEof; |
|
316 if (iNumWords == 0 || stricmp((const char*)iWord[0], "rem")==0) |
|
317 goto NextLine; |
|
318 if (stricmp((const char*)iWord[0], "stop")==0) |
|
319 return KErrEof; |
|
320 |
|
321 const ObeyFileKeyword* k=0; |
|
322 for (k=iKeywords; k->iKeyword!=0; k++) |
|
323 { |
|
324 if (k->iKeywordLength == 0) |
|
325 { |
|
326 // Exact case-insensitive match on keyword |
|
327 if (stricmp((const char*)iWord[0], k->iKeyword) != 0) |
|
328 continue; |
|
329 iSuffix = 0; |
|
330 } |
|
331 else |
|
332 { |
|
333 // Prefix match |
|
334 if (strnicmp((const char*)iWord[0], k->iKeyword, k->iKeywordLength) != 0) |
|
335 continue; |
|
336 // Suffix must be empty, or a variant number in [] |
|
337 iSuffix = iWord[0]+k->iKeywordLength; |
|
338 if (*iSuffix != '\0' && *iSuffix != '[') |
|
339 continue; |
|
340 } |
|
341 // found a match |
|
342 if ((k->iPass & aPass) == 0) |
|
343 goto NextLine; |
|
344 if (k->iNumArgs>=0 && (1+k->iNumArgs != iNumWords)) |
|
345 { |
|
346 |
|
347 if(EKeywordHardwareConfigRepositoryData == k->iKeywordEnum){ // preq2131 specific |
|
348 Print(EWarning, "Incorrect number of arguments for keyword '%s' on line %d. Extra argument(s) are ignored.\n", |
|
349 iWord[0],iCurrentLine); |
|
350 aKeyword = k->iKeywordEnum; |
|
351 return KErrNone; |
|
352 }else{ |
|
353 Print(EError, "Incorrect number of arguments for keyword %s on line %d.\n", |
|
354 iWord[0], iCurrentLine); |
|
355 } |
|
356 goto NextLine; |
|
357 } |
|
358 if (k->iNumArgs<0 && (1-k->iNumArgs > iNumWords)) |
|
359 { |
|
360 Print(EError, "Too few arguments for keyword %s on line %d.\n", |
|
361 iWord[0], iCurrentLine); |
|
362 goto NextLine; |
|
363 } |
|
364 |
|
365 aKeyword = k->iKeywordEnum; |
|
366 return KErrNone; |
|
367 } |
|
368 if (aPass == 1) |
|
369 Print(EWarning, "Unknown keyword '%s'. Line %d ignored\n", iWord[0], iCurrentLine); |
|
370 goto NextLine; |
|
371 } |
|
372 |
|
373 inline TBool ObeyFileReader::IsGap(char ch) |
|
374 { |
|
375 return (ch==' ' || ch=='=' || ch=='\t'); |
|
376 } |
|
377 |
|
378 TInt ObeyFileReader::Parse() |
|
379 // |
|
380 // splits a line into words, and returns the number of words found |
|
381 // |
|
382 |
|
383 { |
|
384 |
|
385 TUint i; |
|
386 TText *letter=iLine; |
|
387 TText *end=iLine+strlen((char *)iLine); |
|
388 for (i=0; i<KNumWords; i++) |
|
389 iWord[i]=end; |
|
390 |
|
391 enum TState {EInWord, EInQuotedWord, EInGap}; |
|
392 TState state=EInGap; |
|
393 |
|
394 i=0; |
|
395 while (i<KNumWords && letter<end) |
|
396 { |
|
397 char ch=*letter; |
|
398 if (ch==0) |
|
399 break; |
|
400 if (ch=='\n') |
|
401 { |
|
402 *letter='\0'; // remove trailing newline left by fgets |
|
403 break; |
|
404 } |
|
405 switch (state) |
|
406 { |
|
407 case EInGap: |
|
408 if (ch=='\"') |
|
409 { |
|
410 if (letter[1]!=0 && letter[1]!='\"') |
|
411 iWord[i++]=letter+1; |
|
412 state=EInQuotedWord; |
|
413 } |
|
414 else if (!IsGap(ch)) |
|
415 { |
|
416 iWord[i++]=letter; |
|
417 state=EInWord; |
|
418 } |
|
419 else |
|
420 *letter=0; |
|
421 break; |
|
422 case EInWord: |
|
423 if (ch=='\"') |
|
424 { |
|
425 *letter=0; |
|
426 if (letter[1]!=0 && letter[1]!='\"') |
|
427 iWord[i++]=letter+1; |
|
428 state=EInQuotedWord; |
|
429 } |
|
430 else if (IsGap(ch)) |
|
431 { |
|
432 *letter=0; |
|
433 state=EInGap; |
|
434 } |
|
435 break; |
|
436 case EInQuotedWord: |
|
437 if (ch=='\"') |
|
438 { |
|
439 *letter=0; |
|
440 state=EInGap; |
|
441 } |
|
442 break; |
|
443 } |
|
444 letter++; |
|
445 } |
|
446 return i; |
|
447 } |
|
448 |
|
449 void ObeyFileReader::ProcessLanguages(TInt64& aLanguageMask) |
|
450 { |
|
451 TInt i=1; |
|
452 while (i<iNumWords) |
|
453 { |
|
454 char *aStr=(char *)iWord[i]; |
|
455 TLanguage l=ELangTest; |
|
456 if (stricmp(aStr, "test")==0) |
|
457 l=ELangTest; |
|
458 else if (stricmp(aStr, "english")==0) |
|
459 l=ELangEnglish; |
|
460 else if (stricmp(aStr, "french")==0) |
|
461 l=ELangFrench; |
|
462 else if (stricmp(aStr, "german")==0) |
|
463 l=ELangGerman; |
|
464 else if (stricmp(aStr, "spanish")==0) |
|
465 l=ELangSpanish; |
|
466 else if (stricmp(aStr, "italian")==0) |
|
467 l=ELangItalian; |
|
468 else if (stricmp(aStr, "swedish")==0) |
|
469 l=ELangSwedish; |
|
470 else if (stricmp(aStr, "danish")==0) |
|
471 l=ELangDanish; |
|
472 else if (stricmp(aStr, "norwegian")==0) |
|
473 l=ELangNorwegian; |
|
474 else if (stricmp(aStr, "finnish")==0) |
|
475 l=ELangFinnish; |
|
476 else if (stricmp(aStr, "american")==0) |
|
477 l=ELangAmerican; |
|
478 else if (stricmp(aStr, "SwissFrench")==0) |
|
479 l=ELangSwissFrench; |
|
480 else if (stricmp(aStr, "SwissGerman")==0) |
|
481 l=ELangSwissGerman; |
|
482 else if (stricmp(aStr, "Portuguese")==0) |
|
483 l=ELangPortuguese; |
|
484 else if (stricmp(aStr, "Turkish")==0) |
|
485 l=ELangTurkish; |
|
486 else if (stricmp(aStr, "Icelandic")==0) |
|
487 l=ELangIcelandic; |
|
488 else if (stricmp(aStr, "Russian")==0) |
|
489 l=ELangRussian; |
|
490 else if (stricmp(aStr, "Hungarian")==0) |
|
491 l=ELangHungarian; |
|
492 else if (stricmp(aStr, "Dutch")==0) |
|
493 l=ELangDutch; |
|
494 else if (stricmp(aStr, "BelgianFlemish")==0) |
|
495 l=ELangBelgianFlemish; |
|
496 else if (stricmp(aStr, "Australian")==0) |
|
497 l=ELangAustralian; |
|
498 else if (stricmp(aStr, "BelgianFrench")==0) |
|
499 l=ELangBelgianFrench; |
|
500 else |
|
501 { |
|
502 Print(EError, "Unknown language '%s' on line %d", iWord[i], iCurrentLine); |
|
503 exit(666); |
|
504 } |
|
505 aLanguageMask = aLanguageMask+(1<<(TInt)l); |
|
506 i++; |
|
507 } |
|
508 } |
|
509 |
|
510 void ObeyFileReader::ProcessTime(TInt64& aTime) |
|
511 // |
|
512 // Process the timestamp |
|
513 // |
|
514 { |
|
515 char timebuf[256]; |
|
516 if (iNumWords>2) |
|
517 sprintf(timebuf, "%s_%s", iWord[1], iWord[2]); |
|
518 else |
|
519 strcpy(timebuf, (char*)iWord[1]); |
|
520 |
|
521 TInt r=StringToTime(aTime, timebuf); |
|
522 if (r==KErrGeneral) |
|
523 { |
|
524 Print(EError, "incorrect format for time keyword on line %d\n", iCurrentLine); |
|
525 exit(0x670); |
|
526 } |
|
527 if (r==KErrArgument) |
|
528 { |
|
529 Print(EError, "Time out of range on line %d\n", iCurrentLine); |
|
530 exit(0x670); |
|
531 } |
|
532 } |
|
533 |
|
534 TInt64 ObeyFileReader::iTimeNow=0; |
|
535 void ObeyFileReader::TimeNow(TInt64& aTime) |
|
536 { |
|
537 if (iTimeNow==0) |
|
538 { |
|
539 TInt sysTime=time(0); // seconds since midnight Jan 1st, 1970 |
|
540 sysTime-=(30*365*24*60*60+7*24*60*60); // seconds since midnight Jan 1st, 2000 |
|
541 TInt64 daysTo2000AD=730497; |
|
542 TInt64 t=daysTo2000AD*24*3600+sysTime; // seconds since 0000 |
|
543 t=t+3600; // BST (?) |
|
544 iTimeNow=t*1000000; // milliseconds |
|
545 } |
|
546 aTime=iTimeNow; |
|
547 } |
|
548 |
|
549 TInt ObeyFileReader::ProcessAlign(TInt &aAlign) |
|
550 // |
|
551 // Process the align keyword |
|
552 // |
|
553 { |
|
554 |
|
555 TInt align; |
|
556 if (Val(align, Word(1))) |
|
557 return Print(EError, "Number required for 'align' keyword on line %d\n", iCurrentLine); |
|
558 aAlign=align; |
|
559 TInt i; |
|
560 for (i=4; i!=0x40000000; i<<=1) |
|
561 if (i==aAlign) |
|
562 return KErrNone; |
|
563 return Print(EError, "Alignment must be a power of 2 and bigger than 4. Line %d\n", iCurrentLine); |
|
564 } |
|
565 |
|
566 |
|
567 const FileAttributeKeyword ObeyFileReader::iAttributeKeywords[] = |
|
568 { |
|
569 {"stackreserve",6 ,1,1,EAttributeStackReserve, "?"}, |
|
570 {"stack",3 ,1,1,EAttributeStack, "?"}, |
|
571 {"reloc",3 ,1,1,EAttributeReloc, "?"}, |
|
572 {"code-align",10 ,1,1,EAttributeCodeAlign, "Additional code alignment constraint"}, |
|
573 {"data-align",10 ,1,1,EAttributeDataAlign, "Additional data alignment constraint"}, |
|
574 {"fixed",3 ,1,0,EAttributeFixed, "Relocate to a fixed address space"}, |
|
575 {"attrib",3 ,0,1,EAttributeAtt, "File attributes in ROM file system"}, |
|
576 {"priority",3 ,1,1,EAttributePriority, "Override process priority"}, |
|
577 {"patched",5 ,1,0,EAttributePatched, "File to be replaced in second section"}, |
|
578 {_K("uid1") ,1,1,EAttributeUid1, "Override first UID"}, |
|
579 {_K("uid2") ,1,1,EAttributeUid2, "Override second UID"}, |
|
580 {_K("uid3") ,1,1,EAttributeUid3, "Override third UID"}, |
|
581 {_K("heapmin") ,1,1,EAttributeHeapMin, "Override initial heap size"}, |
|
582 {_K("heapmax") ,1,1,EAttributeHeapMax, "Override maximum heap size"}, |
|
583 {_K("keepIAT") ,1,0,EAttributeKeepIAT, "(Retain old-style Import Address Table)"}, |
|
584 {_K("hide") ,0,0,EAttributeHidden, "Don't record file in the ROM file system"}, |
|
585 {_K("area") ,1,1,EAttributeArea, "Relocate file to given area"}, |
|
586 {_K("process") ,1,1,EAttributeProcessSpecific, "Indicate which process a DLL will attach to"}, |
|
587 {_K("capability") ,1,1,EAttributeCapability, "Override capabilities"}, |
|
588 {_K("preferred") ,1,0,EAttributePreferred, "Prefer this over other minor versions of same major version"}, |
|
589 {_K("unpaged") ,1,0,EAttributeUnpaged, "Don't use demand paging for this file"}, |
|
590 {_K("paged") ,1,0,EAttributePaged, "Use demand paging for this file"}, |
|
591 {_K("unpagedcode") ,1,0,EAttributeUnpagedCode, "Don't use code paging for this file"}, |
|
592 {_K("pagedcode") ,1,0,EAttributePagedCode, "Use code paging for this file"}, |
|
593 {_K("unpageddata") ,1,0,EAttributeUnpagedData, "Don't use data paging for this file"}, |
|
594 {_K("pageddata") ,1,0,EAttributePagedData, "Use data paging for this file"}, |
|
595 {0,0,0,0,EAttributeStackReserve,0} |
|
596 }; |
|
597 |
|
598 TInt ObeyFileReader::NextAttribute(TInt& aIndex, TInt aHasFile, enum EFileAttribute& aKeyword, TText*& aArg) |
|
599 { |
|
600 NextAttribute: |
|
601 if (aIndex >= iNumWords) |
|
602 return KErrEof; |
|
603 TText* word=iWord[aIndex++]; |
|
604 const FileAttributeKeyword* k; |
|
605 for (k=iAttributeKeywords; k->iKeyword!=0; k++) |
|
606 { |
|
607 if (k->iKeywordLength == 0) |
|
608 { |
|
609 // Exact match on keyword |
|
610 if (stricmp((const char*)word, k->iKeyword) != 0) |
|
611 continue; |
|
612 } |
|
613 else |
|
614 { |
|
615 // Prefix match |
|
616 if (strnicmp((const char*)word, k->iKeyword, k->iKeywordLength) != 0) |
|
617 continue; |
|
618 } |
|
619 // found a match |
|
620 if (k->iNumArgs>0) |
|
621 { |
|
622 TInt argIndex = aIndex; |
|
623 aIndex += k->iNumArgs; // interface only really supports 1 argument |
|
624 if (aIndex>iNumWords) |
|
625 { |
|
626 Print(EError, "Missing argument for attribute %s on line %d\n", word, iCurrentLine); |
|
627 return KErrArgument; |
|
628 } |
|
629 aArg=iWord[argIndex]; |
|
630 } |
|
631 if (k->iIsFileAttribute && !aHasFile) |
|
632 { |
|
633 Print(EError, "File attribute %s applied to non-file on line %d\n", word, iCurrentLine); |
|
634 return KErrNotSupported; |
|
635 } |
|
636 aKeyword=k->iAttributeEnum; |
|
637 return KErrNone; |
|
638 } |
|
639 Print(EWarning, "Unknown attribute '%s' skipped on line %d\n", word, iCurrentLine); |
|
640 goto NextAttribute; |
|
641 } |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 CObeyFile::CObeyFile(ObeyFileReader& aReader): |
|
647 iRomFileName(0),iRomOddFileName(0),iRomEvenFileName(0), |
|
648 iSRecordFileName(0),iBootFileName(0),iKernelRomName(0), |
|
649 iRomSize(0),iRomLinearBase(0xffffffff),iRomAlign(0), |
|
650 iKernDataRunAddress(0),iDataRunAddress(0),iKernelLimit(0xffffffff), |
|
651 iKernHeapMin(0),iKernHeapMax(0),iSectionStart(0),iSectionPosition(-1), |
|
652 iVersion(0,0,0),iCheckSum(0),iNumberOfPeFiles(0),iNumberOfDataFiles(0), |
|
653 iNumberOfPrimaries(0),iNumberOfExtensions(0),iNumberOfVariants(0), |
|
654 iNumberOfDevices(0),iNumberOfHCRDataFiles (0), |
|
655 //iAllVariantsMask[256], |
|
656 iPrimaries(0),iVariants(0),iExtensions(0),iDevices(0), |
|
657 iLanguage(0),iHardware(0),iTime(0),iMemModel(E_MM_Moving),iPageSize(0x1000), |
|
658 iChunkSize(0x100000),iVirtualAllocSize(0x1000),iKernelModel(ESingleKernel), |
|
659 iCollapseMode(ECollapseNone),iSRecordBase(0),iCurrentSectionNumber(0), |
|
660 iDefaultStackReserve(0),//iTraceMask[KNumTraceMaskWords];iInitialBTraceFilter[8]; |
|
661 iInitialBTraceBuffer(0),iInitialBTraceMode(0),iDebugPort(0), |
|
662 iDebugPortParsed(EFalse),iRootDirectory(0),iDllDataTop(0x40000000), |
|
663 iKernelConfigFlags(0),iPagingPolicyParsed(EFalse),iCodePagingPolicyParsed(EFalse), |
|
664 iDataPagingPolicyParsed(EFalse),iPagingOverrideParsed(EFalse), |
|
665 iCodePagingOverrideParsed(EFalse),iDataPagingOverrideParsed(EFalse), |
|
666 /*iPlatSecDisabledCaps(), */iPlatSecDisabledCapsParsed(EFalse),iMaxUnpagedMemSize(0), |
|
667 iReader(aReader),iMissingFiles(0),iLastExecutable(0),iAreaSet(),iFirstFile(0), |
|
668 iCurrentFile(0),iLastVariantFile(0),iFirstDllDataEntry(0), |
|
669 iUpdatedMaxUnpagedMemSize(EFalse),iPatchData(new CPatchDataProcessor) |
|
670 { |
|
671 |
|
672 TUint i; |
|
673 for (i=0; i<256; i++) |
|
674 iAllVariantsMask[i]=0; |
|
675 for (i=0; i<(TUint)KNumTraceMaskWords; i++) |
|
676 iTraceMask[i]=0; |
|
677 for (i=0; i<sizeof(iInitialBTraceFilter)/sizeof(TUint32); i++) |
|
678 iInitialBTraceFilter[i]=0; |
|
679 memset(&iPlatSecDisabledCaps,0,sizeof(SCapabilitySet)); |
|
680 iNextFilePtrPtr = &iFirstFile; |
|
681 } |
|
682 |
|
683 CObeyFile::~CObeyFile() |
|
684 // |
|
685 // Destructor |
|
686 // |
|
687 { |
|
688 |
|
689 Release(); |
|
690 delete [] iRomFileName; |
|
691 if (iRootDirectory) |
|
692 iRootDirectory->Destroy(); |
|
693 delete iPatchData; |
|
694 } |
|
695 |
|
696 void CObeyFile::Release() |
|
697 // |
|
698 // Free resources not needed after building a ROM |
|
699 // |
|
700 { |
|
701 iAreaSet.ReleaseAllAreas(); |
|
702 |
|
703 delete [] iBootFileName; |
|
704 delete [] iPrimaries; |
|
705 delete [] iVariants; |
|
706 delete [] iExtensions; |
|
707 delete [] iDevices; |
|
708 |
|
709 iBootFileName = 0; |
|
710 iPrimaries = 0; |
|
711 iVariants = 0; |
|
712 iExtensions = 0; |
|
713 iDevices = 0; |
|
714 iFirstFile = 0; |
|
715 iNextFilePtrPtr = &iFirstFile; |
|
716 } |
|
717 |
|
718 TRomBuilderEntry *CObeyFile::FirstFile() |
|
719 { |
|
720 iCurrentFile = iFirstFile; |
|
721 return iCurrentFile; |
|
722 } |
|
723 |
|
724 TRomBuilderEntry *CObeyFile::NextFile() |
|
725 { |
|
726 iCurrentFile = iCurrentFile ? iCurrentFile->iNext : 0; |
|
727 return iCurrentFile; |
|
728 } |
|
729 |
|
730 /* |
|
731 *Set first link in patchdata linked list |
|
732 **/ |
|
733 void CObeyFile::SetFirstDllDataEntry(DllDataEntry* aDllDataEntry) |
|
734 { |
|
735 iFirstDllDataEntry = aDllDataEntry; |
|
736 } |
|
737 |
|
738 /* |
|
739 *Get first link in patchdata linked list |
|
740 **/ |
|
741 DllDataEntry* CObeyFile::GetFirstDllDataEntry() const |
|
742 { |
|
743 return iFirstDllDataEntry; |
|
744 } |
|
745 |
|
746 TInt CObeyFile::ProcessKernelRom() |
|
747 { |
|
748 // |
|
749 // First pass through the obey file to set up key variables |
|
750 // |
|
751 |
|
752 iReader.Rewind(); |
|
753 |
|
754 TInt count=0; |
|
755 enum EKeyword keyword; |
|
756 while (iReader.NextLine(1,keyword) != KErrEof) |
|
757 { |
|
758 if (keyword == EKeywordExtensionRom) |
|
759 { |
|
760 if (count==0) |
|
761 return KErrNotFound; // no kernel ROM, just extension ROMs. |
|
762 break; |
|
763 } |
|
764 |
|
765 count++; |
|
766 if (! ProcessKeyword(keyword)) |
|
767 return KErrGeneral; |
|
768 } |
|
769 |
|
770 if (!GotKeyVariables()) |
|
771 return KErrGeneral; |
|
772 |
|
773 if (! CreateDefaultArea()) |
|
774 return KErrGeneral; |
|
775 |
|
776 // |
|
777 // second pass to process the file specifications in the obey file building |
|
778 // up the TRomNode directory structure and the TRomBuilderEntry list |
|
779 // |
|
780 iReader.Rewind(); |
|
781 |
|
782 iRootDirectory = new TRomNode((TText*)""); |
|
783 iLastExecutable = iRootDirectory; |
|
784 |
|
785 TInt align=0; |
|
786 while (iReader.NextLine(2,keyword)!=KErrEof) |
|
787 { |
|
788 if (keyword == EKeywordExtensionRom) |
|
789 break; |
|
790 |
|
791 switch (keyword) |
|
792 { |
|
793 case EKeywordSection: |
|
794 if (ParseSection()!=KErrNone) |
|
795 return KErrGeneral; |
|
796 break; |
|
797 case EKeywordAlign: |
|
798 if (iReader.ProcessAlign(align)!=KErrNone) |
|
799 return KErrGeneral; |
|
800 break; |
|
801 case EKeywordHide: |
|
802 case EKeywordAlias: |
|
803 case EKeywordRename: |
|
804 if (!ProcessRenaming(keyword)) |
|
805 return KErrGeneral; |
|
806 break; |
|
807 case EKeywordPatchDllData: |
|
808 { |
|
809 // Collect patchdata statements to process at the end |
|
810 StringVector patchDataTokens; |
|
811 SplitPatchDataStatement(patchDataTokens); |
|
812 iPatchData->AddPatchDataStatement(patchDataTokens); |
|
813 break; |
|
814 } |
|
815 |
|
816 default: |
|
817 if (!ProcessFile(align, keyword)) |
|
818 return KErrGeneral; |
|
819 align=0; |
|
820 break; |
|
821 } |
|
822 } |
|
823 |
|
824 if( !ParsePatchDllData()) |
|
825 return KErrGeneral; |
|
826 |
|
827 iReader.Mark(); // ready for processing the extension rom(s) |
|
828 |
|
829 if (iMissingFiles!=0) |
|
830 return KErrGeneral; |
|
831 if (iNumberOfDataFiles+iNumberOfPeFiles==0) |
|
832 { |
|
833 Print(EError, "No files specified.\n"); |
|
834 return KErrGeneral; |
|
835 } |
|
836 if (!CheckHardwareVariants()) |
|
837 return KErrGeneral; |
|
838 |
|
839 return KErrNone; |
|
840 } |
|
841 |
|
842 |
|
843 TInt CObeyFile::ParseSection() |
|
844 // |
|
845 // Process the section keyword |
|
846 // |
|
847 { |
|
848 TInt currentLine = iReader.CurrentLine(); |
|
849 if (iSectionPosition!=-1) |
|
850 return Print(EError, "Rom already sectioned. Line %d\n", currentLine); |
|
851 TInt offset; |
|
852 if (Val(offset, iReader.Word(1))) |
|
853 return Print(EError, "Number required for 'section' keyword on line %d\n", currentLine); |
|
854 iSectionStart=offset+iRomLinearBase; |
|
855 if (offset>=iRomSize) |
|
856 return Print(EError, "Sectioned beyond end of Rom. Line %d\n", currentLine); |
|
857 if (offset&0x0fff) |
|
858 return Print(EError, "Section must be on a 4K boundry. Line %d\n", currentLine); |
|
859 iSectionPosition=iNumberOfDataFiles+iNumberOfPeFiles; |
|
860 iCurrentSectionNumber++; |
|
861 return KErrNone; |
|
862 } |
|
863 |
|
864 TInt CObeyFile::ParseFileAttributes(TRomNode *aNode, TRomBuilderEntry* aFile) |
|
865 // |
|
866 // Process any inline keywords |
|
867 // |
|
868 { |
|
869 TInt currentLine = iReader.CurrentLine(); |
|
870 enum EFileAttribute attribute; |
|
871 TInt r=KErrNone; |
|
872 TInt index=3; |
|
873 TText* arg=0; |
|
874 |
|
875 while(r==KErrNone) |
|
876 { |
|
877 r=iReader.NextAttribute(index,(aFile!=0),attribute,arg); |
|
878 if (r!=KErrNone) |
|
879 break; |
|
880 switch(attribute) |
|
881 { |
|
882 case EAttributeStackReserve: |
|
883 r=aFile->SetStackReserve(arg); |
|
884 break; |
|
885 case EAttributeStack: |
|
886 r=aFile->SetStackSize(arg); |
|
887 break; |
|
888 case EAttributeReloc: |
|
889 r=aFile->SetRelocationAddress(arg); |
|
890 break; |
|
891 case EAttributeCodeAlign: |
|
892 r=aFile->SetCodeAlignment(arg); |
|
893 break; |
|
894 case EAttributeDataAlign: |
|
895 r=aFile->SetDataAlignment(arg); |
|
896 break; |
|
897 case EAttributeFixed: |
|
898 r=aFile->SetRelocationAddress(NULL); |
|
899 break; |
|
900 case EAttributeAtt: |
|
901 r=aNode->SetAtt(arg); |
|
902 break; |
|
903 case EAttributeUid1: |
|
904 r=aFile->SetUid1(arg); |
|
905 break; |
|
906 case EAttributeUid2: |
|
907 r=aFile->SetUid2(arg); |
|
908 break; |
|
909 case EAttributeUid3: |
|
910 r=aFile->SetUid3(arg); |
|
911 break; |
|
912 case EAttributeHeapMin: |
|
913 r=aFile->SetHeapSizeMin(arg); |
|
914 break; |
|
915 case EAttributeHeapMax: |
|
916 r=aFile->SetHeapSizeMax(arg); |
|
917 break; |
|
918 case EAttributePriority: |
|
919 r=aFile->SetPriority(arg); |
|
920 break; |
|
921 case EAttributePatched: |
|
922 if (iSectionPosition!=-1) |
|
923 return Print(EError, "Not sensible to patch files in top section. Line %d.\n", currentLine); |
|
924 aFile->iPatched=ETrue; |
|
925 break; |
|
926 case EAttributeKeepIAT: |
|
927 aFile->iOverrideFlags |= KOverrideKeepIAT; |
|
928 break; |
|
929 case EAttributeHidden: |
|
930 if (aFile->Extension()) |
|
931 return Print(EError, "Cannot hide Extension. Line %d.\n", currentLine); |
|
932 aNode->iHidden=ETrue; |
|
933 break; |
|
934 case EAttributeArea: |
|
935 { |
|
936 TRACE(TAREA, Print(EScreen, "Area Attribute: %s\n", arg)); |
|
937 const Area* area = aFile->iArea; |
|
938 if (! ParseAreaAttribute(arg, currentLine, area)) |
|
939 return KErrGeneral; |
|
940 } |
|
941 break; |
|
942 case EAttributeProcessSpecific: |
|
943 if (!IsValidFilePath(arg)) |
|
944 { |
|
945 Print(EError, "Invalid file path for process attribute on line %d\n", currentLine); |
|
946 return KErrGeneral; |
|
947 } |
|
948 r=aFile->SetAttachProcess(arg); |
|
949 break; |
|
950 case EAttributeCapability: |
|
951 r=aFile->SetCapability(arg); |
|
952 break; |
|
953 case EAttributePreferred: |
|
954 aFile->iPreferred = ETrue; |
|
955 break; |
|
956 case EAttributeUnpaged: |
|
957 aFile->iOverrideFlags |= KOverrideCodeUnpaged | KOverrideDataUnpaged; |
|
958 aFile->iOverrideFlags &= ~(KOverrideCodePaged | KOverrideDataPaged); |
|
959 break; |
|
960 case EAttributePaged: |
|
961 aFile->iOverrideFlags |= KOverrideCodePaged | KOverrideDataPaged; |
|
962 aFile->iOverrideFlags &= ~(KOverrideCodeUnpaged | KOverrideDataUnpaged); |
|
963 break; |
|
964 case EAttributeUnpagedCode: |
|
965 aFile->iOverrideFlags |= KOverrideCodeUnpaged; |
|
966 aFile->iOverrideFlags &= ~KOverrideCodePaged; |
|
967 break; |
|
968 case EAttributePagedCode: |
|
969 aFile->iOverrideFlags |= KOverrideCodePaged; |
|
970 aFile->iOverrideFlags &= ~KOverrideCodeUnpaged; |
|
971 break; |
|
972 case EAttributeUnpagedData: |
|
973 aFile->iOverrideFlags |= KOverrideDataUnpaged; |
|
974 aFile->iOverrideFlags &= ~KOverrideDataPaged; |
|
975 break; |
|
976 case EAttributePagedData: |
|
977 aFile->iOverrideFlags |= KOverrideDataPaged; |
|
978 aFile->iOverrideFlags &= ~KOverrideDataUnpaged; |
|
979 break; |
|
980 |
|
981 default: |
|
982 return Print(EError, "Unrecognised keyword in file attributes on line %d.\n",currentLine); |
|
983 } |
|
984 } |
|
985 |
|
986 // aFile may be null if processing an extension ROM |
|
987 if (aFile && aFile->iPatched && ! aFile->iArea->IsDefault()) |
|
988 { |
|
989 return Print(EError, "Relocation to area at line %d forbidden because file is patched\n", currentLine); |
|
990 } |
|
991 |
|
992 if (r==KErrEof) |
|
993 return KErrNone; |
|
994 return r; |
|
995 } |
|
996 |
|
997 TUint32 CObeyFile::ParseVariant() |
|
998 { |
|
999 char* left=iReader.Suffix(); |
|
1000 if (left == 0 || *left=='\0') |
|
1001 return KVariantIndependent; |
|
1002 const char* right=left+strlen(left)-1; |
|
1003 if (*left=='[' && *right==']') |
|
1004 { |
|
1005 TUint variant; |
|
1006 #ifdef __TOOLS2__ |
|
1007 string s(left+1); |
|
1008 string s2=s.substr(0,right-(left+1)); |
|
1009 istringstream val(s2,ios::in); |
|
1010 #else |
|
1011 istrstream val(left+1, right-(left+1)); |
|
1012 #endif |
|
1013 |
|
1014 |
|
1015 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
1016 val >> setbase(0); |
|
1017 #endif //__MSVCDOTNET__ |
|
1018 |
|
1019 val >> variant; |
|
1020 if (val.eof() && !val.fail()) |
|
1021 return variant; |
|
1022 } |
|
1023 //#endif |
|
1024 Print(EError,"Syntax error in variant, %s keyword on line %d\n", iReader.Word(0), iReader.CurrentLine()); |
|
1025 return KVariantIndependent; |
|
1026 } |
|
1027 |
|
1028 TBool CObeyFile::ProcessFile(TInt aAlign, enum EKeyword aKeyword) |
|
1029 // |
|
1030 // Process a parsed line to set up one or more new TRomBuilder entry objects. |
|
1031 // iWord[0] = the keyword (file, primary or secondary) |
|
1032 // iWord[1] = the PC pathname |
|
1033 // iWord[2] = the EPOC pathname |
|
1034 // iWord[3] = start of the file attributes |
|
1035 // |
|
1036 { |
|
1037 |
|
1038 TUint imageFlags = 0; |
|
1039 TUint overrides = 0; |
|
1040 TBool isPeFile = ETrue; |
|
1041 TBool isResource = EFalse; |
|
1042 TBool isNonXIP = EFalse; |
|
1043 TUint compression = 0; |
|
1044 TBool callEntryPoint = EFalse; |
|
1045 TUint hardwareVariant=KVariantIndependent; |
|
1046 TBool mustBeInSysBin = EFalse; |
|
1047 TBool tryForSysBin = EFalse; |
|
1048 TBool warnFlag = EFalse; |
|
1049 |
|
1050 // do some validation of the keyword |
|
1051 TInt currentLine = iReader.CurrentLine(); |
|
1052 |
|
1053 switch (aKeyword) |
|
1054 { |
|
1055 case EKeywordPrimary: |
|
1056 imageFlags |= KRomImageFlagPrimary; |
|
1057 overrides |= KOverrideCodeUnpaged | KOverrideDataUnpaged; |
|
1058 mustBeInSysBin = gPlatSecEnforceSysBin; |
|
1059 warnFlag = gEnableStdPathWarning; |
|
1060 hardwareVariant=ParseVariant(); |
|
1061 if (iKernelModel==ESingleKernel && !THardwareVariant(hardwareVariant).IsIndependent()) |
|
1062 { |
|
1063 Print(EError,"Kernel must be independent in single kernel ROMs\n"); |
|
1064 } |
|
1065 break; |
|
1066 |
|
1067 case EKeywordSecondary: |
|
1068 imageFlags |= KRomImageFlagSecondary; |
|
1069 mustBeInSysBin = gPlatSecEnforceSysBin; |
|
1070 warnFlag = gEnableStdPathWarning; |
|
1071 hardwareVariant=ParseVariant(); |
|
1072 break; |
|
1073 |
|
1074 case EKeywordVariant: |
|
1075 imageFlags |= KRomImageFlagVariant; |
|
1076 overrides |= KOverrideCodeUnpaged | KOverrideDataUnpaged; |
|
1077 mustBeInSysBin = gPlatSecEnforceSysBin; |
|
1078 warnFlag = gEnableStdPathWarning; |
|
1079 hardwareVariant=ParseVariant(); |
|
1080 break; |
|
1081 |
|
1082 case EKeywordExtension: |
|
1083 imageFlags |= KRomImageFlagExtension; |
|
1084 overrides |= KOverrideCodeUnpaged | KOverrideDataUnpaged; |
|
1085 mustBeInSysBin = gPlatSecEnforceSysBin; |
|
1086 warnFlag = gEnableStdPathWarning; |
|
1087 hardwareVariant=ParseVariant(); |
|
1088 break; |
|
1089 |
|
1090 case EKeywordDevice: |
|
1091 imageFlags |= KRomImageFlagDevice; |
|
1092 overrides |= KOverrideCodeUnpaged | KOverrideDataUnpaged; |
|
1093 mustBeInSysBin = gPlatSecEnforceSysBin; |
|
1094 warnFlag = gEnableStdPathWarning; |
|
1095 hardwareVariant=ParseVariant(); |
|
1096 break; |
|
1097 |
|
1098 case EKeywordExecutableCompressionMethodBytePair: |
|
1099 compression=KUidCompressionBytePair; |
|
1100 |
|
1101 case EKeywordExecutableCompressionMethodInflate: |
|
1102 case EKeywordFileCompress: |
|
1103 compression = compression ? compression : KUidCompressionDeflate; |
|
1104 |
|
1105 case EKeywordExecutableCompressionMethodNone: |
|
1106 case EKeywordFileUncompress: |
|
1107 isNonXIP = ETrue; |
|
1108 case EKeywordData: |
|
1109 iNumberOfDataFiles++; |
|
1110 isPeFile = EFalse; |
|
1111 isResource = ETrue; |
|
1112 hardwareVariant=ParseVariant(); |
|
1113 tryForSysBin = gPlatSecEnforceSysBin; |
|
1114 break; |
|
1115 |
|
1116 case EKeywordHardwareConfigRepositoryData: |
|
1117 if(iNumberOfHCRDataFiles){ |
|
1118 Print(EError,"Multiple keywords '%s' on line %d.\n",iReader.Word(0),currentLine); |
|
1119 return EFalse ; |
|
1120 } |
|
1121 compression = EFalse ; |
|
1122 overrides |= KOverrideCodeUnpaged | KOverrideDataUnpaged | KOverrideHCRData; |
|
1123 warnFlag = gEnableStdPathWarning; |
|
1124 iNumberOfHCRDataFiles ++ ; |
|
1125 isPeFile = EFalse; |
|
1126 break; |
|
1127 |
|
1128 case EKeywordDll: |
|
1129 callEntryPoint = ETrue; |
|
1130 // and fall through to handling for "file" |
|
1131 |
|
1132 case EKeywordFile: |
|
1133 { |
|
1134 |
|
1135 char* nname = NormaliseFileName(iReader.Word(1)); |
|
1136 strupr(nname); |
|
1137 |
|
1138 if( gCompressionMethod == 0 || NULL != strstr(nname, ".DLL") || callEntryPoint ) |
|
1139 { |
|
1140 mustBeInSysBin = gPlatSecEnforceSysBin; |
|
1141 warnFlag = gEnableStdPathWarning; |
|
1142 hardwareVariant=ParseVariant(); |
|
1143 } |
|
1144 else |
|
1145 { |
|
1146 compression = gCompressionMethod; |
|
1147 hardwareVariant=ParseVariant(); |
|
1148 tryForSysBin = gPlatSecEnforceSysBin; |
|
1149 } |
|
1150 } |
|
1151 break; |
|
1152 |
|
1153 default: |
|
1154 Print(EError,"Unexpected keyword '%s' on line %d.\n",iReader.Word(0),currentLine); |
|
1155 return EFalse; |
|
1156 } |
|
1157 |
|
1158 if (isPeFile) |
|
1159 iNumberOfPeFiles++; |
|
1160 |
|
1161 // check the PC file exists |
|
1162 char* nname = NormaliseFileName(iReader.Word(1)); |
|
1163 |
|
1164 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
1165 ifstream test(nname,ios_base::binary ); |
|
1166 #else //!__MSVCDOTNET__ |
|
1167 ifstream test(nname,ios::nocreate | ios::binary); |
|
1168 #endif //__MSVCDOTNET__ |
|
1169 |
|
1170 if (!test.is_open()) |
|
1171 { |
|
1172 Print(EError,"Cannot open file %s for input.\n",iReader.Word(1)); |
|
1173 if(EKeywordHardwareConfigRepositoryData == aKeyword) |
|
1174 { |
|
1175 free(nname); |
|
1176 return EFalse ; |
|
1177 } |
|
1178 iMissingFiles++; |
|
1179 } |
|
1180 |
|
1181 if(EKeywordHardwareConfigRepositoryData == aKeyword) |
|
1182 { // check hcr file |
|
1183 |
|
1184 TUint32 magicWord = 0; |
|
1185 test.read(reinterpret_cast<char*>(&magicWord),sizeof(TUint32)); |
|
1186 if(0x66524348 != magicWord) |
|
1187 { |
|
1188 Print(EError,"Invalid hardware configuration repository data file %s .\n",iReader.Word(1)); |
|
1189 test.close(); |
|
1190 free(nname); |
|
1191 return EFalse; |
|
1192 } |
|
1193 |
|
1194 } |
|
1195 test.close(); |
|
1196 free(nname); |
|
1197 |
|
1198 |
|
1199 TBool endOfName=EFalse; |
|
1200 TText *epocStartPtr=IsValidFilePath(iReader.Text(2)); |
|
1201 if (epocStartPtr==NULL) |
|
1202 { |
|
1203 Print(EError, "Invalid destination path on line %d\n",currentLine); |
|
1204 return EFalse; |
|
1205 } |
|
1206 epocStartPtr = (TText*)NormaliseFileName((const char*)epocStartPtr,false); |
|
1207 if(tryForSysBin) |
|
1208 { |
|
1209 if(strnicmp((const char*)epocStartPtr, "system\\bin\\", 11)==0) |
|
1210 mustBeInSysBin = 1; |
|
1211 if(strnicmp((const char*)epocStartPtr, "system\\libs\\", 12)==0) |
|
1212 mustBeInSysBin = 1; |
|
1213 if(strnicmp((const char*)epocStartPtr, "system\\programs\\", 16)==0) |
|
1214 mustBeInSysBin = 1; |
|
1215 } |
|
1216 |
|
1217 static const char sysBin[] = "sys\\bin\\"; |
|
1218 static const int sysBinLength = sizeof(sysBin)-1; |
|
1219 |
|
1220 if (strnicmp((const char*)epocStartPtr, sysBin, sysBinLength)!=0) |
|
1221 { |
|
1222 if(mustBeInSysBin) |
|
1223 { |
|
1224 TInt len = strlen((char*)epocStartPtr); |
|
1225 TInt i = len; |
|
1226 while(--i>=0) if(epocStartPtr[i]=='\\') break; |
|
1227 ++i; |
|
1228 char* old = (char*)epocStartPtr; |
|
1229 epocStartPtr = (TText*)malloc(sysBinLength+(len-i)+1); |
|
1230 strcpy((char*)epocStartPtr,sysBin); |
|
1231 strcat((char*)epocStartPtr,old+i); |
|
1232 |
|
1233 Print(EDiagnostic, "%s moved to %s\n", old, epocStartPtr); |
|
1234 delete old; |
|
1235 } |
|
1236 else if (warnFlag) |
|
1237 { |
|
1238 Print(EWarning, "Outside standard path at %s\n", epocStartPtr); |
|
1239 } |
|
1240 } |
|
1241 |
|
1242 TText *epocEndPtr=epocStartPtr; |
|
1243 AUTO_FREE(epocStartPtr); |
|
1244 |
|
1245 TRomNode* dir=iRootDirectory; |
|
1246 TRomNode* subDir=0; |
|
1247 TRomBuilderEntry *file=0; |
|
1248 while (!endOfName) |
|
1249 { |
|
1250 endOfName = GetNextBitOfFileName(&epocEndPtr); |
|
1251 if (endOfName) // file |
|
1252 { |
|
1253 TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr,hardwareVariant); |
|
1254 if (alreadyExists) // duplicate file |
|
1255 { |
|
1256 Print(EError, "Duplicate file for %s on line %d\n",iReader.Word(1),iReader.CurrentLine()); |
|
1257 return EFalse; |
|
1258 } |
|
1259 file = new TRomBuilderEntry(iReader.Word(1),epocStartPtr); |
|
1260 file->iRomImageFlags = imageFlags; |
|
1261 file->iResource = isResource; |
|
1262 file->iNonXIP = isNonXIP; |
|
1263 file->iCompression = compression; |
|
1264 |
|
1265 file->iArea = iAreaSet.FindByName(AreaSet::KDefaultAreaName); |
|
1266 file->iRomSectionNumber = iCurrentSectionNumber; |
|
1267 file->iHardwareVariant = hardwareVariant; |
|
1268 file->iOverrideFlags |= overrides; |
|
1269 if (callEntryPoint) |
|
1270 file->SetCallEntryPoint(callEntryPoint); |
|
1271 file->iAlignment=aAlign; |
|
1272 TUint32 uid; |
|
1273 file->iBareName = SplitFileName((const char*)file->iName, uid, file->iVersionInName, file->iVersionPresentInName); |
|
1274 assert(uid==0 && !(file->iVersionPresentInName & EUidPresent)); |
|
1275 if (strchr(file->iBareName, '{') || strchr(file->iBareName, '}')) |
|
1276 { |
|
1277 Print(EError, "Illegal character in name %s on line %d\n", file->iName, iReader.CurrentLine()); |
|
1278 delete file; |
|
1279 return EFalse; |
|
1280 } |
|
1281 TRomNode* node=new TRomNode(epocStartPtr, file); |
|
1282 if (node==0){ |
|
1283 delete file; |
|
1284 return EFalse; |
|
1285 } |
|
1286 |
|
1287 TInt r=ParseFileAttributes(node, file); |
|
1288 if (r!=KErrNone){ |
|
1289 delete file; |
|
1290 delete node; |
|
1291 return EFalse; |
|
1292 } |
|
1293 |
|
1294 TRACE(TAREA, Print(EScreen, "File %s area '%s'\n", iReader.Word(1), file->iArea->Name())); |
|
1295 |
|
1296 // Apply some specific overrides to the primary |
|
1297 if (imageFlags & KRomImageFlagPrimary) |
|
1298 { |
|
1299 if (file->iCodeAlignment < iPageSize) |
|
1300 file->iCodeAlignment = iPageSize; // Kernel code is at least page aligned |
|
1301 file->iHeapSizeMin = iKernHeapMin; |
|
1302 file->iHeapSizeMax = iKernHeapMax; |
|
1303 file->iOverrideFlags |= KOverrideHeapMin+KOverrideHeapMax; |
|
1304 } |
|
1305 |
|
1306 if (!file->iPatched) |
|
1307 dir->AddFile(node); // to ROM directory structure, though possibly hidden |
|
1308 if (isPeFile) |
|
1309 TRomNode::AddExecutableFile(iLastExecutable, node); |
|
1310 |
|
1311 AddFile(file); |
|
1312 } |
|
1313 else // directory |
|
1314 { |
|
1315 subDir = dir->FindInDirectory(epocStartPtr); |
|
1316 if (!subDir) // sub directory does not exist |
|
1317 { |
|
1318 subDir = dir->NewSubDir(epocStartPtr); |
|
1319 if (!subDir) |
|
1320 return EFalse; |
|
1321 } |
|
1322 dir=subDir; |
|
1323 epocStartPtr = epocEndPtr; |
|
1324 } |
|
1325 } |
|
1326 return ETrue; |
|
1327 } |
|
1328 |
|
1329 |
|
1330 void CObeyFile::AddFile(TRomBuilderEntry* aFile) |
|
1331 { |
|
1332 aFile->iArea->AddFile(aFile); |
|
1333 |
|
1334 *iNextFilePtrPtr = aFile; |
|
1335 iNextFilePtrPtr = &(aFile->iNext); |
|
1336 } |
|
1337 |
|
1338 |
|
1339 TBool CObeyFile::ProcessRenaming(enum EKeyword aKeyword) |
|
1340 { |
|
1341 TUint hardwareVariant=ParseVariant(); |
|
1342 |
|
1343 // find existing file |
|
1344 TBool endOfName=EFalse; |
|
1345 |
|
1346 // Store the current name and new name to maintain renamed file map |
|
1347 String currentName=iReader.Word(1); |
|
1348 String newName=iReader.Word(2); |
|
1349 |
|
1350 TText *epocStartPtr=IsValidFilePath(iReader.Text(1)); |
|
1351 if (epocStartPtr==NULL) |
|
1352 { |
|
1353 Print(EError, "Invalid source path on line %d\n",iReader.CurrentLine()); |
|
1354 return EFalse; |
|
1355 } |
|
1356 epocStartPtr = (TText*)NormaliseFileName((const char*)epocStartPtr,false); |
|
1357 TText *epocEndPtr=epocStartPtr; |
|
1358 AUTO_FREE(epocStartPtr); |
|
1359 |
|
1360 char saved_srcname[257]; |
|
1361 strcpy(saved_srcname, iReader.Word(1)); |
|
1362 |
|
1363 TRomNode* dir=iRootDirectory; |
|
1364 TRomNode* existingFile=0; |
|
1365 while (!endOfName) |
|
1366 { |
|
1367 endOfName = GetNextBitOfFileName(&epocEndPtr); |
|
1368 if (endOfName) // file |
|
1369 { |
|
1370 existingFile=dir->FindInDirectory(epocStartPtr,hardwareVariant); |
|
1371 if (existingFile) |
|
1372 { |
|
1373 TInt fileCount=0; |
|
1374 TInt dirCount=0; |
|
1375 existingFile->CountDirectory(fileCount, dirCount); |
|
1376 if (dirCount != 0 || fileCount != 0) |
|
1377 { |
|
1378 Print(EError, "Keyword %s not applicable to directories - line %d\n",iReader.Word(0),iReader.CurrentLine()); |
|
1379 return EFalse; |
|
1380 } |
|
1381 } |
|
1382 } |
|
1383 else // directory |
|
1384 { |
|
1385 TRomNode* subDir = dir->FindInDirectory(epocStartPtr); |
|
1386 if (!subDir) // sub directory does not exist |
|
1387 break; |
|
1388 dir=subDir; |
|
1389 epocStartPtr = epocEndPtr; |
|
1390 } |
|
1391 } |
|
1392 if (aKeyword == EKeywordHide) |
|
1393 { |
|
1394 if (!existingFile) |
|
1395 { |
|
1396 Print(EWarning, "Hiding non-existent file %s on line %d\n", |
|
1397 saved_srcname, iReader.CurrentLine()); |
|
1398 // Just a warning, as we've achieved the right overall effect. |
|
1399 } |
|
1400 else |
|
1401 { |
|
1402 existingFile->iHidden = ETrue; |
|
1403 } |
|
1404 return ETrue; |
|
1405 } |
|
1406 |
|
1407 if (!existingFile) |
|
1408 { |
|
1409 Print(EError, "Can't %s non-existent source file %s on line %d\n", |
|
1410 iReader.Word(0), saved_srcname, iReader.CurrentLine()); |
|
1411 return EFalse; |
|
1412 } |
|
1413 |
|
1414 epocStartPtr=IsValidFilePath(iReader.Text(2)); |
|
1415 epocEndPtr=epocStartPtr; |
|
1416 endOfName=EFalse; |
|
1417 if (epocStartPtr==NULL) |
|
1418 { |
|
1419 Print(EError, "Invalid destination path on line %d\n",iReader.CurrentLine()); |
|
1420 return EFalse; |
|
1421 } |
|
1422 |
|
1423 TRomNode* newdir=iRootDirectory; |
|
1424 while (!endOfName) |
|
1425 { |
|
1426 endOfName = GetNextBitOfFileName(&epocEndPtr); |
|
1427 if (endOfName) // file |
|
1428 { |
|
1429 TRomNode* alreadyExists=newdir->FindInDirectory(epocStartPtr,existingFile->HardwareVariant()); |
|
1430 if (alreadyExists) // duplicate file |
|
1431 { |
|
1432 Print(EError, "Duplicate file for %s on line %d\n",saved_srcname,iReader.CurrentLine()); |
|
1433 return EFalse; |
|
1434 } |
|
1435 } |
|
1436 else // directory |
|
1437 { |
|
1438 TRomNode* subDir = newdir->FindInDirectory(epocStartPtr); |
|
1439 if (!subDir) // sub directory does not exist |
|
1440 { |
|
1441 subDir = newdir->NewSubDir(epocStartPtr); |
|
1442 if (!subDir) |
|
1443 return EFalse; |
|
1444 } |
|
1445 newdir=subDir; |
|
1446 epocStartPtr = epocEndPtr; |
|
1447 } |
|
1448 } |
|
1449 |
|
1450 if (aKeyword == EKeywordRename) |
|
1451 { |
|
1452 // rename => remove existingFile and insert into tree at new place |
|
1453 // has no effect on the iNextExecutable or iNextNodeForSameFile links |
|
1454 |
|
1455 TInt r=ParseFileAttributes(existingFile, existingFile->iRomFile->iRbEntry); |
|
1456 if (r!=KErrNone) |
|
1457 return EFalse; |
|
1458 r = existingFile->Rename(dir, newdir, epocStartPtr); |
|
1459 if (r==KErrBadName) |
|
1460 { |
|
1461 Print(EError, "Bad name %s at line %d\n", epocStartPtr, iReader.CurrentLine()); |
|
1462 return EFalse; |
|
1463 } |
|
1464 else if (r==KErrArgument) |
|
1465 { |
|
1466 Print(EError, "Version in name %s does not match version in file header at line %d\n", epocStartPtr, iReader.CurrentLine()); |
|
1467 return EFalse; |
|
1468 } |
|
1469 // Store the current and new name of file in the renamed file map. |
|
1470 iPatchData->AddToRenamedFileMap(currentName, newName); |
|
1471 return ETrue; |
|
1472 } |
|
1473 |
|
1474 // alias => create new TRomNode entry and insert into tree |
|
1475 |
|
1476 TRomNode* node = new TRomNode(epocStartPtr, existingFile); |
|
1477 if (node == 0) |
|
1478 { |
|
1479 Print(EError, "Out of memory\n"); |
|
1480 return EFalse; |
|
1481 } |
|
1482 |
|
1483 TInt r = node->Alias(existingFile, iLastExecutable); |
|
1484 if (r==KErrBadName) |
|
1485 { |
|
1486 Print(EError, "Bad name %s at line %d\n", epocStartPtr, iReader.CurrentLine()); |
|
1487 return EFalse; |
|
1488 } |
|
1489 else if (r==KErrArgument) |
|
1490 { |
|
1491 Print(EError, "Version in name %s does not match version in file header at line %d\n", epocStartPtr, iReader.CurrentLine()); |
|
1492 return EFalse; |
|
1493 } |
|
1494 r=ParseFileAttributes(node, 0); |
|
1495 if (r!=KErrNone) |
|
1496 return EFalse; |
|
1497 |
|
1498 newdir->AddFile(node); // to ROM directory structure, though possibly hidden |
|
1499 |
|
1500 return ETrue; |
|
1501 } |
|
1502 |
|
1503 |
|
1504 TInt ParsePagingPolicy(const char* policy) |
|
1505 { |
|
1506 if(stricmp(policy,"NOPAGING")==0) |
|
1507 return EKernelConfigPagingPolicyNoPaging; |
|
1508 else if (stricmp(policy,"ALWAYSPAGE")==0) |
|
1509 return EKernelConfigPagingPolicyAlwaysPage; |
|
1510 else if(stricmp(policy,"DEFAULTUNPAGED")==0) |
|
1511 return EKernelConfigPagingPolicyDefaultUnpaged; |
|
1512 else if(stricmp(policy,"DEFAULTPAGED")==0) |
|
1513 return EKernelConfigPagingPolicyDefaultPaged; |
|
1514 return KErrArgument; |
|
1515 } |
|
1516 |
|
1517 |
|
1518 TBool CObeyFile::ProcessKeyword(enum EKeyword aKeyword) |
|
1519 { |
|
1520 TUint hardwareVariant=KVariantIndependent; |
|
1521 |
|
1522 #ifdef __TOOLS2__ |
|
1523 istringstream val(iReader.Word(1)); |
|
1524 #else |
|
1525 istrstream val(iReader.Word(1),strlen(iReader.Word(1))); |
|
1526 #endif |
|
1527 |
|
1528 #if defined(__MSVCDOTNET__) || defined (__TOOLS2__) |
|
1529 val >> setbase(0); |
|
1530 #endif //__MSVCDOTNET__ |
|
1531 |
|
1532 TBool success = ETrue; |
|
1533 |
|
1534 switch (aKeyword) |
|
1535 { |
|
1536 case EKeywordUnicode: |
|
1537 Unicode=ETrue; |
|
1538 break; |
|
1539 case EKeywordAscii: |
|
1540 Unicode=EFalse; |
|
1541 break; |
|
1542 |
|
1543 case EKeywordSingleKernel: |
|
1544 iKernelModel=ESingleKernel; |
|
1545 break; |
|
1546 case EKeywordMultiKernel: |
|
1547 iKernelModel=EMultipleKernels; |
|
1548 break; |
|
1549 |
|
1550 case EKeywordBootBinary: |
|
1551 iReader.CopyWord(1, iBootFileName); |
|
1552 break; |
|
1553 case EKeywordRomName: |
|
1554 iReader.CopyWord(1, iRomFileName); |
|
1555 break; |
|
1556 case EKeywordRomNameOdd: |
|
1557 iReader.CopyWord(1, iRomOddFileName); |
|
1558 break; |
|
1559 case EKeywordRomNameEven: |
|
1560 iReader.CopyWord(1, iRomEvenFileName); |
|
1561 break; |
|
1562 case EKeywordSRecordFileName: |
|
1563 iReader.CopyWord(1, iSRecordFileName); |
|
1564 break; |
|
1565 |
|
1566 case EKeywordRomLinearBase: |
|
1567 val >> iRomLinearBase; |
|
1568 break; |
|
1569 case EKeywordRomSize: |
|
1570 val >> iRomSize; |
|
1571 break; |
|
1572 case EKeywordRomAlign: |
|
1573 val >> iRomAlign; |
|
1574 break; |
|
1575 case EKeywordKernelDataAddress: |
|
1576 val >> iKernDataRunAddress; |
|
1577 break; |
|
1578 case EKeywordKernelHeapMin: |
|
1579 val >> iKernHeapMin; |
|
1580 break; |
|
1581 case EKeywordKernelHeapMax: |
|
1582 val >> iKernHeapMax; |
|
1583 break; |
|
1584 case EKeywordDataAddress: |
|
1585 val >> iDataRunAddress; |
|
1586 break; |
|
1587 case EKeywordDefaultStackReserve: |
|
1588 val >> iDefaultStackReserve; |
|
1589 break; |
|
1590 case EKeywordVersion: |
|
1591 val >> iVersion; |
|
1592 break; |
|
1593 case EKeywordSRecordBase: |
|
1594 val >> iSRecordBase; |
|
1595 break; |
|
1596 case EKeywordRomChecksum: |
|
1597 val >> iCheckSum; |
|
1598 break; |
|
1599 case EKeywordHardware: |
|
1600 val >> iHardware; |
|
1601 break; |
|
1602 case EKeywordLanguages: |
|
1603 iReader.ProcessLanguages(iLanguage); |
|
1604 break; |
|
1605 case EKeywordTime: |
|
1606 iReader.ProcessTime(iTime); |
|
1607 break; |
|
1608 case EKeywordDllDataTop: |
|
1609 val >> iDllDataTop; |
|
1610 break; |
|
1611 |
|
1612 case EKeywordMemModel: |
|
1613 { |
|
1614 char* arg1=iReader.Word(1); |
|
1615 char* arg2=iReader.Word(2); |
|
1616 char* arg3=iReader.Word(3); |
|
1617 char* arg4=iReader.Word(4); |
|
1618 if (strnicmp(arg1, "moving", 6)==0) |
|
1619 iMemModel=E_MM_Moving; |
|
1620 else if (strnicmp(arg1, "direct", 6)==0) |
|
1621 iMemModel=E_MM_Direct; |
|
1622 else if (strnicmp(arg1, "multiple", 8)==0) |
|
1623 iMemModel=E_MM_Multiple; |
|
1624 else if (strnicmp(arg1, "flexible", 8)==0) |
|
1625 iMemModel=E_MM_Flexible; |
|
1626 else |
|
1627 { |
|
1628 Print(EError, "Unknown memory model specified\n"); |
|
1629 success = EFalse; |
|
1630 } |
|
1631 if (strlen(arg2)) |
|
1632 { |
|
1633 #ifdef __TOOLS2__ |
|
1634 istringstream arg2s(arg2); |
|
1635 #else |
|
1636 istrstream arg2s(arg2,strlen(arg2)); |
|
1637 #endif |
|
1638 |
|
1639 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
1640 arg2s >> setbase(0); |
|
1641 #endif //__MSVCDOTNET__ |
|
1642 |
|
1643 arg2s >> iChunkSize; |
|
1644 } |
|
1645 if (iMemModel!=E_MM_Direct && strlen(arg3)) |
|
1646 { |
|
1647 #ifdef __TOOLS2__ |
|
1648 istringstream arg3s(arg3); |
|
1649 #else |
|
1650 istrstream arg3s(arg3,strlen(arg3)); |
|
1651 #endif |
|
1652 |
|
1653 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
1654 arg3s >> setbase(0); |
|
1655 #endif //__MSVCDOTNET__ |
|
1656 |
|
1657 arg3s >> iPageSize; |
|
1658 } |
|
1659 else if (iMemModel==E_MM_Direct) |
|
1660 iPageSize=iChunkSize; |
|
1661 if (iMemModel!=E_MM_Direct && strlen(arg4)) |
|
1662 { |
|
1663 #ifdef __TOOLS2__ |
|
1664 istringstream arg4s(arg4); |
|
1665 #else |
|
1666 istrstream arg4s(arg4,strlen(arg4)); |
|
1667 #endif |
|
1668 |
|
1669 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
1670 arg4s >> setbase(0); |
|
1671 #endif //__MSVCDOTNET__ |
|
1672 |
|
1673 arg4s >> iVirtualAllocSize; |
|
1674 } |
|
1675 else |
|
1676 iVirtualAllocSize = iPageSize; |
|
1677 |
|
1678 break; |
|
1679 } |
|
1680 case EKeywordNoWrapper: |
|
1681 if (gHeaderType<0) |
|
1682 gHeaderType=0; |
|
1683 break; |
|
1684 case EKeywordEpocWrapper: |
|
1685 if (gHeaderType<0) |
|
1686 gHeaderType=1; |
|
1687 break; |
|
1688 case EKeywordCoffWrapper: |
|
1689 if (gHeaderType<0) |
|
1690 gHeaderType=2; |
|
1691 break; |
|
1692 |
|
1693 case EKeywordPlatSecEnforcement: |
|
1694 ParseBoolArg(gPlatSecEnforcement,iReader.Word(1)); |
|
1695 if(gPlatSecEnforcement) |
|
1696 iKernelConfigFlags |= EKernelConfigPlatSecEnforcement; |
|
1697 else |
|
1698 iKernelConfigFlags &= ~EKernelConfigPlatSecEnforcement; |
|
1699 break; |
|
1700 case EKeywordPlatSecDiagnostics: |
|
1701 ParseBoolArg(gPlatSecDiagnostics,iReader.Word(1)); |
|
1702 if(gPlatSecDiagnostics) |
|
1703 iKernelConfigFlags |= EKernelConfigPlatSecDiagnostics; |
|
1704 else |
|
1705 iKernelConfigFlags &= ~EKernelConfigPlatSecDiagnostics; |
|
1706 break; |
|
1707 case EKeywordPlatSecProcessIsolation: |
|
1708 { |
|
1709 TInt processIsolation; |
|
1710 ParseBoolArg(processIsolation,iReader.Word(1)); |
|
1711 if(processIsolation) |
|
1712 iKernelConfigFlags |= EKernelConfigPlatSecProcessIsolation; |
|
1713 else |
|
1714 iKernelConfigFlags &= ~EKernelConfigPlatSecProcessIsolation; |
|
1715 break; |
|
1716 } |
|
1717 case EKeywordPlatSecEnforceSysBin: |
|
1718 { |
|
1719 ParseBoolArg(gPlatSecEnforceSysBin,iReader.Word(1)); |
|
1720 if(gPlatSecEnforceSysBin) |
|
1721 iKernelConfigFlags |= EKernelConfigPlatSecEnforceSysBin; |
|
1722 else |
|
1723 iKernelConfigFlags &= ~EKernelConfigPlatSecEnforceSysBin; |
|
1724 break; |
|
1725 } |
|
1726 case EKeywordPlatSecDisabledCaps: |
|
1727 if(iPlatSecDisabledCapsParsed) |
|
1728 Print(EWarning, "PlatSecDisabledCaps redefined - previous values lost\n"); |
|
1729 { |
|
1730 ParseCapabilitiesArg(iPlatSecDisabledCaps, iReader.Word(1)); |
|
1731 gPlatSecDisabledCaps = iPlatSecDisabledCaps; |
|
1732 iPlatSecDisabledCapsParsed=ETrue; |
|
1733 } |
|
1734 break; |
|
1735 case EKeywordPagingPolicy: |
|
1736 { |
|
1737 if(iPagingPolicyParsed) |
|
1738 Print(EWarning, "PagingPolicy redefined - previous PagingPolicy values lost\n"); |
|
1739 if(iDataPagingPolicyParsed) |
|
1740 Print(EWarning, "PagingPolicy defined - previous DataPagingPolicy values lost\n"); |
|
1741 if(iCodePagingPolicyParsed) |
|
1742 Print(EWarning, "PagingPolicy defined - previous DataPagingPolicy values lost\n"); |
|
1743 iPagingPolicyParsed = true; |
|
1744 iKernelConfigFlags &= ~(EKernelConfigCodePagingPolicyMask|EKernelConfigDataPagingPolicyMask); |
|
1745 TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1746 if(policy<0) |
|
1747 { |
|
1748 Print(EError,"Unrecognised option for PAGINGPOLICY keyword\n"); |
|
1749 success = false; |
|
1750 } |
|
1751 else { |
|
1752 #ifndef SYMBIAN_WRITABLE_DATA_PAGING |
|
1753 if ((policy != EKernelConfigPagingPolicyNoPaging) && (iMemModel == E_MM_Flexible)) |
|
1754 Print(EWarning, "SYMBIAN_WRITABLE_DATA_PAPING is not defined. Writable data paging is not warranted on this version of Symbian."); |
|
1755 #endif |
|
1756 iKernelConfigFlags |= policy << EKernelConfigCodePagingPolicyShift; |
|
1757 iKernelConfigFlags |= policy << EKernelConfigDataPagingPolicyShift; |
|
1758 } |
|
1759 } |
|
1760 break; |
|
1761 case EKeywordCodePagingPolicy: |
|
1762 { |
|
1763 if(iCodePagingPolicyParsed) |
|
1764 Print(EWarning, "CodePagingPolicy redefined - previous CodePagingPolicy values lost\n"); |
|
1765 if(iPagingPolicyParsed) |
|
1766 Print(EWarning, "CodePagingPolicy defined - previous PagingPolicy values lost\n"); |
|
1767 iCodePagingPolicyParsed = true; |
|
1768 iKernelConfigFlags &= ~EKernelConfigCodePagingPolicyMask; |
|
1769 TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1770 if(policy<0) |
|
1771 { |
|
1772 Print(EError,"Unrecognised option for CODEPAGINGPOLICY keyword\n"); |
|
1773 success = false; |
|
1774 } |
|
1775 else |
|
1776 iKernelConfigFlags |= policy << EKernelConfigCodePagingPolicyShift; |
|
1777 } |
|
1778 break; |
|
1779 case EKeywordDataPagingPolicy: |
|
1780 { |
|
1781 if(iDataPagingPolicyParsed) |
|
1782 Print(EWarning, "DataPagingPolicy redefined - previous DataPagingPolicy values lost\n"); |
|
1783 if(iPagingPolicyParsed) |
|
1784 Print(EWarning, "DataPagingPolicy defined - previous PagingPolicy values lost\n"); |
|
1785 iDataPagingPolicyParsed = true; |
|
1786 iKernelConfigFlags &= ~EKernelConfigDataPagingPolicyMask; |
|
1787 TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1788 if(policy<0) |
|
1789 { |
|
1790 Print(EError,"Unrecognised option for DATAPAGINGPOLICY keyword\n"); |
|
1791 success = false; |
|
1792 } |
|
1793 else |
|
1794 #ifndef SYMBIAN_WRITABLE_DATA_PAGING |
|
1795 if ((policy != EKernelConfigPagingPolicyNoPaging) && (iMemModel == E_MM_Flexible)) |
|
1796 Print(EWarning, "SYMBIAN_WRITABLE_DATA_PAPING is not defined. Writable data paging is not warranted on this version of Symbian."); |
|
1797 #endif |
|
1798 iKernelConfigFlags |= policy << EKernelConfigDataPagingPolicyShift; |
|
1799 } |
|
1800 break; |
|
1801 case EKeywordPagingOverride: |
|
1802 { |
|
1803 if(iPagingOverrideParsed) |
|
1804 Print(EWarning, "PagingOverride redefined - previous PagingOverride values lost\n"); |
|
1805 if(iCodePagingOverrideParsed) |
|
1806 Print(EWarning, "PagingOverride defined - previous CodePagingOverride valus lost\n"); |
|
1807 if(iDataPagingOverrideParsed) |
|
1808 Print(EWarning, "PagingOverride defined - previous DataPagingOverride values lostn"); |
|
1809 iPagingOverrideParsed = true; |
|
1810 TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1811 if(policy<0) |
|
1812 { |
|
1813 Print(EError,"Unrecognised option for PAGINGOVERRIDE keyword\n"); |
|
1814 success = false; |
|
1815 } |
|
1816 else |
|
1817 { |
|
1818 gCodePagingOverride = policy; |
|
1819 gDataPagingOverride = policy; |
|
1820 } |
|
1821 } |
|
1822 break; |
|
1823 case EKeywordCodePagingOverride: |
|
1824 { |
|
1825 if(iCodePagingOverrideParsed) |
|
1826 Print(EWarning, "CodePagingOverride redefined - previous CodePagingOverride values lost\n"); |
|
1827 if(iPagingOverrideParsed) |
|
1828 Print(EWarning, "CodePagingOverride defined - previous PagingOverride values lost\n"); |
|
1829 iCodePagingOverrideParsed = true; |
|
1830 TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1831 if(policy<0) |
|
1832 { |
|
1833 Print(EError,"Unrecognised option for CODEPAGINGOVERRIDE keyword\n"); |
|
1834 success = false; |
|
1835 } |
|
1836 else |
|
1837 gCodePagingOverride = policy; |
|
1838 } |
|
1839 break; |
|
1840 case EKeywordDataPagingOverride: |
|
1841 { |
|
1842 if(iDataPagingOverrideParsed) |
|
1843 Print(EWarning, "DataPagingOverride redefined - previous DataPagingOverride values lost\n"); |
|
1844 if(iPagingOverrideParsed) |
|
1845 Print(EWarning, "DataPagingOverride defined - previous PagingOverride values lost\n"); |
|
1846 iDataPagingOverrideParsed = true; |
|
1847 TInt policy = ParsePagingPolicy(iReader.Word(1)); |
|
1848 if(policy<0) |
|
1849 { |
|
1850 Print(EError,"Unrecognised option for DATAPAGINGOVERRIDE keyword\n"); |
|
1851 success = false; |
|
1852 } |
|
1853 else |
|
1854 gDataPagingOverride = policy; |
|
1855 } |
|
1856 break; |
|
1857 case EKeywordDemandPagingConfig: |
|
1858 { |
|
1859 memset(&gDemandPagingConfig,0,sizeof(gDemandPagingConfig)); |
|
1860 val >> gDemandPagingConfig.iMinPages; |
|
1861 if(strlen(iReader.Word(2))) |
|
1862 { |
|
1863 #ifdef __TOOLS2__ |
|
1864 istringstream val(iReader.Word(2)); |
|
1865 #else |
|
1866 istrstream val(iReader.Word(2),strlen(iReader.Word(2))); |
|
1867 #endif |
|
1868 val >> gDemandPagingConfig.iMaxPages; |
|
1869 if(strlen(iReader.Word(3))) |
|
1870 { |
|
1871 #ifdef __TOOLS2__ |
|
1872 istringstream val(iReader.Word(3)); |
|
1873 #else |
|
1874 istrstream val(iReader.Word(3),strlen(iReader.Word(3))); |
|
1875 #endif |
|
1876 val >> gDemandPagingConfig.iYoungOldRatio; |
|
1877 for(int i=0; i<=2; i++) |
|
1878 { |
|
1879 if(!strlen(iReader.Word(4+i))) |
|
1880 break; |
|
1881 #ifdef __TOOLS2__ |
|
1882 istringstream val(iReader.Word(4+i)); |
|
1883 #else |
|
1884 istrstream val(iReader.Word(4+i),strlen(iReader.Word(4+i))); |
|
1885 #endif |
|
1886 val >> gDemandPagingConfig.iSpare[i]; |
|
1887 } |
|
1888 } |
|
1889 } |
|
1890 if(gDemandPagingConfig.iMaxPages && gDemandPagingConfig.iMaxPages<gDemandPagingConfig.iMinPages) |
|
1891 { |
|
1892 Print(EError,"DemandPagingConfig maxPages must be >= minPages\n"); |
|
1893 success = EFalse; |
|
1894 break; |
|
1895 } |
|
1896 } |
|
1897 break; |
|
1898 case EKeywordPagedRom: |
|
1899 gPagedRom = ETrue; |
|
1900 break; |
|
1901 |
|
1902 case EKeywordTrace: |
|
1903 val >> TraceMask; |
|
1904 break; |
|
1905 |
|
1906 case EKeywordKernelTrace: |
|
1907 { |
|
1908 TInt i; |
|
1909 val >> iTraceMask[0]; |
|
1910 i=1; |
|
1911 while(strlen(iReader.Word(i+1)) && i<KNumTraceMaskWords) |
|
1912 { |
|
1913 #ifdef __TOOLS2__ |
|
1914 istringstream val(iReader.Word(i+1)); |
|
1915 #else |
|
1916 istrstream val(iReader.Word(i+1),strlen(iReader.Word(i+1))); |
|
1917 #endif |
|
1918 #if defined(__MSVCDOTNET__) || defined (__TOOLS2__) |
|
1919 val >> setbase(0); |
|
1920 #endif |
|
1921 val >> iTraceMask[i]; |
|
1922 ++i; |
|
1923 } |
|
1924 } |
|
1925 break; |
|
1926 |
|
1927 case EKeywordBTrace: |
|
1928 { |
|
1929 TUint i; |
|
1930 val >> iInitialBTraceFilter[0]; |
|
1931 i=1; |
|
1932 while(strlen(iReader.Word(i+1)) && i<sizeof(iInitialBTraceFilter)/sizeof(TUint32)) |
|
1933 { |
|
1934 #ifdef __TOOLS2__ |
|
1935 istringstream val(iReader.Word(i+1)); |
|
1936 #else |
|
1937 istrstream val(iReader.Word(i+1),strlen(iReader.Word(i+1))); |
|
1938 #endif |
|
1939 #if defined(__MSVCDOTNET__) || defined (__TOOLS2__) |
|
1940 val >> setbase(0); |
|
1941 #endif |
|
1942 val >> iInitialBTraceFilter[i]; |
|
1943 ++i; |
|
1944 } |
|
1945 } |
|
1946 break; |
|
1947 |
|
1948 case EKeywordBTraceMode: |
|
1949 val >> iInitialBTraceMode; |
|
1950 break; |
|
1951 |
|
1952 case EKeywordBTraceBuffer: |
|
1953 val >> iInitialBTraceBuffer; |
|
1954 break; |
|
1955 |
|
1956 case EKeywordDebugPort: |
|
1957 if (iDebugPortParsed) |
|
1958 Print(EWarning, "DEBUGPORT redefined - previous value lost\n"); |
|
1959 val >> iDebugPort; |
|
1960 iDebugPortParsed = ETrue; |
|
1961 break; |
|
1962 |
|
1963 case EKeywordCompress: |
|
1964 gEnableCompress=ETrue; // Set ROM Compression on. |
|
1965 break; |
|
1966 |
|
1967 case EKeywordCollapse: |
|
1968 if (strnicmp(iReader.Word(1), "arm", 3)!=0 || strnicmp(iReader.Word(2), "gcc", 3)!=0) |
|
1969 { |
|
1970 Print(EWarning, "COLLAPSE only supported for ARM and GCC - keyword ignored\n"); |
|
1971 } |
|
1972 else |
|
1973 { |
|
1974 TInt cm; |
|
1975 #ifdef __TOOLS2__ |
|
1976 istringstream cmval(iReader.Word(3)); |
|
1977 #else |
|
1978 istrstream cmval(iReader.Word(3),strlen(iReader.Word(3))); |
|
1979 #endif |
|
1980 |
|
1981 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
1982 cmval >> setbase(0); |
|
1983 #endif //__MSVCDOTNET__ |
|
1984 |
|
1985 cmval>>cm; |
|
1986 if (cm<0 || cm>ECollapseAllChainBranches) |
|
1987 { |
|
1988 Print(EWarning, "COLLAPSE mode unrecognised - keyword ignored\n"); |
|
1989 } |
|
1990 else |
|
1991 iCollapseMode=cm; |
|
1992 } |
|
1993 break; |
|
1994 |
|
1995 case EKeywordPrimary: |
|
1996 iNumberOfPrimaries++; |
|
1997 break; |
|
1998 case EKeywordVariant: |
|
1999 hardwareVariant=ParseVariant(); |
|
2000 if (THardwareVariant(hardwareVariant).IsVariant()) |
|
2001 { |
|
2002 iNumberOfVariants++; |
|
2003 TUint layer=THardwareVariant(hardwareVariant).Layer(); |
|
2004 TUint vmask=THardwareVariant(hardwareVariant).VMask(); |
|
2005 iAllVariantsMask[layer] |= vmask; |
|
2006 } |
|
2007 else |
|
2008 { |
|
2009 Print(EError,"Variant DLLs must belong to variant layer - line %d\n", iReader.CurrentLine()); |
|
2010 break; |
|
2011 } |
|
2012 |
|
2013 break; |
|
2014 case EKeywordExtension: |
|
2015 iNumberOfExtensions++; |
|
2016 break; |
|
2017 case EKeywordDevice: |
|
2018 iNumberOfDevices++; |
|
2019 break; |
|
2020 |
|
2021 case EKeywordKernelRomName: |
|
2022 Print(EError,"Keyword '%s' only valid in extension ROMs - line %d\n", iReader.Word(0), iReader.CurrentLine()); |
|
2023 break; |
|
2024 |
|
2025 case EKeywordArea: |
|
2026 if(! ParseAreaKeyword()) |
|
2027 success = EFalse; |
|
2028 break; |
|
2029 |
|
2030 case EKeywordExecutableCompressionMethodNone: |
|
2031 gCompressionMethod = 0; |
|
2032 break; |
|
2033 |
|
2034 case EKeywordExecutableCompressionMethodInflate: |
|
2035 gCompressionMethod = KUidCompressionDeflate; |
|
2036 break; |
|
2037 |
|
2038 case EKeywordExecutableCompressionMethodBytePair: |
|
2039 gCompressionMethod = KUidCompressionBytePair; |
|
2040 break; |
|
2041 |
|
2042 case EKeywordKernelConfig: |
|
2043 { |
|
2044 TInt bit, setTo; |
|
2045 val >> bit; |
|
2046 if(bit<0 || bit>31) |
|
2047 { |
|
2048 Print(EError,"KernelConfig bit must be between 0 and 31\n"); |
|
2049 success = EFalse; |
|
2050 break; |
|
2051 } |
|
2052 if(ParseBoolArg(setTo,iReader.Word(2))!=KErrNone) |
|
2053 { |
|
2054 success = EFalse; |
|
2055 break; |
|
2056 } |
|
2057 if(setTo) |
|
2058 iKernelConfigFlags |= 1<<bit; |
|
2059 else |
|
2060 iKernelConfigFlags &= ~(1<<bit); |
|
2061 break; |
|
2062 } |
|
2063 |
|
2064 case EKeywordMaxUnpagedMemSize: |
|
2065 { |
|
2066 TInt unpagedSize = -1; |
|
2067 val >> unpagedSize; |
|
2068 |
|
2069 if (!val || unpagedSize < 0) |
|
2070 { |
|
2071 Print(EWarning, "Invalid value of MaxUnpagedSize (0 to 0x7FFFFFFF) - value ignored\n"); |
|
2072 break; |
|
2073 } |
|
2074 |
|
2075 iMaxUnpagedMemSize = unpagedSize; |
|
2076 |
|
2077 if(iUpdatedMaxUnpagedMemSize) |
|
2078 { |
|
2079 Print(EWarning, "MaxUnpagedSize redefined - previous values lost\n"); |
|
2080 } |
|
2081 else |
|
2082 { |
|
2083 iUpdatedMaxUnpagedMemSize = ETrue; |
|
2084 } |
|
2085 |
|
2086 break; |
|
2087 } |
|
2088 |
|
2089 default: |
|
2090 // unexpected keyword iReader.Word(0) |
|
2091 break; |
|
2092 } |
|
2093 |
|
2094 return success; |
|
2095 } |
|
2096 |
|
2097 TBool CObeyFile::GotKeyVariables() |
|
2098 // |
|
2099 // Checks that the obeyfile has supplied enough variables to continue |
|
2100 // |
|
2101 { |
|
2102 |
|
2103 TBool retVal=ETrue; |
|
2104 |
|
2105 // Mandatory keywords |
|
2106 |
|
2107 if (iRomFileName==0) |
|
2108 { |
|
2109 Print(EAlways,"The name of the ROM has not been supplied.\n"); |
|
2110 Print(EAlways,"Use the keyword \"romname\".\n"); |
|
2111 retVal = EFalse; |
|
2112 } |
|
2113 if (iBootFileName==0) |
|
2114 { |
|
2115 Print(EAlways,"The name of the bootstrap binary has not been supplied.\n"); |
|
2116 Print(EAlways,"Use the keyword \"bootbinary\".\n"); |
|
2117 retVal = EFalse; |
|
2118 } |
|
2119 if (iRomLinearBase==0xFFFFFFFF) |
|
2120 { |
|
2121 Print(EAlways,"The base linear address of the ROM has not been supplied.\n"); |
|
2122 Print(EAlways,"Use the keyword \"romlinearbase\".\n"); |
|
2123 retVal = EFalse; |
|
2124 } |
|
2125 if (iRomSize==0) |
|
2126 { |
|
2127 Print(EAlways,"The size of the ROM has not been supplied.\n"); |
|
2128 Print(EAlways,"Use the keyword \"romsize\".\n"); |
|
2129 retVal = EFalse; |
|
2130 } |
|
2131 if (iKernDataRunAddress==0) |
|
2132 { |
|
2133 Print(EAlways,"The address for the kernel's data section has not been supplied.\n"); |
|
2134 Print(EAlways,"Use the keyword \"kerneldataaddress\".\n"); |
|
2135 retVal = EFalse; |
|
2136 } |
|
2137 |
|
2138 // Validation |
|
2139 if (iNumberOfPrimaries>1 && iKernelModel==ESingleKernel) |
|
2140 { |
|
2141 Print(EError,"More than one primary in single-kernel ROM\n"); |
|
2142 retVal = EFalse; |
|
2143 } |
|
2144 if (iNumberOfPrimaries==0) |
|
2145 { |
|
2146 Print(EError,"No primary file specified\n"); |
|
2147 retVal = EFalse; |
|
2148 } |
|
2149 if (iNumberOfVariants==0) |
|
2150 { |
|
2151 Print(EError,"No variants specified\n"); |
|
2152 retVal = EFalse; |
|
2153 } |
|
2154 if(iNumberOfHCRDataFiles > 1) |
|
2155 { |
|
2156 Print(EError,"More than one hcr data files in ROM.\n"); |
|
2157 retVal = EFalse ; |
|
2158 } |
|
2159 // Warn about enabling data paging on OS versions where's it's not officially supported |
|
2160 #ifndef SYMBIAN_WRITABLE_DATA_PAGING |
|
2161 if (iMemModel == E_MM_Flexible && |
|
2162 (iKernelConfigFlags & EKernelConfigDataPagingPolicyMask) != EKernelConfigDataPagingPolicyNoPaging) |
|
2163 { |
|
2164 Print(EWarning, "Writable data paging is not warranted on this version of Symbian OS."); |
|
2165 } |
|
2166 #endif |
|
2167 |
|
2168 // Apply defaults as necessary |
|
2169 TheRomLinearAddress=iRomLinearBase; |
|
2170 |
|
2171 if (iDataRunAddress==0) |
|
2172 { |
|
2173 iDataRunAddress=0x400000; |
|
2174 Print(EWarning,"The address for a running ROM app's data section (keyword \"dataaddress\") has not been supplied.\n"); |
|
2175 Print(EWarning,"Will use the default value of 0x%0x.\n", iDataRunAddress); |
|
2176 retVal = EFalse; |
|
2177 } |
|
2178 if (iRomAlign==0) |
|
2179 { |
|
2180 iRomAlign=0x1000; |
|
2181 Print(EWarning,"The ROM section alignment (keyword \"romalign\") has not been supplied.\n"); |
|
2182 Print(EWarning,"Will use the default value of 0x%0x.\n", iRomAlign); |
|
2183 } |
|
2184 if (iRomAlign&0x3) |
|
2185 { |
|
2186 Print(EWarning, "Rounding rom alignment to multiple of 4.\n"); |
|
2187 iRomAlign=(iRomAlign+0x3)&0xfffffffc; |
|
2188 } |
|
2189 if (iKernHeapMin==0) |
|
2190 { |
|
2191 iKernHeapMin=0x10000; |
|
2192 Print(EWarning,"The kernel heap min size (keyword \"kernelheapmin\") has not been supplied.\n"); |
|
2193 Print(EWarning,"Will use the default value of 0x%0x.\n", iKernHeapMin); |
|
2194 } |
|
2195 if (iKernHeapMax==0) |
|
2196 { |
|
2197 iKernHeapMax=0x100000; |
|
2198 Print(EWarning,"The kernel heap max size (keyword \"kernelheapmax\") has not been supplied.\n"); |
|
2199 Print(EWarning,"Will use the default value of 0x%0x.\n", iKernHeapMax); |
|
2200 } |
|
2201 |
|
2202 if (iTime==0) |
|
2203 { |
|
2204 Print(ELog, "No timestamp specified. Using current time...\n"); |
|
2205 ObeyFileReader::TimeNow(iTime); |
|
2206 } |
|
2207 |
|
2208 Print(ELog, "\nCreating Rom image %s\n", iRomFileName); |
|
2209 Print(ELog, "MemModel: %1d\nChunkSize: %08x\nPageSize: %08x\n", iMemModel, iChunkSize, iPageSize); |
|
2210 return retVal; |
|
2211 } |
|
2212 |
|
2213 |
|
2214 TText *CObeyFile::IsValidFilePath(TText *aPath) |
|
2215 // |
|
2216 // Check the path is valid |
|
2217 // |
|
2218 { |
|
2219 // skip leading "\" |
|
2220 if (*aPath=='\\') |
|
2221 aPath++; |
|
2222 if (*aPath==0) |
|
2223 return NULL; // file ends in a backslash |
|
2224 |
|
2225 TText *p=aPath; |
|
2226 TInt len=0; |
|
2227 FOREVER |
|
2228 { |
|
2229 if (*p==0) |
|
2230 return (len ? aPath : NULL); |
|
2231 if (*p=='\\') |
|
2232 { |
|
2233 if (len==0) |
|
2234 return NULL; |
|
2235 len=0; |
|
2236 } |
|
2237 len++; |
|
2238 p++; |
|
2239 } |
|
2240 } |
|
2241 |
|
2242 TBool CObeyFile::GetNextBitOfFileName(TText **epocEndPtr) |
|
2243 // |
|
2244 // Move the end pointer past the next directory separator, replacing it with 0 |
|
2245 // |
|
2246 { |
|
2247 while (**epocEndPtr != '\\') // until reach the directory separator |
|
2248 { |
|
2249 if (**epocEndPtr==0) // if reach end of string, return TRUE, it's the filename |
|
2250 return ETrue; |
|
2251 (*epocEndPtr)++; |
|
2252 } |
|
2253 **epocEndPtr=0; // overwrite the directory separator with a 0 |
|
2254 (*epocEndPtr)++; // point past the 0 ready for the next one |
|
2255 return EFalse; |
|
2256 } |
|
2257 |
|
2258 |
|
2259 TBool CObeyFile::CheckHardwareVariants() |
|
2260 { |
|
2261 iPrimaries=new TRomBuilderEntry*[iNumberOfPrimaries]; |
|
2262 iVariants=new TRomBuilderEntry*[iNumberOfVariants]; |
|
2263 THardwareVariant* primaryHwVariants=new THardwareVariant[iNumberOfPrimaries]; |
|
2264 TInt nVar=0; |
|
2265 TRomBuilderEntry* current=FirstFile(); |
|
2266 THardwareVariant* variantHwVariants=new THardwareVariant[iNumberOfVariants]; |
|
2267 while(current) |
|
2268 { |
|
2269 if (current->Variant()) |
|
2270 { |
|
2271 TInt i; |
|
2272 for(i=0; i<nVar; i++) |
|
2273 { |
|
2274 if (!current->iHardwareVariant.MutuallyExclusive(variantHwVariants[i])) |
|
2275 { |
|
2276 delete[] variantHwVariants; |
|
2277 delete[] primaryHwVariants; |
|
2278 Print(EError,"Variants not mutually exclusive\n"); |
|
2279 return EFalse; |
|
2280 } |
|
2281 } |
|
2282 iVariants[nVar]=current; |
|
2283 variantHwVariants[nVar++]=current->iHardwareVariant; |
|
2284 } |
|
2285 current=NextFile(); |
|
2286 } |
|
2287 delete[] variantHwVariants; |
|
2288 nVar=0; |
|
2289 current=FirstFile(); |
|
2290 while(current) |
|
2291 { |
|
2292 TInt i; |
|
2293 for (i=0; i<iNumberOfVariants; i++) |
|
2294 { |
|
2295 if (iVariants[i]->iHardwareVariant<=current->iHardwareVariant) |
|
2296 break; |
|
2297 } |
|
2298 if (i==iNumberOfVariants) |
|
2299 { |
|
2300 Print(EError,"File %s[%08x] does not correspond to any variant\n", |
|
2301 current->iName,TUint(current->iHardwareVariant)); |
|
2302 delete[] primaryHwVariants; |
|
2303 return EFalse; |
|
2304 } |
|
2305 if (current->Primary()) |
|
2306 { |
|
2307 for(i=0; i<nVar; i++) |
|
2308 { |
|
2309 if (!current->iHardwareVariant.MutuallyExclusive(primaryHwVariants[i])) |
|
2310 { |
|
2311 delete[] primaryHwVariants; |
|
2312 Print(EError,"Primaries not mutually exclusive\n"); |
|
2313 return EFalse; |
|
2314 } |
|
2315 } |
|
2316 iPrimaries[nVar]=current; |
|
2317 primaryHwVariants[nVar++]=current->iHardwareVariant; |
|
2318 } |
|
2319 current=NextFile(); |
|
2320 } |
|
2321 delete[] primaryHwVariants; |
|
2322 if (iNumberOfExtensions) |
|
2323 { |
|
2324 nVar=0; |
|
2325 iExtensions=new TRomBuilderEntry*[iNumberOfExtensions]; |
|
2326 TRomBuilderEntry* current=FirstFile(); |
|
2327 while(current) |
|
2328 { |
|
2329 if (current->Extension()) |
|
2330 { |
|
2331 if (current->iHardwareVariant.IsVariant()) |
|
2332 { |
|
2333 TUint layer=current->iHardwareVariant.Layer(); |
|
2334 TUint vmask=current->iHardwareVariant.VMask(); |
|
2335 if ((iAllVariantsMask[layer]&vmask)==0) |
|
2336 { |
|
2337 Print(EError,"Variant-layer extension %s has no corresponding variant DLL\n",current->iName); |
|
2338 return EFalse; |
|
2339 } |
|
2340 } |
|
2341 iExtensions[nVar++]=current; |
|
2342 } |
|
2343 current=NextFile(); |
|
2344 } |
|
2345 } |
|
2346 if (iNumberOfDevices) |
|
2347 { |
|
2348 nVar=0; |
|
2349 iDevices=new TRomBuilderEntry*[iNumberOfDevices]; |
|
2350 TRomBuilderEntry* current=FirstFile(); |
|
2351 while(current) |
|
2352 { |
|
2353 if (current->Device()) |
|
2354 { |
|
2355 if (current->iHardwareVariant.IsVariant()) |
|
2356 { |
|
2357 TUint layer=current->iHardwareVariant.Layer(); |
|
2358 TUint vmask=current->iHardwareVariant.VMask(); |
|
2359 if ((iAllVariantsMask[layer]&vmask)==0) |
|
2360 { |
|
2361 Print(EError,"Variant-layer device %s has no corresponding variant DLL\n",current->iName); |
|
2362 return EFalse; |
|
2363 } |
|
2364 } |
|
2365 iDevices[nVar++]=current; |
|
2366 } |
|
2367 current=NextFile(); |
|
2368 } |
|
2369 } |
|
2370 NumberOfVariants=iNumberOfVariants; |
|
2371 return ETrue; |
|
2372 } |
|
2373 |
|
2374 |
|
2375 TInt CObeyFile::ProcessExtensionRom(MRomImage*& aKernelRom) |
|
2376 { |
|
2377 // |
|
2378 // First pass through the obey file to set up key variables |
|
2379 // |
|
2380 |
|
2381 iReader.Rewind(); |
|
2382 |
|
2383 enum EKeyword keyword; |
|
2384 |
|
2385 // Deal with the "extensionrom" keyword, which should be first |
|
2386 |
|
2387 if (iReader.NextLine(1,keyword) != KErrNone) |
|
2388 return KErrEof; |
|
2389 if (keyword != EKeywordExtensionRom) |
|
2390 return Print(EError, "Unexpected keyword '%s' at start of extension rom - line %d\n", |
|
2391 iReader.Word(0), iReader.CurrentLine()); |
|
2392 |
|
2393 iReader.CopyWord(1, iRomFileName); |
|
2394 Print(ELog, "\n========================================================\n"); |
|
2395 Print(ELog, "Extension ROM %s starting at line %d\n\n", iRomFileName, iReader.CurrentLine()); |
|
2396 |
|
2397 iReader.MarkNext(); // so that we rewind to the line after the extensionrom keyword |
|
2398 |
|
2399 while (iReader.NextLine(1,keyword) != KErrEof) |
|
2400 { |
|
2401 if (keyword == EKeywordExtensionRom) |
|
2402 break; |
|
2403 ProcessExtensionKeyword(keyword); |
|
2404 } |
|
2405 |
|
2406 if (!GotExtensionVariables(aKernelRom)) |
|
2407 return KErrGeneral; |
|
2408 |
|
2409 if (! CreateDefaultArea()) |
|
2410 return KErrGeneral; |
|
2411 |
|
2412 // |
|
2413 // second pass to process the file specifications in the obey file building |
|
2414 // up the TRomNode directory structure and the TRomBuilderEntry list |
|
2415 // |
|
2416 iReader.Rewind(); |
|
2417 |
|
2418 if (aKernelRom==0) |
|
2419 return Print(EError, "Option to extend a kernel ROM image not yet implemented\n"); |
|
2420 iLastExecutable = 0; |
|
2421 iRootDirectory = aKernelRom->CopyDirectory(iLastExecutable); |
|
2422 |
|
2423 |
|
2424 TInt align=0; |
|
2425 while (iReader.NextLine(2,keyword)!=KErrEof) |
|
2426 { |
|
2427 if (keyword == EKeywordExtensionRom) |
|
2428 break; |
|
2429 |
|
2430 switch (keyword) |
|
2431 { |
|
2432 case EKeywordSection: |
|
2433 case EKeywordArea: |
|
2434 case EKeywordPrimary: |
|
2435 case EKeywordSecondary: |
|
2436 case EKeywordExtension: |
|
2437 case EKeywordDevice: |
|
2438 case EKeywordVariant: |
|
2439 case EKeywordHardwareConfigRepositoryData: |
|
2440 Print(EError, "Keyword '%s' not supported in extension ROMs - line %d\n", |
|
2441 iReader.Word(0), iReader.CurrentLine()); |
|
2442 break; |
|
2443 |
|
2444 case EKeywordAlign: |
|
2445 if (iReader.ProcessAlign(align)!=KErrNone) |
|
2446 return KErrGeneral; |
|
2447 break; |
|
2448 |
|
2449 case EKeywordHide: |
|
2450 case EKeywordAlias: |
|
2451 case EKeywordRename: |
|
2452 if (!ProcessRenaming(keyword)) |
|
2453 return KErrGeneral; |
|
2454 break; |
|
2455 case EKeywordPatchDllData: |
|
2456 { |
|
2457 // Collect patchdata statements to process at the end |
|
2458 StringVector patchDataTokens; |
|
2459 SplitPatchDataStatement(patchDataTokens); |
|
2460 iPatchData->AddPatchDataStatement(patchDataTokens); |
|
2461 break; |
|
2462 } |
|
2463 |
|
2464 default: |
|
2465 if (!ProcessFile(align, keyword)) |
|
2466 return KErrGeneral; |
|
2467 align=0; |
|
2468 break; |
|
2469 } |
|
2470 } |
|
2471 |
|
2472 if( !ParsePatchDllData()) |
|
2473 return KErrGeneral; |
|
2474 |
|
2475 iReader.Mark(); // ready for processing the next extension rom(s) |
|
2476 |
|
2477 if (iMissingFiles!=0) |
|
2478 return KErrGeneral; |
|
2479 if (iNumberOfDataFiles+iNumberOfPeFiles==0) |
|
2480 { |
|
2481 Print(EError, "No files specified.\n"); |
|
2482 return KErrGeneral; |
|
2483 } |
|
2484 return KErrNone; |
|
2485 } |
|
2486 |
|
2487 void CObeyFile::ProcessExtensionKeyword(enum EKeyword aKeyword) |
|
2488 { |
|
2489 #ifdef __TOOLS2__ |
|
2490 istringstream val(iReader.Word(1)); |
|
2491 #else |
|
2492 istrstream val(iReader.Word(1),strlen(iReader.Word(1))); |
|
2493 #endif |
|
2494 |
|
2495 |
|
2496 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
2497 val >> setbase(0); |
|
2498 #endif //__MSVCDOTNET__ |
|
2499 |
|
2500 switch (aKeyword) |
|
2501 { |
|
2502 case EKeywordKernelRomName: |
|
2503 iReader.CopyWord(1, iKernelRomName); |
|
2504 return; |
|
2505 case EKeywordRomNameOdd: |
|
2506 iReader.CopyWord(1, iRomOddFileName); |
|
2507 return; |
|
2508 case EKeywordRomNameEven: |
|
2509 iReader.CopyWord(1, iRomEvenFileName); |
|
2510 return; |
|
2511 case EKeywordSRecordFileName: |
|
2512 iReader.CopyWord(1, iSRecordFileName); |
|
2513 return; |
|
2514 |
|
2515 case EKeywordRomLinearBase: |
|
2516 val >> iRomLinearBase; |
|
2517 return; |
|
2518 case EKeywordRomSize: |
|
2519 val >> iRomSize; |
|
2520 return; |
|
2521 case EKeywordRomAlign: |
|
2522 val >> iRomAlign; |
|
2523 return; |
|
2524 |
|
2525 case EKeywordDataAddress: |
|
2526 val >> iDataRunAddress; |
|
2527 return; |
|
2528 case EKeywordDefaultStackReserve: |
|
2529 val >> iDefaultStackReserve; |
|
2530 return; |
|
2531 case EKeywordVersion: |
|
2532 val >> iVersion; |
|
2533 return; |
|
2534 case EKeywordSRecordBase: |
|
2535 val >> iSRecordBase; |
|
2536 return; |
|
2537 case EKeywordRomChecksum: |
|
2538 val >> iCheckSum; |
|
2539 return; |
|
2540 case EKeywordTime: |
|
2541 iReader.ProcessTime(iTime); |
|
2542 return; |
|
2543 |
|
2544 case EKeywordTrace: |
|
2545 val >> TraceMask; |
|
2546 return; |
|
2547 |
|
2548 case EKeywordCollapse: |
|
2549 if (strnicmp(iReader.Word(1), "arm", 3)!=0 || strnicmp(iReader.Word(2), "gcc", 3)!=0) |
|
2550 { |
|
2551 Print(EWarning, "COLLAPSE only supported for ARM and GCC - keyword ignored\n"); |
|
2552 } |
|
2553 else |
|
2554 { |
|
2555 TInt cm; |
|
2556 #ifdef __TOOLS2__ |
|
2557 istringstream cmval(iReader.Word(3)); |
|
2558 #else |
|
2559 istrstream cmval(iReader.Word(3),strlen(iReader.Word(3))); |
|
2560 #endif |
|
2561 |
|
2562 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
2563 cmval >> setbase(0); |
|
2564 #endif //__MSVCDOTNET__ |
|
2565 |
|
2566 cmval>>cm; |
|
2567 if (cm<0 || cm>ECollapseAllChainBranches) |
|
2568 { |
|
2569 Print(EWarning, "COLLAPSE mode unrecognised - keyword ignored\n"); |
|
2570 } |
|
2571 else |
|
2572 { |
|
2573 Print(EWarning, "COLLAPSE not currently supported for extension roms\n"); |
|
2574 } |
|
2575 } |
|
2576 return; |
|
2577 |
|
2578 case EKeywordCoreImage: |
|
2579 //Already handled, skip it |
|
2580 return; |
|
2581 |
|
2582 default: |
|
2583 Print(EError,"Keyword '%s' not valid in extension ROMs - line %d\n", iReader.Word(0), iReader.CurrentLine()); |
|
2584 break; |
|
2585 } |
|
2586 return; |
|
2587 } |
|
2588 |
|
2589 TBool CObeyFile::GotExtensionVariables(MRomImage*& aRom) |
|
2590 // |
|
2591 // Checks that the obeyfile has supplied enough variables to continue |
|
2592 // |
|
2593 { |
|
2594 |
|
2595 TBool retVal=ETrue; |
|
2596 TText* kernelRomName = iKernelRomName; |
|
2597 |
|
2598 // Mandatory keywords |
|
2599 |
|
2600 if (iRomSize==0) |
|
2601 { |
|
2602 Print(EAlways,"The size of the extension ROM has not been supplied.\n"); |
|
2603 Print(EAlways,"Use the keyword \"romsize\".\n"); |
|
2604 retVal = EFalse; |
|
2605 } |
|
2606 |
|
2607 // keywords we need if we don't already have a ROM image to work from |
|
2608 |
|
2609 if (aRom==0) |
|
2610 { |
|
2611 if (iKernelRomName==0) |
|
2612 { |
|
2613 Print(EAlways,"The name of the kernel ROM has not been supplied.\n"); |
|
2614 Print(EAlways,"Use the keyword \"kernelromname\".\n"); |
|
2615 retVal = EFalse; |
|
2616 } |
|
2617 if (iRomLinearBase==0xFFFFFFFF) |
|
2618 { |
|
2619 Print(EAlways,"The base linear address of the ROM has not been supplied.\n"); |
|
2620 Print(EAlways,"Use the keyword \"romlinearbase\".\n"); |
|
2621 retVal = EFalse; |
|
2622 } |
|
2623 } |
|
2624 else |
|
2625 { |
|
2626 if (iKernelRomName != 0) |
|
2627 { |
|
2628 Print(EWarning,"Keyword \"kernelromname\") ignored.\n"); |
|
2629 } |
|
2630 kernelRomName = aRom->RomFileName(); |
|
2631 } |
|
2632 |
|
2633 // validation |
|
2634 |
|
2635 // Apply defaults as necessary |
|
2636 |
|
2637 if (iRomLinearBase==0xFFFFFFFF && aRom!=0) |
|
2638 { |
|
2639 iRomLinearBase = aRom->RomBase() + aRom->RomSize(); |
|
2640 Print(ELog,"Assuming extension ROM is contiguous with kernel ROM\n"); |
|
2641 Print(ELog,"Setting romlinearbase to 0x%08x\n", iRomLinearBase); |
|
2642 } |
|
2643 TheRomLinearAddress=iRomLinearBase; |
|
2644 |
|
2645 if (iDataRunAddress==0) |
|
2646 { |
|
2647 iDataRunAddress= aRom->DataRunAddress(); |
|
2648 Print(EWarning,"The address for a running ROM app's data section (keyword \"dataaddress\") has not been supplied.\n"); |
|
2649 Print(EWarning,"Will use the default value of 0x%0x.\n", iDataRunAddress); |
|
2650 } |
|
2651 if (iRomAlign==0) |
|
2652 { |
|
2653 iRomAlign = aRom->RomAlign(); |
|
2654 Print(EWarning,"The ROM section alignment (keyword \"romalign\") has not been supplied.\n"); |
|
2655 Print(EWarning,"Will use the default value of 0x%0x.\n", iRomAlign); |
|
2656 } |
|
2657 if (iRomAlign&0x3) |
|
2658 { |
|
2659 Print(EWarning, "Rounding rom alignment to multiple of 4.\n"); |
|
2660 iRomAlign=(iRomAlign+0x3)&0xfffffffc; |
|
2661 } |
|
2662 if (iTime==0) |
|
2663 { |
|
2664 Print(ELog, "No timestamp specified. Using current time...\n"); |
|
2665 ObeyFileReader::TimeNow(iTime); |
|
2666 } |
|
2667 |
|
2668 // fix up "*" in romname |
|
2669 TText newname[256]; |
|
2670 TText* p=newname; |
|
2671 TText* q=iRomFileName; |
|
2672 TText c; |
|
2673 |
|
2674 while ((c=*q++)!='\0') |
|
2675 { |
|
2676 if (c!='*') |
|
2677 { |
|
2678 *p++=c; |
|
2679 continue; |
|
2680 } |
|
2681 TText *r=kernelRomName; |
|
2682 while ((c=*r++)!='\0') |
|
2683 *p++=c; |
|
2684 } |
|
2685 *p = '\0'; |
|
2686 free(iRomFileName); |
|
2687 iRomFileName = (TText*)strdup((char*)newname); |
|
2688 |
|
2689 Print(ELog, "\nCreating Rom image %s\n", iRomFileName); |
|
2690 return retVal; |
|
2691 } |
|
2692 |
|
2693 |
|
2694 //////////////////////////////////////////////////////////////////////// |
|
2695 // AREA RELATED CODE |
|
2696 //////////////////////////////////////////////////////////////////////// |
|
2697 |
|
2698 /** |
|
2699 Process an area declaration. |
|
2700 */ |
|
2701 |
|
2702 TBool CObeyFile::ParseAreaKeyword() |
|
2703 { |
|
2704 const char* name = iReader.Word(1); |
|
2705 TLinAddr start; |
|
2706 TUint length; |
|
2707 if(Val(start, iReader.Word(2)) != KErrNone || Val(length, iReader.Word(3)) != KErrNone) |
|
2708 { |
|
2709 Print(EError, "Line %d: Wrong area specification: Should be <name> <start address> <length>\n", |
|
2710 iReader.CurrentLine()); |
|
2711 return EFalse; |
|
2712 } |
|
2713 |
|
2714 if (! AddAreaAndHandleError(name, start, length, iReader.CurrentLine())) |
|
2715 return EFalse; |
|
2716 |
|
2717 return ETrue; |
|
2718 } |
|
2719 |
|
2720 |
|
2721 /** |
|
2722 Process an "area=xxx" file attribute. |
|
2723 */ |
|
2724 |
|
2725 TBool CObeyFile::ParseAreaAttribute(const TText* aArg, TInt aLineNumber, const Area*& aArea) |
|
2726 { |
|
2727 if (iSectionPosition != -1) |
|
2728 { |
|
2729 Print(EError, "Line %d: Relocation to area forbidden in second section\n", aLineNumber); |
|
2730 return EFalse; |
|
2731 } |
|
2732 |
|
2733 aArea = iAreaSet.FindByName(reinterpret_cast<const char*>(aArg)); |
|
2734 if (aArea == 0) |
|
2735 { |
|
2736 Print(EError, "Line %d: Attempt to use an unknown area named '%s'\n", aLineNumber, aArg); |
|
2737 return EFalse; |
|
2738 } |
|
2739 |
|
2740 return ETrue; |
|
2741 } |
|
2742 |
|
2743 |
|
2744 TBool CObeyFile::CreateDefaultArea() |
|
2745 { |
|
2746 return AddAreaAndHandleError(AreaSet::KDefaultAreaName, iRomLinearBase, iRomSize); |
|
2747 } |
|
2748 |
|
2749 |
|
2750 TBool CObeyFile::AddAreaAndHandleError(const char* aName, TLinAddr aDestBaseAddr, TUint aLength, TInt aLineNumber) |
|
2751 { |
|
2752 TBool added = EFalse; |
|
2753 |
|
2754 const char lineInfoFmt[] = "Line %d:"; |
|
2755 char lineInfo[sizeof(lineInfoFmt)+10]; |
|
2756 if (aLineNumber > 0) |
|
2757 sprintf(lineInfo, lineInfoFmt, aLineNumber); |
|
2758 else |
|
2759 lineInfo[0] = '\0'; |
|
2760 |
|
2761 const char* overlappingArea; |
|
2762 switch (iAreaSet.AddArea(aName, aDestBaseAddr, aLength, overlappingArea)) |
|
2763 { |
|
2764 case AreaSet::EAdded: |
|
2765 TRACE(TAREA, Print(EScreen, "Area '%s' added to AreaSet\n", aName)); |
|
2766 added = ETrue; |
|
2767 break; |
|
2768 case AreaSet::EOverlap: |
|
2769 Print(EError, "%s Area '%s' collides with area '%s'\n", lineInfo, aName, overlappingArea); |
|
2770 break; |
|
2771 case AreaSet::EDuplicateName: |
|
2772 Print(EError, "%s Name '%s' already reserved for another area\n", lineInfo, aName); |
|
2773 break; |
|
2774 case AreaSet::EOverflow: |
|
2775 Print(EError, "%s Area overflow (0x%X+0x%X > 0x%X)\n", lineInfo, aDestBaseAddr, aLength, -1); |
|
2776 break; |
|
2777 default: |
|
2778 assert(0); // can't happen |
|
2779 } |
|
2780 |
|
2781 return added; |
|
2782 } |
|
2783 |
|
2784 TInt getNumber(TText*); |
|
2785 |
|
2786 |
|
2787 // Fuction to split patchdata statement |
|
2788 void CObeyFile::SplitPatchDataStatement(StringVector& aPatchDataTokens) |
|
2789 { |
|
2790 // Get the value of symbol size, address/ordinal and new value |
|
2791 // to be patched from the patchdata statement. |
|
2792 // Syntax of patchdata statements is as follows: |
|
2793 // 1) patchdata dll_name ordinal OrdinalNumber size_in_bytes new_value |
|
2794 // 2) patchdata dll_name addr Address size_in_bytes new_value |
|
2795 for(TInt count=1; count<=5; count++) |
|
2796 { |
|
2797 aPatchDataTokens.push_back(iReader.Word(count)); |
|
2798 } |
|
2799 |
|
2800 // Store the the value of current line which will be used |
|
2801 // when displaying error messages. |
|
2802 OutputStringStream outStrStream; |
|
2803 outStrStream << iReader.CurrentLine(); |
|
2804 aPatchDataTokens.push_back(outStrStream.str()); |
|
2805 } |
|
2806 |
|
2807 TBool CObeyFile::ParsePatchDllData() |
|
2808 { |
|
2809 // Get the list of patchdata statements |
|
2810 VectorOfStringVector patchDataStatements=iPatchData->GetPatchDataStatements(); |
|
2811 // Get the list of renamed file map |
|
2812 MapOfString RenamedFileMap=iPatchData->GetRenamedFileMap(); |
|
2813 DllDataEntry *aDllDataEntry=NULL; |
|
2814 |
|
2815 for(TUint count=0; count<patchDataStatements.size(); count++) |
|
2816 { |
|
2817 StringVector strVector = patchDataStatements.at(count); |
|
2818 String filename=strVector.at(0); |
|
2819 String lineNoStr = strVector.at(5); |
|
2820 TUint lineNo=getNumber(((TText*)lineNoStr.c_str())); |
|
2821 TRomNode* existingFile = NULL; |
|
2822 |
|
2823 do |
|
2824 { |
|
2825 TUint hardwareVariant=ParseVariant(); |
|
2826 TRomNode* dir=iRootDirectory; |
|
2827 TBool endOfName=EFalse; |
|
2828 |
|
2829 TText *epocStartPtr=IsValidFilePath((TText*)filename.c_str()); |
|
2830 if (epocStartPtr==NULL) |
|
2831 { |
|
2832 Print(EError, "Invalid source path on line %d\n",lineNo); |
|
2833 return EFalse; |
|
2834 } |
|
2835 epocStartPtr = (TText*)NormaliseFileName((const char*)epocStartPtr); |
|
2836 TText *epocEndPtr=epocStartPtr; |
|
2837 |
|
2838 while (!endOfName) |
|
2839 { |
|
2840 endOfName = GetNextBitOfFileName(&epocEndPtr); |
|
2841 if (endOfName) // file |
|
2842 { |
|
2843 existingFile=dir->FindInDirectory(epocStartPtr,hardwareVariant,TRUE); |
|
2844 if (existingFile) |
|
2845 { |
|
2846 TInt fileCount=0; |
|
2847 TInt dirCount=0; |
|
2848 existingFile->CountDirectory(fileCount, dirCount); |
|
2849 if (dirCount != 0 || fileCount != 0) |
|
2850 { |
|
2851 Print(EError, "Keyword %s not applicable to directories - line %d\n","patchdata",lineNo); |
|
2852 return EFalse; |
|
2853 } |
|
2854 } |
|
2855 } |
|
2856 else // directory |
|
2857 { |
|
2858 TRomNode* subDir = dir->FindInDirectory(epocStartPtr); |
|
2859 if (!subDir) // sub directory does not exist |
|
2860 break; |
|
2861 dir=subDir; |
|
2862 epocStartPtr = epocEndPtr; |
|
2863 } |
|
2864 } |
|
2865 |
|
2866 if( !existingFile ) |
|
2867 { |
|
2868 MapOfStringIterator RenamedFileMapIterator; |
|
2869 |
|
2870 // If the E32Image file to be patched is not included then check if the |
|
2871 // file was renamed. |
|
2872 if ((RenamedFileMapIterator=RenamedFileMap.find(filename)) != RenamedFileMap.end()) |
|
2873 filename = (*RenamedFileMapIterator).second; |
|
2874 else |
|
2875 { |
|
2876 Print(EError, "File %s not found - line %d\n", filename.c_str(), lineNo); |
|
2877 return EFalse; |
|
2878 } |
|
2879 } |
|
2880 }while(!existingFile); |
|
2881 |
|
2882 TUint32 aSize, aOrdinal, aNewValue, aOffset; |
|
2883 TLinAddr aDataAddr; |
|
2884 |
|
2885 aOrdinal = (TUint32)-1; |
|
2886 aDataAddr = (TUint32)-1; |
|
2887 aOffset = 0; |
|
2888 |
|
2889 String symbolSize = strVector.at(3); |
|
2890 aSize = getNumber((TText*)symbolSize.c_str()); |
|
2891 String aValue = strVector.at(4); |
|
2892 aNewValue = getNumber( (TText*)aValue.c_str()); |
|
2893 |
|
2894 DllDataEntry *dataEntry = new DllDataEntry(aSize, aNewValue); |
|
2895 |
|
2896 // Set the address of the data or the ordinal number specified in OBY statement. |
|
2897 String keyword = strVector.at(1); |
|
2898 String keywordValue = strVector.at(2); |
|
2899 |
|
2900 /* Check for +OFFSET at the end of the ordinal number or address */ |
|
2901 TUint plus = keywordValue.find("+",0); |
|
2902 if (plus != std::string::npos) |
|
2903 { |
|
2904 /* Get the offset that we found after the + sign */ |
|
2905 String offset = keywordValue.substr(plus+1); |
|
2906 aOffset = getNumber((TText*)offset.c_str()); |
|
2907 |
|
2908 keywordValue.resize(plus); |
|
2909 } |
|
2910 if(stricmp ((char*)keyword.c_str(), "addr") == 0) |
|
2911 aDataAddr = getNumber((TText*)keywordValue.c_str()); |
|
2912 |
|
2913 else |
|
2914 aOrdinal = getNumber((TText*)keywordValue.c_str()); |
|
2915 |
|
2916 dataEntry->iDataAddress = aDataAddr; |
|
2917 dataEntry->iOrdinal = aOrdinal; |
|
2918 dataEntry->iOffset = aOffset; |
|
2919 dataEntry->iRomNode = existingFile; |
|
2920 |
|
2921 if (aDllDataEntry==NULL) |
|
2922 { |
|
2923 // Set the first node of the patchdata linked list |
|
2924 aDllDataEntry = dataEntry; |
|
2925 SetFirstDllDataEntry(aDllDataEntry); |
|
2926 } |
|
2927 else |
|
2928 { |
|
2929 // Add the new node at the end of linked list |
|
2930 aDllDataEntry->AddDllDataEntry(dataEntry); |
|
2931 aDllDataEntry = aDllDataEntry->NextDllDataEntry(); |
|
2932 } |
|
2933 } |
|
2934 return ETrue; |
|
2935 } |
|
2936 |
|
2937 int CObeyFile::SkipToExtension() |
|
2938 { |
|
2939 int found = 0; |
|
2940 |
|
2941 iReader.Rewind(); |
|
2942 enum EKeyword keyword; |
|
2943 while (iReader.NextLine(1,keyword) != KErrEof) |
|
2944 { |
|
2945 if (keyword == EKeywordExtensionRom) |
|
2946 { |
|
2947 found = 1; |
|
2948 iReader.Mark(); // ready for processing extension |
|
2949 break; |
|
2950 } |
|
2951 } |
|
2952 |
|
2953 if(!found) |
|
2954 { |
|
2955 Print(EError, "Coreimage option requires valid \"extensionrom\" keyword\n"); |
|
2956 } |
|
2957 |
|
2958 return found; |
|
2959 } |
|
2960 |
|
2961 TText* CObeyFile::ProcessCoreImage() |
|
2962 { |
|
2963 // check for coreimage keyword and return filename |
|
2964 iReader.Rewind(); |
|
2965 enum EKeyword keyword; |
|
2966 TText* coreImageFileName = 0; |
|
2967 |
|
2968 iRomAlign = KDefaultRomAlign; |
|
2969 iDataRunAddress = KDefaultDataRunAddress; |
|
2970 |
|
2971 while (iReader.NextLine(1,keyword) != KErrEof) |
|
2972 { |
|
2973 if (keyword == EKeywordCoreImage) |
|
2974 { |
|
2975 istringstream val(iReader.Word(1),ios_base::in|ios_base::out); |
|
2976 iReader.CopyWord(1, coreImageFileName); |
|
2977 break; |
|
2978 } |
|
2979 else if ((keyword == EKeywordRomAlign) || (keyword == EKeywordDataAddress)) |
|
2980 { |
|
2981 #ifdef __TOOLS2__ |
|
2982 istringstream val(iReader.Word(1)); |
|
2983 #else |
|
2984 istrstream val(iReader.Word(1),strlen(iReader.Word(1))); |
|
2985 #endif |
|
2986 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
2987 val >> setbase(0); |
|
2988 #endif //__MSVCDOTNET__ |
|
2989 if(keyword == EKeywordRomAlign) |
|
2990 { |
|
2991 val >> iRomAlign; |
|
2992 } |
|
2993 else |
|
2994 { |
|
2995 val >> iDataRunAddress; |
|
2996 } |
|
2997 } |
|
2998 } |
|
2999 |
|
3000 if (iRomAlign&0x3) |
|
3001 { |
|
3002 //Rounding rom alignment to multiple of 4 |
|
3003 iRomAlign=(iRomAlign+0x3)&0xfffffffc; |
|
3004 } |
|
3005 |
|
3006 return coreImageFileName; |
|
3007 } |
|
3008 |