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