]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FfsInfStatement.py
Sync EDKII BaseTools to BaseTools project r2093.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FfsInfStatement.py
index 0dcd96da2e11027e1945250cfa555cf222bb1b20..d2397e07da33154a3c4633db7c67d0c7be2691da 100644 (file)
@@ -1,9 +1,9 @@
 ## @file\r
 # process FFS generation from INF statement\r
 #\r
-#  Copyright (c) 2007, Intel Corporation\r
+#  Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
 #\r
-#  All rights reserved. This program and the accompanying materials\r
+#  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution.  The full text of the license may be found at\r
 #  http://opensource.org/licenses/bsd-license.php\r
@@ -31,6 +31,9 @@ from Common.Misc import PathClass
 from Common.Misc import GuidStructureByteArrayToGuidString\r
 from Common import EdkLogger\r
 from Common.BuildToolError import *\r
+from GuidSection import GuidSection\r
+from FvImageSection import FvImageSection\r
+from Common.Misc import PeImageClass\r
 \r
 ## generate FFS from INF\r
 #\r
@@ -47,6 +50,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
         self.KeepRelocFromRule = None\r
         self.InDsc = True\r
         self.OptRomDefs = {}\r
+        self.PiSpecVersion = 0\r
         \r
     ## __InfParse() method\r
     #\r
@@ -76,7 +80,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
         #\r
 \r
         PathClassObj = PathClass(self.InfFileName, GenFdsGlobalVariable.WorkSpaceDir)\r
-        ErrorCode, ErrorInfo = PathClassObj.Validate()\r
+        ErrorCode, ErrorInfo = PathClassObj.Validate(".inf")\r
         if ErrorCode != 0:\r
             EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)\r
         \r
@@ -89,6 +93,8 @@ class FfsInfStatement(FfsInfStatementClassObject):
             self.BaseName = Inf.BaseName\r
             self.ModuleGuid = Inf.Guid\r
             self.ModuleType = Inf.ModuleType\r
+            if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification:\r
+                self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION']\r
             if Inf.AutoGenVersion < 0x00010005:\r
                 self.ModuleType = Inf.ComponentType\r
             self.VersionString = Inf.Version\r
@@ -102,6 +108,8 @@ class FfsInfStatement(FfsInfStatementClassObject):
             self.BaseName = Inf.BaseName\r
             self.ModuleGuid = Inf.Guid\r
             self.ModuleType = Inf.ModuleType\r
+            if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification:\r
+                self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION']\r
             self.VersionString = Inf.Version\r
             self.BinFileList = Inf.Binaries\r
             self.SourceFileList = Inf.Sources\r
@@ -113,6 +121,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
         if len(self.SourceFileList) != 0 and not self.InDsc:\r
             EdkLogger.warn("GenFds", GENFDS_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % (self.InfFileName))\r
 \r
+        if self.ModuleType == 'SMM_CORE' and self.PiSpecVersion < 0x0001000A:\r
+            EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File=self.InfFileName)      \r
+\r
         if Inf._Defs != None and len(Inf._Defs) > 0:\r
             self.OptRomDefs.update(Inf._Defs)\r
             \r
@@ -138,22 +149,43 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #\r
     #   Generate FFS\r
     #\r
-    #   @param  self        The object pointer\r
-    #   @param  Dict        dictionary contains macro and value pair\r
-    #   @retval string      Generated FFS file name\r
+    #   @param  self         The object pointer\r
+    #   @param  Dict         dictionary contains macro and value pair\r
+    #   @param  FvChildAddr  Array of the inside FvImage base address\r
+    #   @param  FvParentAddr Parent Fv base address\r
+    #   @retval string       Generated FFS file name\r
     #\r
-    def GenFfs(self, Dict = {}):\r
+    def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None):\r
         #\r
         # Parse Inf file get Module related information\r
         #\r
 \r
         self.__InfParse__(Dict)\r
+        \r
+        #\r
+        # Allow binary type module not specify override rule in FDF file.\r
+        # \r
+        if len(self.BinFileList) >0 and not self.InDsc:\r
+            if self.Rule == None or self.Rule == "":\r
+                self.Rule = "BINARY"\r
+                \r
         #\r
         # Get the rule of how to generate Ffs file\r
         #\r
         Rule = self.__GetRule__()\r
         GenFdsGlobalVariable.VerboseLogger( "Packing binaries from inf file : %s" %self.InfFileName)\r
