Support putting unreference DYNAMIC_EX PCD into Pcd runtime database.
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 5 Jul 2006 05:28:48 +0000 (05:28 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 5 Jul 2006 05:28:48 +0000 (05:28 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@761 6f19259b-4bc3-4df7-8a09-765794883524

EdkNt32Pkg/Nt32.fpd
Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
Tools/Source/GenBuild/org/tianocore/build/pcd/entity/MemoryDatabaseManager.java

index 7dea2ca..da894c3 100644 (file)
         <Value>L"UGA Window 1!UGA Window 2"</Value>\r
       </SkuInfo>\r
     </PcdBuildData>\r
-    <PcdBuildData ItemType="DYNAMIC">\r
-      <C_Name>PcdTestDynamicUint8</C_Name>\r
-      <Token>0x00011000</Token>\r
-      <TokenSpaceGuidCName>gEfiEdkNt32PkgTokenSpaceGuid</TokenSpaceGuidCName>\r
-      <DatumType>UINT8</DatumType>\r
-      <MaxDatumSize>1</MaxDatumSize>\r
-      <SkuInfo>\r
-        <SkuId>0</SkuId>\r
-        <Value>0x1</Value>\r
-      </SkuInfo>\r
-    </PcdBuildData>\r
-    <PcdBuildData ItemType="DYNAMIC">\r
-      <C_Name>PcdTestDynamicUint16</C_Name>\r
-      <Token>0x00011001</Token>\r
-      <TokenSpaceGuidCName>gEfiEdkNt32PkgTokenSpaceGuid</TokenSpaceGuidCName>\r
-      <DatumType>UINT16</DatumType>\r
-      <MaxDatumSize>2</MaxDatumSize>\r
-      <SkuInfo>\r
-        <SkuId>0</SkuId>\r
-        <Value>0x1234</Value>\r
-      </SkuInfo>\r
-    </PcdBuildData>\r
-    <PcdBuildData ItemType="DYNAMIC">\r
-      <C_Name>PcdTestDynamicUint32</C_Name>\r
-      <Token>0x00011002</Token>\r
-      <TokenSpaceGuidCName>gEfiEdkNt32PkgTokenSpaceGuid</TokenSpaceGuidCName>\r
-      <DatumType>UINT32</DatumType>\r
-      <MaxDatumSize>4</MaxDatumSize>\r
-      <SkuInfo>\r
-        <SkuId>0</SkuId>\r
-        <Value>0</Value>\r
-      </SkuInfo>\r
-    </PcdBuildData>\r
-    <PcdBuildData ItemType="DYNAMIC">\r
-      <C_Name>PcdTestDynamicUint64</C_Name>\r
-      <Token>0x00011003</Token>\r
-      <TokenSpaceGuidCName>gEfiEdkNt32PkgTokenSpaceGuid</TokenSpaceGuidCName>\r
-      <DatumType>UINT64</DatumType>\r
-      <MaxDatumSize>8</MaxDatumSize>\r
-      <SkuInfo>\r
-        <SkuId>0</SkuId>\r
-        <Value>0</Value>\r
-      </SkuInfo>\r
-    </PcdBuildData>\r
-    <PcdBuildData ItemType="DYNAMIC">\r
+    <PcdBuildData ItemType="DYNAMIC_EX">\r
       <C_Name>PcdTestDynamicBoolean</C_Name>\r
       <Token>0x00011004</Token>\r
       <TokenSpaceGuidCName>gEfiEdkNt32PkgTokenSpaceGuid</TokenSpaceGuidCName>\r
index 29819dd..610739e 100644 (file)
@@ -37,10 +37,10 @@ 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
@@ -2020,6 +2020,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();\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
@@ -2769,14 +3007,14 @@ public class CollectPCDAction {
     **/\r
     public static void main(String argv[]) throws EntityException {\r
         CollectPCDAction ca = new CollectPCDAction();\r
-        ca.setWorkspacePath("f:/tianocore/edk2");\r
-        ca.setFPDFilePath("f:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd");\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
-                            "f:/tianocore/edk2",\r
+                            "m:/tianocore/edk2",\r
                             "tools_def.txt");\r
         FpdParserTask fpt = new FpdParserTask();\r
-        fpt.parseFpdFile(new File("f:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd"));\r
+        fpt.parseFpdFile(new File("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd"));\r
         ca.execute();\r
     }\r
 }\r
index 0439c11..2e29106 100644 (file)
@@ -197,11 +197,15 @@ public class MemoryDatabaseManager {
                 }\r
                 \r
                 if (!found) {\r
-                    //\r
-                    // We only support Dynamice(EX) type for PEI and DXE phase.\r
-                    // If it is not referenced in either PEI or DXE, throw exception now.\r
-                    //\r
-                    throw new EntityException("Dynamic(EX) PCD Entries are referenced in module that is not in PEI phase nor in DXE phase.");\r
+                    if (token.isDynamicPCD && token.consumers.size() == 0) {\r
+                        dxe.add(token);\r
+                    } else {\r
+                        //\r
+                        // We only support Dynamice(EX) type for PEI and DXE phase.\r
+                        // If it is not referenced in either PEI or DXE, throw exception now.\r
+                        //\r
+                        throw new EntityException("Dynamic(EX) PCD Entries are referenced in module that is not in PEI phase nor in DXE phase.");\r
+                    }\r
                 }\r
             }\r
         }\r