2 PCDAutoGenAction class.
4 This class is to manage how to generate the PCD information into Autogen.c and
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 package org
.tianocore
.build
.pcd
.action
;
20 import java
.util
.List
;
22 import org
.tianocore
.build
.global
.GlobalData
;
23 import org
.tianocore
.build
.pcd
.entity
.MemoryDatabaseManager
;
24 import org
.tianocore
.build
.pcd
.entity
.Token
;
25 import org
.tianocore
.build
.pcd
.entity
.UsageInstance
;
26 import org
.tianocore
.build
.pcd
.exception
.BuildActionException
;
27 import org
.tianocore
.build
.pcd
.exception
.EntityException
;
29 /** This class is to manage how to generate the PCD information into Autogen.c and
32 public class PCDAutoGenAction
extends BuildAction
{
34 /// The reference of DBManager in GlobalData class.
36 private MemoryDatabaseManager dbManager
;
38 /// The name of module which is analysised currently.
40 private String moduleName
;
42 /// Wheter current module is PCD emulated driver. It is only for
43 /// emulated PCD driver and will be kept until PCD IMAGE tool ready.
45 private boolean isEmulatedPCDDriver
;
47 /// The generated string for header file.
49 private String hAutoGenString
;
51 /// The generated string for C code file.
53 private String cAutoGenString
;
56 Set parameter ModuleName
58 @param moduleName the module name parameter.
60 public void setModuleName(String moduleName
) {
61 this.moduleName
= moduleName
;
65 Set parameter isEmulatedPCDDriver
67 @param isEmulatedPCDDriver whether this module is PeiEmulatedPCD driver
69 public void setIsEmulatedPCDDriver(boolean isEmulatedPCDDriver
) {
70 this.isEmulatedPCDDriver
= isEmulatedPCDDriver
;
74 Get the output of generated string for header file.
76 @return the string of header file for PCD
78 public String
OutputH() {
79 return hAutoGenString
;
83 Get the output of generated string for C Code file.
85 @return the string of C code file for PCD
87 public String
OutputC() {
88 return cAutoGenString
;
94 This function mainly initialize some member variable.
96 @param moduleName Parameter of this action class.
97 @param isEmulatedPCDDriver Parameter of this action class.
99 public PCDAutoGenAction(String moduleName
, boolean isEmulatedPCDDriver
) {
101 setIsEmulatedPCDDriver(isEmulatedPCDDriver
);
102 setModuleName(moduleName
);
106 check the parameter for action class.
108 @throws BuildActionException Bad parameter.
110 void checkParameter() throws BuildActionException
{
111 if(!isEmulatedPCDDriver
&&(moduleName
== null)) {
112 throw new BuildActionException("Wrong module name parameter for PCDAutoGenAction tool!");
115 if(!isEmulatedPCDDriver
&& moduleName
.length() == 0) {
116 throw new BuildActionException("Wrong module name parameter for PCDAutoGenAction tool!");
121 Core execution function for this action class.
123 All PCD information of this module comes from memory dabase. The collection
124 work should be done before this action execution.
125 Currently, we should generated all PCD information(maybe all dynamic) as array
126 in Pei emulated driver for simulating PCD runtime database.
128 @throws BuildActionException Failed to execute this aciton class.
130 void performAction() throws BuildActionException
{
131 ActionMessage
.debug(this,
132 "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");
135 // Check the PCD memory database manager is valid.
137 if(GlobalData
.getPCDMemoryDBManager() == null) {
138 throw new BuildActionException("Memory database has not been initlizated!");
141 dbManager
= GlobalData
.getPCDMemoryDBManager();
143 if(dbManager
.getDBSize() == 0) {
147 ActionMessage
.debug(this,
148 "PCD memory database contains " + dbManager
.getDBSize() + " PCD tokens");
153 if(isEmulatedPCDDriver
) {
154 generateAutogenForPCDEmulatedDriver();
156 generateAutogenForModule();
161 Generate the autogen string for a common module.
163 All PCD information of this module comes from memory dabase. The collection
164 work should be done before this action execution.
166 private void generateAutogenForModule()
169 List
<UsageInstance
> usageInstanceArray
;
171 usageInstanceArray
= dbManager
.getUsageInstanceArrayByModuleName(moduleName
);
173 if(usageInstanceArray
.size() != 0) {
175 // Add "#include 'PcdLib.h'" for Header file
177 hAutoGenString
= "#include <MdePkg/Include/Library/PcdLib.h>\r\n";
180 for(index
= 0; index
< usageInstanceArray
.size(); index
++) {
181 ActionMessage
.debug(this,
182 "Module " + moduleName
+ "'s PCD [" + Integer
.toHexString(index
) +
183 "]: " + usageInstanceArray
.get(index
).parentToken
.cName
);
185 usageInstanceArray
.get(index
).generateAutoGen();
186 hAutoGenString
+= usageInstanceArray
.get(index
).getHAutogenStr() + "\r\n";
187 cAutoGenString
+= usageInstanceArray
.get(index
).getCAutogenStr() + "\r\n";
188 } catch(EntityException exp
) {
189 throw new BuildActionException(exp
.getMessage());
193 ActionMessage
.debug(this,
194 "Module " + moduleName
+ "'s PCD header file:\r\n" + hAutoGenString
+ "\r\n"
196 ActionMessage
.debug(this,
197 "Module " + moduleName
+ "'s PCD C file:\r\n" + cAutoGenString
+ "\r\n"
202 Generate all PCD autogen string and the emulated PCD IMAGE array for emulated driver.
204 Currently, we should generated all PCD information(maybe all dynamic) as array
205 in Pei emulated driver for simulating PCD runtime database.
208 private void generateAutogenForPCDEmulatedDriver() {
211 UsageInstance usageInstance
;
214 // Add "#include 'PcdLib.h'" for Header file
216 hAutoGenString
= "#include <MdePkg/Include/Library/PcdLib.h>\r\n";
218 tokenArray
= dbManager
.getRecordArray();
219 for(index
= 0; index
< tokenArray
.length
; index
++) {
221 // Get one consumer instance and generate autogen for this token.
223 if(tokenArray
[index
].consumers
!= null ) {
224 if(tokenArray
[index
].consumers
.size() == 0) {
228 usageInstance
= tokenArray
[index
].consumers
.get(0);
230 usageInstance
.generateAutoGen();
231 } catch(EntityException exp
) {
232 throw new BuildActionException(exp
.getMessage());
235 hAutoGenString
+= usageInstance
.getHAutogenStr();
236 cAutoGenString
+= usageInstance
.getCAutogenStr();
238 hAutoGenString
+= "\r\n";
239 cAutoGenString
+= "\r\n";
243 generatePCDEmulatedArray(tokenArray
);
245 ActionMessage
.debug(this,
246 "PCD emulated driver's header: \r\n" + hAutoGenString
+ "\r\n"
248 ActionMessage
.debug(this,
249 "PCD emulated driver's C code: \r\n" + cAutoGenString
+ "\r\n"
255 Generate PCDEmulated array in PCDEmulated driver for emulated runtime database.
257 @param tokenArray All PCD token in memory database.
259 @throws BuildActionException Unknown PCD_TYPE
261 private void generatePCDEmulatedArray(Token
[] tokenArray
)
262 throws BuildActionException
{
265 String
[] guidStrArray
;
269 // The value of String type of PCD entry maybe use byte array but not string direcly
270 // such as {0x1, 0x2, 0x3}, and define PCD1_STRING_Value as L"string define here"
271 // For this case, we should generate a string array to C output and use the address
272 // of generated string array.
274 for(index
= 0; index
< tokenArray
.length
; index
++) {
275 token
= tokenArray
[index
];
277 if((token
.producers
.size() == 0) &&(token
.consumers
.size() == 0)) {
279 // If no one use this PCD token, it will not generated in emulated array.
283 value
= token
.datum
.toString();
284 if(token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
285 if(!((value
.charAt(0) == 'L' && value
.charAt(1) == '"') ||(value
.charAt(0) == '"'))) {
286 cAutoGenString
+= String
.format("UINT8 _mPcdArray%08x[] = %s;\r\n",
295 // Output emulated PCD entry array
297 cAutoGenString
+= "\r\nEMULATED_PCD_ENTRY gEmulatedPcdEntry[] = {\r\n";
299 for(index
= 0; index
< tokenArray
.length
; index
++) {
300 token
= tokenArray
[index
];
302 if((token
.producers
.size() == 0) &&(token
.consumers
.size() == 0)) {
304 // If no one use this PCD token, it will not generated in emulated array.
310 cAutoGenString
+= ",\r\n";
314 // Print Start "{" for a Token item in array
316 cAutoGenString
+= " {\r\n";
321 cAutoGenString
+= String
.format(" _PCD_TOKEN_%s,\r\n", token
.cName
);
324 // Print Hii information
326 if(token
.hiiEnabled
) {
327 cAutoGenString
+= String
.format(" TRUE,\r\n");
329 cAutoGenString
+= String
.format(" FALSE,\r\n");
333 // Print sku information
335 if(token
.skuEnabled
) {
336 cAutoGenString
+= String
.format(" TRUE,\r\n");
338 cAutoGenString
+= String
.format(" FALSE,\r\n");
344 cAutoGenString
+= String
.format(" %d,\r\n", token
.maxSkuCount
);
346 cAutoGenString
+= String
.format(" %d,\r\n", token
.skuId
);
348 if(token
.variableGuid
== null) {
349 cAutoGenString
+= " { 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },\r\n";
351 guidStrArray
=(token
.variableGuid
.toString()).split("-");
353 cAutoGenString
+= String
.format(" { 0x%s, 0x%s, 0x%s, { 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s } },\r\n",
357 (guidStrArray
[3].substring(0, 2)),
358 (guidStrArray
[3].substring(2, 4)),
359 (guidStrArray
[4].substring(0, 2)),
360 (guidStrArray
[4].substring(2, 4)),
361 (guidStrArray
[4].substring(4, 6)),
362 (guidStrArray
[4].substring(6, 8)),
363 (guidStrArray
[4].substring(8, 10)),
364 (guidStrArray
[4].substring(10, 12))
369 value
= token
.datum
.toString();
370 if(token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
371 if((value
.charAt(0) == 'L' && value
.charAt(1) == '"') || value
.charAt(0) == '"') {
372 cAutoGenString
+= String
.format(" sizeof(_PCD_VALUE_%s),\r\n", token
.cName
);
373 cAutoGenString
+= String
.format(" 0, %s, %s,\r\n", token
.variableName
, value
);
375 cAutoGenString
+= String
.format(" sizeof(_mPcdArray%08x),\r\n", index
);
376 cAutoGenString
+= String
.format(" 0, &_mPcdArray%08x, %s,\r\n", index
, token
.variableName
);
379 switch(token
.datumType
) {
381 cAutoGenString
+= " 1,\r\n";
384 cAutoGenString
+= " 2,\r\n";
387 cAutoGenString
+= " 4,\r\n";
390 cAutoGenString
+= " 8,\r\n";
393 cAutoGenString
+= " 1,\r\n";
396 throw new BuildActionException("Unknown datum size");
398 cAutoGenString
+= String
.format(" %s, %s, NULL,\r\n", value
, token
.variableName
);
402 // Print end "}" for a token item in array
404 cAutoGenString
+= " }";
407 cAutoGenString
+= "\r\n};\r\n";
408 cAutoGenString
+= "\r\n";
409 cAutoGenString
+= "UINTN\r\n";
410 cAutoGenString
+= "GetPcdDataBaseSize(\r\n";
411 cAutoGenString
+= " VOID\r\n";
412 cAutoGenString
+= " )\r\n";
413 cAutoGenString
+= "{\r\n";
414 cAutoGenString
+= " return sizeof(gEmulatedPcdEntry);\r\n";
415 cAutoGenString
+= "}\r\n";
421 @param argv paramter from command line
423 public static void main(String argv
[]) {
424 String logFilePath
= "G:/mdk/EdkNt32Pkg/build/Nt32.fpd";
427 // At first, CollectPCDAction should be invoked to collect
428 // all PCD information from SPD, MSA, FPD.
430 CollectPCDAction collectionAction
= new CollectPCDAction();
431 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db",
434 GlobalData
.getPCDMemoryDBManager().setLogFileName(logFilePath
+ ".PCDMemroyDatabaseLog.txt");
437 collectionAction
.perform("G:/mdk",
439 ActionMessage
.MAX_MESSAGE_LEVEL
);
440 } catch(Exception e
) {
445 // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c
447 PCDAutoGenAction autogenAction
= new PCDAutoGenAction("HelloWorld",
450 autogenAction
.execute();