Sync BaseTool trunk (version r2610) into EDKII BaseTools.

Signed-off-by: Liming Gao <liming.gao@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14856 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Liming Gao
2013-11-18 07:41:21 +00:00
committed by lgao4
parent fddbbc661e
commit e8a47801a1
65 changed files with 3487 additions and 1302 deletions

View File

@ -1,7 +1,7 @@
## @file
# parse FDF file
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@ -1423,7 +1423,15 @@ class FdfParser:
if not Status:
raise Warning("FD name error", self.FileName, self.CurrentLineNumber)
self.__GetTokenStatements(FdObj)
while self.__GetTokenStatements(FdObj):
pass
for Attr in ("BaseAddress", "Size", "ErasePolarity"):
if getattr(FdObj, Attr) == None:
self.__GetNextToken()
raise Warning("Keyword %s missing" % Attr, self.FileName, self.CurrentLineNumber)
if not FdObj.BlockSizeList:
FdObj.BlockSizeList.append((1, FdObj.Size, None))
self.__GetDefineStatements(FdObj)
@ -1480,58 +1488,54 @@ class FdfParser:
# @param Obj for whom token statement is got
#
def __GetTokenStatements(self, Obj):
if not self.__IsKeyword( "BaseAddress"):
raise Warning("BaseAddress missing", self.FileName, self.CurrentLineNumber)
if self.__IsKeyword( "BaseAddress"):
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if not self.__GetNextHexNumber():
raise Warning("expected Hex base address", self.FileName, self.CurrentLineNumber)
Obj.BaseAddress = self.__Token
if self.__IsToken( "|"):
pcdPair = self.__GetNextPcdName()
Obj.BaseAddressPcd = pcdPair
self.Profile.PcdDict[pcdPair] = Obj.BaseAddress
FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)
self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple
return True
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if self.__IsKeyword( "Size"):
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if not self.__GetNextHexNumber():
raise Warning("expected Hex size", self.FileName, self.CurrentLineNumber)
if not self.__GetNextHexNumber():
raise Warning("expected Hex base address", self.FileName, self.CurrentLineNumber)
Size = self.__Token
if self.__IsToken( "|"):
pcdPair = self.__GetNextPcdName()
Obj.SizePcd = pcdPair
self.Profile.PcdDict[pcdPair] = Size
FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)
self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple
Obj.Size = long(Size, 0)
return True
Obj.BaseAddress = self.__Token
if self.__IsKeyword( "ErasePolarity"):
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
raise Warning("expected Erase Polarity", self.FileName, self.CurrentLineNumber)
if self.__Token != "1" and self.__Token != "0":
raise Warning("expected 1 or 0 Erase Polarity", self.FileName, self.CurrentLineNumber)
Obj.ErasePolarity = self.__Token
return True
if self.__IsToken( "|"):
pcdPair = self.__GetNextPcdName()
Obj.BaseAddressPcd = pcdPair
self.Profile.PcdDict[pcdPair] = Obj.BaseAddress
FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)
self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple
if not self.__IsKeyword( "Size"):
raise Warning("Size missing", self.FileName, self.CurrentLineNumber)
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if not self.__GetNextHexNumber():
raise Warning("expected Hex size", self.FileName, self.CurrentLineNumber)
Size = self.__Token
if self.__IsToken( "|"):
pcdPair = self.__GetNextPcdName()
Obj.SizePcd = pcdPair
self.Profile.PcdDict[pcdPair] = Size
FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)
self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple
Obj.Size = long(Size, 0)
if not self.__IsKeyword( "ErasePolarity"):
raise Warning("ErasePolarity missing", self.FileName, self.CurrentLineNumber)
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
raise Warning("expected Erase Polarity", self.FileName, self.CurrentLineNumber)
if self.__Token != "1" and self.__Token != "0":
raise Warning("expected 1 or 0 Erase Polarity", self.FileName, self.CurrentLineNumber)
Obj.ErasePolarity = self.__Token
self.__GetBlockStatements(Obj)
return self.__GetBlockStatements(Obj)
## __GetAddressStatements() method
#
@ -1572,18 +1576,14 @@ class FdfParser:
# @param Obj for whom block statement is got
#
def __GetBlockStatements(self, Obj):
if not self.__GetBlockStatement(Obj):
#set default block size is 1
Obj.BlockSizeList.append((1, Obj.Size, None))
return
IsBlock = False
while self.__GetBlockStatement(Obj):
pass
IsBlock = True
for Item in Obj.BlockSizeList:
Item = Obj.BlockSizeList[-1]
if Item[0] == None or Item[1] == None:
raise Warning("expected block statement", self.FileName, self.CurrentLineNumber)
return IsBlock
## __GetBlockStatement() method
#
@ -2038,27 +2038,16 @@ class FdfParser:
self.__GetAddressStatements(FvObj)
while self.__GetBlockStatement(FvObj):
pass
self.__GetSetStatements(FvObj)
self.__GetFvBaseAddress(FvObj)
self.__GetFvForceRebase(FvObj)
self.__GetFvAlignment(FvObj)
self.__GetFvAttributes(FvObj)
self.__GetFvNameGuid(FvObj)
FvObj.FvExtEntryTypeValue = []
FvObj.FvExtEntryType = []
FvObj.FvExtEntryData = []
while True:
isFvExtEntry = self.__GetFvExtEntryStatement(FvObj)
if not isFvExtEntry:
self.__GetSetStatements(FvObj)
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)):
break
self.__GetAprioriSection(FvObj, FvObj.DefineVarDict.copy())
@ -2177,9 +2166,9 @@ class FdfParser:
"WRITE_DISABLED_CAP", "WRITE_STATUS", "READ_ENABLED_CAP", \
"READ_DISABLED_CAP", "READ_STATUS", "READ_LOCK_CAP", \
"READ_LOCK_STATUS", "WRITE_LOCK_CAP", "WRITE_LOCK_STATUS", \
"WRITE_POLICY_RELIABLE"):
"WRITE_POLICY_RELIABLE", "WEAK_ALIGNMENT"):
self.__UndoToken()
return
return False
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
@ -2189,7 +2178,7 @@ class FdfParser:
FvObj.FvAttributeDict[name] = self.__Token
return
return True
## __GetFvNameGuid() method
#
@ -2202,7 +2191,7 @@ class FdfParser:
def __GetFvNameGuid(self, FvObj):
if not self.__IsKeyword( "FvNameGuid"):
return
return False
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
@ -2212,7 +2201,7 @@ class FdfParser:
FvObj.FvNameGuid = self.__Token
return
return True
def __GetFvExtEntryStatement(self, FvObj):
@ -3058,7 +3047,7 @@ class FdfParser:
def __GetCapsuleTokens(self, Obj):
if not self.__GetNextToken():
return False
while self.__Token in ("CAPSULE_GUID", "CAPSULE_HEADER_SIZE", "CAPSULE_FLAGS"):
while self.__Token in ("CAPSULE_GUID", "CAPSULE_HEADER_SIZE", "CAPSULE_FLAGS", "OEM_CAPSULE_FLAGS"):
Name = self.__Token.strip()
if not self.__IsToken("="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
@ -3075,6 +3064,15 @@ class FdfParser:
if not self.__Token in ("PersistAcrossReset", "PopulateSystemTable", "InitiateReset"):
raise Warning("expected PersistAcrossReset, PopulateSystemTable, or InitiateReset", self.FileName, self.CurrentLineNumber)
Value += self.__Token.strip()
elif Name == 'OEM_CAPSULE_FLAGS':
Value = self.__Token.strip()
try:
Value = int(Value, 0)
except ValueError:
raise Warning("expected integer value between 0x0000 and 0xFFFF", self.FileName, self.CurrentLineNumber)
if not 0x0000 <= Value <= 0xFFFF:
raise Warning("expected integer value between 0x0000 and 0xFFFF", self.FileName, self.CurrentLineNumber)
Value = self.__Token.strip()
else:
Value = self.__Token.strip()
Obj.TokensDict[Name] = Value

View File

@ -37,6 +37,7 @@ from GuidSection import GuidSection
from FvImageSection import FvImageSection
from Common.Misc import PeImageClass
from AutoGen.GenDepex import DependencyExpression
from PatchPcdValue.PatchPcdValue import PatchBinaryFile
## generate FFS from INF
#
@ -203,14 +204,80 @@ class FfsInfStatement(FfsInfStatementClassObject):
if Inf._Defs != None and len(Inf._Defs) > 0:
self.OptRomDefs.update(Inf._Defs)
self.PatchPcds = []
InfPcds = Inf.Pcds
Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
FdfPcdDict = GenFdsGlobalVariable.FdfParser.Profile.PcdDict
DscModules = {}
for DscModule in Platform.Modules:
DscModules[str(DscModule).lower()] = Platform.Modules[DscModule]
for PcdKey in InfPcds:
Pcd = InfPcds[PcdKey]
if not hasattr(Pcd, 'Offset'):
continue
if Pcd.Type != 'PatchableInModule':
continue
PatchPcd = None
InfLowerPath = str(PathClassObj).lower()
if InfLowerPath in DscModules and PcdKey in DscModules[InfLowerPath].Pcds:
PatchPcd = DscModules[InfLowerPath].Pcds[PcdKey]
elif PcdKey in Platform.Pcds:
PatchPcd = Platform.Pcds[PcdKey]
DscOverride = False
if PatchPcd and Pcd.Type == PatchPcd.Type:
DefaultValue = PatchPcd.DefaultValue
DscOverride = True
FdfOverride = False
if PcdKey in FdfPcdDict:
DefaultValue = FdfPcdDict[PcdKey]
FdfOverride = True
if not DscOverride and not FdfOverride:
continue
if Pcd.DatumType == "VOID*":
if Pcd.DefaultValue == DefaultValue or DefaultValue in [None, '']:
continue
if DefaultValue[0] == 'L':
MaxDatumSize = str((len(DefaultValue) - 2) * 2)
elif DefaultValue[0] == '{':
MaxDatumSize = str(len(DefaultValue.split(',')))
else:
MaxDatumSize = str(len(DefaultValue) - 1)
if DscOverride:
Pcd.MaxDatumSize = PatchPcd.MaxDatumSize
if Pcd.MaxDatumSize in ['', None]:
Pcd.MaxDatumSize = str(len(Pcd.DefaultValue.split(',')))
else:
Base1 = Base2 = 10
if Pcd.DefaultValue.upper().startswith('0X'):
Base1 = 16
if DefaultValue.upper().startswith('0X'):
Base2 = 16
try:
PcdValueInImg = int(Pcd.DefaultValue, Base1)
PcdValueInDscOrFdf = int(DefaultValue, Base2)
if PcdValueInImg == PcdValueInDscOrFdf:
continue
except:
continue
if Pcd.DatumType == "VOID*":
if int(MaxDatumSize) > int(Pcd.MaxDatumSize):
EdkLogger.error("GenFds", GENFDS_ERROR, "The size of VOID* type PCD '%s.%s' exceeds its maximum size %d bytes." \
% (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, int(MaxDatumSize) - int(Pcd.MaxDatumSize)))
else:
if PcdValueInDscOrFdf > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType] \
or PcdValueInImg > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType]:
EdkLogger.error("GenFds", GENFDS_ERROR, "The size of %s type PCD '%s.%s' doesn't match its data type." \
% (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
Pcd.DefaultValue = DefaultValue
self.PatchPcds.append(Pcd)
self.InfModule = Inf
GenFdsGlobalVariable.VerboseLogger( "BaseName : %s" %self.BaseName)
GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" %self.ModuleGuid)
GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" %self.ModuleType)
GenFdsGlobalVariable.VerboseLogger("VersionString : %s" %self.VersionString)
GenFdsGlobalVariable.VerboseLogger("InfFileName :%s" %self.InfFileName)
self.PcdIsDriver = Inf.PcdIsDriver
self.IsBinaryModule = Inf.IsBinaryModule
GenFdsGlobalVariable.VerboseLogger("BaseName : %s" % self.BaseName)
GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" % self.ModuleGuid)
GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" % self.ModuleType)
GenFdsGlobalVariable.VerboseLogger("VersionString : %s" % self.VersionString)
GenFdsGlobalVariable.VerboseLogger("InfFileName :%s" % self.InfFileName)
#
# Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${MdouleName}\
@ -224,6 +291,27 @@ class FfsInfStatement(FfsInfStatementClassObject):
self.EfiOutputPath = self.__GetEFIOutPutPath__()
GenFdsGlobalVariable.VerboseLogger( "ModuelEFIPath: " + self.EfiOutputPath)
## PatchEfiFile
#
# Patch EFI file with patch PCD
#
# @param EfiFile: EFI file needs to be patched.
# @retval: Full path of patched EFI file: self.OutputPath + EfiFile base name
# If passed in file does not end with efi, return as is
#
def PatchEfiFile(self, EfiFile):
if os.path.splitext(EfiFile)[1].lower() != '.efi':
return EfiFile
if not self.PatchPcds:
return EfiFile
Basename = os.path.basename(EfiFile)
Output = os.path.join(self.OutputPath, Basename)
CopyLongFilePath(EfiFile, Output)
for Pcd in self.PatchPcds:
RetVal, RetStr = PatchBinaryFile(Output, int(Pcd.Offset, 0), Pcd.DatumType, Pcd.DefaultValue, Pcd.MaxDatumSize)
if RetVal:
EdkLogger.error("GenFds", GENFDS_ERROR, RetStr, File=self.InfFileName)
return Output
## GenFfs() method
#
# Generate FFS
@ -668,6 +756,30 @@ class FfsInfStatement(FfsInfStatementClassObject):
SectAlignments = []
Index = 1
HasGneratedFlag = False
if self.PcdIsDriver == 'PEI_PCD_DRIVER':
if self.IsBinaryModule:
PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "PEIPcdDataBase.raw")
else:
PcdExDbFileName = os.path.join(self.EfiOutputPath, "PEIPcdDataBase.raw")
PcdExDbSecName = os.path.join(self.OutputPath, "PEIPcdDataBaseSec.raw")
GenFdsGlobalVariable.GenerateSection(PcdExDbSecName,
[PcdExDbFileName],
"EFI_SECTION_RAW",
)
SectFiles.append(PcdExDbSecName)
SectAlignments.append(None)
elif self.PcdIsDriver == 'DXE_PCD_DRIVER':
if self.IsBinaryModule:
PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "DXEPcdDataBase.raw")
else:
PcdExDbFileName = os.path.join(self.EfiOutputPath, "DXEPcdDataBase.raw")
PcdExDbSecName = os.path.join(self.OutputPath, "DXEPcdDataBaseSec.raw")
GenFdsGlobalVariable.GenerateSection(PcdExDbSecName,
[PcdExDbFileName],
"EFI_SECTION_RAW",
)
SectFiles.append(PcdExDbSecName)
SectAlignments.append(None)
for Sect in Rule.SectionList:
SecIndex = '%d' %Index
SectList = []

View File

@ -131,7 +131,7 @@ class Section (SectionClassObject):
if File.Arch == "COMMON" or FfsInf.CurrentArch == File.Arch:
if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A and FileType == 'DXE_DPEX'and File.Type == 'SMM_DEPEX'):
if '*' in FfsInf.TargetOverrideList or File.Target == '*' or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []:
FileList.append(File.Path)
FileList.append(FfsInf.PatchEfiFile(File.Path))
else:
GenFdsGlobalVariable.InfLogger ("\nBuild Target \'%s\' of File %s is not in the Scope of %s specified by INF %s in FDF" %(File.Target, File.File, FfsInf.TargetOverrideList, FfsInf.InfFileName))
else: