]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
BaseTools: Update Makefile to support FFS file generation
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFdsGlobalVariable.py
index 83996beeea958f8518430909fc4cf4f99503328c..371d5a8217f70ffcf3cbe8175d79ac2cc8b7a1a4 100644 (file)
@@ -69,6 +69,11 @@ class GenFdsGlobalVariable:
     ToolChainFamily = "MSFT"\r
     __BuildRuleDatabase = None\r
     GuidToolDefinition = {}\r
+    FfsCmdDict = {}\r
+    SecCmdList = []\r
+    CopyList   = []\r
+    ModuleFile = ''\r
+    EnableGenfdsMultiThread = False\r
     \r
     #\r
     # The list whose element are flags to indicate if large FFS or SECTION files exist in FV.\r
@@ -264,6 +269,10 @@ class GenFdsGlobalVariable:
                 SourceList.extend(Target.Outputs)\r
                 LastTarget = Target\r
                 FileType = DataType.TAB_UNKNOWN_FILE\r
+                for Cmd in Target.Commands:\r
+                    if "$(CP)" == Cmd.split()[0]:\r
+                        CpTarget = Cmd.split()[2]\r
+                        TargetList.add(CpTarget)\r
 \r
         return list(TargetList)\r
 \r
@@ -317,6 +326,73 @@ class GenFdsGlobalVariable:
 \r
         FvAddressFile.close()\r
 \r
+    def SetEnv(FdfParser, WorkSpace, ArchList, GlobalData):\r
+        GenFdsGlobalVariable.ModuleFile = WorkSpace.ModuleFile\r
+        GenFdsGlobalVariable.FdfParser = FdfParser\r
+        GenFdsGlobalVariable.WorkSpace = WorkSpace.Db\r
+        GenFdsGlobalVariable.ArchList = ArchList\r
+        GenFdsGlobalVariable.ToolChainTag = GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]\r
+        GenFdsGlobalVariable.TargetName = GlobalData.gGlobalDefines["TARGET"]\r
+        GenFdsGlobalVariable.ActivePlatform = GlobalData.gActivePlatform\r
+        GenFdsGlobalVariable.EdkSourceDir = GlobalData.gGlobalDefines["EDK_SOURCE"]\r
+        GenFdsGlobalVariable.ConfDir  = GlobalData.gConfDirectory\r
+        GenFdsGlobalVariable.EnableGenfdsMultiThread = GlobalData.gEnableGenfdsMultiThread\r
+        for Arch in ArchList:\r
+            GenFdsGlobalVariable.OutputDirDict[Arch] = os.path.normpath(\r
+                os.path.join(GlobalData.gWorkspace,\r
+                             WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,GlobalData.gGlobalDefines['TARGET'],\r
+                             GlobalData.gGlobalDefines['TOOLCHAIN']].OutputDirectory,\r
+                             GlobalData.gGlobalDefines['TARGET'] +'_' + GlobalData.gGlobalDefines['TOOLCHAIN']))\r
+            GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = os.path.normpath(\r
+                             WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
+                             GlobalData.gGlobalDefines['TARGET'], GlobalData.gGlobalDefines['TOOLCHAIN']].OutputDirectory)\r
+            GenFdsGlobalVariable.PlatformName = WorkSpace.Db.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
+                                                                      GlobalData.gGlobalDefines['TARGET'],\r
+                                                                      GlobalData.gGlobalDefines['TOOLCHAIN']].PlatformName\r
+        GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], 'FV')\r
+        if not os.path.exists(GenFdsGlobalVariable.FvDir):\r
+            os.makedirs(GenFdsGlobalVariable.FvDir)\r
+        GenFdsGlobalVariable.FfsDir = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs')\r
+        if not os.path.exists(GenFdsGlobalVariable.FfsDir):\r
+            os.makedirs(GenFdsGlobalVariable.FfsDir)\r
+\r
+        T_CHAR_LF = '\n'\r
+        #\r
+        # Create FV Address inf file\r
+        #\r
+        GenFdsGlobalVariable.FvAddressFileName = os.path.join(GenFdsGlobalVariable.FfsDir, 'FvAddress.inf')\r
+        FvAddressFile = open(GenFdsGlobalVariable.FvAddressFileName, 'w')\r
+        #\r
+        # Add [Options]\r
+        #\r
+        FvAddressFile.writelines("[options]" + T_CHAR_LF)\r
+        BsAddress = '0'\r
+        for Arch in ArchList:\r
+            BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch,\r
+                                                                   GlobalData.gGlobalDefines['TARGET'],\r
+                                                                   GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].BsBaseAddress\r
+            if BsAddress:\r
+                break\r
+\r
+        FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
+                                 BsAddress + \\r
+                                 T_CHAR_LF)\r
+\r
+        RtAddress = '0'\r
+        for Arch in ArchList:\r
+            if GenFdsGlobalVariable.WorkSpace.BuildObject[\r
+                GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],\r
+                GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].RtBaseAddress:\r
+                RtAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[\r
+                    GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],\r
+                    GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].RtBaseAddress\r
+\r
+        FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
+                                 RtAddress + \\r
+                                 T_CHAR_LF)\r
+\r
+        FvAddressFile.close()\r
+\r
     ## ReplaceWorkspaceMacro()\r
     #\r
     #   @param  String           String that may contain macro\r
