]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/Fv.py
BaseTools: Extend the RAW format to support multiple binary files
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Fv.py
index 163ccd37f1582a03a3056bae04e587801dfa51a7..e385ccb1b546a467cfdd61067e43245818f2e320 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process FV generation\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, 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
@@ -112,6 +112,34 @@ 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
@@ -181,30 +209,33 @@ class FV (FvClassObject):
         #\r
         # Write the Fv contents to Buffer\r
         #\r
-        FvFileObj = open ( FvOutputFile,'r+b')\r
+        if os.path.isfile(FvOutputFile):\r
+            FvFileObj = open ( FvOutputFile,'r+b')\r
 \r
-        GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s FV Successfully" %self.UiFvName)\r
-        GenFdsGlobalVariable.SharpCounter = 0\r
+            GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s FV Successfully" %self.UiFvName)\r
+            GenFdsGlobalVariable.SharpCounter = 0\r
 \r
-        Buffer.write(FvFileObj.read())\r
-        FvFileObj.seek(0)\r
-        # PI FvHeader is 0x48 byte\r
-        FvHeaderBuffer = FvFileObj.read(0x48)\r
-        # FV alignment position.\r
-        FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r
-        # FvAlignmentValue is larger than or equal to 1K\r
-        if FvAlignmentValue >= 0x400:\r
-            if FvAlignmentValue >= 0x10000:\r
-                #The max alignment supported by FFS is 64K.\r
-                self.FvAlignment = "64K"\r
+            Buffer.write(FvFileObj.read())\r
+            FvFileObj.seek(0)\r
+            # PI FvHeader is 0x48 byte\r
+            FvHeaderBuffer = FvFileObj.read(0x48)\r
+            # FV alignment position.\r
+            FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r
+            # FvAlignmentValue is larger than or equal to 1K\r
+            if FvAlignmentValue >= 0x400:\r
+                if FvAlignmentValue >= 0x10000:\r
+                    #The max alignment supported by FFS is 64K.\r
+                    self.FvAlignment = "64K"\r
+                else:\r
+                    self.FvAlignment = str (FvAlignmentValue / 0x400) + "K"\r
             else:\r
-                self.FvAlignment = str (FvAlignmentValue / 0x400) + "K"\r
+                # FvAlignmentValue is less than 1K\r
+                self.FvAlignment = str (FvAlignmentValue)\r
+            FvFileObj.close()\r
+            GenFds.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r
+            GenFdsGlobalVariable.LargeFileInFvFlags.pop()\r
         else:\r
-            # FvAlignmentValue is less than 1K\r
-            self.FvAlignment = str (FvAlignmentValue)\r
-        FvFileObj.close()\r
-        GenFds.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r
-        GenFdsGlobalVariable.LargeFileInFvFlags.pop()\r
+            GenFdsGlobalVariable.ErrorLogger("Failed to generate %s FV file." %self.UiFvName)\r
         return FvOutputFile\r
 \r
     ## _GetBlockSize()\r