BaseTools: Add mixed PCD support feature
authorYonghong Zhu <yonghong.zhu@intel.com>
Tue, 12 Apr 2016 02:31:55 +0000 (10:31 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 20 Apr 2016 01:24:46 +0000 (09:24 +0800)
Problem statement:
The current build system requires that a PCD must use the same access
method for all modules. A Binary Module may use a different PCD access
method than: 1.A source tree build it is integrated into. 2.Other Binary
Modules in platform build that use the same PCD.

Solution:
1. Source build:
No change. PCDs must use the same access method for building all Source
Modules.
2. Mixed Source & Binary Builds or Binary Only Builds:
1) Source Modules - No changes
2) Module that is interpreted as a Binary Module
a.DSC file may optionally override default value of PatchableInModule
PCDs in scope of Binary Module.
b.DSC file must declare DynamicEx PCD subtype for all DynamicEx PCDs
from Binary Modules.
c.FDF file must list Binary Module INF

Build update:
1. PCDs in a binary module are permitted to use the PatchableInModule
or DynamicEx access methods (the Binary INF clearly identifies the PCD
access method for each PCD). The build must support binary modules that
use the same or different PCD access method than the Source INFs or
other Binary INFs.
2. Build report list PCDs that have mixed PCD access methods.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools/Source/Python/AutoGen/GenC.py
BaseTools/Source/Python/AutoGen/GenPcdDb.py
BaseTools/Source/Python/Common/GlobalData.py
BaseTools/Source/Python/Common/VpdInfoFile.py
BaseTools/Source/Python/Workspace/WorkspaceCommon.py
BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
BaseTools/Source/Python/build/BuildReport.py

index 50d585f6aa010360f5c541a19e8a1ffc6193e582..2cc6970325fffb4a5ee2d4a5b189e77f770a8990 100644 (file)
@@ -413,6 +413,129 @@ class WorkspaceAutoGen(AutoGen):
                     if (TokenCName, TokenSpaceGuidCName) in PcdSet:\r
                         PcdSet[(TokenCName, TokenSpaceGuidCName)] = NewValue\r
 \r
