diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index 12d4f2bb73..28af09b982 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -2716,14 +2716,13 @@ class FdfParser: # 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} + FfsFileObj.SubAlignment = [] 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] + AlignValue = self.__Token if not self.__GetNextToken(): raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber) @@ -2735,14 +2734,14 @@ class FdfParser: self.__VerifyFile(FileName) File = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir) FfsFileObj.FileName.append(File.Path) - FfsFileObj.Alignment.append(AlignValue) + FfsFileObj.SubAlignment.append(AlignValue) if self.__IsToken( "}"): self.__UndoToken() break - if len(FfsFileObj.Alignment) == 1: - FfsFileObj.Alignment = FfsFileObj.Alignment[0] + if len(FfsFileObj.SubAlignment) == 1: + FfsFileObj.SubAlignment = FfsFileObj.SubAlignment[0] if len(FfsFileObj.FileName) == 1: FfsFileObj.FileName = FfsFileObj.FileName[0] diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py b/BaseTools/Source/Python/GenFds/FfsFileStatement.py index 506789e979..690826bcb9 100644 --- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py @@ -45,6 +45,7 @@ class FileStatement (FileStatementClassObject) : self.CurrentLineContent = None self.FileName = None self.InfFileName = None + self.SubAlignment = None ## GenFfs() method # @@ -94,8 +95,10 @@ class FileStatement (FileStatementClassObject) : 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): + 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, 'r+b') @@ -103,9 +106,12 @@ class FileStatement (FileStatementClassObject) : GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File)) Content = f.read() f.close() - AlignValue = self.Alignment[Index] - if AlignValue == None: - AlignValue = 1 + AlignValue = 1 + if self.SubAlignment[Index] != 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 @@ -116,10 +122,14 @@ class FileStatement (FileStatementClassObject) : 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.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)', ' ') diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py index e385ccb1b5..64d1709946 100644 --- a/BaseTools/Source/Python/GenFds/Fv.py +++ b/BaseTools/Source/Python/GenFds/Fv.py @@ -112,34 +112,6 @@ class FV (FvClassObject): # 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 = " + \