import java.io.IOException;\r
import java.math.BigInteger;\r
import java.util.ArrayList;\r
-import java.util.Collections;\r
import java.util.Comparator;\r
import java.util.HashMap;\r
+import java.util.Iterator;\r
import java.util.List;\r
import java.util.Map;\r
+import java.util.Set;\r
import java.util.UUID;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
import org.apache.xmlbeans.XmlException;\r
import org.apache.xmlbeans.XmlObject;\r
-import org.tianocore.DynamicPcdBuildDefinitionsDocument;\r
import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r
-import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData;\r
-import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo;\r
import org.tianocore.FrameworkModulesDocument;\r
-import org.tianocore.FrameworkPlatformDescriptionDocument;\r
-import org.tianocore.FrameworkPlatformDescriptionDocument.FrameworkPlatformDescription;\r
+import org.tianocore.PlatformSurfaceAreaDocument;\r
+import org.tianocore.PcdBuildDefinitionDocument;\r
import org.tianocore.ModuleSADocument;\r
-import org.tianocore.ModuleSADocument.ModuleSA;\r
-import org.tianocore.PackageSurfaceAreaDocument;\r
import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;\r
+import org.tianocore.build.autogen.CommonDefinition;\r
import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
import org.tianocore.build.pcd.action.ActionMessage;\r
import org.tianocore.build.pcd.entity.DynamicTokenValue;\r
import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
import org.tianocore.build.pcd.entity.UsageInstance;\r
import org.tianocore.build.pcd.exception.EntityException;\r
\r
+/**\r
+ CStructTypeDeclaration \r
+ \r
+ This class is used to store the declaration string, such as\r
+ "UINT32 PcdPlatformFlashBaseAddress", of \r
+ each memember in the C structure, which is a standard C language\r
+ feature used to implement a simple and efficient database for\r
+ dynamic(ex) type PCD entry.\r
+**/\r
+\r
+class CStructTypeDeclaration {\r
+ String key;\r
+ int alignmentSize;\r
+ String cCode;\r
+ boolean initTable;\r
+ \r
+ public CStructTypeDeclaration (String key, int alignmentSize, String cCode, boolean initTable) {\r
+ this.key = key;\r
+ this.alignmentSize = alignmentSize;\r
+ this.cCode = cCode;\r
+ this.initTable = initTable;\r
+ }\r
+}\r
+\r
+/**\r
+ StringTable \r
+ \r
+ This class is used to store the String in a PCD database.\r
+ \r
+**/\r
class StringTable {\r
private ArrayList<String> al; \r
private ArrayList<String> alComments;\r
private String phase;\r
int len; \r
- int bodyStart;\r
- int bodyLineNum;\r
\r
public StringTable (String phase) {\r
this.phase = phase;\r
al = new ArrayList<String>();\r
alComments = new ArrayList<String>();\r
len = 0;\r
- bodyStart = 0;\r
- bodyLineNum = 0;\r
}\r
\r
public String getSizeMacro () {\r
return len == 0 ? 1 : len;\r
}\r
\r
- public int getTableLen () {\r
- return al.size() == 0 ? 1 : al.size();\r
- }\r
-\r
public String getExistanceMacro () {\r
return String.format(PcdDatabase.StringTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
}\r
-\r
- public String getTypeDeclaration () {\r
-\r
- String output;\r
-\r
+ \r
+ public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable) {\r
final String stringTable = "StringTable";\r
- final String tab = "\t";\r
- final String newLine = ";\r\n";\r
-\r
- output = "/* StringTable */\r\n";\r
-\r
- if (al.size() == 0) {\r
- output += tab + String.format("UINT16 %s[1] /* StringTable is Empty */", stringTable) + newLine;\r
- }\r
-\r
- for (int i = 0; i < al.size(); i++) {\r
- String str = al.get(i);\r
-\r
- if (i == 0) {\r
- //\r
- // StringTable is a well-known name in the PCD DXE driver\r
- //\r
- output += tab + String.format("UINT16 %s[%d] /* %s */", stringTable, str.length() + 1, alComments.get(i)) + newLine;\r
- } else {\r
- output += tab + String.format("UINT16 %s_%d[%d] /* %s */", stringTable, i, str.length() + 1, alComments.get(i)) + newLine;\r
- }\r
- }\r
-\r
- return output;\r
-\r
- }\r
-\r
- public ArrayList<String> getInstantiation () {\r
- ArrayList<String> output = new ArrayList<String>();\r
+ final String tab = "\t";\r
+ final String newLine = "\r\n";\r
+ final String commaNewLine = ",\r\n";\r
+ \r
+ CStructTypeDeclaration decl;\r
\r
- output.add("/* StringTable */"); \r
+ String cDeclCode = "";\r
+ String cInstCode = "";\r
\r
+ //\r
+ // If we have a empty StringTable\r
+ //\r
if (al.size() == 0) {\r
- output.add("{ 0 }");\r
+ cDeclCode += String.format("%-20s%s[1]; /* StringTable is empty */", "UINT16", stringTable) + newLine; \r
+ decl = new CStructTypeDeclaration (\r
+ stringTable,\r
+ 2,\r
+ cDeclCode,\r
+ true\r
+ ); \r
+ declaList.add(decl);\r
+\r
+ cInstCode = String.format("/* %s */", stringTable) + newLine + tab + "{ 0 }";\r
+ instTable.put(stringTable, cInstCode);\r
} else {\r
- String str;\r
\r
+ //\r
+ // If there is any String in the StringTable\r
+ //\r
for (int i = 0; i < al.size(); i++) {\r
- str = String.format("L\"%s\" /* %s */", al.get(i), alComments.get(i));\r
+ String str = al.get(i);\r
+ String stringTableName;\r
+ \r
+ if (i == 0) {\r
+ //\r
+ // StringTable is a well-known name in the PCD DXE driver\r
+ //\r
+ stringTableName = stringTable;\r
+ \r
+ } else {\r
+ stringTableName = String.format("%s_%d", stringTable, i);\r
+ cDeclCode += tab;\r
+ }\r
+ cDeclCode += String.format("%-20s%s[%d]; /* %s */", "UINT16", \r
+ stringTableName, str.length() + 1, \r
+ alComments.get(i)) \r
+ + newLine;\r
+ \r
+ if (i == 0) {\r
+ cInstCode = "/* StringTable */" + newLine;\r
+ }\r
+ \r
+ cInstCode += tab + String.format("L\"%s\" /* %s */", al.get(i), alComments.get(i));\r
if (i != al.size() - 1) {\r
- str += ",";\r
+ cInstCode += commaNewLine;\r
}\r
- output.add(str);\r
}\r
+ \r
+ decl = new CStructTypeDeclaration (\r
+ stringTable,\r
+ 2,\r
+ cDeclCode,\r
+ true\r
+ ); \r
+ declaList.add(decl);\r
+ \r
+ instTable.put(stringTable, cInstCode);\r
}\r
-\r
- return output;\r
}\r
\r
- public int add (String str, Token token) {\r
+ public int add (String inputStr, Token token) {\r
int i;\r
+ int pos;\r
+\r
+ String str = inputStr;\r
+ \r
+ //\r
+ // The input can be two types:\r
+ // "L\"Bootmode\"" or "Bootmode". \r
+ // We drop the L\" and \" for the first type. \r
+ if (str.startsWith("L\"") && str.endsWith("\"")) {\r
+ str = str.substring(2, str.length() - 1);\r
+ }\r
+ //\r
+ // Check if StringTable has this String already.\r
+ // If so, return the current pos.\r
+ //\r
+ for (i = 0, pos = 0; i < al.size(); i++) {\r
+ String s = al.get(i);;\r
\r
+ if (str.equals(s)) {\r
+ return pos;\r
+ }\r
+ pos = s.length() + 1;\r
+ }\r
+ \r
i = len;\r
//\r
// Include the NULL character at the end of String\r
}\r
}\r
\r
+/**\r
+ SizeTable \r
+ \r
+ This class is used to store the Size information for\r
+ POINTER TYPE PCD entry in a PCD database.\r
+\r
+**/\r
class SizeTable {\r
private ArrayList<Integer> al;\r
private ArrayList<String> alComments;\r
private String phase;\r
private int len;\r
- private int bodyStart;\r
- private int bodyLineNum;\r
-\r
+ \r
public SizeTable (String phase) {\r
this.phase = phase;\r
al = new ArrayList<Integer>();\r
alComments = new ArrayList<String>();\r
len = 0;\r
- bodyStart = 0;\r
- bodyLineNum = 0;\r
}\r
\r
- public String getTypeDeclaration () {\r
- return String.format(PcdDatabase.SizeTableDeclaration, phase);\r
+ public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
+ final String name = "SizeTable";\r
+ \r
+ CStructTypeDeclaration decl;\r
+ String cCode;\r
+\r
+ cCode = String.format(PcdDatabase.SizeTableDeclaration, phase); \r
+ decl = new CStructTypeDeclaration (\r
+ name,\r
+ 2,\r
+ cCode,\r
+ true\r
+ ); \r
+ declaList.add(decl);\r
+\r
+\r
+ cCode = PcdDatabase.genInstantiationStr(getInstantiation());\r
+ instTable.put(name, cCode);\r
}\r
\r
- public ArrayList<String> getInstantiation () {\r
+ private ArrayList<String> getInstantiation () {\r
ArrayList<String> Output = new ArrayList<String>();\r
\r
Output.add("/* SizeTable */");\r
Output.add("{");\r
- bodyStart = 2;\r
-\r
if (al.size() == 0) {\r
- Output.add("0");\r
+ Output.add("\t0");\r
} else {\r
for (int index = 0; index < al.size(); index++) {\r
Integer n = al.get(index);\r
- String str = n.toString();\r
+ String str = "\t" + n.toString();\r
\r
if (index != (al.size() - 1)) {\r
str += ",";\r
\r
str += " /* " + alComments.get(index) + " */"; \r
Output.add(str);\r
- bodyLineNum++;\r
\r
}\r
}\r
return Output;\r
}\r
\r
- public int getBodyStart() {\r
- return bodyStart;\r
- }\r
-\r
- public int getBodyLineNum () {\r
- return bodyLineNum;\r
- }\r
-\r
public int add (Token token) {\r
int index = len;\r
\r
return index;\r
}\r
\r
- private int getDatumSize(Token token) {\r
- /*\r
- switch (token.datumType) {\r
- case Token.DATUM_TYPE.UINT8:\r
- return 1;\r
- default:\r
- return 0;\r
- }\r
- */\r
- return 0;\r
- }\r
-\r
public int getTableLen () {\r
return al.size() == 0 ? 1 : al.size();\r
}\r
\r
}\r
\r
+/**\r
+ GuidTable \r
+ \r
+ This class is used to store the GUIDs in a PCD database.\r
+**/\r
class GuidTable {\r
private ArrayList<UUID> al;\r
private ArrayList<String> alComments;\r
private String phase;\r
private int len;\r
- private int bodyStart;\r
private int bodyLineNum;\r
\r
public GuidTable (String phase) {\r
al = new ArrayList<UUID>();\r
alComments = new ArrayList<String>();\r
len = 0;\r
- bodyStart = 0;\r
bodyLineNum = 0;\r
}\r
\r
return String.format(PcdDatabase.GuidTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
}\r
\r
- public String getTypeDeclaration () {\r
- return String.format(PcdDatabase.GuidTableDeclaration, phase);\r
+ public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
+ final String name = "GuidTable";\r
+ \r
+ CStructTypeDeclaration decl;\r
+ String cCode = "";\r
+\r
+ cCode += String.format(PcdDatabase.GuidTableDeclaration, phase); \r
+ decl = new CStructTypeDeclaration (\r
+ name,\r
+ 8,\r
+ cCode,\r
+ true\r
+ ); \r
+ declaList.add(decl);\r
+\r
+\r
+ cCode = PcdDatabase.genInstantiationStr(getInstantiation());\r
+ instTable.put(name, cCode);\r
}\r
\r
private String getUuidCString (UUID uuid) {\r
\r
guidStrArray =(uuid.toString()).split("-");\r
\r
- return 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
+ return 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
guidStrArray[0],\r
guidStrArray[1],\r
guidStrArray[2],\r
);\r
}\r
\r
- public ArrayList<String> getInstantiation () {\r
+ private ArrayList<String> getInstantiation () {\r
ArrayList<String> Output = new ArrayList<String>();\r
\r
Output.add("/* GuidTable */");\r
Output.add("{");\r
- bodyStart = 2;\r
\r
if (al.size() == 0) {\r
- Output.add(getUuidCString(new UUID(0, 0)));\r
+ Output.add("\t" + getUuidCString(new UUID(0, 0)));\r
}\r
\r
- for (Object u : al) {\r
- UUID uuid = (UUID)u;\r
- String str = getUuidCString(uuid);\r
+ for (int i = 0; i < al.size(); i++) {\r
+ String str = "\t" + getUuidCString(al.get(i));\r
\r
- if (al.indexOf(u) != (al.size() - 1)) {\r
+ str += "/* " + alComments.get(i) + " */";\r
+ if (i != (al.size() - 1)) {\r
str += ",";\r
}\r
Output.add(str);\r
return Output;\r
}\r
\r
- public int getBodyStart() {\r
- return bodyStart;\r
- }\r
-\r
- public int getBodyLineNum () {\r
- return bodyLineNum;\r
- }\r
-\r
public int add (UUID uuid, String name) {\r
- int index = len;\r
//\r
- // Include the NULL character at the end of String\r
+ // Check if GuidTable has this entry already.\r
+ // If so, return the GuidTable index.\r
//\r
+ for (int i = 0; i < al.size(); i++) {\r
+ if (al.get(i).equals(uuid)) {\r
+ return i;\r
+ }\r
+ }\r
+ \r
len++; \r
al.add(uuid);\r
+ alComments.add(name);\r
\r
- return index;\r
- }\r
-\r
- public int getTableLen () {\r
- return al.size() == 0 ? 0 : al.size();\r
+ //\r
+ // Return the previous Table Index\r
+ //\r
+ return len - 1;\r
}\r
\r
}\r
\r
+/**\r
+ SkuIdTable \r
+ \r
+ This class is used to store the SKU IDs in a PCD database.\r
+\r
+**/\r
class SkuIdTable {\r
private ArrayList<Integer[]> al;\r
private ArrayList<String> alComment;\r
private String phase;\r
private int len;\r
- private int bodyStart;\r
- private int bodyLineNum;\r
\r
public SkuIdTable (String phase) {\r
this.phase = phase;\r
al = new ArrayList<Integer[]>();\r
alComment = new ArrayList<String>();\r
- bodyStart = 0;\r
- bodyLineNum = 0;\r
len = 0;\r
}\r
\r
}\r
\r
private int getSize () {\r
- return (al.size() == 0)? 1 : al.size();\r
+ return (len == 0)? 1 : len;\r
}\r
\r
public String getExistanceMacro () {\r
return String.format(PcdDatabase.SkuTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
}\r
\r
- public String getTypeDeclaration () {\r
- return String.format(PcdDatabase.SkuIdTableDeclaration, phase);\r
+ public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
+ final String name = "SkuIdTable";\r
+ \r
+ CStructTypeDeclaration decl;\r
+ String cCode = "";\r
+\r
+ cCode += String.format(PcdDatabase.SkuIdTableDeclaration, phase); \r
+ decl = new CStructTypeDeclaration (\r
+ name,\r
+ 1,\r
+ cCode,\r
+ true\r
+ ); \r
+ declaList.add(decl);\r
+\r
+\r
+ cCode = PcdDatabase.genInstantiationStr(getInstantiation());\r
+ instTable.put(name, cCode);\r
+\r
+ //\r
+ // SystemSkuId is in PEI phase PCD Database\r
+ //\r
+ if (phase.equalsIgnoreCase("PEI")) {\r
+ decl = new CStructTypeDeclaration (\r
+ "SystemSkuId",\r
+ 1,\r
+ String.format("%-20sSystemSkuId;\r\n", "SKU_ID"),\r
+ true\r
+ );\r
+ declaList.add(decl);\r
+ \r
+ instTable.put("SystemSkuId", "0");\r
+ }\r
+\r
}\r
\r
- public ArrayList<String> getInstantiation () {\r
+ private ArrayList<String> getInstantiation () {\r
ArrayList<String> Output = new ArrayList<String> ();\r
\r
Output.add("/* SkuIdTable */");\r
Output.add("{");\r
- bodyStart = 2;\r
\r
if (al.size() == 0) {\r
- Output.add("0");\r
+ Output.add("\t0");\r
}\r
\r
for (int index = 0; index < al.size(); index++) {\r
\r
Integer[] ia = al.get(index);\r
\r
- str += ia[0].toString() + ", ";\r
+ str += "\t" + ia[0].toString() + ", ";\r
for (int index2 = 1; index2 < ia.length; index2++) {\r
str += ia[index2].toString();\r
- if (index != al.size() - 1) {\r
+ if (!((index2 == ia.length - 1) && (index == al.size() - 1))) {\r
str += ", ";\r
}\r
}\r
\r
Output.add(str);\r
- bodyLineNum++;\r
\r
}\r
\r
public int add (Token token) {\r
\r
int index;\r
+ int pos;\r
+ \r
+ //\r
+ // Check if this SKU_ID Array is already in the table\r
+ //\r
+ pos = 0;\r
+ for (Object o: al) {\r
+ Integer [] s = (Integer[]) o;\r
+ boolean different = false;\r
+ if (s[0] == token.getSkuIdCount()) {\r
+ for (index = 1; index < s.length; index++) {\r
+ if (s[index] != token.skuData.get(index-1).id) {\r
+ different = true;\r
+ break;\r
+ }\r
+ }\r
+ } else {\r
+ different = true;\r
+ }\r
+ if (different) {\r
+ pos += s[0] + 1;\r
+ } else {\r
+ return pos;\r
+ }\r
+ }\r
\r
Integer [] skuIds = new Integer[token.skuData.size() + 1];\r
skuIds[0] = new Integer(token.skuData.size());\r
return index;\r
}\r
\r
- public int getTableLen () {\r
- return al.size() == 0 ? 1 : al.size();\r
- }\r
-\r
}\r
\r
class LocalTokenNumberTable {\r
return String.format(PcdDatabase.DatabaseExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
}\r
\r
- public String getTypeDeclaration () {\r
- return String.format(PcdDatabase.LocalTokenNumberTableDeclaration, phase);\r
+ public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
+ final String name = "LocalTokenNumberTable";\r
+ \r
+ CStructTypeDeclaration decl;\r
+ String cCode = "";\r
+\r
+ cCode += String.format(PcdDatabase.LocalTokenNumberTableDeclaration, phase); \r
+ decl = new CStructTypeDeclaration (\r
+ name,\r
+ 4,\r
+ cCode,\r
+ true\r
+ ); \r
+ declaList.add(decl);\r
+\r
+ cCode = PcdDatabase.genInstantiationStr(getInstantiation());\r
+ instTable.put(name, cCode);\r
}\r
\r
- public ArrayList<String> getInstantiation () {\r
+ private ArrayList<String> getInstantiation () {\r
ArrayList<String> output = new ArrayList<String>();\r
\r
output.add("/* LocalTokenNumberTable */");\r
output.add("{");\r
\r
if (al.size() == 0) {\r
- output.add("0");\r
+ output.add("\t0");\r
}\r
\r
for (int index = 0; index < al.size(); index++) {\r
String str;\r
\r
- str = (String)al.get(index);\r
+ str = "\t" + (String)al.get(index);\r
\r
str += " /* " + alComment.get(index) + " */ ";\r
\r
}\r
}\r
\r
+/**\r
+ ExMapTable \r
+ \r
+ This class is used to store the table of mapping information\r
+ between DynamicEX ID pair(Guid, TokenNumber) and\r
+ the local token number assigned by PcdDatabase class.\r
+**/\r
class ExMapTable {\r
\r
+ /**\r
+ ExTriplet \r
+ \r
+ This class is used to store the mapping information\r
+ between DynamicEX ID pair(Guid, TokenNumber) and\r
+ the local token number assigned by PcdDatabase class.\r
+ **/\r
class ExTriplet {\r
public Integer guidTableIdx;\r
public Long exTokenNumber;\r
private ArrayList<String> alComment;\r
private String phase;\r
private int len;\r
- private int bodyStart;\r
private int bodyLineNum;\r
- private int base;\r
-\r
+ \r
public ExMapTable (String phase) {\r
this.phase = phase;\r
al = new ArrayList<ExTriplet>();\r
alComment = new ArrayList<String>();\r
- bodyStart = 0;\r
bodyLineNum = 0;\r
len = 0;\r
}\r
+ String.format(PcdDatabase.ExTokenNumber, phase, al.size());\r
}\r
\r
- private int getSize () {\r
- return (al.size() == 0)? 1 : al.size();\r
- }\r
-\r
public String getExistanceMacro () {\r
return String.format(PcdDatabase.ExMapTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
}\r
\r
- public String getTypeDeclaration () {\r
- return String.format(PcdDatabase.ExMapTableDeclaration, phase);\r
- }\r
+ public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
+ final String exMapTableName = "ExMapTable";\r
+ \r
+ sortTable();\r
+ \r
+ CStructTypeDeclaration decl;\r
+ String cCode = "";\r
+\r
+ cCode += String.format(PcdDatabase.ExMapTableDeclaration, phase); \r
+ decl = new CStructTypeDeclaration (\r
+ exMapTableName,\r
+ 4,\r
+ cCode,\r
+ true\r
+ ); \r
+ declaList.add(decl);\r
\r
- public ArrayList<String> getInstantiation () {\r
+\r
+ cCode = PcdDatabase.genInstantiationStr(getInstantiation());\r
+ instTable.put(exMapTableName, cCode);\r
+ }\r
+ \r
+ private ArrayList<String> getInstantiation () {\r
ArrayList<String> Output = new ArrayList<String>();\r
\r
Output.add("/* ExMapTable */");\r
Output.add("{");\r
- bodyStart = 2;\r
-\r
if (al.size() == 0) {\r
- Output.add("{0, 0, 0}");\r
+ Output.add("\t{0, 0, 0}");\r
}\r
\r
int index;\r
\r
ExTriplet e = (ExTriplet)al.get(index);\r
\r
- str = "{ " + e.exTokenNumber.toString() + ", ";\r
+ str = "\t" + "{ " + String.format("0x%08X", e.exTokenNumber) + ", ";\r
str += e.localTokenIdx.toString() + ", ";\r
str += e.guidTableIdx.toString();\r
\r
- str += " /* " + alComment.get(index) + " */";\r
+ str += "}" + " /* " + alComment.get(index) + " */" ;\r
\r
if (index != al.size() - 1) {\r
str += ",";\r
return index;\r
}\r
\r
- public int getTableLen () {\r
+ private int getTableLen () {\r
return al.size() == 0 ? 1 : al.size();\r
}\r
\r
+ //\r
+ // To simplify the algorithm for GetNextToken and GetNextTokenSpace in\r
+ // PCD PEIM/Driver, we need to sort the ExMapTable according to the\r
+ // following order:\r
+ // 1) ExGuid\r
+ // 2) ExTokenNumber\r
+ // \r
+ class ExTripletComp implements Comparator<ExTriplet> {\r
+ public int compare (ExTriplet a, ExTriplet b) {\r
+ if (a.guidTableIdx == b.guidTableIdx ) {\r
+ //\r
+ // exTokenNumber is long, we can't use simple substraction.\r
+ //\r
+ if (a.exTokenNumber > b.exTokenNumber) {\r
+ return 1;\r
+ } else if (a.exTokenNumber == b.exTokenNumber) {\r
+ return 0;\r
+ } else {\r
+ return -1;\r
+ }\r
+ }\r
+ \r
+ return a.guidTableIdx - b.guidTableIdx;\r
+ }\r
+ }\r
+\r
+ private void sortTable () {\r
+ java.util.Comparator<ExTriplet> comparator = new ExTripletComp();\r
+ java.util.Collections.sort(al, comparator);\r
+ }\r
}\r
\r
+/**\r
+ PcdDatabase \r
+ \r
+ This class is used to generate C code for Autogen.h and Autogen.c of\r
+ a PCD service DXE driver and PCD service PEIM.\r
+**/\r
class PcdDatabase {\r
\r
- public final static String ExMapTableDeclaration = "DYNAMICEX_MAPPING ExMapTable[%s_EXMAPPING_TABLE_SIZE];\r\n";\r
- public final static String GuidTableDeclaration = "EFI_GUID GuidTable[%s_GUID_TABLE_SIZE];\r\n";\r
- public final static String LocalTokenNumberTableDeclaration = "UINT32 LocalTokenNumberTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";\r
- public final static String StringTableDeclaration = "UINT16 StringTable[%s_STRING_TABLE_SIZE];\r\n";\r
- public final static String SizeTableDeclaration = "UINT16 SizeTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";\r
- public final static String SkuIdTableDeclaration = "UINT8 SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n";\r
+ private final static int SkuHeadAlignmentSize = 4;\r
+ private final String newLine = "\r\n";\r
+ private final String commaNewLine = ",\r\n";\r
+ private final String tab = "\t";\r
+ public final static String ExMapTableDeclaration = "DYNAMICEX_MAPPING ExMapTable[%s_EXMAPPING_TABLE_SIZE];\r\n";\r
+ public final static String GuidTableDeclaration = "EFI_GUID GuidTable[%s_GUID_TABLE_SIZE];\r\n";\r
+ public final static String LocalTokenNumberTableDeclaration = "UINT32 LocalTokenNumberTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";\r
+ public final static String StringTableDeclaration = "UINT16 StringTable[%s_STRING_TABLE_SIZE];\r\n";\r
+ public final static String SizeTableDeclaration = "UINT16 SizeTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";\r
+ public final static String SkuIdTableDeclaration = "UINT8 SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n";\r
\r
\r
public final static String ExMapTableSizeMacro = "#define %s_EXMAPPING_TABLE_SIZE %d\r\n";\r
public final static String ExTokenNumber = "#define %s_EX_TOKEN_NUMBER %d\r\n";\r
- public final static String GuidTableSizeMacro = "#define %s_GUID_TABLE_SIZE %d\r\n";\r
+ public final static String GuidTableSizeMacro = "#define %s_GUID_TABLE_SIZE %d\r\n"; \r
public final static String LocalTokenNumberTableSizeMacro = "#define %s_LOCAL_TOKEN_NUMBER_TABLE_SIZE %d\r\n";\r
public final static String LocalTokenNumberSizeMacro = "#define %s_LOCAL_TOKEN_NUMBER %d\r\n";\r
public final static String StringTableSizeMacro = "#define %s_STRING_TABLE_SIZE %d\r\n";\r
public final static String SkuTableExistenceMacro = "#define %s_SKUID_TABLE_EMPTY %s\r\n";\r
\r
public final static String offsetOfSkuHeadStrTemplate = "offsetof(%s_PCD_DATABASE, %s.%s_SkuDataTable)";\r
+ public final static String offsetOfVariableEnabledDefault = "offsetof(%s_PCD_DATABASE, %s.%s_VariableDefault_%d)";\r
public final static String offsetOfStrTemplate = "offsetof(%s_PCD_DATABASE, %s.%s)";\r
+ \r
+ private final static String skuDataTableTemplate = "SkuDataTable";\r
+\r
\r
private StringTable stringTable;\r
private GuidTable guidTable;\r
private String phase;\r
private int assignedTokenNumber;\r
\r
+ //\r
+ // Use two class global variable to store\r
+ // temperary \r
+ //\r
+ private String privateGlobalName;\r
+ private String privateGlobalCCode;\r
//\r
// After Major changes done to the PCD\r
// database generation class PcdDatabase\r
// also update the version number in PCD\r
// service PEIM and DXE driver accordingly.\r
//\r
- private final int version = 1;\r
+ private final int version = 2;\r
\r
private String hString;\r
private String cString;\r
\r
-\r
- class AlignmentSizeComp implements Comparator<Token> {\r
- public int compare (Token a, Token b) {\r
- return getAlignmentSize(b) \r
- - getAlignmentSize(a);\r
- }\r
- }\r
-\r
+ /**\r
+ Constructor for PcdDatabase class. \r
+ \r
+ <p>We have two PCD dynamic(ex) database for the Framework implementation. One\r
+ for PEI phase and the other for DXE phase. </p>\r
+ \r
+ @param alTokens A ArrayList of Dynamic(EX) PCD entry.\r
+ @param exePhase The phase to generate PCD database for: valid input\r
+ is "PEI" or "DXE".\r
+ @param startLen The starting Local Token Number for the PCD database. For\r
+ PEI phase, the starting Local Token Number starts from 0.\r
+ For DXE phase, the starting Local Token Number starts\r
+ from the total number of PCD entry of PEI phase.\r
+ @return void\r
+ **/\r
public PcdDatabase (ArrayList<Token> alTokens, String exePhase, int startLen) {\r
phase = exePhase;\r
\r
sizeTable = new SizeTable(phase);\r
exMapTable = new ExMapTable(phase); \r
\r
- assignedTokenNumber = startLen;\r
+ //\r
+ // Local token number 0 is reserved for INVALID_TOKEN_NUMBER.\r
+ // So we will increment 1 for the startLen passed from the \r
+ // constructor.\r
+ //\r
+ assignedTokenNumber = startLen + 1;\r
this.alTokens = alTokens;\r
}\r
\r
- private void getTwoGroupsOfTokens (ArrayList<Token> alTokens, List<Token> initTokens, List<Token> uninitTokens) {\r
+ private void getNonExAndExTokens (ArrayList<Token> alTokens, List<Token> nexTokens, List<Token> exTokens) {\r
for (int i = 0; i < alTokens.size(); i++) {\r
Token t = (Token)alTokens.get(i);\r
- if (t.hasDefaultValue()) {\r
- initTokens.add(t);\r
+ if (t.isDynamicEx()) {\r
+ exTokens.add(t);\r
} else {\r
- uninitTokens.add(t);\r
+ nexTokens.add(t);\r
}\r
}\r
\r
return;\r
}\r
\r
+ private int getDataTypeAlignmentSize (Token token) {\r
+ switch (token.datumType) {\r
+ case UINT8:\r
+ return 1;\r
+ case UINT16:\r
+ return 2;\r
+ case UINT32:\r
+ return 4;\r
+ case UINT64:\r
+ return 8;\r
+ case POINTER:\r
+ return 1;\r
+ case BOOLEAN:\r
+ return 1;\r
+ default:\r
+ return 1;\r
+ }\r
+ }\r
+ \r
+ private int getHiiPtrTypeAlignmentSize(Token token) {\r
+ switch (token.datumType) {\r
+ case UINT8:\r
+ return 1;\r
+ case UINT16:\r
+ return 2;\r
+ case UINT32:\r
+ return 4;\r
+ case UINT64:\r
+ return 8;\r
+ case POINTER:\r
+ if (token.isHiiEnable()) {\r
+ if (token.isHiiDefaultValueUnicodeStringType()) {\r
+ return 2;\r
+ }\r
+ }\r
+ return 1;\r
+ case BOOLEAN:\r
+ return 1;\r
+ default:\r
+ return 1;\r
+ }\r
+ }\r
+ \r
private int getAlignmentSize (Token token) {\r
if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {\r
return 2;\r
if (token.isUnicodeStringType()) {\r
return 2;\r
}\r
-\r
- switch (token.datumType) {\r
- case UINT8:\r
- return 1;\r
- case UINT16:\r
- return 2;\r
- case UINT32:\r
- return 4;\r
- case UINT64:\r
- return 8;\r
- case POINTER:\r
- return 1;\r
- case BOOLEAN:\r
- return 1;\r
- }\r
- return 1;\r
+ \r
+ return getDataTypeAlignmentSize(token);\r
}\r
\r
public String getCString () {\r
public String getHString () {\r
return hString;\r
}\r
+ \r
+ private void genCodeWorker(Token t,\r
+ ArrayList<CStructTypeDeclaration> declaList,\r
+ HashMap<String, String> instTable, String phase)\r
+ throws EntityException {\r
\r
- public void genCode () \r
- throws EntityException {\r
+ CStructTypeDeclaration decl;\r
\r
- final String newLine = "\r\n";\r
- final String declNewLine = ";\r\n";\r
- final String tab = "\t";\r
- final String commaNewLine = ", \r\n";\r
+ //\r
+ // Insert SKU_HEAD if isSkuEnable is true\r
+ //\r
+ if (t.isSkuEnable()) {\r
+ int tableIdx;\r
+ tableIdx = skuIdTable.add(t);\r
+ decl = new CStructTypeDeclaration(t.getPrimaryKeyString(),\r
+ SkuHeadAlignmentSize, getSkuEnabledTypeDeclaration(t), true);\r
+ declaList.add(decl);\r
+ instTable.put(t.getPrimaryKeyString(),\r
+ getSkuEnabledTypeInstantiaion(t, tableIdx));\r
+ }\r
\r
- int i;\r
- ArrayList<String> decla;\r
- ArrayList<String> inst;\r
+ //\r
+ // Insert PCD_ENTRY declaration and instantiation\r
+ //\r
+ getCDeclarationString(t);\r
\r
- String macroStr = "";\r
- String initDeclStr = "";\r
- String initInstStr = "";\r
- String uninitDeclStr = "";\r
+ decl = new CStructTypeDeclaration(privateGlobalName,\r
+ getAlignmentSize(t), privateGlobalCCode, t.hasDefaultValue());\r
+ declaList.add(decl);\r
\r
- List<Token> initTokens = new ArrayList<Token> ();\r
- List<Token> uninitTokens = new ArrayList<Token> ();\r
+ if (t.hasDefaultValue()) {\r
+ instTable.put(privateGlobalName, \r
+ getTypeInstantiation(t, declaList, instTable, phase)\r
+ );\r
+ }\r
+\r
+ }\r
+\r
+ private void ProcessTokens (List<Token> tokens, \r
+ ArrayList<CStructTypeDeclaration> cStructDeclList,\r
+ HashMap<String, String> cStructInstTable,\r
+ String phase\r
+ ) \r
+ throws EntityException {\r
\r
- HashMap <String, ArrayList<String>> initCode = new HashMap<String, ArrayList<String>> ();\r
- HashMap <String, ArrayList<String>> uninitCode = new HashMap<String, ArrayList<String>> ();\r
+ for (int idx = 0; idx < tokens.size(); idx++) {\r
+ Token t = tokens.get(idx);\r
+ \r
+ genCodeWorker (t, cStructDeclList, cStructInstTable, phase);\r
+ \r
+ sizeTable.add(t);\r
+ localTokenNumberTable.add(t);\r
+ t.tokenNumber = assignedTokenNumber++;\r
+ \r
+ //\r
+ // Add a mapping if this dynamic PCD entry is a EX type\r
+ //\r
+ if (t.isDynamicEx()) {\r
+ exMapTable.add((int)t.tokenNumber, \r
+ t.dynamicExTokenNumber, \r
+ guidTable.add(t.tokenSpaceName, t.getPrimaryKeyString()), \r
+ t.getPrimaryKeyString()\r
+ );\r
+ }\r
+ }\r
\r
- getTwoGroupsOfTokens (alTokens, initTokens, uninitTokens);\r
+ }\r
+ \r
+ public void genCode () throws EntityException {\r
+ \r
+ ArrayList<CStructTypeDeclaration> cStructDeclList = new ArrayList<CStructTypeDeclaration>();\r
+ HashMap<String, String> cStructInstTable = new HashMap<String, String>();\r
+ \r
+ List<Token> nexTokens = new ArrayList<Token> ();\r
+ List<Token> exTokens = new ArrayList<Token> ();\r
\r
- //\r
- // Generate Structure Declaration for PcdTokens without Default Value\r
- // PEI_PCD_DATABASE_INIT\r
- //\r
- java.util.Comparator<Token> comparator = new AlignmentSizeComp();\r
- java.util.Collections.sort(initTokens, comparator);\r
- initCode = processTokens(initTokens);\r
+ getNonExAndExTokens (alTokens, nexTokens, exTokens);\r
\r
//\r
- // Generate Structure Declaration for PcdTokens without Default Value\r
- // PEI_PCD_DATABASE_UNINIT\r
+ // We have to process Non-Ex type PCD entry first. The reason is\r
+ // that our optimization assumes that the Token Number of Non-Ex \r
+ // PCD entry start from 1 (for PEI phase) and grows continously upwards.\r
+ // \r
+ // EX type token number starts from the last Non-EX PCD entry and\r
+ // grows continously upwards.\r
//\r
- java.util.Collections.sort(uninitTokens, comparator);\r
- uninitCode = processTokens(uninitTokens);\r
+ ProcessTokens (nexTokens, cStructDeclList, cStructInstTable, phase);\r
+ ProcessTokens (exTokens, cStructDeclList, cStructInstTable, phase);\r
+ \r
+ stringTable.genCode(cStructDeclList, cStructInstTable);\r
+ skuIdTable.genCode(cStructDeclList, cStructInstTable, phase);\r
+ exMapTable.genCode(cStructDeclList, cStructInstTable, phase);\r
+ localTokenNumberTable.genCode(cStructDeclList, cStructInstTable, phase);\r
+ sizeTable.genCode(cStructDeclList, cStructInstTable, phase);\r
+ guidTable.genCode(cStructDeclList, cStructInstTable, phase);\r
+ \r
+ hString = genCMacroCode ();\r
+ \r
+ HashMap <String, String> result;\r
+ \r
+ result = genCStructCode(cStructDeclList, \r
+ cStructInstTable, \r
+ phase\r
+ );\r
+ \r
+ hString += result.get("initDeclStr");\r
+ hString += result.get("uninitDeclStr");\r
+ \r
+ hString += String.format("#define PCD_%s_SERVICE_DRIVER_VERSION %d", phase, version);\r
+ \r
+ cString = newLine + newLine + result.get("initInstStr");\r
+ \r
+ }\r
+ \r
+ private String genCMacroCode () {\r
+ String macroStr = "";\r
\r
//\r
// Generate size info Macro for all Tables\r
macroStr += localTokenNumberTable.getExistanceMacro();\r
macroStr += exMapTable.getExistanceMacro();\r
\r
+ macroStr += newLine;\r
+ \r
+ return macroStr;\r
+ }\r
+ \r
+ private HashMap <String, String> genCStructCode(\r
+ ArrayList<CStructTypeDeclaration> declaList, \r
+ HashMap<String, String> instTable, \r
+ String phase\r
+ ) {\r
+ \r
+ int i;\r
+ HashMap <String, String> result = new HashMap<String, String>();\r
+ HashMap <Integer, ArrayList<String>> alignmentInitDecl = new HashMap<Integer, ArrayList<String>>();\r
+ HashMap <Integer, ArrayList<String>> alignmentUninitDecl = new HashMap<Integer, ArrayList<String>>();\r
+ HashMap <Integer, ArrayList<String>> alignmentInitInst = new HashMap<Integer, ArrayList<String>>();\r
+ \r
//\r
- // Generate Structure Declaration for PcdTokens with Default Value\r
- // for example PEI_PCD_DATABASE_INIT\r
+ // Initialize the storage for each alignment\r
//\r
- initDeclStr += "typedef struct {" + newLine;\r
- {\r
- initDeclStr += tab + exMapTable.getTypeDeclaration();\r
- initDeclStr += tab + guidTable.getTypeDeclaration();\r
- initDeclStr += tab + localTokenNumberTable.getTypeDeclaration();\r
- initDeclStr += tab + stringTable.getTypeDeclaration();\r
- initDeclStr += tab + sizeTable.getTypeDeclaration();\r
- initDeclStr += tab + skuIdTable.getTypeDeclaration();\r
- if (phase.equalsIgnoreCase("PEI")) {\r
- initDeclStr += tab + "SKU_ID SystemSkuId;" + newLine;\r
- }\r
-\r
- decla = initCode.get(new String("Declaration"));\r
- for (i = 0; i < decla.size(); i++) {\r
- initDeclStr += tab + decla.get(i) + declNewLine;\r
- }\r
-\r
- //\r
- // Generate Structure Declaration for PcdToken with SkuEnabled\r
- //\r
- decla = initCode.get("DeclarationForSku");\r
-\r
- for (i = 0; i < decla.size(); i++) {\r
- initDeclStr += tab + decla.get(i) + declNewLine;\r
- }\r
- }\r
- initDeclStr += String.format("} %s_PCD_DATABASE_INIT;\r\n\r\n", phase);\r
+ for (i = 8; i > 0; i>>=1) {\r
+ alignmentInitDecl.put(new Integer(i), new ArrayList<String>());\r
+ alignmentInitInst.put(new Integer(i), new ArrayList<String>());\r
+ alignmentUninitDecl.put(new Integer(i), new ArrayList<String>());\r
+ }\r
+ \r
+ String initDeclStr = "typedef struct {" + newLine;\r
+ String initInstStr = String.format("%s_PCD_DATABASE_INIT g%sPcdDbInit = { ", phase.toUpperCase(), phase.toUpperCase()) + newLine;\r
+ String uninitDeclStr = "typedef struct {" + newLine;\r
\r
//\r
- // Generate MACRO for structure intialization of PCDTokens with Default Value\r
- // The sequence must match the sequence of declaration of the memembers in the structure\r
- String tmp = String.format("%s_PCD_DATABASE_INIT g%sPcdDbInit = { ", phase.toUpperCase(), phase.toUpperCase());\r
- initInstStr += tmp + newLine;\r
- initInstStr += tab + genInstantiationStr(exMapTable.getInstantiation()) + commaNewLine;\r
- initInstStr += tab + genInstantiationStr(guidTable.getInstantiation()) + commaNewLine;\r
- initInstStr += tab + genInstantiationStr(localTokenNumberTable.getInstantiation()) + commaNewLine; \r
- initInstStr += tab + genInstantiationStr(stringTable.getInstantiation()) + commaNewLine;\r
- initInstStr += tab + genInstantiationStr(sizeTable.getInstantiation()) + commaNewLine;\r
- initInstStr += tab + genInstantiationStr(skuIdTable.getInstantiation()) + commaNewLine;\r
- //\r
- // For SystemSkuId\r
+ // Sort all C declaration and instantiation base on Alignment Size \r
//\r
- if (phase.equalsIgnoreCase("PEI")) {\r
- initInstStr += tab + "0" + tab + "/* SystemSkuId */" + commaNewLine;\r
- }\r
-\r
- inst = initCode.get("Instantiation");\r
- for (i = 0; i < inst.size(); i++) {\r
- initInstStr += tab + inst.get(i) + commaNewLine;\r
- }\r
-\r
- inst = initCode.get("InstantiationForSku");\r
- for (i = 0; i < inst.size(); i++) {\r
- initInstStr += tab + inst.get(i);\r
- if (i != inst.size() - 1) {\r
- initInstStr += commaNewLine;\r
+ for (Object d : declaList) {\r
+ CStructTypeDeclaration decl = (CStructTypeDeclaration) d;\r
+ \r
+ if (decl.initTable) {\r
+ alignmentInitDecl.get(new Integer(decl.alignmentSize)).add(decl.cCode);\r
+ alignmentInitInst.get(new Integer(decl.alignmentSize)).add(instTable.get(decl.key));\r
+ } else {\r
+ alignmentUninitDecl.get(new Integer(decl.alignmentSize)).add(decl.cCode);\r
}\r
}\r
\r
- initInstStr += "};";\r
-\r
- uninitDeclStr += "typedef struct {" + newLine;\r
- {\r
- decla = uninitCode.get("Declaration");\r
- if (decla.size() == 0) {\r
- uninitDeclStr += "UINT8 dummy /* The UINT struct is empty */" + declNewLine;\r
+ //\r
+ // Generate code for every alignment size\r
+ //\r
+ boolean uinitDatabaseEmpty = true;\r
+ for (int align = 8; align > 0; align >>= 1) {\r
+ ArrayList<String> declaListBasedOnAlignment = alignmentInitDecl.get(new Integer(align));\r
+ ArrayList<String> instListBasedOnAlignment = alignmentInitInst.get(new Integer(align));\r
+ for (i = 0; i < declaListBasedOnAlignment.size(); i++) {\r
+ initDeclStr += tab + declaListBasedOnAlignment.get(i);\r
+ initInstStr += tab + instListBasedOnAlignment.get(i);\r
+ \r
+ //\r
+ // We made a assumption that both PEI_PCD_DATABASE and DXE_PCD_DATABASE\r
+ // has a least one data memember with alignment size of 1. So we can\r
+ // remove the last "," in the C structure instantiation string. Luckily,\r
+ // this is true as both data structure has SKUID_TABLE anyway.\r
+ //\r
+ if ((align == 1) && (i == declaListBasedOnAlignment.size() - 1)) {\r
+ initInstStr += newLine;\r
} else {\r
- \r
- for (i = 0; i < decla.size(); i++) {\r
- uninitDeclStr += tab + decla.get(i) + declNewLine;\r
- }\r
- \r
- decla = uninitCode.get("DeclarationForSku");\r
- \r
- for (i = 0; i < decla.size(); i++) {\r
- uninitDeclStr += tab + decla.get(i) + declNewLine;\r
- }\r
+ initInstStr += commaNewLine;\r
}\r
}\r
- uninitDeclStr += String.format("} %s_PCD_DATABASE_UNINIT;\r\n\r\n", phase);\r
-\r
- cString = initInstStr + newLine;\r
- hString = macroStr + newLine \r
- + initDeclStr + newLine\r
- + uninitDeclStr + newLine\r
- + newLine;\r
+ \r
+ declaListBasedOnAlignment = alignmentUninitDecl.get(new Integer(align));\r
+ \r
+ if (declaListBasedOnAlignment.size() != 0) {\r
+ uinitDatabaseEmpty = false;\r
+ }\r
+ \r
+ for (Object d : declaListBasedOnAlignment) {\r
+ String s = (String)d;\r
+ uninitDeclStr += tab + s;\r
+ }\r
+ }\r
+ \r
+ if (uinitDatabaseEmpty) {\r
+ uninitDeclStr += tab + String.format("%-20sdummy; /* PCD_DATABASE_UNINIT is emptry */\r\n", "UINT8");\r
+ }\r
+ \r
+ initDeclStr += String.format("} %s_PCD_DATABASE_INIT;", phase) + newLine + newLine;\r
+ initInstStr += "};" + newLine;\r
+ uninitDeclStr += String.format("} %s_PCD_DATABASE_UNINIT;", phase) + newLine + newLine;\r
\r
- hString += String.format("#define PCD_%s_SERVICE_DRIVER_VERSION %d", phase, version);\r
+ result.put("initDeclStr", initDeclStr);\r
+ result.put("initInstStr", initInstStr);\r
+ result.put("uninitDeclStr", uninitDeclStr);\r
\r
+ return result;\r
}\r
\r
- private String genInstantiationStr (ArrayList<String> alStr) {\r
+ public static String genInstantiationStr (ArrayList<String> alStr) {\r
String str = "";\r
for (int i = 0; i< alStr.size(); i++) {\r
- str += "\t" + alStr.get(i);\r
+ if (i != 0) {\r
+ str += "\t";\r
+ }\r
+ str += alStr.get(i);\r
if (i != alStr.size() - 1) {\r
str += "\r\n";\r
}\r
return str;\r
}\r
\r
- private HashMap<String, ArrayList<String>> processTokens (List<Token> alToken) \r
- throws EntityException {\r
-\r
- HashMap <String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();\r
-\r
- ArrayList<String> decl = new ArrayList<String>();\r
- ArrayList<String> declForSkuEnableType = new ArrayList<String>();\r
- ArrayList<String> inst = new ArrayList<String>();\r
- ArrayList<String> instForSkuEnableType = new ArrayList<String>();\r
-\r
- for (int index = 0; index < alToken.size(); index++) {\r
- Token token = alToken.get(index);\r
-\r
- if (token.isSkuEnable()) {\r
- //\r
- // BugBug: Schema only support Data type now\r
- //\r
- int tableIdx;\r
-\r
- tableIdx = skuIdTable.add(token);\r
-\r
- decl.add(getSkuEnabledTypeDeclaration(token));\r
- if (token.hasDefaultValue()) {\r
- inst.add(getSkuEnabledTypeInstantiaion(token, tableIdx)); \r
- }\r
-\r
- declForSkuEnableType.add(getDataTypeDeclarationForSkuEnabled(token));\r
- if (token.hasDefaultValue()) {\r
- instForSkuEnableType.add(getDataTypeInstantiationForSkuEnabled(token));\r
- }\r
-\r
- } else {\r
- if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {\r
- decl.add(getVariableEnableTypeDeclaration(token));\r
- inst.add(getVariableEnableInstantiation(token));\r
- } else if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {\r
- decl.add(getVpdEnableTypeDeclaration(token));\r
- inst.add(getVpdEnableTypeInstantiation(token));\r
- } else if (token.isUnicodeStringType()) {\r
- decl.add(getStringTypeDeclaration(token));\r
- inst.add(getStringTypeInstantiation(stringTable.add(token.getStringTypeString(), token), token));\r
- }\r
- else {\r
- decl.add(getDataTypeDeclaration(token));\r
- if (token.hasDefaultValue()) {\r
- inst.add(getDataTypeInstantiation(token));\r
- }\r
- }\r
- }\r
-\r
- sizeTable.add(token);\r
- localTokenNumberTable.add(token);\r
- token.tokenNumber = assignedTokenNumber++;\r
-\r
- }\r
-\r
- map.put("Declaration", decl);\r
- map.put("DeclarationForSku", declForSkuEnableType);\r
- map.put("Instantiation", inst);\r
- map.put("InstantiationForSku", instForSkuEnableType);\r
-\r
- return map;\r
- }\r
-\r
private String getSkuEnabledTypeDeclaration (Token token) {\r
- return String.format("SKU_HEAD %s;\r\n", token.getPrimaryKeyString());\r
+ return String.format("%-20s%s;\r\n", "SKU_HEAD", token.getPrimaryKeyString());\r
}\r
\r
private String getSkuEnabledTypeInstantiaion (Token token, int SkuTableIdx) {\r
\r
String offsetof = String.format(PcdDatabase.offsetOfSkuHeadStrTemplate, phase, token.hasDefaultValue()? "Init" : "Uninit", token.getPrimaryKeyString());\r
- return String.format("{ %s, %d }", offsetof, SkuTableIdx);\r
+ return String.format("{ %s, %d } /* SKU_ENABLED: %s */", offsetof, SkuTableIdx, token.getPrimaryKeyString());\r
}\r
\r
- private String getDataTypeDeclarationForSkuEnabled (Token token) {\r
- String typeStr = "";\r
-\r
- if (token.datumType == Token.DATUM_TYPE.UINT8) {\r
- typeStr = "UINT8 %s_%s[%d];\r\n";\r
- } else if (token.datumType == Token.DATUM_TYPE.UINT16) {\r
- typeStr = "UINT16 %s_%s[%d];\r\n";\r
- } else if (token.datumType == Token.DATUM_TYPE.UINT32) {\r
- typeStr = "UINT32 %s_%s[%d];\r\n";\r
- } else if (token.datumType == Token.DATUM_TYPE.UINT64) {\r
- typeStr = "UINT64 %s_%s[%d];\r\n";\r
- } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
- typeStr = "BOOLEAN %s_%s[%d];\r\n";\r
- } else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
- return String.format("UINT8 %s_%s[%d];\r\n", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.skuData.size());\r
- } \r
-\r
- return String.format(typeStr, token.getPrimaryKeyString(), "SkuDataTable", token.skuData.size());\r
-\r
+ private String getDataTypeInstantiationForVariableDefault (Token token, String cName, int skuId) {\r
+ return String.format("%s /* %s */", token.skuData.get(skuId).value.hiiDefaultValue, cName);\r
}\r
\r
- private String getDataTypeInstantiationForSkuEnabled (Token token) {\r
- String str = "";\r
-\r
- if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
- return String.format("UINT8 %s_%s[%d]", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.skuData.size());\r
- } else {\r
- str = "{ ";\r
- for (int idx = 0; idx < token.skuData.size(); idx++) {\r
- str += token.skuData.get(idx).toString();\r
- if (idx != token.skuData.size() - 1) {\r
- str += ", ";\r
- }\r
- }\r
- str += "}";\r
-\r
- return str;\r
+ private String getCType (Token t) \r
+ throws EntityException {\r
+ \r
+ if (t.isHiiEnable()) {\r
+ return "VARIABLE_HEAD";\r
+ }\r
+ \r
+ if (t.isVpdEnable()) {\r
+ return "VPD_HEAD";\r
+ }\r
+ \r
+ if (t.isUnicodeStringType()) {\r
+ return "STRING_HEAD";\r
+ }\r
+ \r
+ switch (t.datumType) {\r
+ case UINT64:\r
+ return "UINT64";\r
+ case UINT32:\r
+ return "UINT32";\r
+ case UINT16:\r
+ return "UINT16";\r
+ case UINT8:\r
+ return "UINT8";\r
+ case BOOLEAN:\r
+ return "BOOLEAN";\r
+ case POINTER:\r
+ return "UINT8";\r
+ default:\r
+ throw new EntityException("Unknown type in getDataTypeCDeclaration");\r
}\r
-\r
}\r
+ \r
+ private void getCDeclarationString(Token t) \r
+ throws EntityException {\r
+ \r
+ if (t.isSkuEnable()) {\r
+ privateGlobalName = String.format("%s_%s", t.getPrimaryKeyString(), skuDataTableTemplate);\r
+ } else {\r
+ privateGlobalName = t.getPrimaryKeyString();\r
+ }\r
\r
- private String getDataTypeInstantiation (Token token) {\r
-\r
- if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
- return String.format("%s /* %s */", token.getDefaultSku().value, token.getPrimaryKeyString());\r
+ String type = getCType(t);\r
+ if ((t.datumType == Token.DATUM_TYPE.POINTER) && (!t.isHiiEnable())) {\r
+ int bufferSize;\r
+ if (t.isASCIIStringType()) {\r
+ //\r
+ // Build tool will add a NULL string at the end of the ASCII string\r
+ //\r
+ bufferSize = t.datumSize + 1;\r
+ } else {\r
+ bufferSize = t.datumSize;\r
+ }\r
+ privateGlobalCCode = String.format("%-20s%s[%d][%d];\r\n", type, privateGlobalName, t.getSkuIdCount(), bufferSize);\r
} else {\r
- return String.format("%s /* %s */", token.getDefaultSku().value, token.getPrimaryKeyString());\r
+ privateGlobalCCode = String.format("%-20s%s[%d];\r\n", type, privateGlobalName, t.getSkuIdCount());\r
}\r
}\r
+ \r
+ private String getDataTypeDeclarationForVariableDefault (Token token, String cName, int skuId) \r
+ throws EntityException {\r
\r
-\r
- private String getDataTypeDeclaration (Token token) {\r
-\r
- String typeStr = "";\r
+ String typeStr;\r
\r
if (token.datumType == Token.DATUM_TYPE.UINT8) {\r
typeStr = "UINT8";\r
} else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
typeStr = "BOOLEAN";\r
} else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
- return String.format("UINT8 %s[%d]", token.getPrimaryKeyString(), token.datumSize);\r
+ int size;\r
+ if (token.isHiiDefaultValueUnicodeStringType()) {\r
+ typeStr = "UINT16";\r
+ //\r
+ // Include the NULL charactor\r
+ //\r
+ size = token.datumSize / 2 + 1;\r
+ } else {\r
+ typeStr = "UINT8";\r
+ if (token.isHiiDefaultValueASCIIStringType()) {\r
+ //\r
+ // Include the NULL charactor\r
+ //\r
+ size = token.datumSize + 1;\r
+ } else {\r
+ size = token.datumSize;\r
+ }\r
+ }\r
+ return String.format("%-20s%s[%d];\r\n", typeStr, cName, size);\r
} else {\r
+ throw new EntityException("Unknown DATUM_TYPE type in when generating code for VARIABLE_ENABLED PCD entry");\r
}\r
\r
- return String.format("%s %s", typeStr, token.getPrimaryKeyString());\r
- }\r
-\r
- private String getVpdEnableTypeDeclaration (Token token) {\r
- return String.format("VPD_HEAD %s", token.getPrimaryKeyString());\r
- }\r
-\r
- private String getVpdEnableTypeInstantiation (Token token) {\r
- return String.format("{ %s } /* %s */", token.getDefaultSku().vpdOffset,\r
- token.getPrimaryKeyString());\r
- }\r
-\r
- private String getStringTypeDeclaration (Token token) {\r
- return String.format("UINT16 %s", token.getPrimaryKeyString());\r
- }\r
-\r
- private String getStringTypeInstantiation (int StringTableIdx, Token token) {\r
- return String.format ("%d /* %s */", StringTableIdx,\r
- token.getPrimaryKeyString()); \r
- }\r
-\r
-\r
- private String getVariableEnableTypeDeclaration (Token token) {\r
- return String.format("VARIABLE_HEAD %s", token.getPrimaryKeyString());\r
- }\r
-\r
- private String getVariableEnableInstantiation (Token token) \r
- throws EntityException {\r
- //\r
- // Need scott fix\r
- // \r
- return String.format("{ %d, %d, %s } /* %s */", guidTable.add(token.getDefaultSku().variableGuid, token.getPrimaryKeyString()),\r
- stringTable.add(token.getDefaultSku().getStringOfVariableName(), token),\r
- token.getDefaultSku().variableOffset, \r
- token.getPrimaryKeyString());\r
+ return String.format("%-20s%s;\r\n", typeStr, cName);\r
}\r
+ \r
+ private String getTypeInstantiation (Token t, ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) throws EntityException {\r
+ \r
+ int i;\r
+\r
+ String s;\r
+ s = String.format("/* %s */", t.getPrimaryKeyString()) + newLine;\r
+ s += tab + "{" + newLine;\r
+\r
+ for (i = 0; i < t.skuData.size(); i++) {\r
+ if (t.isUnicodeStringType()) {\r
+ s += tab + tab + String.format("{ %d }", stringTable.add(t.skuData.get(i).value.value, t));\r
+ } else if (t.isHiiEnable()) {\r
+ /* VPD_HEAD definition\r
+ typedef struct {\r
+ UINT16 GuidTableIndex; // Offset in Guid Table in units of GUID.\r
+ UINT16 StringIndex; // Offset in String Table in units of UINT16.\r
+ UINT16 Offset; // Offset in Variable\r
+ UINT16 DefaultValueOffset; // Offset of the Default Value\r
+ } VARIABLE_HEAD ;\r
+ */\r
+ String variableDefaultName = String.format("%s_VariableDefault_%d", t.getPrimaryKeyString(), i); \r
+ \r
+ s += tab + tab + String.format("{ %d, %d, %s, %s }", guidTable.add(t.skuData.get(i).value.variableGuid, t.getPrimaryKeyString()),\r
+ stringTable.add(t.skuData.get(i).value.getStringOfVariableName(), t),\r
+ t.skuData.get(i).value.variableOffset,\r
+ String.format("offsetof(%s_PCD_DATABASE, Init.%s)", phase, variableDefaultName)\r
+ );\r
+ //\r
+ // We need to support the default value, so we add the declaration and\r
+ // the instantiation for the default value.\r
+ //\r
+ CStructTypeDeclaration decl = new CStructTypeDeclaration (variableDefaultName,\r
+ getHiiPtrTypeAlignmentSize(t),\r
+ getDataTypeDeclarationForVariableDefault(t, variableDefaultName, i),\r
+ true\r
+ ); \r
+ declaList.add(decl);\r
+ instTable.put(variableDefaultName, getDataTypeInstantiationForVariableDefault (t, variableDefaultName, i));\r
+ } else if (t.isVpdEnable()) {\r
+ /* typedef struct {\r
+ UINT32 Offset;\r
+ } VPD_HEAD;\r
+ */\r
+ s += tab + tab + String.format("{ %s }", t.skuData.get(i).value.vpdOffset);\r
+ } else {\r
+ if (t.isByteStreamType()) {\r
+ //\r
+ // Byte stream type input has their own "{" "}", so we won't help to insert.\r
+ //\r
+ s += tab + tab + String.format(" %s ", t.skuData.get(i).value.value);\r
+ } else {\r
+ s += tab + tab + String.format("{ %s }", t.skuData.get(i).value.value);\r
+ }\r
+ }\r
+ \r
+ if (i != t.skuData.size() - 1) {\r
+ s += commaNewLine;\r
+ } else {\r
+ s += newLine;\r
+ }\r
\r
- public int getTotalTokenNumber () {\r
- return sizeTable.getTableLen();\r
+ }\r
+ \r
+ s += tab + "}";\r
+ \r
+ return s;\r
}\r
-\r
+ \r
public static String getPcdDatabaseCommonDefinitions () \r
throws EntityException {\r
\r
}\r
\r
class ModuleInfo {\r
- public ModuleSADocument.ModuleSA module;\r
- public UsageInstance.MODULE_TYPE type;\r
+ private String type;\r
+ private FpdModuleIdentification moduleId;\r
+ private PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef;\r
+ \r
+ \r
\r
- public ModuleInfo (ModuleSADocument.ModuleSA module, UsageInstance.MODULE_TYPE type) {\r
- this.module = module;\r
+ public ModuleInfo (FpdModuleIdentification moduleId, String type, XmlObject pcdDef) {\r
+ this.moduleId = moduleId;\r
this.type = type;\r
+ this.pcdBuildDef = ((PcdBuildDefinitionDocument)pcdDef).getPcdBuildDefinition();\r
+ }\r
+ public String getModuleType (){\r
+ return this.type;\r
+ }\r
+ public FpdModuleIdentification getModuleId (){\r
+ return this.moduleId;\r
+ }\r
+ public PcdBuildDefinitionDocument.PcdBuildDefinition getPcdBuildDef(){\r
+ return this.pcdBuildDef;\r
}\r
}\r
\r
private int originalMessageLevel;\r
\r
/// Cache the fpd docment instance for private usage.\r
- private FrameworkPlatformDescriptionDocument fpdDocInstance;\r
-\r
+ private PlatformSurfaceAreaDocument fpdDocInstance;\r
+ \r
+ /// xmlObject name\r
+ private static String xmlObjectName = "PcdBuildDefinition"; \r
+ \r
/**\r
Set WorkspacePath parameter for this action class.\r
\r
@throws EntityException Exception indicate failed to execute this action.\r
\r
**/\r
- private void execute() throws EntityException {\r
+ public void execute() throws EntityException {\r
//\r
// Get memoryDatabaseManager instance from GlobalData.\r
// The memoryDatabaseManager should be initialized for whatever build\r
dbManager.getTwoPhaseDynamicRecordArray(alPei, alDxe);\r
PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r
pcdPeiDatabase.genCode();\r
- dbManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString()\r
+ MemoryDatabaseManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString()\r
+ PcdDatabase.getPcdPeiDatabaseDefinitions();\r
- dbManager.PcdPeimCString = pcdPeiDatabase.getCString();\r
+ MemoryDatabaseManager.PcdPeimCString = pcdPeiDatabase.getCString();\r
\r
PcdDatabase pcdDxeDatabase = new PcdDatabase (alDxe, \r
"DXE",\r
alPei.size()\r
);\r
pcdDxeDatabase.genCode();\r
- dbManager.PcdDxeHString = dbManager.PcdPeimHString + pcdDxeDatabase.getHString()\r
+ MemoryDatabaseManager.PcdDxeHString = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString()\r
+ PcdDatabase.getPcdDxeDatabaseDefinitions();\r
- dbManager.PcdDxeCString = pcdDxeDatabase.getCString();\r
+ MemoryDatabaseManager.PcdDxeCString = pcdDxeDatabase.getCString();\r
}\r
\r
/**\r
*/\r
private List<ModuleInfo> getComponentsFromFPD() \r
throws EntityException {\r
- HashMap<String, XmlObject> map = new HashMap<String, XmlObject>();\r
List<ModuleInfo> allModules = new ArrayList<ModuleInfo>();\r
ModuleInfo current = null;\r
int index = 0;\r
- org.tianocore.Components components = null;\r
FrameworkModulesDocument.FrameworkModules fModules = null;\r
- java.util.List<ModuleSADocument.ModuleSA> modules = null;\r
- \r
+ ModuleSADocument.ModuleSA[] modules = null;\r
+ HashMap<String, XmlObject> map = new HashMap<String, XmlObject>();\r
\r
if (fpdDocInstance == null) {\r
try {\r
- fpdDocInstance = (FrameworkPlatformDescriptionDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
+ fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
} catch(IOException ioE) {\r
throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
} catch(XmlException xmlE) {\r
\r
}\r
\r
- //\r
- // Check whether FPD contians <FramworkModules>\r
- // \r
- fModules = fpdDocInstance.getFrameworkPlatformDescription().getFrameworkModules();\r
- if (fModules == null) {\r
- return null;\r
- }\r
-\r
- //\r
- // BUGBUG: The following is work around code, the final component type should be get from\r
- // GlobalData class.\r
- // \r
- components = fModules.getSEC();\r
- if (components != null) {\r
- modules = components.getModuleSAList();\r
- for (index = 0; index < modules.size(); index ++) {\r
- allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.SEC));\r
- }\r
- }\r
-\r
- components = fModules.getPEICORE();\r
- if (components != null) {\r
- modules = components.getModuleSAList();\r
- for (index = 0; index < modules.size(); index ++) {\r
- allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.PEI_CORE));\r
- }\r
- }\r
-\r
- components = fModules.getPEIM();\r
- if (components != null) {\r
- modules = components.getModuleSAList();\r
- for (index = 0; index < modules.size(); index ++) {\r
- allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.PEIM));\r
- }\r
- }\r
-\r
- components = fModules.getDXECORE();\r
- if (components != null) {\r
- modules = components.getModuleSAList();\r
- for (index = 0; index < modules.size(); index ++) {\r
- allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.DXE_CORE));\r
- }\r
- }\r
-\r
- components = fModules.getDXEDRIVERS();\r
- if (components != null) {\r
- modules = components.getModuleSAList();\r
- for (index = 0; index < modules.size(); index ++) {\r
- allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.DXE_DRIVERS));\r
- }\r
- }\r
-\r
- components = fModules.getOTHERCOMPONENTS();\r
- if (components != null) {\r
- modules = components.getModuleSAList();\r
- for (index = 0; index < modules.size(); index ++) {\r
- allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.OTHER_COMPONENTS));\r
- }\r
+ Map<FpdModuleIdentification,XmlObject>pcdBuildDef = GlobalData.getFpdModuleSaXmlObject(CollectPCDAction.xmlObjectName);\r
+ Set<FpdModuleIdentification> pcdBuildKeySet = pcdBuildDef.keySet();\r
+ Iterator item = pcdBuildKeySet.iterator();\r
+ while (item.hasNext()){\r
+ FpdModuleIdentification id = (FpdModuleIdentification)item.next();\r
+ allModules.add(new ModuleInfo(id, id.getModule().getModuleType(),pcdBuildDef.get(id))); \r
}\r
\r
return allModules;\r
List<PcdBuildDefinition.PcdData> pcdBuildDataArray = new ArrayList<PcdBuildDefinition.PcdData>();\r
PcdBuildDefinition.PcdData pcdBuildData = null;\r
Token token = null;\r
- SkuInstance skuInstance = null;\r
- int skuIndex = 0;\r
List<ModuleInfo> modules = null;\r
String primaryKey = null;\r
String exceptionString = null;\r
boolean isDuplicate = false;\r
Token.PCD_TYPE pcdType = Token.PCD_TYPE.UNKNOWN;\r
Token.DATUM_TYPE datumType = Token.DATUM_TYPE.UNKNOWN;\r
- int tokenNumber = 0;\r
+ long tokenNumber = 0;\r
String moduleName = null;\r
String datum = null;\r
int maxDatumSize = 0;\r
+ String[] tokenSpaceStrRet = null;\r
\r
//\r
// ----------------------------------------------\r
// BUGBUG: For transition schema, we can *not* get module's version from \r
// <ModuleSAs>, It is work around code.\r
// \r
- primaryKey1 = UsageInstance.getPrimaryKey(modules.get(index).module.getModuleName(), \r
+ primaryKey1 = UsageInstance.getPrimaryKey(modules.get(index).getModuleId().getModule().getName(), \r
+ null,\r
null,\r
null, \r
- null, \r
- modules.get(index).module.getArch().toString(),\r
+ modules.get(index).getModuleId().getArch(),\r
null);\r
- primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).module.getModuleName(), \r
+ primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).getModuleId().getModule().getName(), \r
null, \r
null, \r
null, \r
- modules.get(index2).module.getArch().toString(), \r
+ modules.get(index2).getModuleId().getArch(), \r
null);\r
if (primaryKey1.equalsIgnoreCase(primaryKey2)) {\r
isDuplicate = true;\r
//\r
// It is legal for a module does not contains ANY pcd build definitions.\r
// \r
- if (modules.get(index).module.getPcdBuildDefinition() == null) {\r
+ if (modules.get(index).getPcdBuildDef() == null) {\r
continue;\r
}\r
\r
- pcdBuildDataArray = modules.get(index).module.getPcdBuildDefinition().getPcdDataList();\r
+ pcdBuildDataArray = modules.get(index).getPcdBuildDef().getPcdDataList();\r
\r
- moduleName = modules.get(index).module.getModuleName();\r
+ moduleName = modules.get(index).getModuleId().getModule().getName();\r
\r
//\r
// ----------------------------------------------------------------------\r
// \r
for (pcdIndex = 0; pcdIndex < pcdBuildDataArray.size(); pcdIndex ++) {\r
pcdBuildData = pcdBuildDataArray.get(pcdIndex);\r
+ \r
+ try {\r
+ tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(pcdBuildData.getTokenSpaceGuidCName());\r
+ } catch ( Exception e ) {\r
+ throw new EntityException ("Faile get Guid for token " + pcdBuildData.getCName() + ":" + e.getMessage());\r
+ }\r
+\r
+ if (tokenSpaceStrRet == null) {\r
+ throw new EntityException ("Fail to get Token space guid for token" + pcdBuildData.getCName());\r
+ } \r
+\r
primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(),\r
- translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));\r
+ translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
- tokenNumber = Integer.decode(pcdBuildData.getToken().toString());\r
+ tokenNumber = Long.decode(pcdBuildData.getToken().toString());\r
if (pcdBuildData.getValue() != null) {\r
datum = pcdBuildData.getValue().toString();\r
} else {\r
throw new EntityException(exceptionString);\r
}\r
\r
- //\r
- // Check <TokenSpaceGuid> is exist? In future, because all schema verification will tools\r
- // will check that, following checking code could be removed.\r
- // \r
- if (pcdBuildData.getTokenSpaceGuid() == null) {\r
- exceptionString = String.format("[FPD file error] There is no <TokenSpaceGuid> for PCD %s in module %s! This is required!",\r
- pcdBuildData.getCName(),\r
- moduleName);\r
- throw new EntityException(exceptionString);\r
- }\r
-\r
//\r
// -------------------------------------------------------------------------------------------\r
// 2.1.1), Do some necessary checking work for FixedAtBuild, FeatureFlag and PatchableInModule\r
// If the token is not in database, create a new token instance and add\r
// a usage instance into this token in database.\r
// \r
+ try {\r
+ tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(pcdBuildData.getTokenSpaceGuidCName());\r
+ } catch (Exception e) {\r
+ throw new EntityException("Fail to get token space guid for token " + token.cName);\r
+ }\r
+\r
+ if (tokenSpaceStrRet == null) {\r
+ throw new EntityException("Fail to get token space guid for token " + token.cName);\r
+ }\r
+\r
token = new Token(pcdBuildData.getCName(), \r
- translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));\r
+ translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
\r
token.datumType = datumType;\r
token.tokenNumber = tokenNumber;\r
null,\r
null,\r
null,\r
- modules.get(index).type, \r
+ CommonDefinition.getModuleType(modules.get(index).getModuleType()), \r
pcdType,\r
- modules.get(index).module.getArch().toString(), \r
+ modules.get(index).getModuleId().getArch(), \r
null,\r
datum,\r
maxDatumSize);\r
String dynamicPrimaryKey = null;\r
DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;\r
List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray = null;\r
+ String[] tokenSpaceStrRet = null;\r
\r
//\r
// If FPD document is not be opened, open and initialize it.\r
// \r
if (fpdDocInstance == null) {\r
try {\r
- fpdDocInstance = (FrameworkPlatformDescriptionDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
+ fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
} catch(IOException ioE) {\r
throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
} catch(XmlException xmlE) {\r
throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
}\r
}\r
-\r
- dynamicPcdBuildDefinitions = fpdDocInstance.getFrameworkPlatformDescription().getDynamicPcdBuildDefinitions();\r
+ \r
+ dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
if (dynamicPcdBuildDefinitions == null) {\r
exceptionString = String.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+\r
"PCD entry %s in module %s!",\r
\r
dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {\r
- //\r
- // Check <TokenSpaceGuid> is exist? In future, because all schema verification will tools\r
- // will check that, following checking code could be removed.\r
- // \r
- if (dynamicPcdBuildDataArray.get(index).getTokenSpaceGuid() == null) {\r
- exceptionString = String.format("[FPD file error] There is no <TokenSpaceGuid> for PCD %s in <DynamicPcdBuildDefinitions>! This is required!",\r
- dynamicPcdBuildDataArray.get(index).getCName());\r
- throw new EntityException(exceptionString);\r
+ //String tokenSpaceGuidString = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName())[1];\r
+ String tokenSpaceGuidString = null;\r
+ try {\r
+ tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName());\r
+ } catch (Exception e) {\r
+ throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
+ }\r
+ \r
+ if (tokenSpaceStrRet == null) {\r
+ throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
}\r
\r
dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
- translateSchemaStringToUUID(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuid()));\r
+ translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
return dynamicPcdBuildDataArray.get(index);\r
}\r
String temp;\r
boolean hasSkuId0 = false;\r
Token.PCD_TYPE pcdType = Token.PCD_TYPE.UNKNOWN;\r
- int tokenNumber = 0;\r
+ long tokenNumber = 0;\r
String hiiDefaultValue = null;\r
String[] variableGuidString = null;\r
\r
dynamicInfo.getMaxDatumSize());\r
throw new EntityException(exceptionString);\r
}\r
- tokenNumber = Integer.decode(dynamicInfo.getToken().toString());\r
+ tokenNumber = Long.decode(dynamicInfo.getToken().toString());\r
if (tokenNumber != token.tokenNumber) {\r
exceptionString = String.format("[FPD file error] For dynamic PCD %s, the token number in module %s is 0x%x, but"+\r
"in <DynamicPcdBuildDefinictions>, the token number is 0x%x, they are not match!",\r
//\r
// Get variable guid string according to the name of guid which will be mapped into a GUID in SPD file.\r
// \r
- variableGuidString = GlobalData.getGuidInfoGuid(skuInfoList.get(index).getVariableGuid().toString());\r
+ variableGuidString = GlobalData.getGuidInfoFromCname(skuInfoList.get(index).getVariableGuid().toString());\r
if (variableGuidString == null) {\r
throw new EntityException(String.format("[GUID Error] For dynamic PCD %s, the variable guid %s can be found in all SPD file!",\r
token.cName, \r
skuInfoList.get(index).getVariableGuid().toString()));\r
}\r
-\r
- skuInstance.value.setHiiData(skuInfoList.get(index).getVariableName(),\r
+ String variableStr = skuInfoList.get(index).getVariableName();\r
+ Pattern pattern = Pattern.compile("0x([a-fA-F0-9]){4}");\r
+ Matcher matcher = pattern.matcher(variableStr);\r
+ List<String> varNameList = new ArrayList<String>();\r
+ while (matcher.find()){\r
+ String str = variableStr.substring(matcher.start(),matcher.end());\r
+ varNameList.add(str);\r
+ }\r
+ \r
+ skuInstance.value.setHiiData(varNameList,\r
translateSchemaStringToUUID(variableGuidString[1]),\r
skuInfoList.get(index).getVariableOffset(),\r
skuInfoList.get(index).getHiiDefaultValue().toString());\r
ca.setWorkspacePath("m:/tianocore/edk2");\r
ca.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd");\r
ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
- GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
- "m:/tianocore/edk2");\r
- ca.execute();\r
+// GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
+// "m:/tianocore/edk2");\r
+// ca.execute();\r
}\r
}\r