BaseTools/GenFds: Fix the bug for wrong alignment generate for RAW file
When do the multiple raw file support feature, it cause the regression that the raw file section alignment value was wrongly overridden by the single raw file. this patch: 1) fix the wrong overridden bug. 2) remove the duplicate code for combine multiple raw file into one. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
parent
15f69ddfc9
commit
cfaaf99bdd
@ -2716,14 +2716,13 @@ class FdfParser:
|
|||||||
#
|
#
|
||||||
def __GetRAWData(self, FfsFileObj, MacroDict = {}):
|
def __GetRAWData(self, FfsFileObj, MacroDict = {}):
|
||||||
FfsFileObj.FileName = []
|
FfsFileObj.FileName = []
|
||||||
FfsFileObj.Alignment = []
|
FfsFileObj.SubAlignment = []
|
||||||
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:
|
while True:
|
||||||
AlignValue = None
|
AlignValue = None
|
||||||
if self.__GetAlignment():
|
if self.__GetAlignment():
|
||||||
if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):
|
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)
|
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
|
||||||
AlignValue = AlignValue = AlignDict[self.__Token]
|
AlignValue = self.__Token
|
||||||
if not self.__GetNextToken():
|
if not self.__GetNextToken():
|
||||||
raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)
|
raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)
|
||||||
|
|
||||||
@ -2735,14 +2734,14 @@ class FdfParser:
|
|||||||
self.__VerifyFile(FileName)
|
self.__VerifyFile(FileName)
|
||||||
File = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir)
|
File = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir)
|
||||||
FfsFileObj.FileName.append(File.Path)
|
FfsFileObj.FileName.append(File.Path)
|
||||||
FfsFileObj.Alignment.append(AlignValue)
|
FfsFileObj.SubAlignment.append(AlignValue)
|
||||||
|
|
||||||
if self.__IsToken( "}"):
|
if self.__IsToken( "}"):
|
||||||
self.__UndoToken()
|
self.__UndoToken()
|
||||||
break
|
break
|
||||||
|
|
||||||
if len(FfsFileObj.Alignment) == 1:
|
if len(FfsFileObj.SubAlignment) == 1:
|
||||||
FfsFileObj.Alignment = FfsFileObj.Alignment[0]
|
FfsFileObj.SubAlignment = FfsFileObj.SubAlignment[0]
|
||||||
if len(FfsFileObj.FileName) == 1:
|
if len(FfsFileObj.FileName) == 1:
|
||||||
FfsFileObj.FileName = FfsFileObj.FileName[0]
|
FfsFileObj.FileName = FfsFileObj.FileName[0]
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ class FileStatement (FileStatementClassObject) :
|
|||||||
self.CurrentLineContent = None
|
self.CurrentLineContent = None
|
||||||
self.FileName = None
|
self.FileName = None
|
||||||
self.InfFileName = None
|
self.InfFileName = None
|
||||||
|
self.SubAlignment = None
|
||||||
|
|
||||||
## GenFfs() method
|
## GenFfs() method
|
||||||
#
|
#
|
||||||
@ -94,8 +95,10 @@ class FileStatement (FileStatementClassObject) :
|
|||||||
|
|
||||||
elif self.FileName != None:
|
elif self.FileName != None:
|
||||||
if hasattr(self, 'FvFileType') and self.FvFileType == 'RAW':
|
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 = ''
|
FileContent = ''
|
||||||
|
MaxAlignIndex = 0
|
||||||
|
MaxAlignValue = 1
|
||||||
for Index, File in enumerate(self.FileName):
|
for Index, File in enumerate(self.FileName):
|
||||||
try:
|
try:
|
||||||
f = open(File, 'r+b')
|
f = open(File, 'r+b')
|
||||||
@ -103,9 +106,12 @@ class FileStatement (FileStatementClassObject) :
|
|||||||
GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File))
|
GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File))
|
||||||
Content = f.read()
|
Content = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
AlignValue = self.Alignment[Index]
|
AlignValue = 1
|
||||||
if AlignValue == None:
|
if self.SubAlignment[Index] != None:
|
||||||
AlignValue = 1
|
AlignValue = GenFdsGlobalVariable.GetAlignment(self.SubAlignment[Index])
|
||||||
|
if AlignValue > MaxAlignValue:
|
||||||
|
MaxAlignIndex = Index
|
||||||
|
MaxAlignValue = AlignValue
|
||||||
FileContent += Content
|
FileContent += Content
|
||||||
if len(FileContent) % AlignValue != 0:
|
if len(FileContent) % AlignValue != 0:
|
||||||
Size = AlignValue - len(FileContent) % AlignValue
|
Size = AlignValue - len(FileContent) % AlignValue
|
||||||
@ -116,10 +122,14 @@ class FileStatement (FileStatementClassObject) :
|
|||||||
OutputRAWFile = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid, self.NameGuid + '.raw')
|
OutputRAWFile = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid, self.NameGuid + '.raw')
|
||||||
SaveFileOnChange(OutputRAWFile, FileContent, True)
|
SaveFileOnChange(OutputRAWFile, FileContent, True)
|
||||||
self.FileName = OutputRAWFile
|
self.FileName = OutputRAWFile
|
||||||
if max(self.Alignment):
|
self.SubAlignment = self.SubAlignment[MaxAlignIndex]
|
||||||
self.Alignment = str(max(self.Alignment))
|
|
||||||
else:
|
if self.Alignment and self.SubAlignment:
|
||||||
self.Alignment = None
|
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)
|
self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
|
||||||
#Replace $(SAPCE) with real space
|
#Replace $(SAPCE) with real space
|
||||||
self.FileName = self.FileName.replace('$(SPACE)', ' ')
|
self.FileName = self.FileName.replace('$(SPACE)', ' ')
|
||||||
|
@ -112,34 +112,6 @@ class FV (FvClassObject):
|
|||||||
|
|
||||||
# Process Modules in FfsList
|
# Process Modules in FfsList
|
||||||
for FfsFile in self.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)
|
FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress)
|
||||||
FfsFileList.append(FileName)
|
FfsFileList.append(FileName)
|
||||||
self.FvInfFile.writelines("EFI_FILE_NAME = " + \
|
self.FvInfFile.writelines("EFI_FILE_NAME = " + \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user