X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FFfsFileStatement.py;h=ba8e0465ef34721defca9355978dba5df7cc2691;hp=b0b1b00c7e751074612fb3fc928e982be7706972;hb=92beb1e4c73a40a708c7c0cade5c7cee314b3887;hpb=52302d4dee589a5df43a464420c9fe68ba83937d diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py b/BaseTools/Source/Python/GenFds/FfsFileStatement.py index b0b1b00c7e..ba8e0465ef 100644 --- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py @@ -1,9 +1,9 @@ ## @file # process FFS generation from FILE statement # -# Copyright (c) 2007 - 2010, Intel Corporation +# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# -# All rights reserved. This program and the accompanying materials +# 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 @@ -17,7 +17,7 @@ # import Ffs import Rule -import os +import Common.LongFilePathOs as os import StringIO import subprocess @@ -28,6 +28,8 @@ from Common.BuildToolError import * from Common.Misc import GuidStructureByteArrayToGuidString from GuidSection import GuidSection from FvImageSection import FvImageSection +from Common.Misc import SaveFileOnChange +from struct import * ## generate FFS from FILE # @@ -39,6 +41,11 @@ class FileStatement (FileStatementClassObject) : # def __init__(self): FileStatementClassObject.__init__(self) + self.CurrentLineNum = None + self.CurrentLineContent = None + self.FileName = None + self.InfFileName = None + self.SubAlignment = None ## GenFfs() method # @@ -50,9 +57,9 @@ class FileStatement (FileStatementClassObject) : # @param FvParentAddr Parent Fv base address # @retval string Generated FFS file name # - def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None): + def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None): - if self.NameGuid != None and self.NameGuid.startswith('PCD('): + 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.' \ @@ -65,29 +72,70 @@ class FileStatement (FileStatementClassObject) : % (self.NameGuid)) self.NameGuid = RegistryGuidStr - OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid) + Str = self.NameGuid + if FvName: + Str += FvName + OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, Str) if not os.path.exists(OutputDir): - os.makedirs(OutputDir) + os.makedirs(OutputDir) Dict.update(self.DefineVarDict) SectionAlignments = None - if self.FvName != None : + if self.FvName is not None : Buffer = StringIO.StringIO('') - if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): + 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 != None: - if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): + 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 != None: + 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: @@ -103,9 +151,11 @@ class FileStatement (FileStatementClassObject) : section.FvAddr = FvChildAddr.pop(0) elif isinstance(section, GuidSection): section.FvAddr = FvChildAddr - if FvParentAddr != None and isinstance(section, GuidSection): + 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: