2 Java class FpdFileContents is used to parse fpd xml file.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. 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
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.
13 package org
.tianocore
.frameworkwizard
.platform
.ui
;
16 import java
.io
.IOException
;
17 import java
.math
.BigInteger
;
18 import java
.util
.ArrayList
;
19 import java
.util
.HashMap
;
20 import java
.util
.Iterator
;
21 import java
.util
.LinkedHashMap
;
22 import java
.util
.List
;
23 import java
.util
.ListIterator
;
27 import javax
.xml
.namespace
.QName
;
29 import org
.apache
.xmlbeans
.XmlCursor
;
30 import org
.apache
.xmlbeans
.XmlObject
;
31 import org
.apache
.xmlbeans
.XmlOptions
;
32 import org
.tianocore
.AntTaskDocument
;
33 import org
.tianocore
.BuildOptionsDocument
;
34 import org
.tianocore
.DynamicPcdBuildDefinitionsDocument
;
35 import org
.tianocore
.EfiSectionType
;
36 import org
.tianocore
.FlashDefinitionFileDocument
;
37 import org
.tianocore
.FlashDocument
;
38 import org
.tianocore
.FrameworkModulesDocument
;
39 import org
.tianocore
.LibrariesDocument
;
40 import org
.tianocore
.ModuleSADocument
;
41 import org
.tianocore
.ModuleSurfaceAreaDocument
;
42 import org
.tianocore
.OptionDocument
;
43 import org
.tianocore
.OptionsDocument
;
44 import org
.tianocore
.PcdBuildDefinitionDocument
;
45 import org
.tianocore
.PcdCodedDocument
;
46 import org
.tianocore
.PcdDataTypes
;
47 import org
.tianocore
.PcdDeclarationsDocument
;
48 import org
.tianocore
.PcdItemTypes
;
49 import org
.tianocore
.PlatformDefinitionsDocument
;
50 import org
.tianocore
.PlatformSurfaceAreaDocument
;
51 import org
.tianocore
.FvImageTypes
;
52 import org
.tianocore
.FvImagesDocument
;
53 import org
.tianocore
.LicenseDocument
;
54 import org
.tianocore
.PlatformHeaderDocument
;
55 import org
.tianocore
.SkuInfoDocument
;
56 import org
.tianocore
.UserDefinedAntTasksDocument
;
57 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.GlobalData
;
58 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.SurfaceAreaQuery
;
59 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.ModuleIdentification
;
60 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PackageIdentification
;
63 This class processes fpd file contents such as add remove xml elements.
64 @since PackageEditor 1.0
66 public class FpdFileContents
{
68 static final String xmlNs
= "http://www.TianoCore.org/2006/Edk2.0";
70 private PlatformSurfaceAreaDocument fpdd
= null;
72 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
74 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
76 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
78 private FlashDocument
.Flash fpdFlash
= null;
80 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
82 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
84 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
86 public static HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
89 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
91 public void initDynPcdMap() {
92 if (dynPcdMap
== null) {
93 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
94 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
98 ListIterator
<ModuleSADocument
.ModuleSA
> li
= l
.listIterator();
99 while (li
.hasNext()) {
100 ModuleSADocument
.ModuleSA msa
= li
.next();
101 if (msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null) {
104 String ModuleInfo
= msa
.getModuleGuid() + " " + msa
.getModuleVersion() +
105 " " + msa
.getPackageGuid() + " " + msa
.getPackageVersion();
106 List
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lp
= msa
.getPcdBuildDefinition().getPcdDataList();
107 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lpi
= lp
.listIterator();
108 while (lpi
.hasNext()) {
109 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= lpi
.next();
110 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
111 if (dynPcdMap
.get(pcdKey
) == null) {
112 ArrayList
<String
> al
= new ArrayList
<String
>();
113 al
.add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
114 dynPcdMap
.put(pcdKey
, al
);
117 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
124 Constructor to create a new spd file
126 public FpdFileContents() {
128 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
129 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
134 Constructor for existing document object
137 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
139 fpdHdr
= fpdRoot
.getPlatformHeader();
140 fpdPlatformDefs
= fpdRoot
.getPlatformDefinitions();
141 fpdBuildOpts
= fpdRoot
.getBuildOptions();
142 fpdFrameworkModules
= fpdRoot
.getFrameworkModules();
143 fpdDynPcdBuildDefs
= fpdRoot
.getDynamicPcdBuildDefinitions();
144 fpdFlash
= fpdRoot
.getFlash();
148 Constructor based on an existing spd file
150 @param f Existing spd file
152 public FpdFileContents(File f
) {
154 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
155 fpdRoot
= fpdd
.getPlatformSurfaceArea();
156 } catch (Exception e
) {
157 System
.out
.println(e
.toString());
161 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
162 if (fpdDynPcdBuildDefs
== null){
163 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
165 return fpdDynPcdBuildDefs
;
168 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
169 if (fpdFrameworkModules
== null){
170 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
172 return fpdFrameworkModules
;
175 public int getPlatformDefsSkuInfoCount(){
176 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
179 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
182 public void getPlatformDefsSkuInfos(String
[][] saa
){
183 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
187 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
188 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
190 while(li
.hasNext()) {
191 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
192 saa
[i
][0] = sku
.getSkuID()+"";
193 saa
[i
][1] = sku
.getStringValue();
198 public int getFrameworkModulesCount() {
199 if (getfpdFrameworkModules().getModuleSAList() == null){
202 return getfpdFrameworkModules().getModuleSAList().size();
205 public void getFrameworkModulesInfo(String
[][] saa
) {
206 if (getFrameworkModulesCount() == 0){
210 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
212 while(li
.hasNext()) {
213 ModuleSADocument
.ModuleSA msa
= (ModuleSADocument
.ModuleSA
)li
.next();
214 saa
[i
][1] = msa
.getModuleGuid();
215 saa
[i
][2] = msa
.getModuleVersion();
217 saa
[i
][3] = msa
.getPackageGuid();
218 saa
[i
][4] = msa
.getPackageVersion();
219 // saa[i][4] = listToString(msa.getSupArchList());
224 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
225 String
[] s
= key
.split(" ");
226 if (getfpdFrameworkModules().getModuleSAList() == null) {
229 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
230 while(li
.hasNext()) {
231 ModuleSADocument
.ModuleSA msa
= (ModuleSADocument
.ModuleSA
)li
.next();
232 if (msa
.getModuleGuid().equals(s
[0]) && msa
.getModuleVersion().equals(s
[1])
233 && msa
.getPackageGuid().equals(s
[2]) && msa
.getPackageVersion().equals(s
[3])) {
240 public void removeModuleSA(int i
) {
241 XmlObject o
= getfpdFrameworkModules();
246 XmlCursor cursor
= o
.newCursor();
247 if (cursor
.toFirstChild()) {
248 for (int j
= 0; j
< i
; ++j
) {
249 cursor
.toNextSibling();
252 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
254 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
255 String moduleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() + " " +
256 moduleSa
.getPackageGuid()+ " " + moduleSa
.getPackageVersion();
257 PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
= moduleSa
.getPcdBuildDefinition();
258 if (pcdBuildDef
!= null) {
259 maintainDynPcdMap(pcdBuildDef
, moduleInfo
);
266 private void maintainDynPcdMap(PcdBuildDefinitionDocument
.PcdBuildDefinition o
, String moduleInfo
) {
267 XmlCursor cursor
= o
.newCursor();
268 boolean fromLibInstance
= false;
269 if (!cursor
.toFirstChild()){
273 // deal with first child, same process in the while loop below for siblings.
275 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
276 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
277 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
278 for(int i
= 0; i
< al
.size(); ++i
){
279 if (al
.get(i
).startsWith(moduleInfo
)){
280 fromLibInstance
= true;
284 al
.remove(moduleInfo
+ " " + pcdData
.getItemType().toString());
285 if (al
.size() == 0) {
286 dynPcdMap
.remove(pcdKey
);
289 if (pcdData
.getItemType().toString().equals("DYNAMIC")) {
290 if (dynPcdMap
.get(pcdKey
) == null) {
291 removeDynamicPcdBuildData(pcdData
.getCName(), pcdData
.getTokenSpaceGuidCName());
294 if (fromLibInstance
){
297 while(cursor
.toNextSibling()) {
298 fromLibInstance
= false;
299 pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
301 // remove each pcd record from dynPcdMap
303 pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
304 al
= dynPcdMap
.get(pcdKey
);
305 for(int i
= 0; i
< al
.size(); ++i
){
306 if (al
.get(i
).startsWith(moduleInfo
)){
307 fromLibInstance
= true;
311 al
.remove(moduleInfo
+ " " + pcdData
.getItemType().toString());
312 if (al
.size() == 0) {
313 dynPcdMap
.remove(pcdKey
);
316 if (pcdData
.getItemType().toString().equals("DYNAMIC")) {
318 // First check whether this is the only consumer of this dyn pcd.
320 if (dynPcdMap
.get(pcdKey
) == null) {
322 // delete corresponding entry in DynamicPcdBuildData
324 removeDynamicPcdBuildData(pcdData
.getCName(), pcdData
.getTokenSpaceGuidCName());
327 if (fromLibInstance
){
333 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
335 public int getPcdDataCount(String key
){
336 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
337 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
340 return msa
.getPcdBuildDefinition().getPcdDataList().size();
343 public void getPcdData(String key
, String
[][] saa
) {
344 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
345 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
348 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
349 for (int i
= 0; i
< saa
.length
; ++i
) {
350 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
351 saa
[i
][0] = pcdData
.getCName();
352 saa
[i
][1] = pcdData
.getTokenSpaceGuidCName();
353 saa
[i
][2] = pcdData
.getItemType().toString();
354 saa
[i
][3] = pcdData
.getToken().toString();
355 saa
[i
][4] = pcdData
.getDatumType().toString();
356 saa
[i
][5] = pcdData
.getValue();
361 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
363 public int getLibraryInstancesCount(String key
) {
364 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
365 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
368 return msa
.getLibraries().getInstanceList().size();
371 public void getLibraryInstances(String key
, String
[][] saa
){
372 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
373 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
377 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
378 for (int i
= 0; i
< saa
.length
; ++i
) {
379 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
380 saa
[i
][1] = instance
.getModuleGuid();
381 saa
[i
][2] = instance
.getModuleVersion();
382 saa
[i
][3] = instance
.getPackageGuid();
383 saa
[i
][4] = instance
.getPackageVersion();
387 public void removeLibraryInstances(String key
) {
388 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
389 if (msa
== null || msa
.getLibraries() == null){
393 XmlCursor cursor
= msa
.getLibraries().newCursor();
398 public void genLibraryInstance(String mg
, String mv
, String pg
, String pv
, String key
) {
399 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
401 msa
= getfpdFrameworkModules().addNewModuleSA();
403 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
405 libs
= msa
.addNewLibraries();
408 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
409 instance
.setModuleGuid(mg
);
410 instance
.setModuleVersion(mv
);
411 instance
.setPackageGuid(pg
);
412 instance
.setPackageVersion(pv
);
415 /**add pcd information of module mi to a ModuleSA.
417 * @param moduleSa if null, generate a new ModuleSA.
419 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, ModuleSADocument
.ModuleSA moduleSa
){
420 //ToDo add Arch filter
423 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)GlobalData
.getModuleXmlObject(mi
);
424 if (msa
.getPcdCoded() == null) {
427 if (moduleSa
== null) {
428 moduleSa
= genModuleSA(mi
);
430 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
431 m
.put("ModuleSurfaceArea", msa
);
432 SurfaceAreaQuery
.setDoc(m
);
433 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null);
435 // Implementing InitializePlatformPcdBuildDefinitions
437 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
438 ListIterator li
= l
.listIterator();
439 while(li
.hasNext()) {
440 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
441 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
442 if (spdPcd
== null) {
449 // AddItem to ModuleSA PcdBuildDefinitions
451 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
452 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType()+"", defaultVal
, moduleSa
);
462 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
464 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
465 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
466 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
467 m
.put("PackageSurfaceArea", GlobalData
.getPackageXmlObject(depPkgs
[i
]));
468 SurfaceAreaQuery
.setDoc(m
);
469 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations();
473 for (int j
= 0; j
< xo
.length
; ++j
) {
474 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
475 if (msaPcd
.getTokenSpaceGuidCName() == null) {
476 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
481 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
492 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
) {
493 PackageIdentification pi
= GlobalData
.getPackageForModule(mi
);
494 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
495 msa
.setModuleGuid(mi
.getGuid());
496 msa
.setModuleVersion(mi
.getVersion());
497 msa
.setPackageGuid(pi
.getGuid());
498 msa
.setPackageVersion(pi
.getVersion());
503 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
, ModuleSADocument
.ModuleSA moduleSa
) {
504 if (moduleSa
.getPcdBuildDefinition() == null){
505 moduleSa
.addNewPcdBuildDefinition();
508 // constructe pcd to modulesa mapping first.
509 // Attention : for any error condition, remove from map this pcd.
511 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
512 if (pcdConsumer
== null) {
513 pcdConsumer
= new ArrayList
<String
>();
515 String listValue
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion()
516 + " " + moduleSa
.getPackageGuid() + " " + moduleSa
.getPackageVersion()
518 pcdConsumer
.add(listValue
);
519 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
521 // Special dynamic type, if this pcd already exists in other ModuleSA
523 if (itemType
.equals("DYNAMIC")) {
525 ListIterator li
= pcdConsumer
.listIterator();
526 while(li
.hasNext()) {
527 String value
= li
.next().toString();
528 String
[] valuePart
= value
.split(" ");
529 if (!valuePart
[4].equals("DYNAMIC")) {
530 //ToDo error for same pcd, other type than dynamic
531 pcdConsumer
.remove(listValue
);
537 ListIterator li
= pcdConsumer
.listIterator();
538 while(li
.hasNext()) {
539 String value
= li
.next().toString();
540 String
[] valuePart
= value
.split(" ");
541 if (valuePart
[4].equals("DYNAMIC")) {
542 //ToDo error for same pcd, other type than non-dynamic
543 pcdConsumer
.remove(listValue
);
549 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
550 fpdPcd
.setCName(cName
);
551 fpdPcd
.setToken(token
);
552 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
553 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
554 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
556 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
557 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
559 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
560 // so need to add one dyn pcd.
562 if (al
.size() == 1) {
563 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
567 if (defaultVal
!= null){
568 fpdPcd
.setValue(defaultVal
);
571 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
572 fpdPcd
.setValue("0");
574 if (dataType
.equals("BOOLEAN")){
575 fpdPcd
.setValue("false");
577 if (dataType
.equals("VOID*")) {
581 if (dataType
.equals("UINT8")){
582 fpdPcd
.setMaxDatumSize(1);
584 if (dataType
.equals("UINT16")) {
585 fpdPcd
.setMaxDatumSize(2);
587 if (dataType
.equals("UINT32")) {
588 fpdPcd
.setMaxDatumSize(4);
590 if (dataType
.equals("UINT64")){
591 fpdPcd
.setMaxDatumSize(8);
593 if (dataType
.equals("BOOLEAN")){
594 fpdPcd
.setMaxDatumSize(1);
596 if (dataType
.equals("VOID*")) {
597 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
598 fpdPcd
.setMaxDatumSize(maxSize
);
603 private int setMaxSizeForPointer(String datum
) {
607 char ch
= datum
.charAt(0);
611 // For void* type PCD, only three datum is support:
612 // 1) Unicode: string with start char is "L"
613 // 2) Ansci: String is ""
614 // 3) byte array: String start char "{"
617 start
= datum
.indexOf('\"');
618 end
= datum
.lastIndexOf('\"');
620 (end
> datum
.length())||
621 ((start
== end
) && (datum
.length() > 0))) {
622 //ToDo Error handling here
625 strValue
= datum
.substring(start
+ 1, end
);
626 return strValue
.length() * 2;
627 } else if (ch
== '\"'){
628 start
= datum
.indexOf('\"');
629 end
= datum
.lastIndexOf('\"');
631 (end
> datum
.length())||
632 ((start
== end
) && (datum
.length() > 0))) {
635 strValue
= datum
.substring(start
+ 1, end
);
636 return strValue
.length();
637 } else if (ch
=='{') {
638 String
[] strValueArray
;
640 start
= datum
.indexOf('{');
641 end
= datum
.lastIndexOf('}');
642 strValue
= datum
.substring(start
+ 1, end
);
643 strValue
= strValue
.trim();
644 if (strValue
.length() == 0) {
647 strValueArray
= strValue
.split(",");
648 for (int index
= 0; index
< strValueArray
.length
; index
++) {
649 Integer value
= Integer
.decode(strValueArray
[index
].trim());
652 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
653 // "it is byte array in fact. But the element of %s exceed the byte range",
657 return strValueArray
.length
;
661 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
662 // "1) UNICODE string: like L\"xxxx\";\r\n"+
663 // "2) ANSIC string: like \"xxx\";\r\n"+
664 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
665 // "but the datum in seems does not following above format!",
671 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
672 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
677 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
679 return dynPcdMap
.get("pcdKey");
682 public int getDynamicPcdBuildDataCount() {
683 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
686 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
689 public void getDynamicPcdBuildData(String
[][] saa
) {
690 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
693 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
694 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
696 while(li
.hasNext()) {
697 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
698 saa
[i
][0] = dynPcd
.getCName();
699 saa
[i
][1] = dynPcd
.getToken().toString();
700 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
701 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
702 saa
[i
][4] = dynPcd
.getDatumType().toString();
708 private void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
) {
709 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
710 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
711 dynPcdData
.setCName(cName
);
712 dynPcdData
.setToken(token
);
713 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
714 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
716 BigInteger bigInt
= new BigInteger("0");
717 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
718 skuInfo
.setSkuId(bigInt
);
719 if (defaultVal
!= null){
720 skuInfo
.setValue(defaultVal
);
723 if (dataType
.equals("UINT8")){
724 skuInfo
.setValue("0");
726 if (dataType
.equals("UINT16")) {
727 skuInfo
.setValue("0");
729 if (dataType
.equals("UINT32")) {
730 skuInfo
.setValue("0");
732 if (dataType
.equals("UINT64")){
733 skuInfo
.setValue("0");
735 if (dataType
.equals("BOOLEAN")){
736 skuInfo
.setValue("false");
738 if (dataType
.equals("VOID*")) {
739 skuInfo
.setValue("");
742 if (dataType
.equals("UINT8")){
743 dynPcdData
.setMaxDatumSize(1);
745 if (dataType
.equals("UINT16")) {
746 dynPcdData
.setMaxDatumSize(2);
748 if (dataType
.equals("UINT32")) {
749 dynPcdData
.setMaxDatumSize(4);
751 if (dataType
.equals("UINT64")){
752 dynPcdData
.setMaxDatumSize(8);
754 if (dataType
.equals("BOOLEAN")){
755 dynPcdData
.setMaxDatumSize(1);
757 if (dataType
.equals("VOID*")) {
758 int maxSize
= setMaxSizeForPointer(defaultVal
);
759 dynPcdData
.setMaxDatumSize(maxSize
);
763 private void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
764 XmlObject o
= getfpdDynPcdBuildDefs();
766 XmlCursor cursor
= o
.newCursor();
767 if (cursor
.toFirstChild()) {
768 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
769 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
770 while (!(pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
))) {
771 cursor
.toNextSibling();
772 pcdBuildData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
780 // Get the Sku Info count of ith dyn pcd element.
782 public int getDynamicPcdSkuInfoCount(int i
){
783 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
787 int skuInfoCount
= 0;
788 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
789 if (cursor
.toFirstChild()) {
790 for (int j
= 0; j
< i
; ++j
) {
791 cursor
.toNextSibling();
793 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
794 if (pcdData
.getSkuInfoList() == null) {
798 skuInfoCount
= pcdData
.getSkuInfoList().size();
805 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
806 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
810 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
811 if (cursor
.toFirstChild()) {
812 for (int j
= 0; j
< i
; ++j
) {
813 cursor
.toNextSibling();
815 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
816 if (pcdData
.getSkuInfoList() == null) {
821 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
823 while (li
.hasNext()) {
824 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
825 saa
[k
][0] = skuInfo
.getSkuId()+"";
826 saa
[k
][1] = skuInfo
.getVariableName();
827 saa
[k
][2] = skuInfo
.getVariableGuid();
828 saa
[k
][3] = skuInfo
.getVariableOffset();
829 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
830 saa
[k
][5] = skuInfo
.getVpdOffset();
831 saa
[k
][6] = skuInfo
.getValue();
841 public String
getDynamicPcdBuildDataValue(int i
){
843 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
847 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
848 if (cursor
.toFirstChild()) {
849 for (int j
= 0; j
< i
; ++j
) {
850 cursor
.toNextSibling();
852 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
853 if (pcdData
.getSkuInfoList() == null) {
857 value
= pcdData
.getSkuInfoArray(0).getValue();
864 public String
getDynamicPcdBuildDataVpdOffset(int i
){
865 String vpdOffset
= null;
866 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
870 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
871 if (cursor
.toFirstChild()) {
872 for (int j
= 0; j
< i
; ++j
) {
873 cursor
.toNextSibling();
875 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
876 if (pcdData
.getSkuInfoList() == null) {
880 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
887 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
888 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
892 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
893 if (cursor
.toFirstChild()) {
894 for (int j
= 0; j
< i
; ++j
) {
895 cursor
.toNextSibling();
897 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
898 if (pcdData
.getSkuInfoList() == null) {
903 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
904 cursor
.toChild(qSkuInfo
);
911 // generate sku info for ith dyn pcd build data.
913 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
914 String hiiDefault
, String vpdOffset
, String value
, int i
) {
915 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
919 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
920 if (cursor
.toFirstChild()) {
921 for (int j
= 0; j
< i
; ++j
) {
922 cursor
.toNextSibling();
924 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
925 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
926 skuInfo
.setSkuId(new BigInteger(id
));
927 if (varName
!= null){
928 skuInfo
.setVariableName(varName
);
929 skuInfo
.setVariableGuid(varGuid
);
930 skuInfo
.setVariableOffset(varOffset
);
931 skuInfo
.setHiiDefaultValue(hiiDefault
);
933 else if (vpdOffset
!= null){
934 skuInfo
.setVpdOffset(vpdOffset
);
937 skuInfo
.setValue(value
);
942 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
943 String hiiDefault
, String vpdOffset
, String value
, int i
){
944 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
948 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
949 if (cursor
.toFirstChild()) {
950 for (int j
= 0; j
< i
; ++j
) {
951 cursor
.toNextSibling();
953 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
954 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
955 while (li
.hasNext()) {
956 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
957 if (skuInfo
.getSkuId().toString().equals(id
)){
958 if (varName
!= null){
959 skuInfo
.setVariableName(varName
);
960 skuInfo
.setVariableGuid(varGuid
);
961 skuInfo
.setVariableOffset(varOffset
);
962 skuInfo
.setHiiDefaultValue(hiiDefault
);
964 else if (vpdOffset
!= null){
965 skuInfo
.setVpdOffset(vpdOffset
);
968 skuInfo
.setValue(value
);
976 public void removePcdDataFromLibraryInstance(String moduleKey
, String libInstanceKey
){
977 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
979 // should better maintain pcd from lib instance only, but maintain all is acceptable now.
981 maintainDynPcdMap(moduleSa
.getPcdBuildDefinition(), libInstanceKey
);
985 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
986 if (fpdBuildOpts
== null) {
987 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
992 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
993 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
995 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
998 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
999 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1002 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
1003 at
.setId(new Integer(id
));
1004 if (fileName
!= null){
1005 at
.setFilename(fileName
);
1007 if (execOrder
!= null) {
1008 at
.setAntCmdOptions(execOrder
);
1012 public void removeBuildOptionsUserDefAntTask(int i
) {
1013 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1017 XmlCursor cursor
= o
.newCursor();
1018 if (cursor
.toFirstChild()) {
1019 for (int j
= 0; j
< i
; ++j
) {
1020 cursor
.toNextSibling();
1027 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
1028 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1032 XmlCursor cursor
= o
.newCursor();
1033 if (cursor
.toFirstChild()) {
1034 for (int j
= 0; j
< i
; ++j
) {
1035 cursor
.toNextSibling();
1037 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
1038 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1043 public int getBuildOptionsUserDefAntTaskCount() {
1044 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1045 if (udats
== null || udats
.getAntTaskList() == null) {
1049 return udats
.getAntTaskList().size();
1052 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
1053 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1054 if (udats
== null || udats
.getAntTaskList() == null) {
1058 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
1059 ListIterator li
= l
.listIterator();
1061 while (li
.hasNext()) {
1062 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
1063 saa
[i
][0] = at
.getId() + "";
1064 saa
[i
][1] = saa
[i
][2] = "";
1065 if (at
.getFilename() != null){
1066 saa
[i
][1] = at
.getFilename();
1068 if (at
.getAntCmdOptions() != null) {
1069 saa
[i
][2] = at
.getAntCmdOptions();
1074 public void genBuildOptionsOpt(String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
) {
1075 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
1077 opts
= getfpdBuildOpts().addNewOptions();
1079 OptionDocument
.Option opt
= opts
.addNewOption();
1080 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1083 private void setBuildOptionsOpt(String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
, OptionDocument
.Option opt
){
1084 opt
.setStringValue(contents
);
1085 // opt.setBuildTargets(buildTargets);
1086 opt
.setToolChainFamily(toolChain
);
1087 opt
.setTagName(tagName
);
1088 opt
.setToolCode(toolCmd
);
1089 String
[] s
= archList
.split(" ");
1090 ArrayList
<String
> al
= new ArrayList
<String
>();
1091 for (int i
= 0; i
< s
.length
; ++i
) {
1094 opt
.setSupArchList(al
);
1097 public void removeBuildOptionsOpt(int i
){
1099 XmlObject o
= getfpdBuildOpts().getOptions();
1104 XmlCursor cursor
= o
.newCursor();
1105 if (cursor
.toFirstChild()) {
1106 for (int j
= 0; j
< i
; ++j
) {
1107 cursor
.toNextSibling();
1114 public void updateBuildOptionsOpt(int i
, String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
) {
1115 XmlObject o
= getfpdBuildOpts().getOptions();
1120 XmlCursor cursor
= o
.newCursor();
1121 if (cursor
.toFirstChild()) {
1122 for (int j
= 0; j
< i
; ++j
) {
1123 cursor
.toNextSibling();
1125 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1126 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1131 public int getBuildOptionsOptCount(){
1132 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1135 return getfpdBuildOpts().getOptions().getOptionList().size();
1138 public void getBuildOptionsOpts(String
[][] saa
) {
1139 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1143 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
1144 ListIterator li
= lOpt
.listIterator();
1146 while(li
.hasNext()) {
1147 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1148 if (opt
.getBuildTargets() != null) {
1149 saa
[i
][0] = listToString(opt
.getBuildTargets());
1151 saa
[i
][1] = opt
.getToolChainFamily();
1152 if (opt
.getSupArchList() != null){
1153 saa
[i
][2] = listToString(opt
.getSupArchList());
1156 saa
[i
][3] = opt
.getToolCode();
1157 saa
[i
][4] = opt
.getTagName();
1158 saa
[i
][5] = opt
.getStringValue();
1164 public void genBuildOptionsFfs(String ffsKey
, String type
) {
1165 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
1166 ffs
.setFfsKey(ffsKey
);
1168 ffs
.addNewSections().setEncapsulationType(type
);
1172 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
1173 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1174 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
1175 attrib
.setName(name
);
1176 attrib
.setValue(value
);
1179 /**update jth attribute of ith ffs.
1183 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
1184 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1185 XmlCursor cursor
= ffs
.newCursor();
1186 QName qAttrib
= new QName(xmlNs
, "Attribute");
1187 if (cursor
.toChild(qAttrib
)) {
1188 for (int k
= 0; k
< j
; ++k
) {
1189 cursor
.toNextSibling(qAttrib
);
1191 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
1192 attrib
.setName(name
);
1193 attrib
.setValue(value
);
1198 public void removeBuildOptionsFfsAttribute(int i
, int j
){
1199 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1200 XmlCursor cursor
= ffs
.newCursor();
1201 QName qAttrib
= new QName(xmlNs
, "Attribute");
1202 if (cursor
.toChild(qAttrib
)) {
1203 for (int k
= 0; k
< j
; ++k
) {
1204 cursor
.toNextSibling(qAttrib
);
1211 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
1212 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1216 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1218 if (sections
== null){
1219 sections
= ffs
.addNewSections();
1221 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
1224 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
1225 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1229 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1231 if (sections
== null){
1232 sections
= ffs
.addNewSections();
1234 sections
.addNewSections().setEncapsulationType(encapType
);
1237 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
1238 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1242 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1243 XmlCursor cursor
= sections
.newCursor();
1244 QName qSections
= new QName(xmlNs
, "Sections");
1245 if (cursor
.toChild(qSections
)){
1246 for (int k
= 0; k
< j
; ++k
) {
1247 cursor
.toNextSibling(qSections
);
1249 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
1250 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
1255 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
1256 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1260 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1261 XmlCursor cursor
= sections
.newCursor();
1262 QName qSections
= new QName(xmlNs
, "Sections");
1263 if (cursor
.toChild(qSections
)){
1264 for (int k
= 0; k
< j
; ++k
) {
1265 cursor
.toNextSibling(qSections
);
1267 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
1268 if (sections2
.getSectionList() == null){
1272 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
1273 while(li
.hasNext()) {
1274 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
1275 al
.add(section
.getSectionType().toString());
1282 public int getBuildOptionsFfsCount(){
1283 if (getfpdBuildOpts().getFfsList() == null) {
1286 return getfpdBuildOpts().getFfsList().size();
1289 public void getBuildOptionsFfsKey(String
[][] saa
) {
1290 if (getfpdBuildOpts().getFfsList() == null) {
1293 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
1295 while(li
.hasNext()){
1296 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
1297 saa
[i
][0] = ffs
.getFfsKey();
1302 /**Get ith FFS key and contents.
1305 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
1306 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1310 sa
[0] = ffs
.getFfsKey();
1311 if (ffs
.getSections() != null) {
1312 if(ffs
.getSections().getEncapsulationType() != null){
1313 sa
[1] = ffs
.getSections().getEncapsulationType();
1315 if (ffs
.getSections().getSectionList() != null){
1316 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
1317 while (li
.hasNext()) {
1318 firstLevelSection
.add(li
.next().getSectionType().toString());
1321 if (ffs
.getSections().getSectionsList() != null) {
1322 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
1323 while(li
.hasNext()) {
1324 firstLevelSections
.add(li
.next().getEncapsulationType());
1328 if (ffs
.getAttributeList() != null) {
1329 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
1330 while(li
.hasNext()) {
1331 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
1332 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
1341 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
1342 XmlObject o
= getfpdBuildOpts();
1343 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
1345 XmlCursor cursor
= o
.newCursor();
1346 QName qFfs
= new QName(xmlNs
, "Ffs");
1347 if (cursor
.toChild(qFfs
)) {
1348 for (int j
= 0; j
< i
; ++j
) {
1349 cursor
.toNextSibling(qFfs
);
1351 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
1357 public void removeBuildOptionsFfs(int i
) {
1358 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1363 XmlCursor cursor
= ffs
.newCursor();
1368 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
1369 if (fpdPlatformDefs
== null){
1370 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
1372 return fpdPlatformDefs
;
1375 public FlashDocument
.Flash
getfpdFlash() {
1376 if (fpdFlash
== null) {
1377 fpdFlash
= fpdRoot
.addNewFlash();
1382 public void genFlashDefinitionFile(String file
) {
1383 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
1385 fdf
= getfpdFlash().addNewFlashDefinitionFile();
1388 fdf
.setStringValue(file
);
1391 public String
getFlashDefinitionFile() {
1392 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
1397 return fdf
.getStringValue();
1402 public void genFvImagesNameValue(String name
, String value
) {
1404 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
1406 fi
= getfpdFlash().addNewFvImages();
1409 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
1414 public void removeFvImagesNameValue(int i
){
1416 XmlObject o
= getfpdFlash().getFvImages();
1421 QName qNameValue
= new QName(xmlNs
, "NameValue");
1422 XmlCursor cursor
= o
.newCursor();
1423 if (cursor
.toChild(qNameValue
)) {
1424 for (int j
= 0; j
< i
; ++j
) {
1425 cursor
.toNextSibling(qNameValue
);
1432 public void updateFvImagesNameValue(int i
, String name
, String value
){
1434 XmlObject o
= getfpdFlash().getFvImages();
1439 QName qNameValue
= new QName(xmlNs
, "NameValue");
1440 XmlCursor cursor
= o
.newCursor();
1441 if (cursor
.toChild(qNameValue
)) {
1442 for (int j
= 0; j
< i
; ++j
) {
1443 cursor
.toNextSibling(qNameValue
);
1445 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
1452 public int getFvImagesNameValueCount() {
1454 FvImagesDocument
.FvImages fi
= null;
1455 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
1458 return fi
.getNameValueList().size();
1461 public void getFvImagesNameValues(String
[][] nv
) {
1463 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
1467 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
1469 ListIterator li
= l
.listIterator();
1470 while (li
.hasNext()) {
1471 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
1473 nv
[i
][0] = e
.getName();
1474 nv
[i
][1] = e
.getValue();
1480 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
1482 FvImagesDocument
.FvImages fis
= null;
1483 if ((fis
= getfpdFlash().getFvImages()) == null) {
1484 fis
= getfpdFlash().addNewFvImages();
1488 //gen FvImage with FvImageNames array
1490 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
1491 for (int i
= 0; i
< names
.length
; ++i
) {
1492 fi
.addFvImageNames(names
[i
]);
1494 fi
.setType(FvImageTypes
.Enum
.forString(types
));
1495 if (options
!= null){
1496 setFvImagesFvImageFvImageOptions(options
, fi
);
1500 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
1501 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
1503 fio
= fi
.addNewFvImageOptions();
1506 Set
<String
> key
= options
.keySet();
1507 Iterator
<String
> i
= key
.iterator();
1508 while (i
.hasNext()) {
1510 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
1511 String k
= (String
)i
.next();
1514 nv
.setValue((String
)options
.get(k
));
1521 public void removeFvImagesFvImage(int i
) {
1523 XmlObject o
= getfpdFlash().getFvImages();
1528 QName qFvImage
= new QName(xmlNs
, "FvImage");
1529 XmlCursor cursor
= o
.newCursor();
1530 if (cursor
.toChild(qFvImage
)) {
1531 for (int j
= 0; j
< i
; ++j
) {
1532 cursor
.toNextSibling(qFvImage
);
1539 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
1541 XmlObject o
= getfpdFlash().getFvImages();
1545 XmlCursor cursor
= o
.newCursor();
1546 QName qFvImage
= new QName(xmlNs
, "FvImage");
1547 if (cursor
.toChild(qFvImage
)) {
1548 for (int j
= 0; j
< i
; ++j
) {
1549 cursor
.toNextSibling(qFvImage
);
1551 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
1552 fi
.setType(FvImageTypes
.Enum
.forString(types
));
1555 // remove old FvImageNames before adding new ones
1557 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
1558 cursor
.toChild(qFvImageNames
);
1560 while (cursor
.toNextSibling(qFvImageNames
)) {
1564 for (int k
= 0; k
< names
.length
; ++k
) {
1565 fi
.addFvImageNames(names
[k
]);
1568 // remove old FvImageOptions before adding new options
1570 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
1571 cursor
.toNextSibling(qFvImageOptions
);
1574 setFvImagesFvImageFvImageOptions(options
, fi
);
1579 public int getFvImagesFvImageCount() {
1581 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
1584 return getfpdFlash().getFvImages().getFvImageList().size();
1587 /**Only Get Fv image setting - name and type.
1590 public void getFvImagesFvImages(String
[][] saa
) {
1592 if (getfpdFlash().getFvImages() == null) {
1595 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
1599 ListIterator li
= l
.listIterator();
1601 while(li
.hasNext()) {
1602 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
1604 // get FvImageNames array, space separated
1606 List
<String
> lfn
= fi
.getFvImageNamesList();
1607 ListIterator lfni
= lfn
.listIterator();
1609 while (lfni
.hasNext()) {
1610 saa
[i
][0] += (String
)lfni
.next();
1613 saa
[i
][0] = saa
[i
][0].trim();
1615 saa
[i
][1] = fi
.getType()+"";
1621 /**Get FvImage Options for FvImage i
1622 * @param i the ith FvImage
1624 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
1625 XmlObject o
= getfpdFlash().getFvImages();
1629 XmlCursor cursor
= o
.newCursor();
1630 QName qFvImage
= new QName(xmlNs
, "FvImage");
1631 if (cursor
.toChild(qFvImage
)) {
1632 for (int j
= 0; j
< i
; ++j
) {
1633 cursor
.toNextSibling(qFvImage
);
1635 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
1636 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
1639 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
1640 while(li
.hasNext()){
1641 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
1642 m
.put(nv
.getName(), nv
.getValue());
1648 Get platform header element
1649 @return PlatformHeaderDocument.PlatformHeader
1651 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
1652 if (fpdHdr
== null) {
1653 fpdHdr
= fpdRoot
.addNewPlatformHeader();
1655 genPlatformDefsSkuInfo("0", "DEFAULT");
1659 public void genPlatformDefsSkuInfo(String id
, String name
) {
1660 SkuInfoDocument
.SkuInfo skuInfo
= null;
1661 if (getfpdPlatformDefs().getSkuInfo() == null) {
1662 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
1664 skuInfo
= getfpdPlatformDefs().getSkuInfo();
1665 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
1666 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
1667 skuName
.setSkuID(new BigInteger("0"));
1668 skuName
.setStringValue("DEFAULT");
1670 if (id
.equals("0")) {
1673 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
1674 skuName
.setSkuID(new BigInteger(id
));
1675 skuName
.setStringValue(name
);
1679 public String
getFpdHdrPlatformName() {
1680 return getFpdHdr().getPlatformName();
1683 public String
getFpdHdrGuidValue() {
1684 return getFpdHdr().getGuidValue();
1687 public String
getFpdHdrVer() {
1688 return getFpdHdr().getVersion();
1691 public String
getFpdHdrAbs() {
1692 return getFpdHdr().getAbstract();
1695 public String
getFpdHdrDescription() {
1696 return getFpdHdr().getDescription();
1699 public String
getFpdHdrCopyright() {
1700 return getFpdHdr().getCopyright();
1703 public String
getFpdHdrLicense() {
1704 LicenseDocument
.License l
= getFpdHdr().getLicense();
1708 return l
.getStringValue();
1711 public String
getFpdHdrUrl() {
1712 LicenseDocument
.License l
= getFpdHdr().getLicense();
1719 public String
getFpdHdrSpec() {
1721 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1722 // return getFpdHdr().getSpecification();
1725 public void setFpdHdrPlatformName(String name
){
1726 getFpdHdr().setPlatformName(name
);
1729 public void setFpdHdrGuidValue(String guid
){
1730 getFpdHdr().setGuidValue(guid
);
1733 public void setFpdHdrVer(String v
){
1734 getFpdHdr().setVersion(v
);
1737 public void setFpdHdrAbs(String abs
) {
1738 getFpdHdr().setAbstract(abs
);
1741 public void setFpdHdrDescription(String desc
){
1742 getFpdHdr().setDescription(desc
);
1745 public void setFpdHdrCopyright(String cr
) {
1746 getFpdHdr().setCopyright(cr
);
1749 public void setFpdHdrLicense(String license
){
1750 LicenseDocument
.License l
= getFpdHdr().getLicense();
1752 getFpdHdr().addNewLicense().setStringValue(license
);
1755 l
.setStringValue(license
);
1759 public void setFpdHdrUrl(String url
){
1760 LicenseDocument
.License l
= getFpdHdr().getLicense();
1766 public void setFpdHdrSpec(String s
){
1767 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1768 getFpdHdr().setSpecification(s
);
1771 Save the processed xml contents to file
1773 @param fpdFile The file to save xml contents
1774 @throws IOException Exceptions during file operation
1776 public void saveAs(File fpdFile
) throws IOException
{
1778 XmlOptions options
= new XmlOptions();
1780 options
.setCharacterEncoding("UTF-8");
1781 options
.setSavePrettyPrint();
1782 options
.setSavePrettyPrintIndent(2);
1784 fpdd
.save(fpdFile
, options
);
1785 } catch (IOException e
) {
1786 e
.printStackTrace();
1791 private String
listToString(List
<String
> l
) {
1796 ListIterator li
= l
.listIterator();
1797 while(li
.hasNext()) {