]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FfsFileStatement.py
BaseTools: Replace StandardError with Expression
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FfsFileStatement.py
index 506789e97981f33d734e8058672fedb0455ab6c2..ba8e0465ef34721defca9355978dba5df7cc2691 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process FFS generation from FILE statement\r
 #\r
-#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2018, 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
@@ -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
@@ -56,9 +57,9 @@ 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
+        if self.NameGuid is not None and self.NameGuid.startswith('PCD('):\r
             PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)\r
             if len(PcdValue) == 0:\r
                 EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \\r
@@ -71,41 +72,49 @@ 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
         Dict.update(self.DefineVarDict)\r
         SectionAlignments = None\r
-        if self.FvName != None :\r
+        if self.FvName is not None :\r
             Buffer = StringIO.StringIO('')\r
-            if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
+            if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict:\r
                 EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName))\r
             Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper())\r
             FileName = Fv.AddToBuffer(Buffer)\r
             SectionFiles = [FileName]\r
 \r
-        elif self.FdName != None:\r
-            if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
+        elif self.FdName is not None:\r
+            if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict:\r
                 EdkLogger.error("GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName))\r
             Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper())\r
             FileName = Fd.GenFd()\r
             SectionFiles = [FileName]\r
 \r
-        elif self.FileName != None:\r
+        elif self.FileName is not 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
+                            f = open(File, 'rb')\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
+                        AlignValue = 1\r
+                        if self.SubAlignment[Index] is not 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 +125,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
@@ -138,7 +151,7 @@ class FileStatement (FileStatementClassObject) :
                         section.FvAddr = FvChildAddr.pop(0)\r
                     elif isinstance(section, GuidSection):\r
                         section.FvAddr = FvChildAddr\r
-                if FvParentAddr != None and isinstance(section, GuidSection):\r
+                if FvParentAddr is not None and isinstance(section, GuidSection):\r
                     section.FvParentAddr = FvParentAddr\r
 \r
                 if self.KeepReloc == False:\r