]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FfsInfStatement.py
Sync BaseTools Branch (version r2321) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FfsInfStatement.py
index 47521e08c56621511c057fd6f9e60d39862a8504..b9e18f6bca922ca09b82717026cdeb8fc41712bd 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process FFS generation from INF statement\r
 #\r
-#  Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2011, 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
@@ -18,6 +18,8 @@
 import Rule\r
 import os\r
 import shutil\r
+import StringIO\r
+from struct import *\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 import Ffs\r
 import subprocess\r
@@ -34,6 +36,7 @@ from Common.BuildToolError import *
 from GuidSection import GuidSection\r
 from FvImageSection import FvImageSection\r
 from Common.Misc import PeImageClass\r
+from AutoGen.GenDepex import DependencyExpression\r
 \r
 ## generate FFS from INF\r
 #\r
@@ -50,8 +53,78 @@ class FfsInfStatement(FfsInfStatementClassObject):
         self.KeepRelocFromRule = None\r
         self.InDsc = True\r
         self.OptRomDefs = {}\r
-        self.PiSpecVersion = 0\r
-        \r
+        self.PiSpecVersion = '0x00000000'\r
+        self.InfModule = None\r
+        self.FinalTargetSuffixMap = {}\r
+\r
+    ## GetFinalTargetSuffixMap() method\r
+    #\r
+    #    Get final build target list\r
+    def GetFinalTargetSuffixMap(self):\r
+        if not self.InfModule or not self.CurrentArch:\r
+            return []\r
+        if not self.FinalTargetSuffixMap:\r
+            FinalBuildTargetList = GenFdsGlobalVariable.GetModuleCodaTargetList(self.InfModule, self.CurrentArch)\r
+            for File in FinalBuildTargetList:\r
+                self.FinalTargetSuffixMap.setdefault(os.path.splitext(File)[1], []).append(File)\r
+\r
+            # Check if current INF module has DEPEX\r
+            if '.depex' not in self.FinalTargetSuffixMap and self.InfModule.ModuleType != "USER_DEFINED" \\r
+                and not self.InfModule.DxsFile and not self.InfModule.LibraryClass:\r
+                ModuleType = self.InfModule.ModuleType\r
+                PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+\r
+                if ModuleType != DataType.SUP_MODULE_USER_DEFINED:\r
+                    for LibraryClass in PlatformDataBase.LibraryClasses.GetKeys():\r
+                        if LibraryClass.startswith("NULL") and PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]:\r
+                            self.InfModule.LibraryClasses[LibraryClass] = PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]\r
+\r
+                StrModule = str(self.InfModule)\r
+                PlatformModule = None\r
+                if StrModule in PlatformDataBase.Modules:\r
+                    PlatformModule = PlatformDataBase.Modules[StrModule]\r
+                    for LibraryClass in PlatformModule.LibraryClasses:\r
+                        if LibraryClass.startswith("NULL"):\r
+                            self.InfModule.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
+\r
+                DependencyList = [self.InfModule]\r
+                LibraryInstance = {}\r
+                DepexList = []\r
+                while len(DependencyList) > 0:\r
+                    Module = DependencyList.pop(0)\r
+                    if not Module:\r
+                        continue\r
+                    for Dep in Module.Depex[self.CurrentArch, ModuleType]:\r
+                        if DepexList != []:\r
+                            DepexList.append('AND')\r
+                        DepexList.append('(')\r
+                        DepexList.extend(Dep)\r
+                        if DepexList[-1] == 'END':  # no need of a END at this time\r
+                            DepexList.pop()\r
+                        DepexList.append(')')\r
+                    if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
+                        break\r
+                    for LibName in Module.LibraryClasses:\r
+                        if LibName in LibraryInstance:\r
+                            continue\r
+                        if PlatformModule and LibName in PlatformModule.LibraryClasses:\r
+                            LibraryPath = PlatformModule.LibraryClasses[LibName]\r
+                        else:\r
+                            LibraryPath = PlatformDataBase.LibraryClasses[LibName, ModuleType]\r
+                        if not LibraryPath:\r
+                            LibraryPath = Module.LibraryClasses[LibName]\r
+                        if not LibraryPath:\r
+                            continue\r
+                        LibraryModule = GenFdsGlobalVariable.WorkSpace.BuildObject[LibraryPath, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+                        LibraryInstance[LibName] = LibraryModule\r
+                        DependencyList.append(LibraryModule)\r
+                if DepexList:\r
+                    Dpx = DependencyExpression(DepexList, ModuleType, True)\r
+                    if len(Dpx.PostfixNotation) != 0:\r
+                        # It means this module has DEPEX\r
+                        self.FinalTargetSuffixMap['.depex'] = [os.path.join(self.EfiOutputPath, self.BaseName) + '.depex']\r
+        return self.FinalTargetSuffixMap\r
+\r
     ## __InfParse() method\r
     #\r
     #   Parse inf file to get module information\r
@@ -121,11 +194,13 @@ 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
+        if self.ModuleType == 'SMM_CORE' and int(self.PiSpecVersion, 16) < 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
+        self.InfModule = Inf\r
             \r
         GenFdsGlobalVariable.VerboseLogger( "BaseName : %s" %self.BaseName)\r
         GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" %self.ModuleGuid)\r
@@ -161,6 +236,14 @@ class FfsInfStatement(FfsInfStatementClassObject):
         #\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
@@ -169,13 +252,13 @@ class FfsInfStatement(FfsInfStatementClassObject):
         #\r
         # Convert Fv File Type for PI1.1 SMM driver.\r
         #\r
-        if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion >= 0x0001000A:\r
+        if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) >= 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 self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) < 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
@@ -401,9 +484,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
         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:
