def __ExtendMacro__ (self, String): MacroDict = { '$(INF_OUTPUT)' : self.EfiOutputPath, '$(MODULE_NAME)' : self.BaseName, '$(BUILD_NUMBER)': self.BuildNum, '$(INF_VERSION)' : self.VersionString, '$(NAMED_GUID)' : self.ModuleGuid } String = GenFdsGlobalVariable.MacroExtend(String, MacroDict) String = GenFdsGlobalVariable.MacroExtend(String, self.MacroDict) return String
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}): # # Prepare the parameter of GenSection # if FfsInf != None: self.Alignment = FfsInf.__ExtendMacro__(self.Alignment) self.StringData = FfsInf.__ExtendMacro__(self.StringData) self.FileName = FfsInf.__ExtendMacro__(self.FileName) OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get('UI')) if self.StringData != None : NameString = self.StringData elif self.FileName != None: FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict) FileObj = open(FileNameStr, 'r') NameString = FileObj.read() NameString = '\"' + NameString + "\"" FileObj.close() else: NameString = '' GenFdsGlobalVariable.GenerateSection(OutputFile, None, 'EFI_SECTION_USER_INTERFACE', Ui=NameString) OutputFileList = [] OutputFileList.append(OutputFile) return OutputFileList, self.Alignment
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False): # # Prepare the parameter of GenSection # if FfsInf is not None: self.Alignment = FfsInf.__ExtendMacro__(self.Alignment) self.BuildNum = FfsInf.__ExtendMacro__(self.BuildNum) self.StringData = FfsInf.__ExtendMacro__(self.StringData) self.FileName = FfsInf.__ExtendMacro__(self.FileName) OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get('VERSION')) OutputFile = os.path.normpath(OutputFile) # Get String Data StringData = '' if self.StringData is not None: StringData = self.StringData elif self.FileName is not None: FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict) FileObj = open(FileNameStr, 'r') StringData = FileObj.read() StringData = '"' + StringData + '"' FileObj.close() else: StringData = '' GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION', Ver=StringData, BuildNumber=self.BuildNum, IsMakefile=IsMakefile) OutputFileList = [] OutputFileList.append(OutputFile) return OutputFileList, self.Alignment
def GetCurrentArch(self): TargetArchList = GenFdsGlobalVariable.ArchList PlatformArchList = self.__GetPlatformArchList__() CurArchList = TargetArchList if PlatformArchList != []: CurArchList = list(set(TargetArchList) & set(PlatformArchList)) GenFdsGlobalVariable.VerboseLogger( "Valid target architecture(s) is : " + " ".join(CurArchList)) ArchList = [] if self.KeyStringList != []: for Key in self.KeyStringList: Key = GenFdsGlobalVariable.MacroExtend(Key) Target, Tag, Arch = Key.split('_') if Arch in CurArchList: ArchList.append(Arch) if Target not in self.TargetOverrideList: self.TargetOverrideList.append(Target) else: ArchList = CurArchList UseArchList = TargetArchList if self.UseArch != None: UseArchList = [] UseArchList.append(self.UseArch) ArchList = list(set(UseArchList) & set(ArchList)) self.InfFileName = NormPath(self.InfFileName) if len(PlatformArchList) == 0: self.InDsc = False PathClassObj = PathClass(self.InfFileName, GenFdsGlobalVariable.WorkSpaceDir) ErrorCode, ErrorInfo = PathClassObj.Validate(".inf") if ErrorCode != 0: EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo) if len(ArchList) == 1: Arch = ArchList[0] return Arch elif len(ArchList) > 1: if len(PlatformArchList) == 0: EdkLogger.error( "GenFds", GENFDS_ERROR, "GenFds command line option has multiple ARCHs %s. Not able to determine which ARCH is valid for Module %s !" % (str(ArchList), self.InfFileName)) else: EdkLogger.error( "GenFds", GENFDS_ERROR, "Module built under multiple ARCHs %s. Not able to determine which output to put into flash for Module %s !" % (str(ArchList), self.InfFileName)) else: EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s appears under ARCH %s in platform %s, but current deduced ARCH is %s, so NO build output could be put into flash." \ % (self.InfFileName, str(PlatformArchList), GenFdsGlobalVariable.ActivePlatform, str(set (UseArchList) & set (TargetArchList))))
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile=False): # # Prepare the parameter of GenSection # if FfsInf is not None: self.Alignment = FfsInf.__ExtendMacro__(self.Alignment) self.StringData = FfsInf.__ExtendMacro__(self.StringData) self.FileName = FfsInf.__ExtendMacro__(self.FileName) OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get(BINARY_FILE_TYPE_UI)) if self.StringData is not None: NameString = self.StringData elif self.FileName is not None: FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro( self.FileName) FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict) FileObj = open(FileNameStr, 'r') NameString = FileObj.read() FileObj.close() else: NameString = '' GenFdsGlobalVariable.GenerateSection(OutputFile, None, 'EFI_SECTION_USER_INTERFACE', Ui=NameString, IsMakefile=IsMakefile) OutputFileList = [] OutputFileList.append(OutputFile) return OutputFileList, self.Alignment
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False) : if self.FileName is not None and self.FileName.startswith('PCD('): self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName) """Prepare the parameter of GenSection""" if FfsInf is not None : InfFileName = FfsInf.InfFileName SectionType = FfsInf.__ExtendMacro__(self.SectionType) Filename = FfsInf.__ExtendMacro__(self.FileName) BuildNum = FfsInf.__ExtendMacro__(self.BuildNum) StringData = FfsInf.__ExtendMacro__(self.StringData) ModuleNameStr = FfsInf.__ExtendMacro__('$(MODULE_NAME)') NoStrip = True if FfsInf.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM) and SectionType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32): if FfsInf.KeepReloc is not None: NoStrip = FfsInf.KeepReloc elif FfsInf.KeepRelocFromRule is not None: NoStrip = FfsInf.KeepRelocFromRule elif self.KeepReloc is not None: NoStrip = self.KeepReloc elif FfsInf.ShadowFromInfFile is not None: NoStrip = FfsInf.ShadowFromInfFile else: EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s apply rule for None!" %ModuleName) """If the file name was pointed out, add it in FileList""" FileList = [] if Filename is not 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): FileList.append(Filename) elif IsMakefile: SuffixMap = FfsInf.GetFinalTargetSuffixMap() if '.depex' in SuffixMap: FileList.append(Filename) else: FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict, IsMakefile=IsMakefile) if IsSect : return FileList, self.Alignment Index = 0 Align = self.Alignment """ If Section type is 'VERSION'""" OutputFileList = [] if SectionType == 'VERSION': InfOverrideVerString = False if FfsInf.Version is not None: #StringData = FfsInf.Version BuildNum = FfsInf.Version InfOverrideVerString = True if InfOverrideVerString: #VerTuple = ('-n', '"' + StringData + '"') if BuildNum is not None and BuildNum != '': BuildNumTuple = ('-j', BuildNum) else: BuildNumTuple = tuple() Num = SecNum OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION', #Ui=StringData, Ver=BuildNum, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) elif FileList != []: for File in FileList: Index = Index + 1 Num = '%s.%d' %(SecNum, Index) OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get(SectionType)) f = open(File, 'r') VerString = f.read() f.close() BuildNum = VerString if BuildNum is not None and BuildNum != '': BuildNumTuple = ('-j', BuildNum) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION', #Ui=VerString, Ver=BuildNum, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) else: BuildNum = StringData if BuildNum is not None and BuildNum != '': BuildNumTuple = ('-j', BuildNum) else: BuildNumTuple = tuple() BuildNumString = ' ' + ' '.join(BuildNumTuple) #if VerString == '' and if BuildNumString == '': if self.Optional == True : GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!") return [], None else: EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss Version Section value" %InfFileName) Num = SecNum OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION', #Ui=VerString, Ver=BuildNum, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) # # If Section Type is BINARY_FILE_TYPE_UI # elif SectionType == BINARY_FILE_TYPE_UI: InfOverrideUiString = False if FfsInf.Ui is not None: StringData = FfsInf.Ui InfOverrideUiString = True if InfOverrideUiString: Num = SecNum if IsMakefile and StringData == ModuleNameStr: StringData = "$(MODULE_NAME)" OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE', Ui=StringData, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) elif FileList != []: for File in FileList: Index = Index + 1 Num = '%s.%d' %(SecNum, Index) OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get(SectionType)) f = open(File, 'r') UiString = f.read() f.close() if IsMakefile and UiString == ModuleNameStr: UiString = "$(MODULE_NAME)" GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE', Ui=UiString, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) else: if StringData is not None and len(StringData) > 0: UiTuple = ('-n', '"' + StringData + '"') else: UiTuple = tuple() if self.Optional == True : GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!") return '', None else: EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss UI Section value" %InfFileName) Num = SecNum if IsMakefile and StringData == ModuleNameStr: StringData = "$(MODULE_NAME)" OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE', Ui=StringData, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) else: """If File List is empty""" if FileList == [] : if self.Optional == True: GenFdsGlobalVariable.VerboseLogger("Optional Section don't exist!") return [], None else: EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName)) else: """Convert the File to Section file one by one """ for File in FileList: """ Copy Map file to FFS output path """ Index = Index + 1 Num = '%s.%d' %(SecNum, Index) OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_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 == BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE): ImageObj = PeImageClass (File) if ImageObj.SectionAlignment < 0x400: Align = str (ImageObj.SectionAlignment) elif ImageObj.SectionAlignment < 0x100000: Align = str (ImageObj.SectionAlignment / 0x400) + 'K' else: Align = str (ImageObj.SectionAlignment / 0x100000) + 'M' if File[(len(File)-4):] == '.efi': MapFile = File.replace('.efi', '.map') CopyMapFile = os.path.join(OutputPath, ModuleName + '.map') if IsMakefile: if GenFdsGlobalVariable.CopyList == []: GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)] else: GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile)) else: if os.path.exists(MapFile): if not os.path.exists(CopyMapFile) or \ (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)): CopyLongFilePath(MapFile, CopyMapFile) if not NoStrip: FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi') if IsMakefile: if GenFdsGlobalVariable.CopyList == []: GenFdsGlobalVariable.CopyList = [(File, FileBeforeStrip)] else: GenFdsGlobalVariable.CopyList.append((File, FileBeforeStrip)) else: if not os.path.exists(FileBeforeStrip) or \ (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)): CopyLongFilePath(File, FileBeforeStrip) StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped') GenFdsGlobalVariable.GenerateFirmwareImage( StrippedFile, [File], Strip=True, IsMakefile = IsMakefile ) File = StrippedFile """For TE Section call GenFw to generate TE image""" if SectionType == BINARY_FILE_TYPE_TE: TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw') GenFdsGlobalVariable.GenerateFirmwareImage( TeFile, [File], Type='te', IsMakefile = IsMakefile ) File = TeFile """Call GenSection""" GenFdsGlobalVariable.GenerateSection(OutputFile, [File], Section.Section.SectionType.get (SectionType), IsMakefile=IsMakefile ) OutputFileList.append(OutputFile) return OutputFileList, Align
def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile=None, Dict={}): # # Prepare the parameter of GenSection # if FfsFile != None: self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro( self.SectFileName) self.SectFileName = GenFdsGlobalVariable.MacroExtend( self.SectFileName, Dict, FfsFile.CurrentArch) else: self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro( self.SectFileName) self.SectFileName = GenFdsGlobalVariable.MacroExtend( self.SectFileName, Dict) """Check Section file exist or not !""" if not os.path.exists(self.SectFileName): self.SectFileName = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.SectFileName) """Copy Map file to Ffs output""" Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName) if Filename[(len(Filename) - 4):] == '.efi': MapFile = Filename.replace('.efi', '.map') if os.path.exists(MapFile): CopyMapFile = os.path.join(OutputPath, ModuleName + '.map') if not os.path.exists(CopyMapFile) or ( os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)): CopyLongFilePath(MapFile, CopyMapFile) #Get PE Section alignment when align is set to AUTO if self.Alignment == 'Auto' and self.SecType in ('TE', 'PE32'): ImageObj = PeImageClass(Filename) if ImageObj.SectionAlignment < 0x400: self.Alignment = str(ImageObj.SectionAlignment) elif ImageObj.SectionAlignment < 0x100000: self.Alignment = str(ImageObj.SectionAlignment / 0x400) + 'K' else: self.Alignment = str( ImageObj.SectionAlignment / 0x100000) + 'M' NoStrip = True if self.SecType in ('TE', 'PE32'): if self.KeepReloc != None: NoStrip = self.KeepReloc if not NoStrip: FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi') if not os.path.exists(FileBeforeStrip) or \ (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)): CopyLongFilePath(self.SectFileName, FileBeforeStrip) StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped') GenFdsGlobalVariable.GenerateFirmwareImage( StrippedFile, [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)], Strip=True) self.SectFileName = StrippedFile if self.SecType == 'TE': TeFile = os.path.join(OutputPath, ModuleName + 'Te.raw') GenFdsGlobalVariable.GenerateFirmwareImage( TeFile, [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)], Type='te') self.SectFileName = TeFile OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get(self.SecType)) OutputFile = os.path.normpath(OutputFile) GenFdsGlobalVariable.GenerateSection( OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType)) FileList = [OutputFile] return FileList, self.Alignment
def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict, vtfDict=None, MacroDict={}): Size = self.Size GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset) GenFdsGlobalVariable.InfLogger(" Region Size = 0x%X" % Size) GenFdsGlobalVariable.SharpCounter = 0 if self.RegionType == 'FV': # # Get Fv from FvDict # self.FvAddress = int(BaseAddress, 16) + self.Offset FvBaseAddress = '0x%X' % self.FvAddress FvOffset = 0 for RegionData in self.RegionDataList: FileName = None if RegionData.endswith(".fv"): RegionData = GenFdsGlobalVariable.MacroExtend( RegionData, MacroDict) GenFdsGlobalVariable.InfLogger( ' Region FV File Name = .fv : %s' % RegionData) if RegionData[1] != ':': RegionData = os.path.join( GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + 'fv' in ImageBinDict.keys(): GenFdsGlobalVariable.InfLogger(' Region Name = FV') FileName = ImageBinDict[RegionData.upper() + 'fv'] else: # # Generate FvImage. # FvObj = None if RegionData.upper( ) in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get( RegionData.upper()) if FvObj != None: GenFdsGlobalVariable.InfLogger(' Region Name = FV') # # Call GenFv tool # self.BlockInfoOfRegion(BlockSizeList, FvObj) self.FvAddress = self.FvAddress + FvOffset FvAlignValue = self.GetFvAlignValue(FvObj.FvAlignment) if self.FvAddress % FvAlignValue != 0: EdkLogger.error( "GenFds", GENFDS_ERROR, "FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment)) FvBuffer = StringIO.StringIO('') FvBaseAddress = '0x%X' % self.FvAddress BlockSize = None BlockNum = None FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict) if FvBuffer.len > Size: FvBuffer.close() EdkLogger.error( "GenFds", GENFDS_ERROR, "Size of FV (%s) is larger than Region Size 0x%X specified." % (RegionData, Size)) # # Put the generated image into FD buffer. # Buffer.write(FvBuffer.getvalue()) FvBuffer.close() FvOffset = FvOffset + FvBuffer.len Size = Size - FvBuffer.len continue else: EdkLogger.error( "GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (RegionData)) # # Add the exist Fv image into FD buffer # if FileName != None: FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of FV File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) BinFile = open(FileName, 'r+b') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1'): PadData = 0xFF else: PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == 'CAPSULE': # # Get Capsule from Capsule Dict # for RegionData in self.RegionDataList: if RegionData.endswith(".cap"): RegionData = GenFdsGlobalVariable.MacroExtend( RegionData, MacroDict) GenFdsGlobalVariable.InfLogger( ' Region CAPSULE Image Name = .cap : %s' % RegionData) if RegionData[1] != ':': RegionData = os.path.join( GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + 'cap' in ImageBinDict.keys(): GenFdsGlobalVariable.InfLogger(' Region Name = CAPSULE') FileName = ImageBinDict[RegionData.upper() + 'cap'] else: # # Generate Capsule image and Put it into FD buffer # CapsuleObj = None if RegionData.upper( ) in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys( ): CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[ RegionData.upper()] if CapsuleObj != None: CapsuleObj.CapsuleName = RegionData.upper() GenFdsGlobalVariable.InfLogger( ' Region Name = CAPSULE') # # Call GenFv tool to generate Capsule Image # FileName = CapsuleObj.GenCapsule() CapsuleObj.CapsuleName = None else: EdkLogger.error( "GenFds", GENFDS_ERROR, "Capsule (%s) is NOT described in FDF file!" % (RegionData)) # # Add the capsule image into FD buffer # FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size 0x%X of Capsule File (%s) is larger than Region Size 0x%X specified." \ % (FileLength, RegionData, Size)) BinFile = open(FileName, 'r+b') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1'): PadData = 0xFF else: PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == 'FILE': for RegionData in self.RegionDataList: RegionData = GenFdsGlobalVariable.MacroExtend( RegionData, MacroDict) if RegionData[1] != ':': RegionData = os.path.join( GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) # # Add the file image into FD buffer # FileLength = os.stat(RegionData)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) GenFdsGlobalVariable.InfLogger(' Region File Name = %s' % RegionData) BinFile = open(RegionData, 'rb') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1'): PadData = 0xFF else: PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == 'DATA': GenFdsGlobalVariable.InfLogger(' Region Name = DATA') DataSize = 0 for RegionData in self.RegionDataList: Data = RegionData.split(',') DataSize = DataSize + len(Data) if DataSize > Size: EdkLogger.error( "GenFds", GENFDS_ERROR, "Size of DATA is larger than Region Size ") else: for item in Data: Buffer.write(pack('B', int(item, 16))) Size = Size - DataSize # # Pad the left buffer # if Size > 0: if (ErasePolarity == '1'): PadData = 0xFF else: PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData)) if self.RegionType == None: GenFdsGlobalVariable.InfLogger(' Region Name = None') if (ErasePolarity == '1'): PadData = 0xFF else: PadData = 0 for i in range(0, Size): Buffer.write(pack('B', PadData))
def GenFfs(self, Dict={}, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None): if self.NameGuid is not None and self.NameGuid.startswith('PCD('): PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid) if len(PcdValue) == 0: EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \ % (self.NameGuid)) if PcdValue.startswith('{'): PcdValue = GuidStructureByteArrayToGuidString(PcdValue) RegistryGuidStr = PcdValue if len(RegistryGuidStr) == 0: EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \ % (self.NameGuid)) self.NameGuid = RegistryGuidStr Str = self.NameGuid if FvName: Str += FvName OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, Str) if not os.path.exists(OutputDir): os.makedirs(OutputDir) Dict.update(self.DefineVarDict) SectionAlignments = None if self.FvName is not None: Buffer = BytesIO('') if self.FvName.upper( ) not in GenFdsGlobalVariable.FdfParser.Profile.FvDict: EdkLogger.error( "GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName)) Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get( self.FvName.upper()) FileName = Fv.AddToBuffer(Buffer) SectionFiles = [FileName] elif self.FdName is not None: if self.FdName.upper( ) not in GenFdsGlobalVariable.FdfParser.Profile.FdDict: EdkLogger.error( "GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName)) Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get( self.FdName.upper()) FileName = Fd.GenFd() SectionFiles = [FileName] elif self.FileName is not None: if hasattr(self, 'FvFileType') and self.FvFileType == 'RAW': if isinstance(self.FileName, list) and isinstance( self.SubAlignment, list) and len(self.FileName) == len( self.SubAlignment): FileContent = '' MaxAlignIndex = 0 MaxAlignValue = 1 for Index, File in enumerate(self.FileName): try: f = open(File, 'rb') except: GenFdsGlobalVariable.ErrorLogger( "Error opening RAW file %s." % (File)) Content = f.read() f.close() AlignValue = 1 if self.SubAlignment[Index] is not None: AlignValue = GenFdsGlobalVariable.GetAlignment( self.SubAlignment[Index]) if AlignValue > MaxAlignValue: MaxAlignIndex = Index MaxAlignValue = AlignValue FileContent += Content if len(FileContent) % AlignValue != 0: Size = AlignValue - len(FileContent) % AlignValue for i in range(0, Size): FileContent += pack('B', 0xFF) if FileContent: OutputRAWFile = os.path.join( GenFdsGlobalVariable.FfsDir, self.NameGuid, self.NameGuid + '.raw') SaveFileOnChange(OutputRAWFile, FileContent, True) self.FileName = OutputRAWFile self.SubAlignment = self.SubAlignment[MaxAlignIndex] if self.Alignment and self.SubAlignment: if GenFdsGlobalVariable.GetAlignment( self.Alignment ) < GenFdsGlobalVariable.GetAlignment(self.SubAlignment): self.Alignment = self.SubAlignment elif self.SubAlignment: self.Alignment = self.SubAlignment self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro( self.FileName) #Replace $(SAPCE) with real space self.FileName = self.FileName.replace('$(SPACE)', ' ') SectionFiles = [ GenFdsGlobalVariable.MacroExtend(self.FileName, Dict) ] else: SectionFiles = [] Index = 0 SectionAlignments = [] 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 is not None and isinstance( section, GuidSection): section.FvParentAddr = FvParentAddr if self.KeepReloc == False: section.KeepReloc = False sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict) if sectList != []: for sect in sectList: SectionFiles.append(sect) SectionAlignments.append(align) # # Prepare the parameter # FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs') GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles, Ffs.Ffs.FdfFvFileTypeToFileType.get( self.FvFileType), self.NameGuid, Fixed=self.Fixed, CheckSum=self.CheckSum, Align=self.Alignment, SectionAlign=SectionAlignments) return FfsFileOutput
def GenFfs(self, FvName, Dict={}): DXE_GUID = "FC510EE7-FFDC-11D4-BD41-0080C73C8881" PEI_GUID = "1B45CC0A-156A-428A-AF62-49864DA0E6E6" Buffer = StringIO.StringIO('') AprioriFileGuid = DXE_GUID if self.AprioriType == "PEI": AprioriFileGuid = PEI_GUID OutputAprFilePath = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, \ GenFdsGlobalVariable.FfsDir,\ AprioriFileGuid + FvName) if not os.path.exists(OutputAprFilePath): os.makedirs(OutputAprFilePath) OutputAprFileName = os.path.join( OutputAprFilePath, \ AprioriFileGuid + FvName + '.Apri' ) AprFfsFileName = os.path.join (OutputAprFilePath,\ AprioriFileGuid + FvName + '.Ffs') Dict.update(self.DefineVarDict) for FfsObj in self.FfsList: Guid = "" if isinstance(FfsObj, FfsFileStatement.FileStatement): Guid = FfsObj.NameGuid else: InfFileName = NormPath(FfsObj.InfFileName) Arch = FfsObj.GetCurrentArch() if Arch != None: Dict['$(ARCH)'] = Arch InfFileName = GenFdsGlobalVariable.MacroExtend( InfFileName, Dict, Arch) if Arch != None: Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[ PathClass(InfFileName, GenFdsGlobalVariable. WorkSpaceDir), Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] Guid = Inf.Guid else: Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[ PathClass(InfFileName, GenFdsGlobalVariable. WorkSpaceDir), 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] Guid = Inf.Guid self.BinFileList = Inf.Module.Binaries if self.BinFileList == []: EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE, "INF %s not found in build ARCH %s!" \ % (InfFileName, GenFdsGlobalVariable.ArchList)) GuidPart = Guid.split('-') Buffer.write(pack('I', long(GuidPart[0], 16))) Buffer.write(pack('H', int(GuidPart[1], 16))) Buffer.write(pack('H', int(GuidPart[2], 16))) for Num in range(2): Char = GuidPart[3][Num * 2:Num * 2 + 2] Buffer.write(pack('B', int(Char, 16))) for Num in range(6): Char = GuidPart[4][Num * 2:Num * 2 + 2] Buffer.write(pack('B', int(Char, 16))) SaveFileOnChange(OutputAprFileName, Buffer.getvalue()) RawSectionFileName = os.path.join( OutputAprFilePath, \ AprioriFileGuid + FvName + '.raw' ) GenFdsGlobalVariable.GenerateSection(RawSectionFileName, [OutputAprFileName], 'EFI_SECTION_RAW') GenFdsGlobalVariable.GenerateFfs(AprFfsFileName, [RawSectionFileName], 'EFI_FV_FILETYPE_FREEFORM', AprioriFileGuid) return AprFfsFileName
def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None): if self.NameGuid != None and self.NameGuid.startswith('PCD('): PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid) if len(PcdValue) == 0: EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \ % (self.NameGuid)) if PcdValue.startswith('{'): PcdValue = GuidStructureByteArrayToGuidString(PcdValue) RegistryGuidStr = PcdValue if len(RegistryGuidStr) == 0: EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \ % (self.NameGuid)) self.NameGuid = RegistryGuidStr OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid) if not os.path.exists(OutputDir): os.makedirs(OutputDir) Dict.update(self.DefineVarDict) SectionAlignments = None if self.FvName != None : Buffer = StringIO.StringIO('') if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName)) Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper()) FileName = Fv.AddToBuffer(Buffer) SectionFiles = [FileName] elif self.FdName != None: if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): EdkLogger.error("GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName)) Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper()) FileName = Fd.GenFd() SectionFiles = [FileName] elif self.FileName != None: self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)] else: SectionFiles = [] Index = 0 SectionAlignments = [] 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 if self.KeepReloc == False: section.KeepReloc = False sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict) if sectList != []: for sect in sectList: SectionFiles.append(sect) SectionAlignments.append(align) # # Prepare the parameter # FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs') GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles, Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType), self.NameGuid, Fixed=self.Fixed, CheckSum=self.CheckSum, Align=self.Alignment, SectionAlign=SectionAlignments ) return FfsFileOutput
def __GenSimpleFileSection__(self, Rule): # # Prepare the parameter of GenSection # 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) Index = 1 SectionType = Rule.SectionType # # 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' # # 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': 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: NoStrip = self.KeepReloc elif Rule.KeepReloc != None: NoStrip = Rule.KeepReloc elif self.ShadowFromInfFile != None: NoStrip = self.ShadowFromInfFile if FileList != [] : for File in FileList: SecNum = '%d' %Index GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \ 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') if not os.path.exists(FileBeforeStrip) or \ (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)): CopyLongFilePath(File, FileBeforeStrip) StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped') GenFdsGlobalVariable.GenerateFirmwareImage( StrippedFile, [File], Strip=True ) File = StrippedFile if SectionType == 'TE': TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw') GenFdsGlobalVariable.GenerateFirmwareImage( TeFile, [File], Type='te' ) File = TeFile GenFdsGlobalVariable.GenerateSection(OutputFile, [File], Section.Section.SectionType[SectionType]) OutputFileList.append(OutputFile) else: SecNum = '%d' %Index 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') if not os.path.exists(FileBeforeStrip) or \ (os.path.getmtime(GenSecInputFile) > os.path.getmtime(FileBeforeStrip)): CopyLongFilePath(GenSecInputFile, FileBeforeStrip) StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped') GenFdsGlobalVariable.GenerateFirmwareImage( StrippedFile, [GenSecInputFile], Strip=True ) GenSecInputFile = StrippedFile if SectionType == 'TE': TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw') GenFdsGlobalVariable.GenerateFirmwareImage( TeFile, [GenSecInputFile], Type='te' ) GenSecInputFile = TeFile GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputFile], Section.Section.SectionType[SectionType]) OutputFileList.append(OutputFile) return OutputFileList
def GenBsfInf(self): FvList = self.GetFvList() self.BsfInfName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiName + '.inf') BsfInf = open(self.BsfInfName, 'w+') if self.ResetBin is not None: BsfInf.writelines("[OPTIONS]" + T_CHAR_LF) BsfInf.writelines ("IA32_RST_BIN" + \ " = " + \ GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.ResetBin)) + \ T_CHAR_LF) BsfInf.writelines(T_CHAR_LF) BsfInf.writelines("[COMPONENTS]" + T_CHAR_LF) for ComponentObj in self.ComponentStatementList: BsfInf.writelines ("COMP_NAME" + \ " = " + \ ComponentObj.CompName + \ T_CHAR_LF) if ComponentObj.CompLoc.upper() == 'NONE': BsfInf.writelines ("COMP_LOC" + \ " = " + \ 'N' + \ T_CHAR_LF) elif ComponentObj.FilePos is not None: BsfInf.writelines ("COMP_LOC" + \ " = " + \ ComponentObj.FilePos + \ T_CHAR_LF) else: Index = FvList.index(ComponentObj.CompLoc.upper()) if Index == 0: BsfInf.writelines ("COMP_LOC" + \ " = " + \ 'F' + \ T_CHAR_LF) elif Index == 1: BsfInf.writelines ("COMP_LOC" + \ " = " + \ 'S' + \ T_CHAR_LF) BsfInf.writelines ("COMP_TYPE" + \ " = " + \ ComponentObj.CompType + \ T_CHAR_LF) BsfInf.writelines ("COMP_VER" + \ " = " + \ ComponentObj.CompVer + \ T_CHAR_LF) BsfInf.writelines ("COMP_CS" + \ " = " + \ ComponentObj.CompCs + \ T_CHAR_LF) BinPath = ComponentObj.CompBin if BinPath != '-': BinPath = GenFdsGlobalVariable.MacroExtend( GenFdsGlobalVariable.ReplaceWorkspaceMacro(BinPath)) BsfInf.writelines ("COMP_BIN" + \ " = " + \ BinPath + \ T_CHAR_LF) SymPath = ComponentObj.CompSym if SymPath != '-': SymPath = GenFdsGlobalVariable.MacroExtend( GenFdsGlobalVariable.ReplaceWorkspaceMacro(SymPath)) BsfInf.writelines ("COMP_SYM" + \ " = " + \ SymPath + \ T_CHAR_LF) BsfInf.writelines ("COMP_SIZE" + \ " = " + \ ComponentObj.CompSize + \ T_CHAR_LF) BsfInf.writelines(T_CHAR_LF) BsfInf.close()
def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict, vtfDict=None, MacroDict={}, Flag=False): Size = self.Size if not Flag: GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset) GenFdsGlobalVariable.InfLogger(" Region Size = 0x%X" % Size) GenFdsGlobalVariable.SharpCounter = 0 if Flag and (self.RegionType != BINARY_FILE_TYPE_FV): return if self.RegionType == BINARY_FILE_TYPE_FV: # # Get Fv from FvDict # self.FvAddress = int(BaseAddress, 16) + self.Offset FvBaseAddress = '0x%X' % self.FvAddress FvOffset = 0 for RegionData in self.RegionDataList: FileName = None if RegionData.endswith(".fv"): RegionData = GenFdsGlobalVariable.MacroExtend( RegionData, MacroDict) if not Flag: GenFdsGlobalVariable.InfLogger( ' Region FV File Name = .fv : %s' % RegionData) if RegionData[1] != ':': RegionData = mws.join( GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + 'fv' in ImageBinDict: if not Flag: GenFdsGlobalVariable.InfLogger(' Region Name = FV') FileName = ImageBinDict[RegionData.upper() + 'fv'] else: # # Generate FvImage. # FvObj = None if RegionData.upper( ) in GenFdsGlobalVariable.FdfParser.Profile.FvDict: FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[ RegionData.upper()] if FvObj is not None: if not Flag: GenFdsGlobalVariable.InfLogger( ' Region Name = FV') # # Call GenFv tool # self.BlockInfoOfRegion(BlockSizeList, FvObj) self.FvAddress = self.FvAddress + FvOffset FvAlignValue = self.GetFvAlignValue(FvObj.FvAlignment) if self.FvAddress % FvAlignValue != 0: EdkLogger.error( "GenFds", GENFDS_ERROR, "FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment)) FvBuffer = BytesIO('') FvBaseAddress = '0x%X' % self.FvAddress BlockSize = None BlockNum = None FvObj.AddToBuffer(FvBuffer, FvBaseAddress, BlockSize, BlockNum, ErasePolarity, vtfDict, Flag=Flag) if Flag: continue FvBufferLen = len(FvBuffer.getvalue()) if FvBufferLen > Size: FvBuffer.close() EdkLogger.error( "GenFds", GENFDS_ERROR, "Size of FV (%s) is larger than Region Size 0x%X specified." % (RegionData, Size)) # # Put the generated image into FD buffer. # Buffer.write(FvBuffer.getvalue()) FvBuffer.close() FvOffset = FvOffset + FvBufferLen Size = Size - FvBufferLen continue else: EdkLogger.error( "GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (RegionData)) # # Add the exist Fv image into FD buffer # if not Flag: if FileName is not None: FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of FV File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) BinFile = open(FileName, 'rb') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # if not Flag: self.PadBuffer(Buffer, ErasePolarity, Size) if self.RegionType == 'CAPSULE': # # Get Capsule from Capsule Dict # for RegionData in self.RegionDataList: if RegionData.endswith(".cap"): RegionData = GenFdsGlobalVariable.MacroExtend( RegionData, MacroDict) GenFdsGlobalVariable.InfLogger( ' Region CAPSULE Image Name = .cap : %s' % RegionData) if RegionData[1] != ':': RegionData = mws.join( GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData elif RegionData.upper() + 'cap' in ImageBinDict: GenFdsGlobalVariable.InfLogger(' Region Name = CAPSULE') FileName = ImageBinDict[RegionData.upper() + 'cap'] else: # # Generate Capsule image and Put it into FD buffer # CapsuleObj = None if RegionData.upper( ) in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict: CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[ RegionData.upper()] if CapsuleObj is not None: CapsuleObj.CapsuleName = RegionData.upper() GenFdsGlobalVariable.InfLogger( ' Region Name = CAPSULE') # # Call GenFv tool to generate Capsule Image # FileName = CapsuleObj.GenCapsule() CapsuleObj.CapsuleName = None else: EdkLogger.error( "GenFds", GENFDS_ERROR, "Capsule (%s) is NOT described in FDF file!" % (RegionData)) # # Add the capsule image into FD buffer # FileLength = os.stat(FileName)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size 0x%X of Capsule File (%s) is larger than Region Size 0x%X specified." \ % (FileLength, RegionData, Size)) BinFile = open(FileName, 'rb') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # self.PadBuffer(Buffer, ErasePolarity, Size) if self.RegionType in ('FILE', 'INF'): for RegionData in self.RegionDataList: if self.RegionType == 'INF': RegionData.__InfParse__(None) if len(RegionData.BinFileList) != 1: EdkLogger.error( 'GenFds', GENFDS_ERROR, 'INF in FD region can only contain one binary: %s' % RegionData) File = RegionData.BinFileList[0] RegionData = RegionData.PatchEfiFile(File.Path, File.Type) else: RegionData = GenFdsGlobalVariable.MacroExtend( RegionData, MacroDict) if RegionData[1] != ':': RegionData = mws.join( GenFdsGlobalVariable.WorkSpaceDir, RegionData) if not os.path.exists(RegionData): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) # # Add the file image into FD buffer # FileLength = os.stat(RegionData)[ST_SIZE] if FileLength > Size: EdkLogger.error("GenFds", GENFDS_ERROR, "Size of File (%s) is larger than Region Size 0x%X specified." \ % (RegionData, Size)) GenFdsGlobalVariable.InfLogger(' Region File Name = %s' % RegionData) BinFile = open(RegionData, 'rb') Buffer.write(BinFile.read()) BinFile.close() Size = Size - FileLength # # Pad the left buffer # self.PadBuffer(Buffer, ErasePolarity, Size) if self.RegionType == 'DATA': GenFdsGlobalVariable.InfLogger(' Region Name = DATA') DataSize = 0 for RegionData in self.RegionDataList: Data = RegionData.split(',') DataSize = DataSize + len(Data) if DataSize > Size: EdkLogger.error( "GenFds", GENFDS_ERROR, "Size of DATA is larger than Region Size ") else: for item in Data: Buffer.write(pack('B', int(item, 16))) Size = Size - DataSize # # Pad the left buffer # self.PadBuffer(Buffer, ErasePolarity, Size) if self.RegionType is None: GenFdsGlobalVariable.InfLogger(' Region Name = None') self.PadBuffer(Buffer, ErasePolarity, Size)