+            SourcePcdDict = {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}\r
+            BinaryPcdDict = {'DynamicEx':[], 'PatchableInModule':[]}\r
+            SourcePcdDict_Keys = SourcePcdDict.keys()\r
+            BinaryPcdDict_Keys = BinaryPcdDict.keys()\r
+\r
+            # generate the SourcePcdDict and BinaryPcdDict\r
+            for BuildData in PGen.BuildDatabase._CACHE_.values():\r
+                if BuildData.Arch != Arch:\r
+                    continue\r
+                if BuildData.MetaFile.Ext == '.inf':\r
+                    for key in BuildData.Pcds:\r
+                        if BuildData.Pcds[key].Pending:\r
+                            if key in Platform.Pcds:\r
+                                PcdInPlatform = Platform.Pcds[key]\r
+                                if PcdInPlatform.Type not in [None, '']:\r
+                                    BuildData.Pcds[key].Type = PcdInPlatform.Type\r
+\r
+                            if BuildData.MetaFile in Platform.Modules:\r
+                                PlatformModule = Platform.Modules[str(BuildData.MetaFile)]\r
+                                if key in PlatformModule.Pcds:\r
+                                    PcdInPlatform = PlatformModule.Pcds[key]\r
+                                    if PcdInPlatform.Type not in [None, '']:\r
+                                        BuildData.Pcds[key].Type = PcdInPlatform.Type\r
+\r
+                        if 'DynamicEx' in BuildData.Pcds[key].Type:\r
+                            if BuildData.IsBinaryModule:\r
+                                if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['DynamicEx']:\r
+                                    BinaryPcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                            else:\r
+                                if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['DynamicEx']:\r
+                                    SourcePcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+\r
+                        elif 'PatchableInModule' in BuildData.Pcds[key].Type:\r
+                            if BuildData.MetaFile.Ext == '.inf':\r
+                                if BuildData.IsBinaryModule:\r
+                                    if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['PatchableInModule']:\r
+                                        BinaryPcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                                else:\r
+                                    if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['PatchableInModule']:\r
+                                        SourcePcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+\r
+                        elif 'Dynamic' in BuildData.Pcds[key].Type:\r
+                            if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['Dynamic']:\r
+                                SourcePcdDict['Dynamic'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                        elif 'FixedAtBuild' in BuildData.Pcds[key].Type:\r
+                            if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['FixedAtBuild']:\r
+                                SourcePcdDict['FixedAtBuild'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                else:\r
+                    pass\r
+\r
+            #\r
+            # intersection the BinaryPCD for Mixed PCD\r
+            #\r
+            for i in BinaryPcdDict_Keys:\r
+                for j in BinaryPcdDict_Keys:\r
+                    if i != j:\r
+                        IntersectionList = list(set(BinaryPcdDict[i]).intersection(set(BinaryPcdDict[j])))\r
+                        for item in IntersectionList:\r
+                            NewPcd1 = (item[0] + '_' + i, item[1])\r
+                            NewPcd2 = (item[0] + '_' + j, item[1])\r
+                            if item not in GlobalData.MixedPcd:\r
+                                GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
+                            else:\r
+                                if NewPcd1 not in GlobalData.MixedPcd[item]:\r
+                                    GlobalData.MixedPcd[item].append(NewPcd1)\r
+                                if NewPcd2 not in GlobalData.MixedPcd[item]:\r
+                                    GlobalData.MixedPcd[item].append(NewPcd2)\r
+                    else:\r
+                        pass\r
+\r
+            #\r
+            # intersection the SourcePCD and BinaryPCD for Mixed PCD\r
+            #\r
+            for i in SourcePcdDict_Keys:\r
+                for j in BinaryPcdDict_Keys:\r
+                    if i != j:\r
+                        IntersectionList = list(set(SourcePcdDict[i]).intersection(set(BinaryPcdDict[j])))\r
+                        for item in IntersectionList:\r
+                            NewPcd1 = (item[0] + '_' + i, item[1])\r
+                            NewPcd2 = (item[0] + '_' + j, item[1])\r
+                            if item not in GlobalData.MixedPcd:\r
+                                GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
+                            else:\r
+                                if NewPcd1 not in GlobalData.MixedPcd[item]:\r
+                                    GlobalData.MixedPcd[item].append(NewPcd1)\r
+                                if NewPcd2 not in GlobalData.MixedPcd[item]:\r
+                                    GlobalData.MixedPcd[item].append(NewPcd2)\r
+                    else:\r
+                        pass\r
+\r
+            for BuildData in PGen.BuildDatabase._CACHE_.values():\r
+                if BuildData.Arch != Arch:\r
+                    continue\r
+                for key in BuildData.Pcds:\r
+                    for SinglePcd in GlobalData.MixedPcd:\r
+                        if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
+                            for item in GlobalData.MixedPcd[SinglePcd]:\r
+                                Pcd_Type = item[0].split('_')[-1]\r
+                                if (Pcd_Type == BuildData.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and BuildData.Pcds[key].Type in GenC.gDynamicExPcd) or \\r
+                                   (Pcd_Type == TAB_PCDS_DYNAMIC and BuildData.Pcds[key].Type in GenC.gDynamicPcd):\r
+                                    Value = BuildData.Pcds[key]\r
+                                    Value.TokenCName = BuildData.Pcds[key].TokenCName + '_' + Pcd_Type\r
+                                    if len(key) == 2:\r
+                                        newkey = (Value.TokenCName, key[1])\r
+                                    elif len(key) == 3:\r
+                                        newkey = (Value.TokenCName, key[1], key[2])\r
+                                    del BuildData.Pcds[key]\r
+                                    BuildData.Pcds[newkey] = Value\r
+                                    break\r
+                                else:\r
+                                    pass\r
+                            break\r
+                        else:\r
+                            pass\r
+\r
+            # handle the mixed pcd in FDF file\r
+            for key in PcdSet:\r
+                if key in GlobalData.MixedPcd:\r
+                    Value = PcdSet[key]\r
+                    del PcdSet[key]\r
+                    for item in GlobalData.MixedPcd[key]:\r
+                        PcdSet[item] = Value\r
+\r
             #Collect package set information from INF of FDF\r
             PkgSet = set()\r
             for Inf in ModuleList:\r
@@ -770,17 +893,23 @@ class WorkspaceAutoGen(AutoGen):
                         SameTokenValuePcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
                         SameTokenValuePcdListCount = 0\r
                         while (SameTokenValuePcdListCount < len(SameTokenValuePcdList) - 1):\r
+                            Flag = False\r
                             TemListItem = SameTokenValuePcdList[SameTokenValuePcdListCount]\r
                             TemListItemNext = SameTokenValuePcdList[SameTokenValuePcdListCount + 1]\r
 \r
                             if (TemListItem.TokenSpaceGuidCName == TemListItemNext.TokenSpaceGuidCName) and (TemListItem.TokenCName != TemListItemNext.TokenCName):\r
-                                EdkLogger.error(\r
-                                            'build',\r
-                                            FORMAT_INVALID,\r
-                                            "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\\r
-                                            % (TemListItem.TokenValue, TemListItem.TokenSpaceGuidCName, TemListItem.TokenCName, TemListItemNext.TokenSpaceGuidCName, TemListItemNext.TokenCName, Package),\r
-                                            ExtraData=None\r
-                                            )\r
+                                for PcdItem in GlobalData.MixedPcd:\r
+                                    if (TemListItem.TokenCName, TemListItem.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem] or \\r
+                                        (TemListItemNext.TokenCName, TemListItemNext.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                                        Flag = True\r
+                                if not Flag:\r
+                                    EdkLogger.error(\r
+                                                'build',\r
+                                                FORMAT_INVALID,\r
+                                                "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\\r
+                                                % (TemListItem.TokenValue, TemListItem.TokenSpaceGuidCName, TemListItem.TokenCName, TemListItemNext.TokenSpaceGuidCName, TemListItemNext.TokenCName, Package),\r
+                                                ExtraData=None\r
+                                                )\r
                             SameTokenValuePcdListCount += 1\r
                         Count += SameTokenValuePcdListCount\r
                     Count += 1\r
@@ -1055,6 +1184,28 @@ class PlatformAutoGen(AutoGen):
                             Sku.DefaultValue = PcdItem[2]\r
                         break\r
 \r
+        for key in self.Platform.Pcds:\r
+            for SinglePcd in GlobalData.MixedPcd:\r
+                if (self.Platform.Pcds[key].TokenCName, self.Platform.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
+                    for item in GlobalData.MixedPcd[SinglePcd]:\r
+                        Pcd_Type = item[0].split('_')[-1]\r
+                        if (Pcd_Type == self.Platform.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and self.Platform.Pcds[key].Type in GenC.gDynamicExPcd) or \\r
+                           (Pcd_Type == TAB_PCDS_DYNAMIC and self.Platform.Pcds[key].Type in GenC.gDynamicPcd):\r
+                            Value = self.Platform.Pcds[key]\r
+                            Value.TokenCName = self.Platform.Pcds[key].TokenCName + '_' + Pcd_Type\r
+                            if len(key) == 2:\r
+                                newkey = (Value.TokenCName, key[1])\r
+                            elif len(key) == 3:\r
+                                newkey = (Value.TokenCName, key[1], key[2])\r
+                            del self.Platform.Pcds[key]\r
+                            self.Platform.Pcds[newkey] = Value\r
+                            break\r
+                        else:\r
+                            pass\r
+                    break\r
+                else:\r
+                    pass\r
+\r
         # for gathering error information\r
         NoDatumTypePcdList = set()\r
         PcdNotInDb = []\r
@@ -1931,7 +2082,17 @@ class PlatformAutoGen(AutoGen):
         # at this point, ToPcd.Type has the type found from dependent\r
         # package\r
         #\r
+        TokenCName = ToPcd.TokenCName\r
+        for PcdItem in GlobalData.MixedPcd:\r
+            if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                TokenCName = PcdItem[0]\r
+                break\r
         if FromPcd != None:\r
+            if GlobalData.BuildOptionPcd:\r
+                for pcd in GlobalData.BuildOptionPcd:\r
+                    if (FromPcd.TokenSpaceGuidCName, FromPcd.TokenCName) == (pcd[0], pcd[1]):\r
+                        FromPcd.DefaultValue = pcd[2]\r
+                        break\r
             if ToPcd.Pending and FromPcd.Type not in [None, '']:\r
                 ToPcd.Type = FromPcd.Type\r
             elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\\r
@@ -1942,7 +2103,7 @@ class PlatformAutoGen(AutoGen):
                 and ToPcd.Type != FromPcd.Type:\r
                 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
                                 ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\\r
-                                          % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName,\r
+                                          % (ToPcd.TokenSpaceGuidCName, TokenCName,\r
                                              ToPcd.Type, Module, FromPcd.Type),\r
                                           File=self.MetaFile)\r
 \r
@@ -1963,14 +2124,14 @@ class PlatformAutoGen(AutoGen):
             IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)\r
             if not IsValid:\r
                 EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,\r
-                                ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName))\r
+                                ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
             ToPcd.validateranges = FromPcd.validateranges\r
             ToPcd.validlists = FromPcd.validlists\r
             ToPcd.expressions = FromPcd.expressions\r
 \r
         if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:\r
             EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