@@ -363,7 +439,7 @@ class GenFdsGlobalVariable:
 \r
     @staticmethod\r
     def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None,\r
-                        GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None, BuildNumber=None):\r
+                        GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None, BuildNumber=None, DummyFile=None, IsMakefile=False):\r
         Cmd = ["GenSec"]\r
         if Type not in [None, '']:\r
             Cmd += ["-s", Type]\r
@@ -371,6 +447,8 @@ class GenFdsGlobalVariable:
             Cmd += ["-c", CompressionType]\r
         if Guid != None:\r
             Cmd += ["-g", Guid]\r
+        if DummyFile != None:\r
+            Cmd += ["--dummy", DummyFile]\r
         if GuidHdrLen not in [None, '']:\r
             Cmd += ["-l", GuidHdrLen]\r
         if len(GuidAttr) != 0:\r
@@ -385,13 +463,21 @@ class GenFdsGlobalVariable:
         CommandFile = Output + '.txt'\r
         if Ui not in [None, '']:\r
             #Cmd += ["-n", '"' + Ui + '"']\r
-            SectionData = array.array('B', [0, 0, 0, 0])\r
-            SectionData.fromstring(Ui.encode("utf_16_le"))\r
-            SectionData.append(0)\r
-            SectionData.append(0)\r
-            Len = len(SectionData)\r
-            GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)\r
-            SaveFileOnChange(Output, SectionData.tostring())\r
+            if IsMakefile:\r
+                Cmd += ["-n", "$(MODULE_NAME)"]\r
+                Cmd += ["-o", Output]\r
+                #SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
+                if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                    GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
+            else:\r
+                SectionData = array.array('B', [0, 0, 0, 0])\r
+                SectionData.fromstring(Ui.encode("utf_16_le"))\r
+                SectionData.append(0)\r
+                SectionData.append(0)\r
+                Len = len(SectionData)\r
+                GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)\r
+                SaveFileOnChange(Output, SectionData.tostring())\r
+\r
         elif Ver not in [None, '']:\r
             Cmd += ["-n", Ver]\r
             if BuildNumber:\r
@@ -399,22 +485,27 @@ class GenFdsGlobalVariable:
             Cmd += ["-o", Output]\r
 \r
             SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
-            if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
-                return\r
-\r
-            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
+            if IsMakefile:\r
+                if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                    GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
+            else:\r
+                if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
+                    return\r
+                GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
         else:\r
             Cmd += ["-o", Output]\r
             Cmd += Input\r
 \r
             SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
-            if GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
+            if IsMakefile:\r
+                if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                    GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
+            elif GenFdsGlobalVariable.NeedsUpdate(Output, list(Input)):\r
                 GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
                 GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate section")\r
-\r
-            if (os.path.getsize(Output) >= GenFdsGlobalVariable.LARGE_FILE_SIZE and\r
-                GenFdsGlobalVariable.LargeFileInFvFlags):\r
-                GenFdsGlobalVariable.LargeFileInFvFlags[-1] = True \r
+                if (os.path.getsize(Output) >= GenFdsGlobalVariable.LARGE_FILE_SIZE and\r
+                    GenFdsGlobalVariable.LargeFileInFvFlags):\r
+                    GenFdsGlobalVariable.LargeFileInFvFlags[-1] = True\r
 \r
     @staticmethod\r
     def GetAlignment (AlignString):\r
@@ -429,7 +520,7 @@ class GenFdsGlobalVariable:
 \r
     @staticmethod\r
     def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None,\r
-                    SectionAlign=None):\r
+                    SectionAlign=None, MakefilePath=None):\r
         Cmd = ["GenFfs", "-t", Type, "-g", Guid]\r
         mFfsValidAlign = ["0", "8", "16", "128", "512", "1K", "4K", "32K", "64K", "128K", "256K", "512K", "1M", "2M", "4M", "8M", "16M"]\r
         if Fixed == True:\r
