X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FFfsInfStatement.py;h=d4c61c0749636a0e1375bd8a2c29c6112ab814e5;hp=dfff892e21491e51c251c4a88dc3b6906bb44800;hb=8ef653aa5aad4ec994f1c0bc16e2fde266b0eb6b;hpb=0537f332c968e6c3adeefa2222b5f1aa7252b711
diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
index dfff892e21..d4c61c0749 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 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# Copyright (c) 2014-2016 Hewlett-Packard Development Company, L.P.
#
# This program and the accompanying materials
@@ -16,44 +16,44 @@
##
# Import Modules
#
-import Rule
+from __future__ import absolute_import
+from . import Rule
import Common.LongFilePathOs as os
-import StringIO
+from io import BytesIO
from struct import *
-from GenFdsGlobalVariable import GenFdsGlobalVariable
-import Ffs
+from .GenFdsGlobalVariable import GenFdsGlobalVariable
+from .Ffs import SectionSuffix,FdfFvFileTypeToFileType
import subprocess
import sys
-import Section
-import RuleSimpleFile
-import RuleComplexFile
+from . import Section
+from . import RuleSimpleFile
+from . import RuleComplexFile
from CommonDataClass.FdfClass import FfsInfStatementClassObject
from Common.MultipleWorkspace import MultipleWorkspace as mws
-from Common.String import *
+from Common.StringUtils import *
from Common.Misc import PathClass
from Common.Misc import GuidStructureByteArrayToGuidString
from Common.Misc import ProcessDuplicatedInf
from Common.Misc import GetVariableOffset
from Common import EdkLogger
from Common.BuildToolError import *
-from GuidSection import GuidSection
-from FvImageSection import FvImageSection
+from .GuidSection import GuidSection
+from .FvImageSection import FvImageSection
from Common.Misc import PeImageClass
from AutoGen.GenDepex import DependencyExpression
from PatchPcdValue.PatchPcdValue import PatchBinaryFile
from Common.LongFilePathSupport import CopyLongFilePath
from Common.LongFilePathSupport import OpenLongFilePath as open
import Common.GlobalData as GlobalData
-from DepexSection import DepexSection
+from .DepexSection import DepexSection
from Common.Misc import SaveFileOnChange
from Common.Expression import *
+from Common.DataType import *
## generate FFS from INF
#
#
class FfsInfStatement(FfsInfStatementClassObject):
- ## The mapping dictionary from datum type to its maximum number.
- _MAX_SIZE_TYPE = {"BOOLEAN":0x01, "UINT8":0xFF, "UINT16":0xFFFF, "UINT32":0xFFFFFFFF, "UINT64":0xFFFFFFFFFFFFFFFF}
## The constructor
#
# @param self The object pointer
@@ -89,7 +89,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
self.FinalTargetSuffixMap.setdefault(os.path.splitext(File)[1], []).append(File)
# Check if current INF module has DEPEX
- if '.depex' not in self.FinalTargetSuffixMap and self.InfModule.ModuleType != "USER_DEFINED" \
+ if '.depex' not in self.FinalTargetSuffixMap and self.InfModule.ModuleType != SUP_MODULE_USER_DEFINED \
and not self.InfModule.DxsFile and not self.InfModule.LibraryClass:
ModuleType = self.InfModule.ModuleType
PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
@@ -185,7 +185,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
InfLowerPath = str(PathClassObj).lower()
if self.OverrideGuid:
PathClassObj = ProcessDuplicatedInf(PathClassObj, self.OverrideGuid, GenFdsGlobalVariable.WorkSpaceDir)
- if self.CurrentArch != None:
+ if self.CurrentArch is not None:
Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
#
@@ -194,22 +194,22 @@ 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 is not None and 'PI_SPECIFICATION_VERSION' in Inf.Specification:
self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION']
if Inf.AutoGenVersion < 0x00010005:
self.ModuleType = Inf.ComponentType
self.VersionString = Inf.Version
self.BinFileList = Inf.Binaries
self.SourceFileList = Inf.Sources
- if self.KeepReloc == None and Inf.Shadow:
+ if self.KeepReloc is None and Inf.Shadow:
self.ShadowFromInfFile = Inf.Shadow
else:
- Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
+ Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, TAB_COMMON, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
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 is not None and 'PI_SPECIFICATION_VERSION' in Inf.Specification:
self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION']
self.VersionString = Inf.Version
self.BinFileList = Inf.Binaries
@@ -225,13 +225,13 @@ 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 int(self.PiSpecVersion, 16) < 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 self.ModuleType == SUP_MODULE_SMM_CORE and int(self.PiSpecVersion, 16) < 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 self.ModuleType == 'MM_CORE_STANDALONE' and int(self.PiSpecVersion, 16) < 0x00010032:
+ if self.ModuleType == SUP_MODULE_MM_CORE_STANDALONE and int(self.PiSpecVersion, 16) < 0x00010032:
EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "MM_CORE_STANDALONE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x00010032", File=self.InfFileName)
- if Inf._Defs != None and len(Inf._Defs) > 0:
+ if Inf._Defs is not None and len(Inf._Defs) > 0:
self.OptRomDefs.update(Inf._Defs)
self.PatchPcds = []
@@ -250,7 +250,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
Pcd = InfPcds[PcdKey]
if not hasattr(Pcd, 'Offset'):
continue
- if Pcd.Type != 'PatchableInModule':
+ if Pcd.Type != TAB_PCDS_PATCHABLE_IN_MODULE:
continue
# Override Patchable PCD value by the value from DSC
PatchPcd = None
@@ -274,7 +274,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
if GlobalData.BuildOptionPcd:
for pcd in GlobalData.BuildOptionPcd:
if PcdKey == (pcd[1], pcd[0]):
- DefaultValue = pcd[2]
+ if pcd[2]:
+ continue
+ DefaultValue = pcd[3]
BuildOptionOverride = True
break
@@ -288,15 +290,15 @@ class FfsInfStatement(FfsInfStatementClassObject):
except BadExpression:
EdkLogger.error("GenFds", GENFDS_ERROR, 'PCD [%s.%s] Value "%s"' %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValue), File=self.InfFileName)
- if Pcd.DefaultValue:
+ if Pcd.InfDefaultValue:
try:
- Pcd.DefaultValue = ValueExpressionEx(Pcd.DefaultValue, Pcd.DatumType, Platform._GuidDict)(True)
+ Pcd.InfDefaultValue = ValueExpressionEx(Pcd.InfDefaultValue, Pcd.DatumType, Platform._GuidDict)(True)
except BadExpression:
- EdkLogger.error("GenFds", GENFDS_ERROR, 'PCD [%s.%s] Value "%s"' %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DefaultValue),File=self.InfFileName)
+ EdkLogger.error("GenFds", GENFDS_ERROR, 'PCD [%s.%s] Value "%s"' %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DefaultValue), File=self.InfFileName)
# Check value, if value are equal, no need to patch
- if Pcd.DatumType == "VOID*":
- if Pcd.DefaultValue == DefaultValue or DefaultValue in [None, '']:
+ if Pcd.DatumType == TAB_VOID:
+ if Pcd.InfDefaultValue == DefaultValue or not DefaultValue:
continue
# Get the string size from FDF or DSC
if DefaultValue[0] == 'L':
@@ -309,29 +311,29 @@ class FfsInfStatement(FfsInfStatementClassObject):
if DscOverride:
Pcd.MaxDatumSize = PatchPcd.MaxDatumSize
# If no defined the maximum size in DSC, try to get current size from INF
- if Pcd.MaxDatumSize in ['', None]:
- Pcd.MaxDatumSize = str(len(Pcd.DefaultValue.split(',')))
+ if not Pcd.MaxDatumSize:
+ Pcd.MaxDatumSize = str(len(Pcd.InfDefaultValue.split(',')))
else:
Base1 = Base2 = 10
- if Pcd.DefaultValue.upper().startswith('0X'):
+ if Pcd.InfDefaultValue.upper().startswith('0X'):
Base1 = 16
if DefaultValue.upper().startswith('0X'):
Base2 = 16
try:
- PcdValueInImg = int(Pcd.DefaultValue, Base1)
+ PcdValueInImg = int(Pcd.InfDefaultValue, Base1)
PcdValueInDscOrFdf = int(DefaultValue, Base2)
if PcdValueInImg == PcdValueInDscOrFdf:
continue
except:
continue
# Check the Pcd size and data type
- if Pcd.DatumType == "VOID*":
+ if Pcd.DatumType == TAB_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]:
+ if PcdValueInDscOrFdf > MAX_VAL_TYPE[Pcd.DatumType] \
+ or PcdValueInImg > MAX_VAL_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))
self.PatchPcds.append((Pcd, DefaultValue))
@@ -339,9 +341,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
self.InfModule = Inf
self.PcdIsDriver = Inf.PcdIsDriver
self.IsBinaryModule = Inf.IsBinaryModule
- Inf._GetDepex()
- Inf._GetDepexExpression()
- if len(Inf._Depex.data) > 0 and len(Inf._DepexExpression.data) > 0:
+ if len(Inf.Depex.data) > 0 and len(Inf.DepexExpression.data) > 0:
self.Depex = True
GenFdsGlobalVariable.VerboseLogger("BaseName : %s" % self.BaseName)
@@ -373,14 +373,14 @@ class FfsInfStatement(FfsInfStatementClassObject):
def PatchEfiFile(self, EfiFile, FileType):
#
# If the module does not have any patches, then return path to input file
- #
+ #
if not self.PatchPcds:
return EfiFile
#
# Only patch file if FileType is PE32 or ModuleType is USER_DEFINED
- #
- if FileType != 'PE32' and self.ModuleType != "USER_DEFINED":
+ #
+ if FileType != BINARY_FILE_TYPE_PE32 and self.ModuleType != SUP_MODULE_USER_DEFINED:
return EfiFile
#
@@ -397,7 +397,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
#
# If a different file from the same module has already been patched, then generate an error
- #
+ #
if self.PatchedBinFile:
EdkLogger.error("GenFds", GENFDS_ERROR,
'Only one binary file can be patched:\n'
@@ -407,12 +407,12 @@ class FfsInfStatement(FfsInfStatementClassObject):
#
# Copy unpatched file contents to output file location to perform patching
- #
+ #
CopyLongFilePath(EfiFile, Output)
#
# Apply patches to patched output file
- #
+ #
for Pcd, Value in self.PatchPcds:
RetVal, RetStr = PatchBinaryFile(Output, int(Pcd.Offset, 0), Pcd.DatumType, Value, Pcd.MaxDatumSize)
if RetVal:
@@ -420,12 +420,12 @@ class FfsInfStatement(FfsInfStatementClassObject):
#
# Save the path of the patched output file
- #
+ #
self.PatchedBinFile = Output
#
# Return path to patched output file
- #
+ #
return Output
## GenFfs() method
@@ -445,16 +445,16 @@ class FfsInfStatement(FfsInfStatementClassObject):
self.__InfParse__(Dict)
Arch = self.GetCurrentArch()
- SrcFile = mws.join( GenFdsGlobalVariable.WorkSpaceDir , self.InfFileName);
+ SrcFile = mws.join( GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName);
DestFile = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')
-
+
SrcFileDir = "."
SrcPath = os.path.dirname(SrcFile)
SrcFileName = os.path.basename(SrcFile)
- SrcFileBase, SrcFileExt = os.path.splitext(SrcFileName)
+ SrcFileBase, SrcFileExt = os.path.splitext(SrcFileName)
DestPath = os.path.dirname(DestFile)
DestFileName = os.path.basename(DestFile)
- DestFileBase, DestFileExt = os.path.splitext(DestFileName)
+ DestFileBase, DestFileExt = os.path.splitext(DestFileName)
self.MacroDict = {
# source file
"${src}" : SrcFile,
@@ -472,9 +472,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
}
#
# Allow binary type module not specify override rule in FDF file.
- #
+ #
if len(self.BinFileList) > 0:
- if self.Rule == None or self.Rule == "":
+ if self.Rule is None or self.Rule == "":
self.Rule = "BINARY"
if not IsMakefile and GenFdsGlobalVariable.EnableGenfdsMultiThread and self.Rule != 'BINARY':
@@ -487,22 +487,24 @@ class FfsInfStatement(FfsInfStatementClassObject):
#
# Convert Fv File Type for PI1.1 SMM driver.
#
- if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) >= 0x0001000A:
+ if self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER and int(self.PiSpecVersion, 16) >= 0x0001000A:
if Rule.FvFileType == 'DRIVER':
Rule.FvFileType = 'SMM'
#
# Framework SMM Driver has no SMM FV file type
#
- if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) < 0x0001000A:
- if Rule.FvFileType == 'SMM' or Rule.FvFileType == 'SMM_CORE':
+ if self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER and int(self.PiSpecVersion, 16) < 0x0001000A:
+ if Rule.FvFileType == 'SMM' or Rule.FvFileType == SUP_MODULE_SMM_CORE:
EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM or SMM_CORE FV file type", File=self.InfFileName)
#
# For the rule only has simpleFile
#
MakefilePath = None
+ if self.IsBinaryModule:
+ IsMakefile = False
if IsMakefile:
MakefilePath = self.InfFileName, Arch
- if isinstance (Rule, RuleSimpleFile.RuleSimpleFile) :
+ if isinstance (Rule, RuleSimpleFile.RuleSimpleFile):
SectionOutputList = self.__GenSimpleFileSection__(Rule, IsMakefile=IsMakefile)
FfsOutput = self.__GenSimpleFileFfs__(Rule, SectionOutputList, MakefilePath=MakefilePath)
return FfsOutput
@@ -531,7 +533,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
'$(NAMED_GUID)' : self.ModuleGuid
}
String = GenFdsGlobalVariable.MacroExtend(String, MacroDict)
- String = GenFdsGlobalVariable.MacroExtend(String, self.MacroDict)
+ String = GenFdsGlobalVariable.MacroExtend(String, self.MacroDict)
return String
## __GetRule__() method
@@ -543,7 +545,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
#
def __GetRule__ (self) :
CurrentArchList = []
- if self.CurrentArch == None:
+ if self.CurrentArch is None:
CurrentArchList = ['common']
else:
CurrentArchList.append(self.CurrentArch)
@@ -554,23 +556,23 @@ class FfsInfStatement(FfsInfStatementClassObject):
CurrentArch.upper() + \
'.' + \
self.ModuleType.upper()
- if self.Rule != None:
+ if self.Rule is not None:
RuleName = RuleName + \
'.' + \
self.Rule.upper()
Rule = GenFdsGlobalVariable.FdfParser.Profile.RuleDict.get(RuleName)
- if Rule != None:
+ if Rule is not None:
GenFdsGlobalVariable.VerboseLogger ("Want To Find Rule Name is : " + RuleName)
return Rule
RuleName = 'RULE' + \
'.' + \
- 'COMMON' + \
+ TAB_COMMON + \
'.' + \
self.ModuleType.upper()
- if self.Rule != None:
+ if self.Rule is not None:
RuleName = RuleName + \
'.' + \
self.Rule.upper()
@@ -578,11 +580,11 @@ class FfsInfStatement(FfsInfStatementClassObject):
GenFdsGlobalVariable.VerboseLogger ('Trying to apply common rule %s for INF %s' % (RuleName, self.InfFileName))
Rule = GenFdsGlobalVariable.FdfParser.Profile.RuleDict.get(RuleName)
- if Rule != None:
+ if Rule is not None:
GenFdsGlobalVariable.VerboseLogger ("Want To Find Rule Name is : " + RuleName)
return Rule
- if Rule == None :
+ if Rule is None :
EdkLogger.error("GenFds", GENFDS_ERROR, 'Don\'t Find common rule %s for INF %s' \
% (RuleName, self.InfFileName))
@@ -599,7 +601,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
DscArchList = []
for Arch in GenFdsGlobalVariable.ArchList :
PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
- if PlatformDataBase != None:
+ if PlatformDataBase is not None:
if InfFileKey in PlatformDataBase.Modules:
DscArchList.append (Arch)
else:
@@ -608,7 +610,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
# the file name FILE_GUIDmodule.inf, then PlatformDataBase.Modules use FILE_GUIDmodule.inf as key,
# but the path (self.MetaFile.Path) is the real path
#
- for key in PlatformDataBase.Modules.keys():
+ for key in PlatformDataBase.Modules:
if InfFileKey == str((PlatformDataBase.Modules[key]).MetaFile.Path):
DscArchList.append (Arch)
break
@@ -646,7 +648,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
ArchList = CurArchList
UseArchList = TargetArchList
- if self.UseArch != None:
+ if self.UseArch is not None:
UseArchList = []
UseArchList.append(self.UseArch)
ArchList = list(set (UseArchList) & set (ArchList))
@@ -687,17 +689,17 @@ class FfsInfStatement(FfsInfStatementClassObject):
if self.OverrideGuid:
FileName = self.OverrideGuid
Arch = "NoneArch"
- if self.CurrentArch != None:
+ if self.CurrentArch is not None:
Arch = self.CurrentArch
OutputPath = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch],
- Arch ,
+ Arch,
ModulePath,
FileName,
'OUTPUT'
)
DebugPath = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch],
- Arch ,
+ Arch,
ModulePath,
FileName,
'DEBUG'
@@ -721,7 +723,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
FileList = []
OutputFileList = []
GenSecInputFile = None
- if Rule.FileName != None:
+ if Rule.FileName is not None:
GenSecInputFile = self.__ExtendMacro__(Rule.FileName)
if os.path.isabs(GenSecInputFile):
GenSecInputFile = os.path.normpath(GenSecInputFile)
@@ -735,22 +737,22 @@ class FfsInfStatement(FfsInfStatementClassObject):
#
# Convert Fv Section Type for PI1.1 SMM driver.
#
- if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) >= 0x0001000A:
- if SectionType == 'DXE_DEPEX':
- SectionType = 'SMM_DEPEX'
+ if self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER and int(self.PiSpecVersion, 16) >= 0x0001000A:
+ if SectionType == BINARY_FILE_TYPE_DXE_DEPEX:
+ SectionType = BINARY_FILE_TYPE_SMM_DEPEX
#
# Framework SMM Driver has no SMM_DEPEX section type
#
- if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) < 0x0001000A:
- if SectionType == 'SMM_DEPEX':
+ if self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER and int(self.PiSpecVersion, 16) < 0x0001000A:
+ if SectionType == BINARY_FILE_TYPE_SMM_DEPEX:
EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)
NoStrip = True
- if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):
- if self.KeepReloc != None:
+ if self.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM):
+ if self.KeepReloc is not None:
NoStrip = self.KeepReloc
- elif Rule.KeepReloc != None:
+ elif Rule.KeepReloc is not None:
NoStrip = Rule.KeepReloc
- elif self.ShadowFromInfFile != None:
+ elif self.ShadowFromInfFile is not None:
NoStrip = self.ShadowFromInfFile
if FileList != [] :
@@ -758,13 +760,13 @@ class FfsInfStatement(FfsInfStatementClassObject):
SecNum = '%d' %Index
GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \
- Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum
+ SectionSuffix[SectionType] + SUP_MODULE_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'):
+ if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE):
ImageObj = PeImageClass (File)
if ImageObj.SectionAlignment < 0x400:
self.Alignment = str (ImageObj.SectionAlignment)
@@ -787,7 +789,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
)
File = StrippedFile
- if SectionType == 'TE':
+ if SectionType == BINARY_FILE_TYPE_TE:
TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')
GenFdsGlobalVariable.GenerateFirmwareImage(
TeFile,
@@ -801,12 +803,12 @@ class FfsInfStatement(FfsInfStatementClassObject):
else:
SecNum = '%d' %Index
GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \
- Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum
+ SectionSuffix[SectionType] + SUP_MODULE_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'):
+ if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE):
ImageObj = PeImageClass (GenSecInputFile)
if ImageObj.SectionAlignment < 0x400:
self.Alignment = str (ImageObj.SectionAlignment)
@@ -830,7 +832,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
)
GenSecInputFile = StrippedFile
- if SectionType == 'TE':
+ if SectionType == BINARY_FILE_TYPE_TE:
TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')
GenFdsGlobalVariable.GenerateFirmwareImage(
TeFile,
@@ -866,7 +868,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
InputSection.append(InputFile)
SectionAlignments.append(Rule.SectAlignment)
- if Rule.NameGuid != None and Rule.NameGuid.startswith('PCD('):
+ if Rule.NameGuid is not None and Rule.NameGuid.startswith('PCD('):
PcdValue = GenFdsGlobalVariable.GetPcdValue(Rule.NameGuid)
if len(PcdValue) == 0:
EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \
@@ -880,7 +882,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
self.ModuleGuid = RegistryGuidStr
GenFdsGlobalVariable.GenerateFfs(FfsOutput, InputSection,
- Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],
+ FdfFvFileTypeToFileType[Rule.FvFileType],
self.ModuleGuid, Fixed=Rule.Fixed,
CheckSum=Rule.CheckSum, Align=Rule.Alignment,
SectionAlign=SectionAlignments,
@@ -899,8 +901,8 @@ class FfsInfStatement(FfsInfStatementClassObject):
# @retval string File name of the generated section file
#
def __GenComplexFileSection__(self, Rule, FvChildAddr, FvParentAddr, IsMakefile = False):
- if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):
- if Rule.KeepReloc != None:
+ if self.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, SUP_MODULE_MM_CORE_STANDALONE):
+ if Rule.KeepReloc is not None:
self.KeepRelocFromRule = Rule.KeepReloc
SectFiles = []
SectAlignments = []
@@ -938,14 +940,14 @@ class FfsInfStatement(FfsInfStatementClassObject):
#
# Convert Fv Section Type for PI1.1 SMM driver.
#
- if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) >= 0x0001000A:
- if Sect.SectionType == 'DXE_DEPEX':
- Sect.SectionType = 'SMM_DEPEX'
+ if self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER and int(self.PiSpecVersion, 16) >= 0x0001000A:
+ if Sect.SectionType == BINARY_FILE_TYPE_DXE_DEPEX:
+ Sect.SectionType = BINARY_FILE_TYPE_SMM_DEPEX
#
# Framework SMM Driver has no SMM_DEPEX section type
#
- if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) < 0x0001000A:
- if Sect.SectionType == 'SMM_DEPEX':
+ if self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER and int(self.PiSpecVersion, 16) < 0x0001000A:
+ if Sect.SectionType == BINARY_FILE_TYPE_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
@@ -955,16 +957,16 @@ class FfsInfStatement(FfsInfStatementClassObject):
Sect.FvAddr = FvChildAddr.pop(0)
elif isinstance(Sect, GuidSection):
Sect.FvAddr = FvChildAddr
- if FvParentAddr != None and isinstance(Sect, GuidSection):
+ if FvParentAddr is not None and isinstance(Sect, GuidSection):
Sect.FvParentAddr = FvParentAddr
-
+
if Rule.KeyStringList != []:
- SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self, IsMakefile = IsMakefile)
+ SectList, Align = Sect.GenSection(self.OutputPath, self.ModuleGuid, SecIndex, Rule.KeyStringList, self, IsMakefile = IsMakefile)
else :
- SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, self.KeyStringList, self, IsMakefile = IsMakefile)
-
+ SectList, Align = Sect.GenSection(self.OutputPath, self.ModuleGuid, SecIndex, self.KeyStringList, self, IsMakefile = IsMakefile)
+
if not HasGeneratedFlag:
- UniVfrOffsetFileSection = ""
+ UniVfrOffsetFileSection = ""
ModuleFileName = mws.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName)
InfData = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClass(ModuleFileName), self.CurrentArch]
#
@@ -975,16 +977,16 @@ class FfsInfStatement(FfsInfStatementClassObject):
for SourceFile in InfData.Sources:
if SourceFile.Type.upper() == ".VFR" :
#
- # search the .map file to find the offset of vfr binary in the PE32+/TE file.
+ # search the .map file to find the offset of vfr binary in the PE32+/TE file.
#
VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin")
if SourceFile.Type.upper() == ".UNI" :
#
- # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
+ # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
#
VfrUniBaseName["UniOffsetName"] = (self.BaseName + "Strings")
-
-
+
+
if len(VfrUniBaseName) > 0:
if IsMakefile:
if InfData.BuildType != 'UEFI_HII':
@@ -1007,7 +1009,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
if VfrUniOffsetList:
UniVfrOffsetFileName = os.path.join(self.OutputPath, self.BaseName + '.offset')
UniVfrOffsetFileSection = os.path.join(self.OutputPath, self.BaseName + 'Offset' + '.raw')
- self.__GenUniVfrOffsetFile (VfrUniOffsetList, UniVfrOffsetFileName)
+ FfsInfStatement.__GenUniVfrOffsetFile (VfrUniOffsetList, UniVfrOffsetFileName)
UniVfrOffsetFileNameList = []
UniVfrOffsetFileNameList.append(UniVfrOffsetFileName)
"""Call GenSection"""
@@ -1020,7 +1022,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
if UniVfrOffsetFileSection:
SectList.append(UniVfrOffsetFileSection)
HasGeneratedFlag = True
-
+
for SecName in SectList :
SectFiles.append(SecName)
SectAlignments.append(Align)
@@ -1038,7 +1040,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
#
def __GenComplexFileFfs__(self, Rule, InputFile, Alignments, MakefilePath = None):
- if Rule.NameGuid != None and Rule.NameGuid.startswith('PCD('):
+ if Rule.NameGuid is not None and Rule.NameGuid.startswith('PCD('):
PcdValue = GenFdsGlobalVariable.GetPcdValue(Rule.NameGuid)
if len(PcdValue) == 0:
EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \
@@ -1053,7 +1055,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
FfsOutput = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')
GenFdsGlobalVariable.GenerateFfs(FfsOutput, InputFile,
- Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],
+ FdfFvFileTypeToFileType[Rule.FvFileType],
self.ModuleGuid, Fixed=Rule.Fixed,
CheckSum=Rule.CheckSum, Align=Rule.Alignment,
SectionAlign=Alignments,
@@ -1061,27 +1063,6 @@ class FfsInfStatement(FfsInfStatementClassObject):
)
return FfsOutput
- ## __GetGenFfsCmdParameter__() method
- #
- # Create parameter string for GenFfs
- #
- # @param self The object pointer
- # @param Rule The rule object used to generate section
- # @retval tuple (FileType, Fixed, CheckSum, Alignment)
- #
- def __GetGenFfsCmdParameter__(self, Rule):
- result = tuple()
- result += ('-t', Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType])
- if Rule.Fixed != False:
- result += ('-x',)
- if Rule.CheckSum != False:
- result += ('-s',)
-
- if Rule.Alignment != None and Rule.Alignment != '':
- result += ('-a', Rule.Alignment)
-
- return result
-
## __GetBuildOutputMapFileVfrUniInfo() method
#
# Find the offset of UNI/INF object offset in the EFI image file.
@@ -1089,25 +1070,25 @@ class FfsInfStatement(FfsInfStatementClassObject):
# @param self The object pointer
# @param VfrUniBaseName A name list contain the UNI/INF object name.
# @retval RetValue A list contain offset of UNI/INF object.
- #
+ #
def __GetBuildOutputMapFileVfrUniInfo(self, VfrUniBaseName):
MapFileName = os.path.join(self.EfiOutputPath, self.BaseName + ".map")
EfiFileName = os.path.join(self.EfiOutputPath, self.BaseName + ".efi")
return GetVariableOffset(MapFileName, EfiFileName, VfrUniBaseName.values())
-
+
## __GenUniVfrOffsetFile() method
#
# Generate the offset file for the module which contain VFR or UNI file.
#
- # @param self The object pointer
# @param VfrUniOffsetList A list contain the VFR/UNI offsets in the EFI image file.
# @param UniVfrOffsetFileName The output offset file name.
#
- def __GenUniVfrOffsetFile(self, VfrUniOffsetList, UniVfrOffsetFileName):
+ @staticmethod
+ def __GenUniVfrOffsetFile(VfrUniOffsetList, UniVfrOffsetFileName):
# Use a instance of StringIO to cache data
- fStringIO = StringIO.StringIO('')
-
+ fStringIO = BytesIO('')
+
for Item in VfrUniOffsetList:
if (Item[0].find("Strings") != -1):
#
@@ -1117,7 +1098,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
#
UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid]
- fStringIO.write(''.join(UniGuid))
+ fStringIO.write(''.join(UniGuid))
UniValue = pack ('Q', int (Item[1], 16))
fStringIO.write (UniValue)
else:
@@ -1128,19 +1109,19 @@ class FfsInfStatement(FfsInfStatementClassObject):
#
VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]
- fStringIO.write(''.join(VfrGuid))
- type (Item[1])
+ fStringIO.write(''.join(VfrGuid))
+ type (Item[1])
VfrValue = pack ('Q', int (Item[1], 16))
fStringIO.write (VfrValue)
-
+
#
# write data into file.
#
try :
SaveFileOnChange(UniVfrOffsetFileName, fStringIO.getvalue())
except:
- EdkLogger.error("GenFds", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." %UniVfrOffsetFileName,None)
-
+ EdkLogger.error("GenFds", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." %UniVfrOffsetFileName, None)
+
fStringIO.close ()
-
+