-                            % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName))\r
+                            % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
             Value = ToPcd.DefaultValue\r
             if Value in [None, '']:\r
                 ToPcd.MaxDatumSize = '1'\r
@@ -3572,9 +3733,14 @@ class ModuleAutoGen(AutoGen):
                         )\r
         if PatchList:\r
             for PatchPcd in PatchList:\r
-                if PatchPcd[0] not in PatchablePcds:\r
+                if PatchPcd[0] in PatchablePcds:\r
+                    key = PatchPcd[0]\r
+                elif PatchPcd[0] + '_PatchableInModule' in PatchablePcds:\r
+                    key = PatchPcd[0] + '_PatchableInModule'\r
+                else:\r
                     continue\r
-                Pcd = PatchablePcds[PatchPcd[0]]\r
+                Pcd = PatchablePcds[key]\r
+                TokenCName = PatchPcd[0]\r
                 PcdValue = ''\r
                 if Pcd.DatumType != 'VOID*':\r
                     HexFormat = '0x%02x'\r
@@ -3588,7 +3754,7 @@ class ModuleAutoGen(AutoGen):
                 else:\r
                     if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':\r
                         EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                        "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
+                                        "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName)\r
                                         )\r
                     ArraySize = int(Pcd.MaxDatumSize, 0)\r
                     PcdValue = Pcd.DefaultValue\r
@@ -3612,7 +3778,7 @@ class ModuleAutoGen(AutoGen):
                             ArraySize = ArraySize / 2\r
                         if ArraySize < (len(PcdValue) + 1):\r
                             EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                            "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
+                                            "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
                                             )\r
                         if ArraySize > len(PcdValue) + 1:\r
                             NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)\r
@@ -3622,10 +3788,10 @@ class ModuleAutoGen(AutoGen):
                         PcdValue += '}'\r
                     else:\r
                         EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                        "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
+                                        "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
                                         )\r
                 PcdItem = '%s.%s|%s|0x%X' % \\r
-                    (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, PcdValue, PatchPcd[1])\r
+                    (Pcd.TokenSpaceGuidCName, TokenCName, PcdValue, PatchPcd[1])\r
                 PcdComments = ''\r
                 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
                     PcdComments = '\n  '.join(self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName])\r
@@ -3639,6 +3805,11 @@ class ModuleAutoGen(AutoGen):
             PcdCommentList = []\r
             HiiInfo = ''\r
             SkuId = ''\r
+            TokenCName = Pcd.TokenCName\r
+            for PcdItem in GlobalData.MixedPcd:\r
+                if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                    TokenCName = PcdItem[0]\r
+                    break\r
             if Pcd.Type == TAB_PCDS_DYNAMIC_EX_HII:\r
                 for SkuName in Pcd.SkuInfoList:\r
                     SkuInfo = Pcd.SkuInfoList[SkuName]\r
@@ -3669,7 +3840,7 @@ class ModuleAutoGen(AutoGen):
                 else:\r
                     PcdCommentList.append('## UNDEFINED ' + HiiInfo)\r
             PcdComments = '\n  '.join(PcdCommentList)\r
