New EdkShell binaries.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FdfParser.py
CommitLineData
30fdf114
LG
1## @file\r
2# parse FDF file\r
3#\r
e8a47801 4# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>\r
30fdf114 5#\r
40d841f6 6# This program and the accompanying materials\r
30fdf114
LG
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15##\r
16# Import Modules\r
17#\r
0d2711a6
LG
18import re\r
19\r
30fdf114
LG
20import Fd\r
21import Region\r
22import Fv\r
23import AprioriSection\r
24import FfsInfStatement\r
25import FfsFileStatement\r
26import VerSection\r
27import UiSection\r
28import FvImageSection\r
29import DataSection\r
30import DepexSection\r
31import CompressSection\r
32import GuidSection\r
33import Capsule\r
34import CapsuleData\r
35import Rule\r
36import RuleComplexFile\r
37import RuleSimpleFile\r
38import EfiSection\r
39import Vtf\r
40import ComponentStatement\r
41import OptionRom\r
42import OptRomInfStatement\r
43import OptRomFileStatement\r
44\r
52302d4d 45from GenFdsGlobalVariable import GenFdsGlobalVariable\r
30fdf114
LG
46from Common.BuildToolError import *\r
47from Common import EdkLogger\r
14c48571 48from Common.Misc import PathClass\r
49from Common.String import NormPath\r
0d2711a6
LG
50import Common.GlobalData as GlobalData\r
51from Common.Expression import *\r
df692f02 52from Common import GlobalData\r
2bcc713e 53from Common.String import ReplaceMacro\r
30fdf114 54\r
d0acc87a
LG
55from Common.Misc import tdict\r
56\r
30fdf114
LG
57import re\r
58import os\r
59\r
60##define T_CHAR_SPACE ' '\r
61##define T_CHAR_NULL '\0'\r
62##define T_CHAR_CR '\r'\r
63##define T_CHAR_TAB '\t'\r
64##define T_CHAR_LF '\n'\r
65##define T_CHAR_SLASH '/'\r
66##define T_CHAR_BACKSLASH '\\'\r
67##define T_CHAR_DOUBLE_QUOTE '\"'\r
68##define T_CHAR_SINGLE_QUOTE '\''\r
69##define T_CHAR_STAR '*'\r
70##define T_CHAR_HASH '#'\r
71\r
72(T_CHAR_SPACE, T_CHAR_NULL, T_CHAR_CR, T_CHAR_TAB, T_CHAR_LF, T_CHAR_SLASH, \\r
73T_CHAR_BACKSLASH, T_CHAR_DOUBLE_QUOTE, T_CHAR_SINGLE_QUOTE, T_CHAR_STAR, T_CHAR_HASH) = \\r
74(' ', '\0', '\r', '\t', '\n', '/', '\\', '\"', '\'', '*', '#')\r
75\r
76SEPERATOR_TUPLE = ('=', '|', ',', '{', '}')\r
77\r
0d2711a6
LG
78RegionSizePattern = re.compile("\s*(?P<base>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<size>(?:0x|0X)?[a-fA-F0-9]+)\s*")\r
79RegionSizeGuidPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*\|\s*(?P<size>\w+\.\w+)\s*")\r
64b2609f 80ShortcutPcdPattern = re.compile("\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*")\r
0d2711a6 81\r
30fdf114 82IncludeFileList = []\r
30fdf114
LG
83\r
84def GetRealFileLine (File, Line):\r
85\r
86 InsertedLines = 0\r
87 for Profile in IncludeFileList:\r
88 if Line >= Profile.InsertStartLineNumber and Line < Profile.InsertStartLineNumber + Profile.InsertAdjust + len(Profile.FileLinesList):\r
89 return (Profile.FileName, Line - Profile.InsertStartLineNumber + 1)\r
90 if Line >= Profile.InsertStartLineNumber + Profile.InsertAdjust + len(Profile.FileLinesList):\r
91 InsertedLines += Profile.InsertAdjust + len(Profile.FileLinesList)\r
92\r
93 return (File, Line - InsertedLines)\r
94\r
95## The exception class that used to report error messages when parsing FDF\r
96#\r
97# Currently the "ToolName" is set to be "FDF Parser".\r
98#\r
99class Warning (Exception):\r
100 ## The constructor\r
101 #\r
102 # @param self The object pointer\r
103 # @param Str The message to record\r
104 # @param File The FDF name\r
105 # @param Line The Line number that error occurs\r
106 #\r
107 def __init__(self, Str, File = None, Line = None):\r
108\r
109 FileLineTuple = GetRealFileLine(File, Line)\r
110 self.FileName = FileLineTuple[0]\r
111 self.LineNumber = FileLineTuple[1]\r
112 self.Message = Str\r
113 self.ToolName = 'FdfParser'\r
114\r
115 def __str__(self):\r
116 return self.Message\r
117\r
118## The MACRO class that used to record macro value data when parsing include file\r
119#\r
120#\r
121class MacroProfile :\r
122 ## The constructor\r
123 #\r
124 # @param self The object pointer\r
125 # @param FileName The file that to be parsed\r
126 #\r
127 def __init__(self, FileName, Line):\r
128 self.FileName = FileName\r
129 self.DefinedAtLine = Line\r
130 self.MacroName = None\r
131 self.MacroValue = None\r
132\r
133## The Include file content class that used to record file data when parsing include file\r
134#\r
135# May raise Exception when opening file.\r
136#\r
137class IncludeFileProfile :\r
138 ## The constructor\r
139 #\r
140 # @param self The object pointer\r
141 # @param FileName The file that to be parsed\r
142 #\r
143 def __init__(self, FileName):\r
144 self.FileName = FileName\r
145 self.FileLinesList = []\r
146 try:\r
147 fsock = open(FileName, "rb", 0)\r
148 try:\r
149 self.FileLinesList = fsock.readlines()\r
150 finally:\r
151 fsock.close()\r
152\r
153 except:\r
154 EdkLogger.error("FdfParser", FILE_OPEN_FAILURE, ExtraData=FileName)\r
155\r
156 self.InsertStartLineNumber = None\r
157 self.InsertAdjust = 0\r
158\r
159## The FDF content class that used to record file data when parsing FDF\r
160#\r
161# May raise Exception when opening file.\r
162#\r
163class FileProfile :\r
164 ## The constructor\r
165 #\r
166 # @param self The object pointer\r
167 # @param FileName The file that to be parsed\r
168 #\r
169 def __init__(self, FileName):\r
170 self.FileLinesList = []\r
171 try:\r
172 fsock = open(FileName, "rb", 0)\r
173 try:\r
174 self.FileLinesList = fsock.readlines()\r
175 finally:\r
176 fsock.close()\r
177\r
178 except:\r
179 EdkLogger.error("FdfParser", FILE_OPEN_FAILURE, ExtraData=FileName)\r
180\r
181\r
182 self.PcdDict = {}\r
183 self.InfList = []\r
d0acc87a
LG
184 # ECC will use this Dict and List information\r
185 self.PcdFileLineDict = {}\r
186 self.InfFileLineList = []\r
187 \r
30fdf114 188 self.FdDict = {}\r
52302d4d 189 self.FdNameNotSet = False\r
30fdf114 190 self.FvDict = {}\r
fd171542 191 self.CapsuleDict = {}\r
30fdf114
LG
192 self.VtfList = []\r
193 self.RuleDict = {}\r
194 self.OptRomDict = {}\r
195\r
196## The syntax parser for FDF\r
197#\r
198# PreprocessFile method should be called prior to ParseFile\r
199# CycleReferenceCheck method can detect cycles in FDF contents\r
200#\r
201# GetNext*** procedures mean these procedures will get next token first, then make judgement.\r
202# Get*** procedures mean these procedures will make judgement on current token only.\r
203#\r
204class FdfParser:\r
205 ## The constructor\r
206 #\r
207 # @param self The object pointer\r
208 # @param FileName The file that to be parsed\r
209 #\r
210 def __init__(self, FileName):\r
211 self.Profile = FileProfile(FileName)\r
212 self.FileName = FileName\r
213 self.CurrentLineNumber = 1\r
214 self.CurrentOffsetWithinLine = 0\r
215 self.CurrentFdName = None\r
216 self.CurrentFvName = None\r
217 self.__Token = ""\r
218 self.__SkippedChars = ""\r
219\r
d0acc87a
LG
220 # Used to section info\r
221 self.__CurSection = []\r
222 # Key: [section name, UI name, arch]\r
223 # Value: {MACRO_NAME : MACRO_VALUE}\r
224 self.__MacroDict = tdict(True, 3)\r
225 self.__PcdDict = {}\r
226\r
30fdf114 227 self.__WipeOffArea = []\r
14c48571 228 if GenFdsGlobalVariable.WorkSpaceDir == '':\r
229 GenFdsGlobalVariable.WorkSpaceDir = os.getenv("WORKSPACE")\r
30fdf114
LG
230\r
231 ## __IsWhiteSpace() method\r
232 #\r
233 # Whether char at current FileBufferPos is whitespace\r
234 #\r
235 # @param self The object pointer\r
236 # @param Char The char to test\r
237 # @retval True The char is a kind of white space\r
238 # @retval False The char is NOT a kind of white space\r
239 #\r
240 def __IsWhiteSpace(self, Char):\r
241 if Char in (T_CHAR_NULL, T_CHAR_CR, T_CHAR_SPACE, T_CHAR_TAB, T_CHAR_LF):\r
242 return True\r
243 else:\r
244 return False\r
245\r
246 ## __SkipWhiteSpace() method\r
247 #\r
248 # Skip white spaces from current char, return number of chars skipped\r
249 #\r
250 # @param self The object pointer\r
251 # @retval Count The number of chars skipped\r
252 #\r
253 def __SkipWhiteSpace(self):\r
254 Count = 0\r
255 while not self.__EndOfFile():\r
256 Count += 1\r
257 if self.__CurrentChar() in (T_CHAR_NULL, T_CHAR_CR, T_CHAR_LF, T_CHAR_SPACE, T_CHAR_TAB):\r
258 self.__SkippedChars += str(self.__CurrentChar())\r
259 self.__GetOneChar()\r
260\r
261 else:\r
262 Count = Count - 1\r
263 return Count\r
264\r
265 ## __EndOfFile() method\r
266 #\r
267 # Judge current buffer pos is at file end\r
268 #\r
269 # @param self The object pointer\r
270 # @retval True Current File buffer position is at file end\r
271 # @retval False Current File buffer position is NOT at file end\r
272 #\r
273 def __EndOfFile(self):\r
274 NumberOfLines = len(self.Profile.FileLinesList)\r
275 SizeOfLastLine = len(self.Profile.FileLinesList[-1])\r
276 if self.CurrentLineNumber == NumberOfLines and self.CurrentOffsetWithinLine >= SizeOfLastLine - 1:\r
277 return True\r
278 elif self.CurrentLineNumber > NumberOfLines:\r
279 return True\r
280 else:\r
281 return False\r
282\r
283 ## __EndOfLine() method\r
284 #\r
285 # Judge current buffer pos is at line end\r
286 #\r
287 # @param self The object pointer\r
288 # @retval True Current File buffer position is at line end\r
289 # @retval False Current File buffer position is NOT at line end\r
290 #\r
291 def __EndOfLine(self):\r
292 if self.CurrentLineNumber > len(self.Profile.FileLinesList):\r
293 return True\r
294 SizeOfCurrentLine = len(self.Profile.FileLinesList[self.CurrentLineNumber - 1])\r
295 if self.CurrentOffsetWithinLine >= SizeOfCurrentLine:\r
296 return True\r
297 else:\r
298 return False\r
299\r
300 ## Rewind() method\r
301 #\r
302 # Reset file data buffer to the initial state\r
303 #\r
304 # @param self The object pointer\r
305 #\r
306 def Rewind(self):\r
307 self.CurrentLineNumber = 1\r
308 self.CurrentOffsetWithinLine = 0\r
309\r
310 ## __UndoOneChar() method\r
311 #\r
312 # Go back one char in the file buffer\r
313 #\r
314 # @param self The object pointer\r
315 # @retval True Successfully go back one char\r
316 # @retval False Not able to go back one char as file beginning reached\r
317 #\r
318 def __UndoOneChar(self):\r
319\r
320 if self.CurrentLineNumber == 1 and self.CurrentOffsetWithinLine == 0:\r
321 return False\r
322 elif self.CurrentOffsetWithinLine == 0:\r
323 self.CurrentLineNumber -= 1\r
324 self.CurrentOffsetWithinLine = len(self.__CurrentLine()) - 1\r
325 else:\r
326 self.CurrentOffsetWithinLine -= 1\r
327 return True\r
328\r
329 ## __GetOneChar() method\r
330 #\r
331 # Move forward one char in the file buffer\r
332 #\r
333 # @param self The object pointer\r
334 #\r
335 def __GetOneChar(self):\r
336 if self.CurrentOffsetWithinLine == len(self.Profile.FileLinesList[self.CurrentLineNumber - 1]) - 1:\r
0d2711a6
LG
337 self.CurrentLineNumber += 1\r
338 self.CurrentOffsetWithinLine = 0\r
30fdf114 339 else:\r
0d2711a6 340 self.CurrentOffsetWithinLine += 1\r
30fdf114
LG
341\r
342 ## __CurrentChar() method\r
343 #\r
344 # Get the char pointed to by the file buffer pointer\r
345 #\r
346 # @param self The object pointer\r
347 # @retval Char Current char\r
348 #\r
349 def __CurrentChar(self):\r
350 return self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine]\r
351\r
352 ## __NextChar() method\r
353 #\r
354 # Get the one char pass the char pointed to by the file buffer pointer\r
355 #\r
356 # @param self The object pointer\r
357 # @retval Char Next char\r
358 #\r
359 def __NextChar(self):\r
360 if self.CurrentOffsetWithinLine == len(self.Profile.FileLinesList[self.CurrentLineNumber - 1]) - 1:\r
361 return self.Profile.FileLinesList[self.CurrentLineNumber][0]\r
362 else:\r
363 return self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine + 1]\r
364\r
365 ## __SetCurrentCharValue() method\r
366 #\r
367 # Modify the value of current char\r
368 #\r
369 # @param self The object pointer\r
370 # @param Value The new value of current char\r
371 #\r
372 def __SetCurrentCharValue(self, Value):\r
373 self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine] = Value\r
374\r
375 ## __CurrentLine() method\r
376 #\r
377 # Get the list that contains current line contents\r
378 #\r
379 # @param self The object pointer\r
380 # @retval List current line contents\r
381 #\r
382 def __CurrentLine(self):\r
383 return self.Profile.FileLinesList[self.CurrentLineNumber - 1]\r
384\r
385 def __StringToList(self):\r
386 self.Profile.FileLinesList = [list(s) for s in self.Profile.FileLinesList]\r
387 self.Profile.FileLinesList[-1].append(' ')\r
388\r
30fdf114
LG
389 def __ReplaceFragment(self, StartPos, EndPos, Value = ' '):\r
390 if StartPos[0] == EndPos[0]:\r
391 Offset = StartPos[1]\r
392 while Offset <= EndPos[1]:\r
393 self.Profile.FileLinesList[StartPos[0]][Offset] = Value\r
394 Offset += 1\r
395 return\r
396\r
397 Offset = StartPos[1]\r
398 while self.Profile.FileLinesList[StartPos[0]][Offset] not in ('\r', '\n'):\r
399 self.Profile.FileLinesList[StartPos[0]][Offset] = Value\r
400 Offset += 1\r
401\r
402 Line = StartPos[0]\r
403 while Line < EndPos[0]:\r
404 Offset = 0\r
405 while self.Profile.FileLinesList[Line][Offset] not in ('\r', '\n'):\r
406 self.Profile.FileLinesList[Line][Offset] = Value\r
407 Offset += 1\r
408 Line += 1\r
409\r
410 Offset = 0\r
411 while Offset <= EndPos[1]:\r
412 self.Profile.FileLinesList[EndPos[0]][Offset] = Value\r
413 Offset += 1\r
414\r
415\r
d5d56f1b
LG
416 def __GetMacroName(self):\r
417 if not self.__GetNextToken():\r
418 raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)\r
419 MacroName = self.__Token\r
420 NotFlag = False\r
421 if MacroName.startswith('!'):\r
422 NotFlag = True\r
423 MacroName = MacroName[1:].strip()\r
424 \r
425 if not MacroName.startswith('$(') or not MacroName.endswith(')'):\r
426 raise Warning("Macro name expected(Please use '$(%(Token)s)' if '%(Token)s' is a macro.)" % {"Token" : MacroName},\r
427 self.FileName, self.CurrentLineNumber)\r
428 MacroName = MacroName[2:-1]\r
429 return MacroName, NotFlag\r
d0acc87a
LG
430\r
431 def __SetMacroValue(self, Macro, Value):\r
432 if not self.__CurSection:\r
433 return\r
434\r
435 MacroDict = {}\r
436 if not self.__MacroDict[self.__CurSection[0], self.__CurSection[1], self.__CurSection[2]]:\r
437 self.__MacroDict[self.__CurSection[0], self.__CurSection[1], self.__CurSection[2]] = MacroDict\r
438 else:\r
439 MacroDict = self.__MacroDict[self.__CurSection[0], self.__CurSection[1], self.__CurSection[2]]\r
440 MacroDict[Macro] = Value\r
441\r
442 def __GetMacroValue(self, Macro):\r
443 # Highest priority\r
444 if Macro in GlobalData.gCommandLineDefines:\r
445 return GlobalData.gCommandLineDefines[Macro]\r
446 if Macro in GlobalData.gGlobalDefines:\r
447 return GlobalData.gGlobalDefines[Macro]\r
448\r
449 if self.__CurSection:\r
450 MacroDict = self.__MacroDict[\r
451 self.__CurSection[0],\r
452 self.__CurSection[1],\r
453 self.__CurSection[2]\r
454 ]\r
455 if MacroDict and Macro in MacroDict:\r
456 return MacroDict[Macro]\r
457\r
458 # Lowest priority\r
459 if Macro in GlobalData.gPlatformDefines:\r
460 return GlobalData.gPlatformDefines[Macro]\r
461 return None\r
462\r
463 def __SectionHeaderParser(self, Section):\r
464 # [Defines]\r
465 # [FD.UiName]: use dummy instead if UI name is optional\r
466 # [FV.UiName]\r
467 # [Capsule.UiName]\r
468 # [Rule]: don't take rule section into account, macro is not allowed in this section\r
469 # [VTF.arch.UiName, arch]\r
470 # [OptionRom.DriverName]\r
471 self.__CurSection = []\r
472 Section = Section.strip()[1:-1].upper().replace(' ', '').strip('.')\r
473 ItemList = Section.split('.')\r
474 Item = ItemList[0]\r
475 if Item == '' or Item == 'RULE':\r
476 return\r
477\r
478 if Item == 'DEFINES':\r
479 self.__CurSection = ['COMMON', 'COMMON', 'COMMON']\r
480 elif Item == 'VTF' and len(ItemList) == 3:\r
481 UiName = ItemList[2]\r
482 Pos = UiName.find(',')\r
483 if Pos != -1:\r
484 UiName = UiName[:Pos]\r
485 self.__CurSection = ['VTF', UiName, ItemList[1]]\r
486 elif len(ItemList) > 1:\r
487 self.__CurSection = [ItemList[0], ItemList[1], 'COMMON']\r
488 elif len(ItemList) > 0:\r
489 self.__CurSection = [ItemList[0], 'DUMMY', 'COMMON']\r
490\r
30fdf114
LG
491 ## PreprocessFile() method\r
492 #\r
493 # Preprocess file contents, replace comments with spaces.\r
494 # In the end, rewind the file buffer pointer to the beginning\r
495 # BUGBUG: No !include statement processing contained in this procedure\r
496 # !include statement should be expanded at the same FileLinesList[CurrentLineNumber - 1]\r
497 #\r
498 # @param self The object pointer\r
499 #\r
500 def PreprocessFile(self):\r
501\r
502 self.Rewind()\r
503 InComment = False\r
504 DoubleSlashComment = False\r
505 HashComment = False\r
506 # HashComment in quoted string " " is ignored.\r
507 InString = False\r
508\r
509 while not self.__EndOfFile():\r
510\r
511 if self.__CurrentChar() == T_CHAR_DOUBLE_QUOTE and not InComment:\r
512 InString = not InString\r
513 # meet new line, then no longer in a comment for // and '#'\r
514 if self.__CurrentChar() == T_CHAR_LF:\r
515 self.CurrentLineNumber += 1\r
516 self.CurrentOffsetWithinLine = 0\r
517 if InComment and DoubleSlashComment:\r
518 InComment = False\r
519 DoubleSlashComment = False\r
520 if InComment and HashComment:\r
521 InComment = False\r
522 HashComment = False\r
523 # check for */ comment end\r
524 elif InComment and not DoubleSlashComment and not HashComment and self.__CurrentChar() == T_CHAR_STAR and self.__NextChar() == T_CHAR_SLASH:\r
525 self.__SetCurrentCharValue(T_CHAR_SPACE)\r
526 self.__GetOneChar()\r
527 self.__SetCurrentCharValue(T_CHAR_SPACE)\r
528 self.__GetOneChar()\r
529 InComment = False\r
530 # set comments to spaces\r
531 elif InComment:\r
532 self.__SetCurrentCharValue(T_CHAR_SPACE)\r
533 self.__GetOneChar()\r
534 # check for // comment\r
535 elif self.__CurrentChar() == T_CHAR_SLASH and self.__NextChar() == T_CHAR_SLASH and not self.__EndOfLine():\r
536 InComment = True\r
537 DoubleSlashComment = True\r
538 # check for '#' comment\r
539 elif self.__CurrentChar() == T_CHAR_HASH and not self.__EndOfLine() and not InString:\r
540 InComment = True\r
541 HashComment = True\r
542 # check for /* comment start\r
543 elif self.__CurrentChar() == T_CHAR_SLASH and self.__NextChar() == T_CHAR_STAR:\r
544 self.__SetCurrentCharValue( T_CHAR_SPACE)\r
545 self.__GetOneChar()\r
546 self.__SetCurrentCharValue( T_CHAR_SPACE)\r
547 self.__GetOneChar()\r
548 InComment = True\r
549 else:\r
550 self.__GetOneChar()\r
551\r
552 # restore from ListOfList to ListOfString\r
553 self.Profile.FileLinesList = ["".join(list) for list in self.Profile.FileLinesList]\r
554 self.Rewind()\r
555\r
556 ## PreprocessIncludeFile() method\r
557 #\r
558 # Preprocess file contents, replace !include statements with file contents.\r
559 # In the end, rewind the file buffer pointer to the beginning\r
560 #\r
561 # @param self The object pointer\r
562 #\r
563 def PreprocessIncludeFile(self):\r
564\r
565 while self.__GetNextToken():\r
566\r
567 if self.__Token == '!include':\r
568 IncludeLine = self.CurrentLineNumber\r
569 IncludeOffset = self.CurrentOffsetWithinLine - len('!include')\r
570 if not self.__GetNextToken():\r
571 raise Warning("expected include file name", self.FileName, self.CurrentLineNumber)\r
572 IncFileName = self.__Token\r
2bcc713e 573 __IncludeMacros = {}\r
d0acc87a
LG
574 for Macro in ['WORKSPACE', 'ECP_SOURCE', 'EFI_SOURCE', 'EDK_SOURCE']:\r
575 MacroVal = self.__GetMacroValue(Macro)\r
576 if MacroVal:\r
577 __IncludeMacros[Macro] = MacroVal\r
578\r
579 try:\r
580 IncludedFile = NormPath(ReplaceMacro(IncFileName, __IncludeMacros, RaiseError=True))\r
581 except:\r
582 raise Warning("only these system environment variables are permitted to start the path of the included file: "\r
583 "$(WORKSPACE), $(ECP_SOURCE), $(EFI_SOURCE), $(EDK_SOURCE)",\r
584 self.FileName, self.CurrentLineNumber)\r
2bcc713e
LG
585 #\r
586 # First search the include file under the same directory as FDF file\r
587 #\r
588 IncludedFile1 = PathClass(IncludedFile, os.path.dirname(self.FileName))\r
589 ErrorCode = IncludedFile1.Validate()[0]\r
590 if ErrorCode != 0:\r
591 #\r
592 # Then search the include file under the same directory as DSC file\r
593 #\r
d0acc87a
LG
594 PlatformDir = ''\r
595 if GenFdsGlobalVariable.ActivePlatform:\r
596 PlatformDir = GenFdsGlobalVariable.ActivePlatform.Dir\r
597 elif GlobalData.gActivePlatform:\r
598 PlatformDir = GlobalData.gActivePlatform.MetaFile.Dir\r
599 IncludedFile1 = PathClass(IncludedFile, PlatformDir)\r
2bcc713e
LG
600 ErrorCode = IncludedFile1.Validate()[0]\r
601 if ErrorCode != 0:\r
602 #\r
603 # Also search file under the WORKSPACE directory\r
604 #\r
605 IncludedFile1 = PathClass(IncludedFile, GlobalData.gWorkspace)\r
606 ErrorCode = IncludedFile1.Validate()[0]\r
607 if ErrorCode != 0:\r
d0acc87a 608 raise Warning("The include file does not exist under below directories: \n%s\n%s\n%s\n"%(os.path.dirname(self.FileName), PlatformDir, GlobalData.gWorkspace), \r
2bcc713e 609 self.FileName, self.CurrentLineNumber)\r
30fdf114 610\r
2bcc713e 611 IncFileProfile = IncludeFileProfile(IncludedFile1.Path)\r
30fdf114
LG
612\r
613 CurrentLine = self.CurrentLineNumber\r
614 CurrentOffset = self.CurrentOffsetWithinLine\r
615 # list index of the insertion, note that line number is 'CurrentLine + 1'\r
616 InsertAtLine = CurrentLine\r
617 IncFileProfile.InsertStartLineNumber = InsertAtLine + 1\r
618 # deal with remaining portions after "!include filename", if exists.\r
619 if self.__GetNextToken():\r
620 if self.CurrentLineNumber == CurrentLine:\r
621 RemainingLine = self.__CurrentLine()[CurrentOffset:]\r
622 self.Profile.FileLinesList.insert(self.CurrentLineNumber, RemainingLine)\r
623 IncFileProfile.InsertAdjust += 1\r
624 self.CurrentLineNumber += 1\r
625 self.CurrentOffsetWithinLine = 0\r
626\r
627 for Line in IncFileProfile.FileLinesList:\r
628 self.Profile.FileLinesList.insert(InsertAtLine, Line)\r
629 self.CurrentLineNumber += 1\r
630 InsertAtLine += 1\r
631\r
632 IncludeFileList.append(IncFileProfile)\r
633\r
634 # comment out the processed include file statement\r
635 TempList = list(self.Profile.FileLinesList[IncludeLine - 1])\r
636 TempList.insert(IncludeOffset, '#')\r
637 self.Profile.FileLinesList[IncludeLine - 1] = ''.join(TempList)\r
638\r
639 self.Rewind()\r
0d2711a6 640 \r
da92f276
LG
641 def __GetIfListCurrentItemStat(self, IfList):\r
642 if len(IfList) == 0:\r
643 return True\r
644 \r
645 for Item in IfList:\r
646 if Item[1] == False:\r
647 return False\r
648 \r
649 return True\r
0d2711a6 650 \r
6780eef1 651 ## PreprocessConditionalStatement() method\r
30fdf114 652 #\r
6780eef1 653 # Preprocess conditional statement.\r
30fdf114
LG
654 # In the end, rewind the file buffer pointer to the beginning\r
655 #\r
656 # @param self The object pointer\r
657 #\r
658 def PreprocessConditionalStatement(self):\r
659 # IfList is a stack of if branches with elements of list [Pos, CondSatisfied, BranchDetermined]\r
660 IfList = []\r
0d2711a6 661 RegionLayoutLine = 0\r
d0acc87a 662 ReplacedLine = -1\r
30fdf114 663 while self.__GetNextToken():\r
d0acc87a
LG
664 # Determine section name and the location dependent macro\r
665 if self.__GetIfListCurrentItemStat(IfList):\r
666 if self.__Token.startswith('['):\r
667 Header = self.__Token\r
668 if not self.__Token.endswith(']'):\r
669 self.__SkipToToken(']')\r
670 Header += self.__SkippedChars\r
671 if Header.find('$(') != -1:\r
672 raise Warning("macro cannot be used in section header", self.FileName, self.CurrentLineNumber)\r
673 self.__SectionHeaderParser(Header)\r
674 continue\r
675 # Replace macros except in RULE section or out of section\r
676 elif self.__CurSection and ReplacedLine != self.CurrentLineNumber:\r
677 ReplacedLine = self.CurrentLineNumber\r
678 self.__UndoToken()\r
679 CurLine = self.Profile.FileLinesList[ReplacedLine - 1]\r
680 PreIndex = 0\r
681 StartPos = CurLine.find('$(', PreIndex)\r
682 EndPos = CurLine.find(')', StartPos+2)\r
64b2609f 683 while StartPos != -1 and EndPos != -1 and self.__Token not in ['!ifdef', '!ifndef', '!if', '!elseif']:\r
d0acc87a
LG
684 MacroName = CurLine[StartPos+2 : EndPos]\r
685 MacorValue = self.__GetMacroValue(MacroName)\r
686 if MacorValue != None:\r
687 CurLine = CurLine.replace('$(' + MacroName + ')', MacorValue, 1)\r
688 if MacorValue.find('$(') != -1:\r
689 PreIndex = StartPos\r
690 else:\r
691 PreIndex = StartPos + len(MacorValue)\r
692 else:\r
693 PreIndex = EndPos + 1\r
694 StartPos = CurLine.find('$(', PreIndex)\r
695 EndPos = CurLine.find(')', StartPos+2)\r
696 self.Profile.FileLinesList[ReplacedLine - 1] = CurLine\r
697 continue\r
698\r
30fdf114 699 if self.__Token == 'DEFINE':\r
d0acc87a
LG
700 if self.__GetIfListCurrentItemStat(IfList):\r
701 if not self.__CurSection:\r
702 raise Warning("macro cannot be defined in Rule section or out of section", self.FileName, self.CurrentLineNumber)\r
da92f276
LG
703 DefineLine = self.CurrentLineNumber - 1\r
704 DefineOffset = self.CurrentOffsetWithinLine - len('DEFINE')\r
705 if not self.__GetNextToken():\r
706 raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)\r
707 Macro = self.__Token\r
708 if not self.__IsToken( "="):\r
709 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
710 \r
d0acc87a
LG
711 Value = self.__GetExpression()\r
712 self.__SetMacroValue(Macro, Value)\r
da92f276 713 self.__WipeOffArea.append(((DefineLine, DefineOffset), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
0d2711a6 714 elif self.__Token == 'SET':\r
64b2609f
LG
715 SetLine = self.CurrentLineNumber - 1\r
716 SetOffset = self.CurrentOffsetWithinLine - len('SET')\r
0d2711a6
LG
717 PcdPair = self.__GetNextPcdName()\r
718 PcdName = "%s.%s" % (PcdPair[1], PcdPair[0])\r
719 if not self.__IsToken( "="):\r
720 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
721\r
d0acc87a
LG
722 Value = self.__GetExpression()\r
723 Value = self.__EvaluateConditional(Value, self.CurrentLineNumber, 'eval', True)\r
30fdf114 724\r
d0acc87a 725 self.__PcdDict[PcdName] = Value\r
64b2609f
LG
726\r
727 self.Profile.PcdDict[PcdPair] = Value\r
728 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
729 self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
730\r
731 self.__WipeOffArea.append(((SetLine, SetOffset), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
30fdf114
LG
732 elif self.__Token in ('!ifdef', '!ifndef', '!if'):\r
733 IfStartPos = (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len(self.__Token))\r
734 IfList.append([IfStartPos, None, None])\r
0d2711a6 735\r
30fdf114 736 CondLabel = self.__Token\r
0d2711a6 737 Expression = self.__GetExpression()\r
d5d56f1b 738 \r
30fdf114 739 if CondLabel == '!if':\r
0d2711a6 740 ConditionSatisfied = self.__EvaluateConditional(Expression, IfList[-1][0][0] + 1, 'eval')\r
30fdf114 741 else:\r
0d2711a6
LG
742 ConditionSatisfied = self.__EvaluateConditional(Expression, IfList[-1][0][0] + 1, 'in')\r
743 if CondLabel == '!ifndef':\r
30fdf114 744 ConditionSatisfied = not ConditionSatisfied\r
30fdf114 745\r
0d2711a6
LG
746 BranchDetermined = ConditionSatisfied\r
747 IfList[-1] = [IfList[-1][0], ConditionSatisfied, BranchDetermined]\r
748 if ConditionSatisfied:\r
749 self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1))) \r
30fdf114
LG
750 elif self.__Token in ('!elseif', '!else'):\r
751 ElseStartPos = (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len(self.__Token))\r
752 if len(IfList) <= 0:\r
753 raise Warning("Missing !if statement", self.FileName, self.CurrentLineNumber)\r
0d2711a6 754\r
30fdf114
LG
755 if IfList[-1][1]:\r
756 IfList[-1] = [ElseStartPos, False, True]\r
757 self.__WipeOffArea.append((ElseStartPos, (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
758 else:\r
759 self.__WipeOffArea.append((IfList[-1][0], ElseStartPos))\r
760 IfList[-1] = [ElseStartPos, True, IfList[-1][2]]\r
761 if self.__Token == '!elseif':\r
0d2711a6
LG
762 Expression = self.__GetExpression()\r
763 ConditionSatisfied = self.__EvaluateConditional(Expression, IfList[-1][0][0] + 1, 'eval')\r
30fdf114
LG
764 IfList[-1] = [IfList[-1][0], ConditionSatisfied, IfList[-1][2]]\r
765\r
766 if IfList[-1][1]:\r
767 if IfList[-1][2]:\r
768 IfList[-1][1] = False\r
769 else:\r
770 IfList[-1][2] = True\r
771 self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
30fdf114 772 elif self.__Token == '!endif':\r
d0acc87a
LG
773 if len(IfList) <= 0:\r
774 raise Warning("Missing !if statement", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
775 if IfList[-1][1]:\r
776 self.__WipeOffArea.append(((self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len('!endif')), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
777 else:\r
778 self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
779\r
780 IfList.pop()\r
0d2711a6
LG
781 elif not IfList: # Don't use PCDs inside conditional directive\r
782 if self.CurrentLineNumber <= RegionLayoutLine:\r
783 # Don't try the same line twice\r
784 continue\r
64b2609f
LG
785 SetPcd = ShortcutPcdPattern.match(self.Profile.FileLinesList[self.CurrentLineNumber - 1])\r
786 if SetPcd:\r
787 self.__PcdDict[SetPcd.group('name')] = SetPcd.group('value')\r
788 RegionLayoutLine = self.CurrentLineNumber\r
789 continue\r
0d2711a6
LG
790 RegionSize = RegionSizePattern.match(self.Profile.FileLinesList[self.CurrentLineNumber - 1])\r
791 if not RegionSize:\r
792 RegionLayoutLine = self.CurrentLineNumber\r
793 continue\r
794 RegionSizeGuid = RegionSizeGuidPattern.match(self.Profile.FileLinesList[self.CurrentLineNumber])\r
795 if not RegionSizeGuid:\r
796 RegionLayoutLine = self.CurrentLineNumber + 1\r
797 continue\r
d0acc87a
LG
798 self.__PcdDict[RegionSizeGuid.group('base')] = RegionSize.group('base')\r
799 self.__PcdDict[RegionSizeGuid.group('size')] = RegionSize.group('size')\r
0d2711a6
LG
800 RegionLayoutLine = self.CurrentLineNumber + 1\r
801\r
802 if IfList:\r
30fdf114
LG
803 raise Warning("Missing !endif", self.FileName, self.CurrentLineNumber)\r
804 self.Rewind()\r
805\r
d0acc87a
LG
806 def __CollectMacroPcd(self):\r
807 MacroDict = {}\r
808\r
809 # PCD macro\r
64b2609f 810 MacroDict.update(GlobalData.gPlatformPcds)\r
d0acc87a
LG
811 MacroDict.update(self.__PcdDict)\r
812\r
813 # Lowest priority\r
814 MacroDict.update(GlobalData.gPlatformDefines)\r
815\r
816 if self.__CurSection:\r
817 # Defines macro\r
818 ScopeMacro = self.__MacroDict['COMMON', 'COMMON', 'COMMON']\r
819 if ScopeMacro:\r
820 MacroDict.update(ScopeMacro)\r
821 \r
822 # Section macro\r
823 ScopeMacro = self.__MacroDict[\r
824 self.__CurSection[0],\r
825 self.__CurSection[1],\r
826 self.__CurSection[2]\r
827 ]\r
828 if ScopeMacro:\r
829 MacroDict.update(ScopeMacro)\r
830\r
831 MacroDict.update(GlobalData.gGlobalDefines)\r
832 MacroDict.update(GlobalData.gCommandLineDefines)\r
833 # Highest priority\r
834\r
835 return MacroDict\r
836\r
0d2711a6 837 def __EvaluateConditional(self, Expression, Line, Op = None, Value = None):\r
30fdf114 838 FileLineTuple = GetRealFileLine(self.FileName, Line)\r
d0acc87a 839 MacroPcdDict = self.__CollectMacroPcd()\r
0d2711a6
LG
840 if Op == 'eval':\r
841 try:\r
d0acc87a
LG
842 if Value:\r
843 return ValueExpression(Expression, MacroPcdDict)(True)\r
844 else:\r
845 return ValueExpression(Expression, MacroPcdDict)()\r
0d2711a6
LG
846 except WrnExpression, Excpt:\r
847 # \r
848 # Catch expression evaluation warning here. We need to report\r
849 # the precise number of line and return the evaluation result\r
850 #\r
851 EdkLogger.warn('Parser', "Suspicious expression: %s" % str(Excpt),\r
852 File=self.FileName, ExtraData=self.__CurrentLine(), \r
853 Line=Line)\r
854 return Excpt.result\r
855 except Exception, Excpt:\r
64b2609f
LG
856 if hasattr(Excpt, 'Pcd'):\r
857 if Excpt.Pcd in GlobalData.gPlatformOtherPcds:\r
858 Info = GlobalData.gPlatformOtherPcds[Excpt.Pcd]\r
859 raise Warning("Cannot use this PCD (%s) in an expression as"\r
860 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"\r
861 " of the DSC file (%s), and it is currently defined in this section:"\r
862 " %s, line #: %d." % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE'], Info[0], Info[1]),\r
863 *FileLineTuple)\r
864 else:\r
865 raise Warning("PCD (%s) is not defined in DSC file (%s)" % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE']),\r
866 *FileLineTuple)\r
867 else:\r
868 raise Warning(str(Excpt), *FileLineTuple)\r
0d2711a6
LG
869 else:\r
870 if Expression.startswith('$(') and Expression[-1] == ')':\r
871 Expression = Expression[2:-1] \r
d0acc87a 872 return Expression in MacroPcdDict\r
30fdf114
LG
873\r
874 ## __IsToken() method\r
875 #\r
876 # Check whether input string is found from current char position along\r
877 # If found, the string value is put into self.__Token\r
878 #\r
879 # @param self The object pointer\r
880 # @param String The string to search\r
881 # @param IgnoreCase Indicate case sensitive/non-sensitive search, default is case sensitive\r
882 # @retval True Successfully find string, file buffer pointer moved forward\r
883 # @retval False Not able to find string, file buffer pointer not changed\r
884 #\r
885 def __IsToken(self, String, IgnoreCase = False):\r
886 self.__SkipWhiteSpace()\r
887\r
888 # Only consider the same line, no multi-line token allowed\r
889 StartPos = self.CurrentOffsetWithinLine\r
890 index = -1\r
891 if IgnoreCase:\r
892 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].upper().find(String.upper())\r
893 else:\r
894 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].find(String)\r
895 if index == 0:\r
896 self.CurrentOffsetWithinLine += len(String)\r
897 self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
898 return True\r
899 return False\r
900\r
901 ## __IsKeyword() method\r
902 #\r
903 # Check whether input keyword is found from current char position along, whole word only!\r
904 # If found, the string value is put into self.__Token\r
905 #\r
906 # @param self The object pointer\r
907 # @param Keyword The string to search\r
908 # @param IgnoreCase Indicate case sensitive/non-sensitive search, default is case sensitive\r
909 # @retval True Successfully find string, file buffer pointer moved forward\r
910 # @retval False Not able to find string, file buffer pointer not changed\r
911 #\r
912 def __IsKeyword(self, KeyWord, IgnoreCase = False):\r
913 self.__SkipWhiteSpace()\r
914\r
915 # Only consider the same line, no multi-line token allowed\r
916 StartPos = self.CurrentOffsetWithinLine\r
917 index = -1\r
918 if IgnoreCase:\r
919 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].upper().find(KeyWord.upper())\r
920 else:\r
921 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].find(KeyWord)\r
922 if index == 0:\r
923 followingChar = self.__CurrentLine()[self.CurrentOffsetWithinLine + len(KeyWord)]\r
924 if not str(followingChar).isspace() and followingChar not in SEPERATOR_TUPLE:\r
925 return False\r
926 self.CurrentOffsetWithinLine += len(KeyWord)\r
927 self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
928 return True\r
929 return False\r
930\r
0d2711a6
LG
931 def __GetExpression(self):\r
932 Line = self.Profile.FileLinesList[self.CurrentLineNumber - 1]\r
933 Index = len(Line) - 1\r
934 while Line[Index] in ['\r', '\n']:\r
935 Index -= 1\r
936 ExpressionString = self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine:Index+1]\r
937 self.CurrentOffsetWithinLine += len(ExpressionString)\r
938 ExpressionString = ExpressionString.strip()\r
939 return ExpressionString\r
940\r
30fdf114
LG
941 ## __GetNextWord() method\r
942 #\r
943 # Get next C name from file lines\r
944 # If found, the string value is put into self.__Token\r
945 #\r
946 # @param self The object pointer\r
947 # @retval True Successfully find a C name string, file buffer pointer moved forward\r
948 # @retval False Not able to find a C name string, file buffer pointer not changed\r
949 #\r
950 def __GetNextWord(self):\r
951 self.__SkipWhiteSpace()\r
952 if self.__EndOfFile():\r
953 return False\r
954\r
955 TempChar = self.__CurrentChar()\r
956 StartPos = self.CurrentOffsetWithinLine\r
957 if (TempChar >= 'a' and TempChar <= 'z') or (TempChar >= 'A' and TempChar <= 'Z') or TempChar == '_':\r
958 self.__GetOneChar()\r
959 while not self.__EndOfLine():\r
960 TempChar = self.__CurrentChar()\r
961 if (TempChar >= 'a' and TempChar <= 'z') or (TempChar >= 'A' and TempChar <= 'Z') \\r
962 or (TempChar >= '0' and TempChar <= '9') or TempChar == '_' or TempChar == '-':\r
963 self.__GetOneChar()\r
964\r
965 else:\r
966 break\r
967\r
968 self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
969 return True\r
970\r
971 return False\r
972\r
973 ## __GetNextToken() method\r
974 #\r
975 # Get next token unit before a seperator\r
976 # If found, the string value is put into self.__Token\r
977 #\r
978 # @param self The object pointer\r
979 # @retval True Successfully find a token unit, file buffer pointer moved forward\r
980 # @retval False Not able to find a token unit, file buffer pointer not changed\r
981 #\r
982 def __GetNextToken(self):\r
983 # Skip leading spaces, if exist.\r
984 self.__SkipWhiteSpace()\r
985 if self.__EndOfFile():\r
986 return False\r
987 # Record the token start position, the position of the first non-space char.\r
988 StartPos = self.CurrentOffsetWithinLine\r
989 StartLine = self.CurrentLineNumber\r
d0acc87a 990 while StartLine == self.CurrentLineNumber:\r
30fdf114
LG
991 TempChar = self.__CurrentChar()\r
992 # Try to find the end char that is not a space and not in seperator tuple.\r
993 # That is, when we got a space or any char in the tuple, we got the end of token.\r
994 if not str(TempChar).isspace() and TempChar not in SEPERATOR_TUPLE:\r
995 self.__GetOneChar()\r
996 # if we happen to meet a seperator as the first char, we must proceed to get it.\r
997 # That is, we get a token that is a seperator char. nomally it is the boundary of other tokens.\r
998 elif StartPos == self.CurrentOffsetWithinLine and TempChar in SEPERATOR_TUPLE:\r
999 self.__GetOneChar()\r
1000 break\r
1001 else:\r
1002 break\r
1003# else:\r
1004# return False\r
1005\r
1006 EndPos = self.CurrentOffsetWithinLine\r
1007 if self.CurrentLineNumber != StartLine:\r
1008 EndPos = len(self.Profile.FileLinesList[StartLine-1])\r
1009 self.__Token = self.Profile.FileLinesList[StartLine-1][StartPos : EndPos]\r
1010 if StartPos != self.CurrentOffsetWithinLine:\r
1011 return True\r
1012 else:\r
1013 return False\r
1014\r
1015 def __GetNextOp(self):\r
1016 # Skip leading spaces, if exist.\r
1017 self.__SkipWhiteSpace()\r
1018 if self.__EndOfFile():\r
1019 return False\r
1020 # Record the token start position, the position of the first non-space char.\r
1021 StartPos = self.CurrentOffsetWithinLine\r
1022 while not self.__EndOfLine():\r
1023 TempChar = self.__CurrentChar()\r
1024 # Try to find the end char that is not a space\r
1025 if not str(TempChar).isspace():\r
1026 self.__GetOneChar()\r
1027 else:\r
1028 break\r
1029 else:\r
1030 return False\r
1031\r
1032 if StartPos != self.CurrentOffsetWithinLine:\r
1033 self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
1034 return True\r
1035 else:\r
1036 return False\r
1037 ## __GetNextGuid() method\r
1038 #\r
1039 # Get next token unit before a seperator\r
1040 # If found, the GUID string is put into self.__Token\r
1041 #\r
1042 # @param self The object pointer\r
1043 # @retval True Successfully find a registry format GUID, file buffer pointer moved forward\r
1044 # @retval False Not able to find a registry format GUID, file buffer pointer not changed\r
1045 #\r
1046 def __GetNextGuid(self):\r
1047\r
1048 if not self.__GetNextToken():\r
1049 return False\r
1050 p = re.compile('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')\r
1051 if p.match(self.__Token) != None:\r
1052 return True\r
1053 else:\r
1054 self.__UndoToken()\r
1055 return False\r
1056\r
1057 ## __UndoToken() method\r
1058 #\r
1059 # Go back one token unit in file buffer\r
1060 #\r
1061 # @param self The object pointer\r
1062 #\r
1063 def __UndoToken(self):\r
1064 self.__UndoOneChar()\r
1065 while self.__CurrentChar().isspace():\r
1066 if not self.__UndoOneChar():\r
1067 self.__GetOneChar()\r
1068 return\r
1069\r
1070\r
1071 StartPos = self.CurrentOffsetWithinLine\r
1072 CurrentLine = self.CurrentLineNumber\r
1073 while CurrentLine == self.CurrentLineNumber:\r
1074\r
1075 TempChar = self.__CurrentChar()\r
1076 # Try to find the end char that is not a space and not in seperator tuple.\r
1077 # That is, when we got a space or any char in the tuple, we got the end of token.\r
1078 if not str(TempChar).isspace() and not TempChar in SEPERATOR_TUPLE:\r
1079 if not self.__UndoOneChar():\r
d0acc87a 1080 return\r
30fdf114
LG
1081 # if we happen to meet a seperator as the first char, we must proceed to get it.\r
1082 # That is, we get a token that is a seperator char. nomally it is the boundary of other tokens.\r
1083 elif StartPos == self.CurrentOffsetWithinLine and TempChar in SEPERATOR_TUPLE:\r
1084 return\r
1085 else:\r
1086 break\r
1087\r
1088 self.__GetOneChar()\r
1089\r
1090 ## __HexDigit() method\r
1091 #\r
1092 # Whether char input is a Hex data bit\r
1093 #\r
1094 # @param self The object pointer\r
1095 # @param TempChar The char to test\r
1096 # @retval True The char is a Hex data bit\r
1097 # @retval False The char is NOT a Hex data bit\r
1098 #\r
1099 def __HexDigit(self, TempChar):\r
1100 if (TempChar >= 'a' and TempChar <= 'f') or (TempChar >= 'A' and TempChar <= 'F') \\r
1101 or (TempChar >= '0' and TempChar <= '9'):\r
1102 return True\r
1103 else:\r
1104 return False\r
1105\r
1106 def __IsHex(self, HexStr):\r
1107 if not HexStr.upper().startswith("0X"):\r
1108 return False\r
1109 if len(self.__Token) <= 2:\r
1110 return False\r
1111 charList = [c for c in HexStr[2 : ] if not self.__HexDigit( c)]\r
1112 if len(charList) == 0:\r
1113 return True\r
1114 else:\r
1115 return False\r
1116 ## __GetNextHexNumber() method\r
1117 #\r
1118 # Get next HEX data before a seperator\r
1119 # If found, the HEX data is put into self.__Token\r
1120 #\r
1121 # @param self The object pointer\r
1122 # @retval True Successfully find a HEX data, file buffer pointer moved forward\r
1123 # @retval False Not able to find a HEX data, file buffer pointer not changed\r
1124 #\r
1125 def __GetNextHexNumber(self):\r
1126 if not self.__GetNextToken():\r
1127 return False\r
1128 if self.__IsHex(self.__Token):\r
1129 return True\r
1130 else:\r
1131 self.__UndoToken()\r
1132 return False\r
1133\r
1134 ## __GetNextDecimalNumber() method\r
1135 #\r
1136 # Get next decimal data before a seperator\r
1137 # If found, the decimal data is put into self.__Token\r
1138 #\r
1139 # @param self The object pointer\r
1140 # @retval True Successfully find a decimal data, file buffer pointer moved forward\r
1141 # @retval False Not able to find a decimal data, file buffer pointer not changed\r
1142 #\r
1143 def __GetNextDecimalNumber(self):\r
1144 if not self.__GetNextToken():\r
1145 return False\r
1146 if self.__Token.isdigit():\r
1147 return True\r
1148 else:\r
1149 self.__UndoToken()\r
1150 return False\r
1151\r
1152 ## __GetNextPcdName() method\r
1153 #\r
1154 # Get next PCD token space C name and PCD C name pair before a seperator\r
1155 # If found, the decimal data is put into self.__Token\r
1156 #\r
1157 # @param self The object pointer\r
1158 # @retval Tuple PCD C name and PCD token space C name pair\r
1159 #\r
1160 def __GetNextPcdName(self):\r
1161 if not self.__GetNextWord():\r
1162 raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
1163 pcdTokenSpaceCName = self.__Token\r
1164\r
1165 if not self.__IsToken( "."):\r
1166 raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
1167\r
1168 if not self.__GetNextWord():\r
1169 raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
1170 pcdCName = self.__Token\r
1171\r
1172 return (pcdCName, pcdTokenSpaceCName)\r
1173\r
1174 ## __GetStringData() method\r
1175 #\r
1176 # Get string contents quoted in ""\r
1177 # If found, the decimal data is put into self.__Token\r
1178 #\r
1179 # @param self The object pointer\r
1180 # @retval True Successfully find a string data, file buffer pointer moved forward\r
1181 # @retval False Not able to find a string data, file buffer pointer not changed\r
1182 #\r
1183 def __GetStringData(self):\r
1184 if self.__Token.startswith("\"") or self.__Token.startswith("L\""):\r
1185 self.__UndoToken()\r
1186 self.__SkipToToken("\"")\r
1187 currentLineNumber = self.CurrentLineNumber\r
1188\r
1189 if not self.__SkipToToken("\""):\r
1190 raise Warning("Missing Quote \" for String", self.FileName, self.CurrentLineNumber)\r
1191 if currentLineNumber != self.CurrentLineNumber:\r
1192 raise Warning("Missing Quote \" for String", self.FileName, self.CurrentLineNumber)\r
1193 self.__Token = self.__SkippedChars.rstrip('\"')\r
1194 return True\r
1195\r
1196 elif self.__Token.startswith("\'") or self.__Token.startswith("L\'"):\r
1197 self.__UndoToken()\r
1198 self.__SkipToToken("\'")\r
1199 currentLineNumber = self.CurrentLineNumber\r
1200\r
1201 if not self.__SkipToToken("\'"):\r
1202 raise Warning("Missing Quote \' for String", self.FileName, self.CurrentLineNumber)\r
1203 if currentLineNumber != self.CurrentLineNumber:\r
1204 raise Warning("Missing Quote \' for String", self.FileName, self.CurrentLineNumber)\r
1205 self.__Token = self.__SkippedChars.rstrip('\'')\r
1206 return True\r
1207\r
1208 else:\r
1209 return False\r
1210\r
1211 ## __SkipToToken() method\r
1212 #\r
1213 # Search forward in file buffer for the string\r
1214 # The skipped chars are put into self.__SkippedChars\r
1215 #\r
1216 # @param self The object pointer\r
1217 # @param String The string to search\r
1218 # @param IgnoreCase Indicate case sensitive/non-sensitive search, default is case sensitive\r
1219 # @retval True Successfully find the string, file buffer pointer moved forward\r
1220 # @retval False Not able to find the string, file buffer pointer not changed\r
1221 #\r
1222 def __SkipToToken(self, String, IgnoreCase = False):\r
1223 StartPos = self.GetFileBufferPos()\r
1224\r
1225 self.__SkippedChars = ""\r
1226 while not self.__EndOfFile():\r
1227 index = -1\r
1228 if IgnoreCase:\r
1229 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].upper().find(String.upper())\r
1230 else:\r
1231 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].find(String)\r
1232 if index == 0:\r
1233 self.CurrentOffsetWithinLine += len(String)\r
1234 self.__SkippedChars += String\r
1235 return True\r
1236 self.__SkippedChars += str(self.__CurrentChar())\r
1237 self.__GetOneChar()\r
1238\r
1239 self.SetFileBufferPos( StartPos)\r
1240 self.__SkippedChars = ""\r
1241 return False\r
1242\r
1243 ## GetFileBufferPos() method\r
1244 #\r
1245 # Return the tuple of current line and offset within the line\r
1246 #\r
1247 # @param self The object pointer\r
1248 # @retval Tuple Line number and offset pair\r
1249 #\r
1250 def GetFileBufferPos(self):\r
1251 return (self.CurrentLineNumber, self.CurrentOffsetWithinLine)\r
1252\r
1253 ## SetFileBufferPos() method\r
1254 #\r
1255 # Restore the file buffer position\r
1256 #\r
1257 # @param self The object pointer\r
1258 # @param Pos The new file buffer position\r
1259 #\r
1260 def SetFileBufferPos(self, Pos):\r
1261 (self.CurrentLineNumber, self.CurrentOffsetWithinLine) = Pos\r
1262\r
d40b2ee6
LG
1263 ## Preprocess() method\r
1264 #\r
1265 # Preprocess comment, conditional directive, include directive, replace macro.\r
1266 # Exception will be raised if syntax error found\r
1267 #\r
1268 # @param self The object pointer\r
1269 #\r
1270 def Preprocess(self):\r
1271 self.__StringToList()\r
1272 self.PreprocessFile()\r
1273 self.PreprocessIncludeFile()\r
1274 self.__StringToList()\r
1275 self.PreprocessFile()\r
1276 self.PreprocessConditionalStatement()\r
1277 self.__StringToList()\r
1278 for Pos in self.__WipeOffArea:\r
1279 self.__ReplaceFragment(Pos[0], Pos[1])\r
1280 self.Profile.FileLinesList = ["".join(list) for list in self.Profile.FileLinesList]\r
1281\r
1282 while self.__GetDefines():\r
1283 pass\r
d40b2ee6 1284\r
30fdf114
LG
1285 ## ParseFile() method\r
1286 #\r
1287 # Parse the file profile buffer to extract fd, fv ... information\r
1288 # Exception will be raised if syntax error found\r
1289 #\r
1290 # @param self The object pointer\r
1291 #\r
1292 def ParseFile(self):\r
1293\r
1294 try:\r
d40b2ee6 1295 self.Preprocess()\r
30fdf114
LG
1296 while self.__GetFd():\r
1297 pass\r
1298\r
1299 while self.__GetFv():\r
1300 pass\r
1301\r
1302 while self.__GetCapsule():\r
1303 pass\r
1304\r
1305 while self.__GetVtf():\r
1306 pass\r
1307\r
1308 while self.__GetRule():\r
1309 pass\r
1310 \r
1311 while self.__GetOptionRom():\r
1312 pass\r
1313\r
1314 except Warning, X:\r
1315 self.__UndoToken()\r
1316 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1317 #'\n\tGot Token: \"%s\" from File %s\n' % (self.__Token, FileLineTuple[0]) + \\r
1318 X.Message += ' near line %d, column %d: %s' \\r
1319 % (FileLineTuple[1], self.CurrentOffsetWithinLine + 1, self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :].rstrip('\n').rstrip('\r'))\r
1320 raise\r
1321\r
1322 ## __GetDefines() method\r
1323 #\r
1324 # Get Defines section contents and store its data into AllMacrosList\r
1325 #\r
1326 # @param self The object pointer\r
1327 # @retval True Successfully find a Defines\r
1328 # @retval False Not able to find a Defines\r
1329 #\r
1330 def __GetDefines(self):\r
1331\r
1332 if not self.__GetNextToken():\r
1333 return False\r
1334\r
1335 S = self.__Token.upper()\r
1336 if S.startswith("[") and not S.startswith("[DEFINES"):\r
1337 if not S.startswith("[FD.") and not S.startswith("[FV.") and not S.startswith("[CAPSULE.") \\r
1338 and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
1339 raise Warning("Unknown section or section appear sequence error (The correct sequence should be [DEFINES], [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
1340 self.__UndoToken()\r
1341 return False\r
1342\r
1343 self.__UndoToken()\r
1344 if not self.__IsToken("[DEFINES", True):\r
1345 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1346 #print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \\r
1347 # % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)\r
1348 raise Warning("expected [DEFINES", self.FileName, self.CurrentLineNumber)\r
1349\r
1350 if not self.__IsToken( "]"):\r
1351 raise Warning("expected ']'", self.FileName, self.CurrentLineNumber)\r
1352\r
1353 while self.__GetNextWord():\r
6780eef1
LG
1354 # handle the SET statement\r
1355 if self.__Token == 'SET':\r
1356 self.__UndoToken()\r
1357 self.__GetSetStatement(None)\r
1358 continue\r
1359 \r
30fdf114
LG
1360 Macro = self.__Token\r
1361 \r
1362 if not self.__IsToken("="):\r
1363 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1364 if not self.__GetNextToken() or self.__Token.startswith('['):\r
1365 raise Warning("expected MACRO value", self.FileName, self.CurrentLineNumber)\r
1366 Value = self.__Token\r
30fdf114
LG
1367\r
1368 return False\r
1369\r
1370 ## __GetFd() method\r
1371 #\r
1372 # Get FD section contents and store its data into FD dictionary of self.Profile\r
1373 #\r
1374 # @param self The object pointer\r
1375 # @retval True Successfully find a FD\r
1376 # @retval False Not able to find a FD\r
1377 #\r
1378 def __GetFd(self):\r
1379\r
1380 if not self.__GetNextToken():\r
1381 return False\r
1382\r
1383 S = self.__Token.upper()\r
1384 if S.startswith("[") and not S.startswith("[FD."):\r
1385 if not S.startswith("[FV.") and not S.startswith("[CAPSULE.") \\r
1386 and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
1387 raise Warning("Unknown section", self.FileName, self.CurrentLineNumber)\r
1388 self.__UndoToken()\r
1389 return False\r
1390\r
1391 self.__UndoToken()\r
1392 if not self.__IsToken("[FD.", True):\r
1393 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1394 #print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \\r
1395 # % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)\r
1396 raise Warning("expected [FD.]", self.FileName, self.CurrentLineNumber)\r
1397\r
1398 FdName = self.__GetUiName()\r
52302d4d
LG
1399 if FdName == "":\r
1400 if len (self.Profile.FdDict) == 0:\r
1401 FdName = GenFdsGlobalVariable.PlatformName\r
d0acc87a
LG
1402 if FdName == "" and GlobalData.gActivePlatform:\r
1403 FdName = GlobalData.gActivePlatform.PlatformName\r
52302d4d
LG
1404 self.Profile.FdNameNotSet = True\r
1405 else:\r
1406 raise Warning("expected FdName in [FD.] section", self.FileName, self.CurrentLineNumber)\r
30fdf114 1407 self.CurrentFdName = FdName.upper()\r
52302d4d
LG
1408 \r
1409 if self.CurrentFdName in self.Profile.FdDict:\r
1410 raise Warning("Unexpected the same FD name", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
1411\r
1412 if not self.__IsToken( "]"):\r
1413 raise Warning("expected ']'", self.FileName, self.CurrentLineNumber)\r
1414\r
1415 FdObj = Fd.FD()\r
1416 FdObj.FdUiName = self.CurrentFdName\r
1417 self.Profile.FdDict[self.CurrentFdName] = FdObj\r
52302d4d
LG
1418\r
1419 if len (self.Profile.FdDict) > 1 and self.Profile.FdNameNotSet:\r
1420 raise Warning("expected all FDs have their name", self.FileName, self.CurrentLineNumber)\r
1421\r
30fdf114
LG
1422 Status = self.__GetCreateFile(FdObj)\r
1423 if not Status:\r
1424 raise Warning("FD name error", self.FileName, self.CurrentLineNumber)\r
1425\r
e8a47801
LG
1426 while self.__GetTokenStatements(FdObj):\r
1427 pass\r
1428 for Attr in ("BaseAddress", "Size", "ErasePolarity"):\r
1429 if getattr(FdObj, Attr) == None:\r
1430 self.__GetNextToken()\r
1431 raise Warning("Keyword %s missing" % Attr, self.FileName, self.CurrentLineNumber)\r
1432\r
1433 if not FdObj.BlockSizeList:\r
1434 FdObj.BlockSizeList.append((1, FdObj.Size, None))\r
30fdf114
LG
1435\r
1436 self.__GetDefineStatements(FdObj)\r
1437\r
1438 self.__GetSetStatements(FdObj)\r
1439\r
1440 if not self.__GetRegionLayout(FdObj):\r
1441 raise Warning("expected region layout", self.FileName, self.CurrentLineNumber)\r
1442\r
1443 while self.__GetRegionLayout(FdObj):\r
1444 pass\r
1445 return True\r
1446\r
1447 ## __GetUiName() method\r
1448 #\r
1449 # Return the UI name of a section\r
1450 #\r
1451 # @param self The object pointer\r
1452 # @retval FdName UI name\r
1453 #\r
1454 def __GetUiName(self):\r
1455 Name = ""\r
1456 if self.__GetNextWord():\r
1457 Name = self.__Token\r
1458\r
1459 return Name\r
1460\r
1461 ## __GetCreateFile() method\r
1462 #\r
1463 # Return the output file name of object\r
1464 #\r
1465 # @param self The object pointer\r
1466 # @param Obj object whose data will be stored in file\r
1467 # @retval FdName UI name\r
1468 #\r
1469 def __GetCreateFile(self, Obj):\r
1470\r
1471 if self.__IsKeyword( "CREATE_FILE"):\r
1472 if not self.__IsToken( "="):\r
1473 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1474\r
1475 if not self.__GetNextToken():\r
1476 raise Warning("expected file name", self.FileName, self.CurrentLineNumber)\r
1477\r
1478 FileName = self.__Token\r
1479 Obj.CreateFileName = FileName\r
1480\r
1481 return True\r
1482\r
1483 ## __GetTokenStatements() method\r
1484 #\r
1485 # Get token statements\r
1486 #\r
1487 # @param self The object pointer\r
1488 # @param Obj for whom token statement is got\r
30fdf114
LG
1489 #\r
1490 def __GetTokenStatements(self, Obj):\r
e8a47801
LG
1491 if self.__IsKeyword( "BaseAddress"):\r
1492 if not self.__IsToken( "="):\r
1493 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1494 \r
1495 if not self.__GetNextHexNumber():\r
1496 raise Warning("expected Hex base address", self.FileName, self.CurrentLineNumber)\r
1497 \r
1498 Obj.BaseAddress = self.__Token\r
1499 \r
1500 if self.__IsToken( "|"):\r
1501 pcdPair = self.__GetNextPcdName()\r
1502 Obj.BaseAddressPcd = pcdPair\r
1503 self.Profile.PcdDict[pcdPair] = Obj.BaseAddress\r
1504 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1505 self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple\r
1506 return True\r
30fdf114 1507\r
e8a47801
LG
1508 if self.__IsKeyword( "Size"):\r
1509 if not self.__IsToken( "="):\r
1510 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1511 \r
1512 if not self.__GetNextHexNumber():\r
1513 raise Warning("expected Hex size", self.FileName, self.CurrentLineNumber)\r
30fdf114 1514\r
e8a47801
LG
1515 Size = self.__Token\r
1516 if self.__IsToken( "|"):\r
1517 pcdPair = self.__GetNextPcdName()\r
1518 Obj.SizePcd = pcdPair\r
1519 self.Profile.PcdDict[pcdPair] = Size\r
1520 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1521 self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple\r
1522 Obj.Size = long(Size, 0)\r
1523 return True\r
30fdf114 1524\r
e8a47801
LG
1525 if self.__IsKeyword( "ErasePolarity"):\r
1526 if not self.__IsToken( "="):\r
1527 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1528 \r
1529 if not self.__GetNextToken():\r
1530 raise Warning("expected Erase Polarity", self.FileName, self.CurrentLineNumber)\r
1531 \r
1532 if self.__Token != "1" and self.__Token != "0":\r
1533 raise Warning("expected 1 or 0 Erase Polarity", self.FileName, self.CurrentLineNumber)\r
1534 \r
1535 Obj.ErasePolarity = self.__Token\r
1536 return True\r
30fdf114 1537\r
e8a47801 1538 return self.__GetBlockStatements(Obj)\r
30fdf114
LG
1539\r
1540 ## __GetAddressStatements() method\r
1541 #\r
1542 # Get address statements\r
1543 #\r
1544 # @param self The object pointer\r
1545 # @param Obj for whom address statement is got\r
1546 # @retval True Successfully find\r
1547 # @retval False Not able to find\r
1548 #\r
1549 def __GetAddressStatements(self, Obj):\r
1550\r
1551 if self.__IsKeyword("BsBaseAddress"):\r
1552 if not self.__IsToken( "="):\r
1553 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1554\r
1555 if not self.__GetNextDecimalNumber() and not self.__GetNextHexNumber():\r
1556 raise Warning("expected address", self.FileName, self.CurrentLineNumber)\r
1557\r
1558 BsAddress = long(self.__Token, 0)\r
1559 Obj.BsBaseAddress = BsAddress\r
1560\r
1561 if self.__IsKeyword("RtBaseAddress"):\r
1562 if not self.__IsToken( "="):\r
1563 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1564\r
1565 if not self.__GetNextDecimalNumber() and not self.__GetNextHexNumber():\r
1566 raise Warning("expected address", self.FileName, self.CurrentLineNumber)\r
1567\r
1568 RtAddress = long(self.__Token, 0)\r
1569 Obj.RtBaseAddress = RtAddress\r
1570\r
1571 ## __GetBlockStatements() method\r
1572 #\r
1573 # Get block statements\r
1574 #\r
1575 # @param self The object pointer\r
1576 # @param Obj for whom block statement is got\r
30fdf114
LG
1577 #\r
1578 def __GetBlockStatements(self, Obj):\r
e8a47801 1579 IsBlock = False\r
30fdf114 1580 while self.__GetBlockStatement(Obj):\r
e8a47801 1581 IsBlock = True\r
52302d4d 1582 \r
e8a47801 1583 Item = Obj.BlockSizeList[-1]\r
52302d4d 1584 if Item[0] == None or Item[1] == None:\r
6780eef1 1585 raise Warning("expected block statement", self.FileName, self.CurrentLineNumber)\r
e8a47801 1586 return IsBlock\r
30fdf114
LG
1587\r
1588 ## __GetBlockStatement() method\r
1589 #\r
1590 # Get block statement\r
1591 #\r
1592 # @param self The object pointer\r
1593 # @param Obj for whom block statement is got\r
1594 # @retval True Successfully find\r
1595 # @retval False Not able to find\r
1596 #\r
1597 def __GetBlockStatement(self, Obj):\r
1598 if not self.__IsKeyword( "BlockSize"):\r
1599 return False\r
1600\r
1601 if not self.__IsToken( "="):\r
1602 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1603\r
1604 if not self.__GetNextHexNumber() and not self.__GetNextDecimalNumber():\r
6780eef1 1605 raise Warning("expected Hex or Integer block size", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
1606\r
1607 BlockSize = self.__Token\r
1608 BlockSizePcd = None\r
1609 if self.__IsToken( "|"):\r
1610 PcdPair = self.__GetNextPcdName()\r
1611 BlockSizePcd = PcdPair\r
1612 self.Profile.PcdDict[PcdPair] = BlockSize\r
d0acc87a
LG
1613 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1614 self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
52302d4d 1615 BlockSize = long(BlockSize, 0)\r
30fdf114
LG
1616\r
1617 BlockNumber = None\r
1618 if self.__IsKeyword( "NumBlocks"):\r
1619 if not self.__IsToken( "="):\r
1620 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1621\r
1622 if not self.__GetNextDecimalNumber() and not self.__GetNextHexNumber():\r
1623 raise Warning("expected block numbers", self.FileName, self.CurrentLineNumber)\r
1624\r
1625 BlockNumber = long(self.__Token, 0)\r
1626\r
1627 Obj.BlockSizeList.append((BlockSize, BlockNumber, BlockSizePcd))\r
1628 return True\r
1629\r
1630 ## __GetDefineStatements() method\r
1631 #\r
1632 # Get define statements\r
1633 #\r
1634 # @param self The object pointer\r
1635 # @param Obj for whom define statement is got\r
1636 # @retval True Successfully find\r
1637 # @retval False Not able to find\r
1638 #\r
1639 def __GetDefineStatements(self, Obj):\r
1640 while self.__GetDefineStatement( Obj):\r
1641 pass\r
1642\r
1643 ## __GetDefineStatement() method\r
1644 #\r
1645 # Get define statement\r
1646 #\r
1647 # @param self The object pointer\r
1648 # @param Obj for whom define statement is got\r
1649 # @retval True Successfully find\r
1650 # @retval False Not able to find\r
1651 #\r
1652 def __GetDefineStatement(self, Obj):\r
1653 if self.__IsKeyword("DEFINE"):\r
1654 self.__GetNextToken()\r
1655 Macro = self.__Token\r
1656 if not self.__IsToken( "="):\r
1657 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1658\r
1659 if not self.__GetNextToken():\r
1660 raise Warning("expected value", self.FileName, self.CurrentLineNumber)\r
1661\r
1662 Value = self.__Token\r
1663 Macro = '$(' + Macro + ')'\r
1664 Obj.DefineVarDict[Macro] = Value\r
1665 return True\r
1666\r
1667 return False\r
1668\r
1669 ## __GetSetStatements() method\r
1670 #\r
1671 # Get set statements\r
1672 #\r
1673 # @param self The object pointer\r
1674 # @param Obj for whom set statement is got\r
1675 # @retval True Successfully find\r
1676 # @retval False Not able to find\r
1677 #\r
1678 def __GetSetStatements(self, Obj):\r
1679 while self.__GetSetStatement(Obj):\r
1680 pass\r
1681\r
1682 ## __GetSetStatement() method\r
1683 #\r
1684 # Get set statement\r
1685 #\r
1686 # @param self The object pointer\r
1687 # @param Obj for whom set statement is got\r
1688 # @retval True Successfully find\r
1689 # @retval False Not able to find\r
1690 #\r
1691 def __GetSetStatement(self, Obj):\r
1692 if self.__IsKeyword("SET"):\r
1693 PcdPair = self.__GetNextPcdName()\r
1694\r
1695 if not self.__IsToken( "="):\r
1696 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1697\r
d0acc87a
LG
1698 Value = self.__GetExpression()\r
1699 Value = self.__EvaluateConditional(Value, self.CurrentLineNumber, 'eval', True)\r
30fdf114 1700\r
6780eef1
LG
1701 if Obj:\r
1702 Obj.SetVarDict[PcdPair] = Value\r
30fdf114 1703 self.Profile.PcdDict[PcdPair] = Value\r
d0acc87a
LG
1704 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1705 self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
30fdf114
LG
1706 return True\r
1707\r
1708 return False\r
1709\r
4afd3d04
LG
1710 ## __CalcRegionExpr(self)\r
1711 #\r
1712 # Calculate expression for offset or size of a region\r
1713 #\r
1714 # @return: None if invalid expression\r
1715 # Calculated number if successfully\r
1716 #\r
1717 def __CalcRegionExpr(self):\r
1718 StartPos = self.GetFileBufferPos()\r
1719 Expr = ''\r
1720 PairCount = 0\r
1721 while not self.__EndOfFile():\r
1722 CurCh = self.__CurrentChar()\r
1723 if CurCh == '(':\r
1724 PairCount += 1\r
1725 elif CurCh == ')':\r
1726 PairCount -= 1\r
1727\r
1728 if CurCh in '|\r\n' and PairCount == 0:\r
1729 break\r
1730 Expr += CurCh\r
1731 self.__GetOneChar()\r
1732 try:\r
1733 return long(\r
1734 ValueExpression(Expr,\r
1735 dict(['%s.%s' % (Pcd[1], Pcd[0]), Val] \r
1736 for Pcd, Val in self.Profile.PcdDict.iteritems())\r
1737 )(True),0)\r
1738 except Exception:\r
1739 self.SetFileBufferPos(StartPos)\r
1740 return None\r
1741\r
30fdf114
LG
1742 ## __GetRegionLayout() method\r
1743 #\r
1744 # Get region layout for FD\r
1745 #\r
1746 # @param self The object pointer\r
1747 # @param Fd for whom region is got\r
1748 # @retval True Successfully find\r
1749 # @retval False Not able to find\r
1750 #\r
1751 def __GetRegionLayout(self, Fd):\r
4afd3d04
LG
1752 Offset = self.__CalcRegionExpr() \r
1753 if Offset == None:\r
30fdf114
LG
1754 return False\r
1755\r
1756 RegionObj = Region.Region()\r
4afd3d04 1757 RegionObj.Offset = Offset\r
30fdf114
LG
1758 Fd.RegionList.append(RegionObj)\r
1759\r
1760 if not self.__IsToken( "|"):\r
1761 raise Warning("expected '|'", self.FileName, self.CurrentLineNumber)\r
1762\r
4afd3d04
LG
1763 Size = self.__CalcRegionExpr()\r
1764 if Size == None:\r
30fdf114 1765 raise Warning("expected Region Size", self.FileName, self.CurrentLineNumber)\r
4afd3d04 1766 RegionObj.Size = Size\r
30fdf114
LG
1767\r
1768 if not self.__GetNextWord():\r
1769 return True\r
1770\r
fd171542 1771 if not self.__Token in ("SET", "FV", "FILE", "DATA", "CAPSULE"):\r
30fdf114
LG
1772 self.__UndoToken()\r
1773 RegionObj.PcdOffset = self.__GetNextPcdName()\r
1774 self.Profile.PcdDict[RegionObj.PcdOffset] = "0x%08X" % (RegionObj.Offset + long(Fd.BaseAddress, 0))\r
d0acc87a
LG
1775 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1776 self.Profile.PcdFileLineDict[RegionObj.PcdOffset] = FileLineTuple\r
30fdf114
LG
1777 if self.__IsToken( "|"):\r
1778 RegionObj.PcdSize = self.__GetNextPcdName()\r
1779 self.Profile.PcdDict[RegionObj.PcdSize] = "0x%08X" % RegionObj.Size\r
d0acc87a
LG
1780 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1781 self.Profile.PcdFileLineDict[RegionObj.PcdSize] = FileLineTuple\r
30fdf114
LG
1782\r
1783 if not self.__GetNextWord():\r
1784 return True\r
1785\r
1786 if self.__Token == "SET":\r
1787 self.__UndoToken()\r
1788 self.__GetSetStatements( RegionObj)\r
1789 if not self.__GetNextWord():\r
1790 return True\r
1791\r
fd171542 1792 elif self.__Token == "FV":\r
30fdf114
LG
1793 self.__UndoToken()\r
1794 self.__GetRegionFvType( RegionObj)\r
1795\r
fd171542 1796 elif self.__Token == "CAPSULE":\r
1797 self.__UndoToken()\r
1798 self.__GetRegionCapType( RegionObj)\r
1799\r
30fdf114
LG
1800 elif self.__Token == "FILE":\r
1801 self.__UndoToken()\r
1802 self.__GetRegionFileType( RegionObj)\r
1803\r
79b74a03 1804 elif self.__Token == "DATA":\r
30fdf114
LG
1805 self.__UndoToken()\r
1806 self.__GetRegionDataType( RegionObj)\r
79b74a03
LG
1807 else:\r
1808 raise Warning("A valid region type was not found. "\r
1809 "Valid types are [SET, FV, CAPSULE, FILE, DATA]. This error occurred",\r
1810 self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
1811\r
1812 return True\r
1813\r
1814 ## __GetRegionFvType() method\r
1815 #\r
1816 # Get region fv data for region\r
1817 #\r
1818 # @param self The object pointer\r
1819 # @param RegionObj for whom region data is got\r
1820 #\r
1821 def __GetRegionFvType(self, RegionObj):\r
1822\r
1823 if not self.__IsKeyword( "FV"):\r
1824 raise Warning("expected Keyword 'FV'", self.FileName, self.CurrentLineNumber)\r
1825\r
1826 if not self.__IsToken( "="):\r
1827 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1828\r
1829 if not self.__GetNextToken():\r
1830 raise Warning("expected FV name", self.FileName, self.CurrentLineNumber)\r
1831\r
1832 RegionObj.RegionType = "FV"\r
1833 RegionObj.RegionDataList.append(self.__Token)\r
1834\r
1835 while self.__IsKeyword( "FV"):\r
1836\r
1837 if not self.__IsToken( "="):\r
1838 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1839\r
1840 if not self.__GetNextToken():\r
1841 raise Warning("expected FV name", self.FileName, self.CurrentLineNumber)\r
1842\r
1843 RegionObj.RegionDataList.append(self.__Token)\r
1844\r
fd171542 1845 ## __GetRegionCapType() method\r
1846 #\r
1847 # Get region capsule data for region\r
1848 #\r
1849 # @param self The object pointer\r
1850 # @param RegionObj for whom region data is got\r
1851 #\r
1852 def __GetRegionCapType(self, RegionObj):\r
1853\r
1854 if not self.__IsKeyword("CAPSULE"):\r
1855 raise Warning("expected Keyword 'CAPSULE'", self.FileName, self.CurrentLineNumber)\r
1856\r
1857 if not self.__IsToken("="):\r
1858 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1859\r
1860 if not self.__GetNextToken():\r
1861 raise Warning("expected CAPSULE name", self.FileName, self.CurrentLineNumber)\r
1862\r
1863 RegionObj.RegionType = "CAPSULE"\r
1864 RegionObj.RegionDataList.append(self.__Token)\r
1865\r
1866 while self.__IsKeyword("CAPSULE"):\r
1867\r
1868 if not self.__IsToken("="):\r
1869 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1870\r
1871 if not self.__GetNextToken():\r
1872 raise Warning("expected CAPSULE name", self.FileName, self.CurrentLineNumber)\r
1873\r
1874 RegionObj.RegionDataList.append(self.__Token)\r
1875\r
30fdf114
LG
1876 ## __GetRegionFileType() method\r
1877 #\r
1878 # Get region file data for region\r
1879 #\r
1880 # @param self The object pointer\r
1881 # @param RegionObj for whom region data is got\r
1882 #\r
1883 def __GetRegionFileType(self, RegionObj):\r
1884\r
1885 if not self.__IsKeyword( "FILE"):\r
1886 raise Warning("expected Keyword 'FILE'", self.FileName, self.CurrentLineNumber)\r
1887\r
1888 if not self.__IsToken( "="):\r
1889 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1890\r
1891 if not self.__GetNextToken():\r
1892 raise Warning("expected File name", self.FileName, self.CurrentLineNumber)\r
1893\r
1894 RegionObj.RegionType = "FILE"\r
1895 RegionObj.RegionDataList.append( self.__Token)\r
1896\r
1897 while self.__IsKeyword( "FILE"):\r
1898\r
1899 if not self.__IsToken( "="):\r
1900 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1901\r
1902 if not self.__GetNextToken():\r
1903 raise Warning("expected FILE name", self.FileName, self.CurrentLineNumber)\r
1904\r
1905 RegionObj.RegionDataList.append(self.__Token)\r
1906\r
1907 ## __GetRegionDataType() method\r
1908 #\r
1909 # Get region array data for region\r
1910 #\r
1911 # @param self The object pointer\r
1912 # @param RegionObj for whom region data is got\r
1913 #\r
1914 def __GetRegionDataType(self, RegionObj):\r
1915\r
1916 if not self.__IsKeyword( "DATA"):\r
1917 raise Warning("expected Region Data type", self.FileName, self.CurrentLineNumber)\r
1918\r
1919 if not self.__IsToken( "="):\r
1920 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1921\r
1922 if not self.__IsToken( "{"):\r
1923 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
1924\r
1925 if not self.__GetNextHexNumber():\r
1926 raise Warning("expected Hex byte", self.FileName, self.CurrentLineNumber)\r
1927\r
636f2be6
LG
1928 if len(self.__Token) > 18:\r
1929 raise Warning("Hex string can't be converted to a valid UINT64 value", self.FileName, self.CurrentLineNumber)\r
1930\r
1931 # convert hex string value to byte hex string array\r
1932 AllString = self.__Token\r
1933 AllStrLen = len (AllString)\r
1934 DataString = ""\r
1935 while AllStrLen > 4:\r
1936 DataString = DataString + "0x" + AllString[AllStrLen - 2: AllStrLen] + ","\r
1937 AllStrLen = AllStrLen - 2\r
1938 DataString = DataString + AllString[:AllStrLen] + ","\r
1939\r
1940 # byte value array\r
1941 if len (self.__Token) <= 4:\r
1942 while self.__IsToken(","):\r
1943 if not self.__GetNextHexNumber():\r
1944 raise Warning("Invalid Hex number", self.FileName, self.CurrentLineNumber)\r
1945 if len(self.__Token) > 4:\r
1946 raise Warning("Hex byte(must be 2 digits) too long", self.FileName, self.CurrentLineNumber)\r
1947 DataString += self.__Token\r
1948 DataString += ","\r
30fdf114
LG
1949\r
1950 if not self.__IsToken( "}"):\r
1951 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
1952\r
1953 DataString = DataString.rstrip(",")\r
1954 RegionObj.RegionType = "DATA"\r
1955 RegionObj.RegionDataList.append( DataString)\r
1956\r
1957 while self.__IsKeyword( "DATA"):\r
1958\r
1959 if not self.__IsToken( "="):\r
1960 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1961\r
1962 if not self.__IsToken( "{"):\r
1963 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
1964\r
1965 if not self.__GetNextHexNumber():\r
1966 raise Warning("expected Hex byte", self.FileName, self.CurrentLineNumber)\r
1967\r
636f2be6
LG
1968 if len(self.__Token) > 18:\r
1969 raise Warning("Hex string can't be converted to a valid UINT64 value", self.FileName, self.CurrentLineNumber)\r
1970\r
1971 # convert hex string value to byte hex string array\r
1972 AllString = self.__Token\r
1973 AllStrLen = len (AllString)\r
1974 DataString = ""\r
1975 while AllStrLen > 4:\r
1976 DataString = DataString + "0x" + AllString[AllStrLen - 2: AllStrLen] + ","\r
1977 AllStrLen = AllStrLen - 2\r
1978 DataString = DataString + AllString[:AllStrLen] + ","\r
1979\r
1980 # byte value array\r
1981 if len (self.__Token) <= 4:\r
1982 while self.__IsToken(","):\r
1983 if not self.__GetNextHexNumber():\r
1984 raise Warning("Invalid Hex number", self.FileName, self.CurrentLineNumber)\r
1985 if len(self.__Token) > 4:\r
1986 raise Warning("Hex byte(must be 2 digits) too long", self.FileName, self.CurrentLineNumber)\r
1987 DataString += self.__Token\r
1988 DataString += ","\r
30fdf114
LG
1989\r
1990 if not self.__IsToken( "}"):\r
1991 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
1992\r
1993 DataString = DataString.rstrip(",")\r
1994 RegionObj.RegionDataList.append( DataString)\r
1995\r
1996 ## __GetFv() method\r
1997 #\r
1998 # Get FV section contents and store its data into FV dictionary of self.Profile\r
1999 #\r
2000 # @param self The object pointer\r
2001 # @retval True Successfully find a FV\r
2002 # @retval False Not able to find a FV\r
2003 #\r
2004 def __GetFv(self):\r
2005 if not self.__GetNextToken():\r
2006 return False\r
2007\r
2008 S = self.__Token.upper()\r
2009 if S.startswith("[") and not S.startswith("[FV."):\r
2010 if not S.startswith("[CAPSULE.") \\r
2011 and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
2012 raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
2013 self.__UndoToken()\r
2014 return False\r
2015\r
2016 self.__UndoToken()\r
2017 if not self.__IsToken("[FV.", True):\r
2018 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
2019 #print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \\r
2020 # % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)\r
2021 raise Warning("Unknown Keyword '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
2022\r
2023 FvName = self.__GetUiName()\r
2024 self.CurrentFvName = FvName.upper()\r
2025\r
2026 if not self.__IsToken( "]"):\r
2027 raise Warning("expected ']'", self.FileName, self.CurrentLineNumber)\r
2028\r
2029 FvObj = Fv.FV()\r
2030 FvObj.UiFvName = self.CurrentFvName\r
2031 self.Profile.FvDict[self.CurrentFvName] = FvObj\r
2032\r
2033 Status = self.__GetCreateFile(FvObj)\r
2034 if not Status:\r
2035 raise Warning("FV name error", self.FileName, self.CurrentLineNumber)\r
2036\r
2037 self.__GetDefineStatements(FvObj)\r
2038\r
2039 self.__GetAddressStatements(FvObj)\r
2040\r
b303ea72
LG
2041 FvObj.FvExtEntryTypeValue = []\r
2042 FvObj.FvExtEntryType = []\r
2043 FvObj.FvExtEntryData = []\r
2044 while True:\r
e8a47801
LG
2045 self.__GetSetStatements(FvObj)\r
2046\r
2047 if not (self.__GetBlockStatement(FvObj) or self.__GetFvBaseAddress(FvObj) or \r
2048 self.__GetFvForceRebase(FvObj) or self.__GetFvAlignment(FvObj) or \r
2049 self.__GetFvAttributes(FvObj) or self.__GetFvNameGuid(FvObj) or \r
2050 self.__GetFvExtEntryStatement(FvObj)):\r
b303ea72
LG
2051 break\r
2052\r
30fdf114
LG
2053 self.__GetAprioriSection(FvObj, FvObj.DefineVarDict.copy())\r
2054 self.__GetAprioriSection(FvObj, FvObj.DefineVarDict.copy())\r
2055\r
2056 while True:\r
2057 isInf = self.__GetInfStatement(FvObj, MacroDict = FvObj.DefineVarDict.copy())\r
2058 isFile = self.__GetFileStatement(FvObj, MacroDict = FvObj.DefineVarDict.copy())\r
2059 if not isInf and not isFile:\r
2060 break\r
2061\r
2062 return True\r
2063\r
2064 ## __GetFvAlignment() method\r
2065 #\r
2066 # Get alignment for FV\r
2067 #\r
2068 # @param self The object pointer\r
2069 # @param Obj for whom alignment is got\r
2070 # @retval True Successfully find a alignment statement\r
2071 # @retval False Not able to find a alignment statement\r
2072 #\r
2073 def __GetFvAlignment(self, Obj):\r
2074\r
2075 if not self.__IsKeyword( "FvAlignment"):\r
2076 return False\r
2077\r
2078 if not self.__IsToken( "="):\r
2079 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2080\r
2081 if not self.__GetNextToken():\r
2082 raise Warning("expected alignment value", self.FileName, self.CurrentLineNumber)\r
2083\r
2084 if self.__Token.upper() not in ("1", "2", "4", "8", "16", "32", "64", "128", "256", "512", \\r
2085 "1K", "2K", "4K", "8K", "16K", "32K", "64K", "128K", "256K", "512K", \\r
2086 "1M", "2M", "4M", "8M", "16M", "32M", "64M", "128M", "256M", "512M", \\r
2087 "1G", "2G"):\r
2088 raise Warning("Unknown alignment value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
2089 Obj.FvAlignment = self.__Token\r
2090 return True\r
4234283c
LG
2091 \r
2092 ## __GetFvBaseAddress() method\r
2093 #\r
2094 # Get BaseAddress for FV\r
2095 #\r
2096 # @param self The object pointer\r
2097 # @param Obj for whom FvBaseAddress is got\r
2098 # @retval True Successfully find a FvBaseAddress statement\r
2099 # @retval False Not able to find a FvBaseAddress statement\r
2100 #\r
2101 def __GetFvBaseAddress(self, Obj):\r
2102\r
2103 if not self.__IsKeyword("FvBaseAddress"):\r
2104 return False\r
2105\r
2106 if not self.__IsToken( "="):\r
2107 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2108\r
2109 if not self.__GetNextToken():\r
2110 raise Warning("expected FV base address value", self.FileName, self.CurrentLineNumber)\r
2111\r
2112 IsValidBaseAddrValue = re.compile('^0[x|X][0-9a-fA-F]+')\r
2113\r
2114 if not IsValidBaseAddrValue.match(self.__Token.upper()):\r
79b74a03 2115 raise Warning("Unknown FV base address value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
4234283c 2116 Obj.FvBaseAddress = self.__Token\r
0d2711a6
LG
2117 return True \r
2118 \r
79b74a03
LG
2119 ## __GetFvForceRebase() method\r
2120 #\r
2121 # Get FvForceRebase for FV\r
2122 #\r
2123 # @param self The object pointer\r
2124 # @param Obj for whom FvForceRebase is got\r
2125 # @retval True Successfully find a FvForceRebase statement\r
2126 # @retval False Not able to find a FvForceRebase statement\r
2127 #\r
2128 def __GetFvForceRebase(self, Obj):\r
2129\r
2130 if not self.__IsKeyword("FvForceRebase"):\r
2131 return False\r
2132\r
2133 if not self.__IsToken( "="):\r
2134 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2135\r
2136 if not self.__GetNextToken():\r
2137 raise Warning("expected FvForceRebase value", self.FileName, self.CurrentLineNumber)\r
30fdf114 2138\r
79b74a03
LG
2139 if self.__Token.upper() not in ["TRUE", "FALSE", "0", "0X0", "0X00", "1", "0X1", "0X01"]:\r
2140 raise Warning("Unknown FvForceRebase value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
2141 \r
2142 if self.__Token.upper() in ["TRUE", "1", "0X1", "0X01"]:\r
2143 Obj.FvForceRebase = True\r
2144 elif self.__Token.upper() in ["FALSE", "0", "0X0", "0X00"]:\r
2145 Obj.FvForceRebase = False\r
2146 else:\r
2147 Obj.FvForceRebase = None\r
2148 \r
2149 return True\r
0d2711a6
LG
2150\r
2151\r
30fdf114
LG
2152 ## __GetFvAttributes() method\r
2153 #\r
2154 # Get attributes for FV\r
2155 #\r
2156 # @param self The object pointer\r
2157 # @param Obj for whom attribute is got\r
2158 # @retval None\r
2159 #\r
2160 def __GetFvAttributes(self, FvObj):\r
2161\r
2162 while self.__GetNextWord():\r
2163 name = self.__Token\r
2164 if name not in ("ERASE_POLARITY", "MEMORY_MAPPED", \\r
2165 "STICKY_WRITE", "LOCK_CAP", "LOCK_STATUS", "WRITE_ENABLED_CAP", \\r
2166 "WRITE_DISABLED_CAP", "WRITE_STATUS", "READ_ENABLED_CAP", \\r
2167 "READ_DISABLED_CAP", "READ_STATUS", "READ_LOCK_CAP", \\r
2168 "READ_LOCK_STATUS", "WRITE_LOCK_CAP", "WRITE_LOCK_STATUS", \\r
e8a47801 2169 "WRITE_POLICY_RELIABLE", "WEAK_ALIGNMENT"):\r
30fdf114 2170 self.__UndoToken()\r
e8a47801 2171 return False\r
30fdf114
LG
2172\r
2173 if not self.__IsToken( "="):\r
2174 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2175\r
2176 if not self.__GetNextToken() or self.__Token.upper() not in ("TRUE", "FALSE", "1", "0"):\r
2177 raise Warning("expected TRUE/FALSE (1/0)", self.FileName, self.CurrentLineNumber)\r
2178\r
2179 FvObj.FvAttributeDict[name] = self.__Token\r
2180\r
e8a47801 2181 return True\r
30fdf114
LG
2182 \r
2183 ## __GetFvNameGuid() method\r
2184 #\r
2185 # Get FV GUID for FV\r
2186 #\r
2187 # @param self The object pointer\r
2188 # @param Obj for whom GUID is got\r
2189 # @retval None\r
2190 #\r
2191 def __GetFvNameGuid(self, FvObj):\r
2192\r
2193 if not self.__IsKeyword( "FvNameGuid"):\r
e8a47801 2194 return False\r
30fdf114
LG
2195\r
2196 if not self.__IsToken( "="):\r
2197 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2198\r
2199 if not self.__GetNextGuid():\r
2200 raise Warning("expected FV GUID value", self.FileName, self.CurrentLineNumber)\r
2201\r
2202 FvObj.FvNameGuid = self.__Token\r
2203\r
e8a47801 2204 return True\r
30fdf114 2205\r
b303ea72
LG
2206 def __GetFvExtEntryStatement(self, FvObj):\r
2207\r
2208 if not self.__IsKeyword( "FV_EXT_ENTRY"):\r
2209 return False\r
2210\r
2211 if not self.__IsKeyword ("TYPE"):\r
2212 raise Warning("expected 'TYPE'", self.FileName, self.CurrentLineNumber)\r
2213 \r
2214 if not self.__IsToken( "="):\r
2215 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2216\r
2217 if not self.__GetNextHexNumber() and not self.__GetNextDecimalNumber():\r
2218 raise Warning("expected Hex FV extension entry type value At Line ", self.FileName, self.CurrentLineNumber)\r
2219\r
2220 FvObj.FvExtEntryTypeValue += [self.__Token]\r
2221\r
2222 if not self.__IsToken( "{"):\r
2223 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2224\r
2225 if not self.__IsKeyword ("FILE") and not self.__IsKeyword ("DATA"):\r
2226 raise Warning("expected 'FILE' or 'DATA'", self.FileName, self.CurrentLineNumber)\r
2227\r
2228 FvObj.FvExtEntryType += [self.__Token]\r
2229\r
2230 if self.__Token == 'DATA':\r
2231\r
2232 if not self.__IsToken( "="):\r
2233 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2234 \r
2235 if not self.__IsToken( "{"):\r
2236 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2237\r
2238 if not self.__GetNextHexNumber():\r
2239 raise Warning("expected Hex byte", self.FileName, self.CurrentLineNumber)\r
2240\r
2241 if len(self.__Token) > 4:\r
2242 raise Warning("Hex byte(must be 2 digits) too long", self.FileName, self.CurrentLineNumber)\r
2243\r
2244 DataString = self.__Token\r
2245 DataString += ","\r
2246\r
2247 while self.__IsToken(","):\r
2248 if not self.__GetNextHexNumber():\r
2249 raise Warning("Invalid Hex number", self.FileName, self.CurrentLineNumber)\r
2250 if len(self.__Token) > 4:\r
2251 raise Warning("Hex byte(must be 2 digits) too long", self.FileName, self.CurrentLineNumber)\r
2252 DataString += self.__Token\r
2253 DataString += ","\r
2254\r
2255 if not self.__IsToken( "}"):\r
2256 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2257\r
2258 if not self.__IsToken( "}"):\r
2259 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2260\r
2261 DataString = DataString.rstrip(",")\r
2262 FvObj.FvExtEntryData += [DataString]\r
2263\r
2264 if self.__Token == 'FILE':\r
2265 \r
2266 if not self.__IsToken( "="):\r
2267 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2268 \r
2269 if not self.__GetNextToken():\r
2270 raise Warning("expected FV Extension Entry file path At Line ", self.FileName, self.CurrentLineNumber)\r
2271 \r
2272 FvObj.FvExtEntryData += [self.__Token]\r
2273\r
2274 if not self.__IsToken( "}"):\r
2275 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2276\r
2277 return True\r
2278\r
30fdf114
LG
2279 ## __GetAprioriSection() method\r
2280 #\r
2281 # Get token statements\r
2282 #\r
2283 # @param self The object pointer\r
2284 # @param FvObj for whom apriori is got\r
2285 # @param MacroDict dictionary used to replace macro\r
2286 # @retval True Successfully find apriori statement\r
2287 # @retval False Not able to find apriori statement\r
2288 #\r
2289 def __GetAprioriSection(self, FvObj, MacroDict = {}):\r
2290\r
2291 if not self.__IsKeyword( "APRIORI"):\r
2292 return False\r
2293\r
2294 if not self.__IsKeyword("PEI") and not self.__IsKeyword("DXE"):\r
2295 raise Warning("expected Apriori file type", self.FileName, self.CurrentLineNumber)\r
2296 AprType = self.__Token\r
2297\r
2298 if not self.__IsToken( "{"):\r
2299 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2300\r
2301 AprSectionObj = AprioriSection.AprioriSection()\r
2302 AprSectionObj.AprioriType = AprType\r
2303\r
2304 self.__GetDefineStatements(AprSectionObj)\r
2305 MacroDict.update(AprSectionObj.DefineVarDict)\r
2306\r
2307 while True:\r
2308 IsInf = self.__GetInfStatement( AprSectionObj, MacroDict = MacroDict)\r
2309 IsFile = self.__GetFileStatement( AprSectionObj)\r
2310 if not IsInf and not IsFile:\r
2311 break\r
2312\r
2313 if not self.__IsToken( "}"):\r
2314 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2315\r
2316 FvObj.AprioriSectionList.append(AprSectionObj)\r
2317 return True\r
2318\r
2319 ## __GetInfStatement() method\r
2320 #\r
2321 # Get INF statements\r
2322 #\r
2323 # @param self The object pointer\r
2324 # @param Obj for whom inf statement is got\r
2325 # @param MacroDict dictionary used to replace macro\r
2326 # @retval True Successfully find inf statement\r
2327 # @retval False Not able to find inf statement\r
2328 #\r
2329 def __GetInfStatement(self, Obj, ForCapsule = False, MacroDict = {}):\r
2330\r
2331 if not self.__IsKeyword( "INF"):\r
2332 return False\r
2333\r
2334 ffsInf = FfsInfStatement.FfsInfStatement()\r
2335 self.__GetInfOptions( ffsInf)\r
2336\r
2337 if not self.__GetNextToken():\r
2338 raise Warning("expected INF file path", self.FileName, self.CurrentLineNumber)\r
2339 ffsInf.InfFileName = self.__Token\r
64b2609f
LG
2340\r
2341 ffsInf.CurrentLineNum = self.CurrentLineNumber\r
2342 ffsInf.CurrentLineContent = self.__CurrentLine()\r
2343\r
14c48571 2344 if ffsInf.InfFileName.replace('$(WORKSPACE)', '').find('$') == -1:\r
2345 #do case sensitive check for file path\r
2346 ErrorCode, ErrorInfo = PathClass(NormPath(ffsInf.InfFileName), GenFdsGlobalVariable.WorkSpaceDir).Validate()\r
2347 if ErrorCode != 0:\r
2348 EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)\r
30fdf114 2349\r
30fdf114
LG
2350 if not ffsInf.InfFileName in self.Profile.InfList:\r
2351 self.Profile.InfList.append(ffsInf.InfFileName)\r
d0acc87a
LG
2352 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
2353 self.Profile.InfFileLineList.append(FileLineTuple)\r
30fdf114
LG
2354\r
2355 if self.__IsToken('|'):\r
2356 if self.__IsKeyword('RELOCS_STRIPPED'):\r
2357 ffsInf.KeepReloc = False\r
2358 elif self.__IsKeyword('RELOCS_RETAINED'):\r
2359 ffsInf.KeepReloc = True\r
2360 else:\r
2361 raise Warning("Unknown reloc strip flag '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
79b74a03 2362 \r
30fdf114
LG
2363 if ForCapsule:\r
2364 capsuleFfs = CapsuleData.CapsuleFfs()\r
2365 capsuleFfs.Ffs = ffsInf\r
2366 Obj.CapsuleDataList.append(capsuleFfs)\r
2367 else:\r
2368 Obj.FfsList.append(ffsInf)\r
2369 return True\r
2370\r
2371 ## __GetInfOptions() method\r
2372 #\r
2373 # Get options for INF\r
2374 #\r
2375 # @param self The object pointer\r
2376 # @param FfsInfObj for whom option is got\r
2377 #\r
2378 def __GetInfOptions(self, FfsInfObj):\r
2379\r
2380 if self.__IsKeyword( "RuleOverride"):\r
2381 if not self.__IsToken( "="):\r
2382 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2383 if not self.__GetNextToken():\r
2384 raise Warning("expected Rule name", self.FileName, self.CurrentLineNumber)\r
2385 FfsInfObj.Rule = self.__Token\r
2386\r
2387 if self.__IsKeyword( "VERSION"):\r
2388 if not self.__IsToken( "="):\r
2389 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2390 if not self.__GetNextToken():\r
2391 raise Warning("expected Version", self.FileName, self.CurrentLineNumber)\r
2392\r
2393 if self.__GetStringData():\r
2394 FfsInfObj.Version = self.__Token\r
2395\r
2396 if self.__IsKeyword( "UI"):\r
2397 if not self.__IsToken( "="):\r
2398 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2399 if not self.__GetNextToken():\r
2400 raise Warning("expected UI name", self.FileName, self.CurrentLineNumber)\r
2401\r
2402 if self.__GetStringData():\r
2403 FfsInfObj.Ui = self.__Token\r
2404\r
2405 if self.__IsKeyword( "USE"):\r
2406 if not self.__IsToken( "="):\r
2407 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2408 if not self.__GetNextToken():\r
2409 raise Warning("expected ARCH name", self.FileName, self.CurrentLineNumber)\r
2410 FfsInfObj.UseArch = self.__Token\r
2411\r
2412 \r
2413 if self.__GetNextToken():\r
2414 p = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
2415 if p.match(self.__Token):\r
2416 FfsInfObj.KeyStringList.append(self.__Token)\r
2417 if not self.__IsToken(","):\r
2418 return\r
2419 else:\r
2420 self.__UndoToken()\r
2421 return\r
2422\r
2423 while self.__GetNextToken():\r
2424 if not p.match(self.__Token):\r
2425 raise Warning("expected KeyString \"Target_Tag_Arch\"", self.FileName, self.CurrentLineNumber)\r
2426 FfsInfObj.KeyStringList.append(self.__Token)\r
2427\r
2428 if not self.__IsToken(","):\r
2429 break\r
2430\r
2431 ## __GetFileStatement() method\r
2432 #\r
2433 # Get FILE statements\r
2434 #\r
2435 # @param self The object pointer\r
2436 # @param Obj for whom FILE statement is got\r
2437 # @param MacroDict dictionary used to replace macro\r
2438 # @retval True Successfully find FILE statement\r
2439 # @retval False Not able to find FILE statement\r
2440 #\r
2441 def __GetFileStatement(self, Obj, ForCapsule = False, MacroDict = {}):\r
2442\r
2443 if not self.__IsKeyword( "FILE"):\r
2444 return False\r
2445\r
30fdf114
LG
2446 if not self.__GetNextWord():\r
2447 raise Warning("expected FFS type", self.FileName, self.CurrentLineNumber)\r
b36d134f
LG
2448\r
2449 if ForCapsule and self.__Token == 'DATA':\r
2450 self.__UndoToken()\r
2451 self.__UndoToken()\r
2452 return False\r
2453 \r
2454 FfsFileObj = FfsFileStatement.FileStatement()\r
30fdf114
LG
2455 FfsFileObj.FvFileType = self.__Token\r
2456\r
2457 if not self.__IsToken( "="):\r
2458 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2459\r
2460 if not self.__GetNextGuid():\r
2461 if not self.__GetNextWord():\r
2462 raise Warning("expected File GUID", self.FileName, self.CurrentLineNumber)\r
2463 if self.__Token == 'PCD':\r
2464 if not self.__IsToken( "("):\r
2465 raise Warning("expected '('", self.FileName, self.CurrentLineNumber)\r
2466 PcdPair = self.__GetNextPcdName()\r
2467 if not self.__IsToken( ")"):\r
2468 raise Warning("expected ')'", self.FileName, self.CurrentLineNumber)\r
2469 self.__Token = 'PCD('+PcdPair[1]+'.'+PcdPair[0]+')'\r
2470 \r
2471 FfsFileObj.NameGuid = self.__Token\r
79b74a03 2472 \r
30fdf114
LG
2473 self.__GetFilePart( FfsFileObj, MacroDict.copy())\r
2474\r
2475 if ForCapsule:\r
2476 capsuleFfs = CapsuleData.CapsuleFfs()\r
2477 capsuleFfs.Ffs = FfsFileObj\r
2478 Obj.CapsuleDataList.append(capsuleFfs)\r
2479 else:\r
2480 Obj.FfsList.append(FfsFileObj)\r
2481\r
2482 return True\r
2483\r
2484 ## __FileCouldHaveRelocFlag() method\r
2485 #\r
2486 # Check whether reloc strip flag can be set for a file type.\r
2487 #\r
2488 # @param self The object pointer\r
2489 # @param FileType The file type to check with\r
2490 # @retval True This type could have relocation strip flag\r
2491 # @retval False No way to have it\r
2492 #\r
2493\r
2494 def __FileCouldHaveRelocFlag (self, FileType):\r
2495 if FileType in ('SEC', 'PEI_CORE', 'PEIM', 'PEI_DXE_COMBO'):\r
2496 return True\r
2497 else:\r
2498 return False\r
2499\r
2500 ## __SectionCouldHaveRelocFlag() method\r
2501 #\r
2502 # Check whether reloc strip flag can be set for a section type.\r
2503 #\r
2504 # @param self The object pointer\r
2505 # @param SectionType The section type to check with\r
2506 # @retval True This type could have relocation strip flag\r
2507 # @retval False No way to have it\r
2508 #\r
2509\r
2510 def __SectionCouldHaveRelocFlag (self, SectionType):\r
2511 if SectionType in ('TE', 'PE32'):\r
2512 return True\r
2513 else:\r
2514 return False\r
2515\r
2516 ## __GetFilePart() method\r
2517 #\r
2518 # Get components for FILE statement\r
2519 #\r
2520 # @param self The object pointer\r
2521 # @param FfsFileObj for whom component is got\r
2522 # @param MacroDict dictionary used to replace macro\r
2523 #\r
2524 def __GetFilePart(self, FfsFileObj, MacroDict = {}):\r
2525\r
2526 self.__GetFileOpts( FfsFileObj)\r
2527\r
2528 if not self.__IsToken("{"):\r
4afd3d04
LG
2529 if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'):\r
2530 if self.__FileCouldHaveRelocFlag(FfsFileObj.FvFileType):\r
2531 if self.__Token == 'RELOCS_STRIPPED':\r
2532 FfsFileObj.KeepReloc = False\r
2533 else:\r
2534 FfsFileObj.KeepReloc = True\r
2535 else:\r
2536 raise Warning("File type %s could not have reloc strip flag%d" % (FfsFileObj.FvFileType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
2537\r
2538 if not self.__IsToken("{"):\r
30fdf114
LG
2539 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2540\r
2541 if not self.__GetNextToken():\r
2542 raise Warning("expected File name or section data", self.FileName, self.CurrentLineNumber)\r
2543\r
2544 if self.__Token == "FV":\r
2545 if not self.__IsToken( "="):\r
2546 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2547 if not self.__GetNextToken():\r
2548 raise Warning("expected FV name", self.FileName, self.CurrentLineNumber)\r
2549 FfsFileObj.FvName = self.__Token\r
2550\r
2551 elif self.__Token == "FD":\r
2552 if not self.__IsToken( "="):\r
2553 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2554 if not self.__GetNextToken():\r
2555 raise Warning("expected FD name", self.FileName, self.CurrentLineNumber)\r
2556 FfsFileObj.FdName = self.__Token\r
2557\r
2558 elif self.__Token in ("DEFINE", "APRIORI", "SECTION"):\r
2559 self.__UndoToken()\r
2560 self.__GetSectionData( FfsFileObj, MacroDict)\r
2561 else:\r
64b2609f
LG
2562 FfsFileObj.CurrentLineNum = self.CurrentLineNumber\r
2563 FfsFileObj.CurrentLineContent = self.__CurrentLine()\r
30fdf114 2564 FfsFileObj.FileName = self.__Token\r
14c48571 2565 if FfsFileObj.FileName.replace('$(WORKSPACE)', '').find('$') == -1:\r
df692f02
LG
2566 #\r
2567 # For file in OUTPUT_DIRECTORY will not check whether it exist or not at AutoGen phase.\r
2568 #\r
2569 if not GlobalData.gAutoGenPhase:\r
2570 #do case sensitive check for file path\r
2571 ErrorCode, ErrorInfo = PathClass(NormPath(FfsFileObj.FileName), GenFdsGlobalVariable.WorkSpaceDir).Validate()\r
2572 if ErrorCode != 0:\r
2573 EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)\r
2574 else:\r
d0acc87a 2575 if not self.__GetMacroValue("OUTPUT_DIRECTORY") in FfsFileObj.FileName:\r
df692f02
LG
2576 #do case sensitive check for file path\r
2577 ErrorCode, ErrorInfo = PathClass(NormPath(FfsFileObj.FileName), GenFdsGlobalVariable.WorkSpaceDir).Validate()\r
2578 if ErrorCode != 0:\r
2579 EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo) \r
30fdf114 2580\r
0d2711a6 2581\r
30fdf114
LG
2582 if not self.__IsToken( "}"):\r
2583 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2584\r
2585 ## __GetFileOpts() method\r
2586 #\r
2587 # Get options for FILE statement\r
2588 #\r
2589 # @param self The object pointer\r
2590 # @param FfsFileObj for whom options is got\r
2591 #\r
2592 def __GetFileOpts(self, FfsFileObj):\r
2593\r
2594 if self.__GetNextToken():\r
2595 Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
2596 if Pattern.match(self.__Token):\r
2597 FfsFileObj.KeyStringList.append(self.__Token)\r
2598 if self.__IsToken(","):\r
2599 while self.__GetNextToken():\r
2600 if not Pattern.match(self.__Token):\r
2601 raise Warning("expected KeyString \"Target_Tag_Arch\"", self.FileName, self.CurrentLineNumber)\r
2602 FfsFileObj.KeyStringList.append(self.__Token)\r
2603\r
2604 if not self.__IsToken(","):\r
2605 break\r
2606\r
2607 else:\r
2608 self.__UndoToken()\r
2609\r
2610 if self.__IsKeyword( "FIXED", True):\r
2611 FfsFileObj.Fixed = True\r
2612\r
2613 if self.__IsKeyword( "CHECKSUM", True):\r
2614 FfsFileObj.CheckSum = True\r
2615\r
2616 if self.__GetAlignment():\r
9053bc51 2617 if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
2618 raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
2619 #For FFS, Auto is default option same to ""\r
2620 if not self.__Token == "Auto":\r
2621 FfsFileObj.Alignment = self.__Token\r
30fdf114
LG
2622\r
2623 ## __GetAlignment() method\r
2624 #\r
2625 # Return the alignment value\r
2626 #\r
2627 # @param self The object pointer\r
2628 # @retval True Successfully find alignment\r
2629 # @retval False Not able to find alignment\r
2630 #\r
2631 def __GetAlignment(self):\r
2632 if self.__IsKeyword( "Align", True):\r
2633 if not self.__IsToken( "="):\r
2634 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2635\r
2636 if not self.__GetNextToken():\r
2637 raise Warning("expected alignment value", self.FileName, self.CurrentLineNumber)\r
2638 return True\r
2639\r
2640 return False\r
2641\r
2642 ## __GetFilePart() method\r
2643 #\r
2644 # Get section data for FILE statement\r
2645 #\r
2646 # @param self The object pointer\r
2647 # @param FfsFileObj for whom section is got\r
2648 # @param MacroDict dictionary used to replace macro\r
2649 #\r
2650 def __GetSectionData(self, FfsFileObj, MacroDict = {}):\r
2651 Dict = {}\r
2652 Dict.update(MacroDict)\r
2653\r
2654 self.__GetDefineStatements(FfsFileObj)\r
2655\r
2656 Dict.update(FfsFileObj.DefineVarDict)\r
2657 self.__GetAprioriSection(FfsFileObj, Dict.copy())\r
2658 self.__GetAprioriSection(FfsFileObj, Dict.copy())\r
2659\r
2660 while True:\r
2661 IsLeafSection = self.__GetLeafSection(FfsFileObj, Dict)\r
2662 IsEncapSection = self.__GetEncapsulationSec(FfsFileObj)\r
2663 if not IsLeafSection and not IsEncapSection:\r
2664 break\r
2665\r
2666 ## __GetLeafSection() method\r
2667 #\r
2668 # Get leaf section for Obj\r
2669 #\r
2670 # @param self The object pointer\r
2671 # @param Obj for whom leaf section is got\r
2672 # @param MacroDict dictionary used to replace macro\r
2673 # @retval True Successfully find section statement\r
2674 # @retval False Not able to find section statement\r
2675 #\r
2676 def __GetLeafSection(self, Obj, MacroDict = {}):\r
2677\r
2678 OldPos = self.GetFileBufferPos()\r
2679\r
2680 if not self.__IsKeyword( "SECTION"):\r
2681 if len(Obj.SectionList) == 0:\r
2682 raise Warning("expected SECTION", self.FileName, self.CurrentLineNumber)\r
2683 else:\r
2684 return False\r
2685\r
2686 AlignValue = None\r
2687 if self.__GetAlignment():\r
52302d4d
LG
2688 if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
2689 raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2690 AlignValue = self.__Token\r
2691\r
2692 BuildNum = None\r
2693 if self.__IsKeyword( "BUILD_NUM"):\r
2694 if not self.__IsToken( "="):\r
2695 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2696\r
2697 if not self.__GetNextToken():\r
2698 raise Warning("expected Build number value", self.FileName, self.CurrentLineNumber)\r
2699\r
2700 BuildNum = self.__Token\r
2701\r
2702 if self.__IsKeyword( "VERSION"):\r
52302d4d
LG
2703 if AlignValue == 'Auto':\r
2704 raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2705 if not self.__IsToken( "="):\r
2706 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2707 if not self.__GetNextToken():\r
2708 raise Warning("expected version", self.FileName, self.CurrentLineNumber)\r
2709 VerSectionObj = VerSection.VerSection()\r
2710 VerSectionObj.Alignment = AlignValue\r
2711 VerSectionObj.BuildNum = BuildNum\r
2712 if self.__GetStringData():\r
2713 VerSectionObj.StringData = self.__Token\r
2714 else:\r
2715 VerSectionObj.FileName = self.__Token\r
2716 Obj.SectionList.append(VerSectionObj)\r
52302d4d 2717 \r
30fdf114 2718 elif self.__IsKeyword( "UI"):\r
52302d4d
LG
2719 if AlignValue == 'Auto':\r
2720 raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2721 if not self.__IsToken( "="):\r
2722 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2723 if not self.__GetNextToken():\r
2724 raise Warning("expected UI", self.FileName, self.CurrentLineNumber)\r
2725 UiSectionObj = UiSection.UiSection()\r
2726 UiSectionObj.Alignment = AlignValue\r
2727 if self.__GetStringData():\r
2728 UiSectionObj.StringData = self.__Token\r
2729 else:\r
2730 UiSectionObj.FileName = self.__Token\r
2731 Obj.SectionList.append(UiSectionObj)\r
2732\r
2733 elif self.__IsKeyword( "FV_IMAGE"):\r
52302d4d
LG
2734 if AlignValue == 'Auto':\r
2735 raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2736 if not self.__IsToken( "="):\r
2737 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2738 if not self.__GetNextToken():\r
2739 raise Warning("expected FV name or FV file path", self.FileName, self.CurrentLineNumber)\r
2740\r
2741 FvName = self.__Token\r
2742 FvObj = None\r
2743\r
2744 if self.__IsToken( "{"):\r
2745 FvObj = Fv.FV()\r
2746 FvObj.UiFvName = FvName.upper()\r
2747 self.__GetDefineStatements(FvObj)\r
2748 MacroDict.update(FvObj.DefineVarDict)\r
2749 self.__GetBlockStatement(FvObj)\r
2750 self.__GetSetStatements(FvObj)\r
2751 self.__GetFvAlignment(FvObj)\r
2752 self.__GetFvAttributes(FvObj)\r
2753 self.__GetAprioriSection(FvObj, MacroDict.copy())\r
2754 self.__GetAprioriSection(FvObj, MacroDict.copy())\r
2755\r
2756 while True:\r
2757 IsInf = self.__GetInfStatement(FvObj, MacroDict.copy())\r
2758 IsFile = self.__GetFileStatement(FvObj, MacroDict.copy())\r
2759 if not IsInf and not IsFile:\r
2760 break\r
2761\r
2762 if not self.__IsToken( "}"):\r
2763 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2764\r
2765 FvImageSectionObj = FvImageSection.FvImageSection()\r
2766 FvImageSectionObj.Alignment = AlignValue\r
2767 if FvObj != None:\r
2768 FvImageSectionObj.Fv = FvObj\r
2769 FvImageSectionObj.FvName = None\r
2770 else:\r
2771 FvImageSectionObj.FvName = FvName.upper()\r
2772 FvImageSectionObj.FvFileName = FvName\r
2773\r
2774 Obj.SectionList.append(FvImageSectionObj)\r
2775\r
2776 elif self.__IsKeyword("PEI_DEPEX_EXP") or self.__IsKeyword("DXE_DEPEX_EXP") or self.__IsKeyword("SMM_DEPEX_EXP"):\r
52302d4d
LG
2777 if AlignValue == 'Auto':\r
2778 raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2779 DepexSectionObj = DepexSection.DepexSection()\r
2780 DepexSectionObj.Alignment = AlignValue\r
2781 DepexSectionObj.DepexType = self.__Token\r
2782\r
2783 if not self.__IsToken( "="):\r
2784 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2785 if not self.__IsToken( "{"):\r
2786 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2787 if not self.__SkipToToken( "}"):\r
2788 raise Warning("expected Depex expression ending '}'", self.FileName, self.CurrentLineNumber)\r
2789\r
2790 DepexSectionObj.Expression = self.__SkippedChars.rstrip('}')\r
2791 Obj.SectionList.append(DepexSectionObj)\r
2792\r
2793 else:\r
30fdf114
LG
2794 if not self.__GetNextWord():\r
2795 raise Warning("expected section type", self.FileName, self.CurrentLineNumber)\r
2796\r
2797 # Encapsulation section appear, UndoToken and return\r
2798 if self.__Token == "COMPRESS" or self.__Token == "GUIDED":\r
2799 self.SetFileBufferPos(OldPos)\r
2800 return False\r
2801\r
2802 if self.__Token not in ("COMPAT16", "PE32", "PIC", "TE", "FV_IMAGE", "RAW", "DXE_DEPEX",\\r
2803 "UI", "VERSION", "PEI_DEPEX", "SUBTYPE_GUID", "SMM_DEPEX"):\r
2804 raise Warning("Unknown section type '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
52302d4d
LG
2805 if AlignValue == 'Auto'and (not self.__Token == 'PE32') and (not self.__Token == 'TE'):\r
2806 raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
2807\r
30fdf114
LG
2808 # DataSection\r
2809 DataSectionObj = DataSection.DataSection()\r
2810 DataSectionObj.Alignment = AlignValue\r
2811 DataSectionObj.SecType = self.__Token\r
2812\r
2813 if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'):\r
2814 if self.__FileCouldHaveRelocFlag(Obj.FvFileType) and self.__SectionCouldHaveRelocFlag(DataSectionObj.SecType):\r
2815 if self.__Token == 'RELOCS_STRIPPED':\r
2816 DataSectionObj.KeepReloc = False\r
2817 else:\r
2818 DataSectionObj.KeepReloc = True\r
2819 else:\r
2820 raise Warning("File type %s, section type %s, could not have reloc strip flag%d" % (Obj.FvFileType, DataSectionObj.SecType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
2821\r
2822 if self.__IsToken("="):\r
2823 if not self.__GetNextToken():\r
2824 raise Warning("expected section file path", self.FileName, self.CurrentLineNumber)\r
2825 DataSectionObj.SectFileName = self.__Token\r
14c48571 2826 if DataSectionObj.SectFileName.replace('$(WORKSPACE)', '').find('$') == -1:\r
2827 #do case sensitive check for file path\r
2828 ErrorCode, ErrorInfo = PathClass(NormPath(DataSectionObj.SectFileName), GenFdsGlobalVariable.WorkSpaceDir).Validate()\r
2829 if ErrorCode != 0:\r
2830 EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)\r
30fdf114
LG
2831 else:\r
2832 if not self.__GetCglSection(DataSectionObj):\r
2833 return False\r
2834\r
2835 Obj.SectionList.append(DataSectionObj)\r
2836\r
2837 return True\r
2838\r
2839 ## __GetCglSection() method\r
2840 #\r
2841 # Get compressed or GUIDed section for Obj\r
2842 #\r
2843 # @param self The object pointer\r
2844 # @param Obj for whom leaf section is got\r
2845 # @param AlignValue alignment value for complex section\r
2846 # @retval True Successfully find section statement\r
2847 # @retval False Not able to find section statement\r
2848 #\r
2849 def __GetCglSection(self, Obj, AlignValue = None):\r
2850\r
2851 if self.__IsKeyword( "COMPRESS"):\r
2852 type = "PI_STD"\r
2853 if self.__IsKeyword("PI_STD") or self.__IsKeyword("PI_NONE"):\r
2854 type = self.__Token\r
2855\r
2856 if not self.__IsToken("{"):\r
2857 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2858\r
2859 CompressSectionObj = CompressSection.CompressSection()\r
2860 CompressSectionObj.Alignment = AlignValue\r
2861 CompressSectionObj.CompType = type\r
2862 # Recursive sections...\r
2863 while True:\r
2864 IsLeafSection = self.__GetLeafSection(CompressSectionObj)\r
2865 IsEncapSection = self.__GetEncapsulationSec(CompressSectionObj)\r
2866 if not IsLeafSection and not IsEncapSection:\r
2867 break\r
2868\r
2869\r
2870 if not self.__IsToken( "}"):\r
2871 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2872 Obj.SectionList.append(CompressSectionObj)\r
2873\r
2874# else:\r
2875# raise Warning("Compress type not known")\r
2876\r
2877 return True\r
2878\r
2879 elif self.__IsKeyword( "GUIDED"):\r
2880 GuidValue = None\r
2881 if self.__GetNextGuid():\r
2882 GuidValue = self.__Token\r
2883\r
2884 AttribDict = self.__GetGuidAttrib()\r
2885 if not self.__IsToken("{"):\r
2886 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2887 GuidSectionObj = GuidSection.GuidSection()\r
2888 GuidSectionObj.Alignment = AlignValue\r
2889 GuidSectionObj.NameGuid = GuidValue\r
2890 GuidSectionObj.SectionType = "GUIDED"\r
2891 GuidSectionObj.ProcessRequired = AttribDict["PROCESSING_REQUIRED"]\r
2892 GuidSectionObj.AuthStatusValid = AttribDict["AUTH_STATUS_VALID"]\r
25918452 2893 GuidSectionObj.ExtraHeaderSize = AttribDict["EXTRA_HEADER_SIZE"]\r
30fdf114
LG
2894 # Recursive sections...\r
2895 while True:\r
2896 IsLeafSection = self.__GetLeafSection(GuidSectionObj)\r
2897 IsEncapSection = self.__GetEncapsulationSec(GuidSectionObj)\r
2898 if not IsLeafSection and not IsEncapSection:\r
2899 break\r
2900\r
2901 if not self.__IsToken( "}"):\r
2902 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2903 Obj.SectionList.append(GuidSectionObj)\r
2904\r
2905 return True\r
2906\r
2907 return False\r
2908\r
2909 ## __GetGuidAttri() method\r
2910 #\r
2911 # Get attributes for GUID section\r
2912 #\r
2913 # @param self The object pointer\r
2914 # @retval AttribDict Dictionary of key-value pair of section attributes\r
2915 #\r
2916 def __GetGuidAttrib(self):\r
2917\r
2918 AttribDict = {}\r
14c48571 2919 AttribDict["PROCESSING_REQUIRED"] = "NONE"\r
2920 AttribDict["AUTH_STATUS_VALID"] = "NONE"\r
25918452
LG
2921 AttribDict["EXTRA_HEADER_SIZE"] = -1\r
2922 while self.__IsKeyword("PROCESSING_REQUIRED") or self.__IsKeyword("AUTH_STATUS_VALID") \\r
2923 or self.__IsKeyword("EXTRA_HEADER_SIZE"):\r
30fdf114
LG
2924 AttribKey = self.__Token\r
2925\r
2926 if not self.__IsToken("="):\r
2927 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2928\r
25918452
LG
2929 if not self.__GetNextToken():\r
2930 raise Warning("expected TRUE(1)/FALSE(0)/Number", self.FileName, self.CurrentLineNumber)\r
2931 elif AttribKey == "EXTRA_HEADER_SIZE":\r
2932 Base = 10\r
2933 if self.__Token[0:2].upper() == "0X":\r
2934 Base = 16\r
2935 try:\r
2936 AttribDict[AttribKey] = int(self.__Token, Base)\r
2937 continue\r
2938 except ValueError:\r
2939 raise Warning("expected Number", self.FileName, self.CurrentLineNumber)\r
2940 elif self.__Token.upper() not in ("TRUE", "FALSE", "1", "0"):\r
30fdf114
LG
2941 raise Warning("expected TRUE/FALSE (1/0)", self.FileName, self.CurrentLineNumber)\r
2942 AttribDict[AttribKey] = self.__Token\r
2943\r
2944 return AttribDict\r
2945\r
2946 ## __GetEncapsulationSec() method\r
2947 #\r
2948 # Get encapsulation section for FILE\r
2949 #\r
2950 # @param self The object pointer\r
2951 # @param FfsFile for whom section is got\r
2952 # @retval True Successfully find section statement\r
2953 # @retval False Not able to find section statement\r
2954 #\r
2955 def __GetEncapsulationSec(self, FfsFileObj):\r
2956\r
2957 OldPos = self.GetFileBufferPos()\r
2958 if not self.__IsKeyword( "SECTION"):\r
2959 if len(FfsFileObj.SectionList) == 0:\r
2960 raise Warning("expected SECTION", self.FileName, self.CurrentLineNumber)\r
2961 else:\r
2962 return False\r
2963\r
2964 AlignValue = None\r
2965 if self.__GetAlignment():\r
52302d4d
LG
2966 if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
2967 raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2968 AlignValue = self.__Token\r
2969\r
2970 if not self.__GetCglSection(FfsFileObj, AlignValue):\r
2971 self.SetFileBufferPos(OldPos)\r
2972 return False\r
2973 else:\r
2974 return True\r
2975\r
2976 ## __GetCapsule() method\r
2977 #\r
2978 # Get capsule section contents and store its data into capsule list of self.Profile\r
2979 #\r
2980 # @param self The object pointer\r
2981 # @retval True Successfully find a capsule\r
2982 # @retval False Not able to find a capsule\r
2983 #\r
2984 def __GetCapsule(self):\r
2985\r
2986 if not self.__GetNextToken():\r
2987 return False\r
2988\r
2989 S = self.__Token.upper()\r
2990 if S.startswith("[") and not S.startswith("[CAPSULE."):\r
2991 if not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
2992 raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
2993 self.__UndoToken()\r
2994 return False\r
2995\r
2996 self.__UndoToken()\r
2997 if not self.__IsToken("[CAPSULE.", True):\r
2998 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
2999 #print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \\r
3000 # % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)\r
3001 raise Warning("expected [Capsule.]", self.FileName, self.CurrentLineNumber)\r
3002\r
3003 CapsuleObj = Capsule.Capsule()\r
3004\r
3005 CapsuleName = self.__GetUiName()\r
3006 if not CapsuleName:\r
3007 raise Warning("expected capsule name", self.FileName, self.CurrentLineNumber)\r
3008\r
3009 CapsuleObj.UiCapsuleName = CapsuleName.upper()\r
3010\r
3011 if not self.__IsToken( "]"):\r
3012 raise Warning("expected ']'", self.FileName, self.CurrentLineNumber)\r
3013\r
3014 if self.__IsKeyword("CREATE_FILE"):\r
3015 if not self.__IsToken( "="):\r
3016 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
3017\r
3018 if not self.__GetNextToken():\r
3019 raise Warning("expected file name", self.FileName, self.CurrentLineNumber)\r
3020\r
3021 CapsuleObj.CreateFile = self.__Token\r
3022\r
3023 self.__GetCapsuleStatements(CapsuleObj)\r
fd171542 3024 self.Profile.CapsuleDict[CapsuleObj.UiCapsuleName] = CapsuleObj\r
30fdf114
LG
3025 return True\r
3026\r
3027 ## __GetCapsuleStatements() method\r
3028 #\r
3029 # Get statements for capsule\r
3030 #\r
3031 # @param self The object pointer\r
3032 # @param Obj for whom statements are got\r
3033 #\r
3034 def __GetCapsuleStatements(self, Obj):\r
3035 self.__GetCapsuleTokens(Obj)\r
3036 self.__GetDefineStatements(Obj)\r
3037 self.__GetSetStatements(Obj)\r
30fdf114
LG
3038 self.__GetCapsuleData(Obj)\r
3039\r
fd171542 3040 ## __GetCapsuleTokens() method\r
30fdf114
LG
3041 #\r
3042 # Get token statements for capsule\r
3043 #\r
3044 # @param self The object pointer\r
3045 # @param Obj for whom token statements are got\r
3046 #\r
3047 def __GetCapsuleTokens(self, Obj):\r
b303ea72
LG
3048 if not self.__GetNextToken():\r
3049 return False\r
e8a47801 3050 while self.__Token in ("CAPSULE_GUID", "CAPSULE_HEADER_SIZE", "CAPSULE_FLAGS", "OEM_CAPSULE_FLAGS"):\r
b303ea72
LG
3051 Name = self.__Token.strip()\r
3052 if not self.__IsToken("="):\r
3053 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
3054 if not self.__GetNextToken():\r
3055 raise Warning("expected value", self.FileName, self.CurrentLineNumber)\r
3056 if Name == 'CAPSULE_FLAGS':\r
3057 if not self.__Token in ("PersistAcrossReset", "PopulateSystemTable", "InitiateReset"):\r
3058 raise Warning("expected PersistAcrossReset, PopulateSystemTable, or InitiateReset", self.FileName, self.CurrentLineNumber)\r
3059 Value = self.__Token.strip()\r
3060 while self.__IsToken(","):\r
3061 Value += ','\r
3062 if not self.__GetNextToken():\r
3063 raise Warning("expected value", self.FileName, self.CurrentLineNumber)\r
3064 if not self.__Token in ("PersistAcrossReset", "PopulateSystemTable", "InitiateReset"):\r
3065 raise Warning("expected PersistAcrossReset, PopulateSystemTable, or InitiateReset", self.FileName, self.CurrentLineNumber)\r
3066 Value += self.__Token.strip()\r
e8a47801
LG
3067 elif Name == 'OEM_CAPSULE_FLAGS':\r
3068 Value = self.__Token.strip()\r
3069 try:\r
3070 Value = int(Value, 0)\r
3071 except ValueError:\r
3072 raise Warning("expected integer value between 0x0000 and 0xFFFF", self.FileName, self.CurrentLineNumber)\r
3073 if not 0x0000 <= Value <= 0xFFFF:\r
3074 raise Warning("expected integer value between 0x0000 and 0xFFFF", self.FileName, self.CurrentLineNumber)\r
3075 Value = self.__Token.strip()\r
b303ea72
LG
3076 else:\r
3077 Value = self.__Token.strip()\r
3078 Obj.TokensDict[Name] = Value \r
3079 if not self.__GetNextToken():\r
3080 return False\r
3081 self.__UndoToken()\r
30fdf114
LG
3082\r
3083 ## __GetCapsuleData() method\r
3084 #\r
3085 # Get capsule data for capsule\r
3086 #\r
3087 # @param self The object pointer\r
3088 # @param Obj for whom capsule data are got\r
3089 #\r
3090 def __GetCapsuleData(self, Obj):\r