From 8d82d61173338a480da54065ef7138cb1454e889 Mon Sep 17 00:00:00 2001 From: klu2 Date: Wed, 5 Jul 2006 05:28:48 +0000 Subject: [PATCH] Support putting unreference DYNAMIC_EX PCD into Pcd runtime database. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@761 6f19259b-4bc3-4df7-8a09-765794883524 --- EdkNt32Pkg/Nt32.fpd | 46 +--- .../build/pcd/action/CollectPCDAction.java | 250 +++++++++++++++++- .../pcd/entity/MemoryDatabaseManager.java | 14 +- 3 files changed, 254 insertions(+), 56 deletions(-) diff --git a/EdkNt32Pkg/Nt32.fpd b/EdkNt32Pkg/Nt32.fpd index 7dea2ca884..da894c3690 100644 --- a/EdkNt32Pkg/Nt32.fpd +++ b/EdkNt32Pkg/Nt32.fpd @@ -6478,51 +6478,7 @@ L"UGA Window 1!UGA Window 2" - - PcdTestDynamicUint8 - 0x00011000 - gEfiEdkNt32PkgTokenSpaceGuid - UINT8 - 1 - - 0 - 0x1 - - - - PcdTestDynamicUint16 - 0x00011001 - gEfiEdkNt32PkgTokenSpaceGuid - UINT16 - 2 - - 0 - 0x1234 - - - - PcdTestDynamicUint32 - 0x00011002 - gEfiEdkNt32PkgTokenSpaceGuid - UINT32 - 4 - - 0 - 0 - - - - PcdTestDynamicUint64 - 0x00011003 - gEfiEdkNt32PkgTokenSpaceGuid - UINT64 - 8 - - 0 - 0 - - - + PcdTestDynamicBoolean 0x00011004 gEfiEdkNt32PkgTokenSpaceGuid diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java index 29819dd0d7..610739e48b 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java @@ -37,10 +37,10 @@ import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions; import org.tianocore.FrameworkModulesDocument; -import org.tianocore.PlatformSurfaceAreaDocument; -import org.tianocore.PcdBuildDefinitionDocument; import org.tianocore.ModuleSADocument; +import org.tianocore.PcdBuildDefinitionDocument; import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition; +import org.tianocore.PlatformSurfaceAreaDocument; import org.tianocore.build.autogen.CommonDefinition; import org.tianocore.build.fpd.FpdParserTask; import org.tianocore.build.global.GlobalData; @@ -2020,6 +2020,244 @@ public class CollectPCDAction { token.addUsageInstance(usageInstance); } } + + // + // ------------------------------------------------ + // 3), Add unreference dynamic_Ex pcd token into Pcd database. + // ------------------------------------------------ + // + List tokenArray = getUnreferencedDynamicPcd(); + if (tokenArray != null) { + for (index = 0; index < tokenArray.size(); index ++) { + dbManager.addTokenToDatabase(tokenArray.get(index).getPrimaryKeyString(), + tokenArray.get(index)); + } + } + } + + private List getUnreferencedDynamicPcd () throws EntityException { + List tokenArray = new ArrayList(); + Token token = null; + DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null; + List dynamicPcdBuildDataArray = null; + DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData = null; + List skuInfoList = null; + Token.PCD_TYPE pcdType; + SkuInstance skuInstance = null; + String primaryKey = null; + boolean hasSkuId0 = false; + int index, offset, index2; + String temp; + String exceptionString; + String hiiDefaultValue; + String tokenSpaceStrRet[]; + String variableGuidString[]; + + // + // If FPD document is not be opened, open and initialize it. + // + if (fpdDocInstance == null) { + try { + fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath)); + } catch(IOException ioE) { + throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage()); + } catch(XmlException xmlE) { + throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage()); + } + } + + dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions(); + if (dynamicPcdBuildDefinitions == null) { + return null; + } + + dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList(); + for (index2 = 0; index2 < dynamicPcdBuildDataArray.size(); index2 ++) { + pcdBuildData = dynamicPcdBuildDataArray.get(index2); + try { + tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(pcdBuildData.getTokenSpaceGuidCName()); + } catch ( Exception e ) { + throw new EntityException ("Faile get Guid for token " + pcdBuildData.getCName() + ":" + e.getMessage()); + } + + if (tokenSpaceStrRet == null) { + throw new EntityException ("Fail to get Token space guid for token" + pcdBuildData.getCName()); + } + + primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(), + translateSchemaStringToUUID(tokenSpaceStrRet[1])); + + if (dbManager.isTokenInDatabase(primaryKey)) { + continue; + } + + pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString()); + if (pcdType != Token.PCD_TYPE.DYNAMIC_EX) { + throw new EntityException (String.format("[FPD file error] It not allowed for DYNAMIC PCD %s who is no used by any module", + pcdBuildData.getCName())); + } + + // + // Create new token for unreference dynamic PCD token + // + token = new Token(pcdBuildData.getCName(), translateSchemaStringToUUID(tokenSpaceStrRet[1])); + token.datumSize = pcdBuildData.getMaxDatumSize(); + + + token.datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString()); + token.tokenNumber = Long.decode(pcdBuildData.getToken().toString()); + token.dynamicExTokenNumber = token.tokenNumber; + token.isDynamicPCD = true; + token.updateSupportPcdType(pcdType); + + exceptionString = verifyDatum(token.cName, + null, + null, + token.datumType, + token.datumSize); + if (exceptionString != null) { + throw new EntityException(exceptionString); + } + + skuInfoList = pcdBuildData.getSkuInfoList(); + + // + // Loop all sku data + // + for (index = 0; index < skuInfoList.size(); index ++) { + skuInstance = new SkuInstance(); + // + // Although SkuId in schema is BigInteger, but in fact, sku id is 32 bit value. + // + temp = skuInfoList.get(index).getSkuId().toString(); + skuInstance.id = Integer.decode(temp); + if (skuInstance.id == 0) { + hasSkuId0 = true; + } + // + // Judge whether is DefaultGroup at first, because most case is DefautlGroup. + // + if (skuInfoList.get(index).getValue() != null) { + skuInstance.value.setValue(skuInfoList.get(index).getValue().toString()); + if ((exceptionString = verifyDatum(token.cName, + null, + skuInfoList.get(index).getValue().toString(), + token.datumType, + token.datumSize)) != null) { + throw new EntityException(exceptionString); + } + + token.skuData.add(skuInstance); + + continue; + } + + // + // Judge whether is HII group case. + // + if (skuInfoList.get(index).getVariableName() != null) { + exceptionString = null; + if (skuInfoList.get(index).getVariableGuid() == null) { + exceptionString = String.format("[FPD file error] For dynamic PCD %s in section in FPD "+ + "file, who use HII, but there is no defined for Sku %d data!", + token.cName, + index); + if (exceptionString != null) { + throw new EntityException(exceptionString); + } + } + + if (skuInfoList.get(index).getVariableOffset() == null) { + exceptionString = String.format("[FPD file error] For dynamic PCD %s in section in FPD "+ + "file, who use HII, but there is no defined for Sku %d data!", + token.cName, + index); + if (exceptionString != null) { + throw new EntityException(exceptionString); + } + } + + if (skuInfoList.get(index).getHiiDefaultValue() == null) { + exceptionString = String.format("[FPD file error] For dynamic PCD %s in section in FPD "+ + "file, who use HII, but there is no defined for Sku %d data!", + token.cName, + index); + if (exceptionString != null) { + throw new EntityException(exceptionString); + } + } + + if (skuInfoList.get(index).getHiiDefaultValue() != null) { + hiiDefaultValue = skuInfoList.get(index).getHiiDefaultValue().toString(); + } else { + hiiDefaultValue = null; + } + + if ((exceptionString = verifyDatum(token.cName, + null, + hiiDefaultValue, + token.datumType, + token.datumSize)) != null) { + throw new EntityException(exceptionString); + } + + offset = Integer.decode(skuInfoList.get(index).getVariableOffset()); + if (offset > 0xFFFF) { + throw new EntityException(String.format("[FPD file error] For dynamic PCD %s , the variable offset defined in sku %d data "+ + "exceed 64K, it is not allowed!", + token.cName, + index)); + } + + // + // Get variable guid string according to the name of guid which will be mapped into a GUID in SPD file. + // + variableGuidString = GlobalData.getGuidInfoFromCname(skuInfoList.get(index).getVariableGuid().toString()); + if (variableGuidString == null) { + throw new EntityException(String.format("[GUID Error] For dynamic PCD %s, the variable guid %s can be found in all SPD file!", + token.cName, + skuInfoList.get(index).getVariableGuid().toString())); + } + String variableStr = skuInfoList.get(index).getVariableName(); + Pattern pattern = Pattern.compile("0x([a-fA-F0-9]){4}"); + Matcher matcher = pattern.matcher(variableStr); + List varNameList = new ArrayList(); + while (matcher.find()){ + String str = variableStr.substring(matcher.start(),matcher.end()); + varNameList.add(str); + } + + skuInstance.value.setHiiData(varNameList, + translateSchemaStringToUUID(variableGuidString[1]), + skuInfoList.get(index).getVariableOffset(), + skuInfoList.get(index).getHiiDefaultValue().toString()); + token.skuData.add(skuInstance); + continue; + } + + if (skuInfoList.get(index).getVpdOffset() != null) { + skuInstance.value.setVpdData(skuInfoList.get(index).getVpdOffset()); + token.skuData.add(skuInstance); + continue; + } + + exceptionString = String.format("[FPD file error] For dynamic PCD %s, the dynamic info must "+ + "be one of 'DefaultGroup', 'HIIGroup', 'VpdGroup'.", + token.cName); + throw new EntityException(exceptionString); + } + + if (!hasSkuId0) { + exceptionString = String.format("[FPD file error] For dynamic PCD %s in , there are "+ + "no sku id = 0 data, which is required for every dynamic PCD", + token.cName); + throw new EntityException(exceptionString); + } + + tokenArray.add(token); + } + + return tokenArray; } /** @@ -2769,14 +3007,14 @@ public class CollectPCDAction { **/ public static void main(String argv[]) throws EntityException { CollectPCDAction ca = new CollectPCDAction(); - ca.setWorkspacePath("f:/tianocore/edk2"); - ca.setFPDFilePath("f:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd"); + ca.setWorkspacePath("m:/tianocore/edk2"); + ca.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd"); ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL); GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db", - "f:/tianocore/edk2", + "m:/tianocore/edk2", "tools_def.txt"); FpdParserTask fpt = new FpdParserTask(); - fpt.parseFpdFile(new File("f:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd")); + fpt.parseFpdFile(new File("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd")); ca.execute(); } } diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/MemoryDatabaseManager.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/MemoryDatabaseManager.java index 0439c11d7c..2e29106323 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/MemoryDatabaseManager.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/MemoryDatabaseManager.java @@ -197,11 +197,15 @@ public class MemoryDatabaseManager { } if (!found) { - // - // We only support Dynamice(EX) type for PEI and DXE phase. - // If it is not referenced in either PEI or DXE, throw exception now. - // - throw new EntityException("Dynamic(EX) PCD Entries are referenced in module that is not in PEI phase nor in DXE phase."); + if (token.isDynamicPCD && token.consumers.size() == 0) { + dxe.add(token); + } else { + // + // We only support Dynamice(EX) type for PEI and DXE phase. + // If it is not referenced in either PEI or DXE, throw exception now. + // + throw new EntityException("Dynamic(EX) PCD Entries are referenced in module that is not in PEI phase nor in DXE phase."); + } } } } -- 2.39.2