-            PcdEntry = Pcd.TokenSpaceGuidCName + '.' + Pcd.TokenCName\r
+            PcdEntry = Pcd.TokenSpaceGuidCName + '.' + TokenCName\r
             if PcdComments:\r
                 PcdEntry = PcdComments + '\n  ' + PcdEntry\r
             AsBuiltInfDict['pcd_item'] += [PcdEntry]\r
index 842d8bd6663a8ad7f6bdc1929dd4ff10e21e9d6d..d25d371a468d07a7dd74a02e5a47869d195404e2 100644 (file)
@@ -693,15 +693,20 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
         Index = 0\r
         Count = ExTokenCNameList.count(TokenCName)\r
         for Pcd in PcdExList:\r
+            RealTokenCName = Pcd.TokenCName\r
+            for PcdItem in GlobalData.MixedPcd:\r
+                if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                    RealTokenCName = PcdItem[0]\r
+                    break\r
             if Pcd.TokenCName == TokenCName:\r
                 Index = Index + 1\r
                 if Index == 1:\r
-                    AutoGenH.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr)  (' % (Pcd.TokenCName))\r
+                    AutoGenH.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr)  (' % (RealTokenCName))\r
                     AutoGenH.Append('\\\n  (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
-                                    % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
+                                    % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
                 else:\r
                     AutoGenH.Append('\\\n  (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
-                                    % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
+                                    % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
                 if Index == Count:\r
                     AutoGenH.Append('0 \\\n  )\n')\r
                 TokenCNameList.append(TokenCName)\r
@@ -713,16 +718,21 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
         Index = 0\r
         Count = ExTokenCNameList.count(TokenCName)\r
         for Pcd in PcdExList:\r
+            RealTokenCName = Pcd.TokenCName\r
+            for PcdItem in GlobalData.MixedPcd:\r
+                if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                    RealTokenCName = PcdItem[0]\r
+                    break\r
             if Pcd.Type in gDynamicExPcd and Pcd.TokenCName == TokenCName:\r
                 Index = Index + 1\r
                 if Index == 1:\r
-                    AutoGenH.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr)  (' % (Pcd.TokenCName))\r
+                    AutoGenH.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr)  (' % (RealTokenCName))\r
                     AutoGenH.Append('\\\n  (GuidPtr == NULL) ? 0:')\r
                     AutoGenH.Append('\\\n  COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
-                                    % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
+                                    % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
                 else:\r
                     AutoGenH.Append('\\\n  COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
-                                    % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
+                                    % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
                 if Index == Count:\r
                     AutoGenH.Append('0 \\\n  )\n')\r
                     # Autogen internal worker macro to compare GUIDs.  Guid1 is a pointer to a GUID.  \r
@@ -730,7 +740,7 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
                     # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().\r
                     #  COMPAREGUID() will only be used if the Guid passed in is local to the module.\r
                     AutoGenH.Append('#define _PCD_TOKEN_EX_%s(GuidPtr)   __PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : __PCD_%s_VAL_CMP(GuidPtr)  \n'\r
-                                    % (Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))\r
+                                    % (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))\r
                 TokenCNameList.append(TokenCName)\r
 \r
 def GetPcdSize(Pcd):\r
@@ -766,26 +776,30 @@ def GetPcdSize(Pcd):
 def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
     TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue   #Info.GuidList[Pcd.TokenSpaceGuidCName]\r
     PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
+    #\r
+    # Write PCDs\r
+    #\r
+    TokenCName = Pcd.TokenCName\r
+    for PcdItem in GlobalData.MixedPcd:\r
+        if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+            TokenCName = PcdItem[0]\r
+            break\r
+    PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
+    PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
+    PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
+    FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
 \r
     if GlobalData.BuildOptionPcd:\r
         for PcdItem in GlobalData.BuildOptionPcd:\r
-            if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (PcdItem[0], PcdItem[1]):\r
+            if (Pcd.TokenSpaceGuidCName, TokenCName) == (PcdItem[0], PcdItem[1]):\r
                 Pcd.DefaultValue = PcdItem[2]\r
                 break\r
-\r
-    #\r
-    # Write PCDs\r
-    #\r
-    PcdTokenName = '_PCD_TOKEN_' + Pcd.TokenCName\r
-    PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + Pcd.TokenCName +'_SIZE'\r
-    PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + Pcd.TokenCName\r
-    FixPcdSizeTokenName = '_PCD_SIZE_' + Pcd.TokenCName\r
     \r
     if Pcd.Type in gDynamicExPcd:\r
         TokenNumber = int(Pcd.TokenValue, 0)\r
         # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with \r
         # different Guids but same TokenCName\r
-        PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + Pcd.TokenCName\r
+        PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + TokenCName\r
         AutoGenH.Append('\n#define %s  %dU\n' % (PcdExTokenName, TokenNumber))\r
     else:\r
         if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
@@ -801,28 +815,28 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 TokenNumber = 0\r
             else:\r
                 EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
                                 ExtraData="[%s]" % str(Info))\r
         else:\r
             TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
         AutoGenH.Append('\n#define %s  %dU\n' % (PcdTokenName, TokenNumber))\r
 \r
-    EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + Pcd.TokenCName + "." + Pcd.TokenSpaceGuidCName)\r
+    EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + TokenCName + "." + Pcd.TokenSpaceGuidCName)\r
     if Pcd.Type not in gItemTypeStringDatabase:\r
         EdkLogger.error("build", AUTOGEN_ERROR,\r
-                        "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                        "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
                         ExtraData="[%s]" % str(Info))\r
     if Pcd.DatumType not in gDatumSizeStringDatabase:\r
         EdkLogger.error("build", AUTOGEN_ERROR,\r
-                        "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                        "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                         ExtraData="[%s]" % str(Info))\r
 \r
     DatumSize = gDatumSizeStringDatabase[Pcd.DatumType]\r
     DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType]\r
