2009-07-17 11:10:31 +02:00
## @file
# parse FDF file
#
2021-04-14 05:11:48 +02:00
# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR>
2015-08-26 08:28:59 +02:00
# Copyright (c) 2015, Hewlett Packard Enterprise Development, L.P.<BR>
2009-07-17 11:10:31 +02:00
#
2019-04-04 01:03:11 +02:00
# SPDX-License-Identifier: BSD-2-Clause-Patent
2009-07-17 11:10:31 +02:00
#
##
# Import Modules
#
2018-10-15 02:27:53 +02:00
from __future__ import print_function
from __future__ import absolute_import
2018-10-23 19:29:19 +02:00
from re import compile , DOTALL
from string import hexdigits
from uuid import UUID
2009-07-17 11:10:31 +02:00
from Common . BuildToolError import *
from Common import EdkLogger
2020-07-14 07:30:40 +02:00
from Common . Misc import PathClass , tdict , ProcessDuplicatedInf , GuidStructureStringToGuidString
2018-10-23 19:29:19 +02:00
from Common . StringUtils import NormPath , ReplaceMacro
2011-09-19 11:03:59 +02:00
from Common import GlobalData
2018-10-23 19:29:19 +02:00
from Common . Expression import *
2018-04-16 15:52:13 +02:00
from Common . DataType import *
2016-11-14 10:41:11 +01:00
from Common . MultipleWorkspace import MultipleWorkspace as mws
2014-08-15 05:06:48 +02:00
import Common . LongFilePathOs as os
from Common . LongFilePathSupport import OpenLongFilePath as open
2018-03-15 22:39:07 +01:00
from Common . RangeExpression import RangeExpression
2018-09-25 07:20:46 +02:00
from collections import OrderedDict
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
from . Fd import FD
from . Region import Region
from . Fv import FV
from . AprioriSection import AprioriSection
from . FfsInfStatement import FfsInfStatement
from . FfsFileStatement import FileStatement
from . VerSection import VerSection
from . UiSection import UiSection
from . FvImageSection import FvImageSection
from . DataSection import DataSection
from . DepexSection import DepexSection
from . CompressSection import CompressSection
from . GuidSection import GuidSection
from . Capsule import EFI_CERT_TYPE_PKCS7_GUID , EFI_CERT_TYPE_RSA2048_SHA256_GUID , Capsule
from . CapsuleData import CapsuleFfs , CapsulePayload , CapsuleFv , CapsuleFd , CapsuleAnyFile , CapsuleAfile
from . RuleComplexFile import RuleComplexFile
from . RuleSimpleFile import RuleSimpleFile
from . EfiSection import EfiSection
from . OptionRom import OPTIONROM
from . OptRomInfStatement import OptRomInfStatement , OverrideAttribs
from . OptRomFileStatement import OptRomFileStatement
from . GenFdsGlobalVariable import GenFdsGlobalVariable
T_CHAR_CR = ' \r '
T_CHAR_TAB = ' \t '
T_CHAR_DOUBLE_QUOTE = ' \" '
T_CHAR_SINGLE_QUOTE = ' \' '
2018-10-23 19:29:24 +02:00
T_CHAR_BRACE_R = ' } '
2018-10-23 19:29:19 +02:00
2018-10-23 19:29:24 +02:00
SEPARATORS = { TAB_EQUAL_SPLIT , TAB_VALUE_SPLIT , TAB_COMMA_SPLIT , ' { ' , T_CHAR_BRACE_R }
2018-10-23 19:29:19 +02:00
ALIGNMENTS = { " Auto " , " 8 " , " 16 " , " 32 " , " 64 " , " 128 " , " 512 " , " 1K " , " 4K " , " 32K " , " 64K " , " 128K " ,
" 256K " , " 512K " , " 1M " , " 2M " , " 4M " , " 8M " , " 16M " }
ALIGNMENT_NOAUTO = ALIGNMENTS - { " Auto " }
2018-10-23 19:29:20 +02:00
CR_LB_SET = { T_CHAR_CR , TAB_LINE_BREAK }
2018-10-23 19:29:19 +02:00
RegionSizePattern = compile ( " \ s*(?P<base>(?:0x|0X)?[a-fA-F0-9]+) \ s* \ | \ s*(?P<size>(?:0x|0X)?[a-fA-F0-9]+) \ s* " )
RegionSizeGuidPattern = compile ( " \ s*(?P<base> \ w+ \ . \ w+[ \ . \ w \ [ \ ]]*) \ s* \ | \ s*(?P<size> \ w+ \ . \ w+[ \ . \ w \ [ \ ]]*) \ s* " )
RegionOffsetPcdPattern = compile ( " \ s*(?P<base> \ w+ \ . \ w+[ \ . \ w \ [ \ ]]*) \ s*$ " )
ShortcutPcdPattern = compile ( " \ s* \ w+ \ s*= \ s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+) \ s* \ | \ s*(?P<name> \ w+ \ . \ w+) \ s* " )
BaseAddrValuePattern = compile ( ' ^0[xX][0-9a-fA-F]+ ' )
FileExtensionPattern = compile ( r ' ([a-zA-Z][a-zA-Z0-9]*) ' )
TokenFindPattern = compile ( r ' ([a-zA-Z0-9 \ -]+| \ $ \ (TARGET \ )| \ *)_([a-zA-Z0-9 \ -]+| \ $ \ (TOOL_CHAIN_TAG \ )| \ *)_([a-zA-Z0-9 \ -]+| \ $ \ (ARCH \ )| \ *) ' )
2015-08-26 08:28:59 +02:00
AllIncludeFileList = [ ]
# Get the closest parent
def GetParentAtLine ( Line ) :
for Profile in AllIncludeFileList :
if Profile . IsLineInFile ( Line ) :
return Profile
return None
# Check include loop
def IsValidInclude ( File , Line ) :
for Profile in AllIncludeFileList :
if Profile . IsLineInFile ( Line ) and Profile . FileName == File :
return False
return True
2009-07-17 11:10:31 +02:00
def GetRealFileLine ( File , Line ) :
InsertedLines = 0
2015-08-26 08:28:59 +02:00
for Profile in AllIncludeFileList :
if Profile . IsLineInFile ( Line ) :
return Profile . GetLineInFile ( Line )
elif Line > = Profile . InsertStartLineNumber and Profile . Level == 1 :
2016-04-21 08:50:30 +02:00
InsertedLines + = Profile . GetTotalLines ( )
2009-07-17 11:10:31 +02:00
return ( File , Line - InsertedLines )
## The exception class that used to report error messages when parsing FDF
#
2018-10-23 19:29:19 +02:00
# Currently the "ToolName" is set to be "FdfParser".
2009-07-17 11:10:31 +02:00
#
class Warning ( Exception ) :
## 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
#
def __init__ ( self , Str , File = None , Line = None ) :
FileLineTuple = GetRealFileLine ( File , Line )
self . FileName = FileLineTuple [ 0 ]
self . LineNumber = FileLineTuple [ 1 ]
2015-08-26 08:28:59 +02:00
self . OriginalLineNumber = Line
2009-07-17 11:10:31 +02:00
self . Message = Str
self . ToolName = ' FdfParser '
def __str__ ( self ) :
return self . Message
2018-10-23 19:29:23 +02:00
# helper functions to facilitate consistency in warnings
# each function is for a different common warning
@staticmethod
def Expected ( Str , File , Line ) :
return Warning ( " expected {} " . format ( Str ) , File , Line )
@staticmethod
def ExpectedEquals ( File , Line ) :
return Warning . Expected ( " ' = ' " , File , Line )
@staticmethod
def ExpectedCurlyOpen ( File , Line ) :
return Warning . Expected ( " ' { ' " , File , Line )
@staticmethod
def ExpectedCurlyClose ( File , Line ) :
return Warning . Expected ( " ' } ' " , File , Line )
@staticmethod
def ExpectedBracketClose ( File , Line ) :
return Warning . Expected ( " ' ] ' " , File , Line )
2009-07-17 11:10:31 +02:00
## The Include file content class that used to record file data when parsing include file
#
# May raise Exception when opening file.
#
2018-10-23 19:29:19 +02:00
class IncludeFileProfile :
2009-07-17 11:10:31 +02:00
## The constructor
#
# @param self The object pointer
# @param FileName The file that to be parsed
#
def __init__ ( self , FileName ) :
self . FileName = FileName
self . FileLinesList = [ ]
try :
2019-01-23 03:16:00 +01:00
with open ( FileName , " r " ) as fsock :
2009-07-17 11:10:31 +02:00
self . FileLinesList = fsock . readlines ( )
2017-06-28 12:29:18 +02:00
for index , line in enumerate ( self . FileLinesList ) :
2018-10-23 19:29:19 +02:00
if not line . endswith ( TAB_LINE_BREAK ) :
self . FileLinesList [ index ] + = TAB_LINE_BREAK
2009-07-17 11:10:31 +02:00
except :
EdkLogger . error ( " FdfParser " , FILE_OPEN_FAILURE , ExtraData = FileName )
self . InsertStartLineNumber = None
self . InsertAdjust = 0
2015-08-26 08:28:59 +02:00
self . IncludeFileList = [ ]
self . Level = 1 # first level include file
2018-07-05 11:40:04 +02:00
2015-08-26 08:28:59 +02:00
def GetTotalLines ( self ) :
TotalLines = self . InsertAdjust + len ( self . FileLinesList )
for Profile in self . IncludeFileList :
2016-04-21 08:50:30 +02:00
TotalLines + = Profile . GetTotalLines ( )
2015-08-26 08:28:59 +02:00
return TotalLines
def IsLineInFile ( self , Line ) :
if Line > = self . InsertStartLineNumber and Line < self . InsertStartLineNumber + self . GetTotalLines ( ) :
return True
return False
def GetLineInFile ( self , Line ) :
if not self . IsLineInFile ( Line ) :
return ( self . FileName , - 1 )
2018-07-05 11:40:04 +02:00
2015-08-26 08:28:59 +02:00
InsertedLines = self . InsertStartLineNumber
for Profile in self . IncludeFileList :
if Profile . IsLineInFile ( Line ) :
return Profile . GetLineInFile ( Line )
elif Line > = Profile . InsertStartLineNumber :
InsertedLines + = Profile . GetTotalLines ( )
return ( self . FileName , Line - InsertedLines + 1 )
2009-07-17 11:10:31 +02:00
## The FDF content class that used to record file data when parsing FDF
#
# May raise Exception when opening file.
#
2018-10-23 19:29:19 +02:00
class FileProfile :
2009-07-17 11:10:31 +02:00
## The constructor
#
# @param self The object pointer
# @param FileName The file that to be parsed
#
def __init__ ( self , FileName ) :
self . FileLinesList = [ ]
try :
2019-01-23 03:16:00 +01:00
with open ( FileName , " r " ) as fsock :
2009-07-17 11:10:31 +02:00
self . FileLinesList = fsock . readlines ( )
except :
EdkLogger . error ( " FdfParser " , FILE_OPEN_FAILURE , ExtraData = FileName )
2018-06-22 11:14:13 +02:00
self . FileName = FileName
2018-09-25 07:20:46 +02:00
self . PcdDict = OrderedDict ( )
self . PcdLocalDict = OrderedDict ( )
2009-07-17 11:10:31 +02:00
self . InfList = [ ]
2016-07-20 07:58:03 +02:00
self . InfDict = { ' ArchTBD ' : [ ] }
2011-12-07 07:19:28 +01:00
# ECC will use this Dict and List information
self . PcdFileLineDict = { }
self . InfFileLineList = [ ]
2018-07-05 11:40:04 +02:00
2009-07-17 11:10:31 +02:00
self . FdDict = { }
2010-03-01 00:39:39 +01:00
self . FdNameNotSet = False
2009-07-17 11:10:31 +02:00
self . FvDict = { }
2009-09-11 05:14:43 +02:00
self . CapsuleDict = { }
2009-07-17 11:10:31 +02:00
self . RuleDict = { }
self . OptRomDict = { }
2015-06-23 08:46:01 +02:00
self . FmpPayloadDict = { }
2009-07-17 11:10:31 +02:00
## 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.
#
class FdfParser :
## The constructor
#
# @param self The object pointer
# @param FileName The file that to be parsed
#
def __init__ ( self , FileName ) :
self . Profile = FileProfile ( FileName )
self . FileName = FileName
self . CurrentLineNumber = 1
self . CurrentOffsetWithinLine = 0
self . CurrentFdName = None
self . CurrentFvName = None
2018-10-23 19:29:19 +02:00
self . _Token = " "
self . _SkippedChars = " "
2014-08-28 15:53:34 +02:00
GlobalData . gFdfParser = self
2009-07-17 11:10:31 +02:00
2011-12-07 07:19:28 +01:00
# Used to section info
2018-10-23 19:29:19 +02:00
self . _CurSection = [ ]
2011-12-07 07:19:28 +01:00
# Key: [section name, UI name, arch]
2018-10-23 19:29:19 +02:00
# Value: {MACRO_NAME: MACRO_VALUE}
self . _MacroDict = tdict ( True , 3 )
self . _PcdDict = OrderedDict ( )
2011-12-07 07:19:28 +01:00
2018-10-23 19:29:19 +02:00
self . _WipeOffArea = [ ]
2010-07-21 04:46:15 +02:00
if GenFdsGlobalVariable . WorkSpaceDir == ' ' :
GenFdsGlobalVariable . WorkSpaceDir = os . getenv ( " WORKSPACE " )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _SkipWhiteSpace() method
2009-07-17 11:10:31 +02:00
#
2018-10-23 19:29:19 +02:00
# Skip white spaces from current char.
2009-07-17 11:10:31 +02:00
#
# @param self The object pointer
#
2018-10-23 19:29:19 +02:00
def _SkipWhiteSpace ( self ) :
while not self . _EndOfFile ( ) :
2018-10-23 19:29:20 +02:00
if self . _CurrentChar ( ) in { TAB_PRINTCHAR_NUL , T_CHAR_CR , TAB_LINE_BREAK , TAB_SPACE_SPLIT , T_CHAR_TAB } :
2018-10-23 19:29:19 +02:00
self . _SkippedChars + = str ( self . _CurrentChar ( ) )
self . _GetOneChar ( )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
return
return
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _EndOfFile() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _EndOfFile ( self ) :
2009-07-17 11:10:31 +02:00
NumberOfLines = len ( self . Profile . FileLinesList )
SizeOfLastLine = len ( self . Profile . FileLinesList [ - 1 ] )
if self . CurrentLineNumber == NumberOfLines and self . CurrentOffsetWithinLine > = SizeOfLastLine - 1 :
return True
2018-10-23 19:29:19 +02:00
if self . CurrentLineNumber > NumberOfLines :
2009-07-17 11:10:31 +02:00
return True
2018-10-23 19:29:19 +02:00
return False
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _EndOfLine() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _EndOfLine ( self ) :
2009-07-17 11:10:31 +02:00
if self . CurrentLineNumber > len ( self . Profile . FileLinesList ) :
return True
SizeOfCurrentLine = len ( self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ] )
if self . CurrentOffsetWithinLine > = SizeOfCurrentLine :
return True
2018-10-23 19:29:19 +02:00
return False
2009-07-17 11:10:31 +02:00
## Rewind() method
#
# Reset file data buffer to the initial state
#
# @param self The object pointer
2015-08-26 08:28:59 +02:00
# @param DestLine Optional new destination line number.
2018-07-05 11:40:04 +02:00
# @param DestOffset Optional new destination offset.
2009-07-17 11:10:31 +02:00
#
2018-07-05 11:40:04 +02:00
def Rewind ( self , DestLine = 1 , DestOffset = 0 ) :
self . CurrentLineNumber = DestLine
self . CurrentOffsetWithinLine = DestOffset
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _UndoOneChar() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _UndoOneChar ( self ) :
2009-07-17 11:10:31 +02:00
if self . CurrentLineNumber == 1 and self . CurrentOffsetWithinLine == 0 :
return False
elif self . CurrentOffsetWithinLine == 0 :
self . CurrentLineNumber - = 1
2018-10-23 19:29:19 +02:00
self . CurrentOffsetWithinLine = len ( self . _CurrentLine ( ) ) - 1
2009-07-17 11:10:31 +02:00
else :
self . CurrentOffsetWithinLine - = 1
return True
2018-10-23 19:29:19 +02:00
## _GetOneChar() method
2009-07-17 11:10:31 +02:00
#
# Move forward one char in the file buffer
#
# @param self The object pointer
#
2018-10-23 19:29:19 +02:00
def _GetOneChar ( self ) :
2009-07-17 11:10:31 +02:00
if self . CurrentOffsetWithinLine == len ( self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ] ) - 1 :
2011-10-29 08:59:30 +02:00
self . CurrentLineNumber + = 1
self . CurrentOffsetWithinLine = 0
2009-07-17 11:10:31 +02:00
else :
2011-10-29 08:59:30 +02:00
self . CurrentOffsetWithinLine + = 1
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _CurrentChar() method
2009-07-17 11:10:31 +02:00
#
# Get the char pointed to by the file buffer pointer
#
# @param self The object pointer
# @retval Char Current char
#
2018-10-23 19:29:19 +02:00
def _CurrentChar ( self ) :
2009-07-17 11:10:31 +02:00
return self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ] [ self . CurrentOffsetWithinLine ]
2018-10-23 19:29:19 +02:00
## _NextChar() method
2009-07-17 11:10:31 +02:00
#
# Get the one char pass the char pointed to by the file buffer pointer
#
# @param self The object pointer
# @retval Char Next char
#
2018-10-23 19:29:19 +02:00
def _NextChar ( self ) :
2009-07-17 11:10:31 +02:00
if self . CurrentOffsetWithinLine == len ( self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ] ) - 1 :
return self . Profile . FileLinesList [ self . CurrentLineNumber ] [ 0 ]
2018-10-23 19:29:19 +02:00
return self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ] [ self . CurrentOffsetWithinLine + 1 ]
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _SetCurrentCharValue() method
2009-07-17 11:10:31 +02:00
#
# Modify the value of current char
#
# @param self The object pointer
# @param Value The new value of current char
#
2018-10-23 19:29:19 +02:00
def _SetCurrentCharValue ( self , Value ) :
2009-07-17 11:10:31 +02:00
self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ] [ self . CurrentOffsetWithinLine ] = Value
2018-10-23 19:29:19 +02:00
## _CurrentLine() method
2009-07-17 11:10:31 +02:00
#
# Get the list that contains current line contents
#
# @param self The object pointer
# @retval List current line contents
#
2018-10-23 19:29:19 +02:00
def _CurrentLine ( self ) :
2009-07-17 11:10:31 +02:00
return self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ]
2018-10-23 19:29:19 +02:00
def _StringToList ( self ) :
2009-07-17 11:10:31 +02:00
self . Profile . FileLinesList = [ list ( s ) for s in self . Profile . FileLinesList ]
2018-07-25 06:21:54 +02:00
if not self . Profile . FileLinesList :
EdkLogger . error ( ' FdfParser ' , FILE_READ_FAILURE , ' The file is empty! ' , File = self . FileName )
2009-07-17 11:10:31 +02:00
self . Profile . FileLinesList [ - 1 ] . append ( ' ' )
2018-10-23 19:29:19 +02:00
def _ReplaceFragment ( self , StartPos , EndPos , Value = ' ' ) :
2009-07-17 11:10:31 +02:00
if StartPos [ 0 ] == EndPos [ 0 ] :
Offset = StartPos [ 1 ]
while Offset < = EndPos [ 1 ] :
self . Profile . FileLinesList [ StartPos [ 0 ] ] [ Offset ] = Value
Offset + = 1
return
Offset = StartPos [ 1 ]
2018-10-23 19:29:20 +02:00
while self . Profile . FileLinesList [ StartPos [ 0 ] ] [ Offset ] not in CR_LB_SET :
2009-07-17 11:10:31 +02:00
self . Profile . FileLinesList [ StartPos [ 0 ] ] [ Offset ] = Value
Offset + = 1
Line = StartPos [ 0 ]
while Line < EndPos [ 0 ] :
Offset = 0
2018-10-23 19:29:20 +02:00
while self . Profile . FileLinesList [ Line ] [ Offset ] not in CR_LB_SET :
2009-07-17 11:10:31 +02:00
self . Profile . FileLinesList [ Line ] [ Offset ] = Value
Offset + = 1
Line + = 1
Offset = 0
while Offset < = EndPos [ 1 ] :
self . Profile . FileLinesList [ EndPos [ 0 ] ] [ Offset ] = Value
Offset + = 1
2018-10-23 19:29:19 +02:00
def _SetMacroValue ( self , Macro , Value ) :
if not self . _CurSection :
2011-12-07 07:19:28 +01:00
return
MacroDict = { }
2018-10-23 19:29:19 +02:00
if not self . _MacroDict [ self . _CurSection [ 0 ] , self . _CurSection [ 1 ] , self . _CurSection [ 2 ] ] :
self . _MacroDict [ self . _CurSection [ 0 ] , self . _CurSection [ 1 ] , self . _CurSection [ 2 ] ] = MacroDict
2011-12-07 07:19:28 +01:00
else :
2018-10-23 19:29:19 +02:00
MacroDict = self . _MacroDict [ self . _CurSection [ 0 ] , self . _CurSection [ 1 ] , self . _CurSection [ 2 ] ]
2011-12-07 07:19:28 +01:00
MacroDict [ Macro ] = Value
2018-10-23 19:29:19 +02:00
def _GetMacroValue ( self , Macro ) :
2011-12-07 07:19:28 +01:00
# Highest priority
if Macro in GlobalData . gCommandLineDefines :
return GlobalData . gCommandLineDefines [ Macro ]
if Macro in GlobalData . gGlobalDefines :
return GlobalData . gGlobalDefines [ Macro ]
2018-10-23 19:29:19 +02:00
if self . _CurSection :
MacroDict = self . _MacroDict [
self . _CurSection [ 0 ] ,
self . _CurSection [ 1 ] ,
self . _CurSection [ 2 ]
2011-12-07 07:19:28 +01:00
]
if MacroDict and Macro in MacroDict :
return MacroDict [ Macro ]
# Lowest priority
if Macro in GlobalData . gPlatformDefines :
return GlobalData . gPlatformDefines [ Macro ]
return None
2018-10-23 19:29:19 +02:00
def _SectionHeaderParser ( self , Section ) :
2011-12-07 07:19:28 +01:00
# [Defines]
# [FD.UiName]: use dummy instead if UI name is optional
# [FV.UiName]
# [Capsule.UiName]
# [Rule]: don't take rule section into account, macro is not allowed in this section
# [OptionRom.DriverName]
2018-10-23 19:29:19 +02:00
self . _CurSection = [ ]
Section = Section . strip ( ) [ 1 : - 1 ] . upper ( ) . replace ( ' ' , ' ' ) . strip ( TAB_SPLIT )
ItemList = Section . split ( TAB_SPLIT )
2011-12-07 07:19:28 +01:00
Item = ItemList [ 0 ]
if Item == ' ' or Item == ' RULE ' :
return
2018-04-16 15:52:13 +02:00
if Item == TAB_COMMON_DEFINES . upper ( ) :
2018-10-23 19:29:19 +02:00
self . _CurSection = [ TAB_COMMON , TAB_COMMON , TAB_COMMON ]
2011-12-07 07:19:28 +01:00
elif len ( ItemList ) > 1 :
2018-10-23 19:29:19 +02:00
self . _CurSection = [ ItemList [ 0 ] , ItemList [ 1 ] , TAB_COMMON ]
2011-12-07 07:19:28 +01:00
elif len ( ItemList ) > 0 :
2018-10-23 19:29:19 +02:00
self . _CurSection = [ ItemList [ 0 ] , ' DUMMY ' , TAB_COMMON ]
2011-12-07 07:19:28 +01:00
2009-07-17 11:10:31 +02:00
## 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
#
def PreprocessFile ( self ) :
self . Rewind ( )
InComment = False
DoubleSlashComment = False
HashComment = False
# HashComment in quoted string " " is ignored.
InString = False
2018-10-23 19:29:19 +02:00
while not self . _EndOfFile ( ) :
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _CurrentChar ( ) == T_CHAR_DOUBLE_QUOTE and not InComment :
2009-07-17 11:10:31 +02:00
InString = not InString
# meet new line, then no longer in a comment for // and '#'
2018-10-23 19:29:19 +02:00
if self . _CurrentChar ( ) == TAB_LINE_BREAK :
2009-07-17 11:10:31 +02:00
self . CurrentLineNumber + = 1
self . CurrentOffsetWithinLine = 0
if InComment and DoubleSlashComment :
InComment = False
DoubleSlashComment = False
if InComment and HashComment :
InComment = False
HashComment = False
# check for */ comment end
2018-11-16 16:40:04 +01:00
elif InComment and not DoubleSlashComment and not HashComment and self . _CurrentChar ( ) == TAB_STAR and self . _NextChar ( ) == TAB_BACK_SLASH :
2018-10-23 19:29:19 +02:00
self . _SetCurrentCharValue ( TAB_SPACE_SPLIT )
self . _GetOneChar ( )
self . _SetCurrentCharValue ( TAB_SPACE_SPLIT )
self . _GetOneChar ( )
2009-07-17 11:10:31 +02:00
InComment = False
# set comments to spaces
elif InComment :
2018-10-23 19:29:19 +02:00
self . _SetCurrentCharValue ( TAB_SPACE_SPLIT )
self . _GetOneChar ( )
2009-07-17 11:10:31 +02:00
# check for // comment
2018-10-23 19:29:19 +02:00
elif self . _CurrentChar ( ) == TAB_BACK_SLASH and self . _NextChar ( ) == TAB_BACK_SLASH and not self . _EndOfLine ( ) :
2009-07-17 11:10:31 +02:00
InComment = True
DoubleSlashComment = True
# check for '#' comment
2018-10-23 19:29:19 +02:00
elif self . _CurrentChar ( ) == TAB_COMMENT_SPLIT and not self . _EndOfLine ( ) and not InString :
2009-07-17 11:10:31 +02:00
InComment = True
HashComment = True
# check for /* comment start
2018-11-16 16:40:04 +01:00
elif self . _CurrentChar ( ) == TAB_BACK_SLASH and self . _NextChar ( ) == TAB_STAR :
2018-10-23 19:29:19 +02:00
self . _SetCurrentCharValue ( TAB_SPACE_SPLIT )
self . _GetOneChar ( )
self . _SetCurrentCharValue ( TAB_SPACE_SPLIT )
self . _GetOneChar ( )
2009-07-17 11:10:31 +02:00
InComment = True
else :
2018-10-23 19:29:19 +02:00
self . _GetOneChar ( )
2009-07-17 11:10:31 +02:00
# restore from ListOfList to ListOfString
self . Profile . FileLinesList = [ " " . join ( list ) for list in self . Profile . FileLinesList ]
self . Rewind ( )
## 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
#
def PreprocessIncludeFile ( self ) :
2018-07-05 11:40:04 +02:00
# nested include support
2015-08-26 08:28:59 +02:00
Processed = False
2017-01-22 02:59:32 +01:00
MacroDict = { }
2018-10-23 19:29:19 +02:00
while self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _Token == TAB_DEFINE :
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Macro name " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Macro = self . _Token
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Value = self . _GetExpression ( )
2017-01-22 02:59:32 +01:00
MacroDict [ Macro ] = Value
2018-10-23 19:29:19 +02:00
elif self . _Token == TAB_INCLUDE :
2015-08-26 08:28:59 +02:00
Processed = True
2009-07-17 11:10:31 +02:00
IncludeLine = self . CurrentLineNumber
2018-10-23 19:29:19 +02:00
IncludeOffset = self . CurrentOffsetWithinLine - len ( TAB_INCLUDE )
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " include file name " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
IncFileName = self . _Token
2017-01-22 02:59:32 +01:00
PreIndex = 0
StartPos = IncFileName . find ( ' $( ' , PreIndex )
EndPos = IncFileName . find ( ' ) ' , StartPos + 2 )
while StartPos != - 1 and EndPos != - 1 :
2018-10-23 19:29:19 +02:00
Macro = IncFileName [ StartPos + 2 : EndPos ]
MacroVal = self . _GetMacroValue ( Macro )
2017-01-22 02:59:32 +01:00
if not MacroVal :
if Macro in MacroDict :
MacroVal = MacroDict [ Macro ]
2018-03-26 22:25:43 +02:00
if MacroVal is not None :
2017-01-22 02:59:32 +01:00
IncFileName = IncFileName . replace ( ' $( ' + Macro + ' ) ' , MacroVal , 1 )
if MacroVal . find ( ' $( ' ) != - 1 :
PreIndex = StartPos
else :
PreIndex = StartPos + len ( MacroVal )
else :
raise Warning ( " The Macro %s is not defined " % Macro , self . FileName , self . CurrentLineNumber )
StartPos = IncFileName . find ( ' $( ' , PreIndex )
EndPos = IncFileName . find ( ' ) ' , StartPos + 2 )
IncludedFile = NormPath ( IncFileName )
2011-11-25 07:21:03 +01:00
#
# First search the include file under the same directory as FDF file
#
IncludedFile1 = PathClass ( IncludedFile , os . path . dirname ( self . FileName ) )
ErrorCode = IncludedFile1 . Validate ( ) [ 0 ]
if ErrorCode != 0 :
#
# Then search the include file under the same directory as DSC file
#
2011-12-07 07:19:28 +01:00
PlatformDir = ' '
if GenFdsGlobalVariable . ActivePlatform :
PlatformDir = GenFdsGlobalVariable . ActivePlatform . Dir
elif GlobalData . gActivePlatform :
PlatformDir = GlobalData . gActivePlatform . MetaFile . Dir
IncludedFile1 = PathClass ( IncludedFile , PlatformDir )
2011-11-25 07:21:03 +01:00
ErrorCode = IncludedFile1 . Validate ( ) [ 0 ]
if ErrorCode != 0 :
#
# Also search file under the WORKSPACE directory
#
IncludedFile1 = PathClass ( IncludedFile , GlobalData . gWorkspace )
ErrorCode = IncludedFile1 . Validate ( ) [ 0 ]
if ErrorCode != 0 :
2018-07-05 11:40:04 +02:00
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 ) ,
2011-11-25 07:21:03 +01:00
self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2015-08-26 08:28:59 +02:00
if not IsValidInclude ( IncludedFile1 . Path , self . CurrentLineNumber ) :
raise Warning ( " The include file {0} is causing a include loop. \n " . format ( IncludedFile1 . Path ) , self . FileName , self . CurrentLineNumber )
2011-11-25 07:21:03 +01:00
IncFileProfile = IncludeFileProfile ( IncludedFile1 . Path )
2009-07-17 11:10:31 +02:00
CurrentLine = self . CurrentLineNumber
CurrentOffset = self . CurrentOffsetWithinLine
# list index of the insertion, note that line number is 'CurrentLine + 1'
InsertAtLine = CurrentLine
2015-08-26 08:28:59 +02:00
ParentProfile = GetParentAtLine ( CurrentLine )
2018-03-26 22:25:43 +02:00
if ParentProfile is not None :
2015-08-26 08:28:59 +02:00
ParentProfile . IncludeFileList . insert ( 0 , IncFileProfile )
IncFileProfile . Level = ParentProfile . Level + 1
2009-07-17 11:10:31 +02:00
IncFileProfile . InsertStartLineNumber = InsertAtLine + 1
# deal with remaining portions after "!include filename", if exists.
2018-10-23 19:29:19 +02:00
if self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
if self . CurrentLineNumber == CurrentLine :
2018-10-23 19:29:19 +02:00
RemainingLine = self . _CurrentLine ( ) [ CurrentOffset : ]
2009-07-17 11:10:31 +02:00
self . Profile . FileLinesList . insert ( self . CurrentLineNumber , RemainingLine )
IncFileProfile . InsertAdjust + = 1
self . CurrentLineNumber + = 1
self . CurrentOffsetWithinLine = 0
for Line in IncFileProfile . FileLinesList :
self . Profile . FileLinesList . insert ( InsertAtLine , Line )
self . CurrentLineNumber + = 1
InsertAtLine + = 1
2015-08-26 08:28:59 +02:00
# reversely sorted to better determine error in file
AllIncludeFileList . insert ( 0 , IncFileProfile )
2009-07-17 11:10:31 +02:00
# comment out the processed include file statement
TempList = list ( self . Profile . FileLinesList [ IncludeLine - 1 ] )
2018-10-23 19:29:19 +02:00
TempList . insert ( IncludeOffset , TAB_COMMENT_SPLIT )
2009-07-17 11:10:31 +02:00
self . Profile . FileLinesList [ IncludeLine - 1 ] = ' ' . join ( TempList )
2015-08-26 08:28:59 +02:00
if Processed : # Nested and back-to-back support
self . Rewind ( DestLine = IncFileProfile . InsertStartLineNumber - 1 )
Processed = False
# Preprocess done.
2009-07-17 11:10:31 +02:00
self . Rewind ( )
2018-07-05 11:40:04 +02:00
2018-03-30 02:19:32 +02:00
@staticmethod
2018-10-23 19:29:19 +02:00
def _GetIfListCurrentItemStat ( IfList ) :
2011-05-11 12:26:49 +02:00
if len ( IfList ) == 0 :
return True
2018-07-05 11:40:04 +02:00
2011-05-11 12:26:49 +02:00
for Item in IfList :
if Item [ 1 ] == False :
return False
2018-07-05 11:40:04 +02:00
2011-05-11 12:26:49 +02:00
return True
2018-07-05 11:40:04 +02:00
2010-11-15 03:51:34 +01:00
## PreprocessConditionalStatement() method
2009-07-17 11:10:31 +02:00
#
2010-11-15 03:51:34 +01:00
# Preprocess conditional statement.
2009-07-17 11:10:31 +02:00
# In the end, rewind the file buffer pointer to the beginning
#
# @param self The object pointer
#
def PreprocessConditionalStatement ( self ) :
# IfList is a stack of if branches with elements of list [Pos, CondSatisfied, BranchDetermined]
IfList = [ ]
2011-10-29 08:59:30 +02:00
RegionLayoutLine = 0
2011-12-07 07:19:28 +01:00
ReplacedLine = - 1
2018-10-23 19:29:19 +02:00
while self . _GetNextToken ( ) :
2011-12-07 07:19:28 +01:00
# Determine section name and the location dependent macro
2018-10-23 19:29:19 +02:00
if self . _GetIfListCurrentItemStat ( IfList ) :
if self . _Token . startswith ( TAB_SECTION_START ) :
Header = self . _Token
if not self . _Token . endswith ( TAB_SECTION_END ) :
self . _SkipToToken ( TAB_SECTION_END )
Header + = self . _SkippedChars
2011-12-07 07:19:28 +01:00
if Header . find ( ' $( ' ) != - 1 :
raise Warning ( " macro cannot be used in section header " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
self . _SectionHeaderParser ( Header )
2011-12-07 07:19:28 +01:00
continue
# Replace macros except in RULE section or out of section
2018-10-23 19:29:19 +02:00
elif self . _CurSection and ReplacedLine != self . CurrentLineNumber :
2011-12-07 07:19:28 +01:00
ReplacedLine = self . CurrentLineNumber
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2011-12-07 07:19:28 +01:00
CurLine = self . Profile . FileLinesList [ ReplacedLine - 1 ]
PreIndex = 0
StartPos = CurLine . find ( ' $( ' , PreIndex )
EndPos = CurLine . find ( ' ) ' , StartPos + 2 )
2018-10-23 19:29:20 +02:00
while StartPos != - 1 and EndPos != - 1 and self . _Token not in { TAB_IF_DEF , TAB_IF_N_DEF , TAB_IF , TAB_ELSE_IF } :
2018-10-23 19:29:19 +02:00
MacroName = CurLine [ StartPos + 2 : EndPos ]
2019-02-06 08:44:39 +01:00
MacroValue = self . _GetMacroValue ( MacroName )
if MacroValue is not None :
CurLine = CurLine . replace ( ' $( ' + MacroName + ' ) ' , MacroValue , 1 )
if MacroValue . find ( ' $( ' ) != - 1 :
2011-12-07 07:19:28 +01:00
PreIndex = StartPos
else :
2019-02-06 08:44:39 +01:00
PreIndex = StartPos + len ( MacroValue )
2011-12-07 07:19:28 +01:00
else :
PreIndex = EndPos + 1
StartPos = CurLine . find ( ' $( ' , PreIndex )
EndPos = CurLine . find ( ' ) ' , StartPos + 2 )
self . Profile . FileLinesList [ ReplacedLine - 1 ] = CurLine
continue
2018-10-23 19:29:19 +02:00
if self . _Token == TAB_DEFINE :
if self . _GetIfListCurrentItemStat ( IfList ) :
if not self . _CurSection :
2011-12-07 07:19:28 +01:00
raise Warning ( " macro cannot be defined in Rule section or out of section " , self . FileName , self . CurrentLineNumber )
2011-05-11 12:26:49 +02:00
DefineLine = self . CurrentLineNumber - 1
2018-10-23 19:29:19 +02:00
DefineOffset = self . CurrentOffsetWithinLine - len ( TAB_DEFINE )
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Macro name " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Macro = self . _Token
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
Value = self . _GetExpression ( )
self . _SetMacroValue ( Macro , Value )
self . _WipeOffArea . append ( ( ( DefineLine , DefineOffset ) , ( self . CurrentLineNumber - 1 , self . CurrentOffsetWithinLine - 1 ) ) )
elif self . _Token == ' SET ' :
if not self . _GetIfListCurrentItemStat ( IfList ) :
2015-01-19 06:04:28 +01:00
continue
2012-04-10 09:18:20 +02:00
SetLine = self . CurrentLineNumber - 1
SetOffset = self . CurrentOffsetWithinLine - len ( ' SET ' )
2018-10-23 19:29:19 +02:00
PcdPair = self . _GetNextPcdSettings ( )
2011-10-29 08:59:30 +02:00
PcdName = " %s . %s " % ( PcdPair [ 1 ] , PcdPair [ 0 ] )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2011-10-29 08:59:30 +02:00
2018-10-23 19:29:19 +02:00
Value = self . _GetExpression ( )
Value = self . _EvaluateConditional ( Value , self . CurrentLineNumber , ' eval ' , True )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
self . _PcdDict [ PcdName ] = Value
2012-04-10 09:18:20 +02:00
self . Profile . PcdDict [ PcdPair ] = Value
2018-06-22 11:14:13 +02:00
self . SetPcdLocalation ( PcdPair )
2012-04-10 09:18:20 +02:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
self . Profile . PcdFileLineDict [ PcdPair ] = FileLineTuple
2018-10-23 19:29:19 +02:00
self . _WipeOffArea . append ( ( ( SetLine , SetOffset ) , ( self . CurrentLineNumber - 1 , self . CurrentOffsetWithinLine - 1 ) ) )
2018-10-23 19:29:20 +02:00
elif self . _Token in { TAB_IF_DEF , TAB_IF_N_DEF , TAB_IF } :
2018-10-23 19:29:19 +02:00
IfStartPos = ( self . CurrentLineNumber - 1 , self . CurrentOffsetWithinLine - len ( self . _Token ) )
2009-07-17 11:10:31 +02:00
IfList . append ( [ IfStartPos , None , None ] )
2011-10-29 08:59:30 +02:00
2018-10-23 19:29:19 +02:00
CondLabel = self . _Token
Expression = self . _GetExpression ( )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if CondLabel == TAB_IF :
ConditionSatisfied = self . _EvaluateConditional ( Expression , IfList [ - 1 ] [ 0 ] [ 0 ] + 1 , ' eval ' )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
ConditionSatisfied = self . _EvaluateConditional ( Expression , IfList [ - 1 ] [ 0 ] [ 0 ] + 1 , ' in ' )
if CondLabel == TAB_IF_N_DEF :
2009-07-17 11:10:31 +02:00
ConditionSatisfied = not ConditionSatisfied
2011-10-29 08:59:30 +02:00
BranchDetermined = ConditionSatisfied
IfList [ - 1 ] = [ IfList [ - 1 ] [ 0 ] , ConditionSatisfied , BranchDetermined ]
if ConditionSatisfied :
2018-10-23 19:29:19 +02:00
self . _WipeOffArea . append ( ( IfList [ - 1 ] [ 0 ] , ( self . CurrentLineNumber - 1 , self . CurrentOffsetWithinLine - 1 ) ) )
2018-10-23 19:29:20 +02:00
elif self . _Token in { TAB_ELSE_IF , TAB_ELSE } :
2018-10-23 19:29:19 +02:00
ElseStartPos = ( self . CurrentLineNumber - 1 , self . CurrentOffsetWithinLine - len ( self . _Token ) )
2009-07-17 11:10:31 +02:00
if len ( IfList ) < = 0 :
raise Warning ( " Missing !if statement " , self . FileName , self . CurrentLineNumber )
2011-10-29 08:59:30 +02:00
2009-07-17 11:10:31 +02:00
if IfList [ - 1 ] [ 1 ] :
IfList [ - 1 ] = [ ElseStartPos , False , True ]
2018-10-23 19:29:19 +02:00
self . _WipeOffArea . append ( ( ElseStartPos , ( self . CurrentLineNumber - 1 , self . CurrentOffsetWithinLine - 1 ) ) )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
self . _WipeOffArea . append ( ( IfList [ - 1 ] [ 0 ] , ElseStartPos ) )
2009-07-17 11:10:31 +02:00
IfList [ - 1 ] = [ ElseStartPos , True , IfList [ - 1 ] [ 2 ] ]
2018-10-23 19:29:19 +02:00
if self . _Token == TAB_ELSE_IF :
Expression = self . _GetExpression ( )
ConditionSatisfied = self . _EvaluateConditional ( Expression , IfList [ - 1 ] [ 0 ] [ 0 ] + 1 , ' eval ' )
2009-07-17 11:10:31 +02:00
IfList [ - 1 ] = [ IfList [ - 1 ] [ 0 ] , ConditionSatisfied , IfList [ - 1 ] [ 2 ] ]
if IfList [ - 1 ] [ 1 ] :
if IfList [ - 1 ] [ 2 ] :
IfList [ - 1 ] [ 1 ] = False
else :
IfList [ - 1 ] [ 2 ] = True
2018-10-23 19:29:19 +02:00
self . _WipeOffArea . append ( ( IfList [ - 1 ] [ 0 ] , ( self . CurrentLineNumber - 1 , self . CurrentOffsetWithinLine - 1 ) ) )
elif self . _Token == ' !endif ' :
2011-12-07 07:19:28 +01:00
if len ( IfList ) < = 0 :
raise Warning ( " Missing !if statement " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
if IfList [ - 1 ] [ 1 ] :
2018-10-23 19:29:19 +02:00
self . _WipeOffArea . append ( ( ( self . CurrentLineNumber - 1 , self . CurrentOffsetWithinLine - len ( ' !endif ' ) ) , ( self . CurrentLineNumber - 1 , self . CurrentOffsetWithinLine - 1 ) ) )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
self . _WipeOffArea . append ( ( IfList [ - 1 ] [ 0 ] , ( self . CurrentLineNumber - 1 , self . CurrentOffsetWithinLine - 1 ) ) )
2009-07-17 11:10:31 +02:00
IfList . pop ( )
2011-10-29 08:59:30 +02:00
elif not IfList : # Don't use PCDs inside conditional directive
if self . CurrentLineNumber < = RegionLayoutLine :
# Don't try the same line twice
continue
2012-04-10 09:18:20 +02:00
SetPcd = ShortcutPcdPattern . match ( self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ] )
if SetPcd :
2018-10-23 19:29:19 +02:00
self . _PcdDict [ SetPcd . group ( ' name ' ) ] = SetPcd . group ( ' value ' )
2012-04-10 09:18:20 +02:00
RegionLayoutLine = self . CurrentLineNumber
continue
2011-10-29 08:59:30 +02:00
RegionSize = RegionSizePattern . match ( self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ] )
if not RegionSize :
RegionLayoutLine = self . CurrentLineNumber
continue
RegionSizeGuid = RegionSizeGuidPattern . match ( self . Profile . FileLinesList [ self . CurrentLineNumber ] )
if not RegionSizeGuid :
RegionLayoutLine = self . CurrentLineNumber + 1
continue
2018-10-23 19:29:19 +02:00
self . _PcdDict [ RegionSizeGuid . group ( ' base ' ) ] = RegionSize . group ( ' base ' )
self . _PcdDict [ RegionSizeGuid . group ( ' size ' ) ] = RegionSize . group ( ' size ' )
2011-10-29 08:59:30 +02:00
RegionLayoutLine = self . CurrentLineNumber + 1
if IfList :
2009-07-17 11:10:31 +02:00
raise Warning ( " Missing !endif " , self . FileName , self . CurrentLineNumber )
self . Rewind ( )
2018-10-23 19:29:19 +02:00
def _CollectMacroPcd ( self ) :
2011-12-07 07:19:28 +01:00
MacroDict = { }
# PCD macro
2012-04-10 09:18:20 +02:00
MacroDict . update ( GlobalData . gPlatformPcds )
2018-10-23 19:29:19 +02:00
MacroDict . update ( self . _PcdDict )
2011-12-07 07:19:28 +01:00
# Lowest priority
MacroDict . update ( GlobalData . gPlatformDefines )
2018-10-23 19:29:19 +02:00
if self . _CurSection :
2011-12-07 07:19:28 +01:00
# Defines macro
2018-10-23 19:29:19 +02:00
ScopeMacro = self . _MacroDict [ TAB_COMMON , TAB_COMMON , TAB_COMMON ]
2011-12-07 07:19:28 +01:00
if ScopeMacro :
MacroDict . update ( ScopeMacro )
2018-07-05 11:40:04 +02:00
2011-12-07 07:19:28 +01:00
# Section macro
2018-10-23 19:29:19 +02:00
ScopeMacro = self . _MacroDict [
self . _CurSection [ 0 ] ,
self . _CurSection [ 1 ] ,
self . _CurSection [ 2 ]
2011-12-07 07:19:28 +01:00
]
if ScopeMacro :
MacroDict . update ( ScopeMacro )
MacroDict . update ( GlobalData . gGlobalDefines )
MacroDict . update ( GlobalData . gCommandLineDefines )
2018-10-23 19:29:20 +02:00
for Item in GlobalData . BuildOptionPcd :
if isinstance ( Item , tuple ) :
continue
PcdName , TmpValue = Item . split ( TAB_EQUAL_SPLIT )
TmpValue = BuildOptionValue ( TmpValue , { } )
MacroDict [ PcdName . strip ( ) ] = TmpValue
2011-12-07 07:19:28 +01:00
# Highest priority
return MacroDict
2018-10-23 19:29:19 +02:00
def _EvaluateConditional ( self , Expression , Line , Op = None , Value = None ) :
MacroPcdDict = self . _CollectMacroPcd ( )
2011-10-29 08:59:30 +02:00
if Op == ' eval ' :
try :
2011-12-07 07:19:28 +01:00
if Value :
return ValueExpression ( Expression , MacroPcdDict ) ( True )
else :
return ValueExpression ( Expression , MacroPcdDict ) ( )
2018-06-25 12:31:25 +02:00
except WrnExpression as Excpt :
2018-07-05 11:40:04 +02:00
#
2011-10-29 08:59:30 +02:00
# Catch expression evaluation warning here. We need to report
# the precise number of line and return the evaluation result
#
EdkLogger . warn ( ' Parser ' , " Suspicious expression: %s " % str ( Excpt ) ,
2018-10-23 19:29:19 +02:00
File = self . FileName , ExtraData = self . _CurrentLine ( ) ,
2011-10-29 08:59:30 +02:00
Line = Line )
return Excpt . result
2018-06-25 12:31:25 +02:00
except Exception as Excpt :
2012-04-10 09:18:20 +02:00
if hasattr ( Excpt , ' Pcd ' ) :
if Excpt . Pcd in GlobalData . gPlatformOtherPcds :
Info = GlobalData . gPlatformOtherPcds [ Excpt . Pcd ]
raise Warning ( " Cannot use this PCD ( %s ) in an expression as "
" it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section "
" of the DSC file ( %s ), and it is currently defined in this section: "
" %s , line #: %d . " % ( Excpt . Pcd , GlobalData . gPlatformOtherPcds [ ' DSCFILE ' ] , Info [ 0 ] , Info [ 1 ] ) ,
2018-05-23 05:35:42 +02:00
self . FileName , Line )
2012-04-10 09:18:20 +02:00
else :
raise Warning ( " PCD ( %s ) is not defined in DSC file ( %s ) " % ( Excpt . Pcd , GlobalData . gPlatformOtherPcds [ ' DSCFILE ' ] ) ,
2018-05-23 05:35:42 +02:00
self . FileName , Line )
2012-04-10 09:18:20 +02:00
else :
2018-05-23 05:35:42 +02:00
raise Warning ( str ( Excpt ) , self . FileName , Line )
2011-10-29 08:59:30 +02:00
else :
if Expression . startswith ( ' $( ' ) and Expression [ - 1 ] == ' ) ' :
2018-07-05 11:40:04 +02:00
Expression = Expression [ 2 : - 1 ]
2011-12-07 07:19:28 +01:00
return Expression in MacroPcdDict
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _IsToken() method
2009-07-17 11:10:31 +02:00
#
# Check whether input string is found from current char position along
2018-10-23 19:29:19 +02:00
# If found, the string value is put into self._Token
2009-07-17 11:10:31 +02:00
#
# @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
#
2018-10-23 19:29:19 +02:00
def _IsToken ( self , String , IgnoreCase = False ) :
self . _SkipWhiteSpace ( )
2009-07-17 11:10:31 +02:00
# Only consider the same line, no multi-line token allowed
StartPos = self . CurrentOffsetWithinLine
index = - 1
if IgnoreCase :
2018-10-23 19:29:19 +02:00
index = self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine : ] . upper ( ) . find ( String . upper ( ) )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
index = self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine : ] . find ( String )
2009-07-17 11:10:31 +02:00
if index == 0 :
self . CurrentOffsetWithinLine + = len ( String )
2018-10-23 19:29:19 +02:00
self . _Token = self . _CurrentLine ( ) [ StartPos : self . CurrentOffsetWithinLine ]
2009-07-17 11:10:31 +02:00
return True
return False
2018-10-23 19:29:19 +02:00
## _IsKeyword() method
2009-07-17 11:10:31 +02:00
#
# Check whether input keyword is found from current char position along, whole word only!
2018-10-23 19:29:19 +02:00
# If found, the string value is put into self._Token
2009-07-17 11:10:31 +02:00
#
# @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
#
2018-10-23 19:29:19 +02:00
def _IsKeyword ( self , KeyWord , IgnoreCase = False ) :
self . _SkipWhiteSpace ( )
2009-07-17 11:10:31 +02:00
# Only consider the same line, no multi-line token allowed
StartPos = self . CurrentOffsetWithinLine
index = - 1
if IgnoreCase :
2018-10-23 19:29:19 +02:00
index = self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine : ] . upper ( ) . find ( KeyWord . upper ( ) )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
index = self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine : ] . find ( KeyWord )
2009-07-17 11:10:31 +02:00
if index == 0 :
2018-10-23 19:29:19 +02:00
followingChar = self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine + len ( KeyWord ) ]
if not str ( followingChar ) . isspace ( ) and followingChar not in SEPARATORS :
2009-07-17 11:10:31 +02:00
return False
self . CurrentOffsetWithinLine + = len ( KeyWord )
2018-10-23 19:29:19 +02:00
self . _Token = self . _CurrentLine ( ) [ StartPos : self . CurrentOffsetWithinLine ]
2009-07-17 11:10:31 +02:00
return True
return False
2018-10-23 19:29:19 +02:00
def _GetExpression ( self ) :
2011-10-29 08:59:30 +02:00
Line = self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ]
Index = len ( Line ) - 1
2018-10-23 19:29:20 +02:00
while Line [ Index ] in CR_LB_SET :
2011-10-29 08:59:30 +02:00
Index - = 1
ExpressionString = self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ] [ self . CurrentOffsetWithinLine : Index + 1 ]
self . CurrentOffsetWithinLine + = len ( ExpressionString )
ExpressionString = ExpressionString . strip ( )
return ExpressionString
2018-10-23 19:29:19 +02:00
## _GetNextWord() method
2009-07-17 11:10:31 +02:00
#
# Get next C name from file lines
2018-10-23 19:29:19 +02:00
# If found, the string value is put into self._Token
2009-07-17 11:10:31 +02:00
#
# @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
#
2018-10-23 19:29:19 +02:00
def _GetNextWord ( self ) :
self . _SkipWhiteSpace ( )
if self . _EndOfFile ( ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
TempChar = self . _CurrentChar ( )
2009-07-17 11:10:31 +02:00
StartPos = self . CurrentOffsetWithinLine
if ( TempChar > = ' a ' and TempChar < = ' z ' ) or ( TempChar > = ' A ' and TempChar < = ' Z ' ) or TempChar == ' _ ' :
2018-10-23 19:29:19 +02:00
self . _GetOneChar ( )
while not self . _EndOfLine ( ) :
TempChar = self . _CurrentChar ( )
2009-07-17 11:10:31 +02:00
if ( TempChar > = ' a ' and TempChar < = ' z ' ) or ( TempChar > = ' A ' and TempChar < = ' Z ' ) \
or ( TempChar > = ' 0 ' and TempChar < = ' 9 ' ) or TempChar == ' _ ' or TempChar == ' - ' :
2018-10-23 19:29:19 +02:00
self . _GetOneChar ( )
2009-07-17 11:10:31 +02:00
else :
break
2018-10-23 19:29:19 +02:00
self . _Token = self . _CurrentLine ( ) [ StartPos : self . CurrentOffsetWithinLine ]
2009-07-17 11:10:31 +02:00
return True
return False
2018-10-23 19:29:19 +02:00
def _GetNextPcdWord ( self ) :
self . _SkipWhiteSpace ( )
if self . _EndOfFile ( ) :
2018-06-22 11:14:13 +02:00
return False
2018-10-23 19:29:19 +02:00
TempChar = self . _CurrentChar ( )
2018-06-22 11:14:13 +02:00
StartPos = self . CurrentOffsetWithinLine
2018-10-23 19:29:19 +02:00
if ( TempChar > = ' a ' and TempChar < = ' z ' ) or ( TempChar > = ' A ' and TempChar < = ' Z ' ) or TempChar == ' _ ' or TempChar == TAB_SECTION_START or TempChar == TAB_SECTION_END :
self . _GetOneChar ( )
while not self . _EndOfLine ( ) :
TempChar = self . _CurrentChar ( )
2018-06-22 11:14:13 +02:00
if ( TempChar > = ' a ' and TempChar < = ' z ' ) or ( TempChar > = ' A ' and TempChar < = ' Z ' ) \
2018-10-23 19:29:19 +02:00
or ( TempChar > = ' 0 ' and TempChar < = ' 9 ' ) or TempChar == ' _ ' or TempChar == ' - ' or TempChar == TAB_SECTION_START or TempChar == TAB_SECTION_END :
self . _GetOneChar ( )
2018-06-22 11:14:13 +02:00
else :
break
2018-10-23 19:29:19 +02:00
self . _Token = self . _CurrentLine ( ) [ StartPos : self . CurrentOffsetWithinLine ]
2018-06-22 11:14:13 +02:00
return True
return False
2018-10-23 19:29:19 +02:00
## _GetNextToken() method
2009-07-17 11:10:31 +02:00
#
2019-02-06 08:44:39 +01:00
# Get next token unit before a separator
2018-10-23 19:29:19 +02:00
# If found, the string value is put into self._Token
2009-07-17 11:10:31 +02:00
#
# @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
#
2018-10-23 19:29:19 +02:00
def _GetNextToken ( self ) :
2009-07-17 11:10:31 +02:00
# Skip leading spaces, if exist.
2018-10-23 19:29:19 +02:00
self . _SkipWhiteSpace ( )
if self . _EndOfFile ( ) :
2009-07-17 11:10:31 +02:00
return False
# Record the token start position, the position of the first non-space char.
StartPos = self . CurrentOffsetWithinLine
StartLine = self . CurrentLineNumber
2011-12-07 07:19:28 +01:00
while StartLine == self . CurrentLineNumber :
2018-10-23 19:29:19 +02:00
TempChar = self . _CurrentChar ( )
2019-02-06 08:44:39 +01:00
# Try to find the end char that is not a space and not in separator tuple.
2009-07-17 11:10:31 +02:00
# That is, when we got a space or any char in the tuple, we got the end of token.
2018-10-23 19:29:19 +02:00
if not str ( TempChar ) . isspace ( ) and TempChar not in SEPARATORS :
self . _GetOneChar ( )
2019-02-06 08:44:39 +01:00
# if we happen to meet a separator as the first char, we must proceed to get it.
# That is, we get a token that is a separator char. normally it is the boundary of other tokens.
2018-10-23 19:29:19 +02:00
elif StartPos == self . CurrentOffsetWithinLine and TempChar in SEPARATORS :
self . _GetOneChar ( )
2009-07-17 11:10:31 +02:00
break
else :
break
# else:
# return False
EndPos = self . CurrentOffsetWithinLine
if self . CurrentLineNumber != StartLine :
EndPos = len ( self . Profile . FileLinesList [ StartLine - 1 ] )
2018-10-23 19:29:19 +02:00
self . _Token = self . Profile . FileLinesList [ StartLine - 1 ] [ StartPos : EndPos ]
2018-10-23 19:29:20 +02:00
if self . _Token . lower ( ) in { TAB_IF , TAB_END_IF , TAB_ELSE_IF , TAB_ELSE , TAB_IF_DEF , TAB_IF_N_DEF , TAB_ERROR , TAB_INCLUDE } :
2018-10-23 19:29:19 +02:00
self . _Token = self . _Token . lower ( )
2009-07-17 11:10:31 +02:00
if StartPos != self . CurrentOffsetWithinLine :
return True
else :
return False
2018-10-23 19:29:19 +02:00
## _GetNextGuid() method
2009-07-17 11:10:31 +02:00
#
2019-02-06 08:44:39 +01:00
# Get next token unit before a separator
2018-10-23 19:29:19 +02:00
# If found, the GUID string is put into self._Token
2009-07-17 11:10:31 +02:00
#
# @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
#
2018-10-23 19:29:19 +02:00
def _GetNextGuid ( self ) :
if not self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
return False
2019-01-09 20:00:41 +01:00
if GlobalData . gGuidPattern . match ( self . _Token ) is not None :
2009-07-17 11:10:31 +02:00
return True
2020-07-14 07:30:40 +02:00
elif self . _Token in GlobalData . gGuidDict :
return True
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
return False
2018-04-13 22:51:35 +02:00
@staticmethod
2018-10-23 19:29:19 +02:00
def _Verify ( Name , Value , Scope ) :
2018-04-28 00:32:15 +02:00
# value verification only applies to numeric values.
2018-05-07 07:41:27 +02:00
if Scope not in TAB_PCD_NUMERIC_TYPES :
2018-04-28 00:32:15 +02:00
return
ValueNumber = 0
try :
ValueNumber = int ( Value , 0 )
except :
EdkLogger . error ( " FdfParser " , FORMAT_INVALID , " The value is not valid dec or hex number for %s . " % Name )
if ValueNumber < 0 :
EdkLogger . error ( " FdfParser " , FORMAT_INVALID , " The value can ' t be set to negative value for %s . " % Name )
if ValueNumber > MAX_VAL_TYPE [ Scope ] :
EdkLogger . error ( " FdfParser " , FORMAT_INVALID , " Too large value for %s . " % Name )
return True
2016-08-15 07:52:12 +02:00
2018-10-23 19:29:19 +02:00
## _UndoToken() method
2009-07-17 11:10:31 +02:00
#
# Go back one token unit in file buffer
#
# @param self The object pointer
#
2018-10-23 19:29:19 +02:00
def _UndoToken ( self ) :
self . _UndoOneChar ( )
while self . _CurrentChar ( ) . isspace ( ) :
if not self . _UndoOneChar ( ) :
self . _GetOneChar ( )
2009-07-17 11:10:31 +02:00
return
StartPos = self . CurrentOffsetWithinLine
CurrentLine = self . CurrentLineNumber
while CurrentLine == self . CurrentLineNumber :
2018-10-23 19:29:19 +02:00
TempChar = self . _CurrentChar ( )
2019-02-06 08:44:39 +01:00
# Try to find the end char that is not a space and not in separator tuple.
2009-07-17 11:10:31 +02:00
# That is, when we got a space or any char in the tuple, we got the end of token.
2018-10-23 19:29:19 +02:00
if not str ( TempChar ) . isspace ( ) and not TempChar in SEPARATORS :
if not self . _UndoOneChar ( ) :
2011-12-07 07:19:28 +01:00
return
2019-02-06 08:44:39 +01:00
# if we happen to meet a separator as the first char, we must proceed to get it.
# That is, we get a token that is a separator char. normally it is the boundary of other tokens.
2018-10-23 19:29:19 +02:00
elif StartPos == self . CurrentOffsetWithinLine and TempChar in SEPARATORS :
2009-07-17 11:10:31 +02:00
return
else :
break
2018-10-23 19:29:19 +02:00
self . _GetOneChar ( )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetNextHexNumber() method
2009-07-17 11:10:31 +02:00
#
2019-02-06 08:44:39 +01:00
# Get next HEX data before a separator
2018-10-23 19:29:19 +02:00
# If found, the HEX data is put into self._Token
2009-07-17 11:10:31 +02:00
#
# @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
#
2018-10-23 19:29:19 +02:00
def _GetNextHexNumber ( self ) :
if not self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
return False
2019-01-09 20:00:41 +01:00
if GlobalData . gHexPatternAll . match ( self . _Token ) :
2009-07-17 11:10:31 +02:00
return True
else :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
## _GetNextDecimalNumber() method
2009-07-17 11:10:31 +02:00
#
2019-02-06 08:44:39 +01:00
# Get next decimal data before a separator
2018-10-23 19:29:19 +02:00
# If found, the decimal data is put into self._Token
2009-07-17 11:10:31 +02:00
#
# @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
#
2018-10-23 19:29:19 +02:00
def _GetNextDecimalNumber ( self ) :
if not self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
if self . _Token . isdigit ( ) :
2009-07-17 11:10:31 +02:00
return True
else :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
def _GetNextPcdSettings ( self ) :
if not self . _GetNextWord ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " <PcdTokenSpaceCName> " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
pcdTokenSpaceCName = self . _Token
2018-06-22 11:14:13 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " . " , self . FileName , self . CurrentLineNumber )
2018-06-22 11:14:13 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextWord ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " <PcdCName> " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
pcdCName = self . _Token
2018-06-22 11:14:13 +02:00
Fields = [ ]
2018-10-23 19:29:19 +02:00
while self . _IsToken ( TAB_SPLIT ) :
if not self . _GetNextPcdWord ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Pcd Fields " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Fields . append ( self . _Token )
2018-06-22 11:14:13 +02:00
2018-10-23 19:29:19 +02:00
return ( pcdCName , pcdTokenSpaceCName , TAB_SPLIT . join ( Fields ) )
2018-06-22 11:14:13 +02:00
2018-10-23 19:29:19 +02:00
## _GetStringData() method
2009-07-17 11:10:31 +02:00
#
# Get string contents quoted in ""
2018-10-23 19:29:19 +02:00
# If found, the decimal data is put into self._Token
2009-07-17 11:10:31 +02:00
#
# @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
#
2018-10-23 19:29:19 +02:00
def _GetStringData ( self ) :
2018-10-23 19:29:23 +02:00
QuoteToUse = None
2018-10-23 19:29:19 +02:00
if self . _Token . startswith ( T_CHAR_DOUBLE_QUOTE ) or self . _Token . startswith ( " L \" " ) :
2018-10-23 19:29:23 +02:00
QuoteToUse = T_CHAR_DOUBLE_QUOTE
2018-10-23 19:29:19 +02:00
elif self . _Token . startswith ( T_CHAR_SINGLE_QUOTE ) or self . _Token . startswith ( " L \' " ) :
2018-10-23 19:29:23 +02:00
QuoteToUse = T_CHAR_SINGLE_QUOTE
2009-07-17 11:10:31 +02:00
else :
return False
2018-10-23 19:29:23 +02:00
self . _UndoToken ( )
self . _SkipToToken ( QuoteToUse )
currentLineNumber = self . CurrentLineNumber
if not self . _SkipToToken ( QuoteToUse ) :
raise Warning ( QuoteToUse , self . FileName , self . CurrentLineNumber )
if currentLineNumber != self . CurrentLineNumber :
raise Warning ( QuoteToUse , self . FileName , self . CurrentLineNumber )
self . _Token = self . _SkippedChars . rstrip ( QuoteToUse )
return True
2018-10-23 19:29:19 +02:00
## _SkipToToken() method
2009-07-17 11:10:31 +02:00
#
# Search forward in file buffer for the string
2018-10-23 19:29:19 +02:00
# The skipped chars are put into self._SkippedChars
2009-07-17 11:10:31 +02:00
#
# @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
#
2018-10-23 19:29:19 +02:00
def _SkipToToken ( self , String , IgnoreCase = False ) :
2009-07-17 11:10:31 +02:00
StartPos = self . GetFileBufferPos ( )
2018-10-23 19:29:19 +02:00
self . _SkippedChars = " "
while not self . _EndOfFile ( ) :
2009-07-17 11:10:31 +02:00
index = - 1
if IgnoreCase :
2018-10-23 19:29:19 +02:00
index = self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine : ] . upper ( ) . find ( String . upper ( ) )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
index = self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine : ] . find ( String )
2009-07-17 11:10:31 +02:00
if index == 0 :
self . CurrentOffsetWithinLine + = len ( String )
2018-10-23 19:29:19 +02:00
self . _SkippedChars + = String
2009-07-17 11:10:31 +02:00
return True
2018-10-23 19:29:19 +02:00
self . _SkippedChars + = str ( self . _CurrentChar ( ) )
self . _GetOneChar ( )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
self . SetFileBufferPos ( StartPos )
self . _SkippedChars = " "
2009-07-17 11:10:31 +02:00
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
#
def GetFileBufferPos ( self ) :
return ( self . CurrentLineNumber , self . CurrentOffsetWithinLine )
## SetFileBufferPos() method
#
# Restore the file buffer position
#
# @param self The object pointer
# @param Pos The new file buffer position
#
def SetFileBufferPos ( self , Pos ) :
( self . CurrentLineNumber , self . CurrentOffsetWithinLine ) = Pos
2011-11-09 05:32:08 +01:00
## Preprocess() method
#
# Preprocess comment, conditional directive, include directive, replace macro.
# Exception will be raised if syntax error found
#
# @param self The object pointer
#
def Preprocess ( self ) :
2018-10-23 19:29:19 +02:00
self . _StringToList ( )
2011-11-09 05:32:08 +01:00
self . PreprocessFile ( )
self . PreprocessIncludeFile ( )
2018-10-23 19:29:19 +02:00
self . _StringToList ( )
2011-11-09 05:32:08 +01:00
self . PreprocessFile ( )
self . PreprocessConditionalStatement ( )
2018-10-23 19:29:19 +02:00
self . _StringToList ( )
for Pos in self . _WipeOffArea :
self . _ReplaceFragment ( Pos [ 0 ] , Pos [ 1 ] )
2011-11-09 05:32:08 +01:00
self . Profile . FileLinesList = [ " " . join ( list ) for list in self . Profile . FileLinesList ]
2018-10-23 19:29:19 +02:00
while self . _GetDefines ( ) :
2011-11-09 05:32:08 +01:00
pass
2009-07-17 11:10:31 +02:00
## 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
#
def ParseFile ( self ) :
try :
2011-11-09 05:32:08 +01:00
self . Preprocess ( )
2018-10-23 19:29:19 +02:00
self . _GetError ( )
2016-10-07 23:07:03 +02:00
#
# Keep processing sections of the FDF until no new sections or a syntax error is found
#
2019-01-09 07:44:36 +01:00
while self . _GetFd ( ) or self . _GetFv ( ) or self . _GetFmp ( ) or self . _GetCapsule ( ) or self . _GetRule ( ) or self . _GetOptionRom ( ) :
2009-07-17 11:10:31 +02:00
pass
2018-06-25 12:31:25 +02:00
except Warning as X :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
#'\n\tGot Token: \"%s\" from File %s\n' % (self._Token, FileLineTuple[0]) + \
2015-08-26 08:28:59 +02:00
# At this point, the closest parent would be the included file itself
Profile = GetParentAtLine ( X . OriginalLineNumber )
2018-03-26 22:25:43 +02:00
if Profile is not None :
2015-08-26 08:28:59 +02:00
X . Message + = ' near line %d , column %d : %s ' \
% ( X . LineNumber , 0 , Profile . FileLinesList [ X . LineNumber - 1 ] )
else :
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
X . Message + = ' near line %d , column %d : %s ' \
2018-10-23 19:29:19 +02:00
% ( FileLineTuple [ 1 ] , self . CurrentOffsetWithinLine + 1 , self . Profile . FileLinesList [ self . CurrentLineNumber - 1 ] [ self . CurrentOffsetWithinLine : ] . rstrip ( TAB_LINE_BREAK ) . rstrip ( T_CHAR_CR ) )
2009-07-17 11:10:31 +02:00
raise
2016-04-21 08:50:30 +02:00
## SectionParser() method
#
# Parse the file section info
# Exception will be raised if syntax error found
#
# @param self The object pointer
# @param section The section string
def SectionParser ( self , section ) :
S = section . upper ( )
if not S . startswith ( " [DEFINES " ) and not S . startswith ( " [FD. " ) and not S . startswith ( " [FV. " ) and not S . startswith ( " [CAPSULE. " ) \
2019-01-09 07:44:36 +01:00
and not S . startswith ( " [RULE. " ) and not S . startswith ( " [OPTIONROM. " ) and not S . startswith ( ' [FMPPAYLOAD. ' ) :
raise Warning ( " Unknown section or section appear sequence error (The correct sequence should be [DEFINES], [FD.], [FV.], [Capsule.], [Rule.], [OptionRom.], [FMPPAYLOAD.]) " , self . FileName , self . CurrentLineNumber )
2016-04-21 08:50:30 +02:00
2018-10-23 19:29:19 +02:00
## _GetDefines() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetDefines ( self ) :
if not self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
S = self . _Token . upper ( )
if S . startswith ( TAB_SECTION_START ) and not S . startswith ( " [DEFINES " ) :
2016-04-21 08:50:30 +02:00
self . SectionParser ( S )
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
if not self . _IsToken ( " [DEFINES " , True ) :
2009-07-17 11:10:31 +02:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
#print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
2018-10-23 19:29:19 +02:00
# % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine:], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " [DEFINES " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_SECTION_END ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedBracketClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
while self . _GetNextWord ( ) :
2010-11-15 03:51:34 +01:00
# handle the SET statement
2018-10-23 19:29:19 +02:00
if self . _Token == ' SET ' :
self . _UndoToken ( )
self . _GetSetStatement ( None )
2010-11-15 03:51:34 +01:00
continue
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
Macro = self . _Token
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) or self . _Token . startswith ( TAB_SECTION_START ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " MACRO value " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Value = self . _Token
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
##_GetError() method
def _GetError ( self ) :
2018-06-17 11:22:21 +02:00
#save the Current information
CurrentLine = self . CurrentLineNumber
CurrentOffset = self . CurrentOffsetWithinLine
2018-10-23 19:29:19 +02:00
while self . _GetNextToken ( ) :
if self . _Token == TAB_ERROR :
EdkLogger . error ( ' FdfParser ' , ERROR_STATEMENT , self . _CurrentLine ( ) . replace ( TAB_ERROR , ' ' , 1 ) , File = self . FileName , Line = self . CurrentLineNumber )
2018-06-17 11:22:21 +02:00
self . CurrentLineNumber = CurrentLine
self . CurrentOffsetWithinLine = CurrentOffset
2018-10-23 19:29:19 +02:00
## _GetFd() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetFd ( self ) :
if not self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
S = self . _Token . upper ( )
if S . startswith ( TAB_SECTION_START ) and not S . startswith ( " [FD. " ) :
2015-06-23 08:46:01 +02:00
if not S . startswith ( " [FV. " ) and not S . startswith ( ' [FMPPAYLOAD. ' ) and not S . startswith ( " [CAPSULE. " ) \
2019-01-09 07:44:36 +01:00
and not S . startswith ( " [RULE. " ) and not S . startswith ( " [OPTIONROM. " ) :
2009-07-17 11:10:31 +02:00
raise Warning ( " Unknown section " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
if not self . _IsToken ( " [FD. " , True ) :
2009-07-17 11:10:31 +02:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
#print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
2018-10-23 19:29:19 +02:00
# % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine:], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " [FD.] " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
FdName = self . _GetUiName ( )
2010-03-01 00:39:39 +01:00
if FdName == " " :
if len ( self . Profile . FdDict ) == 0 :
FdName = GenFdsGlobalVariable . PlatformName
2011-12-07 07:19:28 +01:00
if FdName == " " and GlobalData . gActivePlatform :
FdName = GlobalData . gActivePlatform . PlatformName
2010-03-01 00:39:39 +01:00
self . Profile . FdNameNotSet = True
else :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FdName in [FD.] section " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
self . CurrentFdName = FdName . upper ( )
2018-07-05 11:40:04 +02:00
2010-03-01 00:39:39 +01:00
if self . CurrentFdName in self . Profile . FdDict :
raise Warning ( " Unexpected the same FD name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_SECTION_END ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedBracketClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
FdObj = FD ( )
2009-07-17 11:10:31 +02:00
FdObj . FdUiName = self . CurrentFdName
self . Profile . FdDict [ self . CurrentFdName ] = FdObj
2010-03-01 00:39:39 +01:00
if len ( self . Profile . FdDict ) > 1 and self . Profile . FdNameNotSet :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " all FDs have their name " , self . FileName , self . CurrentLineNumber )
2010-03-01 00:39:39 +01:00
2018-10-23 19:29:19 +02:00
Status = self . _GetCreateFile ( FdObj )
2009-07-17 11:10:31 +02:00
if not Status :
raise Warning ( " FD name error " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
while self . _GetTokenStatements ( FdObj ) :
2013-11-18 08:41:21 +01:00
pass
for Attr in ( " BaseAddress " , " Size " , " ErasePolarity " ) :
2018-03-26 22:25:43 +02:00
if getattr ( FdObj , Attr ) is None :
2018-10-23 19:29:19 +02:00
self . _GetNextToken ( )
2013-11-18 08:41:21 +01:00
raise Warning ( " Keyword %s missing " % Attr , self . FileName , self . CurrentLineNumber )
if not FdObj . BlockSizeList :
FdObj . BlockSizeList . append ( ( 1 , FdObj . Size , None ) )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
self . _GetDefineStatements ( FdObj )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
self . _GetSetStatements ( FdObj )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetRegionLayout ( FdObj ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " region layout " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
while self . _GetRegionLayout ( FdObj ) :
2009-07-17 11:10:31 +02:00
pass
return True
2018-10-23 19:29:19 +02:00
## _GetUiName() method
2009-07-17 11:10:31 +02:00
#
# Return the UI name of a section
#
# @param self The object pointer
# @retval FdName UI name
#
2018-10-23 19:29:19 +02:00
def _GetUiName ( self ) :
2009-07-17 11:10:31 +02:00
Name = " "
2018-10-23 19:29:19 +02:00
if self . _GetNextWord ( ) :
Name = self . _Token
2009-07-17 11:10:31 +02:00
return Name
2018-10-23 19:29:19 +02:00
## _GetCreateFile() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetCreateFile ( self , Obj ) :
if self . _IsKeyword ( " CREATE_FILE " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " file name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
FileName = self . _Token
2009-07-17 11:10:31 +02:00
Obj . CreateFileName = FileName
return True
2018-06-22 11:14:13 +02:00
def SetPcdLocalation ( self , pcdpair ) :
self . Profile . PcdLocalDict [ pcdpair ] = ( self . Profile . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
## _GetTokenStatements() method
2009-07-17 11:10:31 +02:00
#
# Get token statements
#
# @param self The object pointer
# @param Obj for whom token statement is got
#
2018-10-23 19:29:19 +02:00
def _GetTokenStatements ( self , Obj ) :
if self . _IsKeyword ( " BaseAddress " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Hex base address " , self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
Obj . BaseAddress = self . _Token
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsToken ( TAB_VALUE_SPLIT ) :
pcdPair = self . _GetNextPcdSettings ( )
2013-11-18 08:41:21 +01:00
Obj . BaseAddressPcd = pcdPair
self . Profile . PcdDict [ pcdPair ] = Obj . BaseAddress
2018-06-22 11:14:13 +02:00
self . SetPcdLocalation ( pcdPair )
2013-11-18 08:41:21 +01:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
self . Profile . PcdFileLineDict [ pcdPair ] = FileLineTuple
return True
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " Size " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Hex size " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
Size = self . _Token
if self . _IsToken ( TAB_VALUE_SPLIT ) :
pcdPair = self . _GetNextPcdSettings ( )
2013-11-18 08:41:21 +01:00
Obj . SizePcd = pcdPair
self . Profile . PcdDict [ pcdPair ] = Size
2018-06-22 11:14:13 +02:00
self . SetPcdLocalation ( pcdPair )
2013-11-18 08:41:21 +01:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
self . Profile . PcdFileLineDict [ pcdPair ] = FileLineTuple
2018-12-03 03:29:40 +01:00
Obj . Size = int ( Size , 0 )
2013-11-18 08:41:21 +01:00
return True
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " ErasePolarity " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Erase Polarity " , self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:23 +02:00
if not self . _Token in { " 1 " , " 0 " } :
raise Warning . Expected ( " 1 or 0 Erase Polarity " , self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
Obj . ErasePolarity = self . _Token
2013-11-18 08:41:21 +01:00
return True
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
return self . _GetBlockStatements ( Obj )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetAddressStatements() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetAddressStatements ( self , Obj ) :
if self . _IsKeyword ( " BsBaseAddress " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextDecimalNumber ( ) and not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " address " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-12-03 03:29:40 +01:00
BsAddress = int ( self . _Token , 0 )
2009-07-17 11:10:31 +02:00
Obj . BsBaseAddress = BsAddress
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " RtBaseAddress " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextDecimalNumber ( ) and not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " address " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-12-03 03:29:40 +01:00
RtAddress = int ( self . _Token , 0 )
2009-07-17 11:10:31 +02:00
Obj . RtBaseAddress = RtAddress
2018-10-23 19:29:19 +02:00
## _GetBlockStatements() method
2009-07-17 11:10:31 +02:00
#
# Get block statements
#
# @param self The object pointer
# @param Obj for whom block statement is got
#
2018-10-23 19:29:19 +02:00
def _GetBlockStatements ( self , Obj ) :
2013-11-18 08:41:21 +01:00
IsBlock = False
2018-10-23 19:29:19 +02:00
while self . _GetBlockStatement ( Obj ) :
2013-11-18 08:41:21 +01:00
IsBlock = True
2018-07-05 11:40:04 +02:00
2013-11-18 08:41:21 +01:00
Item = Obj . BlockSizeList [ - 1 ]
2018-03-26 22:25:43 +02:00
if Item [ 0 ] is None or Item [ 1 ] is None :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " block statement " , self . FileName , self . CurrentLineNumber )
2013-11-18 08:41:21 +01:00
return IsBlock
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetBlockStatement() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetBlockStatement ( self , Obj ) :
if not self . _IsKeyword ( " BlockSize " ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextHexNumber ( ) and not self . _GetNextDecimalNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Hex or Integer block size " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
BlockSize = self . _Token
2009-07-17 11:10:31 +02:00
BlockSizePcd = None
2018-10-23 19:29:19 +02:00
if self . _IsToken ( TAB_VALUE_SPLIT ) :
PcdPair = self . _GetNextPcdSettings ( )
2009-07-17 11:10:31 +02:00
BlockSizePcd = PcdPair
self . Profile . PcdDict [ PcdPair ] = BlockSize
2018-06-22 11:14:13 +02:00
self . SetPcdLocalation ( PcdPair )
2011-12-07 07:19:28 +01:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
self . Profile . PcdFileLineDict [ PcdPair ] = FileLineTuple
2018-12-03 03:29:40 +01:00
BlockSize = int ( BlockSize , 0 )
2009-07-17 11:10:31 +02:00
BlockNumber = None
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " NumBlocks " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextDecimalNumber ( ) and not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " block numbers " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-12-03 03:29:40 +01:00
BlockNumber = int ( self . _Token , 0 )
2009-07-17 11:10:31 +02:00
Obj . BlockSizeList . append ( ( BlockSize , BlockNumber , BlockSizePcd ) )
return True
2018-10-23 19:29:19 +02:00
## _GetDefineStatements() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetDefineStatements ( self , Obj ) :
while self . _GetDefineStatement ( Obj ) :
2009-07-17 11:10:31 +02:00
pass
2018-10-23 19:29:19 +02:00
## _GetDefineStatement() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetDefineStatement ( self , Obj ) :
if self . _IsKeyword ( TAB_DEFINE ) :
self . _GetNextToken ( )
Macro = self . _Token
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " value " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
Value = self . _Token
2009-07-17 11:10:31 +02:00
Macro = ' $( ' + Macro + ' ) '
Obj . DefineVarDict [ Macro ] = Value
return True
return False
2018-10-23 19:29:19 +02:00
## _GetSetStatements() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetSetStatements ( self , Obj ) :
while self . _GetSetStatement ( Obj ) :
2009-07-17 11:10:31 +02:00
pass
2018-10-23 19:29:19 +02:00
## _GetSetStatement() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetSetStatement ( self , Obj ) :
if self . _IsKeyword ( " SET " ) :
PcdPair = self . _GetNextPcdSettings ( )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
Value = self . _GetExpression ( )
Value = self . _EvaluateConditional ( Value , self . CurrentLineNumber , ' eval ' , True )
2009-07-17 11:10:31 +02:00
2010-11-15 03:51:34 +01:00
if Obj :
Obj . SetVarDict [ PcdPair ] = Value
2009-07-17 11:10:31 +02:00
self . Profile . PcdDict [ PcdPair ] = Value
2018-06-22 11:14:13 +02:00
self . SetPcdLocalation ( PcdPair )
2011-12-07 07:19:28 +01:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
self . Profile . PcdFileLineDict [ PcdPair ] = FileLineTuple
2009-07-17 11:10:31 +02:00
return True
return False
2018-10-23 19:29:19 +02:00
## _CalcRegionExpr(self)
2013-08-23 04:18:16 +02:00
#
# Calculate expression for offset or size of a region
#
# @return: None if invalid expression
# Calculated number if successfully
#
2018-10-23 19:29:19 +02:00
def _CalcRegionExpr ( self ) :
2013-08-23 04:18:16 +02:00
StartPos = self . GetFileBufferPos ( )
Expr = ' '
PairCount = 0
2018-10-23 19:29:19 +02:00
while not self . _EndOfFile ( ) :
CurCh = self . _CurrentChar ( )
2013-08-23 04:18:16 +02:00
if CurCh == ' ( ' :
PairCount + = 1
elif CurCh == ' ) ' :
PairCount - = 1
if CurCh in ' | \r \n ' and PairCount == 0 :
break
Expr + = CurCh
2018-10-23 19:29:19 +02:00
self . _GetOneChar ( )
2013-08-23 04:18:16 +02:00
try :
2018-12-03 03:29:40 +01:00
return int (
2013-08-23 04:18:16 +02:00
ValueExpression ( Expr ,
2018-10-23 19:29:19 +02:00
self . _CollectMacroPcd ( )
2018-06-25 12:31:33 +02:00
) ( True ) , 0 )
2013-08-23 04:18:16 +02:00
except Exception :
self . SetFileBufferPos ( StartPos )
return None
2018-10-23 19:29:19 +02:00
## _GetRegionLayout() method
2009-07-17 11:10:31 +02:00
#
# Get region layout for FD
#
# @param self The object pointer
2018-10-23 19:29:19 +02:00
# @param theFd for whom region is got
2009-07-17 11:10:31 +02:00
# @retval True Successfully find
# @retval False Not able to find
#
2018-10-23 19:29:19 +02:00
def _GetRegionLayout ( self , theFd ) :
Offset = self . _CalcRegionExpr ( )
2018-03-26 22:25:43 +02:00
if Offset is None :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
RegionObj = Region ( )
2013-08-23 04:18:16 +02:00
RegionObj . Offset = Offset
2018-10-23 19:29:19 +02:00
theFd . RegionList . append ( RegionObj )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_VALUE_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' | ' " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
Size = self . _CalcRegionExpr ( )
2018-03-26 22:25:43 +02:00
if Size is None :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Region Size " , self . FileName , self . CurrentLineNumber )
2013-08-23 04:18:16 +02:00
RegionObj . Size = Size
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextWord ( ) :
2009-07-17 11:10:31 +02:00
return True
2018-10-23 19:29:20 +02:00
if not self . _Token in { " SET " , BINARY_FILE_TYPE_FV , " FILE " , " DATA " , " CAPSULE " , " INF " } :
2014-01-10 06:25:50 +01:00
#
# If next token is a word which is not a valid FV type, it might be part of [PcdOffset[|PcdSize]]
# Or it might be next region's offset described by an expression which starts with a PCD.
# PcdOffset[|PcdSize] or OffsetPcdExpression|Size
#
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
IsRegionPcd = ( RegionSizeGuidPattern . match ( self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine : ] ) or
RegionOffsetPcdPattern . match ( self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine : ] ) )
2014-01-10 06:25:50 +01:00
if IsRegionPcd :
2018-10-23 19:29:19 +02:00
RegionObj . PcdOffset = self . _GetNextPcdSettings ( )
2018-12-03 03:29:40 +01:00
self . Profile . PcdDict [ RegionObj . PcdOffset ] = " 0x %08X " % ( RegionObj . Offset + int ( theFd . BaseAddress , 0 ) )
2018-06-22 11:14:13 +02:00
self . SetPcdLocalation ( RegionObj . PcdOffset )
2018-10-23 19:29:19 +02:00
self . _PcdDict [ ' %s . %s ' % ( RegionObj . PcdOffset [ 1 ] , RegionObj . PcdOffset [ 0 ] ) ] = " 0x %x " % RegionObj . Offset
2011-12-07 07:19:28 +01:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
2014-01-10 06:25:50 +01:00
self . Profile . PcdFileLineDict [ RegionObj . PcdOffset ] = FileLineTuple
2018-10-23 19:29:19 +02:00
if self . _IsToken ( TAB_VALUE_SPLIT ) :
RegionObj . PcdSize = self . _GetNextPcdSettings ( )
2014-01-10 06:25:50 +01:00
self . Profile . PcdDict [ RegionObj . PcdSize ] = " 0x %08X " % RegionObj . Size
2018-06-22 11:14:13 +02:00
self . SetPcdLocalation ( RegionObj . PcdSize )
2018-10-23 19:29:19 +02:00
self . _PcdDict [ ' %s . %s ' % ( RegionObj . PcdSize [ 1 ] , RegionObj . PcdSize [ 0 ] ) ] = " 0x %x " % RegionObj . Size
2014-01-10 06:25:50 +01:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
self . Profile . PcdFileLineDict [ RegionObj . PcdSize ] = FileLineTuple
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextWord ( ) :
2009-07-17 11:10:31 +02:00
return True
2018-10-23 19:29:19 +02:00
if self . _Token == " SET " :
self . _UndoToken ( )
self . _GetSetStatements ( RegionObj )
if not self . _GetNextWord ( ) :
2009-07-17 11:10:31 +02:00
return True
2018-10-23 19:29:19 +02:00
elif self . _Token == BINARY_FILE_TYPE_FV :
self . _UndoToken ( )
self . _GetRegionFvType ( RegionObj )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
elif self . _Token == " CAPSULE " :
self . _UndoToken ( )
self . _GetRegionCapType ( RegionObj )
2009-09-11 05:14:43 +02:00
2018-10-23 19:29:19 +02:00
elif self . _Token == " FILE " :
self . _UndoToken ( )
self . _GetRegionFileType ( RegionObj )
2015-12-07 09:27:53 +01:00
2018-10-23 19:29:19 +02:00
elif self . _Token == " INF " :
self . _UndoToken ( )
2015-12-07 09:27:53 +01:00
RegionObj . RegionType = " INF "
2018-10-23 19:29:19 +02:00
while self . _IsKeyword ( " INF " ) :
self . _UndoToken ( )
ffsInf = self . _ParseInfStatement ( )
2015-12-07 09:27:53 +01:00
if not ffsInf :
break
RegionObj . RegionDataList . append ( ffsInf )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
elif self . _Token == " DATA " :
self . _UndoToken ( )
self . _GetRegionDataType ( RegionObj )
2011-10-11 04:49:48 +02:00
else :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
if self . _GetRegionLayout ( theFd ) :
2014-01-10 06:25:50 +01:00
return True
2011-10-11 04:49:48 +02:00
raise Warning ( " A valid region type was not found. "
2015-12-07 09:27:53 +01:00
" Valid types are [SET, FV, CAPSULE, FILE, DATA, INF]. This error occurred " ,
2011-10-11 04:49:48 +02:00
self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
return True
2018-10-23 19:29:19 +02:00
## _GetRegionFvType() method
2009-07-17 11:10:31 +02:00
#
# Get region fv data for region
#
# @param self The object pointer
# @param RegionObj for whom region data is got
#
2018-10-23 19:29:19 +02:00
def _GetRegionFvType ( self , RegionObj ) :
if not self . _IsKeyword ( BINARY_FILE_TYPE_FV ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' FV ' " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FV name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-04-26 18:57:56 +02:00
RegionObj . RegionType = BINARY_FILE_TYPE_FV
2018-10-23 19:29:19 +02:00
RegionObj . RegionDataList . append ( ( self . _Token ) . upper ( ) )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
while self . _IsKeyword ( BINARY_FILE_TYPE_FV ) :
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FV name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
RegionObj . RegionDataList . append ( ( self . _Token ) . upper ( ) )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetRegionCapType() method
2009-09-11 05:14:43 +02:00
#
# Get region capsule data for region
#
# @param self The object pointer
# @param RegionObj for whom region data is got
#
2018-10-23 19:29:19 +02:00
def _GetRegionCapType ( self , RegionObj ) :
if not self . _IsKeyword ( " CAPSULE " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' CAPSULE ' " , self . FileName , self . CurrentLineNumber )
2009-09-11 05:14:43 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-09-11 05:14:43 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " CAPSULE name " , self . FileName , self . CurrentLineNumber )
2009-09-11 05:14:43 +02:00
RegionObj . RegionType = " CAPSULE "
2018-10-23 19:29:19 +02:00
RegionObj . RegionDataList . append ( self . _Token )
2009-09-11 05:14:43 +02:00
2018-10-23 19:29:19 +02:00
while self . _IsKeyword ( " CAPSULE " ) :
2009-09-11 05:14:43 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-09-11 05:14:43 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " CAPSULE name " , self . FileName , self . CurrentLineNumber )
2009-09-11 05:14:43 +02:00
2018-10-23 19:29:19 +02:00
RegionObj . RegionDataList . append ( self . _Token )
2009-09-11 05:14:43 +02:00
2018-10-23 19:29:19 +02:00
## _GetRegionFileType() method
2009-07-17 11:10:31 +02:00
#
# Get region file data for region
#
# @param self The object pointer
# @param RegionObj for whom region data is got
#
2018-10-23 19:29:19 +02:00
def _GetRegionFileType ( self , RegionObj ) :
if not self . _IsKeyword ( " FILE " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' FILE ' " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " File name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
RegionObj . RegionType = " FILE "
2018-10-23 19:29:19 +02:00
RegionObj . RegionDataList . append ( self . _Token )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
while self . _IsKeyword ( " FILE " ) :
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FILE name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
RegionObj . RegionDataList . append ( self . _Token )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetRegionDataType() method
2009-07-17 11:10:31 +02:00
#
# Get region array data for region
#
# @param self The object pointer
# @param RegionObj for whom region data is got
#
2018-10-23 19:29:19 +02:00
def _GetRegionDataType ( self , RegionObj ) :
if not self . _IsKeyword ( " DATA " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Region Data type " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Hex byte " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if len ( self . _Token ) > 18 :
2010-03-12 11:54:01 +01:00
raise Warning ( " Hex string can ' t be converted to a valid UINT64 value " , self . FileName , self . CurrentLineNumber )
# convert hex string value to byte hex string array
2018-10-23 19:29:19 +02:00
AllString = self . _Token
2010-03-12 11:54:01 +01:00
AllStrLen = len ( AllString )
DataString = " "
while AllStrLen > 4 :
2018-10-23 19:29:19 +02:00
DataString = DataString + " 0x " + AllString [ AllStrLen - 2 : AllStrLen ] + TAB_COMMA_SPLIT
2010-03-12 11:54:01 +01:00
AllStrLen = AllStrLen - 2
2018-10-23 19:29:19 +02:00
DataString = DataString + AllString [ : AllStrLen ] + TAB_COMMA_SPLIT
2010-03-12 11:54:01 +01:00
# byte value array
2018-10-23 19:29:19 +02:00
if len ( self . _Token ) < = 4 :
while self . _IsToken ( TAB_COMMA_SPLIT ) :
if not self . _GetNextHexNumber ( ) :
2010-03-12 11:54:01 +01:00
raise Warning ( " Invalid Hex number " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if len ( self . _Token ) > 4 :
2010-03-12 11:54:01 +01:00
raise Warning ( " Hex byte(must be 2 digits) too long " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
DataString + = self . _Token
DataString + = TAB_COMMA_SPLIT
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
DataString = DataString . rstrip ( TAB_COMMA_SPLIT )
2009-07-17 11:10:31 +02:00
RegionObj . RegionType = " DATA "
2018-10-23 19:29:19 +02:00
RegionObj . RegionDataList . append ( DataString )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
while self . _IsKeyword ( " DATA " ) :
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Hex byte " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if len ( self . _Token ) > 18 :
2010-03-12 11:54:01 +01:00
raise Warning ( " Hex string can ' t be converted to a valid UINT64 value " , self . FileName , self . CurrentLineNumber )
# convert hex string value to byte hex string array
2018-10-23 19:29:19 +02:00
AllString = self . _Token
2010-03-12 11:54:01 +01:00
AllStrLen = len ( AllString )
DataString = " "
while AllStrLen > 4 :
2018-10-23 19:29:19 +02:00
DataString = DataString + " 0x " + AllString [ AllStrLen - 2 : AllStrLen ] + TAB_COMMA_SPLIT
2010-03-12 11:54:01 +01:00
AllStrLen = AllStrLen - 2
2018-10-23 19:29:19 +02:00
DataString = DataString + AllString [ : AllStrLen ] + TAB_COMMA_SPLIT
2010-03-12 11:54:01 +01:00
# byte value array
2018-10-23 19:29:19 +02:00
if len ( self . _Token ) < = 4 :
while self . _IsToken ( TAB_COMMA_SPLIT ) :
if not self . _GetNextHexNumber ( ) :
2010-03-12 11:54:01 +01:00
raise Warning ( " Invalid Hex number " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if len ( self . _Token ) > 4 :
2010-03-12 11:54:01 +01:00
raise Warning ( " Hex byte(must be 2 digits) too long " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
DataString + = self . _Token
DataString + = TAB_COMMA_SPLIT
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
DataString = DataString . rstrip ( TAB_COMMA_SPLIT )
RegionObj . RegionDataList . append ( DataString )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetFv() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetFv ( self ) :
if not self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
S = self . _Token . upper ( )
if S . startswith ( TAB_SECTION_START ) and not S . startswith ( " [FV. " ) :
2016-04-21 08:50:30 +02:00
self . SectionParser ( S )
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
if not self . _IsToken ( " [FV. " , True ) :
2009-07-17 11:10:31 +02:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
#print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
2018-10-23 19:29:19 +02:00
# % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine:], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
raise Warning ( " Unknown Keyword ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
FvName = self . _GetUiName ( )
2009-07-17 11:10:31 +02:00
self . CurrentFvName = FvName . upper ( )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_SECTION_END ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedBracketClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:21 +02:00
FvObj = FV ( Name = self . CurrentFvName )
2009-07-17 11:10:31 +02:00
self . Profile . FvDict [ self . CurrentFvName ] = FvObj
2018-10-23 19:29:19 +02:00
Status = self . _GetCreateFile ( FvObj )
2009-07-17 11:10:31 +02:00
if not Status :
raise Warning ( " FV name error " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
self . _GetDefineStatements ( FvObj )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
self . _GetAddressStatements ( FvObj )
2009-07-17 11:10:31 +02:00
2009-11-09 12:47:35 +01:00
while True :
2018-10-23 19:29:19 +02:00
self . _GetSetStatements ( FvObj )
2013-11-18 08:41:21 +01:00
2018-10-23 19:29:19 +02:00
if not ( self . _GetBlockStatement ( FvObj ) or self . _GetFvBaseAddress ( FvObj ) or
self . _GetFvForceRebase ( FvObj ) or self . _GetFvAlignment ( FvObj ) or
self . _GetFvAttributes ( FvObj ) or self . _GetFvNameGuid ( FvObj ) or
self . _GetFvExtEntryStatement ( FvObj ) or self . _GetFvNameString ( FvObj ) ) :
2009-11-09 12:47:35 +01:00
break
2015-07-28 07:53:08 +02:00
if FvObj . FvNameString == ' TRUE ' and not FvObj . FvNameGuid :
raise Warning ( " FvNameString found but FvNameGuid was not found " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:22 +02:00
self . _GetAprioriSection ( FvObj )
self . _GetAprioriSection ( FvObj )
2009-07-17 11:10:31 +02:00
while True :
2018-10-23 19:29:19 +02:00
isInf = self . _GetInfStatement ( FvObj )
2018-10-23 19:29:22 +02:00
isFile = self . _GetFileStatement ( FvObj )
2009-07-17 11:10:31 +02:00
if not isInf and not isFile :
break
return True
2018-10-23 19:29:19 +02:00
## _GetFvAlignment() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetFvAlignment ( self , Obj ) :
if not self . _IsKeyword ( " FvAlignment " ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " alignment value " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:20 +02:00
if self . _Token . upper ( ) not in { " 1 " , " 2 " , " 4 " , " 8 " , " 16 " , " 32 " , " 64 " , " 128 " , " 256 " , " 512 " , \
2009-07-17 11:10:31 +02:00
" 1K " , " 2K " , " 4K " , " 8K " , " 16K " , " 32K " , " 64K " , " 128K " , " 256K " , " 512K " , \
" 1M " , " 2M " , " 4M " , " 8M " , " 16M " , " 32M " , " 64M " , " 128M " , " 256M " , " 512M " , \
2018-10-23 19:29:20 +02:00
" 1G " , " 2G " } :
2018-10-23 19:29:19 +02:00
raise Warning ( " Unknown alignment value ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
Obj . FvAlignment = self . _Token
2009-07-17 11:10:31 +02:00
return True
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
## _GetFvBaseAddress() method
2011-08-26 09:46:26 +02:00
#
# Get BaseAddress for FV
#
# @param self The object pointer
# @param Obj for whom FvBaseAddress is got
# @retval True Successfully find a FvBaseAddress statement
# @retval False Not able to find a FvBaseAddress statement
#
2018-10-23 19:29:19 +02:00
def _GetFvBaseAddress ( self , Obj ) :
if not self . _IsKeyword ( " FvBaseAddress " ) :
2011-08-26 09:46:26 +02:00
return False
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2011-08-26 09:46:26 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FV base address value " , self . FileName , self . CurrentLineNumber )
2011-08-26 09:46:26 +02:00
2018-10-23 19:29:19 +02:00
if not BaseAddrValuePattern . match ( self . _Token . upper ( ) ) :
raise Warning ( " Unknown FV base address value ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
Obj . FvBaseAddress = self . _Token
2018-07-05 11:40:04 +02:00
return True
2018-10-23 19:29:19 +02:00
## _GetFvForceRebase() method
2011-10-11 04:49:48 +02:00
#
# Get FvForceRebase for FV
#
# @param self The object pointer
# @param Obj for whom FvForceRebase is got
# @retval True Successfully find a FvForceRebase statement
# @retval False Not able to find a FvForceRebase statement
#
2018-10-23 19:29:19 +02:00
def _GetFvForceRebase ( self , Obj ) :
if not self . _IsKeyword ( " FvForceRebase " ) :
2011-10-11 04:49:48 +02:00
return False
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2011-10-11 04:49:48 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FvForceRebase value " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:20 +02:00
if self . _Token . upper ( ) not in { " TRUE " , " FALSE " , " 0 " , " 0X0 " , " 0X00 " , " 1 " , " 0X1 " , " 0X01 " } :
2018-10-23 19:29:19 +02:00
raise Warning ( " Unknown FvForceRebase value ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:20 +02:00
if self . _Token . upper ( ) in { " TRUE " , " 1 " , " 0X1 " , " 0X01 " } :
2011-10-11 04:49:48 +02:00
Obj . FvForceRebase = True
2018-10-23 19:29:20 +02:00
elif self . _Token . upper ( ) in { " FALSE " , " 0 " , " 0X0 " , " 0X00 " } :
2011-10-11 04:49:48 +02:00
Obj . FvForceRebase = False
else :
Obj . FvForceRebase = None
2018-07-05 11:40:04 +02:00
2011-10-11 04:49:48 +02:00
return True
2011-10-29 08:59:30 +02:00
2018-10-23 19:29:19 +02:00
## _GetFvAttributes() method
2009-07-17 11:10:31 +02:00
#
# Get attributes for FV
#
# @param self The object pointer
# @param Obj for whom attribute is got
# @retval None
#
2018-10-23 19:29:19 +02:00
def _GetFvAttributes ( self , FvObj ) :
2014-01-10 06:25:50 +01:00
IsWordToken = False
2018-10-23 19:29:19 +02:00
while self . _GetNextWord ( ) :
2014-01-10 06:25:50 +01:00
IsWordToken = True
2018-10-23 19:29:19 +02:00
name = self . _Token
2018-10-23 19:29:20 +02:00
if name not in { " ERASE_POLARITY " , " MEMORY_MAPPED " , \
2009-07-17 11:10:31 +02:00
" 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 " , \
2018-10-23 19:29:20 +02:00
" WRITE_POLICY_RELIABLE " , " WEAK_ALIGNMENT " , " FvUsedSizeEnable " } :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2013-11-18 08:41:21 +01:00
return False
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:20 +02:00
if not self . _GetNextToken ( ) or self . _Token . upper ( ) not in { " TRUE " , " FALSE " , " 1 " , " 0 " } :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " TRUE/FALSE (1/0) " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
FvObj . FvAttributeDict [ name ] = self . _Token
2009-07-17 11:10:31 +02:00
2014-01-10 06:25:50 +01:00
return IsWordToken
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
## _GetFvNameGuid() method
2009-07-17 11:10:31 +02:00
#
# Get FV GUID for FV
#
# @param self The object pointer
# @param Obj for whom GUID is got
# @retval None
#
2018-10-23 19:29:19 +02:00
def _GetFvNameGuid ( self , FvObj ) :
if not self . _IsKeyword ( " FvNameGuid " ) :
2013-11-18 08:41:21 +01:00
return False
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextGuid ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " GUID value " , self . FileName , self . CurrentLineNumber )
2020-07-14 07:30:40 +02:00
if self . _Token in GlobalData . gGuidDict :
self . _Token = GuidStructureStringToGuidString ( GlobalData . gGuidDict [ self . _Token ] ) . upper ( )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
FvObj . FvNameGuid = self . _Token
2009-07-17 11:10:31 +02:00
2013-11-18 08:41:21 +01:00
return True
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
def _GetFvNameString ( self , FvObj ) :
if not self . _IsKeyword ( " FvNameString " ) :
2015-07-28 07:53:08 +02:00
return False
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2015-07-28 07:53:08 +02:00
2018-10-23 19:29:23 +02:00
if not self . _GetNextToken ( ) or self . _Token . upper ( ) not in { ' TRUE ' , ' FALSE ' } :
raise Warning . Expected ( " TRUE or FALSE for FvNameString " , self . FileName , self . CurrentLineNumber )
2015-07-28 07:53:08 +02:00
2018-10-23 19:29:19 +02:00
FvObj . FvNameString = self . _Token
2015-07-28 07:53:08 +02:00
return True
2018-10-23 19:29:19 +02:00
def _GetFvExtEntryStatement ( self , FvObj ) :
if not ( self . _IsKeyword ( " FV_EXT_ENTRY " ) or self . _IsKeyword ( " FV_EXT_ENTRY_TYPE " ) ) :
2009-11-09 12:47:35 +01:00
return False
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( " TYPE " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' TYPE ' " , self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextHexNumber ( ) and not self . _GetNextDecimalNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Hex FV extension entry type value At Line " , self . FileName , self . CurrentLineNumber )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:19 +02:00
FvObj . FvExtEntryTypeValue . append ( self . _Token )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:23 +02:00
if not self . _IsKeyword ( " FILE " ) and not self . _IsKeyword ( " DATA " ) :
raise Warning . Expected ( " ' FILE ' or ' DATA ' " , self . FileName , self . CurrentLineNumber )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:19 +02:00
FvObj . FvExtEntryType . append ( self . _Token )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:19 +02:00
if self . _Token == ' DATA ' :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Hex byte " , self . FileName , self . CurrentLineNumber )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:19 +02:00
if len ( self . _Token ) > 4 :
2009-11-09 12:47:35 +01:00
raise Warning ( " Hex byte(must be 2 digits) too long " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
DataString = self . _Token
DataString + = TAB_COMMA_SPLIT
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:19 +02:00
while self . _IsToken ( TAB_COMMA_SPLIT ) :
if not self . _GetNextHexNumber ( ) :
2009-11-09 12:47:35 +01:00
raise Warning ( " Invalid Hex number " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if len ( self . _Token ) > 4 :
2009-11-09 12:47:35 +01:00
raise Warning ( " Hex byte(must be 2 digits) too long " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
DataString + = self . _Token
DataString + = TAB_COMMA_SPLIT
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:19 +02:00
DataString = DataString . rstrip ( TAB_COMMA_SPLIT )
2018-05-18 02:06:52 +02:00
FvObj . FvExtEntryData . append ( DataString )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:19 +02:00
if self . _Token == ' FILE ' :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FV Extension Entry file path At Line " , self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
FvObj . FvExtEntryData . append ( self . _Token )
2009-11-09 12:47:35 +01:00
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-11-09 12:47:35 +01:00
return True
2018-10-23 19:29:19 +02:00
## _GetAprioriSection() method
2009-07-17 11:10:31 +02:00
#
# Get token statements
#
# @param self The object pointer
# @param FvObj for whom apriori is got
# @retval True Successfully find apriori statement
# @retval False Not able to find apriori statement
#
2018-10-23 19:29:22 +02:00
def _GetAprioriSection ( self , FvObj ) :
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( " APRIORI " ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( " PEI " ) and not self . _IsKeyword ( " DXE " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Apriori file type " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
AprType = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
AprSectionObj = AprioriSection ( )
2009-07-17 11:10:31 +02:00
AprSectionObj . AprioriType = AprType
2018-10-23 19:29:19 +02:00
self . _GetDefineStatements ( AprSectionObj )
2009-07-17 11:10:31 +02:00
while True :
2018-10-23 19:29:19 +02:00
IsInf = self . _GetInfStatement ( AprSectionObj )
IsFile = self . _GetFileStatement ( AprSectionObj )
2009-07-17 11:10:31 +02:00
if not IsInf and not IsFile :
break
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
FvObj . AprioriSectionList . append ( AprSectionObj )
return True
2018-10-23 19:29:19 +02:00
def _ParseInfStatement ( self ) :
if not self . _IsKeyword ( " INF " ) :
2015-12-07 09:27:53 +01:00
return None
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
ffsInf = FfsInfStatement ( )
self . _GetInfOptions ( ffsInf )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " INF file path " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
ffsInf . InfFileName = self . _Token
2018-02-07 07:41:11 +01:00
if not ffsInf . InfFileName . endswith ( ' .inf ' ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " .inf file path " , self . FileName , self . CurrentLineNumber )
2012-04-10 09:18:20 +02:00
ffsInf . CurrentLineNum = self . CurrentLineNumber
2018-10-23 19:29:19 +02:00
ffsInf . CurrentLineContent = self . _CurrentLine ( )
2012-04-10 09:18:20 +02:00
2014-08-28 15:53:34 +02:00
#Replace $(SAPCE) with real space
ffsInf . InfFileName = ffsInf . InfFileName . replace ( ' $(SPACE) ' , ' ' )
2018-10-23 19:29:19 +02:00
if ffsInf . InfFileName . replace ( TAB_WORKSPACE , ' ' ) . find ( ' $ ' ) == - 1 :
2010-07-21 04:46:15 +02:00
#do case sensitive check for file path
ErrorCode , ErrorInfo = PathClass ( NormPath ( ffsInf . InfFileName ) , GenFdsGlobalVariable . WorkSpaceDir ) . Validate ( )
if ErrorCode != 0 :
EdkLogger . error ( " GenFds " , ErrorCode , ExtraData = ErrorInfo )
2009-07-17 11:10:31 +02:00
2018-11-16 03:12:15 +01:00
NewFileName = ffsInf . InfFileName
if ffsInf . OverrideGuid :
NewFileName = ProcessDuplicatedInf ( PathClass ( ffsInf . InfFileName , GenFdsGlobalVariable . WorkSpaceDir ) , ffsInf . OverrideGuid , GenFdsGlobalVariable . WorkSpaceDir ) . Path
if not NewFileName in self . Profile . InfList :
self . Profile . InfList . append ( NewFileName )
2011-12-07 07:19:28 +01:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
self . Profile . InfFileLineList . append ( FileLineTuple )
2016-07-20 07:58:03 +02:00
if ffsInf . UseArch :
if ffsInf . UseArch not in self . Profile . InfDict :
self . Profile . InfDict [ ffsInf . UseArch ] = [ ffsInf . InfFileName ]
else :
self . Profile . InfDict [ ffsInf . UseArch ] . append ( ffsInf . InfFileName )
else :
self . Profile . InfDict [ ' ArchTBD ' ] . append ( ffsInf . InfFileName )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsToken ( TAB_VALUE_SPLIT ) :
if self . _IsKeyword ( ' RELOCS_STRIPPED ' ) :
2009-07-17 11:10:31 +02:00
ffsInf . KeepReloc = False
2018-10-23 19:29:19 +02:00
elif self . _IsKeyword ( ' RELOCS_RETAINED ' ) :
2009-07-17 11:10:31 +02:00
ffsInf . KeepReloc = True
else :
2018-10-23 19:29:19 +02:00
raise Warning ( " Unknown reloc strip flag ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
2015-12-07 09:27:53 +01:00
return ffsInf
2018-10-23 19:29:19 +02:00
## _GetInfStatement() method
2015-12-07 09:27:53 +01:00
#
# Get INF statements
#
# @param self The object pointer
# @param Obj for whom inf statement is got
# @retval True Successfully find inf statement
# @retval False Not able to find inf statement
#
2018-10-23 19:29:19 +02:00
def _GetInfStatement ( self , Obj , ForCapsule = False ) :
ffsInf = self . _ParseInfStatement ( )
2015-12-07 09:27:53 +01:00
if not ffsInf :
return False
2009-07-17 11:10:31 +02:00
if ForCapsule :
2018-10-23 19:29:19 +02:00
myCapsuleFfs = CapsuleFfs ( )
myCapsuleFfs . Ffs = ffsInf
Obj . CapsuleDataList . append ( myCapsuleFfs )
2009-07-17 11:10:31 +02:00
else :
Obj . FfsList . append ( ffsInf )
return True
2018-10-23 19:29:19 +02:00
## _GetInfOptions() method
2009-07-17 11:10:31 +02:00
#
# Get options for INF
#
# @param self The object pointer
# @param FfsInfObj for whom option is got
#
2018-10-23 19:29:19 +02:00
def _GetInfOptions ( self , FfsInfObj ) :
if self . _IsKeyword ( " FILE_GUID " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextGuid ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " GUID value " , self . FileName , self . CurrentLineNumber )
2020-07-14 07:30:40 +02:00
if self . _Token in GlobalData . gGuidDict :
self . _Token = GuidStructureStringToGuidString ( GlobalData . gGuidDict [ self . _Token ] ) . upper ( )
2018-10-23 19:29:19 +02:00
FfsInfObj . OverrideGuid = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " RuleOverride " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Rule name " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FfsInfObj . Rule = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " VERSION " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Version " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _GetStringData ( ) :
FfsInfObj . Version = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( BINARY_FILE_TYPE_UI ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " UI name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _GetStringData ( ) :
FfsInfObj . Ui = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " USE " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ARCH name " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FfsInfObj . UseArch = self . _Token
2009-07-17 11:10:31 +02:00
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if self . _GetNextToken ( ) :
p = compile ( r ' ([a-zA-Z0-9 \ -]+| \ $ \ (TARGET \ )| \ *)_([a-zA-Z0-9 \ -]+| \ $ \ (TOOL_CHAIN_TAG \ )| \ *)_([a-zA-Z0-9 \ -]+| \ $ \ (ARCH \ )) ' )
if p . match ( self . _Token ) and p . match ( self . _Token ) . span ( ) [ 1 ] == len ( self . _Token ) :
FfsInfObj . KeyStringList . append ( self . _Token )
if not self . _IsToken ( TAB_COMMA_SPLIT ) :
2009-07-17 11:10:31 +02:00
return
else :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
return
2018-10-23 19:29:19 +02:00
while self . _GetNextToken ( ) :
if not p . match ( self . _Token ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " KeyString \" Target_Tag_Arch \" " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FfsInfObj . KeyStringList . append ( self . _Token )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_COMMA_SPLIT ) :
2009-07-17 11:10:31 +02:00
break
2018-10-23 19:29:19 +02:00
## _GetFileStatement() method
2009-07-17 11:10:31 +02:00
#
# Get FILE statements
#
# @param self The object pointer
# @param Obj for whom FILE statement is got
# @retval True Successfully find FILE statement
# @retval False Not able to find FILE statement
#
2018-10-23 19:29:22 +02:00
def _GetFileStatement ( self , Obj , ForCapsule = False ) :
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( " FILE " ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
if not self . _GetNextWord ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FFS type " , self . FileName , self . CurrentLineNumber )
2011-09-18 14:17:25 +02:00
2018-10-23 19:29:19 +02:00
if ForCapsule and self . _Token == ' DATA ' :
self . _UndoToken ( )
self . _UndoToken ( )
2011-09-18 14:17:25 +02:00
return False
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
FfsFileObj = FileStatement ( )
FfsFileObj . FvFileType = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextGuid ( ) :
if not self . _GetNextWord ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " File GUID " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if self . _Token == ' PCD ' :
if not self . _IsToken ( " ( " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' ( ' " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
PcdPair = self . _GetNextPcdSettings ( )
if not self . _IsToken ( " ) " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' ) ' " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
self . _Token = ' PCD( ' + PcdPair [ 1 ] + TAB_SPLIT + PcdPair [ 0 ] + ' ) '
2018-07-05 11:40:04 +02:00
2020-07-14 07:30:40 +02:00
if self . _Token in GlobalData . gGuidDict :
self . _Token = GuidStructureStringToGuidString ( GlobalData . gGuidDict [ self . _Token ] ) . upper ( )
2018-10-23 19:29:19 +02:00
FfsFileObj . NameGuid = self . _Token
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:22 +02:00
self . _GetFilePart ( FfsFileObj )
2009-07-17 11:10:31 +02:00
if ForCapsule :
2018-10-23 19:29:19 +02:00
capsuleFfs = CapsuleFfs ( )
2009-07-17 11:10:31 +02:00
capsuleFfs . Ffs = FfsFileObj
Obj . CapsuleDataList . append ( capsuleFfs )
else :
Obj . FfsList . append ( FfsFileObj )
return True
2018-10-23 19:29:19 +02:00
## _FileCouldHaveRelocFlag() method
2009-07-17 11:10:31 +02:00
#
# Check whether reloc strip flag can be set for a file type.
#
# @param FileType The file type to check with
# @retval True This type could have relocation strip flag
# @retval False No way to have it
#
2018-03-30 02:19:32 +02:00
@staticmethod
2018-10-23 19:29:19 +02:00
def _FileCouldHaveRelocFlag ( FileType ) :
2019-01-03 13:06:17 +01:00
if FileType in { SUP_MODULE_SEC , SUP_MODULE_PEI_CORE , SUP_MODULE_PEIM , SUP_MODULE_MM_CORE_STANDALONE , ' PEI_DXE_COMBO ' } :
2009-07-17 11:10:31 +02:00
return True
else :
return False
2018-10-23 19:29:19 +02:00
## _SectionCouldHaveRelocFlag() method
2009-07-17 11:10:31 +02:00
#
# Check whether reloc strip flag can be set for a section type.
#
# @param SectionType The section type to check with
# @retval True This type could have relocation strip flag
# @retval False No way to have it
#
2018-03-30 02:19:32 +02:00
@staticmethod
2018-10-23 19:29:19 +02:00
def _SectionCouldHaveRelocFlag ( SectionType ) :
2018-10-23 19:29:20 +02:00
if SectionType in { BINARY_FILE_TYPE_TE , BINARY_FILE_TYPE_PE32 } :
2009-07-17 11:10:31 +02:00
return True
else :
return False
2018-10-23 19:29:19 +02:00
## _GetFilePart() method
2009-07-17 11:10:31 +02:00
#
# Get components for FILE statement
#
# @param self The object pointer
# @param FfsFileObj for whom component is got
#
2018-10-23 19:29:22 +02:00
def _GetFilePart ( self , FfsFileObj ) :
2018-10-23 19:29:19 +02:00
self . _GetFileOpts ( FfsFileObj )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
if self . _IsKeyword ( ' RELOCS_STRIPPED ' ) or self . _IsKeyword ( ' RELOCS_RETAINED ' ) :
if self . _FileCouldHaveRelocFlag ( FfsFileObj . FvFileType ) :
if self . _Token == ' RELOCS_STRIPPED ' :
2013-08-23 04:18:16 +02:00
FfsFileObj . KeepReloc = False
else :
FfsFileObj . KeepReloc = True
else :
raise Warning ( " File type %s could not have reloc strip flag %d " % ( FfsFileObj . FvFileType , self . CurrentLineNumber ) , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " File name or section data " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _Token == BINARY_FILE_TYPE_FV :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FV name " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FfsFileObj . FvName = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
elif self . _Token == " FD " :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FD name " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FfsFileObj . FdName = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:20 +02:00
elif self . _Token in { TAB_DEFINE , " APRIORI " , " SECTION " } :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2018-10-23 19:29:22 +02:00
self . _GetSectionData ( FfsFileObj )
2016-03-21 12:27:35 +01:00
elif hasattr ( FfsFileObj , ' FvFileType ' ) and FfsFileObj . FvFileType == ' RAW ' :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2018-10-23 19:29:22 +02:00
self . _GetRAWData ( FfsFileObj )
2016-03-21 12:27:35 +01:00
2009-07-17 11:10:31 +02:00
else :
2012-04-10 09:18:20 +02:00
FfsFileObj . CurrentLineNum = self . CurrentLineNumber
2018-10-23 19:29:19 +02:00
FfsFileObj . CurrentLineContent = self . _CurrentLine ( )
FfsFileObj . FileName = self . _Token . replace ( ' $(SPACE) ' , ' ' )
self . _VerifyFile ( FfsFileObj . FileName )
2011-10-29 08:59:30 +02:00
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetRAWData() method
2016-03-21 12:27:35 +01:00
#
# Get RAW data for FILE statement
#
# @param self The object pointer
# @param FfsFileObj for whom section is got
#
2018-10-23 19:29:22 +02:00
def _GetRAWData ( self , FfsFileObj ) :
2016-03-21 12:27:35 +01:00
FfsFileObj . FileName = [ ]
2016-04-01 09:20:51 +02:00
FfsFileObj . SubAlignment = [ ]
2016-03-21 12:27:35 +01:00
while True :
AlignValue = None
2018-10-23 19:29:19 +02:00
if self . _GetAlignment ( ) :
if self . _Token not in ALIGNMENTS :
raise Warning ( " Incorrect alignment ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
2016-11-09 11:18:01 +01:00
#For FFS, Auto is default option same to ""
2018-10-23 19:29:19 +02:00
if not self . _Token == " Auto " :
AlignValue = self . _Token
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Filename value " , self . FileName , self . CurrentLineNumber )
2016-03-21 12:27:35 +01:00
2018-10-23 19:29:19 +02:00
FileName = self . _Token . replace ( ' $(SPACE) ' , ' ' )
2018-10-23 19:29:24 +02:00
if FileName == T_CHAR_BRACE_R :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Filename value " , self . FileName , self . CurrentLineNumber )
2016-03-21 12:27:35 +01:00
2018-10-23 19:29:19 +02:00
self . _VerifyFile ( FileName )
2016-03-21 12:27:35 +01:00
File = PathClass ( NormPath ( FileName ) , GenFdsGlobalVariable . WorkSpaceDir )
FfsFileObj . FileName . append ( File . Path )
2016-04-01 09:20:51 +02:00
FfsFileObj . SubAlignment . append ( AlignValue )
2016-03-21 12:27:35 +01:00
2018-10-23 19:29:24 +02:00
if self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2016-03-21 12:27:35 +01:00
break
2016-04-01 09:20:51 +02:00
if len ( FfsFileObj . SubAlignment ) == 1 :
FfsFileObj . SubAlignment = FfsFileObj . SubAlignment [ 0 ]
2016-03-21 12:27:35 +01:00
if len ( FfsFileObj . FileName ) == 1 :
FfsFileObj . FileName = FfsFileObj . FileName [ 0 ]
2018-10-23 19:29:19 +02:00
## _GetFileOpts() method
2009-07-17 11:10:31 +02:00
#
# Get options for FILE statement
#
# @param self The object pointer
# @param FfsFileObj for whom options is got
#
2018-10-23 19:29:19 +02:00
def _GetFileOpts ( self , FfsFileObj ) :
if self . _GetNextToken ( ) :
if TokenFindPattern . match ( self . _Token ) :
FfsFileObj . KeyStringList . append ( self . _Token )
if self . _IsToken ( TAB_COMMA_SPLIT ) :
while self . _GetNextToken ( ) :
if not TokenFindPattern . match ( self . _Token ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " KeyString \" Target_Tag_Arch \" " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FfsFileObj . KeyStringList . append ( self . _Token )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_COMMA_SPLIT ) :
2009-07-17 11:10:31 +02:00
break
else :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " FIXED " , True ) :
2009-07-17 11:10:31 +02:00
FfsFileObj . Fixed = True
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " CHECKSUM " , True ) :
2009-07-17 11:10:31 +02:00
FfsFileObj . CheckSum = True
2018-10-23 19:29:19 +02:00
if self . _GetAlignment ( ) :
if self . _Token not in ALIGNMENTS :
raise Warning ( " Incorrect alignment ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
2010-06-28 11:33:10 +02:00
#For FFS, Auto is default option same to ""
2018-10-23 19:29:19 +02:00
if not self . _Token == " Auto " :
FfsFileObj . Alignment = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetAlignment() method
2009-07-17 11:10:31 +02:00
#
# Return the alignment value
#
# @param self The object pointer
# @retval True Successfully find alignment
# @retval False Not able to find alignment
#
2018-10-23 19:29:19 +02:00
def _GetAlignment ( self ) :
if self . _IsKeyword ( " Align " , True ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " alignment value " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
return True
return False
2018-10-23 19:29:22 +02:00
## _GetSectionData() method
2009-07-17 11:10:31 +02:00
#
# Get section data for FILE statement
#
# @param self The object pointer
# @param FfsFileObj for whom section is got
#
2018-10-23 19:29:22 +02:00
def _GetSectionData ( self , FfsFileObj ) :
2018-10-23 19:29:19 +02:00
self . _GetDefineStatements ( FfsFileObj )
2009-07-17 11:10:31 +02:00
while True :
2018-10-23 19:29:22 +02:00
IsLeafSection = self . _GetLeafSection ( FfsFileObj )
2018-10-23 19:29:19 +02:00
IsEncapSection = self . _GetEncapsulationSec ( FfsFileObj )
2009-07-17 11:10:31 +02:00
if not IsLeafSection and not IsEncapSection :
break
2018-10-23 19:29:19 +02:00
## _GetLeafSection() method
2009-07-17 11:10:31 +02:00
#
# Get leaf section for Obj
#
# @param self The object pointer
# @param Obj for whom leaf section is got
# @retval True Successfully find section statement
# @retval False Not able to find section statement
#
2018-10-23 19:29:22 +02:00
def _GetLeafSection ( self , Obj ) :
2009-07-17 11:10:31 +02:00
OldPos = self . GetFileBufferPos ( )
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( " SECTION " ) :
2009-07-17 11:10:31 +02:00
if len ( Obj . SectionList ) == 0 :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " SECTION " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
else :
return False
AlignValue = None
2018-10-23 19:29:19 +02:00
if self . _GetAlignment ( ) :
if self . _Token not in ALIGNMENTS :
raise Warning ( " Incorrect alignment ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
AlignValue = self . _Token
2009-07-17 11:10:31 +02:00
BuildNum = None
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " BUILD_NUM " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Build number value " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
BuildNum = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " VERSION " ) :
2010-03-01 00:39:39 +01:00
if AlignValue == ' Auto ' :
raise Warning ( " Auto alignment can only be used in PE32 or TE section " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " version " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
VerSectionObj = VerSection ( )
2009-07-17 11:10:31 +02:00
VerSectionObj . Alignment = AlignValue
VerSectionObj . BuildNum = BuildNum
2018-10-23 19:29:19 +02:00
if self . _GetStringData ( ) :
VerSectionObj . StringData = self . _Token
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
VerSectionObj . FileName = self . _Token
2009-07-17 11:10:31 +02:00
Obj . SectionList . append ( VerSectionObj )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
elif self . _IsKeyword ( BINARY_FILE_TYPE_UI ) :
2010-03-01 00:39:39 +01:00
if AlignValue == ' Auto ' :
raise Warning ( " Auto alignment can only be used in PE32 or TE section " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " UI " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
UiSectionObj = UiSection ( )
2009-07-17 11:10:31 +02:00
UiSectionObj . Alignment = AlignValue
2018-10-23 19:29:19 +02:00
if self . _GetStringData ( ) :
UiSectionObj . StringData = self . _Token
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
UiSectionObj . FileName = self . _Token
2009-07-17 11:10:31 +02:00
Obj . SectionList . append ( UiSectionObj )
2018-10-23 19:29:19 +02:00
elif self . _IsKeyword ( " FV_IMAGE " ) :
2010-03-01 00:39:39 +01:00
if AlignValue == ' Auto ' :
raise Warning ( " Auto alignment can only be used in PE32 or TE section " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FV name or FV file path " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
FvName = self . _Token
2009-07-17 11:10:31 +02:00
FvObj = None
2018-10-23 19:29:19 +02:00
if self . _IsToken ( " { " ) :
FvObj = FV ( )
2009-07-17 11:10:31 +02:00
FvObj . UiFvName = FvName . upper ( )
2018-10-23 19:29:19 +02:00
self . _GetDefineStatements ( FvObj )
2018-10-23 19:29:22 +02:00
2018-10-23 19:29:19 +02:00
self . _GetBlockStatement ( FvObj )
self . _GetSetStatements ( FvObj )
self . _GetFvAlignment ( FvObj )
self . _GetFvAttributes ( FvObj )
2009-07-17 11:10:31 +02:00
while True :
2018-10-23 19:29:19 +02:00
IsInf = self . _GetInfStatement ( FvObj )
2018-10-23 19:29:22 +02:00
IsFile = self . _GetFileStatement ( FvObj )
2009-07-17 11:10:31 +02:00
if not IsInf and not IsFile :
break
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
FvImageSectionObj = FvImageSection ( )
2009-07-17 11:10:31 +02:00
FvImageSectionObj . Alignment = AlignValue
2018-03-26 22:25:43 +02:00
if FvObj is not None :
2009-07-17 11:10:31 +02:00
FvImageSectionObj . Fv = FvObj
FvImageSectionObj . FvName = None
else :
FvImageSectionObj . FvName = FvName . upper ( )
FvImageSectionObj . FvFileName = FvName
Obj . SectionList . append ( FvImageSectionObj )
2018-10-23 19:29:19 +02:00
elif self . _IsKeyword ( " PEI_DEPEX_EXP " ) or self . _IsKeyword ( " DXE_DEPEX_EXP " ) or self . _IsKeyword ( " SMM_DEPEX_EXP " ) :
2010-03-01 00:39:39 +01:00
if AlignValue == ' Auto ' :
raise Warning ( " Auto alignment can only be used in PE32 or TE section " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
DepexSectionObj = DepexSection ( )
2009-07-17 11:10:31 +02:00
DepexSectionObj . Alignment = AlignValue
2018-10-23 19:29:19 +02:00
DepexSectionObj . DepexType = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:24 +02:00
if not self . _SkipToToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Depex expression ending ' } ' " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:24 +02:00
DepexSectionObj . Expression = self . _SkippedChars . rstrip ( T_CHAR_BRACE_R )
2009-07-17 11:10:31 +02:00
Obj . SectionList . append ( DepexSectionObj )
else :
2018-10-23 19:29:19 +02:00
if not self . _GetNextWord ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " section type " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
# Encapsulation section appear, UndoToken and return
2018-10-23 19:29:19 +02:00
if self . _Token == " COMPRESS " or self . _Token == " GUIDED " :
2009-07-17 11:10:31 +02:00
self . SetFileBufferPos ( OldPos )
return False
2018-10-23 19:29:20 +02:00
if self . _Token not in { " COMPAT16 " , BINARY_FILE_TYPE_PE32 , BINARY_FILE_TYPE_PIC , BINARY_FILE_TYPE_TE , " FV_IMAGE " , " RAW " , BINARY_FILE_TYPE_DXE_DEPEX , \
BINARY_FILE_TYPE_UI , " VERSION " , BINARY_FILE_TYPE_PEI_DEPEX , " SUBTYPE_GUID " , BINARY_FILE_TYPE_SMM_DEPEX } :
2018-10-23 19:29:19 +02:00
raise Warning ( " Unknown section type ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
if AlignValue == ' Auto ' and ( not self . _Token == BINARY_FILE_TYPE_PE32 ) and ( not self . _Token == BINARY_FILE_TYPE_TE ) :
2010-03-01 00:39:39 +01:00
raise Warning ( " Auto alignment can only be used in PE32 or TE section " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
# DataSection
2018-10-23 19:29:19 +02:00
DataSectionObj = DataSection ( )
2009-07-17 11:10:31 +02:00
DataSectionObj . Alignment = AlignValue
2018-10-23 19:29:19 +02:00
DataSectionObj . SecType = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( ' RELOCS_STRIPPED ' ) or self . _IsKeyword ( ' RELOCS_RETAINED ' ) :
if self . _FileCouldHaveRelocFlag ( Obj . FvFileType ) and self . _SectionCouldHaveRelocFlag ( DataSectionObj . SecType ) :
if self . _Token == ' RELOCS_STRIPPED ' :
2009-07-17 11:10:31 +02:00
DataSectionObj . KeepReloc = False
else :
DataSectionObj . KeepReloc = True
else :
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 )
2018-10-23 19:29:19 +02:00
if self . _IsToken ( TAB_EQUAL_SPLIT ) :
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " section file path " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
DataSectionObj . SectFileName = self . _Token
self . _VerifyFile ( DataSectionObj . SectFileName )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
if not self . _GetCglSection ( DataSectionObj ) :
2009-07-17 11:10:31 +02:00
return False
Obj . SectionList . append ( DataSectionObj )
return True
2018-10-23 19:29:19 +02:00
## _VerifyFile
2014-01-10 06:25:50 +01:00
#
# Check if file exists or not:
# If current phase if GenFds, the file must exist;
# If current phase is AutoGen and the file is not in $(OUTPUT_DIRECTORY), the file must exist
# @param FileName: File path to be verified.
#
2018-10-23 19:29:19 +02:00
def _VerifyFile ( self , FileName ) :
if FileName . replace ( TAB_WORKSPACE , ' ' ) . find ( ' $ ' ) != - 1 :
2014-01-10 06:25:50 +01:00
return
2018-10-23 19:29:19 +02:00
if not GlobalData . gAutoGenPhase or not self . _GetMacroValue ( TAB_DSC_DEFINES_OUTPUT_DIRECTORY ) in FileName :
2014-01-10 06:25:50 +01:00
ErrorCode , ErrorInfo = PathClass ( NormPath ( FileName ) , GenFdsGlobalVariable . WorkSpaceDir ) . Validate ( )
if ErrorCode != 0 :
EdkLogger . error ( " GenFds " , ErrorCode , ExtraData = ErrorInfo )
2018-10-23 19:29:19 +02:00
## _GetCglSection() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetCglSection ( self , Obj , AlignValue = None ) :
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " COMPRESS " ) :
2009-07-17 11:10:31 +02:00
type = " PI_STD "
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " PI_STD " ) or self . _IsKeyword ( " PI_NONE " ) :
type = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
CompressSectionObj = CompressSection ( )
2009-07-17 11:10:31 +02:00
CompressSectionObj . Alignment = AlignValue
CompressSectionObj . CompType = type
# Recursive sections...
while True :
2018-10-23 19:29:19 +02:00
IsLeafSection = self . _GetLeafSection ( CompressSectionObj )
IsEncapSection = self . _GetEncapsulationSec ( CompressSectionObj )
2009-07-17 11:10:31 +02:00
if not IsLeafSection and not IsEncapSection :
break
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
Obj . SectionList . append ( CompressSectionObj )
return True
2018-10-23 19:29:19 +02:00
elif self . _IsKeyword ( " GUIDED " ) :
2009-07-17 11:10:31 +02:00
GuidValue = None
2018-10-23 19:29:19 +02:00
if self . _GetNextGuid ( ) :
2020-07-14 07:30:40 +02:00
if self . _Token in GlobalData . gGuidDict :
self . _Token = GuidStructureStringToGuidString ( GlobalData . gGuidDict [ self . _Token ] ) . upper ( )
2018-10-23 19:29:19 +02:00
GuidValue = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
AttribDict = self . _GetGuidAttrib ( )
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
GuidSectionObj = GuidSection ( )
2009-07-17 11:10:31 +02:00
GuidSectionObj . Alignment = AlignValue
GuidSectionObj . NameGuid = GuidValue
GuidSectionObj . SectionType = " GUIDED "
GuidSectionObj . ProcessRequired = AttribDict [ " PROCESSING_REQUIRED " ]
GuidSectionObj . AuthStatusValid = AttribDict [ " AUTH_STATUS_VALID " ]
2012-05-23 10:27:14 +02:00
GuidSectionObj . ExtraHeaderSize = AttribDict [ " EXTRA_HEADER_SIZE " ]
2009-07-17 11:10:31 +02:00
# Recursive sections...
while True :
2018-10-23 19:29:19 +02:00
IsLeafSection = self . _GetLeafSection ( GuidSectionObj )
IsEncapSection = self . _GetEncapsulationSec ( GuidSectionObj )
2009-07-17 11:10:31 +02:00
if not IsLeafSection and not IsEncapSection :
break
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
Obj . SectionList . append ( GuidSectionObj )
return True
return False
2018-10-23 19:29:19 +02:00
## _GetGuidAttri() method
2009-07-17 11:10:31 +02:00
#
# Get attributes for GUID section
#
# @param self The object pointer
# @retval AttribDict Dictionary of key-value pair of section attributes
#
2018-10-23 19:29:19 +02:00
def _GetGuidAttrib ( self ) :
2009-07-17 11:10:31 +02:00
AttribDict = { }
2010-07-21 04:46:15 +02:00
AttribDict [ " PROCESSING_REQUIRED " ] = " NONE "
AttribDict [ " AUTH_STATUS_VALID " ] = " NONE "
2012-05-23 10:27:14 +02:00
AttribDict [ " EXTRA_HEADER_SIZE " ] = - 1
2018-10-23 19:29:19 +02:00
while self . _IsKeyword ( " PROCESSING_REQUIRED " ) or self . _IsKeyword ( " AUTH_STATUS_VALID " ) \
or self . _IsKeyword ( " EXTRA_HEADER_SIZE " ) :
AttribKey = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " TRUE(1)/FALSE(0)/Number " , self . FileName , self . CurrentLineNumber )
2012-05-23 10:27:14 +02:00
elif AttribKey == " EXTRA_HEADER_SIZE " :
Base = 10
2018-10-23 19:29:19 +02:00
if self . _Token [ 0 : 2 ] . upper ( ) == " 0X " :
2012-05-23 10:27:14 +02:00
Base = 16
try :
2018-10-23 19:29:19 +02:00
AttribDict [ AttribKey ] = int ( self . _Token , Base )
2012-05-23 10:27:14 +02:00
continue
except ValueError :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Number " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:20 +02:00
elif self . _Token . upper ( ) not in { " TRUE " , " FALSE " , " 1 " , " 0 " } :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " TRUE/FALSE (1/0) " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
AttribDict [ AttribKey ] = self . _Token
2009-07-17 11:10:31 +02:00
return AttribDict
2018-10-23 19:29:19 +02:00
## _GetEncapsulationSec() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetEncapsulationSec ( self , FfsFileObj ) :
2009-07-17 11:10:31 +02:00
OldPos = self . GetFileBufferPos ( )
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( " SECTION " ) :
2009-07-17 11:10:31 +02:00
if len ( FfsFileObj . SectionList ) == 0 :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " SECTION " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
else :
return False
AlignValue = None
2018-10-23 19:29:19 +02:00
if self . _GetAlignment ( ) :
if self . _Token not in ALIGNMENT_NOAUTO :
raise Warning ( " Incorrect alignment ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
AlignValue = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetCglSection ( FfsFileObj , AlignValue ) :
2009-07-17 11:10:31 +02:00
self . SetFileBufferPos ( OldPos )
return False
else :
return True
2018-10-23 19:29:19 +02:00
def _GetFmp ( self ) :
if not self . _GetNextToken ( ) :
2015-06-23 08:46:01 +02:00
return False
2018-10-23 19:29:19 +02:00
S = self . _Token . upper ( )
if S . startswith ( TAB_SECTION_START ) and not S . startswith ( " [FMPPAYLOAD. " ) :
2016-04-21 08:50:30 +02:00
self . SectionParser ( S )
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2015-06-23 08:46:01 +02:00
return False
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
self . _SkipToToken ( " [FMPPAYLOAD. " , True )
FmpUiName = self . _GetUiName ( ) . upper ( )
2015-06-23 08:46:01 +02:00
if FmpUiName in self . Profile . FmpPayloadDict :
raise Warning ( " Duplicated FMP UI name found: %s " % FmpUiName , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FmpData = CapsulePayload ( )
2015-06-23 08:46:01 +02:00
FmpData . UiName = FmpUiName
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_SECTION_END ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedBracketClose ( self . FileName , self . CurrentLineNumber )
2015-06-23 08:46:01 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2015-06-23 08:46:01 +02:00
raise Warning ( " The FMP payload section is empty! " , self . FileName , self . CurrentLineNumber )
2016-08-15 07:52:12 +02:00
FmpKeyList = [ ' IMAGE_HEADER_INIT_VERSION ' , ' IMAGE_TYPE_ID ' , ' IMAGE_INDEX ' , ' HARDWARE_INSTANCE ' , ' CERTIFICATE_GUID ' , ' MONOTONIC_COUNT ' ]
2018-10-23 19:29:19 +02:00
while self . _Token in FmpKeyList :
Name = self . _Token
2015-06-23 08:46:01 +02:00
FmpKeyList . remove ( Name )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2015-06-23 08:46:01 +02:00
if Name == ' IMAGE_TYPE_ID ' :
2018-10-23 19:29:19 +02:00
if not self . _GetNextGuid ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " GUID value for IMAGE_TYPE_ID. " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FmpData . ImageTypeId = self . _Token
2016-08-15 07:52:12 +02:00
elif Name == ' CERTIFICATE_GUID ' :
2018-10-23 19:29:19 +02:00
if not self . _GetNextGuid ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " GUID value for CERTIFICATE_GUID. " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FmpData . Certificate_Guid = self . _Token
if UUID ( FmpData . Certificate_Guid ) != EFI_CERT_TYPE_RSA2048_SHA256_GUID and UUID ( FmpData . Certificate_Guid ) != EFI_CERT_TYPE_PKCS7_GUID :
2016-08-15 07:52:12 +02:00
raise Warning ( " Only support EFI_CERT_TYPE_RSA2048_SHA256_GUID or EFI_CERT_TYPE_PKCS7_GUID for CERTIFICATE_GUID. " , self . FileName , self . CurrentLineNumber )
2015-06-23 08:46:01 +02:00
else :
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " value of %s " % Name , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Value = self . _Token
2015-06-23 08:46:01 +02:00
if Name == ' IMAGE_HEADER_INIT_VERSION ' :
2018-10-23 19:29:19 +02:00
if FdfParser . _Verify ( Name , Value , ' UINT8 ' ) :
2016-08-15 07:52:12 +02:00
FmpData . Version = Value
2015-06-23 08:46:01 +02:00
elif Name == ' IMAGE_INDEX ' :
2018-10-23 19:29:19 +02:00
if FdfParser . _Verify ( Name , Value , ' UINT8 ' ) :
2016-08-15 07:52:12 +02:00
FmpData . ImageIndex = Value
2015-06-23 08:46:01 +02:00
elif Name == ' HARDWARE_INSTANCE ' :
2018-10-23 19:29:19 +02:00
if FdfParser . _Verify ( Name , Value , ' UINT8 ' ) :
2016-08-15 07:52:12 +02:00
FmpData . HardwareInstance = Value
elif Name == ' MONOTONIC_COUNT ' :
2018-10-23 19:29:19 +02:00
if FdfParser . _Verify ( Name , Value , ' UINT64 ' ) :
2016-08-15 07:52:12 +02:00
FmpData . MonotonicCount = Value
if FmpData . MonotonicCount . upper ( ) . startswith ( ' 0X ' ) :
2018-12-03 03:29:40 +01:00
FmpData . MonotonicCount = int ( FmpData . MonotonicCount , 16 )
2016-08-15 07:52:12 +02:00
else :
2018-12-03 03:29:40 +01:00
FmpData . MonotonicCount = int ( FmpData . MonotonicCount )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2015-06-23 08:46:01 +02:00
break
else :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2015-06-23 08:46:01 +02:00
2016-08-15 07:52:12 +02:00
if ( FmpData . MonotonicCount and not FmpData . Certificate_Guid ) or ( not FmpData . MonotonicCount and FmpData . Certificate_Guid ) :
EdkLogger . error ( " FdfParser " , FORMAT_INVALID , " CERTIFICATE_GUID and MONOTONIC_COUNT must be work as a pair. " )
2017-01-04 03:40:54 +01:00
# Only the IMAGE_TYPE_ID is required item
if FmpKeyList and ' IMAGE_TYPE_ID ' in FmpKeyList :
2018-10-23 19:29:23 +02:00
raise Warning ( " ' IMAGE_TYPE_ID ' in FMP payload section. " , self . FileName , self . CurrentLineNumber )
2016-10-09 03:30:06 +02:00
# get the Image file and Vendor code file
2018-10-23 19:29:19 +02:00
self . _GetFMPCapsuleData ( FmpData )
2016-10-09 03:30:06 +02:00
if not FmpData . ImageFile :
2016-08-15 07:52:12 +02:00
raise Warning ( " Missing image file in FMP payload section. " , self . FileName , self . CurrentLineNumber )
2016-10-09 03:30:06 +02:00
# check whether more than one Vendor code file
if len ( FmpData . VendorCodeFile ) > 1 :
2018-10-23 19:29:23 +02:00
raise Warning ( " Vendor code file max of 1 per FMP payload section. " , self . FileName , self . CurrentLineNumber )
2015-06-23 08:46:01 +02:00
self . Profile . FmpPayloadDict [ FmpUiName ] = FmpData
return True
2018-10-23 19:29:19 +02:00
## _GetCapsule() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetCapsule ( self ) :
if not self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
S = self . _Token . upper ( )
if S . startswith ( TAB_SECTION_START ) and not S . startswith ( " [CAPSULE. " ) :
2016-04-21 08:50:30 +02:00
self . SectionParser ( S )
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
if not self . _IsToken ( " [CAPSULE. " , True ) :
2009-07-17 11:10:31 +02:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
#print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
2018-10-23 19:29:19 +02:00
# % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine:], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " [Capsule.] " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
CapsuleObj = Capsule ( )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
CapsuleName = self . _GetUiName ( )
2009-07-17 11:10:31 +02:00
if not CapsuleName :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " capsule name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
CapsuleObj . UiCapsuleName = CapsuleName . upper ( )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_SECTION_END ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedBracketClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " CREATE_FILE " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " file name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
CapsuleObj . CreateFile = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
self . _GetCapsuleStatements ( CapsuleObj )
2009-09-11 05:14:43 +02:00
self . Profile . CapsuleDict [ CapsuleObj . UiCapsuleName ] = CapsuleObj
2009-07-17 11:10:31 +02:00
return True
2018-10-23 19:29:19 +02:00
## _GetCapsuleStatements() method
2009-07-17 11:10:31 +02:00
#
# Get statements for capsule
#
# @param self The object pointer
# @param Obj for whom statements are got
#
2018-10-23 19:29:19 +02:00
def _GetCapsuleStatements ( self , Obj ) :
self . _GetCapsuleTokens ( Obj )
self . _GetDefineStatements ( Obj )
self . _GetSetStatements ( Obj )
self . _GetCapsuleData ( Obj )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetCapsuleTokens() method
2009-07-17 11:10:31 +02:00
#
# Get token statements for capsule
#
# @param self The object pointer
# @param Obj for whom token statements are got
#
2018-10-23 19:29:19 +02:00
def _GetCapsuleTokens ( self , Obj ) :
if not self . _GetNextToken ( ) :
2009-11-09 12:47:35 +01:00
return False
2018-10-23 19:29:20 +02:00
while self . _Token in { " CAPSULE_GUID " , " CAPSULE_HEADER_SIZE " , " CAPSULE_FLAGS " , " OEM_CAPSULE_FLAGS " , " CAPSULE_HEADER_INIT_VERSION " } :
2018-10-23 19:29:19 +02:00
Name = self . _Token . strip ( )
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " value " , self . FileName , self . CurrentLineNumber )
2009-11-09 12:47:35 +01:00
if Name == ' CAPSULE_FLAGS ' :
2018-10-23 19:29:20 +02:00
if not self . _Token in { " PersistAcrossReset " , " PopulateSystemTable " , " InitiateReset " } :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " PersistAcrossReset, PopulateSystemTable, or InitiateReset " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Value = self . _Token . strip ( )
while self . _IsToken ( TAB_COMMA_SPLIT ) :
Value + = TAB_COMMA_SPLIT
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " value " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:20 +02:00
if not self . _Token in { " PersistAcrossReset " , " PopulateSystemTable " , " InitiateReset " } :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " PersistAcrossReset, PopulateSystemTable, or InitiateReset " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Value + = self . _Token . strip ( )
2013-11-18 08:41:21 +01:00
elif Name == ' OEM_CAPSULE_FLAGS ' :
2018-10-23 19:29:19 +02:00
Value = self . _Token . strip ( )
2014-01-10 06:25:50 +01:00
if not Value . upper ( ) . startswith ( ' 0X ' ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " hex value starting with 0x " , self . FileName , self . CurrentLineNumber )
2013-11-18 08:41:21 +01:00
try :
Value = int ( Value , 0 )
except ValueError :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " hex string failed to convert to value " , self . FileName , self . CurrentLineNumber )
2013-11-18 08:41:21 +01:00
if not 0x0000 < = Value < = 0xFFFF :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " hex value between 0x0000 and 0xFFFF " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Value = self . _Token . strip ( )
2009-11-09 12:47:35 +01:00
else :
2018-10-23 19:29:19 +02:00
Value = self . _Token . strip ( )
2018-07-05 11:40:04 +02:00
Obj . TokensDict [ Name ] = Value
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2009-11-09 12:47:35 +01:00
return False
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetCapsuleData() method
2009-07-17 11:10:31 +02:00
#
# Get capsule data for capsule
#
# @param self The object pointer
# @param Obj for whom capsule data are got
#
2018-10-23 19:29:19 +02:00
def _GetCapsuleData ( self , Obj ) :
2009-07-17 11:10:31 +02:00
while True :
2018-10-23 19:29:19 +02:00
IsInf = self . _GetInfStatement ( Obj , True )
IsFile = self . _GetFileStatement ( Obj , True )
IsFv = self . _GetFvStatement ( Obj )
IsFd = self . _GetFdStatement ( Obj )
IsAnyFile = self . _GetAnyFileStatement ( Obj )
IsAfile = self . _GetAfileStatement ( Obj )
IsFmp = self . _GetFmpStatement ( Obj )
2015-06-23 08:46:01 +02:00
if not ( IsInf or IsFile or IsFv or IsFd or IsAnyFile or IsAfile or IsFmp ) :
2009-07-17 11:10:31 +02:00
break
2018-10-23 19:29:19 +02:00
## _GetFMPCapsuleData() method
2016-10-09 03:30:06 +02:00
#
# Get capsule data for FMP capsule
#
# @param self The object pointer
# @param Obj for whom capsule data are got
#
2018-10-23 19:29:19 +02:00
def _GetFMPCapsuleData ( self , Obj ) :
2016-10-09 03:30:06 +02:00
while True :
2018-10-23 19:29:19 +02:00
IsFv = self . _GetFvStatement ( Obj , True )
IsFd = self . _GetFdStatement ( Obj , True )
IsAnyFile = self . _GetAnyFileStatement ( Obj , True )
2016-10-09 03:30:06 +02:00
if not ( IsFv or IsFd or IsAnyFile ) :
break
2018-10-23 19:29:19 +02:00
## _GetFvStatement() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetFvStatement ( self , CapsuleObj , FMPCapsule = False ) :
if not self . _IsKeyword ( BINARY_FILE_TYPE_FV ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FV name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _Token . upper ( ) not in self . Profile . FvDict :
2011-11-25 07:21:03 +01:00
raise Warning ( " FV name does not exist " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
myCapsuleFv = CapsuleFv ( )
myCapsuleFv . FvName = self . _Token
2016-10-09 03:30:06 +02:00
if FMPCapsule :
if not CapsuleObj . ImageFile :
2018-10-23 19:29:19 +02:00
CapsuleObj . ImageFile . append ( myCapsuleFv )
2016-10-09 03:30:06 +02:00
else :
2018-10-23 19:29:19 +02:00
CapsuleObj . VendorCodeFile . append ( myCapsuleFv )
2016-10-09 03:30:06 +02:00
else :
2018-10-23 19:29:19 +02:00
CapsuleObj . CapsuleDataList . append ( myCapsuleFv )
2009-07-17 11:10:31 +02:00
return True
2018-10-23 19:29:19 +02:00
## _GetFdStatement() method
2011-09-18 14:17:25 +02:00
#
# Get FD for capsule
#
# @param self The object pointer
# @param CapsuleObj for whom FD is got
# @retval True Successfully find a FD statement
# @retval False Not able to find a FD statement
#
2018-10-23 19:29:19 +02:00
def _GetFdStatement ( self , CapsuleObj , FMPCapsule = False ) :
if not self . _IsKeyword ( " FD " ) :
2011-09-18 14:17:25 +02:00
return False
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2011-09-18 14:17:25 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FD name " , self . FileName , self . CurrentLineNumber )
2011-09-18 14:17:25 +02:00
2018-10-23 19:29:19 +02:00
if self . _Token . upper ( ) not in self . Profile . FdDict :
2011-11-25 07:21:03 +01:00
raise Warning ( " FD name does not exist " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
myCapsuleFd = CapsuleFd ( )
myCapsuleFd . FdName = self . _Token
2016-10-09 03:30:06 +02:00
if FMPCapsule :
if not CapsuleObj . ImageFile :
2018-10-23 19:29:19 +02:00
CapsuleObj . ImageFile . append ( myCapsuleFd )
2016-10-09 03:30:06 +02:00
else :
2018-10-23 19:29:19 +02:00
CapsuleObj . VendorCodeFile . append ( myCapsuleFd )
2016-10-09 03:30:06 +02:00
else :
2018-10-23 19:29:19 +02:00
CapsuleObj . CapsuleDataList . append ( myCapsuleFd )
2011-09-18 14:17:25 +02:00
return True
2018-10-23 19:29:19 +02:00
def _GetFmpStatement ( self , CapsuleObj ) :
if not self . _IsKeyword ( " FMP_PAYLOAD " ) :
if not self . _IsKeyword ( " FMP " ) :
2016-04-21 08:50:30 +02:00
return False
2011-09-18 14:17:25 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( " PAYLOAD " ) :
self . _UndoToken ( )
2016-04-21 08:50:30 +02:00
return False
2011-09-18 14:17:25 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2015-06-23 08:46:01 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " payload name after FMP_PAYLOAD = " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Payload = self . _Token . upper ( )
2015-06-23 08:46:01 +02:00
if Payload not in self . Profile . FmpPayloadDict :
2018-10-23 19:29:19 +02:00
raise Warning ( " This FMP Payload does not exist: %s " % self . _Token , self . FileName , self . CurrentLineNumber )
2015-06-23 08:46:01 +02:00
CapsuleObj . FmpPayloadList . append ( self . Profile . FmpPayloadDict [ Payload ] )
return True
2018-10-23 19:29:19 +02:00
def _ParseRawFileStatement ( self ) :
if not self . _IsKeyword ( " FILE " ) :
2015-06-23 08:46:01 +02:00
return None
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( " DATA " ) :
self . _UndoToken ( )
2015-06-23 08:46:01 +02:00
return None
2011-09-18 14:17:25 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2011-09-18 14:17:25 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " File name " , self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
AnyFileName = self . _Token
self . _VerifyFile ( AnyFileName )
2016-04-28 08:42:26 +02:00
2016-11-14 10:41:11 +01:00
if not os . path . isabs ( AnyFileName ) :
AnyFileName = mws . join ( GenFdsGlobalVariable . WorkSpaceDir , AnyFileName )
2015-06-23 08:46:01 +02:00
return AnyFileName
2018-10-23 19:29:19 +02:00
## _GetAnyFileStatement() method
2015-06-23 08:46:01 +02:00
#
# Get AnyFile for capsule
#
# @param self The object pointer
# @param CapsuleObj for whom AnyFile is got
# @retval True Successfully find a Anyfile statement
# @retval False Not able to find a AnyFile statement
#
2018-10-23 19:29:19 +02:00
def _GetAnyFileStatement ( self , CapsuleObj , FMPCapsule = False ) :
AnyFileName = self . _ParseRawFileStatement ( )
2015-06-23 08:46:01 +02:00
if not AnyFileName :
return False
2011-09-18 14:17:25 +02:00
2018-10-23 19:29:19 +02:00
myCapsuleAnyFile = CapsuleAnyFile ( )
myCapsuleAnyFile . FileName = AnyFileName
2016-10-09 03:30:06 +02:00
if FMPCapsule :
if not CapsuleObj . ImageFile :
2018-10-23 19:29:19 +02:00
CapsuleObj . ImageFile . append ( myCapsuleAnyFile )
2016-10-09 03:30:06 +02:00
else :
2018-10-23 19:29:19 +02:00
CapsuleObj . VendorCodeFile . append ( myCapsuleAnyFile )
2016-10-09 03:30:06 +02:00
else :
2018-10-23 19:29:19 +02:00
CapsuleObj . CapsuleDataList . append ( myCapsuleAnyFile )
2011-09-18 14:17:25 +02:00
return True
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
## _GetAfileStatement() method
2014-01-10 06:25:50 +01:00
#
# Get Afile for capsule
#
# @param self The object pointer
# @param CapsuleObj for whom Afile is got
# @retval True Successfully find a Afile statement
# @retval False Not able to find a Afile statement
#
2018-10-23 19:29:19 +02:00
def _GetAfileStatement ( self , CapsuleObj ) :
if not self . _IsKeyword ( " APPEND " ) :
2014-01-10 06:25:50 +01:00
return False
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2014-01-10 06:25:50 +01:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Afile name " , self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
AfileName = self . _Token
2014-01-10 06:25:50 +01:00
AfileBaseName = os . path . basename ( AfileName )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:20 +02:00
if os . path . splitext ( AfileBaseName ) [ 1 ] not in { " .bin " , " .BIN " , " .Bin " , " .dat " , " .DAT " , " .Dat " , " .data " , " .DATA " , " .Data " } :
2018-04-26 18:57:56 +02:00
raise Warning ( ' invalid binary file type, should be one of " bin " ,BINARY_FILE_TYPE_BIN, " Bin " , " dat " , " DAT " , " Dat " , " data " , " DATA " , " Data " ' , \
2014-01-10 06:25:50 +01:00
self . FileName , self . CurrentLineNumber )
2018-07-05 11:40:04 +02:00
2014-01-10 06:25:50 +01:00
if not os . path . isabs ( AfileName ) :
AfileName = GenFdsGlobalVariable . ReplaceWorkspaceMacro ( AfileName )
2018-10-23 19:29:19 +02:00
self . _VerifyFile ( AfileName )
2014-01-10 06:25:50 +01:00
else :
if not os . path . exists ( AfileName ) :
raise Warning ( ' %s does not exist ' % AfileName , self . FileName , self . CurrentLineNumber )
else :
pass
2018-10-23 19:29:19 +02:00
myCapsuleAfile = CapsuleAfile ( )
myCapsuleAfile . FileName = AfileName
CapsuleObj . CapsuleDataList . append ( myCapsuleAfile )
2014-01-10 06:25:50 +01:00
return True
2011-09-18 14:17:25 +02:00
2018-10-23 19:29:19 +02:00
## _GetRule() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetRule ( self ) :
if not self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
S = self . _Token . upper ( )
if S . startswith ( TAB_SECTION_START ) and not S . startswith ( " [RULE. " ) :
2016-04-21 08:50:30 +02:00
self . SectionParser ( S )
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
if not self . _IsToken ( " [Rule. " , True ) :
2009-07-17 11:10:31 +02:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
#print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \
2018-10-23 19:29:19 +02:00
# % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine:], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " [Rule.] " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _SkipToToken ( TAB_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' . ' " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
Arch = self . _SkippedChars . rstrip ( TAB_SPLIT )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
ModuleType = self . _GetModuleType ( )
2009-07-17 11:10:31 +02:00
TemplateName = " "
2018-10-23 19:29:19 +02:00
if self . _IsToken ( TAB_SPLIT ) :
if not self . _GetNextWord ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " template name " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
TemplateName = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_SECTION_END ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedBracketClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
RuleObj = self . _GetRuleFileStatements ( )
2009-07-17 11:10:31 +02:00
RuleObj . Arch = Arch . upper ( )
RuleObj . ModuleType = ModuleType
RuleObj . TemplateName = TemplateName
2018-10-23 19:29:19 +02:00
if TemplateName == ' ' :
2009-07-17 11:10:31 +02:00
self . Profile . RuleDict [ ' RULE ' + \
2018-10-23 19:29:19 +02:00
TAB_SPLIT + \
2009-07-17 11:10:31 +02:00
Arch . upper ( ) + \
2018-10-23 19:29:19 +02:00
TAB_SPLIT + \
2009-07-17 11:10:31 +02:00
ModuleType . upper ( ) ] = RuleObj
2018-10-23 19:29:19 +02:00
else :
2009-07-17 11:10:31 +02:00
self . Profile . RuleDict [ ' RULE ' + \
2018-10-23 19:29:19 +02:00
TAB_SPLIT + \
2009-07-17 11:10:31 +02:00
Arch . upper ( ) + \
2018-10-23 19:29:19 +02:00
TAB_SPLIT + \
2009-07-17 11:10:31 +02:00
ModuleType . upper ( ) + \
2018-10-23 19:29:19 +02:00
TAB_SPLIT + \
2009-07-17 11:10:31 +02:00
TemplateName . upper ( ) ] = RuleObj
return True
2018-10-23 19:29:19 +02:00
## _GetModuleType() method
2009-07-17 11:10:31 +02:00
#
# Return the module type
#
# @param self The object pointer
# @retval string module type
#
2018-10-23 19:29:19 +02:00
def _GetModuleType ( self ) :
if not self . _GetNextWord ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Module type " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:20 +02:00
if self . _Token . upper ( ) not in {
SUP_MODULE_SEC , SUP_MODULE_PEI_CORE , SUP_MODULE_PEIM ,
SUP_MODULE_DXE_CORE , SUP_MODULE_DXE_DRIVER ,
SUP_MODULE_DXE_SAL_DRIVER , SUP_MODULE_DXE_SMM_DRIVER ,
SUP_MODULE_DXE_RUNTIME_DRIVER , SUP_MODULE_UEFI_DRIVER ,
2019-07-01 08:19:13 +02:00
SUP_MODULE_UEFI_APPLICATION , SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION ,
2018-10-23 19:29:20 +02:00
TAB_DEFAULT , SUP_MODULE_BASE ,
EDK_COMPONENT_TYPE_SECURITY_CORE ,
EDK_COMPONENT_TYPE_COMBINED_PEIM_DRIVER ,
EDK_COMPONENT_TYPE_PIC_PEIM ,
EDK_COMPONENT_TYPE_RELOCATABLE_PEIM , " PE32_PEIM " ,
EDK_COMPONENT_TYPE_BS_DRIVER , EDK_COMPONENT_TYPE_RT_DRIVER ,
EDK_COMPONENT_TYPE_SAL_RT_DRIVER ,
EDK_COMPONENT_TYPE_APPLICATION , " ACPITABLE " ,
SUP_MODULE_SMM_CORE , SUP_MODULE_MM_STANDALONE ,
SUP_MODULE_MM_CORE_STANDALONE } :
2018-10-23 19:29:19 +02:00
raise Warning ( " Unknown Module type ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
return self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetFileExtension() method
2009-07-17 11:10:31 +02:00
#
# Return the file extension
#
# @param self The object pointer
# @retval string file name extension
#
2018-10-23 19:29:19 +02:00
def _GetFileExtension ( self ) :
if not self . _IsToken ( TAB_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' . ' " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
Ext = " "
2018-10-23 19:29:19 +02:00
if self . _GetNextToken ( ) :
if FileExtensionPattern . match ( self . _Token ) :
Ext = self . _Token
return TAB_SPLIT + Ext
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
raise Warning ( " Unknown file extension ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " file extension " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetRuleFileStatement() method
2009-07-17 11:10:31 +02:00
#
# Get rule contents
#
# @param self The object pointer
# @retval Rule Rule object
#
2018-10-23 19:29:19 +02:00
def _GetRuleFileStatements ( self ) :
if not self . _IsKeyword ( " FILE " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FILE " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextWord ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FFS type " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
Type = self . _Token . strip ( ) . upper ( )
2018-10-23 19:29:20 +02:00
if Type not in { " RAW " , " FREEFORM " , SUP_MODULE_SEC , SUP_MODULE_PEI_CORE , SUP_MODULE_PEIM ,
" PEI_DXE_COMBO " , " DRIVER " , SUP_MODULE_DXE_CORE , EDK_COMPONENT_TYPE_APPLICATION ,
" FV_IMAGE " , " SMM " , SUP_MODULE_SMM_CORE , SUP_MODULE_MM_STANDALONE ,
SUP_MODULE_MM_CORE_STANDALONE } :
2018-10-23 19:29:19 +02:00
raise Warning ( " Unknown FV type ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( " $(NAMED_GUID) " ) :
if not self . _GetNextWord ( ) :
2019-05-09 13:58:32 +02:00
NamedGuid = self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine : ] . split ( ) [ 0 ] . strip ( )
if GlobalData . gGuidPatternEnd . match ( NamedGuid ) :
self . CurrentOffsetWithinLine + = len ( NamedGuid )
self . _Token = NamedGuid
else :
raise Warning . Expected ( " $(NAMED_GUID) " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if self . _Token == ' PCD ' :
if not self . _IsToken ( " ( " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' ( ' " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
PcdPair = self . _GetNextPcdSettings ( )
if not self . _IsToken ( " ) " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' ) ' " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
self . _Token = ' PCD( ' + PcdPair [ 1 ] + TAB_SPLIT + PcdPair [ 0 ] + ' ) '
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
NameGuid = self . _Token
2009-07-17 11:10:31 +02:00
KeepReloc = None
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( ' RELOCS_STRIPPED ' ) or self . _IsKeyword ( ' RELOCS_RETAINED ' ) :
if self . _FileCouldHaveRelocFlag ( Type ) :
if self . _Token == ' RELOCS_STRIPPED ' :
2009-07-17 11:10:31 +02:00
KeepReloc = False
else :
KeepReloc = True
else :
raise Warning ( " File type %s could not have reloc strip flag %d " % ( Type , self . CurrentLineNumber ) , self . FileName , self . CurrentLineNumber )
KeyStringList = [ ]
2018-10-23 19:29:19 +02:00
if self . _GetNextToken ( ) :
if TokenFindPattern . match ( self . _Token ) :
KeyStringList . append ( self . _Token )
if self . _IsToken ( TAB_COMMA_SPLIT ) :
while self . _GetNextToken ( ) :
if not TokenFindPattern . match ( self . _Token ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " KeyString \" Target_Tag_Arch \" " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
KeyStringList . append ( self . _Token )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_COMMA_SPLIT ) :
2009-07-17 11:10:31 +02:00
break
else :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
Fixed = False
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " Fixed " , True ) :
2009-07-17 11:10:31 +02:00
Fixed = True
CheckSum = False
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " CheckSum " , True ) :
2009-07-17 11:10:31 +02:00
CheckSum = True
AlignValue = " "
2018-10-23 19:29:19 +02:00
if self . _GetAlignment ( ) :
if self . _Token not in ALIGNMENTS :
raise Warning ( " Incorrect alignment ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
2010-03-01 00:39:39 +01:00
#For FFS, Auto is default option same to ""
2018-10-23 19:29:19 +02:00
if not self . _Token == " Auto " :
AlignValue = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsToken ( " { " ) :
2009-07-17 11:10:31 +02:00
# Complex file rule expected
2018-10-23 19:29:19 +02:00
NewRule = RuleComplexFile ( )
NewRule . FvFileType = Type
NewRule . NameGuid = NameGuid
NewRule . Alignment = AlignValue
NewRule . CheckSum = CheckSum
NewRule . Fixed = Fixed
NewRule . KeyStringList = KeyStringList
2018-03-26 22:25:43 +02:00
if KeepReloc is not None :
2018-10-23 19:29:19 +02:00
NewRule . KeepReloc = KeepReloc
2009-07-17 11:10:31 +02:00
while True :
2018-10-23 19:29:19 +02:00
IsEncapsulate = self . _GetRuleEncapsulationSection ( NewRule )
IsLeaf = self . _GetEfiSection ( NewRule )
2009-07-17 11:10:31 +02:00
if not IsEncapsulate and not IsLeaf :
break
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
return NewRule
2009-07-17 11:10:31 +02:00
else :
# Simple file rule expected
2018-10-23 19:29:19 +02:00
if not self . _GetNextWord ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " leaf section type " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
SectionName = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:20 +02:00
if SectionName not in {
" COMPAT16 " , BINARY_FILE_TYPE_PE32 ,
BINARY_FILE_TYPE_PIC , BINARY_FILE_TYPE_TE , " FV_IMAGE " ,
" RAW " , BINARY_FILE_TYPE_DXE_DEPEX , BINARY_FILE_TYPE_UI ,
BINARY_FILE_TYPE_PEI_DEPEX , " VERSION " , " SUBTYPE_GUID " ,
BINARY_FILE_TYPE_SMM_DEPEX } :
2009-07-17 11:10:31 +02:00
raise Warning ( " Unknown leaf section name ' %s ' " % SectionName , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " Fixed " , True ) :
2009-07-17 11:10:31 +02:00
Fixed = True
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " CheckSum " , True ) :
2009-07-17 11:10:31 +02:00
CheckSum = True
2010-03-01 00:39:39 +01:00
SectAlignment = " "
2018-10-23 19:29:19 +02:00
if self . _GetAlignment ( ) :
if self . _Token not in ALIGNMENTS :
raise Warning ( " Incorrect alignment ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
if self . _Token == ' Auto ' and ( not SectionName == BINARY_FILE_TYPE_PE32 ) and ( not SectionName == BINARY_FILE_TYPE_TE ) :
2010-03-01 00:39:39 +01:00
raise Warning ( " Auto alignment can only be used in PE32 or TE section " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
SectAlignment = self . _Token
2010-03-01 00:39:39 +01:00
Ext = None
2018-10-23 19:29:19 +02:00
if self . _IsToken ( TAB_VALUE_SPLIT ) :
Ext = self . _GetFileExtension ( )
elif not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " File name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
NewRule = RuleSimpleFile ( )
NewRule . SectionType = SectionName
NewRule . FvFileType = Type
NewRule . NameGuid = NameGuid
NewRule . Alignment = AlignValue
NewRule . SectAlignment = SectAlignment
NewRule . CheckSum = CheckSum
NewRule . Fixed = Fixed
NewRule . KeyStringList = KeyStringList
2018-03-26 22:25:43 +02:00
if KeepReloc is not None :
2018-10-23 19:29:19 +02:00
NewRule . KeepReloc = KeepReloc
NewRule . FileExtension = Ext
NewRule . FileName = self . _Token
return NewRule
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetEfiSection() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetEfiSection ( self , Obj ) :
2009-07-17 11:10:31 +02:00
OldPos = self . GetFileBufferPos ( )
2019-05-29 07:29:34 +02:00
EfiSectionObj = EfiSection ( )
2018-10-23 19:29:19 +02:00
if not self . _GetNextWord ( ) :
2019-05-29 07:29:34 +02:00
CurrentLine = self . _CurrentLine ( ) [ self . CurrentOffsetWithinLine : ] . split ( ) [ 0 ] . strip ( )
if self . _Token == ' { ' and Obj . FvFileType == " RAW " and TAB_SPLIT in CurrentLine :
if self . _IsToken ( TAB_VALUE_SPLIT ) :
EfiSectionObj . FileExtension = self . _GetFileExtension ( )
elif self . _GetNextToken ( ) :
EfiSectionObj . FileName = self . _Token
EfiSectionObj . SectionType = BINARY_FILE_TYPE_RAW
Obj . SectionList . append ( EfiSectionObj )
return True
else :
return False
2018-10-23 19:29:19 +02:00
SectionName = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:20 +02:00
if SectionName not in {
" COMPAT16 " , BINARY_FILE_TYPE_PE32 ,
BINARY_FILE_TYPE_PIC , BINARY_FILE_TYPE_TE , " FV_IMAGE " ,
" RAW " , BINARY_FILE_TYPE_DXE_DEPEX , BINARY_FILE_TYPE_UI ,
BINARY_FILE_TYPE_PEI_DEPEX , " VERSION " , " SUBTYPE_GUID " ,
BINARY_FILE_TYPE_SMM_DEPEX , BINARY_FILE_TYPE_GUID } :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
return False
if SectionName == " FV_IMAGE " :
2018-10-23 19:29:19 +02:00
FvImageSectionObj = FvImageSection ( )
if self . _IsKeyword ( " FV_IMAGE " ) :
2009-07-17 11:10:31 +02:00
pass
2018-10-23 19:29:19 +02:00
if self . _IsToken ( " { " ) :
FvObj = FV ( )
self . _GetDefineStatements ( FvObj )
self . _GetBlockStatement ( FvObj )
self . _GetSetStatements ( FvObj )
self . _GetFvAlignment ( FvObj )
self . _GetFvAttributes ( FvObj )
self . _GetAprioriSection ( FvObj )
self . _GetAprioriSection ( FvObj )
2009-07-17 11:10:31 +02:00
while True :
2018-10-23 19:29:19 +02:00
IsInf = self . _GetInfStatement ( FvObj )
IsFile = self . _GetFileStatement ( FvObj )
2009-07-17 11:10:31 +02:00
if not IsInf and not IsFile :
break
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
FvImageSectionObj . Fv = FvObj
FvImageSectionObj . FvName = None
else :
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( BINARY_FILE_TYPE_FV ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' FV ' " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FvImageSectionObj . FvFileType = self . _Token
if self . _GetAlignment ( ) :
if self . _Token not in ALIGNMENT_NOAUTO :
raise Warning ( " Incorrect alignment ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
FvImageSectionObj . Alignment = self . _Token
if self . _IsToken ( TAB_VALUE_SPLIT ) :
FvImageSectionObj . FvFileExtension = self . _GetFileExtension ( )
elif self . _GetNextToken ( ) :
2018-10-23 19:29:20 +02:00
if self . _Token not in {
2018-10-23 19:29:24 +02:00
T_CHAR_BRACE_R , " COMPAT16 " , BINARY_FILE_TYPE_PE32 ,
2018-10-23 19:29:20 +02:00
BINARY_FILE_TYPE_PIC , BINARY_FILE_TYPE_TE ,
" FV_IMAGE " , " RAW " , BINARY_FILE_TYPE_DXE_DEPEX ,
BINARY_FILE_TYPE_UI , " VERSION " ,
BINARY_FILE_TYPE_PEI_DEPEX , BINARY_FILE_TYPE_GUID ,
BINARY_FILE_TYPE_SMM_DEPEX } :
2018-10-23 19:29:19 +02:00
FvImageSectionObj . FvFileName = self . _Token
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " FV file name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
Obj . SectionList . append ( FvImageSectionObj )
return True
EfiSectionObj . SectionType = SectionName
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " file type " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _Token == " STRING " :
if not self . _RuleSectionCouldHaveString ( EfiSectionObj . SectionType ) :
2009-07-17 11:10:31 +02:00
raise Warning ( " %s section could NOT have string data %d " % ( EfiSectionObj . SectionType , self . CurrentLineNumber ) , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Quoted String " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _GetStringData ( ) :
EfiSectionObj . StringData = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " BUILD_NUM " ) :
if not self . _RuleSectionCouldHaveBuildNum ( EfiSectionObj . SectionType ) :
2009-07-17 11:10:31 +02:00
raise Warning ( " %s section could NOT have BUILD_NUM %d " % ( EfiSectionObj . SectionType , self . CurrentLineNumber ) , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Build number " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
EfiSectionObj . BuildNum = self . _Token
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
EfiSectionObj . FileType = self . _Token
self . _CheckRuleSectionFileType ( EfiSectionObj . SectionType , EfiSectionObj . FileType )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " Optional " ) :
if not self . _RuleSectionCouldBeOptional ( EfiSectionObj . SectionType ) :
2009-07-17 11:10:31 +02:00
raise Warning ( " %s section could NOT be optional %d " % ( EfiSectionObj . SectionType , self . CurrentLineNumber ) , self . FileName , self . CurrentLineNumber )
EfiSectionObj . Optional = True
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " BUILD_NUM " ) :
if not self . _RuleSectionCouldHaveBuildNum ( EfiSectionObj . SectionType ) :
2009-07-17 11:10:31 +02:00
raise Warning ( " %s section could NOT have BUILD_NUM %d " % ( EfiSectionObj . SectionType , self . CurrentLineNumber ) , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Build number " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
EfiSectionObj . BuildNum = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _GetAlignment ( ) :
if self . _Token not in ALIGNMENTS :
raise Warning ( " Incorrect alignment ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
if self . _Token == ' Auto ' and ( not SectionName == BINARY_FILE_TYPE_PE32 ) and ( not SectionName == BINARY_FILE_TYPE_TE ) :
2010-03-01 00:39:39 +01:00
raise Warning ( " Auto alignment can only be used in PE32 or TE section " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
EfiSectionObj . Alignment = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( ' RELOCS_STRIPPED ' ) or self . _IsKeyword ( ' RELOCS_RETAINED ' ) :
if self . _SectionCouldHaveRelocFlag ( EfiSectionObj . SectionType ) :
if self . _Token == ' RELOCS_STRIPPED ' :
2009-07-17 11:10:31 +02:00
EfiSectionObj . KeepReloc = False
else :
EfiSectionObj . KeepReloc = True
2018-03-26 22:25:43 +02:00
if Obj . KeepReloc is not None and Obj . KeepReloc != EfiSectionObj . KeepReloc :
2009-07-17 11:10:31 +02:00
raise Warning ( " Section type %s has reloc strip flag conflict with Rule " % EfiSectionObj . SectionType , self . FileName , self . CurrentLineNumber )
else :
raise Warning ( " Section type %s could not have reloc strip flag " % EfiSectionObj . SectionType , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if self . _IsToken ( TAB_VALUE_SPLIT ) :
EfiSectionObj . FileExtension = self . _GetFileExtension ( )
elif self . _GetNextToken ( ) :
2018-10-23 19:29:20 +02:00
if self . _Token not in {
2018-10-23 19:29:24 +02:00
T_CHAR_BRACE_R , " COMPAT16 " , BINARY_FILE_TYPE_PE32 ,
2018-10-23 19:29:20 +02:00
BINARY_FILE_TYPE_PIC , BINARY_FILE_TYPE_TE ,
" FV_IMAGE " , " RAW " , BINARY_FILE_TYPE_DXE_DEPEX ,
BINARY_FILE_TYPE_UI , " VERSION " ,
BINARY_FILE_TYPE_PEI_DEPEX , BINARY_FILE_TYPE_GUID ,
BINARY_FILE_TYPE_SMM_DEPEX } :
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if self . _Token . startswith ( ' PCD ' ) :
self . _UndoToken ( )
self . _GetNextWord ( )
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
if self . _Token == ' PCD ' :
if not self . _IsToken ( " ( " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' ( ' " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
PcdPair = self . _GetNextPcdSettings ( )
if not self . _IsToken ( " ) " ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " ' ) ' " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
self . _Token = ' PCD( ' + PcdPair [ 1 ] + TAB_SPLIT + PcdPair [ 0 ] + ' ) '
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
EfiSectionObj . FileName = self . _Token
2018-07-05 11:40:04 +02:00
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2009-07-17 11:10:31 +02:00
else :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " section file name " , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
Obj . SectionList . append ( EfiSectionObj )
return True
2018-10-23 19:29:19 +02:00
## _RuleSectionCouldBeOptional() method
2009-07-17 11:10:31 +02:00
#
# Get whether a section could be optional
#
# @param SectionType The section type to check
# @retval True section could be optional
# @retval False section never optional
#
2018-03-30 02:19:32 +02:00
@staticmethod
2018-10-23 19:29:19 +02:00
def _RuleSectionCouldBeOptional ( SectionType ) :
2018-10-23 19:29:20 +02:00
if SectionType in { BINARY_FILE_TYPE_DXE_DEPEX , BINARY_FILE_TYPE_UI , " VERSION " , BINARY_FILE_TYPE_PEI_DEPEX , " RAW " , BINARY_FILE_TYPE_SMM_DEPEX } :
2009-07-17 11:10:31 +02:00
return True
else :
return False
2018-10-23 19:29:19 +02:00
## _RuleSectionCouldHaveBuildNum() method
2009-07-17 11:10:31 +02:00
#
# Get whether a section could have build number information
#
# @param SectionType The section type to check
# @retval True section could have build number information
# @retval False section never have build number information
#
2018-03-30 02:19:32 +02:00
@staticmethod
2018-10-23 19:29:19 +02:00
def _RuleSectionCouldHaveBuildNum ( SectionType ) :
2018-10-23 19:29:20 +02:00
if SectionType == " VERSION " :
2009-07-17 11:10:31 +02:00
return True
else :
return False
2018-10-23 19:29:19 +02:00
## _RuleSectionCouldHaveString() method
2009-07-17 11:10:31 +02:00
#
# Get whether a section could have string
#
# @param SectionType The section type to check
# @retval True section could have string
# @retval False section never have string
#
2018-03-30 02:19:32 +02:00
@staticmethod
2018-10-23 19:29:19 +02:00
def _RuleSectionCouldHaveString ( SectionType ) :
2018-10-23 19:29:20 +02:00
if SectionType in { BINARY_FILE_TYPE_UI , " VERSION " } :
2009-07-17 11:10:31 +02:00
return True
else :
return False
2018-10-23 19:29:19 +02:00
## _CheckRuleSectionFileType() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _CheckRuleSectionFileType ( self , SectionType , FileType ) :
2018-10-23 19:29:23 +02:00
WarningString = " Incorrect section file type ' %s ' "
2009-07-17 11:10:31 +02:00
if SectionType == " COMPAT16 " :
2018-10-23 19:29:20 +02:00
if FileType not in { " COMPAT16 " , " SEC_COMPAT16 " } :
2018-10-23 19:29:23 +02:00
raise Warning ( WarningString % FileType , self . FileName , self . CurrentLineNumber )
2018-04-26 18:57:56 +02:00
elif SectionType == BINARY_FILE_TYPE_PE32 :
2018-10-23 19:29:20 +02:00
if FileType not in { BINARY_FILE_TYPE_PE32 , " SEC_PE32 " } :
2018-10-23 19:29:23 +02:00
raise Warning ( WarningString % FileType , self . FileName , self . CurrentLineNumber )
2018-04-26 18:57:56 +02:00
elif SectionType == BINARY_FILE_TYPE_PIC :
2018-10-23 19:29:20 +02:00
if FileType not in { BINARY_FILE_TYPE_PIC , BINARY_FILE_TYPE_PIC } :
2018-10-23 19:29:23 +02:00
raise Warning ( WarningString % FileType , self . FileName , self . CurrentLineNumber )
2018-04-26 18:57:56 +02:00
elif SectionType == BINARY_FILE_TYPE_TE :
2018-10-23 19:29:20 +02:00
if FileType not in { BINARY_FILE_TYPE_TE , " SEC_TE " } :
2018-10-23 19:29:23 +02:00
raise Warning ( WarningString % FileType , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
elif SectionType == " RAW " :
2018-10-23 19:29:20 +02:00
if FileType not in { BINARY_FILE_TYPE_BIN , " SEC_BIN " , " RAW " , " ASL " , " ACPI " } :
2018-10-23 19:29:23 +02:00
raise Warning ( WarningString % FileType , self . FileName , self . CurrentLineNumber )
2018-04-26 18:57:56 +02:00
elif SectionType == BINARY_FILE_TYPE_DXE_DEPEX or SectionType == BINARY_FILE_TYPE_SMM_DEPEX :
2018-10-23 19:29:20 +02:00
if FileType not in { BINARY_FILE_TYPE_DXE_DEPEX , " SEC_DXE_DEPEX " , BINARY_FILE_TYPE_SMM_DEPEX } :
2018-10-23 19:29:23 +02:00
raise Warning ( WarningString % FileType , self . FileName , self . CurrentLineNumber )
2018-04-26 18:57:56 +02:00
elif SectionType == BINARY_FILE_TYPE_UI :
2018-10-23 19:29:20 +02:00
if FileType not in { BINARY_FILE_TYPE_UI , " SEC_UI " } :
2018-10-23 19:29:23 +02:00
raise Warning ( WarningString % FileType , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
elif SectionType == " VERSION " :
2018-10-23 19:29:20 +02:00
if FileType not in { " VERSION " , " SEC_VERSION " } :
2018-10-23 19:29:23 +02:00
raise Warning ( WarningString % FileType , self . FileName , self . CurrentLineNumber )
2018-04-26 18:57:56 +02:00
elif SectionType == BINARY_FILE_TYPE_PEI_DEPEX :
2018-10-23 19:29:20 +02:00
if FileType not in { BINARY_FILE_TYPE_PEI_DEPEX , " SEC_PEI_DEPEX " } :
2018-10-23 19:29:23 +02:00
raise Warning ( WarningString % FileType , self . FileName , self . CurrentLineNumber )
2018-04-26 18:57:56 +02:00
elif SectionType == BINARY_FILE_TYPE_GUID :
2018-10-23 19:29:20 +02:00
if FileType not in { BINARY_FILE_TYPE_PE32 , " SEC_GUID " } :
2018-10-23 19:29:23 +02:00
raise Warning ( WarningString % FileType , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetRuleEncapsulationSection() method
2009-07-17 11:10:31 +02:00
#
# Get encapsulation section for Rule
#
# @param self The object pointer
2018-10-23 19:29:19 +02:00
# @param theRule for whom section is got
2009-07-17 11:10:31 +02:00
# @retval True Successfully find section statement
# @retval False Not able to find section statement
#
2018-10-23 19:29:19 +02:00
def _GetRuleEncapsulationSection ( self , theRule ) :
if self . _IsKeyword ( " COMPRESS " ) :
2009-07-17 11:10:31 +02:00
Type = " PI_STD "
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " PI_STD " ) or self . _IsKeyword ( " PI_NONE " ) :
Type = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
CompressSectionObj = CompressSection ( )
2009-07-17 11:10:31 +02:00
CompressSectionObj . CompType = Type
# Recursive sections...
while True :
2018-10-23 19:29:19 +02:00
IsEncapsulate = self . _GetRuleEncapsulationSection ( CompressSectionObj )
IsLeaf = self . _GetEfiSection ( CompressSectionObj )
2009-07-17 11:10:31 +02:00
if not IsEncapsulate and not IsLeaf :
break
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
theRule . SectionList . append ( CompressSectionObj )
2009-07-17 11:10:31 +02:00
return True
2018-10-23 19:29:19 +02:00
elif self . _IsKeyword ( " GUIDED " ) :
2009-07-17 11:10:31 +02:00
GuidValue = None
2018-10-23 19:29:19 +02:00
if self . _GetNextGuid ( ) :
2020-07-14 07:30:40 +02:00
if self . _Token in GlobalData . gGuidDict :
self . _Token = GuidStructureStringToGuidString ( GlobalData . gGuidDict [ self . _Token ] ) . upper ( )
2018-10-23 19:29:19 +02:00
GuidValue = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " $(NAMED_GUID) " ) :
GuidValue = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
AttribDict = self . _GetGuidAttrib ( )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( " { " ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyOpen ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
GuidSectionObj = GuidSection ( )
2009-07-17 11:10:31 +02:00
GuidSectionObj . NameGuid = GuidValue
GuidSectionObj . SectionType = " GUIDED "
GuidSectionObj . ProcessRequired = AttribDict [ " PROCESSING_REQUIRED " ]
GuidSectionObj . AuthStatusValid = AttribDict [ " AUTH_STATUS_VALID " ]
2012-05-23 10:27:14 +02:00
GuidSectionObj . ExtraHeaderSize = AttribDict [ " EXTRA_HEADER_SIZE " ]
2009-07-17 11:10:31 +02:00
# Efi sections...
while True :
2018-10-23 19:29:19 +02:00
IsEncapsulate = self . _GetRuleEncapsulationSection ( GuidSectionObj )
IsLeaf = self . _GetEfiSection ( GuidSectionObj )
2009-07-17 11:10:31 +02:00
if not IsEncapsulate and not IsLeaf :
break
2018-10-23 19:29:24 +02:00
if not self . _IsToken ( T_CHAR_BRACE_R ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedCurlyClose ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
theRule . SectionList . append ( GuidSectionObj )
2009-07-17 11:10:31 +02:00
return True
return False
2018-10-23 19:29:19 +02:00
## _GetOptionRom() method
2009-07-17 11:10:31 +02:00
#
# Get OptionROM section contents and store its data into OptionROM list of self.Profile
#
# @param self The object pointer
# @retval True Successfully find a OptionROM
# @retval False Not able to find a OptionROM
#
2018-10-23 19:29:19 +02:00
def _GetOptionRom ( self ) :
if not self . _GetNextToken ( ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
S = self . _Token . upper ( )
if S . startswith ( TAB_SECTION_START ) and not S . startswith ( " [OPTIONROM. " ) :
2016-04-21 08:50:30 +02:00
self . SectionParser ( S )
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
2016-04-21 08:50:30 +02:00
return False
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
self . _UndoToken ( )
if not self . _IsToken ( " [OptionRom. " , True ) :
raise Warning ( " Unknown Keyword ' %s ' " % self . _Token , self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
OptRomName = self . _GetUiName ( )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsToken ( TAB_SECTION_END ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedBracketClose ( self . FileName , self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
OptRomObj = OPTIONROM ( OptRomName )
2009-07-17 11:10:31 +02:00
self . Profile . OptRomDict [ OptRomName ] = OptRomObj
while True :
2018-10-23 19:29:19 +02:00
isInf = self . _GetOptRomInfStatement ( OptRomObj )
isFile = self . _GetOptRomFileStatement ( OptRomObj )
2009-07-17 11:10:31 +02:00
if not isInf and not isFile :
break
2018-07-05 11:40:04 +02:00
2009-07-17 11:10:31 +02:00
return True
2018-10-23 19:29:19 +02:00
## _GetOptRomInfStatement() method
2009-07-17 11:10:31 +02:00
#
# Get INF statements
#
# @param self The object pointer
# @param Obj for whom inf statement is got
# @retval True Successfully find inf statement
# @retval False Not able to find inf statement
#
2018-10-23 19:29:19 +02:00
def _GetOptRomInfStatement ( self , Obj ) :
if not self . _IsKeyword ( " INF " ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
ffsInf = OptRomInfStatement ( )
self . _GetInfOptions ( ffsInf )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " INF file path " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
ffsInf . InfFileName = self . _Token
if ffsInf . InfFileName . replace ( TAB_WORKSPACE , ' ' ) . find ( ' $ ' ) == - 1 :
2010-07-28 05:07:30 +02:00
#check for file path
ErrorCode , ErrorInfo = PathClass ( NormPath ( ffsInf . InfFileName ) , GenFdsGlobalVariable . WorkSpaceDir ) . Validate ( )
if ErrorCode != 0 :
EdkLogger . error ( " GenFds " , ErrorCode , ExtraData = ErrorInfo )
2009-07-17 11:10:31 +02:00
2018-11-16 03:12:15 +01:00
NewFileName = ffsInf . InfFileName
if ffsInf . OverrideGuid :
NewFileName = ProcessDuplicatedInf ( PathClass ( ffsInf . InfFileName , GenFdsGlobalVariable . WorkSpaceDir ) , ffsInf . OverrideGuid , GenFdsGlobalVariable . WorkSpaceDir ) . Path
if not NewFileName in self . Profile . InfList :
self . Profile . InfList . append ( NewFileName )
2011-12-07 07:19:28 +01:00
FileLineTuple = GetRealFileLine ( self . FileName , self . CurrentLineNumber )
self . Profile . InfFileLineList . append ( FileLineTuple )
2016-07-20 07:58:03 +02:00
if ffsInf . UseArch :
if ffsInf . UseArch not in self . Profile . InfDict :
self . Profile . InfDict [ ffsInf . UseArch ] = [ ffsInf . InfFileName ]
else :
self . Profile . InfDict [ ffsInf . UseArch ] . append ( ffsInf . InfFileName )
else :
self . Profile . InfDict [ ' ArchTBD ' ] . append ( ffsInf . InfFileName )
2009-07-17 11:10:31 +02:00
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
self . _GetOptRomOverrides ( ffsInf )
2018-07-05 11:40:04 +02:00
2009-07-17 11:10:31 +02:00
Obj . FfsList . append ( ffsInf )
return True
2018-10-23 19:29:19 +02:00
## _GetOptRomOverrides() method
2009-07-17 11:10:31 +02:00
#
# Get overrides for OptROM INF & FILE
#
# @param self The object pointer
# @param FfsInfObj for whom overrides is got
#
2018-10-23 19:29:19 +02:00
def _GetOptRomOverrides ( self , Obj ) :
if self . _IsToken ( ' { ' ) :
Overrides = OverrideAttribs ( )
2009-09-11 05:14:43 +02:00
while True :
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " PCI_VENDOR_ID " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Hex vendor id " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Overrides . PciVendorId = self . _Token
2009-09-11 05:14:43 +02:00
continue
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " PCI_CLASS_CODE " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Hex class code " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Overrides . PciClassCode = self . _Token
2009-09-11 05:14:43 +02:00
continue
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " PCI_DEVICE_ID " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-24 13:42:36 +02:00
# Get a list of PCI IDs
Overrides . PciDeviceId = " "
2018-10-29 17:52:53 +01:00
while ( self . _GetNextHexNumber ( ) ) :
Overrides . PciDeviceId = " {} {} " . format ( Overrides . PciDeviceId , self . _Token )
2018-10-24 13:42:36 +02:00
if not Overrides . PciDeviceId :
raise Warning . Expected ( " one or more Hex device ids " , self . FileName , self . CurrentLineNumber )
2009-09-11 05:14:43 +02:00
continue
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " PCI_REVISION " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextHexNumber ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Hex revision " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Overrides . PciRevision = self . _Token
2009-09-11 05:14:43 +02:00
continue
2018-10-23 19:29:19 +02:00
if self . _IsKeyword ( " PCI_COMPRESS " ) :
if not self . _IsToken ( TAB_EQUAL_SPLIT ) :
2018-10-23 19:29:23 +02:00
raise Warning . ExpectedEquals ( self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " TRUE/FALSE for compress " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
Overrides . NeedCompress = self . _Token . upper ( ) == ' TRUE '
2009-09-11 05:14:43 +02:00
continue
2018-10-23 19:29:24 +02:00
if self . _IsToken ( T_CHAR_BRACE_R ) :
2009-09-11 05:14:43 +02:00
break
else :
EdkLogger . error ( " FdfParser " , FORMAT_INVALID , File = self . FileName , Line = self . CurrentLineNumber )
2009-07-17 11:10:31 +02:00
Obj . OverrideAttribs = Overrides
2018-07-05 11:40:04 +02:00
2018-10-23 19:29:19 +02:00
## _GetOptRomFileStatement() method
2009-07-17 11:10:31 +02:00
#
# Get FILE statements
#
# @param self The object pointer
# @param Obj for whom FILE statement is got
# @retval True Successfully find FILE statement
# @retval False Not able to find FILE statement
#
2018-10-23 19:29:19 +02:00
def _GetOptRomFileStatement ( self , Obj ) :
if not self . _IsKeyword ( " FILE " ) :
2009-07-17 11:10:31 +02:00
return False
2018-10-23 19:29:19 +02:00
FfsFileObj = OptRomFileStatement ( )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _IsKeyword ( " EFI " ) and not self . _IsKeyword ( BINARY_FILE_TYPE_BIN ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " Binary type (EFI/BIN) " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FfsFileObj . FileType = self . _Token
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if not self . _GetNextToken ( ) :
2018-10-23 19:29:23 +02:00
raise Warning . Expected ( " File path " , self . FileName , self . CurrentLineNumber )
2018-10-23 19:29:19 +02:00
FfsFileObj . FileName = self . _Token
if FfsFileObj . FileName . replace ( TAB_WORKSPACE , ' ' ) . find ( ' $ ' ) == - 1 :
2010-07-28 05:07:30 +02:00
#check for file path
ErrorCode , ErrorInfo = PathClass ( NormPath ( FfsFileObj . FileName ) , GenFdsGlobalVariable . WorkSpaceDir ) . Validate ( )
if ErrorCode != 0 :
EdkLogger . error ( " GenFds " , ErrorCode , ExtraData = ErrorInfo )
2009-07-17 11:10:31 +02:00
if FfsFileObj . FileType == ' EFI ' :
2018-10-23 19:29:19 +02:00
self . _GetOptRomOverrides ( FfsFileObj )
2018-07-05 11:40:04 +02:00
2009-07-17 11:10:31 +02:00
Obj . FfsList . append ( FfsFileObj )
return True
2009-09-11 05:14:43 +02:00
2018-10-23 19:29:19 +02:00
## _GetCapInFd() method
2009-09-11 05:14:43 +02:00
#
# Get Cap list contained in FD
#
# @param self The object pointer
# @param FdName FD name
# @retval CapList List of Capsule in FD
#
2018-10-23 19:29:19 +02:00
def _GetCapInFd ( self , FdName ) :
2009-09-11 05:14:43 +02:00
CapList = [ ]
2018-04-17 16:40:15 +02:00
if FdName . upper ( ) in self . Profile . FdDict :
2009-09-11 05:14:43 +02:00
FdObj = self . Profile . FdDict [ FdName . upper ( ) ]
for elementRegion in FdObj . RegionList :
if elementRegion . RegionType == ' CAPSULE ' :
for elementRegionData in elementRegion . RegionDataList :
if elementRegionData . endswith ( " .cap " ) :
continue
2018-03-26 22:25:43 +02:00
if elementRegionData is not None and elementRegionData . upper ( ) not in CapList :
2009-09-11 05:14:43 +02:00
CapList . append ( elementRegionData . upper ( ) )
return CapList
2018-10-23 19:29:19 +02:00
## _GetReferencedFdCapTuple() method
2009-09-11 05:14:43 +02:00
#
# Get FV and FD list referenced by a capsule image
#
# @param self The object pointer
# @param CapObj Capsule section to be searched
# @param RefFdList referenced FD by section
# @param RefFvList referenced FV by section
#
2018-10-23 19:29:19 +02:00
def _GetReferencedFdCapTuple ( self , CapObj , RefFdList = [ ] , RefFvList = [ ] ) :
for CapsuleDataObj in CapObj . CapsuleDataList :
2018-03-26 22:25:43 +02:00
if hasattr ( CapsuleDataObj , ' FvName ' ) and CapsuleDataObj . FvName is not None and CapsuleDataObj . FvName . upper ( ) not in RefFvList :
2009-09-11 05:14:43 +02:00
RefFvList . append ( CapsuleDataObj . FvName . upper ( ) )
2018-03-26 22:25:43 +02:00
elif hasattr ( CapsuleDataObj , ' FdName ' ) and CapsuleDataObj . FdName is not None and CapsuleDataObj . FdName . upper ( ) not in RefFdList :
2018-07-05 11:40:04 +02:00
RefFdList . append ( CapsuleDataObj . FdName . upper ( ) )
2018-03-26 22:25:43 +02:00
elif CapsuleDataObj . Ffs is not None :
2018-10-23 19:29:19 +02:00
if isinstance ( CapsuleDataObj . Ffs , FileStatement ) :
2018-03-26 22:25:43 +02:00
if CapsuleDataObj . Ffs . FvName is not None and CapsuleDataObj . Ffs . FvName . upper ( ) not in RefFvList :
2011-09-18 14:17:25 +02:00
RefFvList . append ( CapsuleDataObj . Ffs . FvName . upper ( ) )
2018-03-26 22:25:43 +02:00
elif CapsuleDataObj . Ffs . FdName is not None and CapsuleDataObj . Ffs . FdName . upper ( ) not in RefFdList :
2011-09-18 14:17:25 +02:00
RefFdList . append ( CapsuleDataObj . Ffs . FdName . upper ( ) )
else :
2018-10-23 19:29:19 +02:00
self . _GetReferencedFdFvTupleFromSection ( CapsuleDataObj . Ffs , RefFdList , RefFvList )
2009-09-11 05:14:43 +02:00
2018-10-23 19:29:19 +02:00
## _GetFvInFd() method
2009-07-17 11:10:31 +02:00
#
# Get FV list contained in FD
#
# @param self The object pointer
# @param FdName FD name
# @retval FvList list of FV in FD
#
2018-10-23 19:29:19 +02:00
def _GetFvInFd ( self , FdName ) :
2009-07-17 11:10:31 +02:00
FvList = [ ]
2018-04-17 16:40:15 +02:00
if FdName . upper ( ) in self . Profile . FdDict :
2009-07-17 11:10:31 +02:00
FdObj = self . Profile . FdDict [ FdName . upper ( ) ]
for elementRegion in FdObj . RegionList :
2018-04-26 18:57:56 +02:00
if elementRegion . RegionType == BINARY_FILE_TYPE_FV :
2009-07-17 11:10:31 +02:00
for elementRegionData in elementRegion . RegionDataList :
2009-09-11 05:14:43 +02:00
if elementRegionData . endswith ( " .fv " ) :
continue
2018-03-26 22:25:43 +02:00
if elementRegionData is not None and elementRegionData . upper ( ) not in FvList :
2009-07-17 11:10:31 +02:00
FvList . append ( elementRegionData . upper ( ) )
return FvList
2018-10-23 19:29:19 +02:00
## _GetReferencedFdFvTuple() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetReferencedFdFvTuple ( self , FvObj , RefFdList = [ ] , RefFvList = [ ] ) :
2009-07-17 11:10:31 +02:00
for FfsObj in FvObj . FfsList :
2018-10-23 19:29:19 +02:00
if isinstance ( FfsObj , FileStatement ) :
2018-03-26 22:25:43 +02:00
if FfsObj . FvName is not None and FfsObj . FvName . upper ( ) not in RefFvList :
2009-07-17 11:10:31 +02:00
RefFvList . append ( FfsObj . FvName . upper ( ) )
2018-03-26 22:25:43 +02:00
elif FfsObj . FdName is not None and FfsObj . FdName . upper ( ) not in RefFdList :
2009-07-17 11:10:31 +02:00
RefFdList . append ( FfsObj . FdName . upper ( ) )
else :
2018-10-23 19:29:19 +02:00
self . _GetReferencedFdFvTupleFromSection ( FfsObj , RefFdList , RefFvList )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
## _GetReferencedFdFvTupleFromSection() method
2009-07-17 11:10:31 +02:00
#
# 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
#
2018-10-23 19:29:19 +02:00
def _GetReferencedFdFvTupleFromSection ( self , FfsFile , FdList = [ ] , FvList = [ ] ) :
2018-10-23 19:29:20 +02:00
SectionStack = list ( FfsFile . SectionList )
2009-07-17 11:10:31 +02:00
while SectionStack != [ ] :
SectionObj = SectionStack . pop ( )
2018-10-23 19:29:19 +02:00
if isinstance ( SectionObj , FvImageSection ) :
2018-03-26 22:25:43 +02:00
if SectionObj . FvName is not None and SectionObj . FvName . upper ( ) not in FvList :
2009-07-17 11:10:31 +02:00
FvList . append ( SectionObj . FvName . upper ( ) )
2018-03-26 22:25:43 +02:00
if SectionObj . Fv is not None and SectionObj . Fv . UiFvName is not None and SectionObj . Fv . UiFvName . upper ( ) not in FvList :
2009-07-17 11:10:31 +02:00
FvList . append ( SectionObj . Fv . UiFvName . upper ( ) )
2018-10-23 19:29:19 +02:00
self . _GetReferencedFdFvTuple ( SectionObj . Fv , FdList , FvList )
2009-07-17 11:10:31 +02:00
2018-10-23 19:29:19 +02:00
if isinstance ( SectionObj , CompressSection ) or isinstance ( SectionObj , GuidSection ) :
2009-07-17 11:10:31 +02:00
SectionStack . extend ( SectionObj . SectionList )
## 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
#
def CycleReferenceCheck ( self ) :
2009-09-11 05:14:43 +02:00
#
# Check the cycle between FV and FD image
#
MaxLength = len ( self . Profile . FvDict )
2018-04-17 16:40:15 +02:00
for FvName in self . Profile . FvDict :
2009-09-11 05:14:43 +02:00
LogStr = " \n Cycle Reference Checking for FV: %s \n " % FvName
2018-10-23 19:29:20 +02:00
RefFvStack = set ( FvName )
FdAnalyzedList = set ( )
2018-07-05 11:40:04 +02:00
2009-09-11 05:14:43 +02:00
Index = 0
2018-10-23 19:29:19 +02:00
while RefFvStack and Index < MaxLength :
2009-09-11 05:14:43 +02:00
Index = Index + 1
FvNameFromStack = RefFvStack . pop ( )
2018-04-17 16:40:15 +02:00
if FvNameFromStack . upper ( ) in self . Profile . FvDict :
2009-09-11 05:14:43 +02:00
FvObj = self . Profile . FvDict [ FvNameFromStack . upper ( ) ]
else :
continue
2009-07-17 11:10:31 +02:00
2009-09-11 05:14:43 +02:00
RefFdList = [ ]
RefFvList = [ ]
2018-10-23 19:29:19 +02:00
self . _GetReferencedFdFvTuple ( FvObj , RefFdList , RefFvList )
2009-07-17 11:10:31 +02:00
2009-09-11 05:14:43 +02:00
for RefFdName in RefFdList :
if RefFdName in FdAnalyzedList :
2009-07-17 11:10:31 +02:00
continue
2009-09-11 05:14:43 +02:00
LogStr + = " FV %s contains FD %s \n " % ( FvNameFromStack , RefFdName )
2018-10-23 19:29:19 +02:00
FvInFdList = self . _GetFvInFd ( RefFdName )
2009-09-11 05:14:43 +02:00
if FvInFdList != [ ] :
for FvNameInFd in FvInFdList :
2018-06-25 12:31:33 +02:00
LogStr + = " FD %s contains FV %s \n " % ( RefFdName , FvNameInFd )
2009-09-11 05:14:43 +02:00
if FvNameInFd not in RefFvStack :
2018-10-23 19:29:20 +02:00
RefFvStack . add ( FvNameInFd )
2009-09-11 05:14:43 +02:00
if FvName in RefFvStack or FvNameFromStack in RefFvStack :
EdkLogger . info ( LogStr )
return True
2018-10-23 19:29:20 +02:00
FdAnalyzedList . add ( RefFdName )
2009-07-17 11:10:31 +02:00
2009-09-11 05:14:43 +02:00
for RefFvName in RefFvList :
LogStr + = " FV %s contains FV %s \n " % ( FvNameFromStack , RefFvName )
if RefFvName not in RefFvStack :
2018-10-23 19:29:20 +02:00
RefFvStack . add ( RefFvName )
2009-09-11 05:14:43 +02:00
if FvName in RefFvStack or FvNameFromStack in RefFvStack :
EdkLogger . info ( LogStr )
return True
#
# Check the cycle between Capsule and FD image
#
MaxLength = len ( self . Profile . CapsuleDict )
2018-04-17 16:40:15 +02:00
for CapName in self . Profile . CapsuleDict :
2009-09-11 05:14:43 +02:00
#
# Capsule image to be checked.
#
LogStr = " \n \n \n Cycle Reference Checking for Capsule: %s \n " % CapName
2018-10-23 19:29:20 +02:00
RefCapStack = { CapName }
FdAnalyzedList = set ( )
FvAnalyzedList = set ( )
2018-07-05 11:40:04 +02:00
2009-09-11 05:14:43 +02:00
Index = 0
2018-10-23 19:29:20 +02:00
while RefCapStack and Index < MaxLength :
2009-09-11 05:14:43 +02:00
Index = Index + 1
CapNameFromStack = RefCapStack . pop ( )
2018-04-17 16:40:15 +02:00
if CapNameFromStack . upper ( ) in self . Profile . CapsuleDict :
2009-09-11 05:14:43 +02:00
CapObj = self . Profile . CapsuleDict [ CapNameFromStack . upper ( ) ]
else :
continue
RefFvList = [ ]
RefFdList = [ ]
2018-10-23 19:29:19 +02:00
self . _GetReferencedFdCapTuple ( CapObj , RefFdList , RefFvList )
2009-09-11 05:14:43 +02:00
FvListLength = 0
FdListLength = 0
while FvListLength < len ( RefFvList ) or FdListLength < len ( RefFdList ) :
2009-07-17 11:10:31 +02:00
for RefFdName in RefFdList :
if RefFdName in FdAnalyzedList :
continue
2009-09-11 05:14:43 +02:00
LogStr + = " Capsule %s contains FD %s \n " % ( CapNameFromStack , RefFdName )
2018-10-23 19:29:20 +02:00
for CapNameInFd in self . _GetCapInFd ( RefFdName ) :
LogStr + = " FD %s contains Capsule %s \n " % ( RefFdName , CapNameInFd )
if CapNameInFd not in RefCapStack :
RefCapStack . append ( CapNameInFd )
if CapName in RefCapStack or CapNameFromStack in RefCapStack :
EdkLogger . info ( LogStr )
return True
for FvNameInFd in self . _GetFvInFd ( RefFdName ) :
LogStr + = " FD %s contains FV %s \n " % ( RefFdName , FvNameInFd )
if FvNameInFd not in RefFvList :
RefFvList . append ( FvNameInFd )
FdAnalyzedList . add ( RefFdName )
2009-09-11 05:14:43 +02:00
#
# the number of the parsed FV and FD image
#
FvListLength = len ( RefFvList )
FdListLength = len ( RefFdList )
2009-07-17 11:10:31 +02:00
for RefFvName in RefFvList :
2009-09-11 05:14:43 +02:00
if RefFvName in FvAnalyzedList :
continue
LogStr + = " Capsule %s contains FV %s \n " % ( CapNameFromStack , RefFvName )
2018-04-17 16:40:15 +02:00
if RefFvName . upper ( ) in self . Profile . FvDict :
2009-09-11 05:14:43 +02:00
FvObj = self . Profile . FvDict [ RefFvName . upper ( ) ]
else :
continue
2018-10-23 19:29:19 +02:00
self . _GetReferencedFdFvTuple ( FvObj , RefFdList , RefFvList )
2018-10-23 19:29:20 +02:00
FvAnalyzedList . add ( RefFvName )
2009-07-17 11:10:31 +02:00
2009-09-11 05:14:43 +02:00
return False
2009-07-17 11:10:31 +02:00
BaseTools: Skip module AutoGen by comparing timestamp.
[Introduction]
The BaseTool Build.py AutoGen parse INF meta-file and generate
AutoGen.c/AutoGen.h/makefile. When we only change .c .h code, the
AutoGen might be not necessary, but Build.py spend a lot of time on it.
There's a -u flag to skip all module's AutoGen. In my environment, it save
35%~50% of time in rebuild a ROM.
However, if user change one .INF meta-file, then -u flag is not available.
[Idea]
AutoGen can compare meta-file's timestamp and decide if the module's
AutoGen can be skipped. With this, when a module's INF is changed, we
only run this module's AutoGen, we don't need to run other module's.
[Implementation]
In the end of a module's AutoGen, we create a AutoGenTimeStamp.
The file save a file list that related to this module's AutoGen.
In other word, the file list in AutoGenTimeStamp is INPUT files of
module AutoGen, AutoGenTimeStamp file is OUTPUT.
During rebuild, we compare time stamp between INPUT and OUTPUT, and
decide if we can skip it.
Below is the Input/Output of a module's AutoGen.
[Input]
1. All the DSC/DEC/FDF used by the platform.
2. Macro and PCD defined by Build Options such as "build -D AAA=TRUE
--pcd BbbPcd=0".
3. INF file of a module.
4. Source files of a module, list in [Sources] section of INF.
5. All the library link by the module.
6. All the .h files included by the module's sources.
[Output]
AutoGen.c/AutoGen.h/makefile/AutoGenTimeStamp
[Testing]
This patch save my build time. When I make a change without touching
DSC/DEC/FDF, it is absolutely much faster than original rebuild,
35%~50% time saving in my environment
(compare to original tool rebuild time).
If I change any DSC/DEC/FDF, there's no performance improve, because it
can't skip any module's AutoGen.
Please note that if your environment will generate DSC/FDF during prebuild,
it will not skip any AutoGen because of DSC timestamp is changed. This will
require prebuild script not to update metafile when content is not changed.
2017-02-24 08:26:19 +01:00
def GetAllIncludedFile ( self ) :
global AllIncludeFileList
return AllIncludeFileList
2009-07-17 11:10:31 +02:00
if __name__ == " __main__ " :
2011-09-18 14:17:25 +02:00
import sys
try :
test_file = sys . argv [ 1 ]
2018-06-25 12:31:25 +02:00
except IndexError as v :
2018-06-25 12:31:26 +02:00
print ( " Usage: %s filename " % sys . argv [ 0 ] )
2011-09-18 14:17:25 +02:00
sys . exit ( 1 )
parser = FdfParser ( test_file )
2009-07-17 11:10:31 +02:00
try :
parser . ParseFile ( )
parser . CycleReferenceCheck ( )
2018-06-25 12:31:25 +02:00
except Warning as X :
2018-06-25 12:31:26 +02:00
print ( str ( X ) )
2009-07-17 11:10:31 +02:00
else :
2018-06-25 12:31:26 +02:00
print ( " Success! " )
2009-07-17 11:10:31 +02:00