diff options
author | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2010-02-28 23:39:39 +0000 |
---|---|---|
committer | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2010-02-28 23:39:39 +0000 |
commit | 52302d4dee589a5df43a464420c9fe68ba83937d (patch) | |
tree | 2393f61b9e8975134e3cdfa0352d4c51a3b2ac8d /BaseTools/Source/Python/GenFds | |
parent | fe35c036354c4b6bf18c4699a45156f3965fae2a (diff) | |
download | edk2-52302d4dee589a5df43a464420c9fe68ba83937d.tar.gz edk2-52302d4dee589a5df43a464420c9fe68ba83937d.tar.bz2 edk2-52302d4dee589a5df43a464420c9fe68ba83937d.zip |
Sync EDKII BaseTools to BaseTools project r1903.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10123 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Source/Python/GenFds')
-rw-r--r-- | BaseTools/Source/Python/GenFds/CompressSection.py | 4 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/DepexSection.py | 29 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/EfiSection.py | 30 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/FdfParser.py | 109 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/FfsFileStatement.py | 26 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/FfsInfStatement.py | 77 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/Fv.py | 57 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/FvImageSection.py | 8 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/GenFds.py | 62 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py | 37 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/GuidSection.py | 140 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/Section.py | 5 | ||||
-rw-r--r-- | BaseTools/Source/Python/GenFds/__init__.py | 15 |
13 files changed, 448 insertions, 151 deletions
diff --git a/BaseTools/Source/Python/GenFds/CompressSection.py b/BaseTools/Source/Python/GenFds/CompressSection.py index 4a32ea4458..7e126678a2 100644 --- a/BaseTools/Source/Python/GenFds/CompressSection.py +++ b/BaseTools/Source/Python/GenFds/CompressSection.py @@ -29,8 +29,8 @@ class CompressSection (CompressSectionClassObject) : ## compress types: PI standard and non PI standard
CompTypeDict = {
- 'PI_STD' : 'PI_STD',
- 'NON_PI_STD' : 'NON_PI_STD'
+ 'PI_STD' : 'PI_STD',
+ 'PI_NONE' : 'PI_NONE'
}
## The constructor
diff --git a/BaseTools/Source/Python/GenFds/DepexSection.py b/BaseTools/Source/Python/GenFds/DepexSection.py index a0a1905dfa..8650a73eb5 100644 --- a/BaseTools/Source/Python/GenFds/DepexSection.py +++ b/BaseTools/Source/Python/GenFds/DepexSection.py @@ -62,24 +62,27 @@ class DepexSection (DepexSectionClassObject): # @retval tuple (Generated file name list, section alignment)
#
def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}):
+
+ if self.ExpressionProcessed == False:
+ self.Expression = self.Expression.replace("\n", " ").replace("\r", " ")
+ ExpList = self.Expression.split()
+ ExpGuidDict = {}
- self.Expression = self.Expression.replace("\n", " ").replace("\r", " ")
- ExpList = self.Expression.split()
- ExpGuidDict = {}
+ for Exp in ExpList:
+ if Exp.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'):
+ GuidStr = self.__FindGuidValue(Exp)
+ if GuidStr == None:
+ EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE,
+ "Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp, ModuleName))
- for Exp in ExpList:
- if Exp.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'):
- GuidStr = self.__FindGuidValue(Exp)
- if GuidStr == None:
- EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE,
- "Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp, ModuleName))
+ ExpGuidDict[Exp] = GuidStr
- ExpGuidDict[Exp] = GuidStr
+ for Item in ExpGuidDict:
+ self.Expression = self.Expression.replace(Item, ExpGuidDict[Item])
- for Item in ExpGuidDict:
- self.Expression = self.Expression.replace(Item, ExpGuidDict[Item])
+ self.Expression = self.Expression.strip()
+ self.ExpressionProcessed = True
- self.Expression = self.Expression.strip()
if self.DepexType == 'PEI_DEPEX_EXP':
ModuleType = 'PEIM'
SecType = 'PEI_DEPEX'
diff --git a/BaseTools/Source/Python/GenFds/EfiSection.py b/BaseTools/Source/Python/GenFds/EfiSection.py index 2c112ed5cb..ad953facb9 100644 --- a/BaseTools/Source/Python/GenFds/EfiSection.py +++ b/BaseTools/Source/Python/GenFds/EfiSection.py @@ -15,6 +15,7 @@ ##
# Import Modules
#
+from struct import *
import Section
from GenFdsGlobalVariable import GenFdsGlobalVariable
import subprocess
@@ -24,6 +25,7 @@ from CommonDataClass.FdfClass import EfiSectionClassObject import shutil
from Common import EdkLogger
from Common.BuildToolError import *
+from Common.Misc import PeImageClass
## generate rule section
#
@@ -78,6 +80,12 @@ class EfiSection (EfiSectionClassObject): FileList = []
if Filename != None:
Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)
+ # check if the path is absolute or relative + if os.path.isabs(Filename): + Filename = os.path.normpath(Filename) + else: + Filename = os.path.normpath(os.path.join(FfsInf.EfiOutputPath, Filename)) +
if not self.Optional:
FileList.append(Filename)
elif os.path.exists(Filename):
@@ -121,7 +129,6 @@ class EfiSection (EfiSectionClassObject): f = open(File, 'r')
VerString = f.read()
f.close()
-# VerTuple = ('-n', '"' + VerString + '"')
BuildNum = VerString
if BuildNum != None and BuildNum != '':
BuildNumTuple = ('-j', BuildNum)
@@ -131,11 +138,6 @@ class EfiSection (EfiSectionClassObject): OutputFileList.append(OutputFile)
else:
-# if StringData != None and len(StringData) > 0:
-# VerTuple = ('-n', '"' + StringData + '"')
-# else:
-# VerTuple = tuple()
-# VerString = ' ' + ' '.join(VerTuple)
BuildNum = StringData
if BuildNum != None and BuildNum != '':
BuildNumTuple = ('-j', BuildNum)
@@ -221,6 +223,15 @@ class EfiSection (EfiSectionClassObject): Num = '%s.%d' %(SecNum , Index)
OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))
File = GenFdsGlobalVariable.MacroExtend(File, Dict)
+
+ #Get PE Section alignment when align is set to AUTO
+ if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):
+ ImageObj = PeImageClass (File)
+ if ImageObj.SectionAlignment < 0x400:
+ self.Alignment = str (ImageObj.SectionAlignment)
+ else:
+ self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'
+
if File[(len(File)-4):] == '.efi':
MapFile = File.replace('.efi', '.map')
if os.path.exists(MapFile):
@@ -237,24 +248,25 @@ class EfiSection (EfiSectionClassObject): StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')
GenFdsGlobalVariable.GenerateFirmwareImage(
StrippedFile,
- [GenFdsGlobalVariable.MacroExtend(File, Dict)],
+ [File],
Strip=True
)
File = StrippedFile
+
"""For TE Section call GenFw to generate TE image"""
if SectionType == 'TE':
TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')
GenFdsGlobalVariable.GenerateFirmwareImage(
TeFile,
- [GenFdsGlobalVariable.MacroExtend(File, Dict)],
+ [File],
Type='te'
)
File = TeFile
"""Call GenSection"""
GenFdsGlobalVariable.GenerateSection(OutputFile,
- [GenFdsGlobalVariable.MacroExtend(File)],
+ [File],
Section.Section.SectionType.get (SectionType)
)
OutputFileList.append(OutputFile)
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index 24732a0d5e..4ce2761243 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -40,6 +40,7 @@ import OptionRom import OptRomInfStatement
import OptRomFileStatement
+from GenFdsGlobalVariable import GenFdsGlobalVariable
from Common.BuildToolError import *
from Common import EdkLogger
@@ -172,6 +173,7 @@ class FileProfile : self.InfList = []
self.FdDict = {}
+ self.FdNameNotSet = False
self.FvDict = {}
self.CapsuleDict = {}
self.VtfList = []
@@ -1300,7 +1302,16 @@ class FdfParser: raise Warning("expected [FD.]", self.FileName, self.CurrentLineNumber)
FdName = self.__GetUiName()
+ if FdName == "":
+ if len (self.Profile.FdDict) == 0:
+ FdName = GenFdsGlobalVariable.PlatformName
+ self.Profile.FdNameNotSet = True
+ else:
+ raise Warning("expected FdName in [FD.] section", self.FileName, self.CurrentLineNumber)
self.CurrentFdName = FdName.upper()
+
+ if self.CurrentFdName in self.Profile.FdDict:
+ raise Warning("Unexpected the same FD name", self.FileName, self.CurrentLineNumber)
if not self.__IsToken( "]"):
raise Warning("expected ']'", self.FileName, self.CurrentLineNumber)
@@ -1308,12 +1319,15 @@ class FdfParser: FdObj = Fd.FD()
FdObj.FdUiName = self.CurrentFdName
self.Profile.FdDict[self.CurrentFdName] = FdObj
+
+ if len (self.Profile.FdDict) > 1 and self.Profile.FdNameNotSet:
+ raise Warning("expected all FDs have their name", self.FileName, self.CurrentLineNumber)
+
Status = self.__GetCreateFile(FdObj)
if not Status:
raise Warning("FD name error", self.FileName, self.CurrentLineNumber)
- if not self.__GetTokenStatements(FdObj):
- return False
+ self.__GetTokenStatements(FdObj)
self.__GetDefineStatements(FdObj)
@@ -1368,8 +1382,6 @@ class FdfParser: #
# @param self The object pointer
# @param Obj for whom token statement is got
- # @retval True Successfully find a token statement
- # @retval False Not able to find a token statement
#
def __GetTokenStatements(self, Obj):
if not self.__IsKeyword( "BaseAddress"):
@@ -1419,8 +1431,7 @@ class FdfParser: Obj.ErasePolarity = self.__Token
- Status = self.__GetBlockStatements(Obj)
- return Status
+ self.__GetBlockStatements(Obj)
## __GetAddressStatements() method
#
@@ -1459,17 +1470,20 @@ class FdfParser: #
# @param self The object pointer
# @param Obj for whom block statement is got
- # @retval True Successfully find
- # @retval False Not able to find
#
def __GetBlockStatements(self, Obj):
if not self.__GetBlockStatement(Obj):
- raise Warning("expected block statement", self.FileName, self.CurrentLineNumber)
+ #set default block size is 1
+ Obj.BlockSizeList.append((1, Obj.Size, None))
+ return
while self.__GetBlockStatement(Obj):
pass
- return True
+
+ for Item in Obj.BlockSizeList:
+ if Item[0] == None or Item[1] == None:
+ raise Warning("expected block statement for Fd Section", self.FileName, self.CurrentLineNumber)
## __GetBlockStatement() method
#
@@ -1496,7 +1510,7 @@ class FdfParser: PcdPair = self.__GetNextPcdName()
BlockSizePcd = PcdPair
self.Profile.PcdDict[PcdPair] = BlockSize
- BlockSize = long(self.__Token, 0)
+ BlockSize = long(BlockSize, 0)
BlockNumber = None
if self.__IsKeyword( "NumBlocks"):
@@ -2113,9 +2127,6 @@ class FdfParser: raise Warning("expected INF file path", self.FileName, self.CurrentLineNumber)
ffsInf.InfFileName = self.__Token
-# if ffsInf.InfFileName.find('$') >= 0:
-# ffsInf.InfFileName = GenFdsGlobalVariable.GenFdsGlobalVariable.MacroExtend(ffsInf.InfFileName, MacroDict)
-
if not ffsInf.InfFileName in self.Profile.InfList:
self.Profile.InfList.append(ffsInf.InfFileName)
@@ -2427,6 +2438,8 @@ class FdfParser: AlignValue = None
if self.__GetAlignment():
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):
+ raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
AlignValue = self.__Token
BuildNum = None
@@ -2440,6 +2453,8 @@ class FdfParser: BuildNum = self.__Token
if self.__IsKeyword( "VERSION"):
+ if AlignValue == 'Auto':
+ raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
@@ -2452,8 +2467,10 @@ class FdfParser: else:
VerSectionObj.FileName = self.__Token
Obj.SectionList.append(VerSectionObj)
-
+
elif self.__IsKeyword( "UI"):
+ if AlignValue == 'Auto':
+ raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
@@ -2467,6 +2484,8 @@ class FdfParser: Obj.SectionList.append(UiSectionObj)
elif self.__IsKeyword( "FV_IMAGE"):
+ if AlignValue == 'Auto':
+ raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
@@ -2508,6 +2527,8 @@ class FdfParser: Obj.SectionList.append(FvImageSectionObj)
elif self.__IsKeyword("PEI_DEPEX_EXP") or self.__IsKeyword("DXE_DEPEX_EXP") or self.__IsKeyword("SMM_DEPEX_EXP"):
+ if AlignValue == 'Auto':
+ raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
DepexSectionObj = DepexSection.DepexSection()
DepexSectionObj.Alignment = AlignValue
DepexSectionObj.DepexType = self.__Token
@@ -2523,7 +2544,6 @@ class FdfParser: Obj.SectionList.append(DepexSectionObj)
else:
-
if not self.__GetNextWord():
raise Warning("expected section type", self.FileName, self.CurrentLineNumber)
@@ -2535,6 +2555,9 @@ class FdfParser: if self.__Token not in ("COMPAT16", "PE32", "PIC", "TE", "FV_IMAGE", "RAW", "DXE_DEPEX",\
"UI", "VERSION", "PEI_DEPEX", "SUBTYPE_GUID", "SMM_DEPEX"):
raise Warning("Unknown section type '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
+ if AlignValue == 'Auto'and (not self.__Token == 'PE32') and (not self.__Token == 'TE'):
+ raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
+
# DataSection
DataSectionObj = DataSection.DataSection()
DataSectionObj.Alignment = AlignValue
@@ -2684,6 +2707,8 @@ class FdfParser: AlignValue = None
if self.__GetAlignment():
+ if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):
+ raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
AlignValue = self.__Token
if not self.__GetCglSection(FfsFileObj, AlignValue):
@@ -3013,9 +3038,11 @@ class FdfParser: AlignValue = ""
if self.__GetAlignment():
- if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
- AlignValue = self.__Token
+ #For FFS, Auto is default option same to ""
+ if not self.__Token == "Auto":
+ AlignValue = self.__Token
if self.__IsToken("{"):
# Complex file rule expected
@@ -3040,24 +3067,6 @@ class FdfParser: return Rule
- elif self.__IsToken("|"):
- # Ext rule expected
- Ext = self.__GetFileExtension()
-
- Rule = RuleSimpleFile.RuleSimpleFile()
-
- Rule.FvFileType = Type
- Rule.NameGuid = NameGuid
- Rule.Alignment = AlignValue
- Rule.CheckSum = CheckSum
- Rule.Fixed = Fixed
- Rule.FileExtension = Ext
- Rule.KeyStringList = KeyStringList
- if KeepReloc != None:
- Rule.KeepReloc = KeepReloc
-
- return Rule
-
else:
# Simple file rule expected
if not self.__GetNextWord():
@@ -3076,12 +3085,18 @@ class FdfParser: if self.__IsKeyword("CheckSum", True):
CheckSum = True
+ SectAlignment = ""
if self.__GetAlignment():
- if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
- AlignValue = self.__Token
+ if self.__Token == 'Auto' and (not SectionName == 'PE32') and (not SectionName == 'TE'):
+ raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
+ SectAlignment = self.__Token
- if not self.__GetNextToken():
+ Ext = None
+ if self.__IsToken('|'):
+ Ext = self.__GetFileExtension()
+ elif not self.__GetNextToken():
raise Warning("expected File name", self.FileName, self.CurrentLineNumber)
Rule = RuleSimpleFile.RuleSimpleFile()
@@ -3089,12 +3104,14 @@ class FdfParser: Rule.FvFileType = Type
Rule.NameGuid = NameGuid
Rule.Alignment = AlignValue
+ Rule.SectAlignment = SectAlignment
Rule.CheckSum = CheckSum
Rule.Fixed = Fixed
- Rule.FileName = self.__Token
Rule.KeyStringList = KeyStringList
if KeepReloc != None:
Rule.KeepReloc = KeepReloc
+ Rule.FileExtension = Ext
+ Rule.FileName = self.__Token
return Rule
## __GetEfiSection() method
@@ -3153,14 +3170,6 @@ class FdfParser: raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
FvImageSectionObj.Alignment = self.__Token
- if self.__IsKeyword("FV"):
- FvImageSectionObj.FvFileType = self.__Token
-
- if self.__GetAlignment():
- if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):
- raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
- FvImageSectionObj.Alignment = self.__Token
-
if self.__IsToken('|'):
FvImageSectionObj.FvFileExtension = self.__GetFileExtension()
elif self.__GetNextToken():
@@ -3224,6 +3233,10 @@ class FdfParser: EfiSectionObj.BuildNum = self.__Token
if self.__GetAlignment():
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):
+ raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
+ if self.__Token == 'Auto' and (not SectionName == 'PE32') and (not SectionName == 'TE'):
+ raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
EfiSectionObj.Alignment = self.__Token
if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'):
diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py b/BaseTools/Source/Python/GenFds/FfsFileStatement.py index e3f2e68fb8..b0b1b00c7e 100644 --- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py @@ -1,7 +1,7 @@ ## @file
# process FFS generation from FILE statement
#
-# Copyright (c) 2007, Intel Corporation
+# Copyright (c) 2007 - 2010, Intel Corporation
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -17,14 +17,17 @@ #
import Ffs
import Rule
-from GenFdsGlobalVariable import GenFdsGlobalVariable
import os
import StringIO
import subprocess
+
+from GenFdsGlobalVariable import GenFdsGlobalVariable
from CommonDataClass.FdfClass import FileStatementClassObject
from Common import EdkLogger
from Common.BuildToolError import *
from Common.Misc import GuidStructureByteArrayToGuidString
+from GuidSection import GuidSection
+from FvImageSection import FvImageSection
## generate FFS from FILE
#
@@ -41,11 +44,13 @@ class FileStatement (FileStatementClassObject) : #
# Generate FFS
#
- # @param self The object pointer
- # @param Dict dictionary contains macro and value pair
- # @retval string Generated FFS file name
+ # @param self The object pointer
+ # @param Dict dictionary contains macro and value pair
+ # @param FvChildAddr Array of the inside FvImage base address
+ # @param FvParentAddr Parent Fv base address
+ # @retval string Generated FFS file name
#
- def GenFfs(self, Dict = {}):
+ def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None):
if self.NameGuid != None and self.NameGuid.startswith('PCD('):
PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)
@@ -92,6 +97,15 @@ class FileStatement (FileStatementClassObject) : for section in self.SectionList :
Index = Index + 1
SecIndex = '%d' %Index
+ # process the inside FvImage from FvSection or GuidSection
+ if FvChildAddr != []:
+ if isinstance(section, FvImageSection):
+ section.FvAddr = FvChildAddr.pop(0)
+ elif isinstance(section, GuidSection):
+ section.FvAddr = FvChildAddr
+ if FvParentAddr != None and isinstance(section, GuidSection):
+ section.FvParentAddr = FvParentAddr
+
sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)
if sectList != []:
for sect in sectList:
diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py index ac13e4d7d9..b00e5a2178 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -1,7 +1,7 @@ ## @file
# process FFS generation from INF statement
#
-# Copyright (c) 2007, Intel Corporation
+# Copyright (c) 2007 - 2010, Intel Corporation
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -31,6 +31,9 @@ from Common.Misc import PathClass from Common.Misc import GuidStructureByteArrayToGuidString
from Common import EdkLogger
from Common.BuildToolError import *
+from GuidSection import GuidSection
+from FvImageSection import FvImageSection
+from Common.Misc import PeImageClass
## generate FFS from INF
#
@@ -90,7 +93,7 @@ class FfsInfStatement(FfsInfStatementClassObject): self.BaseName = Inf.BaseName
self.ModuleGuid = Inf.Guid
self.ModuleType = Inf.ModuleType
- if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification: + if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification:
self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION']
if Inf.AutoGenVersion < 0x00010005:
self.ModuleType = Inf.ComponentType
@@ -105,7 +108,7 @@ class FfsInfStatement(FfsInfStatementClassObject): self.BaseName = Inf.BaseName
self.ModuleGuid = Inf.Guid
self.ModuleType = Inf.ModuleType
- if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification: + if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification:
self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION']
self.VersionString = Inf.Version
self.BinFileList = Inf.Binaries
@@ -118,7 +121,7 @@ class FfsInfStatement(FfsInfStatementClassObject): if len(self.SourceFileList) != 0 and not self.InDsc:
EdkLogger.warn("GenFds", GENFDS_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % (self.InfFileName))
- if self.ModuleType == 'SMM_CORE' and self.PiSpecVersion < 0x0001000A: + if self.ModuleType == 'SMM_CORE' and self.PiSpecVersion < 0x0001000A:
EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File=self.InfFileName)
if Inf._Defs != None and len(Inf._Defs) > 0:
@@ -146,11 +149,13 @@ class FfsInfStatement(FfsInfStatementClassObject): #
# Generate FFS
#
- # @param self The object pointer
- # @param Dict dictionary contains macro and value pair
- # @retval string Generated FFS file name
+ # @param self The object pointer
+ # @param Dict dictionary contains macro and value pair
+ # @param FvChildAddr Array of the inside FvImage base address
+ # @param FvParentAddr Parent Fv base address
+ # @retval string Generated FFS file name
#
- def GenFfs(self, Dict = {}):
+ def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None):
#
# Parse Inf file get Module related information
#
@@ -184,7 +189,7 @@ class FfsInfStatement(FfsInfStatementClassObject): # For Rule has ComplexFile
#
elif isinstance(Rule, RuleComplexFile.RuleComplexFile):
- InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule)
+ InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule, FvChildAddr, FvParentAddr)
FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList, InputSectAlignments)
return FfsOutput
@@ -393,8 +398,13 @@ class FfsInfStatement(FfsInfStatementClassObject): #
FileList = []
OutputFileList = []
+ GenSecInputFile = None
if Rule.FileName != None:
GenSecInputFile = self.__ExtendMacro__(Rule.FileName)
+ if os.path.isabs(GenSecInputFile): + GenSecInputFile = os.path.normpath(GenSecInputFile) + else: + GenSecInputFile = os.path.normpath(os.path.join(self.EfiOutputPath, GenSecInputFile))
else:
FileList, IsSect = Section.Section.GetFileList(self, '', Rule.FileExtension)
@@ -429,6 +439,15 @@ class FfsInfStatement(FfsInfStatementClassObject): Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum
Index = Index + 1
OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)
+ File = GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)
+
+ #Get PE Section alignment when align is set to AUTO
+ if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):
+ ImageObj = PeImageClass (File)
+ if ImageObj.SectionAlignment < 0x400:
+ self.Alignment = str (ImageObj.SectionAlignment)
+ else:
+ self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'
if not NoStrip:
FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')
@@ -438,7 +457,7 @@ class FfsInfStatement(FfsInfStatementClassObject): StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')
GenFdsGlobalVariable.GenerateFirmwareImage(
StrippedFile,
- [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],
+ [File],
Strip=True
)
File = StrippedFile
@@ -447,7 +466,7 @@ class FfsInfStatement(FfsInfStatementClassObject): TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')
GenFdsGlobalVariable.GenerateFirmwareImage(
TeFile,
- [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],
+ [File],
Type='te'
)
File = TeFile
@@ -459,6 +478,15 @@ class FfsInfStatement(FfsInfStatementClassObject): GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \
Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum
OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)
+ GenSecInputFile = GenFdsGlobalVariable.MacroExtend(GenSecInputFile, Dict, self.CurrentArch)
+
+ #Get PE Section alignment when align is set to AUTO
+ if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):
+ ImageObj = PeImageClass (GenSecInputFile)
+ if ImageObj.SectionAlignment < 0x400:
+ self.Alignment = str (ImageObj.SectionAlignment)
+ else:
+ self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'
if not NoStrip:
FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')
@@ -468,7 +496,7 @@ class FfsInfStatement(FfsInfStatementClassObject): StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')
GenFdsGlobalVariable.GenerateFirmwareImage(
StrippedFile,
- [GenFdsGlobalVariable.MacroExtend(GenSecInputFile, Dict, self.CurrentArch)],
+ [GenSecInputFile],
Strip=True
)
GenSecInputFile = StrippedFile
@@ -477,7 +505,7 @@ class FfsInfStatement(FfsInfStatementClassObject): TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')
GenFdsGlobalVariable.GenerateFirmwareImage(
TeFile,
- [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],
+ [GenSecInputFile],
Type='te'
)
GenSecInputFile = TeFile
@@ -507,7 +535,7 @@ class FfsInfStatement(FfsInfStatementClassObject): SectionAlignments = []
for InputFile in InputFileList:
InputSection.append(InputFile)
- SectionAlignments.append(Rule.Alignment)
+ SectionAlignments.append(Rule.SectAlignment)
if Rule.NameGuid != None and Rule.NameGuid.startswith('PCD('):
PcdValue = GenFdsGlobalVariable.GetPcdValue(Rule.NameGuid)
@@ -534,11 +562,13 @@ class FfsInfStatement(FfsInfStatementClassObject): #
# Generate section by sections in Rule
#
- # @param self The object pointer
- # @param Rule The rule object used to generate section
- # @retval string File name of the generated section file
+ # @param self The object pointer
+ # @param Rule The rule object used to generate section
+ # @param FvChildAddr Array of the inside FvImage base address
+ # @param FvParentAddr Parent Fv base address
+ # @retval string File name of the generated section file
#
- def __GenComplexFileSection__(self, Rule):
+ def __GenComplexFileSection__(self, Rule, FvChildAddr, FvParentAddr):
if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):
if Rule.KeepReloc != None:
self.KeepRelocFromRule = Rule.KeepReloc
@@ -560,6 +590,17 @@ class FfsInfStatement(FfsInfStatementClassObject): if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion < 0x0001000A:
if Sect.SectionType == 'SMM_DEPEX':
EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)
+ #
+ # process the inside FvImage from FvSection or GuidSection
+ #
+ if FvChildAddr != []:
+ if isinstance(Sect, FvImageSection):
+ Sect.FvAddr = FvChildAddr.pop(0)
+ elif isinstance(Sect, GuidSection):
+ Sect.FvAddr = FvChildAddr
+ if FvParentAddr != None and isinstance(Sect, GuidSection):
+ Sect.FvParentAddr = FvParentAddr
+
if Rule.KeyStringList != []:
SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self)
else :
diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py index 6190bceba8..8d2ef1d874 100644 --- a/BaseTools/Source/Python/GenFds/Fv.py +++ b/BaseTools/Source/Python/GenFds/Fv.py @@ -1,7 +1,7 @@ ## @file
# process FV generation
#
-# Copyright (c) 2007, Intel Corporation
+# Copyright (c) 2007 - 2010, Intel Corporation
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -63,7 +63,7 @@ class FV (FvClassObject): #
def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None, MacroDict = {}) :
- if self.UiFvName.upper() + 'fv' in GenFds.ImageBinDict.keys():
+ if BaseAddress == None and self.UiFvName.upper() + 'fv' in GenFds.ImageBinDict.keys():
return GenFds.ImageBinDict[self.UiFvName.upper() + 'fv']
#
@@ -103,7 +103,7 @@ class FV (FvClassObject): # Process Modules in FfsList
for FfsFile in self.FfsList :
- FileName = FfsFile.GenFfs(MacroDict)
+ FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress)
FfsFileList.append(FileName)
self.FvInfFile.writelines("EFI_FILE_NAME = " + \
FileName + \
@@ -122,6 +122,9 @@ class FV (FvClassObject): FvInfoFileName = os.path.join(GenFdsGlobalVariable.FfsDir, self.UiFvName + '.inf')
shutil.copy(GenFdsGlobalVariable.FvAddressFileName, FvInfoFileName)
+ OrigFvInfo = None
+ if os.path.exists (FvInfoFileName):
+ OrigFvInfo = open(FvInfoFileName, 'r').read()
GenFdsGlobalVariable.GenerateFirmwareVolume(
FvOutputFile,
[self.InfFileName],
@@ -129,6 +132,35 @@ class FV (FvClassObject): FfsList=FfsFileList
)
+ NewFvInfo = None
+ if os.path.exists (FvInfoFileName):
+ NewFvInfo = open(FvInfoFileName, 'r').read()
+ if NewFvInfo != None and NewFvInfo != OrigFvInfo:
+ FvChildAddr = []
+ AddFileObj = open(FvInfoFileName, 'r')
+ AddrStrings = AddFileObj.readlines()
+ AddrKeyFound = False
+ for AddrString in AddrStrings:
+ if AddrKeyFound:
+ #get base address for the inside FvImage
+ FvChildAddr.append (AddrString)
+ elif AddrString.find ("[FV_BASE_ADDRESS]") != -1:
+ AddrKeyFound = True
+ AddFileObj.close()
+
+ if FvChildAddr != []:
+ # Update Ffs again
+ for FfsFile in self.FfsList :
+ FileName = FfsFile.GenFfs(MacroDict, FvChildAddr, BaseAddress)
+
+ #Update GenFv again
+ GenFdsGlobalVariable.GenerateFirmwareVolume(
+ FvOutputFile,
+ [self.InfFileName],
+ AddressFile=FvInfoFileName,
+ FfsList=FfsFileList
+ )
+
#
# Write the Fv contents to Buffer
#
@@ -138,6 +170,21 @@ class FV (FvClassObject): GenFdsGlobalVariable.SharpCounter = 0
Buffer.write(FvFileObj.read())
+ FvFileObj.seek(0)
+ # PI FvHeader is 0x48 byte
+ FvHeaderBuffer = FvFileObj.read(0x48)
+ # FV alignment position.
+ FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)
+ # FvAlignmentValue is larger than or equal to 1K
+ if FvAlignmentValue >= 0x400:
+ if FvAlignmentValue >= 0x10000:
+ #The max alignment supported by FFS is 64K.
+ self.FvAlignment = "64K"
+ else:
+ self.FvAlignment = str (FvAlignmentValue / 0x400) + "K"
+ else:
+ # FvAlignmentValue is less than 1K
+ self.FvAlignment = str (FvAlignmentValue)
FvFileObj.close()
GenFds.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile
return FvOutputFile
@@ -179,6 +226,10 @@ class FV (FvClassObject): ' 0x%X' %BlockNum + \
T_CHAR_LF)
else:
+ if self.BlockSizeList == []:
+ #set default block size is 1
+ self.FvInfFile.writelines("EFI_BLOCK_SIZE = 0x1" + T_CHAR_LF)
+
for BlockSize in self.BlockSizeList :
if BlockSize[0] != None:
self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \
diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py b/BaseTools/Source/Python/GenFds/FvImageSection.py index 3a3e714228..c945ce9b9b 100644 --- a/BaseTools/Source/Python/GenFds/FvImageSection.py +++ b/BaseTools/Source/Python/GenFds/FvImageSection.py @@ -73,7 +73,13 @@ class FvImageSection(FvImageSectionClassObject): Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)
if Fv != None:
self.Fv = Fv
- FvFileName = self.Fv.AddToBuffer(Buffer, MacroDict = Dict)
+ FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict)
+ if Fv.FvAlignment != None:
+ if self.Alignment == None:
+ self.Alignment = Fv.FvAlignment
+ else:
+ if GenFdsGlobalVariable.GetAlignment (Fv.FvAlignment) > GenFdsGlobalVariable.GetAlignment (self.Alignment):
+ self.Alignment = Fv.FvAlignment
else:
if self.FvFileName != None:
FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)
diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py index 1df19100d3..1285103f5e 100644 --- a/BaseTools/Source/Python/GenFds/GenFds.py +++ b/BaseTools/Source/Python/GenFds/GenFds.py @@ -1,7 +1,7 @@ ## @file # generate flash image # -# Copyright (c) 2007, Intel Corporation +# Copyright (c) 2007 - 2010, Intel Corporation # # All rights reserved. This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -39,7 +39,7 @@ from Common.Misc import DirCache,PathClass ## Version and Copyright versionNumber = "1.0" __version__ = "%prog Version " + versionNumber -__copyright__ = "Copyright (c) 2007, Intel Corporation All rights reserved." +__copyright__ = "Copyright (c) 2007 - 2010, Intel Corporation All rights reserved." ## Tool entrance method # @@ -94,6 +94,18 @@ def main(): if (Options.filename): FdfFilename = Options.filename FdfFilename = GenFdsGlobalVariable.ReplaceWorkspaceMacro(FdfFilename) + + if FdfFilename[0:2] == '..': + FdfFilename = os.path.realpath(FdfFilename) + if not os.path.isabs (FdfFilename): + FdfFilename = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, FdfFilename) + if not os.path.exists(FdfFilename): + EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=FdfFilename) + if os.path.normcase (FdfFilename).find(Workspace) != 0: + EdkLogger.error("GenFds", FILE_NOT_FOUND, "FdfFile doesn't exist in Workspace!") + + GenFdsGlobalVariable.FdfFile = FdfFilename + GenFdsGlobalVariable.FdfFileTimeStamp = os.path.getmtime(FdfFilename) else: EdkLogger.error("GenFds", OPTION_MISSING, "Missing FDF filename") @@ -107,16 +119,6 @@ def main(): else: EdkLogger.error("GenFds", OPTION_MISSING, "Missing tool chain tag") - if FdfFilename[0:2] == '..': - FdfFilename = os.path.realpath(FdfFilename) - if FdfFilename[1] != ':': - FdfFilename = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, FdfFilename) - - if not os.path.exists(FdfFilename): - EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=FdfFilename) - GenFdsGlobalVariable.FdfFile = FdfFilename - GenFdsGlobalVariable.FdfFileTimeStamp = os.path.getmtime(FdfFilename) - if (Options.activePlatform): ActivePlatform = Options.activePlatform ActivePlatform = GenFdsGlobalVariable.ReplaceWorkspaceMacro(ActivePlatform) @@ -124,22 +126,22 @@ def main(): if ActivePlatform[0:2] == '..': ActivePlatform = os.path.realpath(ActivePlatform) - if ActivePlatform[1] != ':': + if not os.path.isabs (ActivePlatform): ActivePlatform = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, ActivePlatform) if not os.path.exists(ActivePlatform) : EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist!") - if ActivePlatform.find(Workspace) == -1: + if os.path.normcase (ActivePlatform).find(Workspace) != 0: EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist in Workspace!") - ActivePlatform = ActivePlatform.replace(Workspace, '') + ActivePlatform = ActivePlatform[len(Workspace):] if len(ActivePlatform) > 0 : if ActivePlatform[0] == '\\' or ActivePlatform[0] == '/': ActivePlatform = ActivePlatform[1:] else: EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist!") - else : + else: EdkLogger.error("GenFds", OPTION_MISSING, "Missing active platform") GenFdsGlobalVariable.ActivePlatform = PathClass(NormPath(ActivePlatform), Workspace) @@ -190,9 +192,14 @@ def main(): for Arch in ArchList: GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = NormPath(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].OutputDirectory) + GenFdsGlobalVariable.PlatformName = BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].PlatformName if (Options.outputDir): OutputDirFromCommandLine = GenFdsGlobalVariable.ReplaceWorkspaceMacro(Options.outputDir) + if not os.path.isabs (Options.outputDir): + Options.outputDir = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, Options.outputDir) + if os.path.normcase (Options.outputDir).find(Workspace) != 0: + EdkLogger.error("GenFds", FILE_NOT_FOUND, "OutputDir doesn't exist in Workspace!") for Arch in ArchList: GenFdsGlobalVariable.OutputDirDict[Arch] = OutputDirFromCommandLine else: @@ -237,10 +244,13 @@ def main(): GenFds.PreprocessImage(BuildWorkSpace, GenFdsGlobalVariable.ActivePlatform) """Call GenFds""" GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList) - + + """Generate GUID cross reference file""" + GenFds.GenerateGuidXRefFile(BuildWorkSpace, ArchList) + """Display FV space info.""" GenFds.DisplayFvSpaceInfo(FdfParserObj) - + except FdfParser.Warning, X: EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError = False) ReturnCode = FORMAT_INVALID @@ -352,7 +362,7 @@ class GenFds : # Get FV base Address FvObj.AddToBuffer(Buffer, None, GenFds.GetFvBlockSize(FvObj)) Buffer.close() - + if GenFds.OnlyGenerateThisFv == None and GenFds.OnlyGenerateThisFd == None: if GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict != {}: GenFdsGlobalVariable.VerboseLogger("\n Generate other Capsule images!") @@ -372,7 +382,7 @@ class GenFds : # @retval int Block size value # def GetFvBlockSize(FvObj): - DefaultBlockSize = 0x10000 + DefaultBlockSize = 0x1 FdObj = None if GenFds.OnlyGenerateThisFd != None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[GenFds.OnlyGenerateThisFd.upper()] @@ -476,11 +486,23 @@ class GenFds : ModuleObj = BuildDb.BuildObject[Key, 'COMMON'] print ModuleObj.BaseName + ' ' + ModuleObj.ModuleType + def GenerateGuidXRefFile(BuildDb, ArchList): + GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref") + GuidXRefFile = open(GuidXRefFileName, "w+") + for Arch in ArchList: + PlatformDataBase = BuildDb.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch] + for ModuleFile in PlatformDataBase.Modules: + Module = BuildDb.BuildObject[ModuleFile, Arch] + GuidXRefFile.write("%s %s\n" % (Module.Guid, Module.BaseName)) + GuidXRefFile.close() + GenFdsGlobalVariable.InfLogger("\nGUID cross reference file saved to %s" % GuidXRefFileName) + ##Define GenFd as static function GenFd = staticmethod(GenFd) GetFvBlockSize = staticmethod(GetFvBlockSize) DisplayFvSpaceInfo = staticmethod(DisplayFvSpaceInfo) PreprocessImage = staticmethod(PreprocessImage) + GenerateGuidXRefFile = staticmethod(GenerateGuidXRefFile) if __name__ == '__main__': r = main() diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py index b54e8c88e2..cad2758627 100644 --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py @@ -1,7 +1,7 @@ ## @file # Global variables for GenFds # -# Copyright (c) 2007, Intel Corporation +# Copyright (c) 2007 - 2010, Intel Corporation # # All rights reserved. This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -54,6 +54,7 @@ class GenFdsGlobalVariable: FdfFile = '' FdfFileTimeStamp = 0 FixedLoadAddress = False + PlatformName = '' SectionHeader = struct.Struct("3B 1B") @@ -154,7 +155,7 @@ class GenFdsGlobalVariable: @staticmethod def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None, - GuidHdrLen=None, GuidAttr=None, Ui=None, Ver=None): + GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None): if not GenFdsGlobalVariable.NeedsUpdate(Output, Input): return GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input)) @@ -168,8 +169,14 @@ class GenFdsGlobalVariable: Cmd += ["-g", Guid] if GuidHdrLen not in [None, '']: Cmd += ["-l", GuidHdrLen] - if GuidAttr not in [None, '']: - Cmd += ["-r", GuidAttr] + if len(GuidAttr) != 0: + #Add each guided attribute + for Attr in GuidAttr: + Cmd += ["-r", Attr] + if InputAlign != None: + #Section Align is only for dummy section without section type + for SecAlign in InputAlign: + Cmd += ["--sectionalign", SecAlign] if Ui not in [None, '']: #Cmd += ["-n", '"' + Ui + '"'] @@ -195,6 +202,15 @@ class GenFdsGlobalVariable: GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section") @staticmethod + def GetAlignment (AlignString): + if AlignString == None: + return 0 + if AlignString in ("1K", "2K", "4K", "8K", "16K", "32K", "64K"):
+ return int (AlignString.rstrip('K')) * 1024
+ else:
+ return int (AlignString)
+ + @staticmethod def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None, SectionAlign=None): if not GenFdsGlobalVariable.NeedsUpdate(Output, Input): @@ -331,18 +347,19 @@ class GenFdsGlobalVariable: GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom") @staticmethod - def GuidTool(Output, Input, ToolPath, Options=''): + def GuidTool(Output, Input, ToolPath, Options='', returnValue=[]): if not GenFdsGlobalVariable.NeedsUpdate(Output, Input): return GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input)) - Cmd = [ToolPath, Options] + Cmd = [ToolPath, ] + Cmd += Options.split(' ') Cmd += ["-o", Output] Cmd += Input - GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath) + GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue) - def CallExternalTool (cmd, errorMess): + def CallExternalTool (cmd, errorMess, returnValue=[]): if type(cmd) not in (tuple, list): GenFdsGlobalVariable.ErrorLogger("ToolError! Invalid parameter type in call to CallExternalTool") @@ -369,6 +386,10 @@ class GenFdsGlobalVariable: while PopenObject.returncode == None : PopenObject.wait() + if returnValue != [] and returnValue[0] != 0: + #get command return value + returnValue[0] = PopenObject.returncode + return if PopenObject.returncode != 0 or GenFdsGlobalVariable.VerboseMode or GenFdsGlobalVariable.DebugLevel != -1: GenFdsGlobalVariable.InfLogger ("Return Value = %d" %PopenObject.returncode) GenFdsGlobalVariable.InfLogger (out) diff --git a/BaseTools/Source/Python/GenFds/GuidSection.py b/BaseTools/Source/Python/GenFds/GuidSection.py index e111e0fe50..d967880472 100644 --- a/BaseTools/Source/Python/GenFds/GuidSection.py +++ b/BaseTools/Source/Python/GenFds/GuidSection.py @@ -1,7 +1,7 @@ ## @file
# process GUIDed section generation
#
-# Copyright (c) 2007, Intel Corporation
+# Copyright (c) 2007 - 2010, Intel Corporation
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -25,6 +25,7 @@ from Common import ToolDefClassObject import sys
from Common import EdkLogger
from Common.BuildToolError import *
+from FvImageSection import FvImageSection
## generate GUIDed section
#
@@ -63,16 +64,57 @@ class GuidSection(GuidSectionClassObject) : self.SectionType = FfsInf.__ExtendMacro__(self.SectionType)
self.CurrentArchList = [FfsInf.CurrentArch]
- SectFile = tuple()
+ SectFile = tuple()
+ SectAlign = []
Index = 0
+ MaxAlign = None
+ if self.FvAddr != []:
+ FvAddrIsSet = True
+ else:
+ FvAddrIsSet = False
+
+ if self.ProcessRequired in ("TRUE", "1"):
+ if self.FvAddr != []:
+ #no use FvAddr when the image is processed.
+ self.FvAddr = []
+ if self.FvParentAddr != None:
+ #no use Parent Addr when the image is processed.
+ self.FvParentAddr = None
+
for Sect in self.SectionList:
Index = Index + 1
SecIndex = '%s.%d' %(SecNum,Index)
+ # set base address for inside FvImage
+ if isinstance(Sect, FvImageSection):
+ if self.FvAddr != []:
+ Sect.FvAddr = self.FvAddr.pop(0)
+ self.IncludeFvSection = True
+ elif isinstance(Sect, GuidSection):
+ Sect.FvAddr = self.FvAddr
+ Sect.FvParentAddr = self.FvParentAddr
ReturnSectList, align = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList,FfsInf, Dict)
+ if isinstance(Sect, GuidSection):
+ if Sect.IncludeFvSection:
+ self.IncludeFvSection = Sect.IncludeFvSection
+
+ if align != None:
+ if MaxAlign == None:
+ MaxAlign = align
+ if GenFdsGlobalVariable.GetAlignment (align) > GenFdsGlobalVariable.GetAlignment (MaxAlign):
+ MaxAlign = align
if ReturnSectList != []:
+ if align == None:
+ align = "1"
for file in ReturnSectList:
SectFile += (file,)
+ SectAlign.append(align)
+ if MaxAlign != None:
+ if self.Alignment == None:
+ self.Alignment = MaxAlign
+ else:
+ if GenFdsGlobalVariable.GetAlignment (MaxAlign) > GenFdsGlobalVariable.GetAlignment (self.Alignment):
+ self.Alignment = MaxAlign
OutputFile = OutputPath + \
os.sep + \
@@ -83,15 +125,17 @@ class GuidSection(GuidSectionClassObject) : OutputFile = os.path.normpath(OutputFile)
ExternalTool = None
+ ExternalOption = None
if self.NameGuid != None:
- ExternalTool = self.__FindExtendTool__()
+ ExternalTool, ExternalOption = self.__FindExtendTool__()
+
#
# If not have GUID , call default
# GENCRC32 section
#
if self.NameGuid == None :
GenFdsGlobalVariable.VerboseLogger( "Use GenSection function Generate CRC32 Section")
- GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.Section.SectionType[self.SectionType])
+ GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.Section.SectionType[self.SectionType], InputAlign=SectAlign)
OutputFileList = []
OutputFileList.append(OutputFile)
return OutputFileList, self.Alignment
@@ -99,14 +143,14 @@ class GuidSection(GuidSectionClassObject) : elif ExternalTool == None:
EdkLogger.error("GenFds", GENFDS_ERROR, "No tool found with GUID %s" % self.NameGuid)
else:
+ DummyFile = OutputFile+".dummy"
#
# Call GenSection with DUMMY section type.
#
- GenFdsGlobalVariable.GenerateSection(OutputFile+".dummy", SectFile)
+ GenFdsGlobalVariable.GenerateSection(DummyFile, SectFile, InputAlign=SectAlign)
#
# Use external tool process the Output
#
- InputFile = OutputFile+".dummy"
TempFile = OutputPath + \
os.sep + \
ModuleName + \
@@ -115,30 +159,76 @@ class GuidSection(GuidSectionClassObject) : '.tmp'
TempFile = os.path.normpath(TempFile)
- ExternalToolCmd = (
- ExternalTool,
- '-e',
- '-o', TempFile,
- InputFile,
- )
-
+ FirstCall = False
+ CmdOption = '-e'
+ if ExternalOption != None:
+ CmdOption = CmdOption + ' ' + ExternalOption
+ if self.ProcessRequired not in ("TRUE", "1") and self.IncludeFvSection and not FvAddrIsSet and self.FvParentAddr != None:
+ #FirstCall is only set for the encapsulated flash FV image without process required attribute.
+ FirstCall = True
#
# Call external tool
#
- GenFdsGlobalVariable.GuidTool(TempFile, [InputFile], ExternalTool, '-e')
+ ReturnValue = [1]
+ if FirstCall:
+ #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.
+ GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, '-z' + ' ' + CmdOption, ReturnValue)
#
- # Call Gensection Add Secntion Header
+ # when no call or first call failed, ReturnValue are not 1.
+ # Call the guided tool with CmdOption
#
- Attribute = None
- if self.ProcessRequired == True:
- Attribute = 'PROCSSING_REQUIRED'
- if self.AuthStatusValid == True:
- Attribute = 'AUTH_STATUS_VALID'
+ if ReturnValue[0] != 0:
+ FirstCall = False
+ ReturnValue[0] = 0
+ GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption)
+
+ FileHandleIn = open(DummyFile,'rb')
+ FileHandleIn.seek(0,2)
+ InputFileSize = FileHandleIn.tell()
+
+ FileHandleOut = open(TempFile,'rb')
+ FileHandleOut.seek(0,2)
+ TempFileSize = FileHandleOut.tell()
+
+ Attribute = []
+ HeaderLength = None
+ if TempFileSize > InputFileSize and TempFileSize % 4 == 0:
+ FileHandleIn.seek(0)
+ BufferIn = FileHandleIn.read()
+ FileHandleOut.seek(0)
+ BufferOut = FileHandleOut.read()
+ if BufferIn == BufferOut[TempFileSize - InputFileSize:]:
+ HeaderLength = str(TempFileSize - InputFileSize)
+ #auto sec guided attribute with process required
+ if HeaderLength == None:
+ Attribute.append('PROCESSING_REQUIRED')
+
+ FileHandleIn.close()
+ FileHandleOut.close()
+
+ if FirstCall and 'PROCESSING_REQUIRED' in Attribute:
+ # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.
+ GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption)
+
+ #
+ # Call Gensection Add Section Header
+ #
+ if self.ProcessRequired in ("TRUE", "1"):
+ if 'PROCESSING_REQUIRED' not in Attribute:
+ Attribute.append('PROCESSING_REQUIRED')
+ HeaderLength = None
+ if self.AuthStatusValid in ("TRUE", "1"):
+ Attribute.append('AUTH_STATUS_VALID')
GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],
- Guid=self.NameGuid, GuidAttr=Attribute)
+ Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength)
OutputFileList = []
OutputFileList.append(OutputFile)
+ if 'PROCESSING_REQUIRED' in Attribute:
+ # reset guided section alignment to none for the processed required guided data
+ self.Alignment = None
+ self.IncludeFvSection = False
+ self.ProcessRequired = "TRUE"
return OutputFileList, self.Alignment
## __FindExtendTool()
@@ -177,6 +267,12 @@ class GuidSection(GuidSectionClassObject) : KeyList[3] + \
'_' + \
'PATH')
+
+ ToolOption = ToolDefinition.get( Key + \
+ '_' + \
+ KeyList[3] + \
+ '_' + \
+ 'FLAGS')
if ToolPathTmp == None:
ToolPathTmp = ToolPath
else:
@@ -184,7 +280,7 @@ class GuidSection(GuidSectionClassObject) : EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))
- return ToolPathTmp
+ return ToolPathTmp, ToolOption
diff --git a/BaseTools/Source/Python/GenFds/Section.py b/BaseTools/Source/Python/GenFds/Section.py index 1905935ebf..2e24697a3d 100644 --- a/BaseTools/Source/Python/GenFds/Section.py +++ b/BaseTools/Source/Python/GenFds/Section.py @@ -140,7 +140,6 @@ class Section (SectionClassObject): GenFdsGlobalVariable.InfLogger ("\nCurrent ARCH \'%s\' of File %s is not in the Support Arch Scope of %s specified by INF %s in FDF" %(FfsInf.CurrentArch, File.File, File.Arch, FfsInf.InfFileName))
if Suffix != None and os.path.exists(FfsInf.EfiOutputPath):
-# FileList.extend(glob.glob(os.path.join(FfsInf.EfiOutputPath, "*" + Suffix)))
# Update to search files with suffix in all sub-dirs.
Tuple = os.walk(FfsInf.EfiOutputPath)
for Dirpath, Dirnames, Filenames in Tuple:
@@ -149,5 +148,9 @@ class Section (SectionClassObject): FullName = os.path.join(Dirpath, F)
FileList.append(FullName)
+ #Process the file lists is alphabetical for a same section type
+ if len (FileList) > 1:
+ FileList.sort()
+
return FileList, IsSect
GetFileList = staticmethod(GetFileList)
diff --git a/BaseTools/Source/Python/GenFds/__init__.py b/BaseTools/Source/Python/GenFds/__init__.py index e69de29bb2..1c5796affe 100644 --- a/BaseTools/Source/Python/GenFds/__init__.py +++ b/BaseTools/Source/Python/GenFds/__init__.py @@ -0,0 +1,15 @@ +## @file
+# Python 'GenFds' package initialization file.
+#
+# This file is required to make Python interpreter treat the directory
+# as containing package.
+#
+# Copyright (c) 2007 - 2010, Intel Corporation<BR>
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
|