]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenFds: Fix the bug for wrong alignment generate for RAW file
authorYonghong Zhu <yonghong.zhu@intel.com>
Fri, 1 Apr 2016 07:20:51 +0000 (15:20 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Tue, 5 Apr 2016 05:24:04 +0000 (13:24 +0800)
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>
BaseTools/Source/Python/GenFds/FdfParser.py
BaseTools/Source/Python/GenFds/FfsFileStatement.py
BaseTools/Source/Python/GenFds/Fv.py

index 12d4f2bb73738fbbd155e7ad1cb42a62463a0308..28af09b982005c419738912a702c933774b88576 100644 (file)
@@ -2716,14 +2716,13 @@ class FdfParser:
     #\r
     def __GetRAWData(self, FfsFileObj, MacroDict = {}):\r
         FfsFileObj.FileName = []\r
-        FfsFileObj.Alignment = []\r
-        AlignDict = {"Auto":1, "8":8, "16":16, "32":32, "64":64, "128":128, "512":512, "1K":1024, "4K":4096, "32K":32768, "64K":65536}\r
+        FfsFileObj.SubAlignment = []\r
         while True:\r
             AlignValue = None\r
             if self.__GetAlignment():\r
                 if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
                     raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
-                AlignValue = AlignValue = AlignDict[self.__Token]\r
+                AlignValue = self.__Token\r
             if not self.__GetNextToken():\r
                 raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
 \r
@@ -2735,14 +2734,14 @@ class FdfParser:
             self.__VerifyFile(FileName)\r
             File = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir)\r
             FfsFileObj.FileName.append(File.Path)\r
-            FfsFileObj.Alignment.append(AlignValue)\r
+            FfsFileObj.SubAlignment.append(AlignValue)\r
 \r
             if self.__IsToken( "}"):\r
                 self.__UndoToken()\r
                 break\r
 \r
-        if len(FfsFileObj.Alignment) == 1:\r
-            FfsFileObj.Alignment = FfsFileObj.Alignment[0]\r
+        if len(FfsFileObj.SubAlignment) == 1:\r
+            FfsFileObj.SubAlignment = FfsFileObj.SubAlignment[0]\r
         if len(FfsFileObj.FileName) == 1:\r
             FfsFileObj.FileName = FfsFileObj.FileName[0]\r
 \r
index 506789e97981f33d734e8058672fedb0455ab6c2..690826bcb999b672739cea3fdf13188f1b5b11ce 100644 (file)
@@ -45,6 +45,7 @@ class FileStatement (FileStatementClassObject) :
         self.CurrentLineContent = None\r
         self.FileName = None\r
         self.InfFileName = None\r
+        self.SubAlignment = None\r
 \r
     ## GenFfs() method\r
     #\r
@@ -94,8 +95,10 @@ class FileStatement (FileStatementClassObject) :
 \r
         elif self.FileName != None:\r
             if hasattr(self, 'FvFileType') and self.FvFileType == 'RAW':\r
-                if isinstance(self.FileName, list) and isinstance(self.Alignment, list) and len(self.FileName) == len(self.Alignment):\r
+                if isinstance(self.FileName, list) and isinstance(self.SubAlignment, list) and len(self.FileName) == len(self.SubAlignment):\r
                     FileContent = ''\r
+                    MaxAlignIndex = 0\r
+                    MaxAlignValue = 1\r
                     for Index, File in enumerate(self.FileName):\r
                         try:\r
                             f = open(File, 'r+b')\r
@@ -103,9 +106,12 @@ class FileStatement (FileStatementClassObject) :
                             GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File))\r
                         Content = f.read()\r
                         f.close()\r
-                        AlignValue = self.Alignment[Index]\r
-                        if AlignValue == None:\r
-                            AlignValue = 1\r
+                        AlignValue = 1\r
+                        if self.SubAlignment[Index] != None:\r
+                            AlignValue = GenFdsGlobalVariable.GetAlignment(self.SubAlignment[Index])\r
+                        if AlignValue > MaxAlignValue:\r
+                            MaxAlignIndex = Index\r
+                            MaxAlignValue = AlignValue\r
                         FileContent += Content\r
                         if len(FileContent) % AlignValue != 0:\r
                             Size = AlignValue - len(FileContent) % AlignValue\r
@@ -116,10 +122,14 @@ class FileStatement (FileStatementClassObject) :
                         OutputRAWFile = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid, self.NameGuid + '.raw')\r
                         SaveFileOnChange(OutputRAWFile, FileContent, True)\r
                         self.FileName = OutputRAWFile\r
-                        if max(self.Alignment):\r
-                            self.Alignment = str(max(self.Alignment))\r
-                        else:\r
-                            self.Alignment = None\r
+                        self.SubAlignment = self.SubAlignment[MaxAlignIndex]\r
+\r
+                if self.Alignment and self.SubAlignment:\r
+                    if GenFdsGlobalVariable.GetAlignment (self.Alignment) < GenFdsGlobalVariable.GetAlignment (self.SubAlignment):\r
+                        self.Alignment = self.SubAlignment\r
+                elif self.SubAlignment:\r
+                    self.Alignment = self.SubAlignment\r
+\r
             self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)\r
             #Replace $(SAPCE) with real space\r
             self.FileName = self.FileName.replace('$(SPACE)', ' ')\r
index e385ccb1b546a467cfdd61067e43245818f2e320..64d1709946483752fde8057b8cbf444dab51b04c 100644 (file)
@@ -112,34 +112,6 @@ class FV (FvClassObject):
 \r
         # Process Modules in FfsList\r
         for FfsFile in self.FfsList :\r
-            if hasattr(FfsFile, 'FvFileType') and FfsFile.FvFileType == 'RAW':\r
-                if isinstance(FfsFile.FileName, list) and isinstance(FfsFile.Alignment, list) and len(FfsFile.FileName) == len(FfsFile.Alignment):\r
-                    FileContent = ''\r
-                    for Index, File in enumerate(FfsFile.FileName):\r
-                        try:\r
-                            f = open(File, 'r+b')\r
-                        except:\r
-                            GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File))\r
-                        Content = f.read()\r
-                        f.close()\r
-                        AlignValue = FfsFile.Alignment[Index]\r
-                        if AlignValue == None:\r
-                            AlignValue = 1\r
-                        FileContent += Content\r
-                        if len(FileContent) % AlignValue != 0:\r
-                            Size = AlignValue - len(FileContent) % AlignValue\r
-                            for i in range(0, Size):\r
-                                FileContent += pack('B', 0xFF)\r
-\r
-                    if FileContent:\r
-                        OutputRAWFile = os.path.join(GenFdsGlobalVariable.FfsDir, FfsFile.NameGuid, FfsFile.NameGuid + '.raw')\r
-                        SaveFileOnChange(OutputRAWFile, FileContent, True)\r
-                        FfsFile.FileName = OutputRAWFile\r
-                        if max(FfsFile.Alignment):\r
-                            FfsFile.Alignment = str(max(FfsFile.Alignment))\r
-                        else:\r
-                            FfsFile.Alignment = None\r
-\r
             FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress)\r
             FfsFileList.append(FileName)\r
             self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r