]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/GenC.py
BaseTools: Enable structure pcd in FDF file
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenC.py
index 4d9ea1b2a8b1a1aff786b67ccd477c4e86b31ee2..2dca9ffd5b4b927fb48d7cc7d74631902007eaed 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Routines for generating AutoGen.h and AutoGen.c\r
 #\r
-# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, 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
@@ -21,15 +21,15 @@ from Common import EdkLogger
 from Common.BuildToolError import *\r
 from Common.DataType import *\r
 from Common.Misc import *\r
-from Common.String import StringToArray\r
+from Common.StringUtils import StringToArray\r
 from StrGather import *\r
 from GenPcdDb import CreatePcdDatabaseCode\r
 from IdfClassObject import *\r
 \r
 ## PCD type string\r
 gItemTypeStringDatabase  = {\r
-    TAB_PCDS_FEATURE_FLAG       :   'FixedAtBuild',\r
-    TAB_PCDS_FIXED_AT_BUILD     :   'FixedAtBuild',\r
+    TAB_PCDS_FEATURE_FLAG       :   TAB_PCDS_FIXED_AT_BUILD,\r
+    TAB_PCDS_FIXED_AT_BUILD     :   TAB_PCDS_FIXED_AT_BUILD,\r
     TAB_PCDS_PATCHABLE_IN_MODULE:   'BinaryPatch',\r
     TAB_PCDS_DYNAMIC            :   '',\r
     TAB_PCDS_DYNAMIC_DEFAULT    :   '',\r
@@ -41,16 +41,11 @@ gItemTypeStringDatabase  = {
     TAB_PCDS_DYNAMIC_EX_HII     :   '',\r
 }\r
 \r
-## Dynamic PCD types\r
-gDynamicPcd = [TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_DEFAULT, TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_HII]\r
-\r
-## Dynamic-ex PCD types\r
-gDynamicExPcd = [TAB_PCDS_DYNAMIC_EX, TAB_PCDS_DYNAMIC_EX_DEFAULT, TAB_PCDS_DYNAMIC_EX_VPD, TAB_PCDS_DYNAMIC_EX_HII]\r
 \r
 ## Datum size\r
-gDatumSizeStringDatabase = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOLEAN','VOID*':'8'}\r
-gDatumSizeStringDatabaseH = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOL','VOID*':'PTR'}\r
-gDatumSizeStringDatabaseLib = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'Bool','VOID*':'Ptr'}\r
+gDatumSizeStringDatabase = {TAB_UINT8:'8',TAB_UINT16:'16',TAB_UINT32:'32',TAB_UINT64:'64','BOOLEAN':'BOOLEAN',TAB_VOID:'8'}\r
+gDatumSizeStringDatabaseH = {TAB_UINT8:'8',TAB_UINT16:'16',TAB_UINT32:'32',TAB_UINT64:'64','BOOLEAN':'BOOL',TAB_VOID:'PTR'}\r
+gDatumSizeStringDatabaseLib = {TAB_UINT8:'8',TAB_UINT16:'16',TAB_UINT32:'32',TAB_UINT64:'64','BOOLEAN':'Bool',TAB_VOID:'Ptr'}\r
 \r
 ## AutoGen File Header Templates\r
 gAutoGenHeaderString = TemplateString("""\\r
@@ -649,7 +644,7 @@ ${END}
 ]\r
 \r
 gLibraryStructorPrototype = {\r
-'BASE'  : TemplateString("""${BEGIN}\r
+SUP_MODULE_BASE  : TemplateString("""${BEGIN}\r
 RETURN_STATUS\r
 EFIAPI\r
 ${Function} (\r
@@ -686,7 +681,7 @@ ${Function} (
 }\r
 \r
 gLibraryStructorCall = {\r
-'BASE'  : TemplateString("""${BEGIN}\r
+SUP_MODULE_BASE  : TemplateString("""${BEGIN}\r
   Status = ${Function} ();\r
   ASSERT_EFI_ERROR (Status);${END}\r
 """),\r
@@ -709,7 +704,7 @@ gLibraryStructorCall = {
 \r
 ## Library Constructor and Destructor Templates\r
 gLibraryString = {\r
-'BASE'  :   TemplateString("""\r
+SUP_MODULE_BASE  :   TemplateString("""\r
 ${BEGIN}${FunctionPrototype}${END}\r
 \r
 VOID\r
@@ -772,24 +767,24 @@ ${FunctionCall}${END}
 gBasicHeaderFile = "Base.h"\r
 \r
 gModuleTypeHeaderFile = {\r
-    "BASE"              :   [gBasicHeaderFile],\r
-    "SEC"               :   ["PiPei.h", "Library/DebugLib.h"],\r
-    "PEI_CORE"          :   ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"],\r
-    "PEIM"              :   ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"],\r
-    "DXE_CORE"          :   ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"],\r
-    "DXE_DRIVER"        :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
-    "DXE_SMM_DRIVER"    :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
-    "DXE_RUNTIME_DRIVER":   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
-    "DXE_SAL_DRIVER"    :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
-    "UEFI_DRIVER"       :   ["Uefi.h",  "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
-    "UEFI_APPLICATION"  :   ["Uefi.h",  "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],\r
-    "SMM_CORE"          :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],\r
-    "MM_STANDALONE"     :   ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmDriverStandaloneEntryPoint.h"],\r
-    "MM_CORE_STANDALONE" :  ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmCoreStandaloneEntryPoint.h"],\r
-    "USER_DEFINED"      :   [gBasicHeaderFile]\r
+    SUP_MODULE_BASE              :   [gBasicHeaderFile],\r
+    SUP_MODULE_SEC               :   ["PiPei.h", "Library/DebugLib.h"],\r
+    SUP_MODULE_PEI_CORE          :   ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"],\r
+    SUP_MODULE_PEIM              :   ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"],\r
+    SUP_MODULE_DXE_CORE          :   ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"],\r
+    SUP_MODULE_DXE_DRIVER        :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
+    SUP_MODULE_DXE_SMM_DRIVER    :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
+    SUP_MODULE_DXE_RUNTIME_DRIVER:   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
+    SUP_MODULE_DXE_SAL_DRIVER    :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
+    SUP_MODULE_UEFI_DRIVER       :   ["Uefi.h",  "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
+    SUP_MODULE_UEFI_APPLICATION  :   ["Uefi.h",  "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],\r
+    SUP_MODULE_SMM_CORE          :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],\r
+    SUP_MODULE_MM_STANDALONE     :   ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmDriverStandaloneEntryPoint.h"],\r
+    SUP_MODULE_MM_CORE_STANDALONE :  ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmCoreStandaloneEntryPoint.h"],\r
+    SUP_MODULE_USER_DEFINED      :   [gBasicHeaderFile]\r
 }\r
 \r
-## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName \r
+## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName\r
 #  the TokenName and Guid comparison to avoid define name collisions.\r
 #\r
 #   @param      Info        The ModuleAutoGen object\r
@@ -802,16 +797,16 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
     # Even it is the Library, the PCD is saved in the ModulePcdList\r
     PcdList = Info.ModulePcdList\r
     for Pcd in PcdList:\r
-        if Pcd.Type in gDynamicExPcd:\r
+        if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
             ExTokenCNameList.append(Pcd.TokenCName)\r
             PcdExList.append(Pcd)\r
     if len(ExTokenCNameList) == 0:\r
         return\r
     AutoGenH.Append('\n#define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1))\n')\r
     # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.\r
-    # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.  \r
+    # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.\r
     # Use the Guid pointer to see if it matches any of the token space GUIDs.\r
-    TokenCNameList = []\r
+    TokenCNameList = set()\r
     for TokenCName in ExTokenCNameList:\r
         if TokenCName in TokenCNameList:\r
             continue\r
@@ -827,16 +822,16 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
                 Index = Index + 1\r
                 if Index == 1:\r
                     AutoGenH.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr)  (' % (RealTokenCName))\r
-                    AutoGenH.Append('\\\n  (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
+                    AutoGenH.Append('\\\n  (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'\r
                                     % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
                 else:\r
-                    AutoGenH.Append('\\\n  (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
+                    AutoGenH.Append('\\\n  (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'\r
                                     % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
                 if Index == Count:\r
                     AutoGenH.Append('0 \\\n  )\n')\r
-                TokenCNameList.append(TokenCName)\r
-    \r
-    TokenCNameList = []\r
+                TokenCNameList.add(TokenCName)\r
+\r
+    TokenCNameList = set()\r
     for TokenCName in ExTokenCNameList:\r
         if TokenCName in TokenCNameList:\r
             continue\r
@@ -848,50 +843,25 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
                 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
+            if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == TokenCName:\r
                 Index = Index + 1\r
                 if Index == 1:\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
+                    AutoGenH.Append('\\\n  COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'\r
                                     % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
                 else:\r
-                    AutoGenH.Append('\\\n  COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
+                    AutoGenH.Append('\\\n  COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'\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
+                    # Autogen internal worker macro to compare GUIDs.  Guid1 is a pointer to a GUID.\r
                     # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler\r
                     # 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
                                     % (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))\r
-                TokenCNameList.append(TokenCName)\r
-\r
-def GetPcdSize(Pcd):\r
-    if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
-        Value = Pcd.DefaultValue\r
-        if Value in [None, '']:\r
-            return 1\r
-        elif Value[0] == 'L':\r
-            return (len(Value) - 2) * 2\r
-        elif Value[0] == '{':\r
-            return len(Value.split(','))\r
-        else:\r
-            return len(Value) - 1\r
-    if Pcd.DatumType == 'UINT64':\r
-        return 8\r
-    if Pcd.DatumType == 'UINT32':\r
-        return 4\r
-    if Pcd.DatumType == 'UINT16':\r
-        return 2\r
-    if Pcd.DatumType == 'UINT8':\r
-        return 1\r
-    if Pcd.DatumType == 'BOOLEAN':\r
-        return 1\r
-    else:\r
-        return Pcd.MaxDatumSize\r
-\r
+                TokenCNameList.add(TokenCName)\r
 \r
 ## Create code for module PCDs\r
 #\r
@@ -914,28 +884,32 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
     PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
     PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
     PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
+    PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName\r
     FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
+    FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName\r
 \r
     if Pcd.PcdValueFromComm:\r
         Pcd.DefaultValue = Pcd.PcdValueFromComm\r
-    \r
-    if Pcd.Type in gDynamicExPcd:\r
+    elif Pcd.PcdValueFromFdf:\r
+        Pcd.DefaultValue = Pcd.PcdValueFromFdf\r
+\r
+    if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
         TokenNumber = int(Pcd.TokenValue, 0)\r
-        # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with \r
+        # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with\r
         # different Guids but same 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
-            # If one of the Source built modules listed in the DSC is not listed in FDF modules, \r
-            # and the INF lists a PCD can only use the PcdsDynamic access method (it is only \r
-            # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will \r
-            # report warning message notify the PI that they are attempting to build a module \r
-            # that must be included in a flash image in order to be functional. These Dynamic PCD \r
-            # will not be added into the Database unless it is used by other modules that are \r
-            # included in the FDF file. \r
+            # If one of the Source built modules listed in the DSC is not listed in FDF modules,\r
+            # and the INF lists a PCD can only use the PcdsDynamic access method (it is only\r
+            # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will\r
+            # report warning message notify the PI that they are attempting to build a module\r
+            # that must be included in a flash image in order to be functional. These Dynamic PCD\r
+            # will not be added into the Database unless it is used by other modules that are\r
+            # included in the FDF file.\r
             # In this case, just assign an invalid token number to make it pass build.\r
-            if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:\r
+            if Pcd.Type in PCD_DYNAMIC_TYPE_SET:\r
                 TokenNumber = 0\r
             else:\r
                 EdkLogger.error("build", AUTOGEN_ERROR,\r
@@ -951,31 +925,34 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                         "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
                         ExtraData="[%s]" % str(Info))\r
 \r
-    DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase['VOID*']\r
-    DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib['VOID*']\r
-    GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH['VOID*'] + '_' + TokenCName\r
-    SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH['VOID*'] + '_' + TokenCName\r
-    SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH['VOID*'] + '_S_' + TokenCName\r
+    DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase[TAB_VOID]\r
+    DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib[TAB_VOID]\r
+    GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName\r
+    SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName\r
+    SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_S_' + TokenCName\r
     GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
-    \r
-    PcdExCNameList  = []\r
-    if Pcd.Type in gDynamicExPcd:\r
+\r
+    if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
         if Info.IsLibrary:\r
             PcdList = Info.LibraryPcdList\r
         else:\r
             PcdList = Info.ModulePcdList\r
+        PcdExCNameTest = 0\r
         for PcdModule in PcdList:\r
-            if PcdModule.Type in gDynamicExPcd:\r
-                PcdExCNameList.append(PcdModule.TokenCName)\r
+            if PcdModule.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:\r
+                PcdExCNameTest += 1\r
+            # get out early once we found > 1...\r
+            if PcdExCNameTest > 1:\r
+                break\r
         # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.\r
         # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
         # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
-        if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
+        if PcdExCNameTest > 1:\r
             AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')\r
             AutoGenH.Append('// #define %s  %s\n' % (PcdTokenName, PcdExTokenName))\r
             AutoGenH.Append('// #define %s  LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
-            AutoGenH.Append('// #define %s  LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
-            if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+            AutoGenH.Append('// #define %s  LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
+            if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
                 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer)  LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
                 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer)  LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
             else:\r
@@ -984,27 +961,27 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
         else:\r
             AutoGenH.Append('#define %s  %s\n' % (PcdTokenName, PcdExTokenName))\r
             AutoGenH.Append('#define %s  LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
-            AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
-            if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+            AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
+            if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
                 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
                 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
             else:\r
                 AutoGenH.Append('#define %s(Value)  LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
                 AutoGenH.Append('#define %s(Value)  LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
-    elif Pcd.Type in gDynamicPcd:\r
-        PcdList = []\r
-        PcdCNameList = []\r
-        PcdList.extend(Info.LibraryPcdList)\r
-        PcdList.extend(Info.ModulePcdList)\r
-        for PcdModule in PcdList:\r
-            if PcdModule.Type in gDynamicPcd:\r
-                PcdCNameList.append(PcdModule.TokenCName)\r
-        if PcdCNameList.count(Pcd.TokenCName) > 1:\r
+    elif Pcd.Type in PCD_DYNAMIC_TYPE_SET:\r
+        PcdCNameTest = 0\r
+        for PcdModule in Info.LibraryPcdList + Info.ModulePcdList:\r
+            if PcdModule.Type in PCD_DYNAMIC_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:\r
+                PcdCNameTest += 1\r
+            # get out early once we found > 1...\r
+            if PcdCNameTest > 1:\r
+                break\r
+        if PcdCNameTest > 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" % (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
-            if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+            if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
                 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
                 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
             else:\r
@@ -1028,7 +1005,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
             elif BoolValue == 'FALSE' or BoolValue == '0':\r
                 Value = '0U'\r
 \r
-        if Pcd.DatumType in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:\r
+        if Pcd.DatumType in TAB_PCD_CLEAN_NUMERIC_TYPES:\r
             try:\r
                 if Value.upper().endswith('L'):\r
                     Value = Value[:-1]\r
@@ -1037,7 +1014,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 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, TokenCName),\r
                                 ExtraData="[%s]" % str(Info))\r
-            if Pcd.DatumType == 'UINT64':\r
+            if Pcd.DatumType == TAB_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, TokenCName),\r
@@ -1048,7 +1025,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                                     ExtraData="[%s]" % str(Info))\r
                 if not Value.endswith('ULL'):\r
                     Value += 'ULL'\r
-            elif Pcd.DatumType == 'UINT32':\r
+            elif Pcd.DatumType == TAB_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, TokenCName),\r
@@ -1059,7 +1036,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                                     ExtraData="[%s]" % str(Info))\r
                 if not Value.endswith('U'):\r
                     Value += 'U'\r
-            elif Pcd.DatumType == 'UINT16':\r
+            elif Pcd.DatumType == TAB_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, TokenCName),\r
@@ -1069,8 +1046,8 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                                     "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
+                    Value += 'U'\r
+            elif Pcd.DatumType == TAB_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, TokenCName),\r
@@ -1081,8 +1058,8 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                                     ExtraData="[%s]" % str(Info))\r
                 if not Value.endswith('U'):\r
                     Value += 'U'\r
-        if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
-            if Pcd.MaxDatumSize is None or Pcd.MaxDatumSize == '':\r
+        if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
+            if not Pcd.MaxDatumSize:\r
                 EdkLogger.error("build", AUTOGEN_ERROR,\r
                                 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
                                 ExtraData="[%s]" % str(Info))\r
@@ -1090,97 +1067,92 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
             ArraySize = int(Pcd.MaxDatumSize, 0)\r
             if Value[0] == '{':\r
                 Type = '(VOID *)'\r
+                ValueSize = len(Value.split(','))\r
             else:\r
                 if Value[0] == 'L':\r
                     Unicode = True\r
                 Value = Value.lstrip('L')   #.strip('"')\r
                 Value = eval(Value)         # translate escape character\r
+                ValueSize = len(Value) + 1\r
                 NewValue = '{'\r
-                for Index in range(0,len(Value)):\r
+                for Index in range(0, len(Value)):\r
                     if Unicode:\r
                         NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '\r
                     else:\r
                         NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '\r
                 if Unicode:\r
-                    ArraySize = ArraySize / 2;\r
-\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, TokenCName),\r
-                                    ExtraData="[%s]" % str(Info))\r
+                    ArraySize = ArraySize / 2\r
                 Value = NewValue + '0 }'\r
+            if ArraySize < ValueSize:\r
+                if Pcd.MaxSizeUserSet:\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, TokenCName),\r
+                                ExtraData="[%s]" % str(Info))\r
+                else:\r
+                    ArraySize = Pcd.GetPcdSize()\r
+                    if Unicode:\r
+                        ArraySize = ArraySize / 2\r
             Array = '[%d]' % ArraySize\r
         #\r
         # skip casting for fixed at build since it breaks ARM assembly.\r
         # Long term we need PCD macros that work in assembly\r
         #\r
-        elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD and Pcd.DatumType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN', 'VOID*']:\r
+        elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD and Pcd.DatumType in TAB_PCD_NUMERIC_TYPES_VOID:\r
             Value = "((%s)%s)" % (Pcd.DatumType, Value)\r
 \r
-        if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN', 'VOID*']:\r
-            # handle structure PCD\r
-            if Pcd.MaxDatumSize is None or Pcd.MaxDatumSize == '':\r
-                EdkLogger.error("build", AUTOGEN_ERROR,\r
-                                "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
-                                ExtraData="[%s]" % str(Info))\r
-\r
-            ArraySize = int(Pcd.MaxDatumSize, 0)\r
-            Array = '[%d]' % ArraySize\r
-\r
         if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
             PcdValueName = '_PCD_PATCHABLE_VALUE_' + TokenCName\r
         else:\r
             PcdValueName = '_PCD_VALUE_' + TokenCName\r
-            \r
-        if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+\r
+        if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
             #\r
             # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.\r
             #\r
+            AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
             if Unicode:\r
-                AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
                 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
                 AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))\r
-                AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, PcdVariableName))\r
             else:\r
