]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FfsInfStatement.py
BaseTools: Update Build tool to support multiple workspaces
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FfsInfStatement.py
index d95af34dfc6b721c3233d480b5ee848daf77fe0b..ed767d3fa698f33f607e0d906a183f5d091a6197 100644 (file)
@@ -1,7 +1,8 @@
 ## @file\r
 # process FFS generation from INF statement\r
 #\r
-#  Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2014 Hewlett-Packard Development Company, L.P.<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
@@ -16,8 +17,9 @@
 # Import Modules\r
 #\r
 import Rule\r
-import os\r
-import shutil\r
+import Common.LongFilePathOs as os\r
+import StringIO\r
+from struct import *\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 import Ffs\r
 import subprocess\r
@@ -26,19 +28,28 @@ import Section
 import RuleSimpleFile\r
 import RuleComplexFile\r
 from CommonDataClass.FdfClass import FfsInfStatementClassObject\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 from Common.String import *\r
 from Common.Misc import PathClass\r
 from Common.Misc import GuidStructureByteArrayToGuidString\r
+from Common.Misc import ProcessDuplicatedInf\r
+from Common.Misc import GetVariableOffset\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
+from AutoGen.GenDepex import DependencyExpression\r
+from PatchPcdValue.PatchPcdValue import PatchBinaryFile\r
+from Common.LongFilePathSupport import CopyLongFilePath\r
+from Common.LongFilePathSupport import OpenLongFilePath as open\r
 \r
 ## generate FFS from INF\r
 #\r
 #\r
 class FfsInfStatement(FfsInfStatementClassObject):\r
+    ## The mapping dictionary from datum type to its maximum number.\r
+    _MAX_SIZE_TYPE = {"BOOLEAN":0x01, "UINT8":0xFF, "UINT16":0xFFFF, "UINT32":0xFFFFFFFF, "UINT64":0xFFFFFFFFFFFFFFFF}\r
     ## The constructor\r
     #\r
     #   @param  self        The object pointer\r
@@ -50,8 +61,85 @@ 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
+        self.CurrentLineNum = None\r
+        self.CurrentLineContent = None\r
+        self.FileName = None\r
+        self.InfFileName = None\r
+        self.OverrideGuid = None\r
+        self.PatchedBinFile = ''\r
+        self.MacroDict = {}\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
@@ -64,7 +152,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
         GenFdsGlobalVariable.VerboseLogger( " Begine parsing INf file : %s" %self.InfFileName)\r
 \r
         self.InfFileName = self.InfFileName.replace('$(WORKSPACE)', '')\r
-        if self.InfFileName[0] == '\\' or self.InfFileName[0] == '/' :\r
+        if len(self.InfFileName) > 1 and self.InfFileName[0] == '\\' and self.InfFileName[1] == '\\':\r
+            pass\r
+        elif self.InfFileName[0] == '\\' or self.InfFileName[0] == '/' :\r
             self.InfFileName = self.InfFileName[1:]\r
 \r
         if self.InfFileName.find('$') == -1:\r
@@ -80,13 +170,15 @@ 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
+\r
+        if self.OverrideGuid:\r
+            PathClassObj = ProcessDuplicatedInf(PathClassObj, self.OverrideGuid, GenFdsGlobalVariable.WorkSpaceDir)\r
         if self.CurrentArch != None:\r
 \r
-            Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, self.CurrentArch]\r
+            Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
             #\r
             # Set Ffs BaseName, MdouleGuid, ModuleType, Version, OutputPath\r
             #\r
@@ -104,7 +196,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 self.ShadowFromInfFile = Inf.Shadow\r
 \r
         else:\r
-            Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, 'COMMON']\r
+            Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
             self.BaseName = Inf.BaseName\r
             self.ModuleGuid = Inf.Guid\r
             self.ModuleType = Inf.ModuleType\r
@@ -118,20 +210,105 @@ class FfsInfStatement(FfsInfStatementClassObject):
                                 "INF %s specified in FDF could not be found in build ARCH %s!" \\r
                                 % (self.InfFileName, GenFdsGlobalVariable.ArchList))\r
 \r
+        if self.OverrideGuid:\r
+            self.ModuleGuid = self.OverrideGuid\r
+\r
         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
