summaryrefslogtreecommitdiff
path: root/BaseTools/Source/Python/msa2inf
diff options
context:
space:
mode:
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2009-07-17 09:10:31 +0000
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2009-07-17 09:10:31 +0000
commit30fdf1140b8d1ce93f3821d986fa165552023440 (patch)
treec45c336a8955b1d03ea56d6c915a0e68a43b4ee9 /BaseTools/Source/Python/msa2inf
parent577e30cdb473e4af8e65fd6f75236691d0c8dfb3 (diff)
downloadedk2-platforms-30fdf1140b8d1ce93f3821d986fa165552023440.tar.xz
Check In tool source code based on Build tool project revision r1655.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8964 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Source/Python/msa2inf')
-rw-r--r--BaseTools/Source/Python/msa2inf/ConvertModule.py112
-rw-r--r--BaseTools/Source/Python/msa2inf/EdkIIWorkspaceGuidsInfo.py325
-rw-r--r--BaseTools/Source/Python/msa2inf/LoadMsa.py747
-rw-r--r--BaseTools/Source/Python/msa2inf/Msa2Inf.py44
-rw-r--r--BaseTools/Source/Python/msa2inf/StoreInf.py442
-rw-r--r--BaseTools/Source/Python/msa2inf/__init__.py0
6 files changed, 1670 insertions, 0 deletions
diff --git a/BaseTools/Source/Python/msa2inf/ConvertModule.py b/BaseTools/Source/Python/msa2inf/ConvertModule.py
new file mode 100644
index 0000000000..e0d7b88695
--- /dev/null
+++ b/BaseTools/Source/Python/msa2inf/ConvertModule.py
@@ -0,0 +1,112 @@
+## @file
+# Convert an MSA Module class object ot an INF Module class object by filling
+# several info required by INF file.
+#
+# Copyright (c) 2007, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+from LoadMsa import LoadMsa
+from StoreInf import StoreInf
+from Common.MigrationUtilities import *
+from EdkIIWorkspaceGuidsInfo import gEdkIIWorkspaceGuidsInfo
+
+#The default INF version number tool generates.
+gInfVersion = "0x00010005"
+
+## Add required version information.
+#
+# Add the default INF version, EFI specificiation version and EDK release
+# version to Module class object.
+#
+# @param Module An input Module class object.
+#
+def AddModuleMiscVersion(Module):
+ Version = gInfVersion
+ Module.Header.InfVersion = Version
+
+ Version = Module.Header.Specification.get("EFI_SPECIFICATION_VERSION", "")
+ Module.Header.EfiSpecificationVersion = Version
+
+ Version = Module.Header.Specification.get("EDK_RELEASE_VERSION", "")
+ Module.Header.EdkReleaseVersion = Version
+
+
+## Add Module produced library class.
+#
+# Add the produced library class from library class list whose usage type is
+# always produced.
+#
+# @param Module An input Module class object.
+#
+def AddModuleProducedLibraryClass(Module):
+ for LibraryClass in Module.LibraryClasses:
+ if "ALWAYS_PRODUCED" in LibraryClass.Usage:
+ Module.Header.LibraryClass.append(LibraryClass)
+
+
+## Add Module Package Dependency path.
+#
+# Translate Package Dependency Guid to a file path relative to workspace.
+#
+# @param Module An input Module class object.
+#
+def AddModulePackageDependencyPath(Module):
+ for PackageDependency in Module.PackageDependencies:
+ PackageGuid = PackageDependency.PackageGuid
+ PackageVersion = PackageDependency.PackageVersion
+
+ GuidToFilePath = gEdkIIWorkspaceGuidsInfo.ResolvePackageFilePath
+ PackageFilePath = GuidToFilePath(PackageGuid, PackageVersion)
+ PackageDependency.FilePath = PackageFilePath
+
+
+## Add Module Recommended Library Instance path.
+#
+# Translate Module Recommened Library Instance Guid to a file path relative to
+# workspace.
+#
+# @param Module An input Module class object.
+#
+def AddModuleRecommonedLibraryInstancePath(Module):
+ for LibraryClass in Module.LibraryClasses:
+ if "ALWAYS_PRODUCED" in LibraryClass.Usage:
+ continue
+
+ if LibraryClass.RecommendedInstanceGuid == "":
+ continue
+
+ LibraryGuid = LibraryClass.RecommendedInstanceGuid
+ LibraryVersion = LibraryClass.RecommendedIntanceVersion
+
+ GuidToFilePath = gEdkIIWorkspaceGuidsInfo.ResolveModuleFilePath
+ LibraryInstance = GuidToFilePath(LibraryGuid, LibraryVersion)
+ LibraryClass.RecommendedIntance = LibraryInstance
+
+
+## Convert MSA Module class object to INF Module class object.
+#
+# Convert MSA module class ojbect to INF Module class object by filling in
+# several information required by INF file.
+#
+# @param Module An input Module class object.
+#
+def ConvertMsaModuleToInfModule(Module):
+ AddModuleMiscVersion(Module)
+ AddModuleProducedLibraryClass(Module)
+ AddModulePackageDependencyPath(Module)
+ AddModuleRecommonedLibraryInstancePath(Module)
+
+
+if __name__ == '__main__':
+ pass
+ \ No newline at end of file
diff --git a/BaseTools/Source/Python/msa2inf/EdkIIWorkspaceGuidsInfo.py b/BaseTools/Source/Python/msa2inf/EdkIIWorkspaceGuidsInfo.py
new file mode 100644
index 0000000000..f1c8d60d75
--- /dev/null
+++ b/BaseTools/Source/Python/msa2inf/EdkIIWorkspaceGuidsInfo.py
@@ -0,0 +1,325 @@
+## @file
+# Collects the Guid Information in current workspace.
+#
+# Copyright (c) 2007, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+import os
+import fnmatch
+from Common.EdkIIWorkspace import EdkIIWorkspace
+from Common.MigrationUtilities import *
+
+## A class for EdkII work space to resolve Guids.
+#
+# This class inherits from EdkIIWorkspace and collects the Guids information
+# in current workspace. The Guids information is important to translate the
+# package Guids and recommended library instances Guids to relative file path
+# (to workspace directory) in MSA files.
+#
+class EdkIIWorkspaceGuidsInfo(EdkIIWorkspace):
+
+ ## The classconstructor.
+ #
+ # The constructor initialize workspace directory. It does not collect
+ # pakage and module Guids info at initialization; instead, it collects them
+ # on the fly.
+ #
+ # @param self The object pointer.
+ #
+ def __init__(self):
+ # Initialize parent class.
+ EdkIIWorkspace.__init__(self)
+ # The internal map from Guid to FilePath.
+ self.__GuidToFilePath = {}
+ # The internal package directory list.
+ self.__PackageDirList = []
+ # The internal flag to indicate whether package Guids info has been
+ # to avoid re-collection collected.
+ self.__PackageGuidInitialized = False
+ # The internal flag to indicate whether module Guids info has been
+ # to avoid re-collection collected.
+ self.__ModuleGuidInitialized = False
+
+ ## Add Guid, Version and FilePath to Guids database.
+ #
+ # Add Guid, Version and FilePath to Guids database. It constructs a map
+ # table from Guid, Version to FilePath internally. If also detects possible
+ # Guid collision. For now, the version information is simply ignored and
+ # Guid value itself acts as master key.
+ #
+ # @param self The object pointer.
+ # @param Guid The Guid Value.
+ # @param Version The version information
+ #
+ # @retval True The Guid value is successfully added to map table.
+ # @retval False The Guid is an empty string or the map table
+ # already contains a same Guid.
+ #
+ def __AddGuidToFilePath(self, Guid, Version, FilePath):
+ if Guid == "":
+ EdkLogger.info("Cannot find Guid in file %s" % FilePath)
+ return False
+ #Add the Guid value to map table to ensure case insensitive comparison.
+ OldFilePath = self.__GuidToFilePath.setdefault(Guid.lower(), FilePath)
+ if OldFilePath == FilePath:
+ EdkLogger.verbose("File %s has new Guid '%s'" % (FilePath, Guid))
+ return True
+ else:
+ EdkLogger.info("File %s has duplicate Guid with & %s" % (FilePath, OldFilePath))
+ return False
+
+
+ ## Gets file information from a module description file.
+ #
+ # Extracts Module Name, File Guid and Version number from INF, MSA and NMSA
+ # file. It supports to exact such information from text based INF file or
+ # XML based (N)MSA file.
+ #
+ # @param self The object pointer.
+ # @param FileName The input module file name.
+ #
+ # @retval True This module file represents a new module discovered
+ # in current workspace.
+ # @retval False This module file is not regarded as a valid module.
+ # The File Guid cannot be extracted or the another
+ # file with the same Guid already exists
+ #
+ def __GetModuleFileInfo(self, FileName):
+ if fnmatch.fnmatch(FileName, "*.inf"):
+ TagTuple = ("BASE_NAME", "FILE_GUID", "VERSION_STRING")
+ (Name, Guid, Version) = GetTextFileInfo(FileName, TagTuple)
+ else :
+ XmlTag1 = "ModuleSurfaceArea/MsaHeader/ModuleName"
+ XmlTag2 = "ModuleSurfaceArea/MsaHeader/GuidValue"
+ XmlTag3 = "ModuleSurfaceArea/MsaHeader/Version"
+ TagTuple = (XmlTag1, XmlTag2, XmlTag3)
+ (Name, Guid, Version) = GetXmlFileInfo(FileName, TagTuple)
+
+ return self.__AddGuidToFilePath(Guid, Version, FileName)
+
+
+ ## Gets file information from a package description file.
+ #
+ # Extracts Package Name, File Guid and Version number from INF, SPD and NSPD
+ # file. It supports to exact such information from text based DEC file or
+ # XML based (N)SPD file. EDK Compatibility Package is hardcoded to be
+ # ignored since no EDKII INF file depends on that package.
+ #
+ # @param self The object pointer.
+ # @param FileName The input package file name.
+ #
+ # @retval True This package file represents a new package
+ # discovered in current workspace.
+ # @retval False This package is not regarded as a valid package.
+ # The File Guid cannot be extracted or the another
+ # file with the same Guid already exists
+ #
+ def __GetPackageFileInfo(self, FileName):
+ if fnmatch.fnmatch(FileName, "*.dec"):
+ TagTuple = ("PACKAGE_NAME", "PACKAGE_GUID", "PACKAGE_VERSION")
+ (Name, Guid, Version) = GetTextFileInfo(FileName, TagTuple)
+ else:
+ XmlTag1 = "PackageSurfaceArea/SpdHeader/PackageName"
+ XmlTag2 = "PackageSurfaceArea/SpdHeader/GuidValue"
+ XmlTag3 = "PackageSurfaceArea/SpdHeader/Version"
+ TagTuple = (XmlTag1, XmlTag2, XmlTag3)
+ (Name, Guid, Version) = GetXmlFileInfo(FileName, TagTuple)
+
+ if Name == "EdkCompatibilityPkg":
+ # Do not scan EDK compatibitilty package to avoid Guid collision
+ # with those in EDK Glue Library.
+ EdkLogger.verbose("Bypass EDK Compatibility Pkg")
+ return False
+
+ return self.__AddGuidToFilePath(Guid, Version, FileName)
+
+ ## Iterate on all package files listed in framework database file.
+ #
+ # Yields all package description files listed in framework database files.
+ # The framework database file describes the packages current workspace
+ # includes.
+ #
+ # @param self The object pointer.
+ #
+ def __FrameworkDatabasePackageFiles(self):
+ XmlFrameworkDb = XmlParseFile(self.WorkspaceFile)
+ XmlTag = "FrameworkDatabase/PackageList/Filename"
+ for PackageFile in XmlElementList(XmlFrameworkDb, XmlTag):
+ yield os.path.join(self.WorkspaceDir, PackageFile)
+
+
+ ## Iterate on all package files in current workspace directory.
+ #
+ # Yields all package description files listed in current workspace
+ # directory. This happens when no framework database file exists.
+ #
+ # @param self The object pointer.
+ #
+ def __TraverseAllPackageFiles(self):
+ for Path, Dirs, Files in os.walk(self.WorkspaceDir):
+ # Ignore svn version control directory.
+ if ".svn" in Dirs:
+ Dirs.remove(".svn")
+ if "Build" in Dirs:
+ Dirs.remove("Build")
+ # Assume priority from high to low: DEC, NSPD, SPD.
+ PackageFiles = fnmatch.filter(Files, "*.dec")
+ if len(PackageFiles) == 0:
+ PackageFiles = fnmatch.filter(Files, "*.nspd")
+ if len(PackageFiles) == 0:
+ PackageFiles = fnmatch.filter(Files, "*.spd")
+
+ for File in PackageFiles:
+ # Assume no more package decription file in sub-directory.
+ del Dirs[:]
+ yield os.path.join(Path, File)
+
+ ## Iterate on all module files in current package directory.
+ #
+ # Yields all module description files listed in current package
+ # directory.
+ #
+ # @param self The object pointer.
+ #
+ def __TraverseAllModuleFiles(self):
+ for PackageDir in self.__PackageDirList:
+ for Path, Dirs, Files in os.walk(PackageDir):
+ # Ignore svn version control directory.
+ if ".svn" in Dirs:
+ Dirs.remove(".svn")
+ # Assume priority from high to low: INF, NMSA, MSA.
+ ModuleFiles = fnmatch.filter(Files, "*.inf")
+ if len(ModuleFiles) == 0:
+ ModuleFiles = fnmatch.filter(Files, "*.nmsa")
+ if len(ModuleFiles) == 0:
+ ModuleFiles = fnmatch.filter(Files, "*.msa")
+
+ for File in ModuleFiles:
+ yield os.path.join(Path, File)
+
+ ## Initialize package Guids info mapping table.
+ #
+ # Collects all package guids map to package decription file path. This
+ # function is invokes on demand to avoid unnecessary directory scan.
+ #
+ # @param self The object pointer.
+ #
+ def __InitializePackageGuidInfo(self):
+ if self.__PackageGuidInitialized:
+ return
+
+ EdkLogger.verbose("Start to collect Package Guids Info.")
+
+ WorkspaceFile = os.path.join("Conf", "FrameworkDatabase.db")
+ self.WorkspaceFile = os.path.join(self.WorkspaceDir, WorkspaceFile)
+
+ # Try to find the frameworkdatabase file to discover package lists
+ if os.path.exists(self.WorkspaceFile):
+ TraversePackage = self.__FrameworkDatabasePackageFiles
+ EdkLogger.verbose("Package list bases on: %s" % self.WorkspaceFile)
+ else:
+ TraversePackage = self.__TraverseAllPackageFiles
+ EdkLogger.verbose("Package list in: %s" % self.WorkspaceDir)
+
+ for FileName in TraversePackage():
+ if self.__GetPackageFileInfo(FileName):
+ PackageDir = os.path.dirname(FileName)
+ EdkLogger.verbose("Find new package directory %s" % PackageDir)
+ self.__PackageDirList.append(PackageDir)
+
+ self.__PackageGuidInitialized = True
+
+ ## Initialize module Guids info mapping table.
+ #
+ # Collects all module guids map to module decription file path. This
+ # function is invokes on demand to avoid unnecessary directory scan.
+ #
+ # @param self The object pointer.
+ #
+ def __InitializeModuleGuidInfo(self):
+ if self.__ModuleGuidInitialized:
+ return
+ EdkLogger.verbose("Start to collect Module Guids Info")
+
+ self.__InitializePackageGuidInfo()
+ for FileName in self.__TraverseAllModuleFiles():
+ if self.__GetModuleFileInfo(FileName):
+ EdkLogger.verbose("Find new module %s" % FileName)
+
+ self.__ModuleGuidInitialized = True
+
+ ## Get Package file path by Package guid and Version.
+ #
+ # Translates the Package Guid and Version to a file path relative
+ # to workspace directory. If no package in current workspace match the
+ # input Guid, an empty file path is returned. For now, the version
+ # value is simply ignored.
+ #
+ # @param self The object pointer.
+ # @param Guid The Package Guid value to look for.
+ # @param Version The Package Version value to look for.
+ #
+ def ResolvePackageFilePath(self, Guid, Version = ""):
+ self.__InitializePackageGuidInfo()
+
+ EdkLogger.verbose("Resolve Package Guid '%s'" % Guid)
+ FileName = self.__GuidToFilePath.get(Guid.lower(), "")
+ if FileName == "":
+ EdkLogger.info("Cannot resolve Package Guid '%s'" % Guid)
+ else:
+ FileName = self.WorkspaceRelativePath(FileName)
+ FileName = os.path.splitext(FileName)[0] + ".dec"
+ FileName = FileName.replace("\\", "/")
+ return FileName
+
+ ## Get Module file path by Package guid and Version.
+ #
+ # Translates the Module Guid and Version to a file path relative
+ # to workspace directory. If no module in current workspace match the
+ # input Guid, an empty file path is returned. For now, the version
+ # value is simply ignored.
+ #
+ # @param self The object pointer.
+ # @param Guid The Module Guid value to look for.
+ # @param Version The Module Version value to look for.
+ #
+ def ResolveModuleFilePath(self, Guid, Version = ""):
+ self.__InitializeModuleGuidInfo()
+
+ EdkLogger.verbose("Resolve Module Guid '%s'" % Guid)
+ FileName = self.__GuidToFilePath.get(Guid.lower(), "")
+ if FileName == "":
+ EdkLogger.info("Cannot resolve Module Guid '%s'" % Guid)
+ else:
+ FileName = self.WorkspaceRelativePath(FileName)
+ FileName = os.path.splitext(FileName)[0] + ".inf"
+ FileName = FileName.replace("\\", "/")
+ return FileName
+
+# A global class object of EdkIIWorkspaceGuidsInfo for external reference.
+gEdkIIWorkspaceGuidsInfo = EdkIIWorkspaceGuidsInfo()
+
+# This acts like the main() function for the script, unless it is 'import'ed
+# into another script.
+if __name__ == '__main__':
+ # Test the translation of package Guid.
+ MdePkgGuid = "1E73767F-8F52-4603-AEB4-F29B510B6766"
+ OldMdePkgGuid = "5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"
+ print gEdkIIWorkspaceGuidsInfo.ResolveModuleFilePath(MdePkgGuid)
+ print gEdkIIWorkspaceGuidsInfo.ResolveModuleFilePath(OldMdePkgGuid)
+
+ # Test the translation of module Guid.
+ UefiLibGuid = "3a004ba5-efe0-4a61-9f1a-267a46ae5ba9"
+ UefiDriverModelLibGuid = "52af22ae-9901-4484-8cdc-622dd5838b09"
+ print gEdkIIWorkspaceGuidsInfo.ResolveModuleFilePath(UefiLibGuid)
+ print gEdkIIWorkspaceGuidsInfo.ResolveModuleFilePath(UefiDriverModelLibGuid)
diff --git a/BaseTools/Source/Python/msa2inf/LoadMsa.py b/BaseTools/Source/Python/msa2inf/LoadMsa.py
new file mode 100644
index 0000000000..4995f2cd0c
--- /dev/null
+++ b/BaseTools/Source/Python/msa2inf/LoadMsa.py
@@ -0,0 +1,747 @@
+## @file
+# Open an MSA file and load all its contents to a ModuleClass object.
+#
+# Copyright (c) 2007, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+import os
+from CommonDataClass.ModuleClass import *
+from Common.XmlRoutines import *
+from Common.MigrationUtilities import *
+
+
+## Load a list of Module Cloned Records.
+#
+# Read an input Module XML DOM object and return a list of Cloned Records
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel ClonedRecords A list of Cloned Records loaded from XmlMsa.
+#
+def LoadModuleClonedRecords(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/ModuleDefinitions/ClonedFrom/Cloned"
+ return map(LoadClonedRecord, XmlList(XmlMsa, XmlTag))
+
+## Load Module Header.
+#
+# Read an input Module XML DOM object and return Module Header class object
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+# @param MsaFileName The file path of MSA File.
+#
+# @retvel ModuleHeader A new Module Header object loaded from XmlMsa.
+#
+def LoadModuleHeader(XmlMsa, MsaFileName):
+ ModuleHeader = ModuleHeaderClass()
+
+ XmlTag = "ModuleSurfaceArea/MsaHeader"
+ MsaHeader = XmlNode(XmlMsa, XmlTag)
+
+ SetIdentification(ModuleHeader, MsaHeader, "ModuleName", MsaFileName)
+ SetCommonHeader(ModuleHeader, MsaHeader)
+
+ XmlTag = "ModuleSurfaceArea/ModuleDefinitions/SupportedArchitectures"
+ ModuleHeader.SupArchList = XmlElement(XmlMsa, XmlTag).split()
+
+ XmlTag = "ModuleSurfaceArea/ModuleDefinitions/BinaryModule"
+ if XmlElement(XmlMsa, XmlTag).lower() == "true":
+ ModuleHeader.BinaryModule = True
+
+ XmlTag = "ModuleSurfaceArea/ModuleDefinitions/OutputFileBasename"
+ ModuleHeader.OutputFileBasename = XmlElement(XmlMsa, XmlTag)
+
+ XmlTag = "ModuleSurfaceArea/ModuleDefinitions/ClonedForm"
+ ModuleHeader.ClonedFrom = LoadModuleClonedRecords(XmlMsa)
+
+ XmlTag = "ModuleSurfaceArea/Externs/PcdDriverTypes"
+ ModuleHeader.PcdIsDriver = XmlElement(XmlMsa, XmlTag)
+
+ XmlTag = "ModuleSurfaceArea/Externs/TianoR8FlashMap_h"
+ if XmlElement(XmlMsa, XmlTag).lower() == "true":
+ ModuleHeader.TianoR8FlashMap_h = True
+
+ XmlTag = "ModuleSurfaceArea/Externs/Specification"
+ for Specification in XmlElementList(XmlMsa, XmlTag):
+ AddToSpecificationDict(ModuleHeader.Specification, Specification)
+
+ return ModuleHeader
+
+
+## Load a list of Module Library Classes.
+#
+# Read an input Module XML DOM object and return a list of Library Classes
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel LibraryClasses A list of Library Classes loaded from XmlMsa.
+#
+def LoadModuleLibraryClasses(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/LibraryClassDefinitions/LibraryClass"
+ return map(LoadLibraryClass, XmlList(XmlMsa, XmlTag))
+
+
+## Load a new Module Source class object.
+#
+# Read an input XML Source DOM object and return an object of Source
+# contained in the DOM object.
+#
+# @param XmlFilename A child XML DOM object in Module XML DOM.
+#
+# @retvel ModuleSource A new Source object created by XmlFilename.
+#
+def LoadModuleSource(XmlFilename):
+ ModuleSource = ModuleSourceFileClass()
+
+ ModuleSource.SourceFile = XmlElementData(XmlFilename)
+
+ XmlTag = "TagName"
+ ModuleSource.TagName = XmlAttribute(XmlFilename, XmlTag)
+
+ XmlTag = "ToolCode"
+ ModuleSource.ToolCode = XmlAttribute(XmlFilename, XmlTag)
+
+ XmlTag = "ToolChainFamily"
+ ModuleSource.ToolChainFamily = XmlAttribute(XmlFilename, XmlTag)
+
+ SetCommon(ModuleSource, XmlFilename)
+
+ return ModuleSource
+
+
+## Load a list of Module Sources.
+#
+# Read an input Module XML DOM object and return a list of Sources
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel Sources A list of Sources loaded from XmlMsa.
+#
+def LoadModuleSources(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/SourceFiles/Filename"
+ return map(LoadModuleSource, XmlList(XmlMsa, XmlTag))
+
+
+## Load a new Module Binary class object.
+#
+# Read an input XML Binary DOM object and return an object of Binary
+# contained in the DOM object.
+#
+# @param XmlFilename A child XML DOM object in Module XML DOM.
+#
+# @retvel ModuleBinary A new Binary object created by XmlFilename.
+#
+def LoadModuleBinary(XmlFilename):
+ ModuleBinary = ModuleBinaryFileClass()
+
+ ModuleBinary.BinaryFile = XmlElementData(XmlFilename)
+
+ XmlTag = "FileType"
+ ModuleBinary.FileType = XmlElementAttribute(XmlFilename, XmlTag)
+
+ SetCommon(ModuleBinary, XmlFilename)
+
+
+## Load a list of Module Binaries.
+#
+# Read an input Module XML DOM object and return a list of Binaries
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel Binaries A list of Binaries loaded from XmlMsa.
+#
+def LoadModuleBinaries(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/BinaryFiles/Filename"
+ return map(LoadModuleBinary, XmlList(XmlMsa, XmlTag))
+
+
+## Load a list of Module Non Processed Files.
+#
+# Read an input Module XML DOM object and return a list of Non Processed Files
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel NonProcessedFiles A list of Non Processed Files loaded from XmlMsa.
+#
+def LoadModuleNonProcessedFiles(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/NonProcessedFiles/Filename"
+ return XmlElementList(XmlMsa, XmlTag)
+
+
+## Load a new Module Package Dependency class object.
+#
+# Read an input XML PackageDependency DOM object and return an object of Package Dependency
+# contained in the DOM object.
+#
+# @param XmlPackage A child XML DOM object in Module XML DOM.
+#
+# @retvel ModulePackageDependency A new Package Dependency object created by XmlPackage.
+#
+def LoadModulePackageDependency(XmlPackage):
+ ModulePackageDependency = ModulePackageDependencyClass()
+
+ XmlTag = "PackageGuid"
+ PackageKey = XmlAttribute(XmlPackage, XmlTag)
+
+ #
+ #TODO: Add resolution for Package name, package Version
+ #
+ ModulePackageDependency.PackageGuid = PackageKey
+ SetCommon(ModulePackageDependency, XmlPackage)
+
+ return ModulePackageDependency
+
+
+## Load a list of Module Package Dependencies.
+#
+# Read an input Module XML DOM object and return a list of Package Dependencies
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel PackageDependencies A list of Package Dependencies loaded from XmlMsa.
+#
+def LoadModulePackageDependencies(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/PackageDependencies/Package"
+ return map(LoadModulePackageDependency, XmlList(XmlMsa, XmlTag))
+
+
+## Load a list of Module Protocols.
+#
+# Read an input Module XML DOM object and return a list of Protocols
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel Protocols A list of Protocols loaded from XmlMsa.
+#
+def LoadModuleProtocols(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/Protocols/Protocol"
+ XmlProtocolList = XmlList(XmlMsa, XmlTag)
+
+ XmlTag = "ModuleSurfaceArea/Protocols/ProtocolNotify"
+ XmlProtocolList += XmlList(XmlMsa, XmlTag)
+
+ return map(LoadGuidProtocolPpiCommon, XmlProtocolList)
+
+
+## Load a list of Module Ppis.
+#
+# Read an input Module XML DOM object and return a list of Ppis
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel Ppis A list of Ppis loaded from XmlMsa.
+#
+def LoadModulePpis(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/PPIs/Ppi"
+ XmlPpiList = XmlList(XmlMsa, XmlTag)
+
+ XmlTag = "ModuleSurfaceArea/PPIs/PpiNotify"
+ XmlPpiList += XmlList(XmlMsa, XmlTag)
+
+ return map(LoadGuidProtocolPpiCommon, XmlPpiList)
+
+
+## Load a new Module Event class object.
+#
+# Read an input XML Event DOM object and return an object of Event
+# contained in the DOM object.
+#
+# @param XmlEvent A child XML DOM object in Module XML DOM.
+# @param Type Specify the event type: SIGNAL_EVENT or CREATE_EVENT.
+#
+# @retvel ModuleEvent A new Event object created by XmlEvent.
+#
+def LoadModuleEvent(XmlEvent, Type):
+ ModuleEvent = ModuleEventClass()
+
+ XmlTag = "EventTypes/EventType"
+ ModuleEvent.CName = XmlElement(XmlEvent, XmlTag)
+
+ XmlTag = "EventGuidCName"
+ ModuleEvent.GuidCName = XmlAttribute(XmlEvent, XmlTag)
+
+ ModuleEvent.Type = Type
+
+ SetCommon(ModuleEvent, XmlEvent)
+
+ return ModuleEvent
+
+
+## Load a list of Module Events.
+#
+# Read an input Module XML DOM object and return a list of Events
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel Events A list of Events loaded from XmlMsa.
+#
+def LoadModuleEvents(XmlMsa):
+ ModuleEvents = []
+
+ XmlTag = "ModuleSurfaceArea/Events/CreateEvents/EventTypes"
+ for XmlCreateEvent in XmlList(XmlMsa, XmlTag):
+ ModuleEvent = LoadModuleEvent(XmlCreateEvent, "CREATE_EVENT")
+ ModuleEvents.append(ModuleEvent)
+
+ XmlTag = "ModuleSurfaceArea/Events/SignalEvents/EventTypes"
+ for XmlCreateEvent in XmlList(XmlMsa, XmlTag):
+ ModuleEvent = LoadModuleEvent(XmlCreateEvent, "SIGNAL_EVENT")
+ ModuleEvents.append(ModuleEvent)
+
+ return ModuleEvents
+
+
+## Load a new Module Hob class object.
+#
+# Read an input XML Hob DOM object and return an object of Hob
+# contained in the DOM object.
+#
+# @param XmlHob A child XML DOM object in Module XML DOM.
+#
+# @retvel ModuleHob A new Hob object created by XmlHob.
+#
+def LoadModuleHob(XmlHob):
+ ModuleHob = ModuleHobClass()
+
+ XmlTag = "HobTypes/HobType"
+ ModuleHob.Type = XmlElement(XmlHob, XmlTag)
+
+ XmlTag = "HobGuidCName"
+ ModuleHob.GuidCName = XmlAttribute(XmlHob, XmlTag)
+
+ SetCommon(ModuleHob, XmlHob)
+
+ return ModuleHob
+
+
+## Load a list of Module Hobs.
+#
+# Read an input Module XML DOM object and return a list of Hobs
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel Hobs A list of Hobs loaded from XmlMsa.
+#
+def LoadModuleHobs(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/Hobs/HobTypes"
+ return map(LoadModuleHob, XmlList(XmlMsa, XmlTag))
+
+
+## Load a new Module Variable class object.
+#
+# Read an input XML Variable DOM object and return an object of Variable
+# contained in the DOM object.
+#
+# @param XmlVariable A child XML DOM object in Module XML DOM.
+#
+# @retvel ModuleVariable A new Variable object created by XmlVariable.
+#
+def LoadModuleVariable(XmlVariable):
+ ModuleVariable = ModuleVariableClass()
+
+ XmlTag = "Variable/VariableName"
+ HexWordArray = XmlElement(XmlVariable, XmlTag).split()
+ try:
+ ModuleVariable.Name = "".join([unichr(int(a, 16)) for a in HexWordArray])
+ except:
+ ModuleVariable.Name = ""
+
+ XmlTag = "Variable/GuidC_Name"
+ ModuleVariable.GuidCName = XmlElement(XmlVariable, XmlTag)
+
+ SetCommon(ModuleVariable, XmlVariable)
+
+ return ModuleVariable
+
+
+## Load a list of Module Variables.
+#
+# Read an input Module XML DOM object and return a list of Variables
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel Variables A list of Variables loaded from XmlMsa.
+#
+def LoadModuleVariables(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/Variables/Variable"
+ return map(LoadModuleVariable, XmlList(XmlMsa, XmlTag))
+
+
+## Load a new Module Boot Mode class object.
+#
+# Read an input XML BootMode DOM object and return an object of Boot Mode
+# contained in the DOM object.
+#
+# @param XmlBootMode A child XML DOM object in Module XML DOM.
+#
+# @retvel ModuleBootMode A new Boot Mode object created by XmlBootMode.
+#
+def LoadModuleBootMode(XmlBootMode):
+ ModuleBootMode = ModuleBootModeClass()
+
+ XmlTag = "BootModeName"
+ ModuleBootMode.Name = XmlAttribute(XmlBootMode, XmlTag)
+
+ SetCommon(ModuleBootMode, XmlBootMode)
+
+ return ModuleBootMode
+
+
+## Load a list of Module Boot Modes.
+#
+# Read an input Module XML DOM object and return a list of Boot Modes
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel BootModes A list of Boot Modes loaded from XmlMsa.
+#
+def LoadModuleBootModes(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/BootModes/BootMode"
+ return map(LoadModuleBootMode, XmlList(XmlMsa, XmlTag))
+
+
+## Load a new Module System Table class object.
+#
+# Read an input XML SystemTable DOM object and return an object of System Table
+# contained in the DOM object.
+#
+# @param XmlSystemTable A child XML DOM object in Module XML DOM.
+#
+# @retvel ModuleSystemTable A new System Table object created by XmlSystemTable.
+#
+def LoadModuleSystemTable(XmlSystemTable):
+ ModuleSystemTable = ModuleSystemTableClass()
+
+ XmlTag = "SystemTable/SystemTableCName"
+ ModuleSystemTable.CName = XmlElement(XmlSystemTable, XmlTag)
+
+ SetCommon(ModuleSystemTable, XmlSystemTable)
+
+ return ModuleSystemTable
+
+
+## Load a list of Module System Tables.
+#
+# Read an input Module XML DOM object and return a list of System Tables
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel SystemTables A list of System Tables loaded from XmlMsa.
+#
+def LoadModuleSystemTables(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/SystemTables/SystemTableCNames"
+ return map(LoadModuleSystemTable, XmlList(XmlMsa, XmlTag))
+
+
+## Load a new Module Data Hub class object.
+#
+# Read an input XML DataHub DOM object and return an object of Data Hub
+# contained in the DOM object.
+#
+# @param XmlDataHub A child XML DOM object in Module XML DOM.
+#
+# @retvel ModuleDataHub A new Data Hub object created by XmlDataHub.
+#
+def LoadModuleDataHub(XmlDataHub):
+ ModuleDataHub = ModuleDataHubClass()
+
+ XmlTag = "DataHub/DataHubCName"
+ ModuleDataHub.CName = XmlElement(XmlDataHub, "DataHubCName")
+
+ SetCommon(ModuleDataHub, XmlDataHub)
+
+ return ModuleDataHub
+
+
+## Load a list of Module Data Hubs.
+#
+# Read an input Module XML DOM object and return a list of Data Hubs
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel DataHubs A list of Data Hubs loaded from XmlMsa.
+#
+def LoadModuleDataHubs(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/DataHubs/DataHubRecord"
+ return map(LoadModuleDataHub, XmlList(XmlMsa, XmlTag))
+
+
+## Load a new Module Hii Package class object.
+#
+# Read an input XML HiiPackage DOM object and return an object of Hii Package
+# contained in the DOM object.
+#
+# @param XmlHiiPackage A child XML DOM object in Module XML DOM.
+#
+# @retvel ModuleHiiPackage A new Hii Package object created by XmlHiiPackage.
+#
+def LoadModuleHiiPackage(XmlHiiPackage):
+ ModuleHiiPackage = ModuleHiiPackageClass()
+
+ XmlTag = "HiiPackage/HiiPackageCName"
+ ModuleHiiPackage.CName = XmlElement(XmlHiiPackage, "HiiCName")
+
+ SetCommon(ModuleHiiPackage, XmlHiiPackage)
+
+ return ModuleHiiPackage
+
+
+## Load a list of Module Hii Packages.
+#
+# Read an input Module XML DOM object and return a list of Hii Packages
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel HiiPackages A list of Hii Packages loaded from XmlMsa.
+#
+def LoadModuleHiiPackages(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/HiiPackages/HiiPackage"
+ return map(LoadModuleHiiPackage, XmlList(XmlMsa, XmlTag))
+
+
+## Load a list of Module Guids.
+#
+# Read an input Module XML DOM object and return a list of Guids
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel Guids A list of Guids loaded from XmlMsa.
+#
+def LoadModuleGuids(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/Guids/GuidCNames"
+ return map(LoadGuidProtocolPpiCommon, XmlList(XmlMsa, XmlTag))
+
+
+## Load a list of Module Pcd Codes.
+#
+# Read an input Module XML DOM object and return a list of Pcd Codes
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel PcdCodes A list of Pcd Codes loaded from XmlMsa.
+#
+def LoadModulePcdCodes(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/PcdCoded/PcdEntry"
+ return map(LoadPcd, XmlList(XmlMsa, XmlTag))
+
+
+## Load a list of Module Extern Images.
+#
+# Read an input Module XML DOM object and return a list of Extern Images
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel ExternImages A list of Extern Images loaded from XmlMsa.
+#
+def LoadModuleExternImages(XmlMsa):
+ ModuleExternImages = []
+
+ XmlTag = "ModuleSurfaceArea/Externs/Extern"
+ for XmlExtern in XmlList(XmlMsa, XmlTag):
+ XmlTag = "Extern/ModuleEntryPoint"
+ ModuleEntryPoint = XmlElement(XmlExtern, XmlTag)
+ XmlTag = "Extern/ModuleUnloadImage"
+ ModuleUnloadImage = XmlElement(XmlExtern, XmlTag)
+ if ModuleEntryPoint == "" and ModuleUnloadImage == "":
+ continue
+
+ ModuleExtern = ModuleExternImageClass()
+ ModuleExtern.ModuleEntryPoint = ModuleEntryPoint
+ ModuleExtern.ModuleUnloadImage = ModuleUnloadImage
+ ModuleExternImages.append(ModuleExtern)
+
+ return ModuleExternImages
+
+
+## Load a list of Module Extern Libraries.
+#
+# Read an input Module XML DOM object and return a list of Extern Libraries
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel ExternLibraries A list of Extern Libraries loaded from XmlMsa.
+#
+def LoadModuleExternLibraries(XmlMsa):
+ ModuleExternLibraries = []
+
+ XmlTag = "ModuleSurfaceArea/Externs/Extern"
+ for XmlExtern in XmlList(XmlMsa, XmlTag):
+ XmlTag = "Extern/Constructor"
+ Constructor = XmlElement(XmlExtern, XmlTag)
+ XmlTag = "Extern/Destructor"
+ Destructor = XmlElement(XmlExtern, XmlTag)
+ if Constructor == "" and Destructor == "":
+ continue
+
+ ModuleExtern = ModuleExternLibraryClass()
+ ModuleExtern.Constructor = Constructor
+ ModuleExtern.Destructor = Destructor
+ ModuleExternLibraries.append(ModuleExtern)
+
+ return ModuleExternLibraries
+
+
+## Load a list of Module Extern Drivers.
+#
+# Read an input Module XML DOM object and return a list of Extern Drivers
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel ExternDrivers A list of Extern Drivers loaded from XmlMsa.
+#
+def LoadModuleExternDrivers(XmlMsa):
+ ModuleExternDrivers = []
+
+ XmlTag = "ModuleSurfaceArea/Externs/Extern"
+ for XmlExtern in XmlList(XmlMsa, XmlTag):
+ XmlTag = "Extern/DriverBinding"
+ DriverBinding = XmlElement(XmlExtern, XmlTag)
+ XmlTag = "Extern/ComponentName"
+ ComponentName = XmlElement(XmlExtern, XmlTag)
+ XmlTag = "Extern/DriverConfig"
+ DriverConfig = XmlElement(XmlExtern, XmlTag)
+ XmlTag = "Extern/DriverDiag"
+ DriverDiag = XmlElement(XmlExtern, XmlTag)
+ if DriverBinding == "":
+ continue
+
+ ModuleExtern = ModuleExternDriverClass()
+ ModuleExtern.DriverBinding = DriverBinding
+ ModuleExtern.ComponentName = ComponentName
+ ModuleExtern.DriverConfig = DriverConfig
+ ModuleExtern.DriverDiag = DriverDiag
+ ModuleExternDrivers.append(ModuleExtern)
+
+ return ModuleExternDrivers
+
+
+## Load a list of Module Extern Call Backs.
+#
+# Read an input Module XML DOM object and return a list of Extern Call Backs
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel ExternCallBacks A list of Extern Call Backs loaded from XmlMsa.
+#
+def LoadModuleExternCallBacks(XmlMsa):
+ ModuleExternCallBacks = []
+
+ XmlTag = "ModuleSurfaceArea/Externs/Extern"
+ for XmlExtern in XmlList(XmlMsa, XmlTag):
+ XmlTag = "Extern/SetVirtualAddressMapCallBack"
+ SetVirtualAddressMap = XmlElement(XmlExtern, XmlTag)
+ XmlTag = "Extern/ExitBootServicesCallBack"
+ ExitBootServices = XmlElement(XmlExtern, XmlTag)
+ if SetVirtualAddressMap == "" and ExitBootServices == "":
+ continue
+
+ ModuleExtern = ModuleExternCallBackClass()
+ ModuleExtern.ExitBootServicesCallBack = ExitBootServices
+ ModuleExtern.SetVirtualAddressMapCallBack = SetVirtualAddressMap
+ ModuleExternCallBacks.append(ModuleExtern)
+
+ return ModuleExternCallBacks
+
+
+## Load a list of Module Build Options.
+#
+# Read an input Module XML DOM object and return a list of Build Options
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel BuildOptions A list of Build Options loaded from XmlMsa.
+#
+def LoadModuleBuildOptions(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/ModuleBuildOptions/Options/Option"
+ return map(LoadBuildOption, XmlList(XmlMsa, XmlTag))
+
+
+## Load a list of Module User Extensions.
+#
+# Read an input Module XML DOM object and return a list of User Extensions
+# contained in the DOM object.
+#
+# @param XmlMsa An XML DOM object read from MSA file.
+#
+# @retvel UserExtensions A list of User Extensions loaded from XmlMsa.
+#
+def LoadModuleUserExtensions(XmlMsa):
+ XmlTag = "ModuleSurfaceArea/UserExtensions"
+ return map(LoadUserExtensions, XmlList(XmlMsa, XmlTag))
+
+## Load a new Module class object.
+#
+# Read an input MSA File and return a new Module class Object.
+#
+# @param MsaFileName An XML DOM object read from MSA file.
+#
+# @retvel Module A new Module class object loaded from MSA File.
+#
+def LoadMsa(MsaFileName):
+ XmlMsa = XmlParseFile(MsaFileName)
+ EdkLogger.verbose("Load MSA File: %s" % MsaFileName)
+
+ Module = ModuleClass()
+ Module.Header = LoadModuleHeader(XmlMsa, MsaFileName)
+ Module.LibraryClasses = LoadModuleLibraryClasses(XmlMsa)
+ Module.Sources = LoadModuleSources(XmlMsa)
+ Module.BinaryFiles = LoadModuleBinaries(XmlMsa)
+ Module.NonProcessedFiles = LoadModuleNonProcessedFiles(XmlMsa)
+ Module.PackageDependencies = LoadModulePackageDependencies(XmlMsa)
+ Module.Protocols = LoadModuleProtocols(XmlMsa)
+ Module.Ppis = LoadModulePpis(XmlMsa)
+ Module.Events = LoadModuleEvents(XmlMsa)
+ Module.Hobs = LoadModuleHobs(XmlMsa)
+ Module.Variables = LoadModuleVariables(XmlMsa)
+ Module.BootModes = LoadModuleBootModes(XmlMsa)
+ Module.SystemTables = LoadModuleSystemTables(XmlMsa)
+ Module.DataHubs = LoadModuleDataHubs(XmlMsa)
+ Module.HiiPackages = LoadModuleHiiPackages(XmlMsa)
+ Module.Guids = LoadModuleGuids(XmlMsa)
+ Module.PcdCodes = LoadModulePcdCodes(XmlMsa)
+ Module.ExternImages = LoadModuleExternImages(XmlMsa)
+ Module.ExternLibraries = LoadModuleExternLibraries(XmlMsa)
+ Module.ExternDrivers = LoadModuleExternDrivers(XmlMsa)
+ Module.ExternCallBacks = LoadModuleExternCallBacks(XmlMsa)
+ Module.BuildOptions = LoadModuleBuildOptions(XmlMsa)
+ Module.UserExtensions = LoadModuleUserExtensions(XmlMsa)
+
+ return Module
+
+
+# This acts like the main() function for the script, unless it is 'import'ed
+# into another script.
+if __name__ == '__main__':
+ pass \ No newline at end of file
diff --git a/BaseTools/Source/Python/msa2inf/Msa2Inf.py b/BaseTools/Source/Python/msa2inf/Msa2Inf.py
new file mode 100644
index 0000000000..5873b1d198
--- /dev/null
+++ b/BaseTools/Source/Python/msa2inf/Msa2Inf.py
@@ -0,0 +1,44 @@
+## @file
+# Convert an XML-based MSA file to a text-based INF file.
+#
+# Copyright (c) 2007, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+import sys
+from Common.MigrationUtilities import *
+from LoadMsa import LoadMsa
+from StoreInf import StoreInf
+from ConvertModule import ConvertMsaModuleToInfModule
+
+## Entrance method
+#
+# This method mainly dispatch specific methods per the command line options.
+# If no error found, return zero value so the caller of this tool can know
+# if it's executed successfully or not.
+#
+# @retval 0 Tool was successful.
+# @retval 1 Tool failed.
+#
+def Main():
+ try:
+ Options, InputFile = MigrationOptionParser("MSA", "INF", "%prog")
+ Module = LoadMsa(InputFile)
+ ConvertMsaModuleToInfModule(Module)
+ StoreInf(Options.OutputFile, Module)
+ return 0
+ except Exception, e:
+ print e
+ return 1
+
+if __name__ == '__main__':
+ sys.exit(Main())
diff --git a/BaseTools/Source/Python/msa2inf/StoreInf.py b/BaseTools/Source/Python/msa2inf/StoreInf.py
new file mode 100644
index 0000000000..bb58dc2f2f
--- /dev/null
+++ b/BaseTools/Source/Python/msa2inf/StoreInf.py
@@ -0,0 +1,442 @@
+## @file
+# Store a Module class object to an INF file.
+#
+# Copyright (c) 2007, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+from LoadMsa import LoadMsa
+from CommonDataClass.ModuleClass import *
+from Common.MigrationUtilities import *
+
+## Get the produced library class.
+#
+# Return the item of Library Class based on Library .
+#
+# @param LibraryClasses A list of library classes the module produces.
+#
+# @retval LibraryClassItem A text format library class item.
+#
+def GetModuleLibraryClass(LibraryClasses):
+ ProducedLibraryClasses = []
+ for LibraryClass in LibraryClasses:
+ ProducedLibraryClass = LibraryClass.LibraryClass
+ SupportedModueTypes = " ".join(LibraryClass.SupModuleList)
+ if SupportedModueTypes != "":
+ ProducedLibraryClass += "|" + SupportedModueTypes
+ ProducedLibraryClasses.append(ProducedLibraryClass)
+
+ return "|".join(ProducedLibraryClasses)
+
+
+## Store Defines section.
+#
+# Write [Defines] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Defines section.
+# @param Module An input Module class object.
+#
+def StoreModuleDefinesSection(InfFile, Module):
+ ModuleHeader = Module.Header
+
+ DefinesTupleList = []
+ DefinesTupleList.append(("INF_VERSION", ModuleHeader.InfVersion))
+
+ if ModuleHeader.Name != "":
+ DefinesTupleList.append(("BASE_NAME", ModuleHeader.Name))
+
+ if ModuleHeader.Guid != "":
+ DefinesTupleList.append(("FILE_GUID", ModuleHeader.Guid))
+
+ if ModuleHeader.Version != "":
+ DefinesTupleList.append(("VERSION_STRING", ModuleHeader.Version))
+
+ if ModuleHeader.ModuleType != "":
+ DefinesTupleList.append(("MODULE_TYPE", ModuleHeader.ModuleType))
+
+ if ModuleHeader.EfiSpecificationVersion != "":
+ DefinesTupleList.append(("EFI_SPECIFICATION_VERSION", ModuleHeader.EfiSpecificationVersion))
+
+ if ModuleHeader.EdkReleaseVersion != "":
+ DefinesTupleList.append(("EDK_RELEASE_VERSION", ModuleHeader.EdkReleaseVersion))
+
+ ProducedLibraryClass = GetModuleLibraryClass(ModuleHeader.LibraryClass)
+ if ProducedLibraryClass != "":
+ DefinesTupleList.append(("LIBRARY_CLASS", ProducedLibraryClass))
+
+ if ModuleHeader.MakefileName != "":
+ DefinesTupleList.append(("MAKEFILE_NAME", ModuleHeader.MakeFileName))
+
+ if ModuleHeader.PcdIsDriver != "":
+ DefinesTupleList.append(("PCD_DRIVER", "TRUE"))
+
+ if len(Module.ExternImages) > 0:
+ ModuleEntryPoint = Module.ExternImages[0].ModuleEntryPoint
+ ModuleUnloadImage = Module.ExternImages[0].ModuleUnloadImage
+ if ModuleEntryPoint != "":
+ DefinesTupleList.append(("ENTRY_POINT", ModuleEntryPoint))
+ if ModuleUnloadImage != "":
+ DefinesTupleList.append(("UNLOAD_IMAGE", ModuleUnloadImage))
+
+ if len(Module.ExternLibraries) > 0:
+ Constructor = Module.ExternLibraries[0].Constructor
+ Destructor = Module.ExternLibraries[0].Destructor
+ if Constructor != "":
+ DefinesTupleList.append(("CONSTRUCTOR", Constructor))
+ if Destructor != "":
+ DefinesTupleList.append(("DESTRUCTOR", Destructor))
+
+ StoreDefinesSection(InfFile, DefinesTupleList)
+
+
+## Return a Module Source Item.
+#
+# Read the input ModuleSourceFile class object and return one line of Source Item.
+#
+# @param ModuleSourceFile An input ModuleSourceFile class object.
+#
+# @retval SourceItem A Module Source Item.
+#
+def GetModuleSourceItem(ModuleSourceFile):
+ Source = []
+ Source.append(ModuleSourceFile.SourceFile)
+ Source.append(ModuleSourceFile.ToolChainFamily)
+ Source.append(ModuleSourceFile.TagName)
+ Source.append(ModuleSourceFile.ToolCode)
+ Source.append(ModuleSourceFile.FeatureFlag)
+ return "|".join(Source).rstrip("|")
+
+
+## Store Sources section.
+#
+# Write [Sources] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Sources section.
+# @param Module An input Module class object.
+#
+def StoreModuleSourcesSection(InfFile, Module):
+ Section = GetSection("Sources", GetModuleSourceItem, Module.Sources)
+ StoreTextFile(InfFile, Section)
+
+
+## Return a Module Binary Item.
+#
+# Read the input ModuleBinaryFile class object and return one line of Binary Item.
+#
+# @param ModuleBinaryFile An input ModuleBinaryFile class object.
+#
+# @retval BinaryItem A Module Binary Item.
+#
+def GetModuleBinaryItem(ModuleBinaryFile):
+ Binary = []
+ Binary.append(ModuleBinaryFile.FileType)
+ Binary.append(ModuleBinaryFile.BinaryFile)
+ Binary.append(ModuleBinaryFile.Target)
+ Binary.append(ModuleBinaryFile.FeatureFlag)
+ return "|".join(Binary).rstrip("|")
+
+
+## Store Binaries section.
+#
+# Write [Binaries] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Binaries section.
+# @param Module An input Module class object.
+#
+def StoreModuleBinariesSection(InfFile, Module):
+ Section = GetSection("Binaries", GetModuleBinaryItem, Module.Binaries)
+ StoreTextFile(InfFile, Section)
+
+
+## Return a Module Library Class Item.
+#
+# Read the input LibraryClass class object and return one line of Library Class Item.
+#
+# @param LibraryClass An input LibraryClass class object.
+#
+# @retval LibraryClassItem A Module Library Class Item.
+#
+def GetModuleLibraryClassItem(LibraryClass):
+ if "ALWAYS_PRODUCED" in LibraryClass.Usage:
+ return ""
+
+ LibraryClassList = []
+ LibraryClassList.append(LibraryClass.LibraryClass)
+ LibraryClassList.append(LibraryClass.RecommendedInstance)
+ LibraryClassList.append(LibraryClass.FeatureFlag)
+
+ return "|".join(LibraryClassList).rstrip("|")
+
+
+## Store Library Classes section.
+#
+# Write [LibraryClasses] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Library Classes section.
+# @param Module An input Module class object.
+#
+def StoreModuleLibraryClassesSection(InfFile, Module):
+ Section = GetSection("LibraryClasses", GetModuleLibraryClassItem, Module.LibraryClasses)
+ StoreTextFile(InfFile, Section)
+
+
+## Return a Module Package Item.
+#
+# Read the input PackageDependency class object and return one line of Package Item.
+#
+# @param PackageDependency An input PackageDependency class object.
+#
+# @retval PackageItem A Module Package Item.
+#
+def GetModulePackageItem(PackageDependency):
+ return PackageDependency.FilePath
+
+
+## Store Packages section.
+#
+# Write [Packages] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Packages section.
+# @param Module An input Module class object.
+#
+def StoreModulePackagesSection(InfFile, Module):
+ Section = GetSection("Packages", GetModulePackageItem, Module.PackageDependencies)
+ StoreTextFile(InfFile, Section)
+
+
+## Return a Module Guid C Name Item.
+#
+# Read the input Guid class object and return one line of Guid C Name Item.
+#
+# @param Guid An input Guid class object.
+#
+# @retval GuidCNameItem A Module Guid C Name Item.
+#
+def GetModuleGuidCNameItem(Guid):
+ try:
+ return Guid.GuidCName
+ except:
+ return Guid.CName
+
+
+## Store Protocols section.
+#
+# Write [Protocols] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Protocols section.
+# @param Module An input Module class object.
+#
+def StoreModuleProtocolsSection(InfFile, Module):
+ Section = GetSection("Protocols", GetModuleGuidCNameItem, Module.Protocols)
+ StoreTextFile(InfFile, Section)
+
+
+## Store Ppis section.
+#
+# Write [Ppis] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Ppis section.
+# @param Module An input Module class object.
+#
+def StoreModulePpisSection(InfFile, Module):
+ Section = GetSection("Ppis", GetModuleGuidCNameItem, Module.Ppis)
+ StoreTextFile(InfFile, Section)
+
+
+## Store Guids section.
+#
+# Write [Guids] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Guids section.
+# @param Module An input Module class object.
+#
+def StoreModuleGuidsSection(InfFile, Module):
+ Guids = []
+ Guids += Module.Guids
+ Guids += Module.Events
+ Guids += Module.Hobs
+ Guids += Module.Variables
+ Guids += Module.SystemTables
+ Guids += Module.DataHubs
+ Guids += Module.HiiPackages
+ Section = GetSection("Guids", GetModuleGuidCNameItem, Guids)
+ StoreTextFile(InfFile, Section)
+
+
+## Return a Module Pcd Item.
+#
+# Read the input Pcd class object and return one line of Pcd Item.
+#
+# @param Pcd An input Pcd class object.
+#
+# @retval PcdItem A Module Pcd Item.
+#
+def GetModulePcdItem(Pcd):
+ PcdItem = "%s.%s" % (Pcd.TokenSpaceGuidCName, Pcd.CName)
+ if Pcd.DefaultValue != "":
+ PcdItem = "%s|%s" % (PcdItem, Pcd.DefaultValue)
+
+ return PcdItem
+
+
+## DEC Pcd Section Name dictionary indexed by PCD Item Type.
+mInfPcdSectionNameDict = {
+ "FEATURE_FLAG" : "FeaturePcd",
+ "FIXED_AT_BUILD" : "FixedPcd",
+ "PATCHABLE_IN_MODULE" : "PatchPcd",
+ "DYNAMIC" : "Pcd",
+ "DYNAMIC_EX" : "PcdEx"
+ }
+
+## Store Pcds section.
+#
+# Write [(PcdType)] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Pcds section.
+# @param Module An input Module class object.
+#
+def StoreModulePcdsSection(InfFile, Module):
+ PcdsDict = {}
+ for Pcd in Module.PcdCodes:
+ PcdSectionName = mInfPcdSectionNameDict.get(Pcd.ItemType)
+ if PcdSectionName:
+ PcdsDict.setdefault(PcdSectionName, []).append(Pcd)
+ else:
+ EdkLogger.info("Unknown Pcd Item Type: %s" % Pcd.ItemType)
+
+ Section = ""
+ for PcdSectionName in PcdsDict:
+ Pcds = PcdsDict[PcdSectionName]
+ Section += GetSection(PcdSectionName, GetModulePcdItem, Pcds)
+ Section += "\n"
+
+ StoreTextFile(InfFile, Section)
+
+
+## Return a Module Depex Item.
+#
+# Read the input Depex class object and return one line of Depex Item.
+#
+# @param Depex An input Depex class object.
+#
+# @retval DepexItem A Module Depex Item.
+#
+def GetModuleDepexItem(Depex):
+ return Depex.Depex
+
+
+## Store Depex section.
+#
+# Write [Depex] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Depex section.
+# @param Module An input Module class object.
+#
+def StoreModuleDepexSection(InfFile, Module):
+ Section = GetSection("Depex", GetModuleDepexItem, Module.Depex)
+ StoreTextFile(InfFile, Section)
+
+
+## Return a Module Build Option Item.
+#
+# Read the input BuildOption class object and return one line of Build Option Item.
+#
+# @param BuildOption An input BuildOption class object.
+#
+# @retval BuildOptionItem A Module Build Option Item.
+#
+def GetModuleBuildOptionItem(BuildOption):
+ BuildTarget = BuildOption.BuildTarget
+ if BuildTarget == "":
+ BuildTarget = "*"
+
+ TagName = BuildOption.TagName
+ if TagName == "":
+ TagName = "*"
+
+ ToolCode = BuildOption.ToolCode
+ if ToolCode == "":
+ ToolCode = "*"
+
+ Item = "_".join((BuildTarget, TagName, "*", ToolCode, "Flag"))
+
+ ToolChainFamily = BuildOption.ToolChainFamily
+ if ToolChainFamily != "":
+ Item = "%s:%s" % (ToolChainFamily, Item)
+
+ return "%-30s = %s" % (Item, BuildOption.Option)
+
+
+## Store Build Options section.
+#
+# Write [BuildOptions] section to the InfFile based on Module class object.
+# Different CPU architectures are specified in the subsection if possible.
+#
+# @param InfFile The output INF file to store the Build Options section.
+# @param Module An input Module class object.
+#
+def StoreModuleBuildOptionsSection(InfFile, Module):
+ Section = GetSection("BuildOption", GetModuleBuildOptionItem, Module.BuildOptions)
+ StoreTextFile(InfFile, Section)
+
+
+## Store User Extensions section.
+#
+# Write [UserExtensions] section to the InfFile based on Module class object.
+#
+# @param InfFile The output INF file to store the User Extensions section.
+# @param Module An input Module class object.
+#
+def StoreModuleUserExtensionsSection(InfFile, Module):
+ Section = "".join(map(GetUserExtensions, Module.UserExtensions))
+ StoreTextFile(InfFile, Section)
+
+
+## Store a Module class object to a new INF file.
+#
+# Read an input Module class object and save the contents to a new INF file.
+#
+# @param INFFileName The output INF file.
+# @param Module An input Package class object.
+#
+def StoreInf(InfFileName, Module):
+ InfFile = open(InfFileName, "w+")
+ EdkLogger.info("Save file to %s" % InfFileName)
+
+ StoreHeader(InfFile, Module.Header)
+ StoreModuleDefinesSection(InfFile, Module)
+ StoreModuleSourcesSection(InfFile, Module)
+ StoreModuleBinariesSection(InfFile, Module)
+ StoreModulePackagesSection(InfFile, Module)
+ StoreModuleLibraryClassesSection(InfFile, Module)
+ StoreModuleProtocolsSection(InfFile, Module)
+ StoreModulePpisSection(InfFile, Module)
+ StoreModuleGuidsSection(InfFile, Module)
+ StoreModulePcdsSection(InfFile, Module)
+ StoreModuleDepexSection(InfFile, Module)
+ StoreModuleBuildOptionsSection(InfFile, Module)
+ StoreModuleUserExtensionsSection(InfFile, Module)
+
+ InfFile.close()
+
+if __name__ == '__main__':
+ pass
diff --git a/BaseTools/Source/Python/msa2inf/__init__.py b/BaseTools/Source/Python/msa2inf/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/BaseTools/Source/Python/msa2inf/__init__.py