-                AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
                 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
                 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))\r
-                AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, PcdVariableName))\r
-                \r
-            PcdDataSize = GetPcdSize(Pcd)\r
+            AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, PcdVariableName))\r
+\r
+            PcdDataSize = Pcd.GetPcdSize()\r
             if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:\r
                 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
-                AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
-            \r
+                AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName, FixPcdSizeTokenName))\r
+                AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (FixedPcdSizeVariableName, PcdDataSize))\r
             if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
                 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize))\r
-                AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
+                AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName, PatchPcdSizeVariableName))\r
                 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
-                AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
+                AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName, PcdDataSize))\r
+                AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (PatchPcdMaxSizeVariable, Pcd.MaxDatumSize))\r
         elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
             AutoGenH.Append('#define %s  %s\n' %(PcdValueName, Value))\r
             AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
             AutoGenH.Append('extern volatile %s  %s  %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
             AutoGenH.Append('#define %s  %s%s\n' % (GetModeName, Type, PcdVariableName))\r
-            \r
-            PcdDataSize = GetPcdSize(Pcd)\r
+\r
+            PcdDataSize = Pcd.GetPcdSize()\r
             AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
-            \r
-            AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
+\r
+            AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName, PatchPcdSizeVariableName))\r
             AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
-            AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
+            AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName, PcdDataSize))\r
         else:\r