-        GenFdsGlobalVariable.VerboseLogger( "BaseName : %s" %self.BaseName)\r
-        GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" %self.ModuleGuid)\r
-        GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" %self.ModuleType)\r
-        GenFdsGlobalVariable.VerboseLogger("VersionString : %s" %self.VersionString)\r
-        GenFdsGlobalVariable.VerboseLogger("InfFileName :%s"  %self.InfFileName)\r
+\r
+        self.PatchPcds = []\r
+        InfPcds = Inf.Pcds\r
+        Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+        FdfPcdDict = GenFdsGlobalVariable.FdfParser.Profile.PcdDict\r
+\r
+        # Workaround here: both build and GenFds tool convert the workspace path to lower case\r
+        # But INF file path in FDF and DSC file may have real case characters.\r
+        # Try to convert the path to lower case to see if PCDs value are override by DSC.\r
+        DscModules = {}\r
+        for DscModule in Platform.Modules:\r
+            DscModules[str(DscModule).lower()] = Platform.Modules[DscModule]\r
+        for PcdKey in InfPcds:\r
+            Pcd = InfPcds[PcdKey]\r
+            if not hasattr(Pcd, 'Offset'):\r
+                continue\r
+            if Pcd.Type != 'PatchableInModule':\r
+                continue\r
+            # Override Patchable PCD value by the value from DSC\r
+            PatchPcd = None\r
+            InfLowerPath = str(PathClassObj).lower()\r
+            if InfLowerPath in DscModules and PcdKey in DscModules[InfLowerPath].Pcds:\r
+                PatchPcd = DscModules[InfLowerPath].Pcds[PcdKey]\r
+            elif PcdKey in Platform.Pcds:\r
+                PatchPcd = Platform.Pcds[PcdKey]\r
+            DscOverride = False\r
+            if PatchPcd and Pcd.Type == PatchPcd.Type:\r
+                DefaultValue = PatchPcd.DefaultValue\r
+                DscOverride = True\r
+\r
+            # Override Patchable PCD value by the value from FDF\r
+            FdfOverride = False\r
+            if PcdKey in FdfPcdDict:\r
+                DefaultValue = FdfPcdDict[PcdKey]\r
+                FdfOverride = True\r
+\r
+            if not DscOverride and not FdfOverride:\r
+                continue\r
+            # Check value, if value are equal, no need to patch\r
+            if Pcd.DatumType == "VOID*":\r
+                if Pcd.DefaultValue == DefaultValue or DefaultValue in [None, '']:\r
+                    continue\r
+                # Get the string size from FDF or DSC\r
+                if DefaultValue[0] == 'L':\r
+                    # Remove L"", but the '\0' must be appended\r
+                    MaxDatumSize = str((len(DefaultValue) - 2) * 2)\r
+                elif DefaultValue[0] == '{':\r
+                    MaxDatumSize = str(len(DefaultValue.split(',')))\r
+                else:\r
+                    MaxDatumSize = str(len(DefaultValue) - 1)\r
+                if DscOverride:\r
+                    Pcd.MaxDatumSize = PatchPcd.MaxDatumSize\r
+                # If no defined the maximum size in DSC, try to get current size from INF\r
+                if Pcd.MaxDatumSize in ['', None]:\r
+                    Pcd.MaxDatumSize = str(len(Pcd.DefaultValue.split(',')))\r
+            else:\r
+                Base1 = Base2 = 10\r
+                if Pcd.DefaultValue.upper().startswith('0X'):\r
+                    Base1 = 16\r
+                if DefaultValue.upper().startswith('0X'):\r
+                    Base2 = 16\r
+                try:\r
+                    PcdValueInImg = int(Pcd.DefaultValue, Base1)\r
+                    PcdValueInDscOrFdf = int(DefaultValue, Base2)\r
+                    if PcdValueInImg == PcdValueInDscOrFdf:\r
+                        continue\r
+                except:\r
+                    continue\r
+            # Check the Pcd size and data type\r
+            if Pcd.DatumType == "VOID*":\r
+                if int(MaxDatumSize) > int(Pcd.MaxDatumSize):\r
+                    EdkLogger.error("GenFds", GENFDS_ERROR, "The size of VOID* type PCD '%s.%s' exceeds its maximum size %d bytes." \\r
+                                    % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, int(MaxDatumSize) - int(Pcd.MaxDatumSize)))\r
+            else:\r
+                if PcdValueInDscOrFdf > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType] \\r
+                    or PcdValueInImg > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType]:\r
+                    EdkLogger.error("GenFds", GENFDS_ERROR, "The size of %s type PCD '%s.%s' doesn't match its data type." \\r
+                                    % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
+            self.PatchPcds.append((Pcd, DefaultValue))\r
+\r
+        self.InfModule = Inf\r
+        self.PcdIsDriver = Inf.PcdIsDriver\r
+        self.IsBinaryModule = Inf.IsBinaryModule\r
+        GenFdsGlobalVariable.VerboseLogger("BaseName : %s" % self.BaseName)\r
+        GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" % self.ModuleGuid)\r
+        GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" % self.ModuleType)\r
+        GenFdsGlobalVariable.VerboseLogger("VersionString : %s" % self.VersionString)\r
+        GenFdsGlobalVariable.VerboseLogger("InfFileName :%s" % self.InfFileName)\r
 \r
         #\r
         # Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${MdouleName}\\r
@@ -145,6 +322,34 @@ class FfsInfStatement(FfsInfStatementClassObject):
         self.EfiOutputPath = self.__GetEFIOutPutPath__()\r
         GenFdsGlobalVariable.VerboseLogger( "ModuelEFIPath: " + self.EfiOutputPath)\r
 \r
+    ## PatchEfiFile\r
+    #\r
+    #  Patch EFI file with patch PCD\r
+    #\r
+    #  @param EfiFile: EFI file needs to be patched.\r
+    #  @retval: Full path of patched EFI file: self.OutputPath + EfiFile base name\r
+    #           If passed in file does not end with efi, return as is\r
+    #\r
+    def PatchEfiFile(self, EfiFile, FileType):\r
+        if not self.PatchPcds:\r
+            return EfiFile\r
+        if FileType != 'PE32' and self.ModuleType != "USER_DEFINED":\r
+            return EfiFile\r
+        if self.PatchedBinFile:\r
+            EdkLogger.error("GenFds", GENFDS_ERROR,\r
+                            'Only one binary file can be patched:\n'\r
+                            '  a binary file has been patched: %s\n'\r
+                            '  current file: %s' % (self.PatchedBinFile, EfiFile),\r
+                            File=self.InfFileName)\r
+        Basename = os.path.basename(EfiFile)\r
+        Output = os.path.join(self.OutputPath, Basename)\r
+        CopyLongFilePath(EfiFile, Output)\r
+        for Pcd, Value in self.PatchPcds:\r
+            RetVal, RetStr = PatchBinaryFile(Output, int(Pcd.Offset, 0), Pcd.DatumType, Value, Pcd.MaxDatumSize)\r
+            if RetVal:\r
+                EdkLogger.error("GenFds", GENFDS_ERROR, RetStr, File=self.InfFileName)\r
+        self.PatchedBinFile = os.path.normpath(EfiFile)\r
+        return Output\r
     ## GenFfs() method\r
     #\r
     #   Generate FFS\r
@@ -161,6 +366,38 @@ class FfsInfStatement(FfsInfStatementClassObject):
         #\r
 \r
         self.__InfParse__(Dict)\r
+        SrcFile = mws.join( GenFdsGlobalVariable.WorkSpaceDir , self.InfFileName);\r
+        DestFile = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')\r
+        \r
+        SrcFileDir = "."\r
+        SrcPath = os.path.dirname(SrcFile)\r
+        SrcFileName = os.path.basename(SrcFile)\r
+        SrcFileBase, SrcFileExt = os.path.splitext(SrcFileName)   \r
+        DestPath = os.path.dirname(DestFile)\r
+        DestFileName = os.path.basename(DestFile)\r
+        DestFileBase, DestFileExt = os.path.splitext(DestFileName)   \r
+        self.MacroDict = {\r
+            # source file\r
+            "${src}"      :   SrcFile,\r
+            "${s_path}"   :   SrcPath,\r
+            "${s_dir}"    :   SrcFileDir,\r
+            "${s_name}"   :   SrcFileName,\r
+            "${s_base}"   :   SrcFileBase,\r
+            "${s_ext}"    :   SrcFileExt,\r
+            # destination file\r
+            "${dst}"      :   DestFile,\r
+            "${d_path}"   :   DestPath,\r
+            "${d_name}"   :   DestFileName,\r
+            "${d_base}"   :   DestFileBase,\r
+            "${d_ext}"    :   DestFileExt\r
+        }\r
+        #\r
+        # Allow binary type module not specify override rule in FDF file.\r
+        # \r
+        if len(self.BinFileList) > 0:\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 +406,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
@@ -211,6 +448,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
             '$(NAMED_GUID)'  : self.ModuleGuid\r
         }\r
         String = GenFdsGlobalVariable.MacroExtend(String, MacroDict)\r
