]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/fpd2dsc/LoadFpd.py
Sync EDKII BaseTools to BaseTools project r1971
[mirror_edk2.git] / BaseTools / Source / Python / fpd2dsc / LoadFpd.py
1 ## @file
2 # Open an FPD file and load all its contents to a PlatformClass object.
3 #
4 # Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ##
15 # Import Modules
16 #
17 import os
18 from CommonDataClass.PlatformClass import *
19 from CommonDataClass.FdfClass import *
20 from Common.XmlRoutines import *
21 from Common.MigrationUtilities import *
22 from EdkIIWorkspaceGuidsInfo import gEdkIIWorkspaceGuidsInfo
23
24 ## Load Platform Header
25 #
26 # Read an input Platform XML DOM object and return Platform Header class object
27 # contained in the DOM object.
28 #
29 # @param XmlFpd An XML DOM object read from FPD file
30 # @param FpdFileName The file path of FPD File
31 #
32 # @retvel PlatformHeader A new Platform Header object loaded from XmlFpd
33 #
34 def LoadPlatformHeader(XmlFpd, FpdFileName):
35 PlatformHeader = PlatformHeaderClass()
36
37 XmlTag = "PlatformSurfaceArea/PlatformHeader"
38 FpdHeader = XmlNode(XmlFpd, XmlTag)
39
40 SetIdentification(PlatformHeader, FpdHeader, "PlatformName", FpdFileName)
41 SetCommonHeader(PlatformHeader, FpdHeader)
42
43 XmlTag = "PlatformSurfaceArea/PlatformHeader/Specification"
44 List = XmlElement(XmlFpd, XmlTag).split()
45 SpecificationName = List[0]
46 SpecificationValue = List[1]
47 PlatformHeader.Specification = {SpecificationName:SpecificationValue}
48
49 XmlTag = "PlatformSurfaceArea/PlatformDefinitions/SupportedArchitectures"
50 PlatformHeader.SupArchList = XmlElement(XmlFpd, XmlTag).split()
51
52 XmlTag = "PlatformSurfaceArea/PlatformDefinitions/BuildTargets"
53 PlatformHeader.BuildTargets = XmlElement(XmlFpd, XmlTag).split()
54
55 XmlTag = "PlatformSurfaceArea/PlatformDefinitions/IntermediateDirectories"
56 PlatformHeader.IntermediateDirectories = XmlElement(XmlFpd, XmlTag)
57
58 XmlTag = "PlatformSurfaceArea/PlatformDefinitions/OutputDirectory"
59 PlatformHeader.OutputDirectory = XmlElement(XmlFpd, XmlTag)
60
61 XmlTag = "PlatformSurfaceArea/PlatformDefinitions/SkuInfo"
62 List = map(LoadSkuId, XmlList(XmlFpd, XmlTag))
63 if List != []:
64 PlatformHeader.SkuIdName = List[0]
65
66 return PlatformHeader
67
68 ## Load a Platform SkuId
69 #
70 # Read an input Platform XML DOM object and return a list of Platform SkuId
71 # contained in the DOM object.
72 #
73 # @param XmlPlatformSkuInfo An XML DOM object read from FPD file
74 #
75 # @retvel PlatformSkuInfo A SkuInfo loaded from XmlFpd
76 #
77 def LoadPlatformSkuInfo(XmlPlatformSkuInfo):
78 XmlTag = "SkuInfo/SkuId"
79 SkuInfo = []
80 SkuId = XmlElement(XmlPlatformSkuInfo, XmlTag)
81 SkuInfo.append(SkuId)
82
83 XmlTag = "SkuInfo/Value"
84 Value = XmlElement(XmlPlatformSkuInfo, XmlTag)
85 SkuInfo.append(Value)
86 return SkuInfo
87
88 ## Load a Platform SkuId
89 #
90 # Read an input Platform XML DOM object and return a list of Platform SkuId
91 # contained in the DOM object.
92 #
93 # @param XmlSkuInfo An XML DOM object read from FPD file
94 #
95 # @retvel List A list of SkuId and SkuValue loaded from XmlFpd
96 #
97 def LoadSkuId(XmlSkuInfo):
98 XmlTag = "SkuInfo/UiSkuName"
99 SkuValue = XmlElement(XmlSkuInfo, XmlTag)
100
101 XmlTag = "SkuInfo/UiSkuName"
102 List = map(LoadSkuID, XmlList(XmlSkuInfo, XmlTag))
103 if List != []:
104 SkuID = List[0]
105 #SkuID = XmlAttribute(XmlSkuInfo, XmlTag)
106 List = []
107 List.append(SkuID)
108 List.append(SkuValue)
109 return List
110
111 def LoadSkuID(XmlUiSkuName):
112 XmlTag = "SkuID"
113 SkuID = XmlAttribute(XmlUiSkuName, XmlTag)
114 return SkuID
115
116 ## Load a list of Platform SkuIds
117 #
118 # Read an input Platform XML DOM object and return a list of Platform SkuId
119 # contained in the DOM object.
120 #
121 # @param XmlFpd An XML DOM object read from FPD file
122 #
123 # @retvel PlatformSkuIds A platform SkuIds object loaded from XmlFpd
124 #
125 def LoadPlatformSkuInfos(XmlFpd):
126 PlatformSkuIds = SkuInfoListClass()
127
128 SkuInfoList = []
129
130 XmlTag = "PlatformSurfaceArea/PlatformDefinitions/SkuInfo"
131 List = map(LoadSkuId, XmlList(XmlFpd, XmlTag))
132 SkuInfoList = List
133
134 XmlTag = "PlatformSurfaceArea/PlatformDefinitions/SkuInfo/UiSkuName"
135 Value = XmlElement(XmlFpd, XmlTag)
136
137 XmlTag = "PlatformSurfaceArea/DynamicPcdBuildDefinitions/PcdBuildData/SkuInfo"
138 # here return a List
139 List = map(LoadPlatformSkuInfo, XmlList(XmlFpd, XmlTag))
140
141 for SkuInfo in List:
142 SkuId = SkuInfo[0]
143 Value = SkuInfo[1]
144
145 SkuInfoList.append(SkuInfo)
146
147 PlatformSkuIds.SkuInfoList = SkuInfoList
148
149 return PlatformSkuIds
150
151 ## Load Platform Module Build Option
152 #
153 # Read an input Platform XML DOM object and return Platform Module Build Option class object
154 # contained in the DOM object.
155 #
156 # @param XmlModuleBuildOption An XML DOM object read from FPD file
157 #
158 # @retvel PlatformBuildOption A Platform Build Option object loaded from XmlFpd
159 #
160 def LoadModuleBuildOption(XmlModuleBuildOption):
161 PlatformBuildOption = PlatformBuildOptionClass()
162 PlatformBuildOption.UserDefinedAntTasks = {}
163
164 XmlTag = "BuildOptions/Options/Option"
165 PlatformBuildOption.Options = map(LoadBuildOption, XmlList(XmlModuleBuildOption, XmlTag))
166
167 PlatformBuildOption.UserExtensions = {}
168 PlatformBuildOption.FfsKeyList = {}
169 return PlatformBuildOption
170
171 ## Load Platform Module Extern
172 #
173 # Read an input Platform XML DOM object and return Platform Module Extern class object
174 # contained in the DOM object.
175 #
176 # @param XmlModuleExtern An XML DOM object read from FPD file
177 #
178 # @retvel PlatformModuleExtern A Platform Module Extern object loaded from XmlFpd
179 #
180 def LoadModuleExtern(XmlModuleExtern):
181 PlatformModuleExtern = []
182
183 XmlTag = "Externs/PcdIsDriver"
184 PcdIsDriver = XmlElement(XmlModuleExtern, XmlTag)
185 PlatformModuleExtern.append(PcdIsDriver)
186
187 XmlTag = "Externs/Specification"
188 Specification = XmlElement(XmlModuleExtern, XmlTag)
189 PlatformModuleExtern.append(Specification)
190
191 XmlTag = "Externs/Extern"
192
193 return PlatformModuleExtern
194
195 ## Load Platform ModuleSaBuildOptions
196 #
197 # Read an input Platform XML DOM object and return Platform ModuleSaBuildOptions class object
198 # contained in the DOM object.
199 #
200 # @param XmlModuleSaBuildOptions An XML DOM object read from FPD file
201 #
202 # @retvel PlatformBuildOptions A list of Platform ModuleSaBuildOption object loaded from XmlFpd
203 #
204 def LoadPlatformModuleSaBuildOption(XmlModuleSA):
205 PlatformModuleSaBuildOption = PlatformBuildOptionClasses()
206
207 XmlTag = "ModuleSA/ModuleSaBuildOptions/FvBinding"
208 PlatformModuleSaBuildOption.FvBinding = XmlElement(XmlModuleSA, XmlTag)
209
210 XmlTag = "ModuleSA/ModuleSaBuildOptions/FfsFormatKey"
211 PlatformModuleSaBuildOption.FfsFormatKey = XmlElement(XmlModuleSA, XmlTag)
212
213 XmlTag = "ModuleSA/ModuleSaBuildOptions/FfsFileNameGuid"
214 PlatformModuleSaBuildOption.FfsFileNameGuid = XmlElement(XmlModuleSA, XmlTag)
215
216 XmlTag = "ModuleSA/ModuleSaBuildOptions/Options/Option"
217 PlatformModuleSaBuildOption.BuildOptionList = map(LoadBuildOption, XmlList(XmlModuleSA, XmlTag))
218
219 return PlatformModuleSaBuildOption
220
221 ## Load a list of Platform Library Classes
222 #
223 # Read an input Platform XML DOM object and return a list of Library Classes
224 # contained in the DOM object.
225 #
226 # @param XmlLibraryInstance An XML DOM object read from FPD file
227 #
228 # @retvel LibraryInstance A Library Instance loaded from XmlFpd
229 #
230 def LoadPlatformModuleLibraryInstance(XmlLibraryInstance):
231 LibraryInstance = []
232
233 XmlTag = "ModuleGuid"
234 ModuleGuid = XmlAttribute(XmlLibraryInstance, XmlTag)
235
236 ModulePath = gEdkIIWorkspaceGuidsInfo.ResolveModuleFilePath(ModuleGuid)
237 ModuleMSAFile = ModulePath.replace('.inf', '.msa')
238 WorkSpace = os.getenv('WORKSPACE')
239 ModuleMSAFileName = os.path.join(WorkSpace, ModuleMSAFile)
240 XmlMsa = XmlParseFile(ModuleMSAFileName)
241
242 XmlTag = "ModuleSurfaceArea/LibraryClassDefinitions/LibraryClass/Keyword"
243 Name = XmlElement(XmlMsa, XmlTag)
244 LibraryInstance.append(Name)
245 LibraryInstance.append(ModulePath)
246
247 #XmlTag = "PackageGuid"
248 #PackageGuid = XmlAttribute(XmlLibraryInstance, XmlTag)
249 #LibraryInstance.append(PackageGuid)
250 return LibraryInstance
251
252 ## Load a Library Class
253 #
254 # Read an input Platform XML DOM object and return a library class object
255 # contained in the DOM object.
256 #
257 # @param XmlLibraryClass An XML DOM object read from FPD file
258 #
259 # @retvel SupModuleList A Library Class Supported Module List object loaded from XmlFpd
260 #
261 def LoadLibraryClassSupModuleList(XmlLibraryClass):
262 XmlTag = "Usage"
263 Usage = XmlAttribute(XmlLibraryClass, XmlTag)
264 if Usage == "ALWAYS_PRODUCED":
265 XmlTag = "SupModuleList"
266 SupModuleList = XmlAttribute(XmlLibraryClass, XmlTag).split()
267 return SupModuleList
268
269 ## Load Platform Library Class
270 #
271 # Read an input Platform XML DOM object and return Platform module class object
272 # contained in the DOM object.
273 #
274 # @param XmlLibraries An XML DOM object read from FPD file
275 #
276 # @retvel PlatformLibraryClass A Platform Library Class object loaded from XmlFpd
277 #
278 def LoadPlatformLibraryClass(XmlPlatformLibraryClass):
279 PlatformLibraryInstance = PlatformLibraryClass()
280
281 XmlTag = "ModuleGuid"
282 LibraryInstanceModuleGuid = XmlAttribute(XmlPlatformLibraryClass, XmlTag)
283
284 XmlTag = "PackageGuid"
285 LibraryInstancePackageGuid = XmlAttribute(XmlPlatformLibraryClass, XmlTag)
286
287 LibraryInstancePath = gEdkIIWorkspaceGuidsInfo.ResolveModuleFilePath(LibraryInstanceModuleGuid)
288
289 if LibraryInstancePath != "": # if LibraryInstancePath == "" that's because the module guid cannot be resolved
290 PlatformLibraryInstance.FilePath = LibraryInstancePath
291 # replace *.inf to *.msa
292 LibraryInstanceMSAName = LibraryInstancePath.replace('.inf', '.msa')
293 WorkSpace = os.getenv('WORKSPACE')
294 LibraryInstanceMSAPath = os.path.join(WorkSpace, LibraryInstanceMSAName)
295
296 PlatformLibraryInstance.FilePath = LibraryInstancePath
297
298 XmlMsa = XmlParseFile(LibraryInstanceMSAPath)
299
300 XmlTag = "ModuleSurfaceArea/MsaHeader/ModuleName"
301 PlatformLibraryInstance.Name = XmlElement(XmlMsa, XmlTag)
302
303 XmlTag = "ModuleSurfaceArea/MsaHeader/ModuleType"
304 PlatformLibraryInstance.ModuleType = XmlElement(XmlMsa, XmlTag)
305
306 if PlatformLibraryInstance.ModuleType != "BASE":
307 XmlTag = "ModuleSurfaceArea/LibraryClassDefinitions/LibraryClass"
308 List = map(LoadLibraryClassSupModuleList, XmlList(XmlMsa, XmlTag))
309 if List != []:
310 PlatformLibraryInstance.SupModuleList = List[0]
311 XmlTag = "ModuleSurfaceArea/ModuleDefinitions/SupportedArchitectures"
312 PlatformLibraryInstance.SupArchList = XmlElement(XmlMsa, XmlTag).split()
313
314 PlatformLibraryInstance.ModuleGuid = LibraryInstanceModuleGuid
315
316 XmlTag = "ModuleSurfaceArea/MsaHeader/Version"
317 PlatformLibraryInstance.ModuleVersion = XmlElement(XmlMsa, XmlTag)
318
319 PlatformLibraryInstance.PackageGuid = LibraryInstancePackageGuid
320 PlatformLibraryInstance.PackageVersion = ''
321
322 return PlatformLibraryInstance
323
324 ## Load Platform Library Classes
325 #
326 # Read an input Platform XML DOM object and return Platform module class object
327 # contained in the DOM object.
328 #
329 # @param XmlLibraries An XML DOM object read from FPD file
330 #
331 # @retvel PlatformLibraryClasses A list of Platform Library Class object loaded from XmlFpd
332 #
333 def LoadPlatformLibraryClasses(XmlFpd):
334 PlatformLibraryInstances = PlatformLibraryClasses()
335 PlatformLibraryInstances.LibraryList = []
336
337 List = []
338 XmlTag = "PlatformSurfaceArea/FrameworkModules/ModuleSA/Libraries/Instance"
339 List = map(LoadPlatformLibraryClass, XmlList(XmlFpd, XmlTag))
340 #List.sort()
341 if List == []:
342 print "Error"
343 else:
344 PlatformLibraryInstances.LibraryList = List
345
346 return PlatformLibraryInstances
347
348 ## Load Platform module
349 #
350 # Read an input Platform XML DOM object and return Platform module class object
351 # contained in the DOM object.
352 #
353 # @param XmlModuleSA An XML DOM object read from FPD file
354 #
355 # @retvel PlatformModule A Platform module object loaded from XmlFpd
356 #
357 def LoadModuleSA(XmlModuleSA):
358 PlatformModule = PlatformModuleClass()
359
360 # three parts: Libraries instances, PcdBuildDefinition, ModuleSaBuildOptions
361 XmlTag = "ModuleSA/Libraries/Instance"
362
363 PlatformModule.LibraryClasses = map(LoadPlatformModuleLibraryInstance, XmlList(XmlModuleSA, XmlTag))
364
365 XmlTag = "ModuleSA/PcdBuildDefinition/PcdData"
366 PlatformModule.PcdBuildDefinitions = map(LoadPlatformPcdData, XmlList(XmlModuleSA, XmlTag))
367
368 XmlTag = "ModuleSA/ModuleSaBuildOptions"
369 PlatformModule.ModuleSaBuildOption = LoadPlatformModuleSaBuildOption(XmlModuleSA)
370
371 XmlTag = "ModuleSA/BuildOptions"
372 PlatformModule.BuildOptions = map(LoadModuleBuildOption, XmlList(XmlModuleSA, XmlTag)) #bugbug fix me
373
374 XmlTag = "ModuleSA/Externs"
375 PlatformModule.Externs = map(LoadModuleExtern, XmlList(XmlModuleSA, XmlTag)) #bugbug fix me
376
377 XmlTag = "SupArchList"
378 PlatformModule.SupArchList = XmlAttribute(XmlModuleSA, XmlTag).split()
379
380 # the package guid which the module depends on, do not care for now
381 XmlTag = "PackageGuid"
382 PlatformModule.PackageGuid = XmlAttribute(XmlModuleSA, XmlTag)
383
384 # the module guid, use this guid to get the module *.msa file and convert it to *.inf file with path
385 XmlTag = "ModuleGuid"
386 PlatformModule.ModuleGuid = XmlAttribute(XmlModuleSA, XmlTag)
387 # use this guid to find the *.msa file path or FilePath $(WORKSPACE)/EdkModulePkg/Core/Dxe/DxeMain.msa
388 # then convert $(WORKSPACE)/EdkModulePkg/Core/Dxe/DxeMain.msa to $(WORKSPACE)/EdkModulePkg/Core/Dxe/DxeMain.inf, it's FilePath
389 PlatformModulePath = gEdkIIWorkspaceGuidsInfo.ResolveModuleFilePath(PlatformModule.ModuleGuid)
390
391 PlatformModule.FilePath = PlatformModulePath # *.inf file path
392 # *.inf back to *.msa
393 ModuleMSAFileName = PlatformModulePath.replace('.inf', '.msa')
394 WorkSpace = os.getenv('WORKSPACE')
395 ModuleMSAFileName = os.path.join(WorkSpace, ModuleMSAFileName)
396 # Open this module
397 #ModuleMSA = open(ModuleMSAFileName, "r")
398 XmlMsa = XmlParseFile(ModuleMSAFileName)
399
400 XmlTag = "ModuleSurfaceArea/MsaHeader/ModuleName"
401 PlatformModule.Name = XmlElement(XmlMsa, XmlTag) # ModuleName
402
403 XmlTag = "ModuleSurfaceArea/MsaHeader/ModuleType"
404 PlatformModule.ModuleType = XmlElement(XmlMsa, XmlTag)
405
406 # IA32, X64, IPF and EBC which the module support arch
407 #XmlTag = "ModuleSurfaceArea/ModuleDefinitions/SupportedArchitectures"
408 #PlatformModule.SupArchList = XmlElement(XmlMsa, XmlTag).split()
409
410 #XmlTag = "ModuleSurfaceArea/MsaHeader/"
411 PlatformModule.Type = '' #LIBRARY | LIBRARY_CLASS | MODULE, used by dsc. New in DSC spec
412
413 PlatformModule.ExecFilePath = '' # New in DSC spec
414
415 XmlTag = "ModuleSurfaceArea/MsaHeader/Specification"
416 PlatformModule.Specifications = XmlElement(XmlMsa, XmlTag).split()
417
418 return PlatformModule
419
420 ## Load Platform modules
421 #
422 # Read an input Platform XML DOM object and return a list of Platform modules class object
423 # contained in the DOM object.
424 #
425 # @param XmlFpd An XML DOM object read from FPD file
426 #
427 # @retvel PlatformModules A list of Platform modules object loaded from XmlFpd
428 #
429 def LoadPlatformModules(XmlFpd):
430 PlatformModules = PlatformModuleClasses()
431
432 XmlTag = "PlatformSurfaceArea/FrameworkModules/ModuleSA"
433 PlatformModules.ModuleList = map(LoadModuleSA, XmlList(XmlFpd, XmlTag))
434
435 return PlatformModules
436
437 ## Load Platform Flash Definition File
438 #
439 # Read an input Platform XML DOM object and return Platform Flash Definition File class object
440 # contained in the DOM object.
441 #
442 # @param XmlFpd An XML DOM object read from FPD file
443 # @param FpdFileName The file path of FPD File
444 #
445 # @retvel PlatformFlashDefinitionFile A new Platform Flash Definition File object loaded from XmlFpd
446 #
447 def LoadPlatformFlashDefinitionFile(XmlFpd, FpdFileName):
448 PlatformFlashDefinitionFile = PlatformFlashDefinitionFileClass()
449
450 XmlTag = "PlatformSurfaceArea/Flash/FlashDefinitionFile"
451 PlatformFlashDefinitionFile.FilePath = XmlElement(XmlFpd, XmlTag)
452
453 XmlTag = "PlatformSurfaceArea/Flash/FlashDefinitionFile/Id"
454 PlatformFlashDefinitionFile.Id = XmlAttribute(XmlFpd, XmlTag)
455
456 XmlTag = "PlatformSurfaceArea/Flash/FlashDefinitionFile/UiName"
457 PlatformFlashDefinitionFile.UiName = XmlAttribute(XmlFpd, XmlTag)
458
459 XmlTag = "PlatformSurfaceArea/Flash/FlashDefinitionFile/Preferred"
460 PlatformFlashDefinitionFile.Preferred = XmlAttribute(XmlFpd, XmlTag)
461
462 return PlatformFlashDefinitionFile
463
464 ## Load Platform User Defined Ant Tasks
465 #
466 # Read an input Platform XML DOM object and return platform
467 # User Defined Ant Tasks contained in the DOM object.
468 #
469 # @param XmlUserDefinedAntTasks An XML DOM object read from FPD file
470 #
471 # @retvel AntTask An Ant Task loaded from XmlFpd
472 #
473 def LoadUserDefinedAntTasks(XmlFpd):
474 Dict = {}
475 AntTask = PlatformAntTaskClass()
476
477 XmlTag = "PlatformSurfaceArea/BuildOptions/UserDefinedAntTasks/AntTask/Id"
478 AntTask.Id = XmlAttribute(XmlFpd, XmlTag)
479
480 XmlTag = "PlatformSurfaceArea/BuildOptions/UserDefinedAntTasks/AntTask/AntCmdOptions"
481 AntTask.AntCmdOptions = XmlElement(XmlFpd, XmlTag)
482
483 XmlTag = "PlatformSurfaceArea/BuildOptions/UserDefinedAntTasks/AntTask/Filename"
484 AntTask.FilePath = XmlElement(XmlFpd, XmlTag)
485
486 Dict[AntTask.Id] = AntTask
487 return Dict
488
489 ## Load Platform Build Options
490 #
491 # Read an input Platform XML DOM object and return a list of platform
492 # Build Option contained in the DOM object.
493 #
494 # @param XmlBuildOptions An XML DOM object read from FPD file
495 #
496 # @retvel PlatformBuildOptions A list of platform Build Options loaded from XmlFpd
497 #
498 def LoadBuildOptions(XmlBuildOptions):
499 XmlTag = "Option"
500 return map(LoadBuildOption, XmlList(XmlBuildOptions, XmlTag)) # LoadBuildOption is a method in MigrationUtilities.py
501
502 ## Load Platform Build Option
503 #
504 # Read an input Platform XML DOM object and return a Build Option
505 # contained in the DOM object.
506 #
507 # @param XmlFpd An XML DOM object read from FPD file
508 #
509 # @retvel PlatformBuildOption A Build Options loaded from XmlFpd
510 #
511 def LoadPlatformBuildOption(XmlBuildOptions):
512 PlatformBuildOption = PlatformBuildOptionClass()
513
514 # handle UserDefinedAntTasks
515 XmlTag = "BuildOptions/UserDefinedAntTasks/AntTask"
516 PlatformBuildOption.UserDefinedAntTasks = LoadUserDefinedAntTasks(XmlTag)
517
518 # handle Options
519 XmlTag = "BuildOptions/Options/Option"
520 PlatformBuildOption.Options = map(LoadBuildOption, XmlList(XmlBuildOptions, XmlTag))
521
522 # handle UserExtensions
523 XmlTag = "BuildOptions/UserExtensions"
524 PlatformBuildOption.UserExtensions = LoadUserExtensions(XmlTag) # from MigrationUtilities.py LoadUserExtensions
525
526 # handle Ffs
527 XmlTag = "BuildOptions/Ffs/FfsKey"
528 PlatformBuildOption.FfsKeyList = map(LoadPlatformFfs, XmlList(XmlBuildOptions, XmlTag))
529
530 return PlatformBuildOption
531
532 ## Load Platform Ffs Dictionary
533 #
534 # Read an input Platform XML DOM object and return a platform Ffs Dictionary
535 # contained in the DOM object.
536 #
537 # @param XmlFpd An XML DOM object read from FPD file
538 #
539 # @retvel Dict A platform Ffs Dict loaded from XmlFpd
540 #
541 def LoadPlatformFfsDict(XmlFpd):
542 Dict = {}
543 XmlTag = "PlatformSurfaceArea/BuildOptions/Ffs"
544 List = map(LoadPlatformFfs, XmlList(XmlFpd, XmlTag))
545 if List != []:
546 for Ffs in List:
547 Dict[Ffs.Key] = Ffs
548 return Dict
549
550 ## Load Platform Ffs Section
551 #
552 # Read an input Platform XML DOM object and return a platform Ffs Section
553 # contained in the DOM object.
554 #
555 # @param XmlFfs An XML DOM object read from FPD file
556 #
557 # @retvel PlatformFfsSection A platform Ffs Section loaded from XmlFpd
558 #
559 def LoadPlatformFfsSection(XmlFfsSection):
560 PlatformFfsSection = PlatformFfsSectionClass()
561
562 XmlTag = ""
563 PlatformFfsSection.BindingOrder = ''
564
565 XmlTag = ""
566 PlatformFfsSection.Compressible = ''
567
568 XmlTag = "SectionType"
569 PlatformFfsSection.SectionType = XmlAttribute(XmlFfsSection, XmlTag)
570
571 XmlTag = ""
572 PlatformFfsSection.EncapsulationType = ''
573
574 XmlTag = ""
575 PlatformFfsSection.ToolName = ''
576
577 XmlTag = ""
578 PlatformFfsSection.Filenames = []
579
580 XmlTag = ""
581 PlatformFfsSection.Args = ''
582
583 XmlTag = ""
584 PlatformFfsSection.OutFile = ''
585
586 XmlTag = ""
587 PlatformFfsSection.OutputFileExtension = ''
588
589 XmlTag = ""
590 PlatformFfsSection.ToolNameElement = ''
591
592 return PlatformFfsSection
593
594 ## Load Platform Ffs Sections
595 #
596 # Read an input Platform XML DOM object and return a platform Ffs Sections
597 # contained in the DOM object.
598 #
599 # @param XmlFfs An XML DOM object read from FPD file
600 #
601 # @retvel PlatformFfsSections A platform Ffs Sections loaded from XmlFpd
602 #
603 def LoadFfsSections():
604 PlatformFfsSections = PlatformFfsSectionsClass()
605 PlatformFfsSections.BindingOrder = ''
606 PlatformFfsSections.Compressible = ''
607 PlatformFfsSections.SectionType = ''
608 PlatformFfsSections.EncapsulationType = ''
609 PlatformFfsSections.ToolName = ''
610 PlatformFfsSections.Section = []
611 PlatformFfsSections.Sections = []
612
613 return PlatformFfsSections
614
615 ## Load Platform Ffs Sections
616 #
617 # Read an input Platform XML DOM object and return a platform Ffs Sections
618 # contained in the DOM object.
619 #
620 # @param XmlFfs An XML DOM object read from FPD file
621 #
622 # @retvel PlatformFfsSections A platform Ffs Sections loaded from XmlFpd
623 #
624 def LoadPlatformFfsSections(XmlFfsSections):
625 PlatformFfsSections = PlatformFfsSectionsClass()
626
627 XmlTag = ""
628 PlatformFfsSections.BindingOrder = ''
629
630 XmlTag = ""
631 Compressible = ''
632
633 XmlTag = ""
634 SectionType = ''
635
636 XmlTag = "EncapsulationType"
637 EncapsulationType = XmlAttribute(XmlFfsSections, XmlTag)
638
639 XmlTag = ""
640 ToolName = ''
641
642 XmlTag = "Sections/Section"
643 Section = [] #[ PlatformFfsSectionClass, ... ]
644 Section = map(LoadPlatformFfsSection, XmlList(XmlFfsSections, XmlTag))
645
646
647 XmlTag = "Sections/Sections"
648 Sections = map(LoadFfsSections, XmlList(XmlFfsSections, XmlTag)) #[ PlatformFfsSectionsClass, ...]
649
650 return PlatformFfsSections
651
652 ## Load Platform Ffs Attribute
653 #
654 # Read an input Platform XML DOM object and return a platform Ffs Attribute
655 # contained in the DOM object.
656 #
657 # @param XmlFfs An XML DOM object read from FPD file
658 #
659 # @retvel List A platform Ffs Attribute loaded from XmlFpd
660 #
661 def LoadFfsAttribute(XmlFfs):
662 List = []
663 XmlTag = "Ffs/Attribute"
664 for XmlAttr in XmlList(XmlFfs, XmlTag):
665 XmlTag = "Name"
666 Name = XmlAttribute(XmlAttr, XmlTag)
667 XmlTag = "Value"
668 Value = XmlAttribute(XmlAttr, XmlTag)
669 List.append([Name,Value])
670 return List
671
672 ## Load a list of Platform Build Options
673 #
674 # Read an input Platform XML DOM object and return a list of Build Options
675 # contained in the DOM object.
676 #
677 # @param XmlFfs An XML DOM object read from FPD file
678 #
679 # @retvel PlatformFfsKey A platform Ffs key loaded from XmlFpd
680 #
681 def LoadPlatformFfs(XmlFfs):
682 PlatformFfs = PlatformFfsClass()
683
684 PlatformFfs.Attribute = {}
685 Dict = {}
686
687 List = LoadFfsAttribute(XmlFfs)
688
689 XmlTag = "Ffs/Sections/Sections"
690 PlatformFfs.Sections = map(LoadPlatformFfsSections, XmlList(XmlFfs, XmlTag)) #[PlatformFfsSectionsClass, ...]
691
692 for Item in List:
693 Name = Item[0]
694 Value = Item[1]
695 for Item in PlatformFfs.Sections:
696 Dict[(Name, Item)] = Value
697 PlatformFfs.Attribute = Dict
698
699 XmlTag = "Ffs/FfsKey"
700 PlatformFfs.Key = XmlAttribute(XmlFfs, XmlTag)
701
702 return PlatformFfs
703
704 ## Load a list of Platform Build Options
705 #
706 # Read an input Platform XML DOM object and return a list of Build Options
707 # contained in the DOM object.
708 #
709 # @param XmlFpd An XML DOM object read from FPD file
710 #
711 # @retvel PlatformBuildOptions A list of Build Options loaded from XmlFpd
712 #
713 def LoadPlatformBuildOptions(XmlFpd):
714 PlatformBuildOptions = PlatformBuildOptionClass()
715
716 PlatformBuildOptions.UserDefinedAntTasks = LoadUserDefinedAntTasks(XmlFpd)
717
718 XmlTag = "PlatformSurfaceArea/BuildOptions/Options/Option"
719 PlatformBuildOptions.Options = map(LoadBuildOption, XmlList(XmlFpd, XmlTag))
720
721 PlatformBuildOptions.UserExtensions = LoadPlatformUserExtension(XmlFpd)
722
723 PlatformBuildOptions.FfsKeyList = LoadPlatformFfsDict(XmlFpd)
724
725 return PlatformBuildOptions
726
727 ## Load Platform Pcd Data
728 #
729 # Read an input Platform XML DOM object and return Platform module class object
730 # contained in the DOM object.
731 #
732 # @param XmlPcd An XML DOM object read from FPD file
733 #
734 # @retvel PlatformPcdData A Platform Pcd object loaded from XmlFpd
735 #
736 def LoadPlatformPcdData(XmlPcdData):
737 PcdData = PcdClass() # defined in CommonDataClass.CommonClass.py
738
739 XmlTag = "ItemType"
740 PcdData.ItemType = XmlAttribute(XmlPcdData, XmlTag) #DYNAMIC
741
742 XmlTag = "PcdData/C_Name"
743 PcdData.C_NAME = XmlElement(XmlPcdData, XmlTag)
744
745 XmlTag = "PcdData/Token"
746 PcdData.Token = XmlElement(XmlPcdData, XmlTag)
747
748 XmlTag = "PcdData/TokenSpaceGuidCName"
749 PcdData.TokenSpaceGuidCName = XmlElement(XmlPcdData, XmlTag)
750
751 XmlTag = "PcdData/DatumType"
752 PcdData.DatumType = XmlElement(XmlPcdData, XmlTag)
753
754 XmlTag = "PcdData/MaxDatumSize"
755 PcdData.MaxDatumSize = XmlElement(XmlPcdData, XmlTag)
756
757 XmlTag = "PcdData/Value"
758 PcdData.Value = XmlElement(XmlPcdData, XmlTag)
759
760 return PcdData
761
762 ## Load a Platform Pcd Build Data
763 #
764 # Read an input Platform XML DOM object and return a list of Pcd Dynamic
765 # contained in the DOM object.
766 #
767 # @param XmlPcdBuildData An XML DOM object read from FPD file
768 #
769 # @retvel PcdBuildData A Platform Pcd Build Data loaded from XmlFpd
770 #
771 def LoadPlatformPcdBuildData(XmlPcdBuildData):
772 PcdBuildData = PcdClass() # defined in CommonDataClass.CommonClass.py
773
774 XmlTag = "ItemType"
775 PcdBuildData.ItemType = XmlAttribute(XmlPcdBuildData, XmlTag) #DYNAMIC
776
777 XmlTag = "PcdBuildData/C_Name"
778 PcdBuildData.C_NAME = XmlElement(XmlPcdBuildData, XmlTag)
779
780 XmlTag = "PcdBuildData/Token"
781 PcdBuildData.Token = XmlElement(XmlPcdBuildData, XmlTag)
782
783 XmlTag = "PcdBuildData/TokenSpaceGuidCName"
784 PcdBuildData.TokenSpaceGuidCName = XmlElement(XmlPcdBuildData, XmlTag)
785
786 XmlTag = "PcdBuildData/DatumType"
787 PcdBuildData.DatumType = XmlElement(XmlPcdBuildData, XmlTag)
788
789 XmlTag = "PcdBuildData/MaxDatumSize"
790 PcdBuildData.MaxDatumSize = XmlElement(XmlPcdBuildData, XmlTag)
791
792 #XmlTag = "PcdBuildData/Value"
793 #PcdBuildData.Value = XmlElement(XmlPcdBuildData, XmlTag)
794
795 return PcdBuildData
796
797 ## Load a list of Platform Pcd Dynamic
798 #
799 # Read an input Platform XML DOM object and return a list of Pcd Dynamic
800 # contained in the DOM object.
801 #
802 # @param XmlFpd An XML DOM object read from FPD file
803 #
804 # @retvel PcdDynamic A list of Pcd Dynamic loaded from XmlFpd
805 #
806 def LoadDynamicPcdBuildDefinitions(XmlFpd):
807 DynamicPcdBuildDefinitions = []
808 XmlTag = "PlatformSurfaceArea/DynamicPcdBuildDefinitions/PcdBuildData"
809 return map(LoadPlatformPcdBuildData, XmlList(XmlFpd, XmlTag))
810
811 ## Load a Platform NameValue object
812 #
813 # Read an input Platform XML DOM object and return a list of User Extensions
814 # contained in the DOM object.
815 #
816 # @param XmlNameValue An XML DOM object read from FPD file
817 #
818 # @retvel NameValue A Platform NameValue object
819 #
820 def LoadNameValue(XmlNameValue):
821 NameValue = []
822
823 XmlTag = "Name"
824 Name = XmlAttribute(XmlNameValue, XmlTag)
825 NameValue.append(Name)
826
827 XmlTag = "Value"
828 Value = XmlAttribute(XmlNameValue, XmlTag)
829 NameValue.append(Value)
830
831 return NameValue
832
833 ## Load a Platform Fv Image Name object
834 #
835 # Read an input Platform XML DOM object and return a platform Fv Image
836 # Name contained in the DOM object.
837 #
838 # @param XmlFvImageNames An XML DOM object read from FPD file
839 #
840 # @retvel FvImageNames A Platform Fv Image Name object
841 #
842 def LoadFvImageNames(XmlFvImageNames):
843 XmlTag = "FvImageNames"
844 FvImageNames = XmlElement(XmlFvImageNames, XmlTag)
845 return FvImageNames
846
847 ## Load a Platform Fv Image option object
848 #
849 # Read an input Platform XML DOM object and return a platform Fv Image
850 # Option contained in the DOM object.
851 #
852 # @param XmlFvImageOptions An XML DOM object read from FPD file
853 #
854 # @retvel PlatformFvImageOption A Platform Fv Image Option object
855 #
856 def LoadFvImageOptions(XmlFvImageOptions):
857 PlatformFvImageOption = PlatformFvImageOptionClass()
858
859 XmlTag = ""
860 PlatformFvImageOption.FvImageOptionName = ''
861
862 XmlTag = ""
863 PlatformFvImageOption.FvImageOptionValues = []
864
865 XmlTag = "FvImageOptions/NameValue"
866 List = map(LoadNameValue, XmlList(XmlFvImageOptions, XmlTag))
867
868 return PlatformFvImageOption
869
870 ## Load a Platform Fv Image object
871 #
872 # Read an input Platform XML DOM object and return a list of User Extensions
873 # contained in the DOM object.
874 #
875 # @param XmlFvImage An XML DOM object read from Fpd file
876 #
877 # @retvel PlatformFvImage A Platform Fv Image object
878 #
879 def LoadPlatformFvImage(XmlFvImage):
880 PlatformFvImage = PlatformFvImageClass()
881
882 XmlTag = "Name"
883 PlatformFvImage.Name = XmlAttribute(XmlFvImage, XmlTag)
884
885 XmlTag = "Value"
886 PlatformFvImage.Value = XmlAttribute(XmlFvImage, XmlTag)
887
888 XmlTag = "Type"
889 PlatformFvImage.Type = XmlAttribute(XmlFvImage, XmlTag)
890
891 XmlTag = "FvImage/FvImageNames"
892 PlatformFvImage.FvImageNames = map(LoadFvImageNames, XmlList(XmlFvImage, XmlTag))
893
894 XmlTag = "FvImage/FvImageOptions"
895 PlatformFvImage.FvImageOptions = map(LoadFvImageOptions, XmlList(XmlFvImage, XmlTag))
896
897 return PlatformFvImage
898
899 ## Load a Platform fdf object
900 #
901 # Read an input Platform XML DOM object and return a list of User Extensions
902 # contained in the DOM object.
903 #
904 # @param XmlFvImages An XML DOM object read from FPD file
905 #
906 # @retvel PlatformFdf A Platform fdf object
907 #
908 def LoadPlatformFvImages(XmlFvImages):
909 List = []
910
911 XmlTag = "FvImages/NameValue"
912 NameValues = map(LoadNameValue, XmlList(XmlFvImages, XmlTag))
913 List.append(NameValues)
914
915 XmlTag = "FvImages/FvImage"
916 FvImages = map(LoadPlatformFvImage, XmlList(XmlFvImages, XmlTag))
917 List.append(FvImages)
918
919 XmlTag = "FvImages/FvImageName"
920 FvImageNames = map(LoadPlatformFvImageName, XmlList(XmlFvImages, XmlTag))
921 List.append(FvImageNames)
922
923 return List
924
925 ## Load a Platform Fv Image Name object
926 #
927 # Read an input Platform XML DOM object and return a list of User Extensions
928 # contained in the DOM object.
929 #
930 # @param XmlFvImageName An XML DOM object read from FPD file
931 #
932 # @retvel PlatformFvImageName A Platform Fv Image Name object
933 #
934 def LoadPlatformFvImageName(XmlFvImageName):
935 PlatformFvImageName = PlatformFvImageNameClass()
936
937 XmlTag = "Name"
938 PlatformFvImageName.Name = XmlAttribute(XmlFvImageName, XmlTag)
939
940 XmlTag = "Type"
941 PlatformFvImageName.Type = XmlAttribute(XmlFvImageName, XmlTag)
942
943 XmlTag = "FvImageOptions"
944 PlatformFvImageName.FvImageOptions = map(LoadFvImageOptions, XmlList(XmlFvImageName, XmlTag))
945
946 return PlatformFvImageName
947
948 ## Load a list of Platform fdf objects
949 #
950 # Read an input Platform XML DOM object and return a list of User Extensions
951 # contained in the DOM object.
952 #
953 # @param XmlFpd An XML DOM object read from FPD file
954 #
955 # @retvel PlatformFdfs A list of Platform fdf object
956 #
957 def LoadPlatformFdfs(XmlFpd):
958 PlatformFvImages = PlatformFvImagesClass()
959
960 XmlTag = "PlatformSurfaceArea/Flash/FvImages"
961 PlatformFvImages.FvImages = map(LoadPlatformFvImages, XmlList(XmlFpd, XmlTag))
962
963 return PlatformFvImages
964
965 ## Load a Platform User Extensions
966 #
967 # Read an input Platform XML DOM object and return an User Extension
968 # contained in the DOM object.
969 #
970 # @param XmlUserExtension An XML DOM object read from FPD file
971 #
972 # @retvel PlatformUserExtensions A platform User Extension loaded from XmlFpd
973 #
974 def LoadPlatformUserExtension(XmlFpd):
975 Dict = {}
976
977 PlatformUserExtensions = UserExtensionsClass()
978
979 XmlTag = "PlatformSurfaceArea/BuildOptions/UserExtensions"
980 List = map(LoadUserExtensions, XmlList(XmlFpd, XmlTag))
981 if List != []:
982 for Item in List:
983 UserID = Item.UserID
984 Identifier = Item.Identifier
985 Dict[(UserID, Identifier)] = Item
986 #XmlTag = "PlatformSurfaceArea/BuildOptions/UserExtensions/UserID"
987 #PlatformUserExtensions.UserID = XmlAttribute(XmlFpd, XmlTag)
988
989 #XmlTag = "PlatformSurfaceArea/BuildOptions/UserExtensions/Identifier"
990 #PlatformUserExtensions.Identifier = XmlAttribute(XmlFpd, XmlTag)
991
992 #PlatformUserExtensions.Content = XmlElementData(XmlFpd)
993 #Dict[(PlatformUserExtensions.UserID,PlatformUserExtensions.Identifier)] = PlatformUserExtensions
994 #return PlatformUserExtensions
995 return Dict
996
997 ## Load a list of Platform User Extensions
998 #
999 # Read an input Platform XML DOM object and return a list of User Extensions
1000 # contained in the DOM object.
1001 #
1002 # @param XmlFpd An XML DOM object read from FPD file
1003 #
1004 # @retvel UserExtensions A list of platform User Extensions loaded from XmlFpd
1005 #
1006 def LoadPlatformUserExtensions(XmlFpd):
1007 XmlTag = "PlatformSurfaceArea/UserExtensions"
1008 return map(LoadUserExtensions, XmlList(XmlFpd, XmlTag)) # from MigrationUtilities.py LoadUserExtensions
1009
1010 ## Load a new Platform class object
1011 #
1012 # Read an input FPD File and return a new Platform class Object.
1013 #
1014 # @param FpdFileName An XML DOM object read from FPD file
1015 #
1016 # @retvel Platform A new Platform class object loaded from FPD File
1017 #
1018 def LoadFpd(FpdFileName):
1019 XmlFpd = XmlParseFile(FpdFileName)
1020 EdkLogger.verbose("Load FPD File: %s" % FpdFileName)
1021
1022 Platform = PlatformClass()
1023 Platform.Header = LoadPlatformHeader(XmlFpd, FpdFileName)
1024 Platform.SkuInfos = LoadPlatformSkuInfos(XmlFpd)
1025 Platform.Libraries = [] #New in dsc spec, do not handle for now
1026 Platform.LibraryClasses = LoadPlatformLibraryClasses(XmlFpd)
1027 Platform.Modules = LoadPlatformModules(XmlFpd)
1028 Platform.FlashDefinitionFile = LoadPlatformFlashDefinitionFile(XmlFpd, FpdFileName)
1029 Platform.BuildOptions = LoadPlatformBuildOptions(XmlFpd)
1030 Platform.DynamicPcdBuildDefinitions = LoadDynamicPcdBuildDefinitions(XmlFpd)
1031 Platform.Fdf = LoadPlatformFdfs(XmlFpd)
1032 Platform.UserExtensions = LoadPlatformUserExtensions(XmlFpd)
1033
1034 return Platform
1035
1036 # This acts like the main() function for the script, unless it is 'import'ed
1037 # into another script.
1038 if __name__ == '__main__':
1039 pass