import org.apache.xmlbeans.XmlObject;\r
import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r
import org.tianocore.FrameworkModulesDocument;\r
-import org.tianocore.PlatformSurfaceAreaDocument;\r
-import org.tianocore.PcdBuildDefinitionDocument;\r
import org.tianocore.ModuleSADocument;\r
+import org.tianocore.PcdBuildDefinitionDocument;\r
import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;\r
+import org.tianocore.PlatformSurfaceAreaDocument;\r
import org.tianocore.build.autogen.CommonDefinition;\r
+import org.tianocore.build.fpd.FpdParserTask;\r
import org.tianocore.build.global.GlobalData;\r
import org.tianocore.build.id.FpdModuleIdentification;\r
import org.tianocore.build.pcd.action.ActionMessage;\r
\r
**/\r
class SizeTable {\r
- private ArrayList<Integer> al;\r
+ private ArrayList<ArrayList<Integer>> al;\r
private ArrayList<String> alComments;\r
- private String phase;\r
private int len;\r
+ private String phase;\r
\r
public SizeTable (String phase) {\r
- this.phase = phase;\r
- al = new ArrayList<Integer>();\r
+ al = new ArrayList<ArrayList<Integer>>();\r
alComments = new ArrayList<String>();\r
len = 0;\r
+ this.phase = phase;\r
+ }\r
+\r
+ public String getSizeMacro () {\r
+ return String.format(PcdDatabase.SizeTableSizeMacro, phase, getSize());\r
+ }\r
+ \r
+ private int getSize() {\r
+ return len == 0 ? 1 : len;\r
}\r
\r
public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
}\r
\r
private ArrayList<String> getInstantiation () {\r
+ final String comma = ",";\r
ArrayList<String> Output = new ArrayList<String>();\r
\r
Output.add("/* SizeTable */");\r
Output.add("\t0");\r
} else {\r
for (int index = 0; index < al.size(); index++) {\r
- Integer n = al.get(index);\r
- String str = "\t" + n.toString();\r
+ ArrayList<Integer> ial = al.get(index);\r
+ \r
+ String str = "\t";\r
+ \r
+ for (int index2 = 0; index2 < ial.size(); index2++) {\r
+ str += " " + ial.get(index2).toString();\r
+ if (index2 != ial.size() - 1) {\r
+ str += comma;\r
+ }\r
+ }\r
\r
+ str += " /* " + alComments.get(index) + " */"; \r
+ \r
if (index != (al.size() - 1)) {\r
- str += ",";\r
+ str += comma;\r
}\r
\r
- str += " /* " + alComments.get(index) + " */"; \r
Output.add(str);\r
\r
}\r
return Output;\r
}\r
\r
- public int add (Token token) {\r
- int index = len;\r
+ public void add (Token token) {\r
\r
- len++; \r
- al.add(token.datumSize);\r
+ //\r
+ // We only have size information for POINTER type PCD entry.\r
+ //\r
+ if (token.datumType != Token.DATUM_TYPE.POINTER) {\r
+ return;\r
+ }\r
+ \r
+ ArrayList<Integer> ial = token.getPointerTypeSize();\r
+ \r
+ len+= ial.size(); \r
+\r
+ al.add(ial);\r
alComments.add(token.getPrimaryKeyString());\r
\r
- return index;\r
+ return;\r
}\r
\r
- public int getTableLen () {\r
- return al.size() == 0 ? 1 : al.size();\r
- }\r
-\r
}\r
\r
/**\r
cCode += String.format(PcdDatabase.GuidTableDeclaration, phase); \r
decl = new CStructTypeDeclaration (\r
name,\r
- 8,\r
+ 4,\r
cCode,\r
true\r
); \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
+ if (al.get(i).compareTo(uuid) == 0) {\r
return i;\r
}\r
}\r
str += " | PCD_TYPE_VPD";\r
}\r
\r
+ switch (token.datumType) {\r
+ case UINT8:\r
+ case BOOLEAN:\r
+ str += " | PCD_DATUM_TYPE_UINT8";\r
+ break;\r
+ case UINT16:\r
+ str += " | PCD_DATUM_TYPE_UINT16";\r
+ break;\r
+ case UINT32:\r
+ str += " | PCD_DATUM_TYPE_UINT32";\r
+ break;\r
+ case UINT64:\r
+ str += " | PCD_DATUM_TYPE_UINT64";\r
+ break;\r
+ case POINTER:\r
+ str += " | PCD_DATUM_TYPE_POINTER";\r
+ break;\r
+ }\r
+ \r
al.add(str);\r
alComment.add(token.getPrimaryKeyString());\r
\r
}\r
\r
private ArrayList<ExTriplet> al;\r
- private ArrayList<String> alComment;\r
+ private Map<ExTriplet, String> alComment;\r
private String phase;\r
private int len;\r
private int bodyLineNum;\r
public ExMapTable (String phase) {\r
this.phase = phase;\r
al = new ArrayList<ExTriplet>();\r
- alComment = new ArrayList<String>();\r
+ alComment = new HashMap<ExTriplet, String>();\r
bodyLineNum = 0;\r
len = 0;\r
}\r
str += e.localTokenIdx.toString() + ", ";\r
str += e.guidTableIdx.toString();\r
\r
- str += "}" + " /* " + alComment.get(index) + " */" ;\r
+ str += "}" + " /* " + alComment.get(e) + " */" ;\r
\r
if (index != al.size() - 1) {\r
str += ",";\r
public int add (int localTokenIdx, long exTokenNum, int guidTableIdx, String name) {\r
int index = len;\r
\r
- len++; \r
- al.add(new ExTriplet(guidTableIdx, exTokenNum, localTokenIdx));\r
- alComment.add(name);\r
+ len++;\r
+ ExTriplet et = new ExTriplet(guidTableIdx, exTokenNum, localTokenIdx); \r
+\r
+ al.add(et);\r
+ alComment.put(et, name);\r
\r
return index;\r
}\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 SizeTableDeclaration = "SIZE_INFO SizeTable[%s_SIZE_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 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 SizeTableSizeMacro = "#define %s_SIZE_TABLE_SIZE %d\r\n";\r
public final static String StringTableSizeMacro = "#define %s_STRING_TABLE_SIZE %d\r\n";\r
public final static String SkuIdTableSizeMacro = "#define %s_SKUID_TABLE_SIZE %d\r\n";\r
\r
if (t.isDynamicEx()) {\r
exMapTable.add((int)t.tokenNumber, \r
t.dynamicExTokenNumber, \r
- guidTable.add(t.tokenSpaceName, t.getPrimaryKeyString()), \r
+ guidTable.add(translateSchemaStringToUUID(t.tokenSpaceName), t.getPrimaryKeyString()), \r
t.getPrimaryKeyString()\r
);\r
}\r
macroStr += skuIdTable.getSizeMacro();\r
macroStr += localTokenNumberTable.getSizeMacro();\r
macroStr += exMapTable.getSizeMacro();\r
+ macroStr += sizeTable.getSizeMacro();\r
\r
//\r
// Generate existance info Macro for all Tables\r
}\r
}\r
\r
+ //\r
+ // privateGlobalName and privateGlobalCCode is used to pass output to caller of getCDeclarationString\r
+ //\r
private void getCDeclarationString(Token t) \r
throws EntityException {\r
\r
}\r
\r
String type = getCType(t);\r
- if ((t.datumType == Token.DATUM_TYPE.POINTER) && (!t.isHiiEnable())) {\r
+ if ((t.datumType == Token.DATUM_TYPE.POINTER) && (!t.isHiiEnable()) && (!t.isUnicodeStringType())) {\r
int bufferSize;\r
if (t.isASCIIStringType()) {\r
//\r
}\r
\r
private String getDataTypeDeclarationForVariableDefault (Token token, String cName, int skuId) \r
- throws EntityException {\r
+ throws EntityException {\r
\r
String typeStr;\r
\r
return retStr;\r
}\r
\r
+ /**\r
+ Translate the schema string to UUID instance.\r
+ \r
+ In schema, the string of UUID is defined as following two types string:\r
+ 1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},(\r
+ )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})?\r
+ \r
+ 2) GuidNamingConvention: pattern =\r
+ [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\r
+ \r
+ This function will convert string and create uuid instance.\r
+ \r
+ @param uuidString UUID string in XML file\r
+ \r
+ @return UUID UUID instance\r
+ **/\r
+ private UUID translateSchemaStringToUUID(String uuidString) \r
+ throws EntityException {\r
+ String temp;\r
+ String[] splitStringArray;\r
+ int index;\r
+ int chIndex;\r
+ int chLen;\r
+\r
+ if (uuidString == null) {\r
+ return null;\r
+ }\r
+\r
+ if (uuidString.length() == 0) {\r
+ return null;\r
+ }\r
+\r
+ if (uuidString.equals("0") ||\r
+ uuidString.equalsIgnoreCase("0x0")) {\r
+ return new UUID(0, 0);\r
+ }\r
+\r
+ uuidString = uuidString.replaceAll("\\{", "");\r
+ uuidString = uuidString.replaceAll("\\}", "");\r
+\r
+ //\r
+ // If the UUID schema string is GuidArrayType type then need translate \r
+ // to GuidNamingConvention type at first.\r
+ // \r
+ if ((uuidString.charAt(0) == '0') && ((uuidString.charAt(1) == 'x') || (uuidString.charAt(1) == 'X'))) {\r
+ splitStringArray = uuidString.split("," );\r
+ if (splitStringArray.length != 11) {\r
+ throw new EntityException ("[FPD file error] Wrong format for UUID string: " + uuidString);\r
+ }\r
+\r
+ //\r
+ // Remove blank space from these string and remove header string "0x"\r
+ // \r
+ for (index = 0; index < 11; index ++) {\r
+ splitStringArray[index] = splitStringArray[index].trim();\r
+ splitStringArray[index] = splitStringArray[index].substring(2, splitStringArray[index].length());\r
+ }\r
+\r
+ //\r
+ // Add heading '0' to normalize the string length\r
+ // \r
+ for (index = 3; index < 11; index ++) {\r
+ chLen = splitStringArray[index].length();\r
+ for (chIndex = 0; chIndex < 2 - chLen; chIndex ++) {\r
+ splitStringArray[index] = "0" + splitStringArray[index];\r
+ }\r
+ }\r
+\r
+ //\r
+ // construct the final GuidNamingConvention string\r
+ // \r
+ temp = String.format("%s-%s-%s-%s%s-%s%s%s%s%s%s",\r
+ splitStringArray[0],\r
+ splitStringArray[1],\r
+ splitStringArray[2],\r
+ splitStringArray[3],\r
+ splitStringArray[4],\r
+ splitStringArray[5],\r
+ splitStringArray[6],\r
+ splitStringArray[7],\r
+ splitStringArray[8],\r
+ splitStringArray[9],\r
+ splitStringArray[10]);\r
+ uuidString = temp;\r
+ }\r
+\r
+ return UUID.fromString(uuidString);\r
+ }\r
}\r
\r
+/** Module Info class is the data structure to hold information got from GlobalData.\r
+*/\r
class ModuleInfo {\r
- private String type;\r
- private FpdModuleIdentification moduleId;\r
+ ///\r
+ /// Module's ID for a <ModuleSA>\r
+ /// \r
+ private FpdModuleIdentification moduleId;\r
+ ///\r
+ /// <PcdBuildDefinition> xmlobject in FPD file for a <ModuleSA>\r
+ /// \r
private PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef;\r
- \r
- \r
\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
+ public ModuleInfo (FpdModuleIdentification moduleId, XmlObject pcdDef) {\r
+ this.moduleId = moduleId;\r
+ this.pcdBuildDef = ((PcdBuildDefinitionDocument)pcdDef).getPcdBuildDefinition();\r
}\r
+\r
public FpdModuleIdentification getModuleId (){\r
- return this.moduleId;\r
+ return moduleId;\r
}\r
+\r
public PcdBuildDefinitionDocument.PcdBuildDefinition getPcdBuildDef(){\r
- return this.pcdBuildDef;\r
+ return pcdBuildDef;\r
}\r
}\r
\r
from buildAction or UIAction.\r
**/\r
public class CollectPCDAction {\r
+ ///\r
/// memoryDatabase hold all PCD information collected from SPD, MSA, FPD.\r
+ /// \r
private MemoryDatabaseManager dbManager;\r
-\r
+ ///\r
/// Workspacepath hold the workspace information.\r
+ /// \r
private String workspacePath;\r
-\r
+ ///\r
/// FPD file is the root file. \r
+ /// \r
private String fpdFilePath;\r
-\r
+ ///\r
/// Message level for CollectPCDAction.\r
+ /// \r
private int originalMessageLevel;\r
-\r
+ ///\r
/// Cache the fpd docment instance for private usage.\r
+ /// \r
private PlatformSurfaceAreaDocument fpdDocInstance;\r
- \r
+ ///\r
/// xmlObject name\r
+ /// \r
private static String xmlObjectName = "PcdBuildDefinition"; \r
\r
/**\r
createTokenInDBFromFPD();\r
\r
//\r
- // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver\r
- // 1) Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
+ // Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
//\r
genPcdDatabaseSourceCode ();\r
\r
**/\r
private void genPcdDatabaseSourceCode()\r
throws EntityException {\r
- String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions ();\r
+ String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions();\r
\r
ArrayList<Token> alPei = new ArrayList<Token> ();\r
ArrayList<Token> alDxe = new ArrayList<Token> ();\r
dbManager.getTwoPhaseDynamicRecordArray(alPei, alDxe);\r
PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r
pcdPeiDatabase.genCode();\r
- MemoryDatabaseManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString()\r
- + PcdDatabase.getPcdPeiDatabaseDefinitions();\r
+ MemoryDatabaseManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString() + \r
+ PcdDatabase.getPcdPeiDatabaseDefinitions();\r
MemoryDatabaseManager.PcdPeimCString = pcdPeiDatabase.getCString();\r
\r
- PcdDatabase pcdDxeDatabase = new PcdDatabase (alDxe, \r
- "DXE",\r
- alPei.size()\r
- );\r
+ PcdDatabase pcdDxeDatabase = new PcdDatabase(alDxe, "DXE", alPei.size());\r
pcdDxeDatabase.genCode();\r
- MemoryDatabaseManager.PcdDxeHString = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString()\r
- + PcdDatabase.getPcdDxeDatabaseDefinitions();\r
+ MemoryDatabaseManager.PcdDxeHString = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString() + \r
+ PcdDatabase.getPcdDxeDatabaseDefinitions();\r
MemoryDatabaseManager.PcdDxeCString = pcdDxeDatabase.getCString();\r
}\r
\r
*/\r
private List<ModuleInfo> getComponentsFromFPD() \r
throws EntityException {\r
- List<ModuleInfo> allModules = new ArrayList<ModuleInfo>();\r
- ModuleInfo current = null;\r
- int index = 0;\r
- FrameworkModulesDocument.FrameworkModules fModules = null;\r
- ModuleSADocument.ModuleSA[] modules = null;\r
- HashMap<String, XmlObject> map = new HashMap<String, XmlObject>();\r
-\r
- if (fpdDocInstance == null) {\r
- try {\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
+ List<ModuleInfo> allModules = new ArrayList<ModuleInfo>();\r
+ FrameworkModulesDocument.FrameworkModules fModules = null;\r
+ ModuleSADocument.ModuleSA[] modules = null;\r
+ Map<FpdModuleIdentification, XmlObject> pcdBuildDefinitions = null;\r
\r
+ pcdBuildDefinitions = GlobalData.getFpdPcdBuildDefinitions();\r
+ if (pcdBuildDefinitions == null) {\r
+ return null;\r
}\r
\r
- Map<FpdModuleIdentification,XmlObject>pcdBuildDef = GlobalData.getFpdModuleSaXmlObject(CollectPCDAction.xmlObjectName);\r
- Set<FpdModuleIdentification> pcdBuildKeySet = pcdBuildDef.keySet();\r
- Iterator item = pcdBuildKeySet.iterator();\r
+ //\r
+ // Loop map to retrieve all PCD build definition and Module id \r
+ // \r
+ Iterator item = pcdBuildDefinitions.keySet().iterator();\r
while (item.hasNext()){\r
- FpdModuleIdentification id = (FpdModuleIdentification)item.next();\r
- allModules.add(new ModuleInfo(id, id.getModule().getModuleType(),pcdBuildDef.get(id))); \r
+ FpdModuleIdentification id = (FpdModuleIdentification) item.next();\r
+ allModules.add(new ModuleInfo(id, pcdBuildDefinitions.get(id))); \r
}\r
\r
return allModules;\r
// -------------------------------------------------------------------\r
// \r
for (index = 0; index < modules.size(); index ++) {\r
- isDuplicate = false;\r
- for (index2 = 0; index2 < index; index2 ++) {\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).getModuleId().getModule().getName(), \r
- null,\r
- null,\r
- null, \r
- modules.get(index).getModuleId().getArch(),\r
- null);\r
- primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).getModuleId().getModule().getName(), \r
- null, \r
- null, \r
- null, \r
- modules.get(index2).getModuleId().getArch(), \r
- null);\r
- if (primaryKey1.equalsIgnoreCase(primaryKey2)) {\r
- isDuplicate = true;\r
- break;\r
- }\r
- }\r
-\r
- if (isDuplicate) {\r
- continue;\r
- }\r
-\r
//\r
// It is legal for a module does not contains ANY pcd build definitions.\r
// \r
throw new EntityException ("Fail to get Token space guid for token" + pcdBuildData.getCName());\r
} \r
\r
- primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(),\r
- translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
+ primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(), tokenSpaceStrRet[1]);\r
pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
tokenNumber = Long.decode(pcdBuildData.getToken().toString());\r
throw new EntityException("Fail to get token space guid for token " + token.cName);\r
}\r
\r
- token = new Token(pcdBuildData.getCName(), \r
- translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
+ token = new Token(pcdBuildData.getCName(), tokenSpaceStrRet[1]);\r
\r
token.datumType = datumType;\r
token.tokenNumber = tokenNumber;\r
// ------------------------------------------------\r
// \r
usageInstance = new UsageInstance(token, \r
- moduleName, \r
- null,\r
- null,\r
- null,\r
- CommonDefinition.getModuleType(modules.get(index).getModuleType()), \r
+ modules.get(index).getModuleId().getModule(), \r
pcdType,\r
modules.get(index).getModuleId().getArch(), \r
- null,\r
datum,\r
maxDatumSize);\r
token.addUsageInstance(usageInstance);\r
}\r
}\r
+\r
+ //\r
+ // ------------------------------------------------\r
+ // 3), Add unreference dynamic_Ex pcd token into Pcd database.\r
+ // ------------------------------------------------\r
+ // \r
+ List<Token> tokenArray = getUnreferencedDynamicPcd();\r
+ if (tokenArray != null) {\r
+ for (index = 0; index < tokenArray.size(); index ++) {\r
+ dbManager.addTokenToDatabase(tokenArray.get(index).getPrimaryKeyString(), \r
+ tokenArray.get(index));\r
+ }\r
+ }\r
+ }\r
+\r
+ private List<Token> getUnreferencedDynamicPcd () throws EntityException {\r
+ List<Token> tokenArray = new ArrayList<Token>();\r
+ Token token = null;\r
+ DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;\r
+ List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray = null;\r
+ DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData = null;\r
+ List<DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> skuInfoList = null;\r
+ Token.PCD_TYPE pcdType;\r
+ SkuInstance skuInstance = null;\r
+ String primaryKey = null;\r
+ boolean hasSkuId0 = false;\r
+ int index, offset, index2;\r
+ String temp;\r
+ String exceptionString;\r
+ String hiiDefaultValue;\r
+ String tokenSpaceStrRet[];\r
+ String variableGuidString[];\r
+\r
+ //\r
+ // Open fpd document to get <DynamicPcdBuildDefinition> Section.\r
+ // BUGBUG: the function should be move GlobalData in furture.\r
+ // \r
+ if (fpdDocInstance == null) {\r
+ try {\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.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
+ if (dynamicPcdBuildDefinitions == null) {\r
+ return null;\r
+ }\r
+\r
+ dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
+ for (index2 = 0; index2 < dynamicPcdBuildDataArray.size(); index2 ++) {\r
+ pcdBuildData = dynamicPcdBuildDataArray.get(index2);\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
+ tokenSpaceStrRet[1]);\r
+\r
+ if (dbManager.isTokenInDatabase(primaryKey)) {\r
+ continue;\r
+ }\r
+\r
+ pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
+ if (pcdType != Token.PCD_TYPE.DYNAMIC_EX) {\r
+ throw new EntityException (String.format("[FPD file error] It not allowed for DYNAMIC PCD %s who is no used by any module",\r
+ pcdBuildData.getCName()));\r
+ }\r
+\r
+ //\r
+ // Create new token for unreference dynamic PCD token\r
+ // \r
+ token = new Token(pcdBuildData.getCName(), tokenSpaceStrRet[1]);\r
+ token.datumSize = pcdBuildData.getMaxDatumSize();\r
+ \r
+\r
+ token.datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
+ token.tokenNumber = Long.decode(pcdBuildData.getToken().toString());\r
+ token.dynamicExTokenNumber = token.tokenNumber;\r
+ token.isDynamicPCD = true; \r
+ token.updateSupportPcdType(pcdType);\r
+\r
+ exceptionString = verifyDatum(token.cName, \r
+ null,\r
+ null, \r
+ token.datumType, \r
+ token.datumSize);\r
+ if (exceptionString != null) {\r
+ throw new EntityException(exceptionString);\r
+ }\r
+\r
+ skuInfoList = pcdBuildData.getSkuInfoList();\r
+\r
+ //\r
+ // Loop all sku data \r
+ // \r
+ for (index = 0; index < skuInfoList.size(); index ++) {\r
+ skuInstance = new SkuInstance();\r
+ //\r
+ // Although SkuId in schema is BigInteger, but in fact, sku id is 32 bit value.\r
+ // \r
+ temp = skuInfoList.get(index).getSkuId().toString();\r
+ skuInstance.id = Integer.decode(temp);\r
+ if (skuInstance.id == 0) {\r
+ hasSkuId0 = true;\r
+ }\r
+ //\r
+ // Judge whether is DefaultGroup at first, because most case is DefautlGroup.\r
+ // \r
+ if (skuInfoList.get(index).getValue() != null) {\r
+ skuInstance.value.setValue(skuInfoList.get(index).getValue().toString());\r
+ if ((exceptionString = verifyDatum(token.cName, \r
+ null, \r
+ skuInfoList.get(index).getValue().toString(), \r
+ token.datumType, \r
+ token.datumSize)) != null) {\r
+ throw new EntityException(exceptionString);\r
+ }\r
+\r
+ token.skuData.add(skuInstance);\r
+\r
+ continue;\r
+ }\r
+\r
+ //\r
+ // Judge whether is HII group case.\r
+ // \r
+ if (skuInfoList.get(index).getVariableName() != null) {\r
+ exceptionString = null;\r
+ if (skuInfoList.get(index).getVariableGuid() == null) {\r
+ exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
+ "file, who use HII, but there is no <VariableGuid> defined for Sku %d data!",\r
+ token.cName,\r
+ index);\r
+ if (exceptionString != null) {\r
+ throw new EntityException(exceptionString);\r
+ } \r
+ }\r
+\r
+ if (skuInfoList.get(index).getVariableOffset() == null) {\r
+ exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
+ "file, who use HII, but there is no <VariableOffset> defined for Sku %d data!",\r
+ token.cName,\r
+ index);\r
+ if (exceptionString != null) {\r
+ throw new EntityException(exceptionString);\r
+ }\r
+ }\r
+\r
+ if (skuInfoList.get(index).getHiiDefaultValue() == null) {\r
+ exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
+ "file, who use HII, but there is no <HiiDefaultValue> defined for Sku %d data!",\r
+ token.cName,\r
+ index);\r
+ if (exceptionString != null) {\r
+ throw new EntityException(exceptionString);\r
+ }\r
+ }\r
+\r
+ if (skuInfoList.get(index).getHiiDefaultValue() != null) {\r
+ hiiDefaultValue = skuInfoList.get(index).getHiiDefaultValue().toString();\r
+ } else {\r
+ hiiDefaultValue = null;\r
+ }\r
+\r
+ if ((exceptionString = verifyDatum(token.cName, \r
+ null, \r
+ hiiDefaultValue, \r
+ token.datumType, \r
+ token.datumSize)) != null) {\r
+ throw new EntityException(exceptionString);\r
+ }\r
+\r
+ offset = Integer.decode(skuInfoList.get(index).getVariableOffset());\r
+ if (offset > 0xFFFF) {\r
+ throw new EntityException(String.format("[FPD file error] For dynamic PCD %s , the variable offset defined in sku %d data "+\r
+ "exceed 64K, it is not allowed!",\r
+ token.cName,\r
+ index));\r
+ }\r
+\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.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
+ 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
+ token.skuData.add(skuInstance);\r
+ continue;\r
+ }\r
+\r
+ if (skuInfoList.get(index).getVpdOffset() != null) {\r
+ skuInstance.value.setVpdData(skuInfoList.get(index).getVpdOffset());\r
+ token.skuData.add(skuInstance);\r
+ continue;\r
+ }\r
+\r
+ exceptionString = String.format("[FPD file error] For dynamic PCD %s, the dynamic info must "+\r
+ "be one of 'DefaultGroup', 'HIIGroup', 'VpdGroup'.",\r
+ token.cName);\r
+ throw new EntityException(exceptionString);\r
+ }\r
+\r
+ if (!hasSkuId0) {\r
+ exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions>, there are "+\r
+ "no sku id = 0 data, which is required for every dynamic PCD",\r
+ token.cName);\r
+ throw new EntityException(exceptionString);\r
+ }\r
+\r
+ tokenArray.add(token);\r
+ }\r
+\r
+ return tokenArray;\r
}\r
\r
/**\r
strValue = datum.substring(start + 1, end);\r
strValue = strValue.trim();\r
if (strValue.length() == 0) {\r
- break;\r
+ exceptionString = String.format ("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+\r
+ "it is byte array in fact, but '{}' is not valid for NULL datam but"+\r
+ " need use '{0}'",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
}\r
strValueArray = strValue.split(",");\r
for (index = 0; index < strValueArray.length; index ++) {\r
\r
//\r
// If FPD document is not be opened, open and initialize it.\r
+ // BUGBUG: The code should be moved into GlobalData in future.\r
// \r
if (fpdDocInstance == null) {\r
try {\r
}\r
\r
dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
- translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
+ tokenSpaceStrRet[1]);\r
if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
return dynamicPcdBuildDataArray.get(index);\r
}\r
}\r
\r
pcdType = Token.getpcdTypeFromString(dynamicInfo.getItemType().toString());\r
- if (pcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
- token.dynamicExTokenNumber = tokenNumber;\r
- }\r
+ token.dynamicExTokenNumber = tokenNumber;\r
\r
skuInfoList = dynamicInfo.getSkuInfoList();\r
\r
**/\r
public static void main(String argv[]) throws EntityException {\r
CollectPCDAction ca = new CollectPCDAction();\r
- ca.setWorkspacePath("m:/tianocore/edk2");\r
- ca.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd");\r
+ String projectDir = "x:/edk2";\r
+ ca.setWorkspacePath(projectDir);\r
+ ca.setFPDFilePath(projectDir + "/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
+ projectDir,\r
+ "tools_def.txt");\r
+ System.out.println("After initInfo!");\r
+ FpdParserTask fpt = new FpdParserTask();\r
+ fpt.parseFpdFile(new File(projectDir + "/EdkNt32Pkg/Nt32.fpd"));\r
+ ca.execute();\r
}\r
}\r