+        String = GenFdsGlobalVariable.MacroExtend(String, self.MacroDict)        \r
         return String\r
 \r
     ## __GetRule__() method\r
@@ -274,33 +512,38 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #\r
     def __GetPlatformArchList__(self):\r
 \r
-        InfFileKey = os.path.normpath(os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName))\r
+        InfFileKey = os.path.normpath(mws.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName))\r
         DscArchList = []\r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IA32']\r
+        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IA32', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
         if  PlatformDataBase != None:\r
             if InfFileKey in PlatformDataBase.Modules:\r
                 DscArchList.append ('IA32')\r
 \r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'X64']\r
+        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'X64', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
         if  PlatformDataBase != None:\r
             if InfFileKey in PlatformDataBase.Modules:\r
                 DscArchList.append ('X64')\r
 \r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IPF']\r
+        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IPF', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
         if PlatformDataBase != None:\r
             if InfFileKey in (PlatformDataBase.Modules):\r
                 DscArchList.append ('IPF')\r
 \r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'ARM']\r
+        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'ARM', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
         if PlatformDataBase != None:\r
             if InfFileKey in (PlatformDataBase.Modules):\r
                 DscArchList.append ('ARM')\r
 \r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'EBC']\r
+        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'EBC', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
         if PlatformDataBase != None:\r
             if InfFileKey in (PlatformDataBase.Modules):\r
                 DscArchList.append ('EBC')\r
 \r