-            PcdDataSize = GetPcdSize(Pcd)\r
+            PcdDataSize = Pcd.GetPcdSize()\r
             AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
-            AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
-            \r
+            AutoGenH.Append('#define %s  %s \n' % (GetModeSizeName, FixPcdSizeTokenName))\r
+\r
             AutoGenH.Append('#define %s  %s\n' %(PcdValueName, Value))\r
             AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
             AutoGenH.Append('extern %s  %s  %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
             AutoGenH.Append('#define %s  %s%s\n' % (GetModeName, Type, PcdVariableName))\r
 \r
         if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
-            if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+            if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\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
             else:\r
@@ -1208,25 +1180,29 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
     FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
     PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
     PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
+    PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName\r
+    FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName\r
 \r
     if Pcd.PcdValueFromComm:\r
         Pcd.DefaultValue = Pcd.PcdValueFromComm\r
+    elif Pcd.PcdValueFromFdf:\r
+        Pcd.DefaultValue = Pcd.PcdValueFromFdf\r
     #\r
     # Write PCDs\r
     #\r
-    if Pcd.Type in gDynamicExPcd:\r
+    if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
         TokenNumber = int(Pcd.TokenValue, 0)\r
     else:\r
         if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
-            # If one of the Source built modules listed in the DSC is not listed in FDF modules, \r
-            # and the INF lists a PCD can only use the PcdsDynamic access method (it is only \r
-            # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will \r
-            # report warning message notify the PI that they are attempting to build a module \r
-            # that must be included in a flash image in order to be functional. These Dynamic PCD \r
-            # will not be added into the Database unless it is used by other modules that are \r
-            # included in the FDF file. \r
+            # If one of the Source built modules listed in the DSC is not listed in FDF modules,\r
+            # and the INF lists a PCD can only use the PcdsDynamic access method (it is only\r
+            # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will\r
+            # report warning message notify the PI that they are attempting to build a module\r
+            # that must be included in a flash image in order to be functional. These Dynamic PCD\r
+            # will not be added into the Database unless it is used by other modules that are\r
+            # included in the FDF file.\r
             # In this case, just assign an invalid token number to make it pass build.\r
-            if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:\r
+            if Pcd.Type in PCD_DYNAMIC_TYPE_SET:\r
                 TokenNumber = 0\r
             else:\r
                 EdkLogger.error("build", AUTOGEN_ERROR,\r
@@ -1241,41 +1217,44 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
                         ExtraData="[%s]" % str(Info))\r
 \r
     DatumType   = Pcd.DatumType\r
-    DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase['VOID*']\r
-    DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib['VOID*']\r
-    GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH['VOID*'] + '_' + TokenCName\r
-    SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH['VOID*'] + '_' + TokenCName\r
-    SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH['VOID*'] + '_S_' + TokenCName\r
+    DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase[TAB_VOID]\r
+    DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib[TAB_VOID]\r
+    GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName\r
+    SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName\r
+    SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_S_' + TokenCName\r
     GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
 \r
     Type = ''\r
     Array = ''\r
-    if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+    if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
         if Pcd.DefaultValue[0]== '{':\r
             Type = '(VOID *)'\r
         Array = '[]'\r
     PcdItemType = Pcd.Type\r
-    PcdExCNameList  = []\r
-    if PcdItemType in gDynamicExPcd:\r
+    if PcdItemType in PCD_DYNAMIC_EX_TYPE_SET:\r
         PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName\r
         AutoGenH.Append('\n#define %s  %dU\n' % (PcdExTokenName, TokenNumber))\r
-        \r
+\r
         if Info.IsLibrary:\r
             PcdList = Info.LibraryPcdList\r
         else:\r
             PcdList = Info.ModulePcdList\r
+        PcdExCNameTest = 0\r
         for PcdModule in PcdList:\r
-            if PcdModule.Type in gDynamicExPcd:\r
-                PcdExCNameList.append(PcdModule.TokenCName)\r
+            if PcdModule.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:\r
+                PcdExCNameTest += 1\r
+            # get out early once we found > 1...\r
+            if PcdExCNameTest > 1:\r
+                break\r
         # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.\r
         # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
         # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
-        if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
+        if PcdExCNameTest > 1:\r
             AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')\r
             AutoGenH.Append('// #define %s  %s\n' % (PcdTokenName, PcdExTokenName))\r
             AutoGenH.Append('// #define %s  LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
-            AutoGenH.Append('// #define %s  LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
-            if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+            AutoGenH.Append('// #define %s  LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
+            if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
                 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer)  LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
                 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer)  LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
             else:\r
@@ -1284,8 +1263,8 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
         else:\r
             AutoGenH.Append('#define %s  %s\n' % (PcdTokenName, PcdExTokenName))\r
             AutoGenH.Append('#define %s  LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
-            AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
-            if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+            AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
+            if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
                 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
                 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
             else:\r
@@ -1293,71 +1272,84 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 AutoGenH.Append('#define %s(Value)  LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
     else:\r
         AutoGenH.Append('#define _PCD_TOKEN_%s  %dU\n' % (TokenCName, TokenNumber))\r
-    if PcdItemType in gDynamicPcd:\r
+    if PcdItemType in PCD_DYNAMIC_TYPE_SET:\r
         PcdList = []\r
         PcdCNameList = []\r
         PcdList.extend(Info.LibraryPcdList)\r
         PcdList.extend(Info.ModulePcdList)\r
         for PcdModule in PcdList:\r
-            if PcdModule.Type in gDynamicPcd:\r
+            if PcdModule.Type in PCD_DYNAMIC_TYPE_SET:\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" % (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
-            if DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+            if DatumType not in TAB_PCD_NUMERIC_TYPES:\r
                 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
                 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
             else:\r
                 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
     if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:\r
+        GetModeMaxSizeName = '_PCD_GET_MODE_MAXSIZE' + '_' + TokenCName\r
         PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName\r
-        if DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
-            ArraySize = int(Pcd.MaxDatumSize, 0)\r
-            if Pcd.DefaultValue[0] == 'L':\r
-                ArraySize = ArraySize / 2\r
-            Array = '[%d]' % ArraySize\r
-            DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']\r
+        if DatumType not in TAB_PCD_NUMERIC_TYPES:\r
+            if DatumType == TAB_VOID and Array == '[]':\r
+                DatumType = [TAB_UINT8, TAB_UINT16][Pcd.DefaultValue[0] == 'L']\r
+            else:\r
+                DatumType = TAB_UINT8\r
             AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array))\r
         else:\r
             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
-        PcdDataSize = GetPcdSize(Pcd)\r
-        if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\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
-            AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize))\r
+        PcdDataSize = Pcd.GetPcdSize()\r
+        if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
+            AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))\r
+            AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))\r
+            AutoGenH.Append('#define %s %s\n' % (GetModeMaxSizeName, PatchPcdMaxSizeVariable))\r
+            AutoGenH.Append('extern const UINTN %s; \n' % PatchPcdMaxSizeVariable)\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
             AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
 \r