+            if os.path.isabs(GenSecInputFile):\r
+                GenSecInputFile = os.path.normpath(GenSecInputFile)\r
+            else:\r
                 GenSecInputFile = os.path.normpath(os.path.join(self.EfiOutputPath, GenSecInputFile))\r
         else:\r
             FileList, IsSect = Section.Section.GetFileList(self, '', Rule.FileExtension)\r
@@ -413,13 +496,13 @@ class FfsInfStatement(FfsInfStatementClassObject):
         #\r
         # Convert Fv Section Type for PI1.1 SMM driver.\r
         #\r
-        if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion >= 0x0001000A:\r
+        if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) >= 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 self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) < 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
@@ -575,19 +658,20 @@ class FfsInfStatement(FfsInfStatementClassObject):
         SectFiles = []\r
         SectAlignments = []\r
         Index = 1\r
+        HasGneratedFlag = False\r
         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 self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) >= 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 self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) < 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
@@ -605,6 +689,51 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self)\r
             else :\r
                 SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, self.KeyStringList, self)\r
+            \r
+            if not HasGneratedFlag:\r
+                UniVfrOffsetFileSection = ""    \r
+                ModuleFileName = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName)\r
+                InfData = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClass(ModuleFileName), self.CurrentArch]\r
+                #\r
+                # Search the source list in InfData to find if there are .vfr file exist.\r
+                #\r
+                VfrUniBaseName = {}\r
+                VfrUniOffsetList = []\r
+                for SourceFile in InfData.Sources:\r
+                    if SourceFile.Type.upper() == ".VFR" :\r
+                        #\r
+                        # search the .map file to find the offset of vfr binary in the PE32+/TE file. \r
+                        #\r
+                        VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin")\r
+                    if SourceFile.Type.upper() == ".UNI" :\r
+                        #\r
+                        # search the .map file to find the offset of Uni strings binary in the PE32+/TE file. \r
+                        #\r
+                        VfrUniBaseName["UniOffsetName"] = (self.BaseName + "Strings")\r
+                    \r
+                \r
+                if len(VfrUniBaseName) > 0:\r
+                    VfrUniOffsetList = self.__GetBuildOutputMapFileVfrUniInfo(VfrUniBaseName)\r
+                    #\r
+                    # Generate the Raw data of raw section\r
+                    #\r
+                    os.path.join( self.OutputPath, self.BaseName + '.offset')\r
+                    UniVfrOffsetFileName    =  os.path.join( self.OutputPath, self.BaseName + '.offset')\r
+                    UniVfrOffsetFileSection =  os.path.join( self.OutputPath, self.BaseName + 'Offset' + '.raw')\r
+                    \r
+                    self.__GenUniVfrOffsetFile (VfrUniOffsetList, UniVfrOffsetFileName)\r
+                    \r
+                    UniVfrOffsetFileNameList = []\r
+                    UniVfrOffsetFileNameList.append(UniVfrOffsetFileName)\r
+                    """Call GenSection"""\r
+                    GenFdsGlobalVariable.GenerateSection(UniVfrOffsetFileSection,\r
+                                                         UniVfrOffsetFileNameList,\r
+                                                         "EFI_SECTION_RAW"\r
+                                                         )\r
+                    os.remove(UniVfrOffsetFileName)         \r
+                    SectList.append(UniVfrOffsetFileSection)\r
+                    HasGneratedFlag = True\r
+                \r
             for SecName in  SectList :\r
                 SectFiles.append(SecName)\r
                 SectAlignments.append(Align)\r