-        #FileType = Ffs.Ffs.ModuleTypeToFileType[Rule.ModuleType]\r
+        #\r
+        # Convert Fv File Type for PI1.1 SMM driver.\r
+        #\r
+        if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion >= 0x0001000A:\r
+            if Rule.FvFileType == 'DRIVER':\r
+                Rule.FvFileType = 'SMM'\r
+        #\r
+        # Framework SMM Driver has no SMM FV file type\r
+        #\r
+        if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion < 0x0001000A:\r
+            if Rule.FvFileType == 'SMM' or Rule.FvFileType == 'SMM_CORE':\r
+                EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM or SMM_CORE FV file type", File=self.InfFileName)\r
         #\r
         # For the rule only has simpleFile\r
         #\r
@@ -165,7 +197,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
         # For Rule has ComplexFile\r
         #\r
         elif isinstance(Rule, RuleComplexFile.RuleComplexFile):\r
-            InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule)\r
+            InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule, FvChildAddr, FvParentAddr)\r
             FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList, InputSectAlignments)\r
 \r
             return FfsOutput\r
@@ -319,7 +351,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
         if len(PlatformArchList) == 0:\r
             self.InDsc = False\r
             PathClassObj = PathClass(self.InfFileName, GenFdsGlobalVariable.WorkSpaceDir)\r
-            ErrorCode, ErrorInfo = PathClassObj.Validate()\r
+            ErrorCode, ErrorInfo = PathClassObj.Validate(".inf")\r
             if ErrorCode != 0:\r
                 EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)\r
         if len(ArchList) == 1:\r
@@ -374,13 +406,30 @@ class FfsInfStatement(FfsInfStatementClassObject):
         #\r
         FileList = []\r
         OutputFileList = []\r
+        GenSecInputFile = None\r
         if Rule.FileName != None:\r
             GenSecInputFile = self.__ExtendMacro__(Rule.FileName)\r
+            if os.path.isabs(GenSecInputFile):
+                GenSecInputFile = os.path.normpath(GenSecInputFile)
+            else:
+                GenSecInputFile = os.path.normpath(os.path.join(self.EfiOutputPath, GenSecInputFile))\r
         else:\r
             FileList, IsSect = Section.Section.GetFileList(self, '', Rule.FileExtension)\r
 \r
         Index = 1\r
-        SectionType     = Rule.SectionType\r
+        SectionType = Rule.SectionType\r
+        #\r
+        # Convert Fv Section Type for PI1.1 SMM driver.\r
+        #\r
+        if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion >= 0x0001000A:\r
+            if SectionType == 'DXE_DEPEX':\r
+                SectionType = 'SMM_DEPEX'\r
+        #\r
+        # Framework SMM Driver has no SMM_DEPEX section type\r
+        #\r
+        if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion < 0x0001000A:\r
+            if SectionType == 'SMM_DEPEX':\r
+                EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)\r
         NoStrip = True\r
         if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):\r
             if self.KeepReloc != None:\r
@@ -398,6 +447,15 @@ class FfsInfStatement(FfsInfStatementClassObject):
                               Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum\r
                 Index = Index + 1\r
                 OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)\r
+                File = GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)\r
+\r
+                #Get PE Section alignment when align is set to AUTO\r
+                if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):\r
+                    ImageObj = PeImageClass (File)\r
+                    if ImageObj.SectionAlignment < 0x400:\r
+                        self.Alignment = str (ImageObj.SectionAlignment)\r
+                    else:\r
+                        self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
 \r
                 if not NoStrip:\r
                     FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
@@ -407,7 +465,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
                     StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
                     GenFdsGlobalVariable.GenerateFirmwareImage(\r
                                             StrippedFile,\r
-                                            [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],\r
+                                            [File],\r
                                             Strip=True\r
                                             )\r
                     File = StrippedFile\r