-        AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
+        AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, PatchPcdSizeVariableName))\r
         AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
-        \r
+\r
     if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:\r
-        key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
+        key = ".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
         PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName\r
-        if DatumType == 'VOID*' and Array == '[]':\r
-            DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']\r
-        if DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN', 'VOID*']:\r
-            DatumType = 'UINT8'\r
+        if DatumType == TAB_VOID and Array == '[]':\r
+            DatumType = [TAB_UINT8, TAB_UINT16][Pcd.DefaultValue[0] == 'L']\r
+        if DatumType not in TAB_PCD_NUMERIC_TYPES_VOID:\r
+            DatumType = TAB_UINT8\r
         AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))\r
         AutoGenH.Append('#define %s  %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName))\r
         AutoGenH.Append('//#define %s  ASSERT(FALSE)  // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
-        \r
+\r
+        ConstFixedPcd = False\r
         if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and (key in Info.ConstPcd or (Info.IsLibrary and not Info._ReferenceModules)):\r
-            if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+            ConstFixedPcd = True\r
+            if key in Info.ConstPcd:\r
+                Pcd.DefaultValue = Info.ConstPcd[key]\r
+            if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
                 AutoGenH.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName, Type, PcdVariableName))\r
             else:\r
                 AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))\r
-        \r
+        PcdDataSize = Pcd.GetPcdSize()\r
         if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:\r