@@ -664,3 +793,116 @@ class FfsInfStatement(FfsInfStatementClassObject):
             result += ('-a', Rule.Alignment)\r
 \r
         return result\r
\r
+    ## __GetBuildOutputMapFileVfrUniInfo() method\r
+    #\r
+    #   Find the offset of UNI/INF object offset in the EFI image file.\r
+    #\r
+    #   @param  self                  The object pointer\r
+    #   @param  VfrUniBaseName        A name list contain the UNI/INF object name.\r
+    #   @retval RetValue              A list contain offset of UNI/INF object.\r
+    #    \r
+    def __GetBuildOutputMapFileVfrUniInfo(self, VfrUniBaseName):\r
+        \r
+        RetValue = []\r
+        \r
+        MapFileName = os.path.join(self.EfiOutputPath, self.BaseName + ".map")\r
+        try:\r
+            fInputfile = open(MapFileName, "r", 0)\r
+            try:\r
+                FileLinesList = fInputfile.readlines()\r
+            except:\r
+                EdkLogger.error("GenFds", FILE_READ_FAILURE, "File read failed for %s" %MapFileName,None)\r
+            finally:\r
+                fInputfile.close()\r
+        except:\r
+            EdkLogger.error("GenFds", FILE_OPEN_FAILURE, "File open failed for %s" %MapFileName,None)\r
+        \r
+        IsHex = False\r
+        for eachLine in FileLinesList:\r
+            for eachName in VfrUniBaseName.values():\r
+                if eachLine.find(eachName) != -1:\r
+                    eachLine = eachLine.strip()\r
+                    Element  = eachLine.split()\r
+                    #\r
+                    # MSFT/ICC/EBC map file\r
+                    #\r
+                    if (len(Element) == 4):\r
+                        try:\r
+                            int (Element[2], 16)\r
+                            IsHex = True\r
+                        except:\r
+                            IsHex = False\r
+                    \r
+                        if IsHex:\r
+                            RetValue.append((eachName, Element[2]))\r
+                            IsHex = False\r
+                    #\r
+                    # GCC map file\r
+                    #\r
+                    elif (len(Element) == 2) and Element[0].startswith("0x"):\r
+                        RetValue.append((eachName, Element[0]))\r
+        \r
+        return RetValue\r
+    \r
+    ## __GenUniVfrOffsetFile() method\r
+    #\r
+    #   Generate the offset file for the module which contain VFR or UNI file.\r
+    #\r
+    #   @param  self                    The object pointer\r
+    #   @param  VfrUniOffsetList        A list contain the VFR/UNI offsets in the EFI image file.\r
+    #   @param  UniVfrOffsetFileName    The output offset file name.\r
+    #\r
+    def __GenUniVfrOffsetFile(self, VfrUniOffsetList, UniVfrOffsetFileName):\r
+        \r
+        try:\r
+            fInputfile = open(UniVfrOffsetFileName, "wb+", 0)\r
+        except:\r
+            EdkLogger.error("GenFds", FILE_OPEN_FAILURE, "File open failed for %s" %UniVfrOffsetFileName,None)\r
+            \r
+        # Use a instance of StringIO to cache data\r
+        fStringIO = StringIO.StringIO('')  \r
+        \r
+        for Item in VfrUniOffsetList:\r
+            if (Item[0].find("Strings") != -1):\r
+                #\r
+                # UNI offset in image.\r
+                # GUID + Offset\r
+                # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }\r
+                #\r
+                UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]\r
+                UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid]\r
+                fStringIO.write(''.join(UniGuid))            \r
+                UniValue = pack ('Q', int (Item[1], 16))\r
+                fStringIO.write (UniValue)\r
+            else:\r
+                #\r
+                # VFR binary offset in image.\r
+                # GUID + Offset\r
+                # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };\r
+                #\r
+                VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]\r
+                VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]\r
+                fStringIO.write(''.join(VfrGuid))                   \r
+                type (Item[1]) \r
+                VfrValue = pack ('Q', int (Item[1], 16))\r
+                fStringIO.write (VfrValue)\r
+            \r
+        #\r
+        # write data into file.\r
+        #\r
+        try :  \r
+            fInputfile.write (fStringIO.getvalue())\r
+        except:\r
+            EdkLogger.error("GenFds", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." %UniVfrOffsetFileName,None)\r
+        \r
+        fStringIO.close ()\r
+        fInputfile.close ()\r
+        \r
+                \r
+                    \r
+            \r
+            \r
+        \r
+                                \r
+        \r