]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/pcd/action/PlatformPcdPreprocessActionForBuilding.java
Updated PeiRebase to produce a map file of the relocations done by this tool. This...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / PlatformPcdPreprocessActionForBuilding.java
CommitLineData
af98370e 1/** @file\r
2 PlatformPcdPreprocessActionForBuilding class.\r
3\r
4 This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
5 This class will be used for wizard and build tools, So it can *not* inherit\r
6 from buildAction or wizardAction.\r
7\r
8Copyright (c) 2006, Intel Corporation\r
9All rights reserved. This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/\r
18package org.tianocore.build.pcd.action;\r
19\r
20import java.io.File;\r
21import java.io.IOException;\r
22import java.math.BigInteger;\r
23import java.util.ArrayList;\r
24import java.util.Iterator;\r
25import java.util.List;\r
26import java.util.Map;\r
27\r
28import org.apache.xmlbeans.XmlException;\r
29import org.apache.xmlbeans.XmlObject;\r
30import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r
31import org.tianocore.PlatformSurfaceAreaDocument;\r
32import org.tianocore.build.fpd.FpdParserTask;\r
33import org.tianocore.build.global.GlobalData;\r
34import org.tianocore.build.id.FpdModuleIdentification;\r
35import org.tianocore.pcd.action.ActionMessage;\r
36import org.tianocore.pcd.entity.ModulePcdInfoFromFpd;\r
37import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
38import org.tianocore.pcd.entity.Token;\r
39import org.tianocore.pcd.entity.UsageIdentification;\r
40import org.tianocore.pcd.exception.EntityException;\r
41import org.tianocore.pcd.action.PlatformPcdPreprocessAction;\r
8b7bd455 42import org.tianocore.build.exception.PlatformPcdPreprocessBuildException;\r
43import org.tianocore.pcd.exception.PlatformPcdPreprocessException;\r
af98370e 44\r
45/**\r
46 This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
47 This class will be used for wizard and build tools, So it can *not* inherit\r
48 from buildAction or UIAction.\r
49**/\r
50public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreprocessAction {\r
af98370e 51 ///\r
52 /// FPD file is the root file.\r
53 ///\r
54 private String fpdFilePath;\r
55\r
56 ///\r
57 /// Message level for CollectPCDAction.\r
58 ///\r
59 private int originalMessageLevel;\r
60\r
61 ///\r
62 /// Cache the fpd docment instance for private usage.\r
63 ///\r
64 private PlatformSurfaceAreaDocument fpdDocInstance;\r
65\r
af98370e 66 /**\r
67 Set action message level for CollectPcdAction tool.\r
68\r
69 The message should be restored when this action exit.\r
70\r
71 @param actionMessageLevel parameter for this action\r
72 **/\r
73 public void setActionMessageLevel(int actionMessageLevel) {\r
74 originalMessageLevel = ActionMessage.messageLevel;\r
75 ActionMessage.messageLevel = actionMessageLevel;\r
76 }\r
77\r
78 /**\r
79 Set FPDFileName parameter for this action class.\r
80\r
81 @param fpdFilePath fpd file path\r
82 **/\r
83 public void setFPDFilePath(String fpdFilePath) {\r
84 this.fpdFilePath = fpdFilePath;\r
85 }\r
86\r
87 /**\r
88 Common function interface for outer.\r
89\r
8b7bd455 90 @param fpdFilePath The fpd file path of current build or analysis.\r
91 @param messageLevel The message level for this Action.\r
af98370e 92\r
8b7bd455 93 @throws PlatformPreprocessBuildException \r
94 The exception of this function. Because it can *not* be predict\r
95 where the action class will be used. So only Exception can be throw.\r
af98370e 96\r
97 **/\r
8b7bd455 98 public void perform(String fpdFilePath, int messageLevel) \r
99 throws PlatformPcdPreprocessBuildException {\r
af98370e 100 setFPDFilePath(fpdFilePath);\r
101 setActionMessageLevel(messageLevel);\r
102 checkParameter();\r
103 execute();\r
104 ActionMessage.messageLevel = originalMessageLevel;\r
105 }\r
106\r
107 /**\r
108 Core execution function for this action class.\r
109\r
110 This function work flows will be:\r
111 1) Collect and prepocess PCD information from FPD file, all PCD\r
112 information will be stored into memory database.\r
113 2) Generate 3 strings for\r
114 a) All modules using Dynamic(Ex) PCD entry.(Token Number)\r
115 b) PEI PCDDatabase (C Structure) for PCD Service PEIM.\r
116 c) DXE PCD Database (C structure) for PCD Service DXE.\r
117\r
118\r
119 @throws EntityException Exception indicate failed to execute this action.\r
120\r
121 **/\r
8b7bd455 122 public void execute() throws PlatformPcdPreprocessBuildException {\r
123 String errorMessageHeader = "Fail to initialize Pcd memory database for building. Because:";\r
af98370e 124 //\r
125 // Get memoryDatabaseManager instance from GlobalData.\r
8b7bd455 126 // The memoryDatabaseManager should be initialized as static variable\r
127 // in some Pre-process class.\r
af98370e 128 //\r
8b7bd455 129 setPcdDbManager(GlobalData.getPCDMemoryDBManager());\r
af98370e 130\r
131 //\r
132 // Collect all PCD information defined in FPD file.\r
133 // Evenry token defind in FPD will be created as an token into\r
134 // memory database.\r
135 //\r
8b7bd455 136 try {\r
137 initPcdMemoryDbWithPlatformInfo();\r
138 } catch (PlatformPcdPreprocessException exp) {\r
139 throw new PlatformPcdPreprocessBuildException(errorMessageHeader + exp.getMessage());\r
140 }\r
af98370e 141\r
142 //\r
143 // Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
144 //\r
8b7bd455 145 try {\r
146 genPcdDatabaseSourceCode ();\r
147 } catch (EntityException exp) {\r
148 throw new PlatformPcdPreprocessBuildException(errorMessageHeader + exp.getMessage());\r
149 }\r
af98370e 150 }\r
151\r
152 /**\r
153 Override function: implementate the method of get Guid string information from SPD file.\r
154\r
155 @param guidCName Guid CName string.\r
156\r
157 @return String[] Guid information from SPD file.\r
8b7bd455 158 @throws PlatformPcdPreprocessException\r
159 Fail to get Guid information from SPD file.\r
af98370e 160 **/\r
8b7bd455 161 public String[] getGuidInfoFromSpd(String guidCName) throws PlatformPcdPreprocessException {\r
af98370e 162 String[] tokenSpaceStrRet = null;\r
163 try {\r
164 tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(guidCName);\r
165 } catch ( Exception e ) {\r
8b7bd455 166 throw new PlatformPcdPreprocessException ("Failed get Guid CName " + guidCName + "from SPD file!");\r
af98370e 167 }\r
168 return tokenSpaceStrRet;\r
169 }\r
170\r
171 /**\r
172 This function generates source code for PCD Database.\r
173\r
af98370e 174 @throws EntityException If the token does *not* exist in memory database.\r
175\r
176 **/\r
177 private void genPcdDatabaseSourceCode()\r
178 throws EntityException {\r
179 String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions();\r
180\r
181 ArrayList<Token> alPei = new ArrayList<Token> ();\r
182 ArrayList<Token> alDxe = new ArrayList<Token> ();\r
183\r
184 getPcdDbManager().getTwoPhaseDynamicRecordArray(alPei, alDxe);\r
185 PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r
186 pcdPeiDatabase.genCode();\r
187 MemoryDatabaseManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString() +\r
188 PcdDatabase.getPcdPeiDatabaseDefinitions();\r
189 MemoryDatabaseManager.PcdPeimCString = pcdPeiDatabase.getCString();\r
190\r
191 PcdDatabase pcdDxeDatabase = new PcdDatabase(alDxe, "DXE", alPei.size());\r
192 pcdDxeDatabase.genCode();\r
193 MemoryDatabaseManager.PcdDxeHString = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString() +\r
194 PcdDatabase.getPcdDxeDatabaseDefinitions();\r
195 MemoryDatabaseManager.PcdDxeCString = pcdDxeDatabase.getCString();\r
196 }\r
197\r
198 /**\r
199 Override function: Get component array from FPD.\r
200\r
201 This function maybe provided by some Global class.\r
202\r
8b7bd455 203 @return List<ModuleInfo> the component array.\r
204 @throws PlatformPcdPreprocessException get all modules in <ModuleSA> in FPD file.\r
af98370e 205\r
8b7bd455 206 **/\r
af98370e 207 public List<ModulePcdInfoFromFpd> getComponentsFromFpd()\r
8b7bd455 208 throws PlatformPcdPreprocessException {\r
af98370e 209 List<ModulePcdInfoFromFpd> allModules = new ArrayList<ModulePcdInfoFromFpd>();\r
210 Map<FpdModuleIdentification, XmlObject> pcdBuildDefinitions = null;\r
211 UsageIdentification usageId = null;\r
212\r
213 pcdBuildDefinitions = GlobalData.getFpdPcdBuildDefinitions();\r
214 if (pcdBuildDefinitions == null) {\r
215 return null;\r
216 }\r
217\r
218 //\r
219 // Loop map to retrieve all PCD build definition and Module id\r
220 //\r
221 Iterator item = pcdBuildDefinitions.keySet().iterator();\r
222 while (item.hasNext()){\r
223 FpdModuleIdentification id = (FpdModuleIdentification) item.next();\r
224 usageId = new UsageIdentification(id.getModule().getName(),\r
225 id.getModule().getGuid(),\r
226 id.getModule().getPackage().getName(),\r
227 id.getModule().getPackage().getGuid(),\r
228 id.getArch(),\r
229 id.getModule().getVersion(),\r
230 id.getModule().getModuleType());\r
231 allModules.add(new ModulePcdInfoFromFpd(usageId, pcdBuildDefinitions.get(id)));\r
232 }\r
233 return allModules;\r
234 }\r
235\r
236 /**\r
237 Override function: Verify the datum value according its datum size and datum type, this\r
238 function maybe moved to FPD verification tools in future.\r
239\r
8b7bd455 240 @param cName The token name\r
241 @param moduleName The module who use this PCD token\r
242 @param datum The PCD's datum\r
243 @param datumType The PCD's datum type\r
244 @param maxDatumSize The max size for PCD's Datum.\r
af98370e 245\r
8b7bd455 246 @return String exception strings.\r
af98370e 247 */\r
af98370e 248 public String verifyDatum(String cName,\r
249 String moduleName,\r
250 String datum,\r
251 Token.DATUM_TYPE datumType,\r
252 int maxDatumSize) {\r
253 String exceptionString = null;\r
254 int value;\r
255 BigInteger value64;\r
256 String subStr;\r
257 int index;\r
258\r
259 if (moduleName == null) {\r
260 moduleName = "section <DynamicPcdBuildDefinitions>";\r
261 } else {\r
262 moduleName = "module " + moduleName;\r
263 }\r
264\r
265 if (maxDatumSize == 0) {\r
266 exceptionString = String.format("[FPD file error] You maybe miss <MaxDatumSize> for PCD %s in %s",\r
267 cName,\r
268 moduleName);\r
269 return exceptionString;\r
270 }\r
271\r
272 switch (datumType) {\r
273 case UINT8:\r
274 if (maxDatumSize != 1) {\r
275 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
276 "is UINT8, but datum size is %d, they are not matched!",\r
277 cName,\r
278 moduleName,\r
279 maxDatumSize);\r
280 return exceptionString;\r
281 }\r
282\r
283 if (datum != null) {\r
284 try {\r
285 value = Integer.decode(datum);\r
286 } catch (NumberFormatException nfeExp) {\r
287 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid "+\r
288 "digital format of UINT8",\r
289 cName,\r
290 moduleName);\r
291 return exceptionString;\r
292 }\r
293 if (value > 0xFF) {\r
294 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s exceed"+\r
295 " the max size of UINT8 - 0xFF",\r
296 cName,\r
297 moduleName,\r
298 datum);\r
299 return exceptionString;\r
300 }\r
301 }\r
302 break;\r
303 case UINT16:\r
304 if (maxDatumSize != 2) {\r
305 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
306 "is UINT16, but datum size is %d, they are not matched!",\r
307 cName,\r
308 moduleName,\r
309 maxDatumSize);\r
310 return exceptionString;\r
311 }\r
312 if (datum != null) {\r
313 try {\r
314 value = Integer.decode(datum);\r
315 } catch (NumberFormatException nfeExp) {\r
316 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is "+\r
317 "not valid digital of UINT16",\r
318 cName,\r
319 moduleName);\r
320 return exceptionString;\r
321 }\r
322 if (value > 0xFFFF) {\r
323 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+\r
324 "which exceed the range of UINT16 - 0xFFFF",\r
325 cName,\r
326 moduleName,\r
327 datum);\r
328 return exceptionString;\r
329 }\r
330 }\r
331 break;\r
332 case UINT32:\r
333 if (maxDatumSize != 4) {\r
334 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
335 "is UINT32, but datum size is %d, they are not matched!",\r
336 cName,\r
337 moduleName,\r
338 maxDatumSize);\r
339 return exceptionString;\r
340 }\r
341\r
342 if (datum != null) {\r
343 try {\r
344 if (datum.length() > 2) {\r
345 if ((datum.charAt(0) == '0') &&\r
346 ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){\r
347 subStr = datum.substring(2, datum.length());\r
348 value64 = new BigInteger(subStr, 16);\r
349 } else {\r
350 value64 = new BigInteger(datum);\r
351 }\r
352 } else {\r
353 value64 = new BigInteger(datum);\r
354 }\r
355 } catch (NumberFormatException nfeExp) {\r
356 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not "+\r
357 "valid digital of UINT32",\r
358 cName,\r
359 moduleName);\r
360 return exceptionString;\r
361 }\r
362\r
363 if (value64.bitLength() > 32) {\r
364 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s which "+\r
365 "exceed the range of UINT32 - 0xFFFFFFFF",\r
366 cName,\r
367 moduleName,\r
368 datum);\r
369 return exceptionString;\r
370 }\r
371 }\r
372 break;\r
373 case UINT64:\r
374 if (maxDatumSize != 8) {\r
375 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
376 "is UINT64, but datum size is %d, they are not matched!",\r
377 cName,\r
378 moduleName,\r
379 maxDatumSize);\r
380 return exceptionString;\r
381 }\r
382\r
383 if (datum != null) {\r
384 try {\r
385 if (datum.length() > 2) {\r
386 if ((datum.charAt(0) == '0') &&\r
387 ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){\r
388 subStr = datum.substring(2, datum.length());\r
389 value64 = new BigInteger(subStr, 16);\r
390 } else {\r
391 value64 = new BigInteger(datum);\r
392 }\r
393 } else {\r
394 value64 = new BigInteger(datum);\r
395 }\r
396 } catch (NumberFormatException nfeExp) {\r
397 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid"+\r
398 " digital of UINT64",\r
399 cName,\r
400 moduleName);\r
401 return exceptionString;\r
402 }\r
403\r
404 if (value64.bitLength() > 64) {\r
405 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+\r
406 "exceed the range of UINT64 - 0xFFFFFFFFFFFFFFFF",\r
407 cName,\r
408 moduleName,\r
409 datum);\r
410 return exceptionString;\r
411 }\r
412 }\r
413 break;\r
414 case BOOLEAN:\r
415 if (maxDatumSize != 1) {\r
416 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
417 "is BOOLEAN, but datum size is %d, they are not matched!",\r
418 cName,\r
419 moduleName,\r
420 maxDatumSize);\r
421 return exceptionString;\r
422 }\r
423\r
424 if (datum != null) {\r
425 if (!(datum.equalsIgnoreCase("TRUE") ||\r
426 datum.equalsIgnoreCase("FALSE"))) {\r
427 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
428 "is BOOELAN, but value is not 'true'/'TRUE' or 'FALSE'/'false'",\r
429 cName,\r
430 moduleName);\r
431 return exceptionString;\r
432 }\r
433\r
434 }\r
435 break;\r
436 case POINTER:\r
437 if (datum == null) {\r
438 break;\r
439 }\r
440\r
441 char ch = datum.charAt(0);\r
442 int start, end;\r
443 String strValue;\r
444 //\r
445 // For void* type PCD, only three datum is support:\r
446 // 1) Unicode: string with start char is "L"\r
447 // 2) Ansci: String start char is ""\r
448 // 3) byte array: String start char "{"\r
449 //\r
450 if (ch == 'L') {\r
451 start = datum.indexOf('\"');\r
452 end = datum.lastIndexOf('\"');\r
453 if ((start > end) ||\r
454 (end > datum.length())||\r
455 ((start == end) && (datum.length() > 0))) {\r
456 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+\r
457 "a UNICODE string because start with L\", but format maybe"+\r
458 "is not right, correct UNICODE string is L\"...\"!",\r
459 cName,\r
460 moduleName);\r
461 return exceptionString;\r
462 }\r
463\r
464 strValue = datum.substring(start + 1, end);\r
465 if ((strValue.length() * 2) > maxDatumSize) {\r
466 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+\r
467 "a UNICODE string, but the datum size is %d exceed to <MaxDatumSize> : %d",\r
468 cName,\r
469 moduleName,\r
470 strValue.length() * 2,\r
471 maxDatumSize);\r
472 return exceptionString;\r
473 }\r
474 } else if (ch == '\"'){\r
475 start = datum.indexOf('\"');\r
476 end = datum.lastIndexOf('\"');\r
477 if ((start > end) ||\r
478 (end > datum.length())||\r
479 ((start == end) && (datum.length() > 0))) {\r
480 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+\r
481 "a ANSCII string because start with \", but format maybe"+\r
482 "is not right, correct ANSIC string is \"...\"!",\r
483 cName,\r
484 moduleName);\r
485 return exceptionString;\r
486 }\r
487 strValue = datum.substring(start + 1, end);\r
488 if ((strValue.length()) > maxDatumSize) {\r
489 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+\r
490 "a ANSCI string, but the datum size is %d which exceed to <MaxDatumSize> : %d",\r
491 cName,\r
492 moduleName,\r
493 strValue.length(),\r
494 maxDatumSize);\r
495 return exceptionString;\r
496 }\r
497 } else if (ch =='{') {\r
498 String[] strValueArray;\r
499\r
500 start = datum.indexOf('{');\r
501 end = datum.lastIndexOf('}');\r
502 strValue = datum.substring(start + 1, end);\r
503 strValue = strValue.trim();\r
504 if (strValue.length() == 0) {\r
505 exceptionString = String.format ("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+\r
506 "it is byte array in fact, but '{}' is not valid for NULL datam but"+\r
507 " need use '{0}'",\r
508 cName,\r
509 moduleName);\r
510 return exceptionString;\r
511 }\r
512 strValueArray = strValue.split(",");\r
513 for (index = 0; index < strValueArray.length; index ++) {\r
514 try{\r
515 value = Integer.decode(strValueArray[index].trim());\r
516 } catch (NumberFormatException nfeEx) {\r
517 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+\r
518 "it is byte array in fact. For every byte in array should be a valid"+\r
519 "byte digital, but element %s is not a valid byte digital!",\r
520 cName,\r
521 moduleName,\r
522 strValueArray[index]);\r
523 return exceptionString;\r
524 }\r
525 if (value > 0xFF) {\r
526 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, "+\r
527 "it is byte array in fact. But the element of %s exceed the byte range",\r
528 cName,\r
529 moduleName,\r
530 strValueArray[index]);\r
531 return exceptionString;\r
532 }\r
533 }\r
534\r
535 if (strValueArray.length > maxDatumSize) {\r
536 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is byte"+\r
537 "array, but the number of bytes is %d which exceed to <MaxDatumSzie> : %d!",\r
538 cName,\r
539 moduleName,\r
540 strValueArray.length,\r
541 maxDatumSize);\r
542 return exceptionString;\r
543 }\r
544 } else {\r
545 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+\r
546 "1) UNICODE string: like L\"xxxx\";\r\n"+\r
547 "2) ANSIC string: like \"xxx\";\r\n"+\r
548 "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+\r
549 "But the datum in seems does not following above format!",\r
550 cName,\r
551 moduleName);\r
552 return exceptionString;\r
553 }\r
554 break;\r
555 default:\r
556 exceptionString = String.format("[FPD file error] For PCD entry %s in %s, datum type is unknown, it should be one of "+\r
557 "UINT8, UINT16, UINT32, UINT64, VOID*, BOOLEAN",\r
558 cName,\r
559 moduleName);\r
560 return exceptionString;\r
561 }\r
562 return null;\r
563 }\r
564\r
565 /**\r
566 Override function: Get dynamic information for a dynamic PCD from <DynamicPcdBuildDefinition> seciton in FPD file.\r
567\r
568 This function should be implemented in GlobalData in future.\r
569\r
570 @param token The token instance which has hold module's PCD information\r
571 @param moduleName The name of module who will use this Dynamic PCD.\r
572\r
573 @return DynamicPcdBuildDefinitions.PcdBuildData\r
574 **/\r
575 public DynamicPcdBuildDefinitions.PcdBuildData getDynamicInfoFromFpd(Token token,\r
576 String moduleName)\r
8b7bd455 577 throws PlatformPcdPreprocessException {\r
af98370e 578 int index = 0;\r
579 String exceptionString = null;\r
580 String dynamicPrimaryKey = null;\r
581 DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;\r
582 List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray = null;\r
583 String[] tokenSpaceStrRet = null;\r
584\r
585 //\r
586 // If FPD document is not be opened, open and initialize it.\r
587 // BUGBUG: The code should be moved into GlobalData in future.\r
588 //\r
589 if (fpdDocInstance == null) {\r
590 try {\r
591 fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
592 } catch(IOException ioE) {\r
8b7bd455 593 throw new PlatformPcdPreprocessException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
af98370e 594 } catch(XmlException xmlE) {\r
8b7bd455 595 throw new PlatformPcdPreprocessException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
af98370e 596 }\r
597 }\r
598\r
599 dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
600 if (dynamicPcdBuildDefinitions == null) {\r
601 exceptionString = String.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+\r
602 "PCD entry %s in module %s!",\r
603 token.cName,\r
604 moduleName);\r
8b7bd455 605 throw new PlatformPcdPreprocessException(exceptionString);\r
af98370e 606 }\r
607\r
608 dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
609 for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {\r
610 try {\r
611 tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName());\r
612 } catch (Exception e) {\r
8b7bd455 613 throw new PlatformPcdPreprocessException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
af98370e 614 }\r
615\r
616 if (tokenSpaceStrRet == null) {\r
8b7bd455 617 throw new PlatformPcdPreprocessException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
af98370e 618 }\r
619\r
620 dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
621 tokenSpaceStrRet[1]);\r
622 if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
623 return dynamicPcdBuildDataArray.get(index);\r
624 }\r
625 }\r
626\r
627 return null;\r
628 }\r
629\r
630 /**\r
631 Override function: get all <DynamicPcdBuildDefinition> from FPD file.\r
632\r
8b7bd455 633 @return List<DynamicPcdBuildDefinitions.PcdBuildData> All DYNAMIC PCD list in <DynamicPcdBuildDefinitions> in FPD file.\r
634 @throws PlatformPcdPreprocessBuildException Failure to get dynamic information list.\r
635\r
af98370e 636 **/\r
637 public List<DynamicPcdBuildDefinitions.PcdBuildData>\r
638 getAllDynamicPcdInfoFromFpd()\r
8b7bd455 639 throws PlatformPcdPreprocessException {\r
af98370e 640 DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;\r
641\r
642 //\r
643 // Open fpd document to get <DynamicPcdBuildDefinition> Section.\r
644 // BUGBUG: the function should be move GlobalData in furture.\r
645 //\r
646 if (fpdDocInstance == null) {\r
647 try {\r
648 fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
649 } catch(IOException ioE) {\r
8b7bd455 650 throw new PlatformPcdPreprocessException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
af98370e 651 } catch(XmlException xmlE) {\r
8b7bd455 652 throw new PlatformPcdPreprocessException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
af98370e 653 }\r
654 }\r
655\r
656 dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
657 if (dynamicPcdBuildDefinitions == null) {\r
658 return null;\r
659 }\r
660\r
661 return dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
662 }\r
663\r
664 /**\r
665 check parameter for this action.\r
666\r
8b7bd455 667 @throws PlatformPcdPreprocessBuildException Bad parameter.\r
af98370e 668 **/\r
8b7bd455 669 private void checkParameter() throws PlatformPcdPreprocessBuildException {\r
af98370e 670 File file = null;\r
671\r
8b7bd455 672 if (fpdFilePath == null) {\r
673 throw new PlatformPcdPreprocessBuildException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
af98370e 674 }\r
675\r
8b7bd455 676 if (fpdFilePath.length() == 0) {\r
677 throw new PlatformPcdPreprocessBuildException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
af98370e 678 }\r
679\r
680 file = new File(fpdFilePath);\r
681\r
682 if(!file.exists()) {\r
8b7bd455 683 throw new PlatformPcdPreprocessBuildException("FPD File " + fpdFilePath + " does not exist!");\r
af98370e 684 }\r
685 }\r
686\r
687 /**\r
688 Test case function\r
689\r
690 @param argv parameter from command line\r
691 **/\r
8b7bd455 692 public static void main(String argv[]) throws PlatformPcdPreprocessBuildException {\r
af98370e 693 PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding();\r
694 String projectDir = "x:/edk2";\r
af98370e 695 ca.setFPDFilePath(projectDir + "/EdkNt32Pkg/Nt32.fpd");\r
696 ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
697 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
698 projectDir,\r
699 "tools_def.txt");\r
700 System.out.println("After initInfo!");\r
701 FpdParserTask fpt = new FpdParserTask();\r
702 fpt.parseFpdFile(new File(projectDir + "/EdkNt32Pkg/Nt32.fpd"));\r
703 ca.execute();\r
704 }\r
705}\r