-            PcdDataSize = GetPcdSize(Pcd)\r
-            AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
-            AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,FixPcdSizeTokenName))\r
+            if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
+                if ConstFixedPcd:\r
+                    AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
+                    AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixPcdSizeTokenName))\r
+                else:\r
+                    AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixedPcdSizeVariableName))\r
+                    AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, FixedPcdSizeVariableName))\r
+                    AutoGenH.Append('extern const UINTN %s; \n' % FixedPcdSizeVariableName)\r
+            else:\r
+                AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
+                AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixPcdSizeTokenName))\r
 \r
 ## Create code for library constructor\r
 #\r
@@ -1379,17 +1371,17 @@ def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):
         if len(Lib.ConstructorList) <= 0:\r
             continue\r
         Dict = {'Function':Lib.ConstructorList}\r
-        if Lib.ModuleType in ['BASE', 'SEC']:\r
-            ConstructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))\r
-            ConstructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))\r
-        elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
+        if Lib.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:\r
+            ConstructorPrototypeString.Append(gLibraryStructorPrototype[SUP_MODULE_BASE].Replace(Dict))\r
+            ConstructorCallingString.Append(gLibraryStructorCall[SUP_MODULE_BASE].Replace(Dict))\r
+        elif Lib.ModuleType in SUP_MODULE_SET_PEI:\r
             ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
             ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
