EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

BaseTools/Source/Python/spd2dec/LoadSpd.py

Go to the documentation of this file.
00001 ## @file
00002 # Open an SPD file and load all its contents to a PackageClass object.
00003 #
00004 # Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
00005 # This program and the accompanying materials
00006 # are licensed and made available under the terms and conditions of the BSD License
00007 # which accompanies this distribution.  The full text of the license may be found at
00008 # http://opensource.org/licenses/bsd-license.php
00009 #
00010 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
00011 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
00012 #
00013 
00014 ##
00015 # Import Modules
00016 #
00017 import os
00018 from Common.XmlRoutines import *
00019 from Common.MigrationUtilities import *
00020 from CommonDataClass.PackageClass import *
00021 
00022 
00023 ## Load a list of Package Cloned Records.
00024 #
00025 # Read an input Package XML DOM object and return a list of Cloned Records
00026 # contained in the DOM object.
00027 #
00028 # @param  XmlSpd               An XML DOM object read from SPD file.
00029 #
00030 # @retvel ClonedRecords        A list of Cloned Records loaded from XmlSpd.
00031 #
00032 def LoadPackageClonedRecords(XmlSpd):
00033     XmlTag = "PackageSurfaceArea/PackageDefinitions/ClonedFrom/Cloned"
00034     return map(LoadClonedRecord, XmlList(XmlSpd, XmlTag))
00035 
00036 
00037 ## Load Package Header.
00038 #
00039 # Read an input Package XML DOM object and return Package Header class object
00040 # contained in the DOM object.
00041 #
00042 # @param  XmlSpd               An XML DOM object read from SPD file.
00043 # @param  SpdFileName          The file path of SPD File.
00044 #
00045 # @retvel PackageHeader        A new Package Header object loaded from XmlSpd.
00046 #
00047 def LoadPackageHeader(XmlSpd, SpdFileName):
00048     PackageHeader = PackageHeaderClass()
00049     
00050     XmlTag = "PackageSurfaceArea/SpdHeader"
00051     SpdHeader = XmlNode(XmlSpd, XmlTag)
00052     
00053     SetIdentification(PackageHeader, SpdHeader, "PackageName", SpdFileName)
00054     SetCommonHeader(PackageHeader, SpdHeader)
00055     
00056     XmlTag = "PackageSurfaceArea/PackageDefinitions/ReadOnly"
00057     if XmlElement(XmlSpd, XmlTag).lower() == "true":
00058         PackageHeader.ReadOnly = True
00059 
00060     XmlTag = "PackageSurfaceArea/PackageDefinitions/RePackage"
00061     if XmlElement(XmlSpd, XmlTag).lower() == "true":
00062         PackageHeader.RePackage = True
00063 
00064     PackageHeader.ClonedFrom = LoadPackageClonedRecords(XmlSpd)
00065     
00066     return PackageHeader
00067 
00068 
00069 ## Load a list of Package Library Classes.
00070 #
00071 # Read an input Package XML DOM object and return a list of Library Classes
00072 # contained in the DOM object.
00073 #
00074 # @param  XmlSpd               An XML DOM object read from SPD file.
00075 #
00076 # @retvel LibraryClasses       A list of Library Classes loaded from XmlSpd.
00077 #
00078 def LoadPackageLibraryClasses(XmlSpd):
00079     XmlTag = "PackageSurfaceArea/LibraryClassDeclarations/LibraryClass"
00080     return map(LoadLibraryClass, XmlList(XmlSpd, XmlTag))
00081 
00082 
00083 ## Load a new Package Industry Std Header class object.
00084 #
00085 # Read an input XML IndustryStdHeader DOM object and return an object of
00086 # Industry Std Header contained in the DOM object.
00087 #
00088 # @param  XmlIndustryStdHeader     A child XML DOM object in Package XML DOM.
00089 #
00090 # @retvel PackageIndustryStdHeader A new Industry Std Header object created by XmlIndustryStdHeader.
00091 #
00092 def LoadPackageIndustryStdHeader(XmlIndustryStdHeader):
00093     PackageIndustryStdHeader = PackageIndustryStdHeaderClass()
00094     
00095     XmlTag = "Name"
00096     Name = XmlAttribute(XmlIndustryStdHeader, XmlTag)
00097     PackageIndustryStdHeader.Name = Name
00098     
00099     XmlTag = "IndustryStdHeader/IncludeHeader"
00100     IncludeHeader = XmlElement(XmlIndustryStdHeader, XmlTag)
00101     PackageIndustryStdHeader.IncludeHeader = IncludeHeader
00102     
00103     SetCommon(PackageIndustryStdHeader, XmlIndustryStdHeader)
00104     
00105     return PackageIndustryStdHeader
00106 
00107 
00108 ## Load a list of Package Industry Std Headers.
00109 #
00110 # Read an input Package XML DOM object and return a list of Industry Std Headers
00111 # contained in the DOM object.
00112 #
00113 # @param  XmlSpd             An XML DOM object read from SPD file.
00114 #
00115 # @retvel IndustryStdHeaders A list of Industry Std Headers loaded from XmlSpd.
00116 #
00117 def LoadPackageIndustryStdHeaders(XmlSpd):
00118     XmlTag = "PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader"
00119     return map(LoadPackageIndustryStdHeader, XmlList(XmlSpd, XmlTag))
00120 
00121 
00122 ## Load a list of Package Module Files.
00123 #
00124 # Read an input Package XML DOM object and return a list of Module Files
00125 # contained in the DOM object.
00126 #
00127 # @param  XmlSpd             An XML DOM object read from SPD file.
00128 #
00129 # @retvel ModuleFiles        A list of Module Files loaded from XmlSpd.
00130 #
00131 def LoadPackageModuleFiles(XmlSpd):
00132     XmlTag = "PackageSurfaceArea/MsaFiles/Filename"
00133     return XmlElementList(XmlSpd, XmlTag)
00134 
00135 
00136 ## Load a new Package Include Pkg Header class object.
00137 #
00138 # Read an input XML IncludePkgHeader DOM object and return an object of Include
00139 # Package Header contained in the DOM object.
00140 #
00141 # @param  XmlPackageIncludeHeader A child XML DOM object in Package XML DOM.
00142 #
00143 # @retvel PackageIncludePkgHeader A new Include Pkg Header object created by
00144 #                                 XmlPackageIncludeHeader.
00145 #
00146 def LoadPackageIncludePkgHeader(XmlPackageIncludeHeader):
00147     PackageIncludeHeader = PackageIncludePkgHeaderClass()
00148     
00149     IncludeHeader = XmlElementData(XmlPackageIncludeHeader)
00150     PackageIncludeHeader.IncludeHeader = IncludeHeader
00151     
00152     XmlTag = "ModuleType"
00153     ModuleTypes = XmlAttribute(XmlPackageIncludeHeader, XmlTag)
00154     PackageIncludeHeader.ModuleType = ModuleTypes.split()
00155     
00156     return PackageIncludeHeader
00157 
00158 
00159 ## Load a list of Package Include Pkg Headers.
00160 #
00161 # Read an input Package XML DOM object and return a list of Include Pkg Headers
00162 # contained in the DOM object.
00163 #
00164 # @param  XmlSpd               An XML DOM object read from SPD file.
00165 #
00166 # @retvel IncludePkgHeaders    A list of Include Pkg Headers loaded from XmlSpd.
00167 #
00168 def LoadPackageIncludePkgHeaders(XmlSpd):
00169     XmlTag = "PackageSurfaceArea/PackageHeaders/IncludePkgHeader"
00170     return map(LoadPackageIncludePkgHeader, XmlList(XmlSpd, XmlTag))
00171 
00172 
00173 ## Load a list of Package Guid Declarations.
00174 #
00175 # Read an input Package XML DOM object and return a list of Guid Declarations
00176 # contained in the DOM object.
00177 #
00178 # @param  XmlSpd               An XML DOM object read from SPD file.
00179 #
00180 # @retvel GuidDeclarations     A list of Guid Declarations loaded from XmlSpd.
00181 #
00182 def LoadPackageGuidDeclarations(XmlSpd):
00183     XmlTag = "PackageSurfaceArea/GuidDeclarations/Entry"
00184     return map(LoadGuidProtocolPpiCommon, XmlList(XmlSpd, XmlTag))
00185 
00186 
00187 ## Load a list of Package Protocol Declarations.
00188 #
00189 # Read an input Package XML DOM object and return a list of Protocol Declarations
00190 # contained in the DOM object.
00191 #
00192 # @param  XmlSpd               An XML DOM object read from SPD file.
00193 #
00194 # @retvel ProtocolDeclarations A list of Protocol Declarations loaded from XmlSpd.
00195 #
00196 def LoadPackageProtocolDeclarations(XmlSpd):
00197     XmlTag = "PackageSurfaceArea/ProtocolDeclarations/Entry"
00198     return map(LoadGuidProtocolPpiCommon, XmlList(XmlSpd, XmlTag))
00199 
00200 
00201 ## Load a list of Package Ppi Declarations.
00202 #
00203 # Read an input Package XML DOM object and return a list of Ppi Declarations
00204 # contained in the DOM object.
00205 #
00206 # @param  XmlSpd               An XML DOM object read from SPD file.
00207 #
00208 # @retvel PpiDeclarations      A list of Ppi Declarations loaded from XmlSpd.
00209 #
00210 def LoadPackagePpiDeclarations(XmlSpd):
00211     XmlTag = "PackageSurfaceArea/PpiDeclarations/Entry"
00212     return map(LoadGuidProtocolPpiCommon, XmlList(XmlSpd, XmlTag))
00213 
00214 
00215 ## Load a list of Package Pcd Declarations.
00216 #
00217 # Read an input Package XML DOM object and return a list of Pcd Declarations
00218 # contained in the DOM object.
00219 #
00220 # @param  XmlSpd               An XML DOM object read from SPD file.
00221 #
00222 # @retvel PcdDeclarations      A list of Pcd Declarations loaded from XmlSpd.
00223 #
00224 def LoadPackagePcdDeclarations(XmlSpd):
00225     XmlTag = "PackageSurfaceArea/PcdDeclarations/PcdEntry"
00226     return map(LoadPcd, XmlList(XmlSpd, XmlTag))
00227 
00228 
00229 ## Load a list of Package User Extensions.
00230 #
00231 # Read an input Package XML DOM object and return a list of User Extensions
00232 # contained in the DOM object.
00233 #
00234 # @param  XmlSpd               An XML DOM object read from SPD file.
00235 #
00236 # @retvel UserExtensions       A list of User Extensions loaded from XmlSpd.
00237 #
00238 def LoadPackageUserExtensions(XmlSpd):
00239     XmlTag = "PackageSurfaceArea/UserExtensions"
00240     return map(LoadUserExtensions, XmlList(XmlSpd, XmlTag))
00241 
00242 
00243 ## Load a new Package class object.
00244 #
00245 # Read an input SPD File and return a new Package class Object.
00246 #
00247 # @param  SpdFileName          An XML DOM object read from SPD file.
00248 #
00249 # @retvel Package              A new Module class object loaded from SPD File.
00250 #
00251 def LoadSpd(SpdFileName):
00252     XmlSpd = XmlParseFile(SpdFileName)
00253     EdkLogger.verbose("Xml Object loaded for file %s" % SpdFileName)
00254 
00255     Package = PackageClass()
00256     Package.Header = LoadPackageHeader(XmlSpd, SpdFileName)
00257     Package.LibraryClassDeclarations = LoadPackageLibraryClasses(XmlSpd)
00258     Package.IndustryStdHeaders = LoadPackageIndustryStdHeaders(XmlSpd)
00259     Package.ModuleFiles = LoadPackageModuleFiles(XmlSpd)
00260     Package.PackageIncludePkgHeaders = LoadPackageIncludePkgHeaders(XmlSpd)
00261     Package.GuidDeclarations = LoadPackageGuidDeclarations(XmlSpd)
00262     Package.ProtocolDeclarations = LoadPackageProtocolDeclarations(XmlSpd)
00263     Package.PpiDeclarations = LoadPackagePpiDeclarations(XmlSpd)
00264     Package.PcdDeclarations = LoadPackagePcdDeclarations(XmlSpd)
00265     Package.UserExtensions = LoadPackageUserExtensions(XmlSpd)
00266     
00267     return Package
00268 
00269 
00270 # This acts like the main() function for the script, unless it is 'import'ed
00271 # into another script.
00272 if __name__ == '__main__':
00273     pass
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines