## @file
# parse FDF file
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
# Import Modules
#
import re
import os
##define T_CHAR_SPACE ' '
##define T_CHAR_NULL '\0'
##define T_CHAR_CR '\r'
##define T_CHAR_TAB '\t'
##define T_CHAR_LF '\n'
##define T_CHAR_SLASH '/'
##define T_CHAR_BACKSLASH '\\'
##define T_CHAR_DOUBLE_QUOTE '\"'
##define T_CHAR_SINGLE_QUOTE '\''
##define T_CHAR_STAR '*'
##define T_CHAR_HASH '#'
(' ', '\0', '\r', '\t', '\n', '/', '\\', '\"', '\'', '*', '#')
IncludeFileList = []
# Macro passed from command line, which has greatest priority and can NOT be overridden by those in FDF
InputMacroDict = {}
# All Macro values when parsing file, not replace existing Macro
AllMacroList = []
InsertedLines = 0
for Profile in IncludeFileList:
if Line >= Profile.InsertStartLineNumber and Line < Profile.InsertStartLineNumber + Profile.InsertAdjust + len(Profile.FileLinesList):
## The exception class that used to report error messages when parsing FDF
#
# Currently the "ToolName" is set to be "FDF Parser".
#
## The constructor
#
# @param self The object pointer
# @param Str The message to record
# @param File The FDF name
# @param Line The Line number that error occurs
#
## The MACRO class that used to record macro value data when parsing include file
#
#
class MacroProfile :
## The constructor
#
# @param self The object pointer
# @param FileName The file that to be parsed
#
self.MacroValue = None
## The Include file content class that used to record file data when parsing include file
#
# May raise Exception when opening file.
#
class IncludeFileProfile :
## The constructor
#
# @param self The object pointer
# @param FileName The file that to be parsed
#
self.FileLinesList = []
try:
try:
finally:
except IOError:
self.InsertStartLineNumber = None
## The FDF content class that used to record file data when parsing FDF
#
# May raise Exception when opening file.
#
class FileProfile :
## The constructor
#
# @param self The object pointer
# @param FileName The file that to be parsed
#
self.FileLinesList = []
try:
try:
finally:
except IOError:
self.PcdFileLineDict = {}
self.InfFileLineList = []
self.CapsuleList = []
# self.VtfList = []
# self.RuleDict = {}
## The syntax parser for FDF
#
# PreprocessFile method should be called prior to ParseFile
# CycleReferenceCheck method can detect cycles in FDF contents
#
# GetNext*** procedures mean these procedures will get next token first, then make judgement.
# Get*** procedures mean these procedures will make judgement on current token only.
#
## The constructor
#
# @param self The object pointer
# @param FileName The file that to be parsed
#
self.CurrentFdName = None
self.CurrentFvName = None
self.__WipeOffArea = []
## __IsWhiteSpace() method
#
# Whether char at current FileBufferPos is whitespace
#
# @param self The object pointer
# @param Char The char to test
# @retval True The char is a kind of white space
# @retval False The char is NOT a kind of white space
#
return True
else:
return False
## __SkipWhiteSpace() method
#
# Skip white spaces from current char, return number of chars skipped
#
# @param self The object pointer
# @retval Count The number of chars skipped
#
Count = 0
while not self.__EndOfFile():
Count += 1
else:
return Count
## __EndOfFile() method
#
# Judge current buffer pos is at file end
#
# @param self The object pointer
# @retval True Current File buffer position is at file end
# @retval False Current File buffer position is NOT at file end
#
return True
return True
else:
return False
## __EndOfLine() method
#
# Judge current buffer pos is at line end
#
# @param self The object pointer
# @retval True Current File buffer position is at line end
# @retval False Current File buffer position is NOT at line end
#
return True
return True
else:
return False
## Rewind() method
#
# Reset file data buffer to the initial state
#
# @param self The object pointer
#
## __UndoOneChar() method
#
# Go back one char in the file buffer
#
# @param self The object pointer
# @retval True Successfully go back one char
# @retval False Not able to go back one char as file beginning reached
#
return False
else:
return True
## __GetOneChar() method
#
# Move forward one char in the file buffer
#
# @param self The object pointer
#
else:
## __CurrentChar() method
#
# Get the char pointed to by the file buffer pointer
#
# @param self The object pointer
# @retval Char Current char
#
## __NextChar() method
#
# Get the one char pass the char pointed to by the file buffer pointer
#
# @param self The object pointer
# @retval Char Next char
#
else:
## __SetCurrentCharValue() method
#
# Modify the value of current char
#
# @param self The object pointer
# @param Value The new value of current char
#
## __CurrentLine() method
#
# Get the list that contains current line contents
#
# @param self The object pointer
# @retval List current line contents
#
MacroEnd = 0
Value = None
if Name in InputMacroDict:
else:
for Profile in AllMacroList:
if Value != None:
else:
return Str
Offset += 1
return
Offset += 1
Offset = 0
Offset += 1
Line += 1
Offset = 0
Offset += 1
if not self.__GetNextToken():
raise Warning("Macro name expected(Please use '$(%(Token)s)' if '%(Token)s' is a macro.)" % {"Token" : MacroName},
## PreprocessFile() method
#
# Preprocess file contents, replace comments with spaces.
# In the end, rewind the file buffer pointer to the beginning
# BUGBUG: No !include statement processing contained in this procedure
# !include statement should be expanded at the same FileLinesList[CurrentLineNumber - 1]
#
# @param self The object pointer
#
# HashComment in quoted string " " is ignored.
while not self.__EndOfFile():
# meet new line, then no longer in a comment for // and '#'
if InComment and DoubleSlashComment:
if InComment and HashComment:
# check for */ comment end
elif InComment and not DoubleSlashComment and not HashComment and self.__CurrentChar() == T_CHAR_STAR and self.__NextChar() == T_CHAR_SLASH:
# set comments to spaces
elif InComment:
# check for // comment
elif self.__CurrentChar() == T_CHAR_SLASH and self.__NextChar() == T_CHAR_SLASH and not self.__EndOfLine():
# check for '#' comment
# check for /* comment start
else:
# restore from ListOfList to ListOfString
## PreprocessIncludeFile() method
#
# Preprocess file contents, replace !include statements with file contents.
# In the end, rewind the file buffer pointer to the beginning
#
# @param self The object pointer
#
while self.__GetNextToken():
if not self.__GetNextToken():
else:
# file is in the same dir with FDF file
# list index of the insertion, note that line number is 'CurrentLine + 1'
# deal with remaining portions after "!include filename", if exists.
if self.__GetNextToken():
InsertAtLine += 1
# comment out the processed include file statement
## PreprocessIncludeFile() method
#
# Preprocess file contents, replace !include statements with file contents.
# In the end, rewind the file buffer pointer to the beginning
#
# @param self The object pointer
#
# IfList is a stack of if branches with elements of list [Pos, CondSatisfied, BranchDetermined]
IfList = []
while self.__GetNextToken():
if not self.__GetNextToken():
if not self.__GetNextToken():
if self.__GetStringData():
pass
if not Macro in InputMacroDict:
self.__WipeOffArea.append(((DefineLine, DefineOffset), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))
if CondLabel == '!ifndef':
if NotFlag:
raise Warning("'NOT' operation not allowed for Macro name At Line ", self.FileName, self.CurrentLineNumber)
if CondLabel == '!if':
if not self.__GetNextOp():
if not self.__GetNextToken():
if self.__GetStringData():
pass
if NotFlag:
else:
if NotFlag:
self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))
else:
if NotDefineFlag:
self.__WipeOffArea.append((IfStartPos, (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))
self.__WipeOffArea.append((ElseStartPos, (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))
else:
if not self.__GetNextOp():
if not self.__GetNextToken():
if self.__GetStringData():
pass
if NotFlag:
else:
if NotFlag:
else:
self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))
self.__WipeOffArea.append(((self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len('!endif')), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))
else:
self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))
if Name in InputMacroDict:
if Op == None:
return False
return True
elif Op == '!=':
if Value != MacroValue:
return True
else:
return False
elif Op == '==':
if Value == MacroValue:
return True
else:
return False
else:
if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(MacroValue) or (MacroValue != None and MacroValue.isdigit())):
if Op == '>':
return True
else:
return False
elif Op == '>=':
return True
else:
return False
elif Op == '<':
return True
else:
return False
elif Op == '<=':
return True
else:
return False
else:
return False
else:
for Profile in AllMacroList:
if Profile.FileName == FileLineTuple[0] and Profile.MacroName == Name and Profile.DefinedAtLine <= FileLineTuple[1]:
if Op == None:
return False
return True
elif Op == '!=':
return True
else:
return False
elif Op == '==':
return True
else:
return False
else:
if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(Profile.MacroValue) or (Profile.MacroValue != None and Profile.MacroValue.isdigit())):
if Op == '>':
return True
else:
return False
elif Op == '>=':
return True
else:
return False
elif Op == '<':
return True
else:
return False
elif Op == '<=':
return True
else:
return False
else:
return False
else:
return False
## __IsToken() method
#
# Check whether input string is found from current char position along
# If found, the string value is put into self.__Token
#
# @param self The object pointer
# @param String The string to search
# @param IgnoreCase Indicate case sensitive/non-sensitive search, default is case sensitive
# @retval True Successfully find string, file buffer pointer moved forward
# @retval False Not able to find string, file buffer pointer not changed
#
# Only consider the same line, no multi-line token allowed
index = -1
if IgnoreCase:
else:
if index == 0:
return True
return False
## __IsKeyword() method
#
# Check whether input keyword is found from current char position along, whole word only!
# If found, the string value is put into self.__Token
#
# @param self The object pointer
# @param Keyword The string to search
# @param IgnoreCase Indicate case sensitive/non-sensitive search, default is case sensitive
# @retval True Successfully find string, file buffer pointer moved forward
# @retval False Not able to find string, file buffer pointer not changed
#
# Only consider the same line, no multi-line token allowed
index = -1
if IgnoreCase:
else:
if index == 0:
return False
return True
return False
## __GetNextWord() method
#
# Get next C name from file lines
# If found, the string value is put into self.__Token
#
# @param self The object pointer
# @retval True Successfully find a C name string, file buffer pointer moved forward
# @retval False Not able to find a C name string, file buffer pointer not changed
#
if self.__EndOfFile():
return False
if (TempChar >= 'a' and TempChar <= 'z') or (TempChar >= 'A' and TempChar <= 'Z') or TempChar == '_':
while not self.__EndOfLine():
else:
break
return True
return False
## __GetNextToken() method
#
# Get next token unit before a seperator
# If found, the string value is put into self.__Token
#
# @param self The object pointer
# @retval True Successfully find a token unit, file buffer pointer moved forward
# @retval False Not able to find a token unit, file buffer pointer not changed
#
# Skip leading spaces, if exist.
if self.__EndOfFile():
return False
# Record the token start position, the position of the first non-space char.
while not self.__EndOfLine():
# Try to find the end char that is not a space and not in seperator tuple.
# That is, when we got a space or any char in the tuple, we got the end of token.
# if we happen to meet a seperator as the first char, we must proceed to get it.
# That is, we get a token that is a seperator char. nomally it is the boundary of other tokens.
break
else:
break
# else:
# return False
return True
else:
return False
# Skip leading spaces, if exist.
if self.__EndOfFile():
return False
# Record the token start position, the position of the first non-space char.
while not self.__EndOfLine():
# Try to find the end char that is not a space
else:
break
else:
return False
return True
else:
return False
## __GetNextGuid() method
#
# Get next token unit before a seperator
# If found, the GUID string is put into self.__Token
#
# @param self The object pointer
# @retval True Successfully find a registry format GUID, file buffer pointer moved forward
# @retval False Not able to find a registry format GUID, file buffer pointer not changed
#
if not self.__GetNextToken():
return False
return True
else:
return False
## __UndoToken() method
#
# Go back one token unit in file buffer
#
# @param self The object pointer
#
if not self.__UndoOneChar():
return
# Try to find the end char that is not a space and not in seperator tuple.
# That is, when we got a space or any char in the tuple, we got the end of token.
if not self.__UndoOneChar():
break
# if we happen to meet a seperator as the first char, we must proceed to get it.
# That is, we get a token that is a seperator char. nomally it is the boundary of other tokens.
return
else:
break
## __HexDigit() method
#
# Whether char input is a Hex data bit
#
# @param self The object pointer
# @param TempChar The char to test
# @retval True The char is a Hex data bit
# @retval False The char is NOT a Hex data bit
#
return True
else:
return False
return False
return False
return True
else:
return False
## __GetNextHexNumber() method
#
# Get next HEX data before a seperator
# If found, the HEX data is put into self.__Token
#
# @param self The object pointer
# @retval True Successfully find a HEX data, file buffer pointer moved forward
# @retval False Not able to find a HEX data, file buffer pointer not changed
#
if not self.__GetNextToken():
return False
return True
else:
return False
## __GetNextDecimalNumber() method
#
# Get next decimal data before a seperator
# If found, the decimal data is put into self.__Token
#
# @param self The object pointer
# @retval True Successfully find a decimal data, file buffer pointer moved forward
# @retval False Not able to find a decimal data, file buffer pointer not changed
#
if not self.__GetNextToken():
return False
return True
else:
return False
## __GetNextPcdName() method
#
# Get next PCD token space C name and PCD C name pair before a seperator
# If found, the decimal data is put into self.__Token
#
# @param self The object pointer
# @retval Tuple PCD C name and PCD token space C name pair
#
if not self.__GetNextWord():
raise Warning("expected PcdTokenSpaceCName.PcdCName At Line ", self.FileName, self.CurrentLineNumber)
raise Warning("expected PcdTokenSpaceCName.PcdCName At Line ", self.FileName, self.CurrentLineNumber)
if not self.__GetNextWord():
raise Warning("expected PcdTokenSpaceCName.PcdCName At Line ", self.FileName, self.CurrentLineNumber)
return (pcdCName, pcdTokenSpaceCName)
## __GetStringData() method
#
# Get string contents quoted in ""
# If found, the decimal data is put into self.__Token
#
# @param self The object pointer
# @retval True Successfully find a string data, file buffer pointer moved forward
# @retval False Not able to find a string data, file buffer pointer not changed
#
return True
return True
else:
return False
## __SkipToToken() method
#
# Search forward in file buffer for the string
# The skipped chars are put into self.__SkippedChars
#
# @param self The object pointer
# @param String The string to search
# @param IgnoreCase Indicate case sensitive/non-sensitive search, default is case sensitive
# @retval True Successfully find the string, file buffer pointer moved forward
# @retval False Not able to find the string, file buffer pointer not changed
#
while not self.__EndOfFile():
index = -1
if IgnoreCase:
else:
if index == 0:
return True
return False
## GetFileBufferPos() method
#
# Return the tuple of current line and offset within the line
#
# @param self The object pointer
# @retval Tuple Line number and offset pair
#
## SetFileBufferPos() method
#
# Restore the file buffer position
#
# @param self The object pointer
# @param Pos The new file buffer position
#
## ParseFile() method
#
# Parse the file profile buffer to extract fd, fv ... information
# Exception will be raised if syntax error found
#
# @param self The object pointer
#
try:
while self.__GetDefines():
pass
Index = 0
self.Profile.FileLinesList[Index] = self.__ReplaceMacros(self.Profile.FileLinesList[Index], FileLineTuple[0], FileLineTuple[1])
Index += 1
pass
pass
while self.__GetCapsule():
pass
# while self.__GetVtf():
# pass
#
# while self.__GetRule():
# pass
except Warning, X:
'Previous Token: \"%s\" At line: %d, Offset Within Line: %d\n' \
% (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :].rstrip('\n').rstrip('\r'), FileLineTuple[1], self.CurrentOffsetWithinLine)
raise
## __GetDefines() method
#
# Get Defines section contents and store its data into AllMacrosList
#
# @param self The object pointer
# @retval True Successfully find a Defines
# @retval False Not able to find a Defines
#
if not self.__GetNextToken():
return False
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)
return False
#print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
# % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
while self.__GetNextWord():
return False
## __GetFd() method
#
# Get FD section contents and store its data into FD dictionary of self.Profile
#
# @param self The object pointer
# @retval True Successfully find a FD
# @retval False Not able to find a FD
#
if not self.__GetNextToken():
return False
return False
print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
% (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
if not Status:
return False
pass
return True
## __GetUiName() method
#
# Return the UI name of a section
#
# @param self The object pointer
# @retval FdName UI name
#
FdName = ""
if self.__GetNextWord():
return FdName
## __GetCreateFile() method
#
# Return the output file name of object
#
# @param self The object pointer
# @param Obj object whose data will be stored in file
# @retval FdName UI name
#
if not self.__GetNextToken():
return True
## __GetTokenStatements() method
#
# Get token statements
#
# @param self The object pointer
# @param Obj for whom token statement is got
# @retval True Successfully find a token statement
# @retval False Not able to find a token statement
#
if not self.__GetNextHexNumber():
if not self.__GetNextHexNumber():
if not self.__GetNextToken():
return Status
## __GetAddressStatements() method
#
# Get address statements
#
# @param self The object pointer
# @param Obj for whom address statement is got
# @retval True Successfully find
# @retval False Not able to find
#
## __GetBlockStatements() method
#
# Get block statements
#
# @param self The object pointer
# @param Obj for whom block statement is got
# @retval True Successfully find
# @retval False Not able to find
#
#set default block size is 1
return True
pass
return True
## __GetBlockStatement() method
#
# Get block statement
#
# @param self The object pointer
# @param Obj for whom block statement is got
# @retval True Successfully find
# @retval False Not able to find
#
return False
BlockSizePcd = None
BlockNumber = None
return True
## __GetDefineStatements() method
#
# Get define statements
#
# @param self The object pointer
# @param Obj for whom define statement is got
# @retval True Successfully find
# @retval False Not able to find
#
pass
## __GetDefineStatement() method
#
# Get define statement
#
# @param self The object pointer
# @param Obj for whom define statement is got
# @retval True Successfully find
# @retval False Not able to find
#
if not self.__GetNextToken():
return True
return False
## __GetSetStatements() method
#
# Get set statements
#
# @param self The object pointer
# @param Obj for whom set statement is got
# @retval True Successfully find
# @retval False Not able to find
#
pass
## __GetSetStatement() method
#
# Get set statement
#
# @param self The object pointer
# @param Obj for whom set statement is got
# @retval True Successfully find
# @retval False Not able to find
#
if not self.__GetNextToken():
# deal with value with {}
return True
return False
## __GetRegionLayout() method
#
# Get region layout for FD
#
# @param self The object pointer
# @param Fd for whom region is got
# @retval True Successfully find
# @retval False Not able to find
#
if not self.__GetNextHexNumber():
return False
if not self.__GetNextHexNumber():
if not self.__GetNextWord():
return True
if not self.__GetNextWord():
return True
if not self.__GetNextWord():
return True
else:
return True
## __GetRegionFvType() method
#
# Get region fv data for region
#
# @param self The object pointer
# @param RegionObj for whom region data is got
#
if not self.__GetNextToken():
if not self.__GetNextToken():
## __GetRegionCapType() method
#
# Get region capsule data for region
#
# @param self The object pointer
# @param RegionObj for whom region data is got
#
if not self.__GetNextToken():
if not self.__GetNextToken():
## __GetRegionFileType() method
#
# Get region file data for region
#
# @param self The object pointer
# @param RegionObj for whom region data is got
#
if not self.__GetNextToken():
if not self.__GetNextToken():
## __GetRegionDataType() method
#
# Get region array data for region
#
# @param self The object pointer
# @param RegionObj for whom region data is got
#
if not self.__GetNextHexNumber():
raise Warning("Hex string can't be converted to a valid UINT64 value", self.FileName, self.CurrentLineNumber)
DataString += ","
if not self.__GetNextHexNumber():
raise Warning("Hex byte(must be 2 digits) too long At Line ", self.FileName, self.CurrentLineNumber)
DataString += ","
if not self.__GetNextHexNumber():
raise Warning("Hex string can't be converted to a valid UINT64 value", self.FileName, self.CurrentLineNumber)
DataString += ","
raise Warning("Hex byte(must be 2 digits) too long At Line ", self.FileName, self.CurrentLineNumber)
DataString += ","
## __GetFv() method
#
# Get FV section contents and store its data into FV dictionary of self.Profile
#
# @param self The object pointer
# @retval True Successfully find a FV
# @retval False Not able to find a FV
#
if not self.__GetNextToken():
return False
if not S.startswith("[CAPSULE.") \
raise Warning("Unknown section or section appear sequence error \n(The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.]) At Line ", self.FileName, self.CurrentLineNumber)
return False
print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
% (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
if not Status:
while True:
break
return True
## __GetFvAlignment() method
#
# Get alignment for FV
#
# @param self The object pointer
# @param Obj for whom alignment is got
# @retval True Successfully find a alignment statement
# @retval False Not able to find a alignment statement
#
return False
if not self.__GetNextToken():
"1K", "2K", "4K", "8K", "16K", "32K", "64K", "128K", "256K", "512K", \
"1M", "2M", "4M", "8M", "16M", "32M", "64M", "128M", "256M", "512M", \
"1G", "2G"):
return True
## __GetFvAttributes() method
#
# Get attributes for FV
#
# @param self The object pointer
# @param Obj for whom attribute is got
# @retval None
#
while self.__GetNextWord():
"STICKY_WRITE", "LOCK_CAP", "LOCK_STATUS", "WRITE_ENABLED_CAP", \
"WRITE_DISABLED_CAP", "WRITE_STATUS", "READ_ENABLED_CAP", \
"READ_DISABLED_CAP", "READ_STATUS", "READ_LOCK_CAP", \
"READ_LOCK_STATUS", "WRITE_LOCK_CAP", "WRITE_LOCK_STATUS", \
"WRITE_POLICY_RELIABLE"):
return
return
## __GetFvNameGuid() method
#
# Get FV GUID for FV
#
# @param self The object pointer
# @param Obj for whom GUID is got
# @retval None
#
return
if not self.__GetNextGuid():
return
## __GetAprioriSection() method
#
# Get token statements
#
# @param self The object pointer
# @param FvObj for whom apriori is got
# @param MacroDict dictionary used to replace macro
# @retval True Successfully find apriori statement
# @retval False Not able to find apriori statement
#
return False
while True:
break
return True
## __GetInfStatement() method
#
# Get INF statements
#
# @param self The object pointer
# @param Obj for whom inf statement is got
# @param MacroDict dictionary used to replace macro
# @retval True Successfully find inf statement
# @retval False Not able to find inf statement
#
return False
if not self.__GetNextToken():
# if ffsInf.InfFileName.find('$') >= 0:
# ffsInf.InfFileName = GenFdsGlobalVariable.GenFdsGlobalVariable.MacroExtend(ffsInf.InfFileName, MacroDict)
else:
if ForCapsule:
else:
return True
## __GetInfOptions() method
#
# Get options for INF
#
# @param self The object pointer
# @param FfsInfObj for whom option is got
#
if not self.__GetNextToken():
if not self.__GetNextToken():
if self.__GetStringData():
if not self.__GetNextToken():
if self.__GetStringData():
if not self.__GetNextToken():
if self.__GetNextToken():
p = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')
return
else:
return
while self.__GetNextToken():
raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber)
break
## __GetFileStatement() method
#
# Get FILE statements
#
# @param self The object pointer
# @param Obj for whom FILE statement is got
# @param MacroDict dictionary used to replace macro
# @retval True Successfully find FILE statement
# @retval False Not able to find FILE statement
#
return False
if not self.__GetNextWord():
if not self.__GetNextGuid():
if not self.__GetNextWord():
if ForCapsule:
else:
return True
## __FileCouldHaveRelocFlag() method
#
# Check whether reloc strip flag can be set for a file type.
#
# @param self The object pointer
# @param FileType The file type to check with
# @retval True This type could have relocation strip flag
# @retval False No way to have it
#
return True
else:
return False
## __SectionCouldHaveRelocFlag() method
#
# Check whether reloc strip flag can be set for a section type.
#
# @param self The object pointer
# @param SectionType The section type to check with
# @retval True This type could have relocation strip flag
# @retval False No way to have it
#
return True
else:
return False
## __GetFilePart() method
#
# Get components for FILE statement
#
# @param self The object pointer
# @param FfsFileObj for whom component is got
# @param MacroDict dictionary used to replace macro
#
# if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'):
# if self.__FileCouldHaveRelocFlag(FfsFileObj.FvFileType):
# if self.__Token == 'RELOCS_STRIPPED':
# FfsFileObj.KeepReloc = False
# else:
# FfsFileObj.KeepReloc = True
# else:
# raise Warning("File type %s could not have reloc strip flag At Line %d" % (FfsFileObj.FvFileType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)
#
# if not self.__IsToken("{"):
if not self.__GetNextToken():
if not self.__GetNextToken():
if not self.__GetNextToken():
else:
## __GetFileOpts() method
#
# Get options for FILE statement
#
# @param self The object pointer
# @param FfsFileObj for whom options is got
#
if self.__GetNextToken():
Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')
while self.__GetNextToken():
raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber)
break
else:
if self.__GetAlignment():
## __GetAlignment() method
#
# Return the alignment value
#
# @param self The object pointer
# @retval True Successfully find alignment
# @retval False Not able to find alignment
#
if not self.__GetNextToken():
return True
return False
## __GetFilePart() method
#
# Get section data for FILE statement
#
# @param self The object pointer
# @param FfsFileObj for whom section is got
# @param MacroDict dictionary used to replace macro
#
Dict = {}
while True:
if not IsLeafSection and not IsEncapSection:
break
## __GetLeafSection() method
#
# Get leaf section for Obj
#
# @param self The object pointer
# @param Obj for whom leaf section is got
# @param MacroDict dictionary used to replace macro
# @retval True Successfully find section statement
# @retval False Not able to find section statement
#
else:
return False
AlignValue = None
if self.__GetAlignment():
BuildNum = None
if not self.__GetNextToken():
if AlignValue == 'Auto':
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
if self.__GetStringData():
else:
if AlignValue == 'Auto':
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
if self.__GetStringData():
else:
if AlignValue == 'Auto':
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
if not self.__GetNextWord():
FvObj = None
while True:
break
if FvObj != None:
FvImageSectionObj.FvName = None
else:
elif self.__IsKeyword("PEI_DEPEX_EXP") or self.__IsKeyword("DXE_DEPEX_EXP") or self.__IsKeyword("SMM_DEPEX_EXP"):
if AlignValue == 'Auto':
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
raise Warning("expected Depex expression ending '}' At Line ", self.FileName, self.CurrentLineNumber)
else:
if not self.__GetNextWord():
# Encapsulation section appear, UndoToken and return
return False
"UI", "VERSION", "PEI_DEPEX", "SUBTYPE_GUID", "SMM_DEPEX"):
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
# DataSection
if self.__FileCouldHaveRelocFlag(Obj.FvFileType) and self.__SectionCouldHaveRelocFlag(DataSectionObj.SecType):
else:
else:
raise Warning("File type %s, section type %s, could not have reloc strip flag At Line %d" % (Obj.FvFileType, DataSectionObj.SecType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
else:
return False
return True
## __GetCglSection() method
#
# Get compressed or GUIDed section for Obj
#
# @param self The object pointer
# @param Obj for whom leaf section is got
# @param AlignValue alignment value for complex section
# @retval True Successfully find section statement
# @retval False Not able to find section statement
#
type = "PI_STD"
# Recursive sections...
while True:
if not IsLeafSection and not IsEncapSection:
break
# else:
# raise Warning("Compress type not known At Line ")
return True
GuidValue = None
if self.__GetNextGuid():
# Recursive sections...
while True:
if not IsLeafSection and not IsEncapSection:
break
return True
return False
## __GetGuidAttri() method
#
# Get attributes for GUID section
#
# @param self The object pointer
# @retval AttribDict Dictionary of key-value pair of section attributes
#
AttribDict = {}
raise Warning("expected '=' At Line ")
return AttribDict
## __GetEncapsulationSec() method
#
# Get encapsulation section for FILE
#
# @param self The object pointer
# @param FfsFile for whom section is got
# @retval True Successfully find section statement
# @retval False Not able to find section statement
#
else:
return False
AlignValue = None
if self.__GetAlignment():
return False
else:
return True
## __GetCapsule() method
#
# Get capsule section contents and store its data into capsule list of self.Profile
#
# @param self The object pointer
# @retval True Successfully find a capsule
# @retval False Not able to find a capsule
#
if not self.__GetNextToken():
return False
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
return False
print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
% (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
if not CapsuleName:
if not self.__GetNextToken():
return True
## __GetCapsuleStatements() method
#
# Get statements for capsule
#
# @param self The object pointer
# @param Obj for whom statements are got
#
## __GetCapsuleStatements() method
#
# Get token statements for capsule
#
# @param self The object pointer
# @param Obj for whom token statements are got
#
## __GetCapsuleData() method
#
# Get capsule data for capsule
#
# @param self The object pointer
# @param Obj for whom capsule data are got
#
while True:
break
## __GetFvStatement() method
#
# Get FV for capsule
#
# @param self The object pointer
# @param CapsuleObj for whom FV is got
# @retval True Successfully find a FV statement
# @retval False Not able to find a FV statement
#
return False
if not self.__GetNextToken():
# CapsuleFv = CapsuleData.CapsuleFv()
# CapsuleFv.FvName = self.__Token
# CapsuleObj.CapsuleDataList.append(CapsuleFv)
return True
## __GetRule() method
#
# Get Rule section contents and store its data into rule list of self.Profile
#
# @param self The object pointer
# @retval True Successfully find a Rule
# @retval False Not able to find a Rule
#
if not self.__GetNextToken():
return False
if not S.startswith("[OPTIONROM."):
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
return False
print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
% (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
TemplateName = ""
if not self.__GetNextWord():
if TemplateName == '' :
'.' + \
'.' + \
else :
'.' + \
'.' + \
ModuleType.upper() + \
'.' + \
# self.Profile.RuleList.append(rule)
return True
## __GetModuleType() method
#
# Return the module type
#
# @param self The object pointer
# @retval string module type
#
if not self.__GetNextWord():
"DXE_DRIVER", "DXE_SAL_DRIVER", \
"DXE_SMM_DRIVER", "DXE_RUNTIME_DRIVER", \
"UEFI_DRIVER", "UEFI_APPLICATION", "USER_DEFINED", "DEFAULT", "BASE", \
"SECURITY_CORE", "COMBINED_PEIM_DRIVER", "PIC_PEIM", "RELOCATABLE_PEIM", \
"PE32_PEIM", "BS_DRIVER", "RT_DRIVER", "SAL_RT_DRIVER", "APPLICATION", "ACPITABLE", "SMM_CORE"):
## __GetFileExtension() method
#
# Return the file extension
#
# @param self The object pointer
# @retval string file name extension
#
Ext = ""
if self.__GetNextToken():
return '.' + Ext
else:
else:
## __GetRuleFileStatement() method
#
# Get rule contents
#
# @param self The object pointer
# @retval Rule Rule object
#
if not self.__GetNextWord():
"PEI_DXE_COMBO", "DRIVER", "DXE_CORE", "APPLICATION", "FV_IMAGE", "SMM", "SMM_CORE"):
if not self.__GetNextWord():
KeepReloc = None
else:
else:
raise Warning("File type %s could not have reloc strip flag At Line %d" % (Type, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)
KeyStringList = []
if self.__GetNextToken():
Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')
while self.__GetNextToken():
raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber)
break
else:
AlignValue = ""
if self.__GetAlignment():
# Complex file rule expected
if KeepReloc != None:
while True:
if not IsEncapsulate and not IsLeaf:
break
return Rule
# Ext rule expected
if KeepReloc != None:
return Rule
else:
# Simple file rule expected
if not self.__GetNextWord():
"UI", "PEI_DEPEX", "VERSION", "SUBTYPE_GUID", "SMM_DEPEX"):
raise Warning("Unknown leaf section name '%s'" % SectionName, self.FileName, self.CurrentLineNumber)
if self.__GetAlignment():
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
if KeepReloc != None:
return Rule
## __GetEfiSection() method
#
# Get section list for Rule
#
# @param self The object pointer
# @param Obj for whom section is got
# @retval True Successfully find section statement
# @retval False Not able to find section statement
#
if not self.__GetNextWord():
return False
"UI", "VERSION", "PEI_DEPEX", "GUID", "SMM_DEPEX"):
return False
if SectionName == "FV_IMAGE":
pass
while True:
break
FvImageSectionObj.FvName = None
else:
if self.__GetAlignment():
elif self.__GetNextToken():
"UI", "VERSION", "PEI_DEPEX", "GUID", "SMM_DEPEX"):
else:
else:
return True
if not self.__GetNextToken():
raise Warning("%s section could NOT have string data At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
if self.__GetStringData():
raise Warning("%s section could NOT have BUILD_NUM At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
else:
raise Warning("%s section could NOT be optional At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)
raise Warning("%s section could NOT have BUILD_NUM At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
if self.__GetAlignment():
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
else:
raise Warning("Section type %s has reloc strip flag conflict with Rule At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)
else:
raise Warning("Section type %s could not have reloc strip flag At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)
elif self.__GetNextToken():
"UI", "VERSION", "PEI_DEPEX", "GUID", "SMM_DEPEX"):
else:
else:
return True
## __RuleSectionCouldBeOptional() method
#
# Get whether a section could be optional
#
# @param self The object pointer
# @param SectionType The section type to check
# @retval True section could be optional
# @retval False section never optional
#
return True
else:
return False
## __RuleSectionCouldHaveBuildNum() method
#
# Get whether a section could have build number information
#
# @param self The object pointer
# @param SectionType The section type to check
# @retval True section could have build number information
# @retval False section never have build number information
#
if SectionType in ("VERSION"):
return True
else:
return False
## __RuleSectionCouldHaveString() method
#
# Get whether a section could have string
#
# @param self The object pointer
# @param SectionType The section type to check
# @retval True section could have string
# @retval False section never have string
#
return True
else:
return False
## __CheckRuleSectionFileType() method
#
# Get whether a section matches a file type
#
# @param self The object pointer
# @param SectionType The section type to check
# @param FileType The file type to check
#
if SectionType == "COMPAT16":
elif SectionType == "PE32":
elif SectionType == "PIC":
elif SectionType == "TE":
elif SectionType == "RAW":
elif SectionType == "UI":
elif SectionType == "VERSION":
elif SectionType == "PEI_DEPEX":
elif SectionType == "GUID":
## __GetRuleEncapsulationSection() method
#
# Get encapsulation section for Rule
#
# @param self The object pointer
# @param Rule for whom section is got
# @retval True Successfully find section statement
# @retval False Not able to find section statement
#
Type = "PI_STD"
# Recursive sections...
while True:
if not IsEncapsulate and not IsLeaf:
break
return True
GuidValue = None
if self.__GetNextGuid():
# Efi sections...
while True:
if not IsEncapsulate and not IsLeaf:
break
return True
return False
## __GetVtf() method
#
# Get VTF section contents and store its data into VTF list of self.Profile
#
# @param self The object pointer
# @retval True Successfully find a VTF
# @retval False Not able to find a VTF
#
if not self.__GetNextToken():
return False
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
return False
print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
% (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
if not self.__GetNextWord():
if not self.__GetNextWord():
if not self.__GetNextToken():
pass
return True
## __GetComponentStatement() method
#
# Get components in VTF
#
# @param self The object pointer
# @param VtfObj for whom component is got
# @retval True Successfully find a component
# @retval False Not able to find a component
#
return False
if not self.__GetNextWord():
if self.__GetNextWord():
if not self.__GetNextWord():
else:
if not self.__GetNextToken():
if not self.__GetNextToken():
if not self.__GetNextToken():
if not self.__GetNextToken():
if not self.__GetNextToken():
elif self.__GetNextDecimalNumber():
elif self.__GetNextHexNumber():
else:
return True
## __GetFvInFd() method
#
# Get FV list contained in FD
#
# @param self The object pointer
# @param FdName FD name
# @retval FvList list of FV in FD
#
FvList = []
return FvList
## __GetReferencedFdFvTuple() method
#
# Get FD and FV list referenced by a FFS file
#
# @param self The object pointer
# @param FfsFile contains sections to be searched
# @param RefFdList referenced FD by section
# @param RefFvList referenced FV by section
#
else:
## __GetReferencedFdFvTupleFromSection() method
#
# Get FD and FV list referenced by a FFS section
#
# @param self The object pointer
# @param FfsFile contains sections to be searched
# @param FdList referenced FD by section
# @param FvList referenced FV by section
#
SectionStack = []
while SectionStack != []:
if SectionObj.Fv != None and SectionObj.Fv.UiFvName != None and SectionObj.Fv.UiFvName.upper() not in FvList:
if isinstance(SectionObj, CompressSection.CompressSection) or isinstance(SectionObj, GuidSection.GuidSection):
## CycleReferenceCheck() method
#
# Check whether cycle reference exists in FDF
#
# @param self The object pointer
# @retval True cycle reference exists
# @retval False Not exists cycle reference
#
try:
RefFvStack = []
FdAnalyzedList = []
while RefFvStack != []:
else:
continue
RefFdList = []
RefFvList = []
if RefFdName in FdAnalyzedList:
continue
if FvInFdList != []:
for FvObj in FvInFdList:
LogStr += ' \n'
if FvObj not in RefFvStack:
if FvName in RefFvStack:
if RefFvName not in RefFvStack:
if FvName in RefFvStack:
except Warning:
print LogStr
finally:
return CycleRefExists
if __name__ == "__main__":
import sys
try:
except IndexError, v:
try:
except Warning, X:
print X.message
else:
print "Success!"