-    GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName\r
-    SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName\r
-    SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + Pcd.TokenCName\r
-    GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + Pcd.TokenCName\r
+    GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName\r
+    SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName\r
+    SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName\r
+    GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
     \r
     PcdExCNameList  = []\r
     if Pcd.Type in gDynamicExPcd:\r
@@ -866,7 +880,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
             if PcdModule.Type in gDynamicPcd:\r
                 PcdCNameList.append(PcdModule.TokenCName)\r
         if PcdCNameList.count(Pcd.TokenCName) > 1:\r
-            EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName. They need to be changed to DynamicEx type to avoid the confliction.\n" % (Pcd.TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
+            EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName. They need to be changed to DynamicEx type to avoid the confliction.\n" % (TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
         else:\r
             AutoGenH.Append('#define %s  LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
             AutoGenH.Append('#define %s  LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
@@ -877,7 +891,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 AutoGenH.Append('#define %s(Value)  LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
                 AutoGenH.Append('#define %s(Value)  LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
     else:\r
-        PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + Pcd.TokenCName\r
+        PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName\r
         Const = 'const'\r
         if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
             Const = ''\r
@@ -902,56 +916,56 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                     ValueNumber = int (Value)\r
             except:\r
                 EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                                 ExtraData="[%s]" % str(Info))\r
             if Pcd.DatumType == 'UINT64':\r
                 if ValueNumber < 0:\r
                     EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                    "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                    "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                                     ExtraData="[%s]" % str(Info))\r
                 elif ValueNumber >= 0x10000000000000000:\r
                     EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                    "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                    "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                                     ExtraData="[%s]" % str(Info))\r
                 if not Value.endswith('ULL'):\r
                     Value += 'ULL'\r
             elif Pcd.DatumType == 'UINT32':\r
                 if ValueNumber < 0:\r
                     EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                    "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                    "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                                     ExtraData="[%s]" % str(Info))\r
                 elif ValueNumber >= 0x100000000:\r
                     EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                    "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                    "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                                     ExtraData="[%s]" % str(Info))\r
                 if not Value.endswith('U'):\r
                     Value += 'U'\r
             elif Pcd.DatumType == 'UINT16':\r
                 if ValueNumber < 0:\r
                     EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                    "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                    "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                                     ExtraData="[%s]" % str(Info))\r
                 elif ValueNumber >= 0x10000:\r
                     EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                    "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                    "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                                     ExtraData="[%s]" % str(Info))\r
                 if not Value.endswith('U'):\r
                     Value += 'U'                    \r
             elif Pcd.DatumType == 'UINT8':\r
                 if ValueNumber < 0:\r
                     EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                    "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                    "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                                     ExtraData="[%s]" % str(Info))\r
                 elif ValueNumber >= 0x100:\r
                     EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                    "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                    "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                                     ExtraData="[%s]" % str(Info))\r
                 if not Value.endswith('U'):\r
                     Value += 'U'\r
         if Pcd.DatumType == 'VOID*':\r
             if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':\r
                 EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
                                 ExtraData="[%s]" % str(Info))\r
 \r
             ArraySize = int(Pcd.MaxDatumSize, 0)\r
@@ -973,7 +987,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
 \r
                 if ArraySize < (len(Value) + 1):\r
                     EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                    "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                    "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),\r
                                     ExtraData="[%s]" % str(Info))\r
                 Value = NewValue + '0 }'\r
             Array = '[%d]' % ArraySize\r
@@ -985,9 +999,9 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
             Value = "((%s)%s)" % (Pcd.DatumType, Value)\r
 \r
         if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
-            PcdValueName = '_PCD_PATCHABLE_VALUE_' + Pcd.TokenCName\r
+            PcdValueName = '_PCD_PATCHABLE_VALUE_' + TokenCName\r
         else:\r
-            PcdValueName = '_PCD_VALUE_' + Pcd.TokenCName\r
+            PcdValueName = '_PCD_VALUE_' + TokenCName\r
             \r
         if Pcd.DatumType == 'VOID*':\r
             #\r
@@ -1057,14 +1071,18 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
     PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
     TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
     TokenCName  = Pcd.TokenCName\r
+    for PcdItem in GlobalData.MixedPcd:\r
+        if (TokenCName, TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+            TokenCName = PcdItem[0]\r
+            break\r
     PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
-    FixPcdSizeTokenName = '_PCD_SIZE_' + Pcd.TokenCName\r
-    PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + Pcd.TokenCName +'_SIZE'\r
-    PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + Pcd.TokenCName\r
+    FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
+    PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
+    PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
 \r
     if GlobalData.BuildOptionPcd:\r
         for PcdItem in GlobalData.BuildOptionPcd:\r
-            if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (PcdItem[0], PcdItem[1]):\r
+            if (Pcd.TokenSpaceGuidCName, TokenCName) == (PcdItem[0], PcdItem[1]):\r
                 Pcd.DefaultValue = PcdItem[2]\r
                 break\r
 \r
@@ -1087,18 +1105,18 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 TokenNumber = 0\r
             else:\r
                 EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                                "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
                                 ExtraData="[%s]" % str(Info))\r
         else:\r
             TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
 \r
     if Pcd.Type not in gItemTypeStringDatabase:\r
         EdkLogger.error("build", AUTOGEN_ERROR,\r
-                        "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                        "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
                         ExtraData="[%s]" % str(Info))\r
     if Pcd.DatumType not in gDatumSizeStringDatabase:\r
         EdkLogger.error("build", AUTOGEN_ERROR,\r
-                        "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
+                        "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
                         ExtraData="[%s]" % str(Info))\r
 \r
     DatumType   = Pcd.DatumType\r
