X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FFfsInfStatement.py;h=cd3b0f647793da01772e6fee4a98e3c576a6026d;hp=b26821b29052ae7b3fcf8d262541de23c40ff38d;hb=04797875d1d53e53e31eca4fa01bc3cf6929f39c;hpb=5a57246eab80f00ae2481970d12a2abc345a2730 diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py index b26821b290..cd3b0f6477 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -4,31 +4,27 @@ # 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 -# 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. +# SPDX-License-Identifier: BSD-2-Clause-Patent # ## # 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.DataType import SUP_MODULE_USER_DEFINED from Common.StringUtils import * from Common.Misc import PathClass from Common.Misc import GuidStructureByteArrayToGuidString @@ -36,15 +32,15 @@ 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 * @@ -93,7 +89,7 @@ class FfsInfStatement(FfsInfStatementClassObject): ModuleType = self.InfModule.ModuleType PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] - if ModuleType != DataType.SUP_MODULE_USER_DEFINED: + if ModuleType != SUP_MODULE_USER_DEFINED: for LibraryClass in PlatformDataBase.LibraryClasses.GetKeys(): if LibraryClass.startswith("NULL") and PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]: self.InfModule.LibraryClasses[LibraryClass] = PlatformDataBase.LibraryClasses[LibraryClass, ModuleType] @@ -151,7 +147,7 @@ class FfsInfStatement(FfsInfStatementClassObject): # @param self The object pointer # @param Dict dictionary contains macro and value pair # - def __InfParse__(self, Dict = {}): + def __InfParse__(self, Dict = None, IsGenFfs=False): GenFdsGlobalVariable.VerboseLogger( " Begine parsing INf file : %s" %self.InfFileName) @@ -188,7 +184,7 @@ class FfsInfStatement(FfsInfStatementClassObject): Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] # - # Set Ffs BaseName, MdouleGuid, ModuleType, Version, OutputPath + # Set Ffs BaseName, ModuleGuid, ModuleType, Version, OutputPath # self.BaseName = Inf.BaseName self.ModuleGuid = Inf.Guid @@ -225,7 +221,7 @@ class FfsInfStatement(FfsInfStatementClassObject): EdkLogger.warn("GenFds", GENFDS_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % (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) + 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_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) @@ -293,7 +289,7 @@ class FfsInfStatement(FfsInfStatementClassObject): try: 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 == TAB_VOID: @@ -340,9 +336,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) @@ -352,9 +346,12 @@ class FfsInfStatement(FfsInfStatementClassObject): GenFdsGlobalVariable.VerboseLogger("InfFileName :%s" % self.InfFileName) # - # Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${MdouleName}\ + # Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${ModuleName}\ # - + if IsGenFfs: + Rule = self.__GetRule__() + if GlobalData.gGuidPatternEnd.match(Rule.NameGuid): + self.ModuleGuid = Rule.NameGuid self.OutputPath = os.path.join(GenFdsGlobalVariable.FfsDir, \ self.ModuleGuid + self.BaseName) if not os.path.exists(self.OutputPath) : @@ -374,13 +371,13 @@ 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 != BINARY_FILE_TYPE_PE32 and self.ModuleType != SUP_MODULE_USER_DEFINED: return EfiFile @@ -398,7 +395,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' @@ -408,12 +405,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: @@ -421,12 +418,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 @@ -444,18 +441,18 @@ class FfsInfStatement(FfsInfStatementClassObject): # Parse Inf file get Module related information # - self.__InfParse__(Dict) + self.__InfParse__(Dict, IsGenFfs=True) 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, @@ -473,7 +470,7 @@ class FfsInfStatement(FfsInfStatementClassObject): } # # Allow binary type module not specify override rule in FDF file. - # + # if len(self.BinFileList) > 0: if self.Rule is None or self.Rule == "": self.Rule = "BINARY" @@ -534,7 +531,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 @@ -694,13 +691,13 @@ class FfsInfStatement(FfsInfStatementClassObject): 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' @@ -761,7 +758,7 @@ class FfsInfStatement(FfsInfStatementClassObject): SecNum = '%d' %Index GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \ - Ffs.Ffs.SectionSuffix[SectionType] + SUP_MODULE_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) @@ -772,9 +769,9 @@ class FfsInfStatement(FfsInfStatementClassObject): if ImageObj.SectionAlignment < 0x400: self.Alignment = str (ImageObj.SectionAlignment) elif ImageObj.SectionAlignment < 0x100000: - self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K' + self.Alignment = str (ImageObj.SectionAlignment // 0x400) + 'K' else: - self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M' + self.Alignment = str (ImageObj.SectionAlignment // 0x100000) + 'M' if not NoStrip: FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc') @@ -804,7 +801,7 @@ class FfsInfStatement(FfsInfStatementClassObject): else: SecNum = '%d' %Index GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \ - Ffs.Ffs.SectionSuffix[SectionType] + SUP_MODULE_SEC + SecNum + SectionSuffix[SectionType] + SUP_MODULE_SEC + SecNum OutputFile = os.path.join(self.OutputPath, GenSecOutputFile) GenSecInputFile = GenFdsGlobalVariable.MacroExtend(GenSecInputFile, Dict, self.CurrentArch) @@ -814,9 +811,9 @@ class FfsInfStatement(FfsInfStatementClassObject): if ImageObj.SectionAlignment < 0x400: self.Alignment = str (ImageObj.SectionAlignment) elif ImageObj.SectionAlignment < 0x100000: - self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K' + self.Alignment = str (ImageObj.SectionAlignment // 0x400) + 'K' else: - self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M' + self.Alignment = str (ImageObj.SectionAlignment // 0x100000) + 'M' if not NoStrip: FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc') @@ -883,7 +880,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, @@ -902,7 +899,7 @@ class FfsInfStatement(FfsInfStatementClassObject): # @retval string File name of the generated section file # def __GenComplexFileSection__(self, Rule, FvChildAddr, FvParentAddr, IsMakefile = False): - if self.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM): + 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 = [] @@ -960,14 +957,14 @@ class FfsInfStatement(FfsInfStatementClassObject): Sect.FvAddr = FvChildAddr 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] # @@ -978,16 +975,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': @@ -1023,7 +1020,7 @@ class FfsInfStatement(FfsInfStatementClassObject): if UniVfrOffsetFileSection: SectList.append(UniVfrOffsetFileSection) HasGeneratedFlag = True - + for SecName in SectList : SectFiles.append(SecName) SectAlignments.append(Align) @@ -1056,7 +1053,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, @@ -1071,12 +1068,12 @@ 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()) - + return GetVariableOffset(MapFileName, EfiFileName, list(VfrUniBaseName.values())) + ## __GenUniVfrOffsetFile() method # # Generate the offset file for the module which contain VFR or UNI file. @@ -1088,8 +1085,8 @@ class FfsInfStatement(FfsInfStatementClassObject): 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): # @@ -1097,9 +1094,8 @@ class FfsInfStatement(FfsInfStatementClassObject): # GUID + Offset # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } } # - 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)) + UniGuid = b'\xe0\xc5\x13\x89\xf63\x86M\x9b\xf1C\xef\x89\xfc\x06f' + fStringIO.write(UniGuid) UniValue = pack ('Q', int (Item[1], 16)) fStringIO.write (UniValue) else: @@ -1108,21 +1104,20 @@ class FfsInfStatement(FfsInfStatementClassObject): # GUID + Offset # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } }; # - 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]) + VfrGuid = b'\xb4|\xbc\xd0Gj_I\xaa\x11q\x07F\xda\x06\xa2' + fStringIO.write(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 () - +