+        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'AARCH64', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+        if PlatformDataBase != None:\r
+            if InfFileKey in (PlatformDataBase.Modules):\r
+                DscArchList.append ('AARCH64')\r
+\r
         return DscArchList\r
 \r
     ## GetCurrentArch() method\r
@@ -343,7 +586,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
@@ -369,8 +612,10 @@ class FfsInfStatement(FfsInfStatementClassObject):
         Arch = ''\r
         OutputPath = ''\r
         (ModulePath, FileName) = os.path.split(self.InfFileName)\r
-        Index = FileName.find('.')\r
+        Index = FileName.rfind('.')\r
         FileName = FileName[0:Index]\r
+        if self.OverrideGuid:\r
+            FileName = self.OverrideGuid\r
         Arch = "NoneArch"\r
         if self.CurrentArch != None:\r
             Arch = self.CurrentArch\r
@@ -401,9 +646,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 +658,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
@@ -452,8 +697,8 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 if not NoStrip:\r
                     FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
                     if not os.path.exists(FileBeforeStrip) or \\r
-                        (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
-                        shutil.copyfile(File, FileBeforeStrip)\r
+                           (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
+                        CopyLongFilePath(File, FileBeforeStrip)\r
                     StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
                     GenFdsGlobalVariable.GenerateFirmwareImage(\r
                                             StrippedFile,\r
@@ -491,8 +736,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
             if not NoStrip:\r
                 FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
                 if not os.path.exists(FileBeforeStrip) or \\r
-                    (os.path.getmtime(GenSecInputFile) > os.path.getmtime(FileBeforeStrip)):\r
-                    shutil.copyfile(GenSecInputFile, FileBeforeStrip)\r
+                       (os.path.getmtime(GenSecInputFile) > os.path.getmtime(FileBeforeStrip)):\r
+                    CopyLongFilePath(GenSecInputFile, FileBeforeStrip)\r
+\r
                 StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
                 GenFdsGlobalVariable.GenerateFirmwareImage(\r
                                         StrippedFile,\r
@@ -575,19 +821,44 @@ class FfsInfStatement(FfsInfStatementClassObject):
         SectFiles = []\r
         SectAlignments = []\r
         Index = 1\r
+        HasGneratedFlag = False\r
+        if self.PcdIsDriver == 'PEI_PCD_DRIVER':\r
+            if self.IsBinaryModule:\r
+                PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "PEIPcdDataBase.raw")\r
+            else:\r
+                PcdExDbFileName = os.path.join(self.EfiOutputPath, "PEIPcdDataBase.raw")\r
+            PcdExDbSecName = os.path.join(self.OutputPath, "PEIPcdDataBaseSec.raw")\r
+            GenFdsGlobalVariable.GenerateSection(PcdExDbSecName,\r
+                                                 [PcdExDbFileName],\r
+                                                 "EFI_SECTION_RAW",\r
+                                                 )\r
+            SectFiles.append(PcdExDbSecName)\r
+            SectAlignments.append(None)\r
+        elif self.PcdIsDriver == 'DXE_PCD_DRIVER':\r
+            if self.IsBinaryModule:\r
+                PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "DXEPcdDataBase.raw")\r
+            else:\r
+                PcdExDbFileName = os.path.join(self.EfiOutputPath, "DXEPcdDataBase.raw")\r
+            PcdExDbSecName = os.path.join(self.OutputPath, "DXEPcdDataBaseSec.raw")\r
+            GenFdsGlobalVariable.GenerateSection(PcdExDbSecName,\r
+                                                 [PcdExDbFileName],\r
+                                                 "EFI_SECTION_RAW",\r
+                                                 )\r
+            SectFiles.append(PcdExDbSecName)\r
+            SectAlignments.append(None)\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 +876,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 = mws.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 +980,78 @@ 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
+        MapFileName = os.path.join(self.EfiOutputPath, self.BaseName + ".map")\r
+        EfiFileName = os.path.join(self.EfiOutputPath, self.BaseName + ".efi")\r
+        return GetVariableOffset(MapFileName, EfiFileName, VfrUniBaseName.values())\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