@@ -416,7 +474,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
                     TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
                     GenFdsGlobalVariable.GenerateFirmwareImage(\r
                                             TeFile,\r
-                                            [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],\r
+                                            [File],\r
                                             Type='te'\r
                                             )\r
                     File = TeFile\r
@@ -428,6 +486,15 @@ class FfsInfStatement(FfsInfStatementClassObject):
             GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \\r
                               Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum\r
             OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)\r
+            GenSecInputFile = GenFdsGlobalVariable.MacroExtend(GenSecInputFile, Dict, self.CurrentArch)\r
+\r
+            #Get PE Section alignment when align is set to AUTO\r
+            if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):\r
+                ImageObj = PeImageClass (GenSecInputFile)\r
+                if ImageObj.SectionAlignment < 0x400:\r
+                    self.Alignment = str (ImageObj.SectionAlignment)\r
+                else:\r
+                    self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
 \r
             if not NoStrip:\r
                 FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
@@ -437,7 +504,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
                 GenFdsGlobalVariable.GenerateFirmwareImage(\r
                                         StrippedFile,\r
-                                        [GenFdsGlobalVariable.MacroExtend(GenSecInputFile, Dict, self.CurrentArch)],\r
+                                        [GenSecInputFile],\r
                                         Strip=True\r
                                         )\r
                 GenSecInputFile = StrippedFile\r
@@ -446,7 +513,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
                 GenFdsGlobalVariable.GenerateFirmwareImage(\r
                                         TeFile,\r
-                                        [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],\r
+                                        [GenSecInputFile],\r
                                         Type='te'\r
                                         )\r
                 GenSecInputFile = TeFile\r
@@ -476,7 +543,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
         SectionAlignments = []\r
         for InputFile in InputFileList:\r
             InputSection.append(InputFile)\r
-            SectionAlignments.append(Rule.Alignment)\r
+            SectionAlignments.append(Rule.SectAlignment)\r
 \r
         if Rule.NameGuid != None and Rule.NameGuid.startswith('PCD('):\r
             PcdValue = GenFdsGlobalVariable.GetPcdValue(Rule.NameGuid)\r
@@ -503,11 +570,13 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #\r
     #   Generate section by sections in Rule\r
     #\r
-    #   @param  self        The object pointer\r
-    #   @param  Rule        The rule object used to generate section\r
-    #   @retval string      File name of the generated section file\r
+    #   @param  self         The object pointer\r
+    #   @param  Rule         The rule object used to generate section\r
+    #   @param  FvChildAddr  Array of the inside FvImage base address\r
+    #   @param  FvParentAddr Parent Fv base address\r
+    #   @retval string       File name of the generated section file\r
     #\r
-    def __GenComplexFileSection__(self, Rule):\r
+    def __GenComplexFileSection__(self, Rule, FvChildAddr, FvParentAddr):\r
         if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):\r
             if Rule.KeepReloc != None:\r
                 self.KeepRelocFromRule = Rule.KeepReloc\r
@@ -517,6 +586,29 @@ class FfsInfStatement(FfsInfStatementClassObject):
         for Sect in Rule.SectionList:\r
             SecIndex = '%d' %Index\r
             SectList  = []\r
+            #\r
+            # Convert Fv Section Type for PI1.1 SMM driver.\r
+            #\r
+            if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion >= 0x0001000A:\r
+                if Sect.SectionType == 'DXE_DEPEX':\r
+                    Sect.SectionType = 'SMM_DEPEX'\r
+            #\r
+            # Framework SMM Driver has no SMM_DEPEX section type\r
+            #\r
+            if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion < 0x0001000A:\r
+                if Sect.SectionType == 'SMM_DEPEX':\r
+                    EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)\r
+            #\r
+            # process the inside FvImage from FvSection or GuidSection\r
+            #\r
+            if FvChildAddr != []:\r
+                if isinstance(Sect, FvImageSection):\r
+                    Sect.FvAddr = FvChildAddr.pop(0)\r
+                elif isinstance(Sect, GuidSection):\r
+                    Sect.FvAddr = FvChildAddr\r
+            if FvParentAddr != None and isinstance(Sect, GuidSection):\r
+                Sect.FvParentAddr = FvParentAddr\r
+            \r
             if Rule.KeyStringList != []:\r
                 SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self)\r
             else :\r