-        elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
-                                'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
+        elif Lib.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,\r
+                                SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:\r
             ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
             ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
-        elif Lib.ModuleType in ['MM_STANDALONE','MM_CORE_STANDALONE']:\r
+        elif Lib.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:\r
             ConstructorPrototypeString.Append(gLibraryStructorPrototype['MM'].Replace(Dict))\r
             ConstructorCallingString.Append(gLibraryStructorCall['MM'].Replace(Dict))\r
 \r
@@ -1410,14 +1402,14 @@ def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):
     if Info.IsLibrary:\r
         AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
     else:\r
-        if Info.ModuleType in ['BASE', 'SEC']:\r
-            AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))\r
-        elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
+        if Info.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:\r
+            AutoGenC.Append(gLibraryString[SUP_MODULE_BASE].Replace(Dict))\r
+        elif Info.ModuleType in SUP_MODULE_SET_PEI:\r
             AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
-        elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
-                                 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
+        elif Info.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,\r
+                                 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:\r
             AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
-        elif Info.ModuleType in ['MM_STANDALONE','MM_CORE_STANDALONE']:\r
+        elif Info.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:\r
             AutoGenC.Append(gLibraryString['MM'].Replace(Dict))\r
 \r
 ## Create code for library destructor\r
@@ -1441,17 +1433,17 @@ def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):
         if len(Lib.DestructorList) <= 0:\r
             continue\r
         Dict = {'Function':Lib.DestructorList}\r
-        if Lib.ModuleType in ['BASE', 'SEC']:\r
-            DestructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))\r
-            DestructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))\r
-        elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
+        if Lib.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:\r
+            DestructorPrototypeString.Append(gLibraryStructorPrototype[SUP_MODULE_BASE].Replace(Dict))\r
+            DestructorCallingString.Append(gLibraryStructorCall[SUP_MODULE_BASE].Replace(Dict))\r
+        elif Lib.ModuleType in SUP_MODULE_SET_PEI:\r
             DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
             DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
-        elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
-                                'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:\r
+        elif Lib.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,\r
+                                SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:\r
             DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
             DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
-        elif Lib.ModuleType in ['MM_STANDALONE','MM_CORE_STANDALONE']:\r
+        elif Lib.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:\r
             DestructorPrototypeString.Append(gLibraryStructorPrototype['MM'].Replace(Dict))\r
             DestructorCallingString.Append(gLibraryStructorCall['MM'].Replace(Dict))\r
 \r
@@ -1472,14 +1464,14 @@ def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):
     if Info.IsLibrary:\r
         AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
     else:\r
-        if Info.ModuleType in ['BASE', 'SEC']:\r
-            AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))\r
-        elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
+        if Info.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:\r
+            AutoGenC.Append(gLibraryString[SUP_MODULE_BASE].Replace(Dict))\r
+        elif Info.ModuleType in SUP_MODULE_SET_PEI:\r
             AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
-        elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
-                                 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
+        elif Info.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,\r
+                                 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:\r
             AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
-        elif Info.ModuleType in ['MM_STANDALONE','MM_CORE_STANDALONE']:\r
+        elif Info.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:\r
             AutoGenC.Append(gLibraryString['MM'].Replace(Dict))\r
 \r
 \r
