]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
Fix bugs in GetNextTokenSpace and GetNextToken
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / CollectPCDAction.java
index c576363074cb561279ce13ec688d7d514ec8b9df..79d488a173c71b00671551629c4fe55e1c40a33e 100644 (file)
@@ -37,11 +37,12 @@ import org.apache.xmlbeans.XmlException;
 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
@@ -228,16 +229,24 @@ class StringTable {
 \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
@@ -261,6 +270,7 @@ class SizeTable {
     }\r
 \r
     private ArrayList<String> getInstantiation () {\r
+        final String comma   = ",";\r
         ArrayList<String> Output = new ArrayList<String>();\r
 \r
         Output.add("/* SizeTable */");\r
@@ -269,14 +279,23 @@ class SizeTable {
             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
@@ -286,20 +305,25 @@ class SizeTable {
         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
@@ -343,7 +367,7 @@ class GuidTable {
         cCode += String.format(PcdDatabase.GuidTableDeclaration, phase); \r
         decl = new CStructTypeDeclaration (\r
                                             name,\r
-                                            8,\r
+                                            4,\r
                                             cCode,\r
                                             true\r
                                            );  \r
@@ -406,7 +430,7 @@ class GuidTable {
         // 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
@@ -673,6 +697,25 @@ class LocalTokenNumberTable {
             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
@@ -709,7 +752,7 @@ class ExMapTable {
     }\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
@@ -717,7 +760,7 @@ class ExMapTable {
     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
@@ -772,7 +815,7 @@ class ExMapTable {
             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
@@ -791,9 +834,11 @@ class ExMapTable {
     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
@@ -850,7 +895,7 @@ class PcdDatabase {
     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
@@ -859,6 +904,7 @@ class PcdDatabase {
     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
@@ -1143,6 +1189,7 @@ class PcdDatabase {
         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
@@ -1310,6 +1357,9 @@ class PcdDatabase {
         }\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
@@ -1320,7 +1370,7 @@ class PcdDatabase {
         }\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
@@ -2019,6 +2069,244 @@ public class CollectPCDAction {
                 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
+        // If FPD document is not be opened, open and initialize it.\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
+                                                   translateSchemaStringToUUID(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(), translateSchemaStringToUUID(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
@@ -2768,11 +3056,16 @@ public class CollectPCDAction {
     **/\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