@@ -1107,7 +1125,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
     GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName\r
     SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName\r
     SetModeStatusName = '_PCD_SET_MODE_' + DatumSize + '_S_' + TokenCName\r
-    GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + Pcd.TokenCName\r
+    GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
 \r
     Type = ''\r
     Array = ''\r
@@ -1118,7 +1136,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
     PcdItemType = Pcd.Type\r
     PcdExCNameList  = []\r
     if PcdItemType in gDynamicExPcd:\r
-        PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + Pcd.TokenCName\r
+        PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName\r
         AutoGenH.Append('\n#define %s  %dU\n' % (PcdExTokenName, TokenNumber))\r
         \r
         if Info.IsLibrary:\r
@@ -1163,7 +1181,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
             if PcdModule.Type in gDynamicPcd:\r
                 PcdCNameList.append(PcdModule.TokenCName)\r
         if PcdCNameList.count(Pcd.TokenCName) > 1:\r
-            EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName.They need to be changed to DynamicEx type to avoid the confliction.\n" % (Pcd.TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
+            EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName.They need to be changed to DynamicEx type to avoid the confliction.\n" % (TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
         else:\r
             AutoGenH.Append('#define %s  LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
             AutoGenH.Append('#define %s  LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
@@ -1186,8 +1204,8 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
             AutoGenH.Append('extern volatile  %s  %s%s;\n' % (DatumType, PcdVariableName, Array))\r
         AutoGenH.Append('#define %s  %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))\r
         if Pcd.DatumType == 'VOID*':\r
-            AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))\r
-            AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))\r
+            AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, TokenCName, TokenCName))\r
+            AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, TokenCName, TokenCName))\r
         else:\r
             AutoGenH.Append('#define %s(Value)  (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
             AutoGenH.Append('#define %s(Value)  ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName))\r
index 76d1254e72ed5d50dcdab50bff677c57f16b7c90..d5997f0e66aaf16d7a6f112f6bbcecb927a3b4e9 100644 (file)
@@ -1141,9 +1141,13 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
         CName = Pcd.TokenCName\r
         TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
 \r
+        for PcdItem in GlobalData.MixedPcd:\r
+            if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                CName = PcdItem[0]\r
+\r
         if GlobalData.BuildOptionPcd:\r
             for PcdItem in GlobalData.BuildOptionPcd:\r
-                if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (PcdItem[0], PcdItem[1]):\r
+                if (Pcd.TokenSpaceGuidCName, CName) == (PcdItem[0], PcdItem[1]):\r
                     Pcd.DefaultValue = PcdItem[2]\r
                     break\r
 \r
@@ -1461,11 +1465,6 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
         TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
         if Pcd.Phase != Phase:\r
             continue\r
-        if GlobalData.BuildOptionPcd:\r
-            for PcdItem in GlobalData.BuildOptionPcd:\r
-                if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (PcdItem[0], PcdItem[1]):\r
-                    Pcd.DefaultValue = PcdItem[2]\r
-                    break\r
 \r
         TokenSpaceGuid = GuidStructureStringToGuidValueName(Pcd.TokenSpaceGuidValue) #(Platform.PackageList, TokenSpaceGuidCName))\r
         GeneratedTokenNumber = Platform.PcdTokenNumber[CName, TokenSpaceGuidCName] - 1\r
@@ -1475,6 +1474,17 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
         if len(Pcd.SkuInfoList) > 1:\r
             Dict['PCD_ORDER_TOKEN_NUMBER_MAP'][GeneratedTokenNumber] = SkuEnablePcdIndex\r
             SkuEnablePcdIndex += 1\r
+\r
+        for PcdItem in GlobalData.MixedPcd:\r
+            if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                CName = PcdItem[0]\r
+\r
+        if GlobalData.BuildOptionPcd:\r
+            for PcdItem in GlobalData.BuildOptionPcd:\r
+                if (Pcd.TokenSpaceGuidCName, CName) == (PcdItem[0], PcdItem[1]):\r
+                    Pcd.DefaultValue = PcdItem[2]\r
+                    break\r
+\r
         EdkLogger.debug(EdkLogger.DEBUG_1, "PCD = %s.%s" % (CName, TokenSpaceGuidCName))\r
         EdkLogger.debug(EdkLogger.DEBUG_1, "phase = %s" % Phase)\r
         EdkLogger.debug(EdkLogger.DEBUG_1, "GeneratedTokenNumber = %s" % str(GeneratedTokenNumber))\r
index 51e370925dc09d14b5cb8e46aef28ac7aedec098..667877e907edf82ba9ea9e016140fe4ccf3516ce 100644 (file)
@@ -80,5 +80,10 @@ gTempInfs = []
 \r
 BuildOptionPcd = []\r
 \r
+#\r
+# Mixed PCD name dict\r
+#\r
+MixedPcd = {}\r
+\r
 # Pcd name for the Pcd which used in the Conditional directives\r
 gConditionalPcds = []\r
index dc8ece9608a83111fb48a09a150a59eea7bf86fa..cc79ee275fd429fdcfb9ae9d9a5dd90682417f20 100644 (file)
@@ -20,6 +20,7 @@ import re
 import Common.EdkLogger as EdkLogger\r
 import Common.BuildToolError as BuildToolError\r
 import subprocess\r
+import Common.GlobalData as GlobalData\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 from Common.Misc import SaveFileOnChange\r
 \r
@@ -131,12 +132,16 @@ class VpdInfoFile:
         Pcds.sort()\r
         for Pcd in Pcds:\r
             i = 0\r
+            PcdTokenCName = Pcd.TokenCName\r
+            for PcdItem in GlobalData.MixedPcd:\r
+                if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                    PcdTokenCName = PcdItem[0]\r
             for Offset in self._VpdArray[Pcd]:\r
                 PcdValue = str(Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[i]].DefaultValue).strip()\r
                 if PcdValue == "" :\r
                     PcdValue  = Pcd.DefaultValue\r
 \r
-                Content += "%s.%s|%s|%s|%s|%s  \n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, str(Pcd.SkuInfoList.keys()[i]),str(Offset).strip(), str(Pcd.MaxDatumSize).strip(),PcdValue)\r
+                Content += "%s.%s|%s|%s|%s|%s  \n" % (Pcd.TokenSpaceGuidCName, PcdTokenCName, str(Pcd.SkuInfoList.keys()[i]),str(Offset).strip(), str(Pcd.MaxDatumSize).strip(),PcdValue)\r
                 i += 1\r
 \r
         return SaveFileOnChange(FilePath, Content, False)\r
@@ -174,8 +179,12 @@ class VpdInfoFile:
             Found = False\r
             \r
             for VpdObject in self._VpdArray.keys():\r
-                for sku in VpdObject.SkuInfoList.keys(): \r
-                    if VpdObject.TokenSpaceGuidCName == TokenSpaceName and VpdObject.TokenCName == PcdTokenName.strip() and sku == SkuId:\r
+                VpdObjectTokenCName = VpdObject.TokenCName\r
+                for PcdItem in GlobalData.MixedPcd:\r
+                    if (VpdObject.TokenCName, VpdObject.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                        VpdObjectTokenCName = PcdItem[0]\r
+                for sku in VpdObject.SkuInfoList.keys():\r
+                    if VpdObject.TokenSpaceGuidCName == TokenSpaceName and VpdObjectTokenCName == PcdTokenName.strip() and sku == SkuId:\r
                         if self._VpdArray[VpdObject][VpdObject.SkuInfoList.keys().index(sku)] == "*":\r
                             if Offset == "*":\r
                                 EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "The offset of %s has not been fixed up by third-party BPDG tool." % PcdName)                              \r
index 60acc914e9d262f6ab15c960ed854ed3a9272f6c..c224b8e0e631863299f828e273f6cb60e4f0ce28 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Common routines used by workspace\r
 #\r
-# Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -14,6 +14,7 @@
 from Common.Misc import sdict\r
 from Common.DataType import SUP_MODULE_USER_DEFINED\r
 from BuildClassObject import LibraryClassObject\r
+import Common.GlobalData as GlobalData\r
 \r
 ## Get all packages from platform for specified arch, target and toolchain\r
 #\r
@@ -47,7 +48,15 @@ def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain):
     DecPcds = {}\r
     for Pkg in PkgList:\r
         for Pcd in Pkg.Pcds:\r
