]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Extend the RAW format to support multiple binary files
authorYonghong Zhu <yonghong.zhu@intel.com>
Mon, 21 Mar 2016 11:27:35 +0000 (19:27 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Sun, 27 Mar 2016 07:11:52 +0000 (15:11 +0800)
Current FDF spec updated to support multiple binary files for RAW File
in the [FV] and [Capsule] section. For the multiple normal files, it may
have the optional FfsAlignment.
Example:
FILE RAW = 197DB236-F856-4924-91F8-C1F12FB875F3 {
 Align=16 $(PLATFORM_PACKAGE)/Binaries/File1.pdb
 Align=16 $(PLATFORM_PACKAGE)/Binaries/File2.pdb
 Align=16 $(PLATFORM_PACKAGE)/Binaries/File3.pdb
}

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 788190567eef4366310fe8d502eb3cf0853db8f3..b86c196067251ac31669158f60060c47d8363389 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # parse FDF file\r
 #\r
-#  Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #  Copyright (c) 2015, Hewlett Packard Enterprise Development, L.P.<BR>\r
 #\r
 #  This program and the accompanying materials\r
@@ -2692,6 +2692,11 @@ class FdfParser:
         elif self.__Token in ("DEFINE", "APRIORI", "SECTION"):\r
             self.__UndoToken()\r
             self.__GetSectionData( FfsFileObj, MacroDict)\r
+\r
+        elif hasattr(FfsFileObj, 'FvFileType') and FfsFileObj.FvFileType == 'RAW':\r
+            self.__UndoToken()\r
+            self.__GetRAWData(FfsFileObj, MacroDict)\r
+\r
         else:\r
             FfsFileObj.CurrentLineNum = self.CurrentLineNumber\r
             FfsFileObj.CurrentLineContent = self.__CurrentLine()\r
@@ -2701,6 +2706,48 @@ class FdfParser:
         if not self.__IsToken( "}"):\r
             raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
 \r
+    ## __GetRAWData() method\r
+    #\r
+    #   Get RAW data for FILE statement\r
+    #\r
+    #   @param  self         The object pointer\r
+    #   @param  FfsFileObj   for whom section is got\r
+    #   @param  MacroDict    dictionary used to replace macro\r
+    #\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
+        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
+            if not self.__GetNextToken():\r
+                raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
+\r
+            FileName = self.__Token.replace('$(SPACE)', ' ')\r
+            if FileName == '}':\r
+                self.__UndoToken()\r
+                raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
+            elif not os.path.isfile(FileName):\r
+                raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
+\r
+            self.__VerifyFile(FileName)\r
+            File = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir)\r
+            FfsFileObj.FileName.append(File.Path)\r
+            FfsFileObj.Alignment.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.FileName) == 1:\r
+            FfsFileObj.FileName = FfsFileObj.FileName[0]\r
+\r
     ## __GetFileOpts() method\r
     #\r
     #   Get options for FILE statement\r
index cd099196d089f98eace4dc682a93500e144d55e6..506789e97981f33d734e8058672fedb0455ab6c2 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 - 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
@@ -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
@@ -91,6 +93,33 @@ 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.Alignment, list) and len(self.FileName) == len(self.Alignment):\r
+                    FileContent = ''\r
+                    for Index, File in enumerate(self.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 = self.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, 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.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)\r
             #Replace $(SAPCE) with real space\r
             self.FileName = self.FileName.replace('$(SPACE)', ' ')\r
index df97ccbab6484fd74d85b09c8429d11d26bd5055..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