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