]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FfsFileStatement.py
BaseTools: Fix a bug for different FV use same FILE statement Guid
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FfsFileStatement.py
index cd099196d089f98eace4dc682a93500e144d55e6..12ec95b5650163a9b240e4b3e4e9077907987478 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process FFS generation from FILE statement\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -28,6 +28,8 @@ from Common.BuildToolError import *
 from Common.Misc import GuidStructureByteArrayToGuidString\r
 from GuidSection import GuidSection\r
 from FvImageSection import FvImageSection\r
+from Common.Misc import SaveFileOnChange\r
+from struct import *\r
 \r
 ## generate FFS from FILE\r
 #\r
@@ -43,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
@@ -54,7 +57,7 @@ class FileStatement (FileStatementClassObject) :
     #   @param  FvParentAddr Parent Fv base address\r
     #   @retval string       Generated FFS file name\r
     #\r
-    def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None):\r
+    def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None):\r
         \r
         if self.NameGuid != None and self.NameGuid.startswith('PCD('):\r
             PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)\r
@@ -69,7 +72,10 @@ class FileStatement (FileStatementClassObject) :
                             % (self.NameGuid))\r
             self.NameGuid = RegistryGuidStr\r
         \r
-        OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid)\r
+        Str = self.NameGuid\r
+        if FvName:\r
+            Str += FvName\r
+        OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, Str)\r
         if not os.path.exists(OutputDir):\r
             os.makedirs(OutputDir)\r
 \r
@@ -91,6 +97,42 @@ class FileStatement (FileStatementClassObject) :
             SectionFiles = [FileName]\r
 \r
         elif self.FileName != None:\r
+            if hasattr(self, 'FvFileType') and self.FvFileType == 'RAW':\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, 'rb')\r
+                        except:\r
+                            GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File))\r
+                        Content = f.read()\r
+                        f.close()\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
+                            for i in range(0, Size):\r
+                                FileContent += pack('B', 0xFF)\r
+\r
+                    if FileContent:\r
+                        OutputRAWFile = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid, self.NameGuid + '.raw')\r
+                        SaveFileOnChange(OutputRAWFile, FileContent, True)\r
+                        self.FileName = OutputRAWFile\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