## @file\r
# Global variables for GenFds\r
#\r
-# Copyright (c) 2007 - 2014, 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
-# which accompanies this distribution. The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
\r
##\r
# Import Modules\r
#\r
+from __future__ import print_function\r
+from __future__ import absolute_import\r
+\r
import Common.LongFilePathOs as os\r
import sys\r
-import subprocess\r
-import struct\r
-import array\r
+from sys import stdout\r
+from subprocess import PIPE,Popen\r
+from struct import Struct\r
+from array import array\r
\r
-from Common.BuildToolError import *\r
+from Common.BuildToolError import COMMAND_FAILURE,GENFDS_ERROR\r
from Common import EdkLogger\r
from Common.Misc import SaveFileOnChange\r
\r
-from Common.TargetTxtClassObject import TargetTxtClassObject\r
-from Common.ToolDefClassObject import ToolDefClassObject\r
-from AutoGen.BuildEngine import BuildRule\r
+from Common.TargetTxtClassObject import TargetTxtDict\r
+from Common.ToolDefClassObject import ToolDefDict\r
+from AutoGen.BuildEngine import ToolBuildRule\r
import Common.DataType as DataType\r
from Common.Misc import PathClass\r
from Common.LongFilePathSupport import OpenLongFilePath as open\r
from Common.MultipleWorkspace import MultipleWorkspace as mws\r
+import Common.GlobalData as GlobalData\r
\r
## Global variables\r
#\r
WorkSpace = None\r
WorkSpaceDir = ''\r
ConfDir = ''\r
- EdkSourceDir = ''\r
OutputDirFromDscDict = {}\r
TargetName = ''\r
ToolChainTag = ''\r
RuleDict = {}\r
ArchList = None\r
- VtfDict = {}\r
ActivePlatform = None\r
FvAddressFileName = ''\r
VerboseMode = False\r
FdfFileTimeStamp = 0\r
FixedLoadAddress = False\r
PlatformName = ''\r
- \r
- BuildRuleFamily = "MSFT"\r
- ToolChainFamily = "MSFT"\r
+\r
+ BuildRuleFamily = DataType.TAB_COMPILER_MSFT\r
+ ToolChainFamily = DataType.TAB_COMPILER_MSFT\r
__BuildRuleDatabase = None\r
- \r
+ GuidToolDefinition = {}\r
+ FfsCmdDict = {}\r
+ SecCmdList = []\r
+ CopyList = []\r
+ ModuleFile = ''\r
+ EnableGenfdsMultiThread = True\r
+\r
#\r
# The list whose element are flags to indicate if large FFS or SECTION files exist in FV.\r
# At the beginning of each generation of FV, false flag is appended to the list,\r
EFI_FIRMWARE_FILE_SYSTEM3_GUID = '5473C07A-3DCB-4dca-BD6F-1E9689E7349A'\r
LARGE_FILE_SIZE = 0x1000000\r
\r
- SectionHeader = struct.Struct("3B 1B")\r
- \r
+ SectionHeader = Struct("3B 1B")\r
+\r
+ # FvName, FdName, CapName in FDF, Image file name\r
+ ImageBinDict = {}\r
+\r
## LoadBuildRule\r
#\r
@staticmethod\r
- def __LoadBuildRule():\r
+ def _LoadBuildRule():\r
if GenFdsGlobalVariable.__BuildRuleDatabase:\r
return GenFdsGlobalVariable.__BuildRuleDatabase\r
- BuildConfigurationFile = os.path.normpath(os.path.join(GenFdsGlobalVariable.ConfDir, "target.txt"))\r
- TargetTxt = TargetTxtClassObject()\r
- if os.path.isfile(BuildConfigurationFile) == True:\r
- TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)\r
- if DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary:\r
- BuildRuleFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
- if BuildRuleFile in [None, '']:\r
- BuildRuleFile = 'Conf/build_rule.txt'\r
- GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)\r
- ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
- if ToolDefinitionFile == '':\r
- ToolDefinitionFile = "Conf/tools_def.txt"\r
- if os.path.isfile(ToolDefinitionFile):\r
- ToolDef = ToolDefClassObject()\r
- ToolDef.LoadToolDefFile(ToolDefinitionFile)\r
- ToolDefinition = ToolDef.ToolsDefTxtDatabase\r
- if DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY in ToolDefinition \\r
- and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
- and ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
- GenFdsGlobalVariable.BuildRuleFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]\r
- \r
- if DataType.TAB_TOD_DEFINES_FAMILY in ToolDefinition \\r
- and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY] \\r
- and ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
- GenFdsGlobalVariable.ToolChainFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]\r
+ BuildRule = ToolBuildRule()\r
+ GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule.ToolBuildRule\r
+ TargetObj = TargetTxtDict()\r
+ ToolDefinitionFile = TargetObj.Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
+ if ToolDefinitionFile == '':\r
+ ToolDefinitionFile = "Conf/tools_def.txt"\r
+ if os.path.isfile(ToolDefinitionFile):\r
+ ToolDefObj = ToolDefDict((os.path.join(os.getenv("WORKSPACE"), "Conf")))\r
+ ToolDefinition = ToolDefObj.ToolDef.ToolsDefTxtDatabase\r
+ if DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY in ToolDefinition \\r
+ and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
+ and ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
+ GenFdsGlobalVariable.BuildRuleFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]\r
+\r
+ if DataType.TAB_TOD_DEFINES_FAMILY in ToolDefinition \\r
+ and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY] \\r
+ and ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
+ GenFdsGlobalVariable.ToolChainFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]\r
return GenFdsGlobalVariable.__BuildRuleDatabase\r
\r
## GetBuildRules\r
@staticmethod\r
def GetBuildRules(Inf, Arch):\r
if not Arch:\r
- Arch = 'COMMON'\r
+ Arch = DataType.TAB_COMMON\r
\r
if not Arch in GenFdsGlobalVariable.OutputDirDict:\r
return {}\r
\r
- BuildRuleDatabase = GenFdsGlobalVariable.__LoadBuildRule()\r
+ BuildRuleDatabase = GenFdsGlobalVariable._LoadBuildRule()\r
if not BuildRuleDatabase:\r
return {}\r
\r
PathClassObj = PathClass(Inf.MetaFile.File,\r
GenFdsGlobalVariable.WorkSpaceDir)\r
- Macro = {}\r
- Macro["WORKSPACE" ] = GenFdsGlobalVariable.WorkSpaceDir\r
- Macro["MODULE_NAME" ] = Inf.BaseName\r
- Macro["MODULE_GUID" ] = Inf.Guid\r
- Macro["MODULE_VERSION" ] = Inf.Version\r
- Macro["MODULE_TYPE" ] = Inf.ModuleType\r
- Macro["MODULE_FILE" ] = str(PathClassObj)\r
- Macro["MODULE_FILE_BASE_NAME" ] = PathClassObj.BaseName\r
- Macro["MODULE_RELATIVE_DIR" ] = PathClassObj.SubDir\r
- Macro["MODULE_DIR" ] = PathClassObj.SubDir\r
-\r
- Macro["BASE_NAME" ] = Inf.BaseName\r
-\r
- Macro["ARCH" ] = Arch\r
- Macro["TOOLCHAIN" ] = GenFdsGlobalVariable.ToolChainTag\r
- Macro["TOOLCHAIN_TAG" ] = GenFdsGlobalVariable.ToolChainTag\r
- Macro["TOOL_CHAIN_TAG" ] = GenFdsGlobalVariable.ToolChainTag\r
- Macro["TARGET" ] = GenFdsGlobalVariable.TargetName\r
-\r
- Macro["BUILD_DIR" ] = GenFdsGlobalVariable.OutputDirDict[Arch]\r
- Macro["BIN_DIR" ] = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch], Arch)\r
- Macro["LIB_DIR" ] = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch], Arch)\r
BuildDir = os.path.join(\r
GenFdsGlobalVariable.OutputDirDict[Arch],\r
Arch,\r
PathClassObj.SubDir,\r
PathClassObj.BaseName\r
)\r
- Macro["MODULE_BUILD_DIR" ] = BuildDir\r
- Macro["OUTPUT_DIR" ] = os.path.join(BuildDir, "OUTPUT")\r
- Macro["DEBUG_DIR" ] = os.path.join(BuildDir, "DEBUG")\r
+ BinDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch], Arch)\r
+ Macro = {\r
+ "WORKSPACE":GenFdsGlobalVariable.WorkSpaceDir,\r
+ "MODULE_NAME":Inf.BaseName,\r
+ "MODULE_GUID":Inf.Guid,\r
+ "MODULE_VERSION":Inf.Version,\r
+ "MODULE_TYPE":Inf.ModuleType,\r
+ "MODULE_FILE":str(PathClassObj),\r
+ "MODULE_FILE_BASE_NAME":PathClassObj.BaseName,\r
+ "MODULE_RELATIVE_DIR":PathClassObj.SubDir,\r
+ "MODULE_DIR":PathClassObj.SubDir,\r
+ "BASE_NAME":Inf.BaseName,\r
+ "ARCH":Arch,\r
+ "TOOLCHAIN":GenFdsGlobalVariable.ToolChainTag,\r
+ "TOOLCHAIN_TAG":GenFdsGlobalVariable.ToolChainTag,\r
+ "TOOL_CHAIN_TAG":GenFdsGlobalVariable.ToolChainTag,\r
+ "TARGET":GenFdsGlobalVariable.TargetName,\r
+ "BUILD_DIR":GenFdsGlobalVariable.OutputDirDict[Arch],\r
+ "BIN_DIR":BinDir,\r
+ "LIB_DIR":BinDir,\r
+ "MODULE_BUILD_DIR":BuildDir,\r
+ "OUTPUT_DIR":os.path.join(BuildDir, "OUTPUT"),\r
+ "DEBUG_DIR":os.path.join(BuildDir, "DEBUG")\r
+ }\r
\r
BuildRules = {}\r
for Type in BuildRuleDatabase.FileTypeList:\r
\r
if not Inf.IsBinaryModule:\r
for File in Inf.Sources:\r
- if File.TagName in ("", "*", GenFdsGlobalVariable.ToolChainTag) and \\r
- File.ToolChainFamily in ("", "*", GenFdsGlobalVariable.ToolChainFamily):\r
+ if File.TagName in {"", DataType.TAB_STAR, GenFdsGlobalVariable.ToolChainTag} and \\r
+ File.ToolChainFamily in {"", DataType.TAB_STAR, GenFdsGlobalVariable.ToolChainFamily}:\r
FileList.append((File, DataType.TAB_UNKNOWN_FILE))\r
\r
for File in Inf.Binaries:\r
- if File.Target in ['COMMON', '*', GenFdsGlobalVariable.TargetName]:\r
+ if File.Target in {DataType.TAB_COMMON, DataType.TAB_STAR, GenFdsGlobalVariable.TargetName}:\r
FileList.append((File, File.Type))\r
\r
for File, FileType in FileList:\r
while Index < len(SourceList):\r
Source = SourceList[Index]\r
Index = Index + 1\r
- \r
- if File.IsBinary and File == Source and Inf.Binaries != None and File in Inf.Binaries:\r
+\r
+ if File.IsBinary and File == Source and Inf.Binaries and File in Inf.Binaries:\r
# Skip all files that are not binary libraries\r
if not Inf.LibraryClass:\r
- continue \r
+ continue\r
RuleObject = BuildRules[DataType.TAB_DEFAULT_BINARY_FILE]\r
elif FileType in BuildRules:\r
RuleObject = BuildRules[FileType]\r
if LastTarget:\r
TargetList.add(str(LastTarget))\r
break\r
- \r
+\r
FileType = RuleObject.SourceFileType\r
- \r
+\r
# stop at STATIC_LIBRARY for library\r
if Inf.LibraryClass and FileType == DataType.TAB_STATIC_LIBRARY:\r
if LastTarget:\r
TargetList.add(str(LastTarget))\r
break\r
- \r
+\r
Target = RuleObject.Apply(Source)\r
if not Target:\r
if LastTarget:\r
elif not Target.Outputs:\r
# Only do build for target with outputs\r
TargetList.add(str(Target))\r
- \r
+\r
# to avoid cyclic rule\r
if FileType in RuleChain:\r
break\r
- \r
+\r
RuleChain.append(FileType)\r
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
# @param Workspace The directory of workspace\r
# @param ArchList The Arch list of platform\r
#\r
+ @staticmethod\r
def SetDir (OutputDir, FdfParser, WorkSpace, ArchList):\r
- GenFdsGlobalVariable.VerboseLogger( "GenFdsGlobalVariable.OutputDir :%s" %OutputDir)\r
-# GenFdsGlobalVariable.OutputDirDict = OutputDir\r
+ GenFdsGlobalVariable.VerboseLogger("GenFdsGlobalVariable.OutputDir:%s" % OutputDir)\r
GenFdsGlobalVariable.FdfParser = FdfParser\r
GenFdsGlobalVariable.WorkSpace = WorkSpace\r
- GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], 'FV')\r
- if not os.path.exists(GenFdsGlobalVariable.FvDir) :\r
+ GenFdsGlobalVariable.FvDir = os.path.join(GenFdsGlobalVariable.OutputDirDict[ArchList[0]], DataType.TAB_FV_DIRECTORY)\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
+ if not os.path.exists(GenFdsGlobalVariable.FfsDir):\r
os.makedirs(GenFdsGlobalVariable.FfsDir)\r
- if ArchList != None:\r
- GenFdsGlobalVariable.ArchList = ArchList\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
+ FvAddressFile = open(GenFdsGlobalVariable.FvAddressFileName, 'w')\r
#\r
# Add [Options]\r
#\r
- FvAddressFile.writelines("[options]" + T_CHAR_LF)\r
+ FvAddressFile.writelines("[options]" + DataType.TAB_LINE_BREAK)\r
BsAddress = '0'\r
for Arch in ArchList:\r
if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].BsBaseAddress:\r
break\r
\r
FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
- BsAddress + \\r
- T_CHAR_LF)\r
+ BsAddress + \\r
+ DataType.TAB_LINE_BREAK)\r
\r
RtAddress = '0'\r
+ for Arch in reversed(ArchList):\r
+ temp = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress\r
+ if temp:\r
+ RtAddress = temp\r
+ break\r
+\r
+ FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
+ RtAddress + \\r
+ DataType.TAB_LINE_BREAK)\r
+\r
+ FvAddressFile.close()\r
+\r
+ @staticmethod\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.ConfDir = GlobalData.gConfDirectory\r
+ GenFdsGlobalVariable.EnableGenfdsMultiThread = GlobalData.gEnableGenfdsMultiThread\r
for Arch in ArchList:\r
- if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress:\r
- RtAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].RtBaseAddress\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]], DataType.TAB_FV_DIRECTORY)\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
+ #\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]" + DataType.TAB_LINE_BREAK)\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
+ DataType.TAB_LINE_BREAK)\r
+\r
+ RtAddress = '0'\r
+ for Arch in reversed(ArchList):\r
+ temp = GenFdsGlobalVariable.WorkSpace.BuildObject[\r
+ GenFdsGlobalVariable.ActivePlatform, Arch, GlobalData.gGlobalDefines['TARGET'],\r
+ GlobalData.gGlobalDefines["TOOL_CHAIN_TAG"]].RtBaseAddress\r
+ if temp:\r
+ RtAddress = temp\r
+ break\r
\r
FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
- RtAddress + \\r
- T_CHAR_LF)\r
+ RtAddress + \\r
+ DataType.TAB_LINE_BREAK)\r
\r
FvAddressFile.close()\r
\r
#\r
# @param String String that may contain macro\r
#\r
+ @staticmethod\r
def ReplaceWorkspaceMacro(String):\r
String = mws.handleWsMacro(String)\r
Str = String.replace('$(WORKSPACE)', GenFdsGlobalVariable.WorkSpaceDir)\r
if not os.path.exists(Output):\r
return True\r
# always update "Output" if no "Input" given\r
- if Input == None or len(Input) == 0:\r
+ if not Input:\r
return True\r
\r
# if fdf file is changed after the 'Output" is generated, update the 'Output'\r
\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=[], BuildNumber=None, DummyFile=None, IsMakefile=False):\r
Cmd = ["GenSec"]\r
- if Type not in [None, '']:\r
- Cmd += ["-s", Type]\r
- if CompressionType not in [None, '']:\r
- Cmd += ["-c", CompressionType]\r
- if Guid != None:\r
- Cmd += ["-g", Guid]\r
- if GuidHdrLen not in [None, '']:\r
- Cmd += ["-l", GuidHdrLen]\r
- if len(GuidAttr) != 0:\r
- #Add each guided attribute\r
- for Attr in GuidAttr:\r
- Cmd += ["-r", Attr]\r
- if InputAlign != None:\r
- #Section Align is only for dummy section without section type\r
- for SecAlign in InputAlign:\r
- Cmd += ["--sectionalign", SecAlign]\r
+ if Type:\r
+ Cmd += ("-s", Type)\r
+ if CompressionType:\r
+ Cmd += ("-c", CompressionType)\r
+ if Guid:\r
+ Cmd += ("-g", Guid)\r
+ if DummyFile:\r
+ Cmd += ("--dummy", DummyFile)\r
+ if GuidHdrLen:\r
+ Cmd += ("-l", GuidHdrLen)\r
+ #Add each guided attribute\r
+ for Attr in GuidAttr:\r
+ Cmd += ("-r", Attr)\r
+ #Section Align is only for dummy section without section type\r
+ for SecAlign in InputAlign:\r
+ Cmd += ("--sectionalign", SecAlign)\r
\r
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
- elif Ver not in [None, '']:\r
- Cmd += ["-n", Ver]\r
+ if Ui:\r
+ if IsMakefile:\r
+ if Ui == "$(MODULE_NAME)":\r
+ Cmd += ('-n', Ui)\r
+ else:\r
+ Cmd += ("-n", '"' + Ui + '"')\r
+ Cmd += ("-o", Output)\r
+ if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+ GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
+ else:\r
+ SectionData = 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:\r
+ Cmd += ("-n", Ver)\r
if BuildNumber:\r
- Cmd += ["-j", BuildNumber]\r
- Cmd += ["-o", Output]\r
+ Cmd += ("-j", BuildNumber)\r
+ 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 += ("-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 sys.platform == "win32":\r
+ Cmd = ['if', 'exist', Input[0]] + Cmd\r
+ else:\r
+ Cmd = ['-test', '-e', Input[0], "&&"] + Cmd\r
+ if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:\r
+ GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
+ elif GenFdsGlobalVariable.NeedsUpdate(Output, list(Input) + [CommandFile]):\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
- if AlignString == None:\r
+ if not AlignString:\r
return 0\r
- if AlignString in ("1K", "2K", "4K", "8K", "16K", "32K", "64K"):\r
+ if AlignString.endswith('K'):\r
return int (AlignString.rstrip('K')) * 1024\r
- else:\r
- return int (AlignString)\r
+ if AlignString.endswith('M'):\r
+ return int (AlignString.rstrip('M')) * 1024 * 1024\r
+ if AlignString.endswith('G'):\r
+ return int (AlignString.rstrip('G')) * 1024 * 1024 * 1024\r
+ return int (AlignString)\r
\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
- Cmd += ["-x"]\r
+ Cmd.append("-x")\r
if CheckSum:\r
- Cmd += ["-s"]\r
- if Align not in [None, '']:\r
- Cmd += ["-a", Align]\r
-\r
- Cmd += ["-o", Output]\r
+ Cmd.append("-s")\r
+ if Align:\r
+ if Align not in mFfsValidAlign:\r
+ Align = GenFdsGlobalVariable.GetAlignment (Align)\r
+ for index in range(0, len(mFfsValidAlign) - 1):\r
+ if ((Align > GenFdsGlobalVariable.GetAlignment(mFfsValidAlign[index])) and (Align <= GenFdsGlobalVariable.GetAlignment(mFfsValidAlign[index + 1]))):\r
+ break\r
+ Align = mFfsValidAlign[index + 1]\r
+ Cmd += ("-a", Align)\r
+\r
+ Cmd += ("-o", Output)\r
for I in range(0, len(Input)):\r
- Cmd += ("-i", Input[I])\r
- if SectionAlign not in [None, '', []] and SectionAlign[I] not in [None, '']:\r
+ if MakefilePath:\r
+ Cmd += ("-oi", Input[I])\r
+ else:\r
+ Cmd += ("-i", Input[I])\r
+ if SectionAlign and SectionAlign[I]:\r
Cmd += ("-n", SectionAlign[I])\r
\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:\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) + [CommandFile]):\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
GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
\r
Cmd = ["GenFv"]\r
- if BaseAddress not in [None, '']:\r
- Cmd += ["-r", BaseAddress]\r
- \r
+ if BaseAddress:\r
+ Cmd += ("-r", BaseAddress)\r
+\r
if ForceRebase == False:\r
- Cmd +=["-F", "FALSE"]\r
+ Cmd += ("-F", "FALSE")\r
elif ForceRebase == True:\r
- Cmd +=["-F", "TRUE"]\r
- \r
+ Cmd += ("-F", "TRUE")\r
+\r
if Capsule:\r
- Cmd += ["-c"]\r
+ Cmd.append("-c")\r
if Dump:\r
- Cmd += ["-p"]\r
- if AddressFile not in [None, '']:\r
- Cmd += ["-a", AddressFile]\r
- if MapFile not in [None, '']:\r
- Cmd += ["-m", MapFile]\r
+ Cmd.append("-p")\r
+ if AddressFile:\r
+ Cmd += ("-a", AddressFile)\r
+ if MapFile:\r
+ Cmd += ("-m", MapFile)\r
if FileSystemGuid:\r
- Cmd += ["-g", FileSystemGuid]\r
- Cmd += ["-o", Output]\r
+ Cmd += ("-g", FileSystemGuid)\r
+ Cmd += ("-o", Output)\r
for I in Input:\r
- Cmd += ["-i", I]\r
+ Cmd += ("-i", I)\r
\r
GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FV")\r
\r
- @staticmethod\r
- def GenerateVtf(Output, Input, BaseAddress=None, FvSize=None):\r
- if not GenFdsGlobalVariable.NeedsUpdate(Output, Input):\r
- return\r
- GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))\r
-\r
- Cmd = ["GenVtf"]\r
- if BaseAddress not in [None, ''] and FvSize not in [None, ''] \\r
- and len(BaseAddress) == len(FvSize):\r
- for I in range(0, len(BaseAddress)):\r
- Cmd += ["-r", BaseAddress[I], "-s", FvSize[I]]\r
- Cmd += ["-o", Output]\r
- for F in Input:\r
- Cmd += ["-f", F]\r
-\r
- GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate VTF")\r
-\r
@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
Cmd = ["GenFw"]\r
if Type.lower() == "te":\r
- Cmd += ["-t"]\r
- if SubType not in [None, '']:\r
- Cmd += ["-e", SubType]\r
- if TimeStamp not in [None, '']:\r
- Cmd += ["-s", TimeStamp]\r
- if Align not in [None, '']:\r
- Cmd += ["-a", Align]\r
- if Padding not in [None, '']:\r
- Cmd += ["-p", Padding]\r
+ Cmd.append("-t")\r
+ if SubType:\r
+ Cmd += ("-e", SubType)\r
+ if TimeStamp:\r
+ Cmd += ("-s", TimeStamp)\r
+ if Align:\r
+ Cmd += ("-a", Align)\r
+ if Padding:\r
+ Cmd += ("-p", Padding)\r
if Zero:\r
- Cmd += ["-z"]\r
+ Cmd.append("-z")\r
if Strip:\r
- Cmd += ["-l"]\r
+ Cmd.append("-l")\r
if Replace:\r
- Cmd += ["-r"]\r
+ Cmd.append("-r")\r
if Join:\r
- Cmd += ["-j"]\r
+ Cmd.append("-j")\r
if Convert:\r
- Cmd += ["-m"]\r
- Cmd += ["-o", Output]\r
+ Cmd.append("-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
- InputList = [] \r
+ Revision=None, DeviceId=None, VendorId=None, IsMakefile=False):\r
+ InputList = []\r
Cmd = ["EfiRom"]\r
- if len(EfiInput) > 0:\r
- \r
+ if EfiInput:\r
+\r
if Compress:\r
- Cmd += ["-ec"]\r
+ Cmd.append("-ec")\r
else:\r
- Cmd += ["-e"]\r
- \r
+ Cmd.append("-e")\r
+\r
for EfiFile in EfiInput:\r
- Cmd += [EfiFile]\r
+ Cmd.append(EfiFile)\r
InputList.append (EfiFile)\r
- \r
- if len(BinaryInput) > 0:\r
- Cmd += ["-b"]\r
+\r
+ if BinaryInput:\r
+ Cmd.append("-b")\r
for BinFile in BinaryInput:\r
- Cmd += [BinFile]\r
+ Cmd.append(BinFile)\r
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
- if ClassCode != None:\r
- Cmd += ["-l", ClassCode]\r
- if Revision != None:\r
- Cmd += ["-r", Revision]\r
- if DeviceId != None:\r
- Cmd += ["-i", DeviceId]\r
- if VendorId != None:\r
- Cmd += ["-f", VendorId]\r
-\r
- Cmd += ["-o", Output] \r
- GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate option rom")\r
+\r
+ if ClassCode:\r
+ Cmd += ("-l", ClassCode)\r
+ if Revision:\r
+ Cmd += ("-r", Revision)\r
+ if DeviceId:\r
+ Cmd += ("-i", DeviceId)\r
+ if VendorId:\r
+ Cmd += ("-f", VendorId)\r
+\r
+ Cmd += ("-o", Output)\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
Cmd = [ToolPath, ]\r
Cmd += Options.split(' ')\r
- Cmd += ["-o", Output]\r
+ Cmd += ("-o", Output)\r
Cmd += Input\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
- GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)\r
-\r
+ @staticmethod\r
def CallExternalTool (cmd, errorMess, returnValue=[]):\r
\r
if type(cmd) not in (tuple, list):\r
cmd += ('-v',)\r
GenFdsGlobalVariable.InfLogger (cmd)\r
else:\r
- sys.stdout.write ('#')\r
- sys.stdout.flush()\r
+ stdout.write ('#')\r
+ stdout.flush()\r
GenFdsGlobalVariable.SharpCounter = GenFdsGlobalVariable.SharpCounter + 1\r
if GenFdsGlobalVariable.SharpCounter % GenFdsGlobalVariable.SharpNumberPerLine == 0:\r
- sys.stdout.write('\n')\r
+ stdout.write('\n')\r
\r
try:\r
- PopenObject = subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, stderr= subprocess.PIPE, shell=True)\r
- except Exception, X:\r
+ PopenObject = Popen(' '.join(cmd), stdout=PIPE, stderr=PIPE, shell=True)\r
+ except Exception as X:\r
EdkLogger.error("GenFds", COMMAND_FAILURE, ExtraData="%s: %s" % (str(X), cmd[0]))\r
(out, error) = PopenObject.communicate()\r
\r
- while PopenObject.returncode == None :\r
+ while PopenObject.returncode is None:\r
PopenObject.wait()\r
if returnValue != [] and returnValue[0] != 0:\r
#get command return value\r
returnValue[0] = PopenObject.returncode\r
return\r
if PopenObject.returncode != 0 or GenFdsGlobalVariable.VerboseMode or GenFdsGlobalVariable.DebugLevel != -1:\r
- GenFdsGlobalVariable.InfLogger ("Return Value = %d" %PopenObject.returncode)\r
- GenFdsGlobalVariable.InfLogger (out)\r
- GenFdsGlobalVariable.InfLogger (error)\r
+ GenFdsGlobalVariable.InfLogger ("Return Value = %d" % PopenObject.returncode)\r
+ GenFdsGlobalVariable.InfLogger(out.decode(encoding='utf-8', errors='ignore'))\r
+ GenFdsGlobalVariable.InfLogger(error.decode(encoding='utf-8', errors='ignore'))\r
if PopenObject.returncode != 0:\r
- print "###", cmd\r
+ print("###", cmd)\r
EdkLogger.error("GenFds", COMMAND_FAILURE, errorMess)\r
\r
+ @staticmethod\r
def VerboseLogger (msg):\r
EdkLogger.verbose(msg)\r
\r
+ @staticmethod\r
def InfLogger (msg):\r
EdkLogger.info(msg)\r
\r
- def ErrorLogger (msg, File = None, Line = None, ExtraData = None):\r
+ @staticmethod\r
+ def ErrorLogger (msg, File=None, Line=None, ExtraData=None):\r
EdkLogger.error('GenFds', GENFDS_ERROR, msg, File, Line, ExtraData)\r
\r
+ @staticmethod\r
def DebugLogger (Level, msg):\r
EdkLogger.debug(Level, msg)\r
\r
- ## ReplaceWorkspaceMacro()\r
+ ## MacroExtend()\r
#\r
# @param Str String that may contain macro\r
# @param MacroDict Dictionary that contains macro value pair\r
#\r
- def MacroExtend (Str, MacroDict = {}, Arch = 'COMMON'):\r
- if Str == None :\r
+ @staticmethod\r
+ def MacroExtend (Str, MacroDict=None, Arch=DataType.TAB_COMMON):\r
+ if Str is None:\r
return None\r
\r
- Dict = {'$(WORKSPACE)' : GenFdsGlobalVariable.WorkSpaceDir,\r
- '$(EDK_SOURCE)' : GenFdsGlobalVariable.EdkSourceDir,\r
+ Dict = {'$(WORKSPACE)': GenFdsGlobalVariable.WorkSpaceDir,\r
# '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,\r
- '$(TARGET)' : GenFdsGlobalVariable.TargetName,\r
- '$(TOOL_CHAIN_TAG)' : GenFdsGlobalVariable.ToolChainTag,\r
- '$(SPACE)' : ' '\r
+ '$(TARGET)': GenFdsGlobalVariable.TargetName,\r
+ '$(TOOL_CHAIN_TAG)': GenFdsGlobalVariable.ToolChainTag,\r
+ '$(SPACE)': ' '\r
}\r
- OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[GenFdsGlobalVariable.ArchList[0]]\r
- if Arch != 'COMMON' and Arch in GenFdsGlobalVariable.ArchList:\r
+\r
+ if Arch != DataType.TAB_COMMON and Arch in GenFdsGlobalVariable.ArchList:\r
OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[Arch]\r
+ else:\r
+ OutputDir = GenFdsGlobalVariable.OutputDirFromDscDict[GenFdsGlobalVariable.ArchList[0]]\r
\r
Dict['$(OUTPUT_DIRECTORY)'] = OutputDir\r
\r
- if MacroDict != None and len (MacroDict) != 0:\r
+ if MacroDict:\r
Dict.update(MacroDict)\r
\r
- for key in Dict.keys():\r
- if Str.find(key) >= 0 :\r
+ for key in Dict:\r
+ if Str.find(key) >= 0:\r
Str = Str.replace (key, Dict[key])\r
\r
if Str.find('$(ARCH)') >= 0:\r
#\r
# @param PcdPattern pattern that labels a PCD.\r
#\r
+ @staticmethod\r
def GetPcdValue (PcdPattern):\r
- if PcdPattern == None :\r
+ if PcdPattern is None:\r
return None\r
- PcdPair = PcdPattern.lstrip('PCD(').rstrip(')').strip().split('.')\r
+ if PcdPattern.startswith('PCD('):\r
+ PcdPair = PcdPattern[4:].rstrip(')').strip().split('.')\r
+ else:\r
+ PcdPair = PcdPattern.strip().split('.')\r
TokenSpace = PcdPair[0]\r
TokenCName = PcdPair[1]\r
\r
- PcdValue = ''\r
for Arch in GenFdsGlobalVariable.ArchList:\r
Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
PcdDict = Platform.Pcds\r
for Key in PcdDict:\r
PcdObj = PcdDict[Key]\r
if (PcdObj.TokenCName == TokenCName) and (PcdObj.TokenSpaceGuidCName == TokenSpace):\r
- if PcdObj.Type != 'FixedAtBuild':\r
+ if PcdObj.Type != DataType.TAB_PCDS_FIXED_AT_BUILD:\r
EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not FixedAtBuild type." % PcdPattern)\r
- if PcdObj.DatumType != 'VOID*':\r
+ if PcdObj.DatumType != DataType.TAB_VOID:\r
EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not VOID* datum type." % PcdPattern)\r
- \r
- PcdValue = PcdObj.DefaultValue\r
- return PcdValue\r
- \r
- for Package in GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform, \r
- Arch, \r
- GenFdsGlobalVariable.TargetName, \r
+\r
+ return PcdObj.DefaultValue\r
+\r
+ for Package in GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform,\r
+ Arch,\r
+ GenFdsGlobalVariable.TargetName,\r
GenFdsGlobalVariable.ToolChainTag):\r
PcdDict = Package.Pcds\r
for Key in PcdDict:\r
PcdObj = PcdDict[Key]\r
if (PcdObj.TokenCName == TokenCName) and (PcdObj.TokenSpaceGuidCName == TokenSpace):\r
- if PcdObj.Type != 'FixedAtBuild':\r
+ if PcdObj.Type != DataType.TAB_PCDS_FIXED_AT_BUILD:\r
EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not FixedAtBuild type." % PcdPattern)\r
- if PcdObj.DatumType != 'VOID*':\r
+ if PcdObj.DatumType != DataType.TAB_VOID:\r
EdkLogger.error("GenFds", GENFDS_ERROR, "%s is not VOID* datum type." % PcdPattern)\r
- \r
- PcdValue = PcdObj.DefaultValue\r
- return PcdValue\r
-\r
- return PcdValue\r
-\r
- SetDir = staticmethod(SetDir)\r
- ReplaceWorkspaceMacro = staticmethod(ReplaceWorkspaceMacro)\r
- CallExternalTool = staticmethod(CallExternalTool)\r
- VerboseLogger = staticmethod(VerboseLogger)\r
- InfLogger = staticmethod(InfLogger)\r
- ErrorLogger = staticmethod(ErrorLogger)\r
- DebugLogger = staticmethod(DebugLogger)\r
- MacroExtend = staticmethod (MacroExtend)\r
- GetPcdValue = staticmethod(GetPcdValue)\r
+\r
+ return PcdObj.DefaultValue\r
+\r
+ return ''\r
+\r
+## FindExtendTool()\r
+#\r
+# Find location of tools to process data\r
+#\r
+# @param KeyStringList Filter for inputs of section generation\r
+# @param CurrentArchList Arch list\r
+# @param NameGuid The Guid name\r
+#\r
+def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):\r
+ ToolDefObj = ToolDefDict((os.path.join(os.getenv("WORKSPACE"), "Conf")))\r
+ ToolDef = ToolDefObj.ToolDef\r
+ ToolDb = ToolDef.ToolsDefTxtDatabase\r
+ # if user not specify filter, try to deduce it from global data.\r
+ if KeyStringList is None or KeyStringList == []:\r
+ Target = GenFdsGlobalVariable.TargetName\r
+ ToolChain = GenFdsGlobalVariable.ToolChainTag\r
+ if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:\r
+ EdkLogger.error("GenFds", GENFDS_ERROR, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain)\r
+ KeyStringList = [Target + '_' + ToolChain + '_' + CurrentArchList[0]]\r
+ for Arch in CurrentArchList:\r
+ if Target + '_' + ToolChain + '_' + Arch not in KeyStringList:\r
+ KeyStringList.append(Target + '_' + ToolChain + '_' + Arch)\r
+\r
+ if GenFdsGlobalVariable.GuidToolDefinition:\r
+ if NameGuid in GenFdsGlobalVariable.GuidToolDefinition:\r
+ return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]\r
+\r
+ ToolDefinition = ToolDef.ToolsDefTxtDictionary\r
+ ToolPathTmp = None\r
+ ToolOption = None\r
+ ToolPathKey = None\r
+ ToolOptionKey = None\r
+ KeyList = None\r
+ for tool_def in ToolDefinition.items():\r
+ if NameGuid.lower() == tool_def[1].lower():\r
+ KeyList = tool_def[0].split('_')\r
+ Key = KeyList[0] + \\r
+ '_' + \\r
+ KeyList[1] + \\r
+ '_' + \\r
+ KeyList[2]\r
+ if Key in KeyStringList and KeyList[4] == DataType.TAB_GUID:\r
+ ToolPathKey = Key + '_' + KeyList[3] + '_PATH'\r
+ ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
+ ToolPath = ToolDefinition.get(ToolPathKey)\r
+ ToolOption = ToolDefinition.get(ToolOptionKey)\r
+ if ToolPathTmp is None:\r
+ ToolPathTmp = ToolPath\r
+ else:\r
+ if ToolPathTmp != ToolPath:\r
+ EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))\r
+\r
+ BuildOption = {}\r
+ for Arch in CurrentArchList:\r
+ Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+ # key is (ToolChainFamily, ToolChain, CodeBase)\r
+ for item in Platform.BuildOptions:\r
+ if '_PATH' in item[1] or '_FLAGS' in item[1] or '_GUID' in item[1]:\r
+ if not item[0] or (item[0] and GenFdsGlobalVariable.ToolChainFamily== item[0]):\r
+ if item[1] not in BuildOption:\r
+ BuildOption[item[1]] = Platform.BuildOptions[item]\r
+ if BuildOption:\r
+ ToolList = [DataType.TAB_TOD_DEFINES_TARGET, DataType.TAB_TOD_DEFINES_TOOL_CHAIN_TAG, DataType.TAB_TOD_DEFINES_TARGET_ARCH]\r
+ for Index in range(2, -1, -1):\r
+ for Key in list(BuildOption.keys()):\r
+ List = Key.split('_')\r
+ if List[Index] == DataType.TAB_STAR:\r
+ for String in ToolDb[ToolList[Index]]:\r
+ if String in [Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]:\r
+ List[Index] = String\r
+ NewKey = '%s_%s_%s_%s_%s' % tuple(List)\r
+ if NewKey not in BuildOption:\r
+ BuildOption[NewKey] = BuildOption[Key]\r
+ continue\r
+ del BuildOption[Key]\r
+ elif List[Index] not in ToolDb[ToolList[Index]]:\r
+ del BuildOption[Key]\r
+ if BuildOption:\r
+ if not KeyList:\r
+ for Op in BuildOption:\r
+ if NameGuid == BuildOption[Op]:\r
+ KeyList = Op.split('_')\r
+ Key = KeyList[0] + '_' + KeyList[1] +'_' + KeyList[2]\r
+ if Key in KeyStringList and KeyList[4] == DataType.TAB_GUID:\r
+ ToolPathKey = Key + '_' + KeyList[3] + '_PATH'\r
+ ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
+ if ToolPathKey in BuildOption:\r
+ ToolPathTmp = BuildOption[ToolPathKey]\r
+ if ToolOptionKey in BuildOption:\r
+ ToolOption = BuildOption[ToolOptionKey]\r
+\r
+ GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)\r
+ return ToolPathTmp, ToolOption\r