Reviewed-by: Liming Gao <[email protected]>
> -----Original Message----- > From: edk2-devel [mailto:[email protected]] On Behalf Of > Yonghong Zhu > Sent: Monday, March 21, 2016 7:31 PM > To: [email protected] > Subject: [edk2] [Patch] BaseTools: Extend the RAW format to support > multiple binary files > > Current FDF spec updated to support multiple binary files for RAW File > in the [FV] and [Capsule] section. For the multiple normal files, it may > have the optional FfsAlignment. > Example: > FILE RAW = 197DB236-F856-4924-91F8-C1F12FB875F3 { > Align=16 $(PLATFORM_PACKAGE)/Binaries/File1.pdb > Align=16 $(PLATFORM_PACKAGE)/Binaries/File2.pdb > Align=16 $(PLATFORM_PACKAGE)/Binaries/File3.pdb > } > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Yonghong Zhu <[email protected]> > --- > BaseTools/Source/Python/GenFds/FdfParser.py | 49 > +++++++++++++++++++++- > BaseTools/Source/Python/GenFds/FfsFileStatement.py | 31 > +++++++++++++- > BaseTools/Source/Python/GenFds/Fv.py | 30 ++++++++++++- > 3 files changed, 107 insertions(+), 3 deletions(-) > > diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py > b/BaseTools/Source/Python/GenFds/FdfParser.py > index 7881905..b86c196 100644 > --- a/BaseTools/Source/Python/GenFds/FdfParser.py > +++ b/BaseTools/Source/Python/GenFds/FdfParser.py > @@ -1,9 +1,9 @@ > ## @file > # parse FDF file > # > -# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR> > +# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR> > # Copyright (c) 2015, Hewlett Packard Enterprise Development, L.P.<BR> > # > # 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 > @@ -2690,19 +2690,66 @@ class FdfParser: > FfsFileObj.FdName = self.__Token > > elif self.__Token in ("DEFINE", "APRIORI", "SECTION"): > self.__UndoToken() > self.__GetSectionData( FfsFileObj, MacroDict) > + > + elif hasattr(FfsFileObj, 'FvFileType') and FfsFileObj.FvFileType == > 'RAW': > + self.__UndoToken() > + self.__GetRAWData(FfsFileObj, MacroDict) > + > else: > FfsFileObj.CurrentLineNum = self.CurrentLineNumber > FfsFileObj.CurrentLineContent = self.__CurrentLine() > FfsFileObj.FileName = self.__Token.replace('$(SPACE)', ' ') > self.__VerifyFile(FfsFileObj.FileName) > > if not self.__IsToken( "}"): > raise Warning("expected '}'", self.FileName, > self.CurrentLineNumber) > > + ## __GetRAWData() method > + # > + # Get RAW data for FILE statement > + # > + # @param self The object pointer > + # @param FfsFileObj for whom section is got > + # @param MacroDict dictionary used to replace macro > + # > + def __GetRAWData(self, FfsFileObj, MacroDict = {}): > + FfsFileObj.FileName = [] > + FfsFileObj.Alignment = [] > + AlignDict = {"Auto":1, "8":8, "16":16, "32":32, "64":64, "128":128, > "512":512, "1K":1024, "4K":4096, "32K":32768, "64K":65536} > + while True: > + AlignValue = None > + if self.__GetAlignment(): > + if self.__Token not in ("Auto", "8", "16", "32", "64", > "128", "512", > "1K", "4K", "32K" ,"64K"): > + raise Warning("Incorrect alignment '%s'" % self.__Token, > self.FileName, self.CurrentLineNumber) > + AlignValue = AlignValue = AlignDict[self.__Token] > + if not self.__GetNextToken(): > + raise Warning("expected Filename value", self.FileName, > self.CurrentLineNumber) > + > + FileName = self.__Token.replace('$(SPACE)', ' ') > + if FileName == '}': > + self.__UndoToken() > + raise Warning("expected Filename value", self.FileName, > self.CurrentLineNumber) > + elif not os.path.isfile(FileName): > + raise Warning("expected '}'", self.FileName, > self.CurrentLineNumber) > + > + self.__VerifyFile(FileName) > + File = PathClass(NormPath(FileName), > GenFdsGlobalVariable.WorkSpaceDir) > + FfsFileObj.FileName.append(File.Path) > + FfsFileObj.Alignment.append(AlignValue) > + > + if self.__IsToken( "}"): > + self.__UndoToken() > + break > + > + if len(FfsFileObj.Alignment) == 1: > + FfsFileObj.Alignment = FfsFileObj.Alignment[0] > + if len(FfsFileObj.FileName) == 1: > + FfsFileObj.FileName = FfsFileObj.FileName[0] > + > ## __GetFileOpts() method > # > # Get options for FILE statement > # > # @param self The object pointer > diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py > b/BaseTools/Source/Python/GenFds/FfsFileStatement.py > index cd09919..506789e 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 - 2014, Intel Corporation. All rights reserved.<BR> > +# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR> > # > # 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 > @@ -26,10 +26,12 @@ from CommonDataClass.FdfClass import > FileStatementClassObject > from Common import EdkLogger > from Common.BuildToolError import * > from Common.Misc import GuidStructureByteArrayToGuidString > from GuidSection import GuidSection > from FvImageSection import FvImageSection > +from Common.Misc import SaveFileOnChange > +from struct import * > > ## generate FFS from FILE > # > # > class FileStatement (FileStatementClassObject) : > @@ -89,10 +91,37 @@ class FileStatement (FileStatementClassObject) : > Fd = > GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper()) > FileName = Fd.GenFd() > SectionFiles = [FileName] > > elif self.FileName != None: > + if hasattr(self, 'FvFileType') and self.FvFileType == 'RAW': > + if isinstance(self.FileName, list) and > isinstance(self.Alignment, list) > and len(self.FileName) == len(self.Alignment): > + FileContent = '' > + for Index, File in enumerate(self.FileName): > + try: > + f = open(File, 'r+b') > + except: > + GenFdsGlobalVariable.ErrorLogger("Error opening > RAW > file %s." % (File)) > + Content = f.read() > + f.close() > + AlignValue = self.Alignment[Index] > + if AlignValue == None: > + AlignValue = 1 > + 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 > + if max(self.Alignment): > + self.Alignment = str(max(self.Alignment)) > + else: > + self.Alignment = None > self.FileName = > GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) > #Replace $(SAPCE) with real space > self.FileName = self.FileName.replace('$(SPACE)', ' ') > SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, > Dict)] > > diff --git a/BaseTools/Source/Python/GenFds/Fv.py > b/BaseTools/Source/Python/GenFds/Fv.py > index df97ccb..e385ccb 100644 > --- a/BaseTools/Source/Python/GenFds/Fv.py > +++ b/BaseTools/Source/Python/GenFds/Fv.py > @@ -1,9 +1,9 @@ > ## @file > # process FV generation > # > -# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR> > +# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR> > # > # 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 > @@ -110,10 +110,38 @@ class FV (FvClassObject): > FileName + \ > T_CHAR_LF) > > # Process Modules in FfsList > for FfsFile in self.FfsList : > + if hasattr(FfsFile, 'FvFileType') and FfsFile.FvFileType == > 'RAW': > + if isinstance(FfsFile.FileName, list) and > isinstance(FfsFile.Alignment, > list) and len(FfsFile.FileName) == len(FfsFile.Alignment): > + FileContent = '' > + for Index, File in enumerate(FfsFile.FileName): > + try: > + f = open(File, 'r+b') > + except: > + GenFdsGlobalVariable.ErrorLogger("Error opening > RAW > file %s." % (File)) > + Content = f.read() > + f.close() > + AlignValue = FfsFile.Alignment[Index] > + if AlignValue == None: > + AlignValue = 1 > + 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, > FfsFile.NameGuid, FfsFile.NameGuid + '.raw') > + SaveFileOnChange(OutputRAWFile, FileContent, True) > + FfsFile.FileName = OutputRAWFile > + if max(FfsFile.Alignment): > + FfsFile.Alignment = str(max(FfsFile.Alignment)) > + else: > + FfsFile.Alignment = None > + > FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress) > FfsFileList.append(FileName) > self.FvInfFile.writelines("EFI_FILE_NAME = " + \ > FileName + \ > T_CHAR_LF) > -- > 2.6.1.windows.1 > > _______________________________________________ > edk2-devel mailing list > [email protected] > https://lists.01.org/mailman/listinfo/edk2-devel _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