@@ -1490,7 +1482,7 @@ def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):
 #   @param      AutoGenH    The TemplateString object for header file\r
 #\r
 def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):\r
-    if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:\r
+    if Info.IsLibrary or Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_SEC]:\r
         return\r
     #\r
     # Module Entry Points\r
@@ -1510,8 +1502,8 @@ def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
         'UefiSpecVersion':   UefiSpecVersion + 'U'\r
     }\r
 \r
-    if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE', 'MM_CORE_STANDALONE']:\r
-        if Info.SourceFileList <> None and Info.SourceFileList <> []:\r
+    if Info.ModuleType in [SUP_MODULE_PEI_CORE, SUP_MODULE_DXE_CORE, SUP_MODULE_SMM_CORE, SUP_MODULE_MM_CORE_STANDALONE]:\r
+        if Info.SourceFileList:\r
           if NumEntryPoints != 1:\r
               EdkLogger.error(\r
                   "build",\r
@@ -1520,43 +1512,43 @@ def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
                   File=str(Info),\r
                   ExtraData= ", ".join(Info.Module.ModuleEntryPointList)\r
                   )\r
-    if Info.ModuleType == 'PEI_CORE':\r
+    if Info.ModuleType == SUP_MODULE_PEI_CORE:\r
         AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict))\r
         AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict))\r
-    elif Info.ModuleType == 'DXE_CORE':\r
+    elif Info.ModuleType == SUP_MODULE_DXE_CORE:\r
         AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict))\r
         AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict))\r
-    elif Info.ModuleType == 'SMM_CORE':\r
+    elif Info.ModuleType == SUP_MODULE_SMM_CORE:\r
         AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict))\r
         AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict))\r
-    elif Info.ModuleType == 'MM_CORE_STANDALONE':\r
+    elif Info.ModuleType == SUP_MODULE_MM_CORE_STANDALONE:\r
         AutoGenC.Append(gMmCoreStandaloneEntryPointString.Replace(Dict))\r
         AutoGenH.Append(gMmCoreStandaloneEntryPointPrototype.Replace(Dict))\r
-    elif Info.ModuleType == 'PEIM':\r
+    elif Info.ModuleType == SUP_MODULE_PEIM:\r
         if NumEntryPoints < 2:\r
             AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict))\r
         else:\r
             AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict))\r
         AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict))\r
-    elif Info.ModuleType in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:\r
+    elif Info.ModuleType in [SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER]:\r
         if NumEntryPoints < 2:\r
             AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict))\r
         else:\r
             AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict))\r
         AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict))\r
-    elif Info.ModuleType == 'DXE_SMM_DRIVER':\r
+    elif Info.ModuleType == SUP_MODULE_DXE_SMM_DRIVER:\r
         if NumEntryPoints == 0:\r
             AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict))\r
         else:\r
             AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict))\r
         AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict))\r
-    elif Info.ModuleType == 'MM_STANDALONE':\r
+    elif Info.ModuleType == SUP_MODULE_MM_STANDALONE:\r
         if NumEntryPoints < 2:\r
             AutoGenC.Append(gMmStandaloneEntryPointString[NumEntryPoints].Replace(Dict))\r
         else:\r
             AutoGenC.Append(gMmStandaloneEntryPointString[2].Replace(Dict))\r
         AutoGenH.Append(gMmStandaloneEntryPointPrototype.Replace(Dict))\r
-    elif Info.ModuleType == 'UEFI_APPLICATION':\r
+    elif Info.ModuleType == SUP_MODULE_UEFI_APPLICATION:\r
         if NumEntryPoints < 2:\r
             AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict))\r
         else:\r
@@ -1570,7 +1562,7 @@ def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
 #   @param      AutoGenH    The TemplateString object for header file\r
 #\r
 def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):\r
-    if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:\r
+    if Info.IsLibrary or Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_SEC]:\r
         return\r
     #\r
     # Unload Image Handlers\r
@@ -1590,8 +1582,8 @@ def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):
 #   @param      AutoGenH    The TemplateString object for header file\r
 #\r
 def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):\r
-    if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
-        GuidType = "GUID"\r
+    if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:\r
+        GuidType = TAB_GUID\r
     else:\r
         GuidType = "EFI_GUID"\r
 \r
@@ -1614,8 +1606,8 @@ def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):
 #   @param      AutoGenH    The TemplateString object for header file\r
 #\r
 def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):\r
-    if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
-        GuidType = "GUID"\r
+    if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:\r
+        GuidType = TAB_GUID\r
     else:\r
         GuidType = "EFI_GUID"\r
 \r
@@ -1638,8 +1630,8 @@ def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):
 #   @param      AutoGenH    The TemplateString object for header file\r
 #\r
 def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):\r
-    if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
-        GuidType = "GUID"\r
+    if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:\r
+        GuidType = TAB_GUID\r
     else:\r
         GuidType = "EFI_GUID"\r
 \r
@@ -1666,19 +1658,19 @@ def CreatePcdCode(Info, AutoGenC, AutoGenH):
     # Collect Token Space GUIDs used by DynamicEc PCDs\r
     TokenSpaceList = []\r
     for Pcd in Info.ModulePcdList:\r
-        if Pcd.Type in gDynamicExPcd and Pcd.TokenSpaceGuidCName not in TokenSpaceList:\r
-            TokenSpaceList += [Pcd.TokenSpaceGuidCName]\r
-            \r
+        if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenSpaceGuidCName not in TokenSpaceList:\r
+            TokenSpaceList.append(Pcd.TokenSpaceGuidCName)\r
+\r
     SkuMgr = Info.Workspace.Platform.SkuIdMgr\r
     AutoGenH.Append("\n// Definition of SkuId Array\n")\r
     AutoGenH.Append("extern UINT64 _gPcd_SkuId_Array[];\n")\r
     # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found\r