-            DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
+            PcdCName = Pcd[0]\r
+            PcdTokenName = Pcd[1]\r
+            if GlobalData.MixedPcd:\r
+                for PcdItem in GlobalData.MixedPcd.keys():\r
+                    if (PcdCName, PcdTokenName) in GlobalData.MixedPcd[PcdItem]:\r
+                        PcdCName = PcdItem[0]\r
+                        break\r
+            if (PcdCName, PcdTokenName) not in DecPcds.keys():\r
+                DecPcds[PcdCName, PcdTokenName] = Pkg.Pcds[Pcd]\r
     return DecPcds\r
 \r
 ## Get all dependent libraries for a module\r
index 6c548ac7090deb13c8f23322cc3f3e5025212b2f..2e6c68e33aaef2a1961c1a02b4589f9d61c88ba8 100644 (file)
@@ -2563,6 +2563,7 @@ class InfBuildData(ModuleBuildClassObject):
 \r
         # resolve PCD type, value, datum info, etc. by getting its definition from package\r
         for PcdCName, TokenSpaceGuid in PcdList:\r
+            PcdRealName = PcdCName\r
             Setting, LineNo = PcdDict[self._Arch, self.Platform, PcdCName, TokenSpaceGuid]\r
             if Setting == None:\r
                 continue\r
@@ -2584,6 +2585,27 @@ class InfBuildData(ModuleBuildClassObject):
                 # Patch PCD: TokenSpace.PcdCName|Value|Offset\r
                 Pcd.Offset = ValueList[1]\r
 \r
+            if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:\r
+                for Package in self.Packages:\r
+                    for key in Package.Pcds:\r
+                        if (Package.Pcds[key].TokenCName, Package.Pcds[key].TokenSpaceGuidCName) == (PcdRealName, TokenSpaceGuid):\r
+                            for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:\r
+                                Pcd_Type = item[0].split('_')[-1]\r
+                                if Pcd_Type == Package.Pcds[key].Type:\r
+                                    Value = Package.Pcds[key]\r
+                                    Value.TokenCName = Package.Pcds[key].TokenCName + '_' + Pcd_Type\r
+                                    if len(key) == 2:\r
+                                        newkey = (Value.TokenCName, key[1])\r
+                                    elif len(key) == 3:\r
+                                        newkey = (Value.TokenCName, key[1], key[2])\r
+                                    del Package.Pcds[key]\r
+                                    Package.Pcds[newkey] = Value\r
+                                    break\r
+                                else:\r
+                                    pass\r
+                        else:\r
+                            pass\r
+\r
             # get necessary info from package declaring this PCD\r
             for Package in self.Packages:\r
                 #\r