@@ -453,11 +544,17 @@ class GenFdsGlobalVariable:
 \r
         CommandFile = Output + '.txt'\r
         SaveFileOnChange(CommandFile, ' '.join(Cmd), False)\r
-        if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\r
-            return\r
-        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
 \r
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FFS")\r
+        GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
+        if MakefilePath:\r
+            if (tuple(Cmd),tuple(GenFdsGlobalVariable.SecCmdList),tuple(GenFdsGlobalVariable.CopyList)) not in GenFdsGlobalVariable.FfsCmdDict.keys():\r
+                GenFdsGlobalVariable.FfsCmdDict[tuple(Cmd), tuple(GenFdsGlobalVariable.SecCmdList), tuple(GenFdsGlobalVariable.CopyList)] = MakefilePath\r
+            GenFdsGlobalVariable.SecCmdList = []\r
+            GenFdsGlobalVariable.CopyList = []\r
+        else:\r
+            if not GenFdsGlobalVariable.NeedsUpdate(Output, list(Input)):\r
+                return\r
+            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FFS")\r
 \r
     @staticmethod\r
     def GenerateFirmwareVolume(Output, Input, BaseAddress=None, ForceRebase=None, Capsule=False, Dump=False,\r
@@ -511,8 +608,8 @@ class GenFdsGlobalVariable:
     @staticmethod\r
     def GenerateFirmwareImage(Output, Input, Type="efi", SubType=None, Zero=False,\r
                               Strip=False, Replace=False, TimeStamp=None, Join=False,\r
-                              Align=None, Padding=None, Convert=False):\r
-        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
+                              Align=None, Padding=None, Convert=False, IsMakefile=False):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input) and not IsMakefile:\r
             return\r
         GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
 \r
@@ -539,12 +636,15 @@ class GenFdsGlobalVariable:
             Cmd += ["-m"]\r
         Cmd += ["-o", Output]\r
         Cmd += Input\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate firmware image")\r
+        if IsMakefile:\r
+            if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())\r
+        else:\r
+            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate firmware image")\r
 \r
     @staticmethod\r
     def GenerateOptionRom(Output, EfiInput, BinaryInput, Compress=False, ClassCode=None,\r
-                        Revision=None, DeviceId=None, VendorId=None):\r
+                        Revision=None, DeviceId=None, VendorId=None, IsMakefile=False):\r
         InputList = []   \r
         Cmd = ["EfiRom"]\r
         if len(EfiInput) > 0:\r
@@ -565,7 +665,7 @@ class GenFdsGlobalVariable:
                 InputList.append (BinFile)\r
 \r
         # Check List\r
-        if not GenFdsGlobalVariable.NeedsUpdate(Output, InputList):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, InputList) and not IsMakefile:\r
             return\r
         GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, InputList))\r
                         \r
@@ -579,11 +679,15 @@ class GenFdsGlobalVariable:
             Cmd += ["-f", VendorId]\r
 \r
         Cmd += ["-o", Output]\r
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")\r
+        if IsMakefile:\r
+            if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())\r
+        else:\r
+            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")\r
 \r
     @staticmethod\r
-    def GuidTool(Output, Input, ToolPath, Options='', returnValue=[]):\r
-        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
+    def GuidTool(Output, Input, ToolPath, Options='', returnValue=[], IsMakefile=False):\r
+        if not GenFdsGlobalVariable.NeedsUpdate(Output, Input) and not IsMakefile:\r
             return\r
         GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
 \r
@@ -591,8 +695,11 @@ class GenFdsGlobalVariable:
         Cmd += Options.split(' ')\r
         Cmd += ["-o", Output]\r
         Cmd += Input\r
-\r
-        GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)\r
+        if IsMakefile:\r
+            if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+                GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())\r
+        else:\r
+            GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)\r
 \r
     def CallExternalTool (cmd, errorMess, returnValue=[]):\r
 \r
@@ -727,6 +834,7 @@ class GenFdsGlobalVariable:
         return PcdValue\r
 \r
     SetDir = staticmethod(SetDir)\r
+    SetEnv = staticmethod(SetEnv)\r
     ReplaceWorkspaceMacro = staticmethod(ReplaceWorkspaceMacro)\r
     CallExternalTool = staticmethod(CallExternalTool)\r
     VerboseLogger = staticmethod(VerboseLogger)\r