-    if TokenSpaceList <> []:            \r
+    if TokenSpaceList:\r
         AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")\r
-        if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
-            GuidType = "GUID"\r
+        if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:\r
+            GuidType = TAB_GUID\r
         else:\r
-            GuidType = "EFI_GUID"              \r
+            GuidType = "EFI_GUID"\r
         for Item in TokenSpaceList:\r
             AutoGenH.Append('extern %s %s;\n' % (GuidType, Item))\r
 \r
@@ -1937,7 +1929,7 @@ def BmpImageDecoder(File, Buffer, PaletteIndex, TransParent):
     ImageType, = struct.unpack('2s', Buffer[0:2])\r
     if ImageType!= 'BM': # BMP file type is 'BM'\r
         EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard BMP file." % File.Path)\r
-    BMP_IMAGE_HEADER = collections.namedtuple('BMP_IMAGE_HEADER', ['bfSize','bfReserved1','bfReserved2','bfOffBits','biSize','biWidth','biHeight','biPlanes','biBitCount', 'biCompression', 'biSizeImage','biXPelsPerMeter','biYPelsPerMeter','biClrUsed','biClrImportant'])\r
+    BMP_IMAGE_HEADER = collections.namedtuple('BMP_IMAGE_HEADER', ['bfSize', 'bfReserved1', 'bfReserved2', 'bfOffBits', 'biSize', 'biWidth', 'biHeight', 'biPlanes', 'biBitCount', 'biCompression', 'biSizeImage', 'biXPelsPerMeter', 'biYPelsPerMeter', 'biClrUsed', 'biClrImportant'])\r
     BMP_IMAGE_HEADER_STRUCT = struct.Struct('IHHIIIIHHIIIIII')\r
     BmpHeader = BMP_IMAGE_HEADER._make(BMP_IMAGE_HEADER_STRUCT.unpack_from(Buffer[2:]))\r
     #\r
@@ -2021,16 +2013,14 @@ def CreateHeaderCode(Info, AutoGenC, AutoGenH):
     # file header\r
     AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'}))\r
     # header file Prologue\r
-    AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-','_')}))\r
+    AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-', '_')}))\r
     AutoGenH.Append(gAutoGenHCppPrologueString)\r
     if Info.AutoGenVersion >= 0x00010005:\r
         # header files includes\r
-        AutoGenH.Append("#include <%s>\n" % gBasicHeaderFile)\r
-        if Info.ModuleType in gModuleTypeHeaderFile \\r
-           and gModuleTypeHeaderFile[Info.ModuleType][0] != gBasicHeaderFile:\r
+        if Info.ModuleType in gModuleTypeHeaderFile:\r
             AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0])\r
         #\r
-        # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h \r
+        # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h\r
         # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.\r
         #\r
         if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds:\r
@@ -2099,7 +2089,7 @@ def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer,
     if Info.UnicodeFileList:\r
         FileName = "%sStrDefs.h" % Info.Name\r
         StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))\r
-        StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-','_')}))\r
+        StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-', '_')}))\r
         CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer)\r
 \r
         GuidMacros = []\r
@@ -2109,15 +2099,16 @@ def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer,
             GuidMacros.append('#define %s %s' % (Guid, Info.Module.Guids[Guid]))\r
         for Guid, Value in Info.Module.Protocols.items() + Info.Module.Ppis.items():\r
             GuidMacros.append('#define %s %s' % (Guid, Value))\r
-        # supports FixedAtBuild usage in VFR file\r
+        # supports FixedAtBuild and FeaturePcd usage in VFR file\r
         if Info.VfrFileList and Info.ModulePcdList:\r
             GuidMacros.append('#define %s %s' % ('FixedPcdGetBool(TokenName)', '_PCD_VALUE_##TokenName'))\r
             GuidMacros.append('#define %s %s' % ('FixedPcdGet8(TokenName)', '_PCD_VALUE_##TokenName'))\r
             GuidMacros.append('#define %s %s' % ('FixedPcdGet16(TokenName)', '_PCD_VALUE_##TokenName'))\r
             GuidMacros.append('#define %s %s' % ('FixedPcdGet32(TokenName)', '_PCD_VALUE_##TokenName'))\r
             GuidMacros.append('#define %s %s' % ('FixedPcdGet64(TokenName)', '_PCD_VALUE_##TokenName'))\r
+            GuidMacros.append('#define %s %s' % ('FeaturePcdGet(TokenName)', '_PCD_VALUE_##TokenName'))\r
             for Pcd in Info.ModulePcdList:\r
-                if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:\r
+                if Pcd.Type in [TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_FEATURE_FLAG]:\r
                     TokenCName = Pcd.TokenCName\r
                     Value = Pcd.DefaultValue\r
                     if Pcd.DatumType == 'BOOLEAN':\r
@@ -2144,7 +2135,7 @@ def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer,
     if Info.IdfFileList:\r
         FileName = "%sImgDefs.h" % Info.Name\r
         StringIdf.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))\r
-        StringIdf.Append(gAutoGenHPrologueString.Replace({'File':'IMAGEDEFS', 'Guid':Info.Guid.replace('-','_')}))\r
+        StringIdf.Append(gAutoGenHPrologueString.Replace({'File':'IMAGEDEFS', 'Guid':Info.Guid.replace('-', '_')}))\r
         CreateIdfFileCode(Info, AutoGenC, StringIdf, IdfGenCFlag, IdfGenBinBuffer)\r
 \r
         StringIdf.Append("\n#endif\n")\r