@@ -2597,11 +2619,32 @@ class InfBuildData(ModuleBuildClassObject):
                 if Type == MODEL_PCD_DYNAMIC:\r
                     Pcd.Pending = True\r
                     for T in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]:\r
-                        if (PcdCName, TokenSpaceGuid, T) in Package.Pcds:\r
-                            PcdType = T\r
+                        if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:\r
+                            for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:\r
+                                if str(item[0]).endswith(T) and (item[0], item[1], T) in Package.Pcds:\r
+                                    PcdType = T\r
+                                    PcdCName = item[0]\r
+                                    break\r
+                                else:\r
+                                    pass\r
                             break\r
+                        else:\r
+                            if (PcdRealName, TokenSpaceGuid, T) in Package.Pcds:\r
+                                PcdType = T\r
+                                break\r
+\r
                 else:\r
                     Pcd.Pending = False\r
+                    if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:\r
+                        for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:\r
+                            Pcd_Type = item[0].split('_')[-1]\r
+                            if Pcd_Type == PcdType:\r
+                                PcdCName = item[0]\r
+                                break\r
+                            else:\r
+                                pass\r
+                    else:\r
+                        pass\r
 \r
                 if (PcdCName, TokenSpaceGuid, PcdType) in Package.Pcds:\r
                     PcdInPackage = Package.Pcds[PcdCName, TokenSpaceGuid, PcdType]\r
@@ -2615,7 +2658,7 @@ class InfBuildData(ModuleBuildClassObject):
                         EdkLogger.error(\r
                                 'build',\r
                                 FORMAT_INVALID,\r
-                                "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid, PcdCName, str(Package)),\r
+                                "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid, PcdRealName, str(Package)),\r
                                 File=self.MetaFile, Line=LineNo,\r
                                 ExtraData=None\r
                                 )                        \r
@@ -2628,7 +2671,7 @@ class InfBuildData(ModuleBuildClassObject):
                             EdkLogger.error(\r
                                     'build',\r
                                     FORMAT_INVALID,\r
-                                    "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd.TokenValue, TokenSpaceGuid, PcdCName, str(Package)),\r
+                                    "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd.TokenValue, TokenSpaceGuid, PcdRealName, str(Package)),\r
                                     File=self.MetaFile, Line=LineNo,\r
                                     ExtraData=None\r
                                     )\r
@@ -2643,7 +2686,7 @@ class InfBuildData(ModuleBuildClassObject):
                                 EdkLogger.error(\r
                                             'build',\r
                                             FORMAT_INVALID,\r
-                                            "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, as a decimal it should between: 0 - 4294967295!" % (Pcd.TokenValue, TokenSpaceGuid, PcdCName, str(Package)),\r
+                                            "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, as a decimal it should between: 0 - 4294967295!" % (Pcd.TokenValue, TokenSpaceGuid, PcdRealName, str(Package)),\r
                                             File=self.MetaFile, Line=LineNo,\r
                                             ExtraData=None\r
                                             )\r
@@ -2651,7 +2694,7 @@ class InfBuildData(ModuleBuildClassObject):
                             EdkLogger.error(\r
                                         'build',\r
                                         FORMAT_INVALID,\r
-                                        "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, it should be hexadecimal or decimal!" % (Pcd.TokenValue, TokenSpaceGuid, PcdCName, str(Package)),\r
+                                        "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, it should be hexadecimal or decimal!" % (Pcd.TokenValue, TokenSpaceGuid, PcdRealName, str(Package)),\r
                                         File=self.MetaFile, Line=LineNo,\r
                                         ExtraData=None\r
                                         )\r
@@ -2666,7 +2709,7 @@ class InfBuildData(ModuleBuildClassObject):
                 EdkLogger.error(\r
                             'build',\r
                             FORMAT_INVALID,\r
-                            "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdCName, self.MetaFile),\r
+                            "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdRealName, self.MetaFile),\r
                             File=self.MetaFile, Line=LineNo,\r
                             ExtraData="\t%s" % '\n\t'.join([str(P) for P in self.Packages])\r
                             )\r
index 27a5d9736efa32d5f1b7645adb38f5facb356ade..ef99989857fac94d86d721070bcf6ecb10328704 100644 (file)
@@ -1676,6 +1676,14 @@ class PlatformReport(object):
         FileWrite(File, "Build Duration:       %s" % BuildDuration)\r
         FileWrite(File, "Report Content:       %s" % ", ".join(ReportType))\r
 \r
+        if GlobalData.MixedPcd:\r
+            FileWrite(File, gSectionStart)\r
+            FileWrite(File, "The following PCDs use different access methods:")\r
+            FileWrite(File, gSectionSep)\r
+            for PcdItem in GlobalData.MixedPcd:\r
+                FileWrite(File, "%s.%s" % (str(PcdItem[1]), str(PcdItem[0])))\r
+            FileWrite(File, gSectionEnd)\r
+\r
         if not self._IsModuleBuild:\r
             if "PCD" in ReportType:\r
                 self.PcdReport.GenerateReport(File, None)\r