BaseTools: PcdDataBase Optimization for multiple SkuIds
authorLiming Gao <liming.gao@intel.com>
Fri, 22 Dec 2017 12:04:04 +0000 (20:04 +0800)
committerLiming Gao <liming.gao@intel.com>
Mon, 25 Dec 2017 03:05:47 +0000 (11:05 +0800)
https://bugzilla.tianocore.org/show_bug.cgi?id=546
BaseTools will generate the optimized PCD database to save the image size
at build time for multiple SKUs. The optimized PCD database layout will be like
below, the PCD database will be composed of the full default SKU data
(PCD_DATABASE_INIT) and the non-default SKU delta data(PCD_DATABASE_SKU_DELTA).
PCD driver will build HOB to store the full default SKU data, and patch HOB
data based on non-default SKU delta data for the SKU set by SetSku(),
it can save memory resource at boot time.

//
// PCD database layout:
// +---------------------------------+
// | PCD_DATABASE_INIT (DEFAULT SKU) |
// +---------------------------------+
// | PCD_DATABASE_SKU_DELTA (SKU A)  |
// +---------------------------------+
// | PCD_DATABASE_SKU_DELTA (SKU B)  |
// +---------------------------------+
// | ......                          |
// +---------------------------------+
//

BaseTools, PCD database and driver updates are needed for this proposal.
For single SKU (default) case, this proposal is expected to have no impact.
For multi-SKU case, PCD database format will be changed.
So, PcdDataBase Version is also updated from 6 to 7.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Feng Bob C <bob.c.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools/Source/Python/AutoGen/GenPcdDb.py
BaseTools/Source/Python/AutoGen/GenVar.py
BaseTools/Source/Python/Common/BuildToolError.py
BaseTools/Source/Python/Common/Misc.py
BaseTools/Source/Python/Common/VpdInfoFile.py
BaseTools/Source/Python/Workspace/DscBuildData.py
BaseTools/Source/Python/Workspace/WorkspaceCommon.py

index be6fecd..5d6cce0 100644 (file)
@@ -1607,11 +1607,14 @@ class PlatformAutoGen(AutoGen):
             if PcdNvStoreDfBuffer:\r
                 var_info = self.CollectVariables(self._DynamicPcdList)\r
                 default_skuobj = PcdNvStoreDfBuffer.SkuInfoList.get("DEFAULT")\r
-                default_skuobj.DefaultValue = var_info.dump()\r
+                vardump = var_info.dump()\r
+                if vardump:\r
+                    default_skuobj.DefaultValue = vardump\r
+                    PcdNvStoreDfBuffer.DefaultValue = vardump\r
                 if default_skuobj:\r
                     PcdNvStoreDfBuffer.SkuInfoList.clear()\r
                     PcdNvStoreDfBuffer.SkuInfoList['DEFAULT'] = default_skuobj\r
-                    PcdNvStoreDfBuffer.MaxDatumSize = len(default_skuobj.DefaultValue.split(","))\r
+                    PcdNvStoreDfBuffer.MaxDatumSize = str(len(default_skuobj.DefaultValue.split(",")))\r
 \r
             PlatformPcds = self._PlatformPcds.keys()\r
             PlatformPcds.sort()\r
@@ -1789,6 +1792,13 @@ class PlatformAutoGen(AutoGen):
         self._DynamicPcdList.extend(UnicodePcdArray)\r
         self._DynamicPcdList.extend(HiiPcdArray)\r
         self._DynamicPcdList.extend(OtherPcdArray)\r
+        allskuset = [(SkuName,Sku.SkuId) for pcd in self._DynamicPcdList for (SkuName,Sku) in pcd.SkuInfoList.items()]\r
+        for pcd in self._DynamicPcdList:\r
+            if len(pcd.SkuInfoList) == 1:\r
+                for (SkuName,SkuId) in allskuset:\r
+                    if type(SkuId) in (str,unicode) and eval(SkuId) == 0 or SkuId == 0:\r
+                        continue\r
+                    pcd.SkuInfoList[SkuName] = pcd.SkuInfoList['DEFAULT']\r
         self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList\r
         \r
     ## Return the platform build data object\r
index 3d9bfd7..e3ab027 100644 (file)
@@ -18,8 +18,10 @@ from ValidCheckingInfoObject import VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER
 from ValidCheckingInfoObject import VAR_CHECK_PCD_VARIABLE_TAB\r
 from ValidCheckingInfoObject import VAR_VALID_OBJECT_FACTORY\r
 from Common.VariableAttributes import VariableAttributes\r
+import copy\r
+from struct import unpack\r
 \r
-DATABASE_VERSION = 6\r
+DATABASE_VERSION = 7\r
 \r
 gPcdDatabaseAutoGenC = TemplateString("""\r
 //\r
@@ -114,7 +116,6 @@ gPcdDatabaseAutoGenH = TemplateString("""
 #define ${PHASE}_EXMAPPING_TABLE_SIZE           ${EXMAPPING_TABLE_SIZE}\r
 #define ${PHASE}_EX_TOKEN_NUMBER                ${EX_TOKEN_NUMBER}\r
 #define ${PHASE}_SIZE_TABLE_SIZE                ${SIZE_TABLE_SIZE}\r
-#define ${PHASE}_SKU_HEAD_SIZE                  ${SKU_HEAD_SIZE}\r
 #define ${PHASE}_GUID_TABLE_EMPTY               ${GUID_TABLE_EMPTY}\r
 #define ${PHASE}_STRING_TABLE_EMPTY             ${STRING_TABLE_EMPTY}\r
 #define ${PHASE}_SKUID_TABLE_EMPTY              ${SKUID_TABLE_EMPTY}\r
@@ -139,9 +140,6 @@ ${END}
 ${BEGIN}  STRING_HEAD        ${STRING_HEAD_CNAME_DECL}_${STRING_HEAD_GUID_DECL}[${STRING_HEAD_NUMSKUS_DECL}];\r
 ${END}\r
 ${BEGIN}  VARIABLE_HEAD      ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}_Variable_Header[${VARIABLE_HEAD_NUMSKUS_DECL}];\r
-${END}\r
-${BEGIN}  SKU_HEAD           SkuHead[${PHASE}_SKU_HEAD_SIZE];\r
-${END}\r
 ${BEGIN}  UINT8              StringTable${STRING_TABLE_INDEX}[${STRING_TABLE_LENGTH}]; /* ${STRING_TABLE_CNAME}_${STRING_TABLE_GUID} */\r
 ${END}\r
   SIZE_INFO          SizeTable[${PHASE}_SIZE_TABLE_SIZE];\r
@@ -653,7 +651,7 @@ def GetTokenTypeValue(TokenType):
         "PCD_TYPE_DATA":(0x0 << 28),\r
         "PCD_TYPE_HII":(0x8 << 28),\r
         "PCD_TYPE_VPD":(0x4 << 28),\r
-        "PCD_TYPE_SKU_ENABLED":(0x2 << 28),\r
+#        "PCD_TYPE_SKU_ENABLED":(0x2 << 28),\r
         "PCD_TYPE_STRING":(0x1 << 28),\r
 \r
         "PCD_DATUM_TYPE_SHIFT":24,\r
@@ -698,9 +696,7 @@ def BuildExDataBase(Dict):
     VariableTable = Dict['VARIABLE_DB_VALUE']\r
     DbVariableTable = DbVariableTableItemList(20, RawDataList = VariableTable)\r
     NumberOfSkuEnabledPcd = GetIntegerValue(Dict['SKU_HEAD_SIZE'])\r
-    Dict['SKUHEAD_TABLE_VALUE'] = [(0,0) for i in xrange(NumberOfSkuEnabledPcd)]\r
-    SkuTable = Dict['SKUHEAD_TABLE_VALUE']  # Generated later\r
-    DbSkuTable = DbSkuHeadTableItemList(8, RawDataList = SkuTable)\r
+\r
     Dict['STRING_TABLE_DB_VALUE'] = [StringArrayToList(x) for x in Dict['STRING_TABLE_VALUE']]\r
     \r
     StringTableValue = Dict['STRING_TABLE_DB_VALUE']\r
@@ -738,8 +734,8 @@ def BuildExDataBase(Dict):
     DbVardefValueBoolean = DbItemList(1, RawDataList = VardefValueBoolean)\r
     SkuidValue = Dict['SKUID_VALUE']\r
     DbSkuidValue = DbItemList(8, RawDataList = SkuidValue)\r
-    SkuIndexValue = Dict['SKU_INDEX_VALUE']\r
-    DbSkuIndexValue = DbItemList(8,RawDataList = SkuIndexValue)\r
+\r
+\r
     \r
     # Unit Db Items\r
     UnInitValueUint64 = Dict['UNINIT_GUID_DECL_UINT64']\r
@@ -754,24 +750,24 @@ def BuildExDataBase(Dict):
     DbUnInitValueBoolean = DbItemList(1, RawDataList = UnInitValueBoolean)\r
     PcdTokenNumberMap = Dict['PCD_ORDER_TOKEN_NUMBER_MAP']\r
  \r
-    DbNameTotle = ["SkuidValue", "SkuIndexValue", "InitValueUint64", "VardefValueUint64", "InitValueUint32", "VardefValueUint32", "VpdHeadValue", "ExMapTable",\r
-               "LocalTokenNumberTable", "GuidTable", "StringHeadValue",  "PcdNameOffsetTable","VariableTable","SkuTable", "StringTableLen", "PcdTokenTable", "PcdCNameTable", \r
+    DbNameTotle = ["SkuidValue",  "InitValueUint64", "VardefValueUint64", "InitValueUint32", "VardefValueUint32", "VpdHeadValue", "ExMapTable",\r
+               "LocalTokenNumberTable", "GuidTable", "StringHeadValue",  "PcdNameOffsetTable","VariableTable", "StringTableLen", "PcdTokenTable", "PcdCNameTable",\r
                "SizeTableValue", "InitValueUint16", "VardefValueUint16", "InitValueUint8", "VardefValueUint8", "InitValueBoolean",\r
                "VardefValueBoolean", "UnInitValueUint64", "UnInitValueUint32", "UnInitValueUint16", "UnInitValueUint8", "UnInitValueBoolean"]\r
  \r
-    DbTotal = [SkuidValue, SkuIndexValue, InitValueUint64, VardefValueUint64, InitValueUint32, VardefValueUint32, VpdHeadValue, ExMapTable,\r
-               LocalTokenNumberTable, GuidTable, StringHeadValue,  PcdNameOffsetTable,VariableTable,SkuTable, StringTableLen, PcdTokenTable,PcdCNameTable, \r
+    DbTotal = [SkuidValue,  InitValueUint64, VardefValueUint64, InitValueUint32, VardefValueUint32, VpdHeadValue, ExMapTable,\r
+               LocalTokenNumberTable, GuidTable, StringHeadValue,  PcdNameOffsetTable,VariableTable, StringTableLen, PcdTokenTable,PcdCNameTable,\r
                SizeTableValue, InitValueUint16, VardefValueUint16, InitValueUint8, VardefValueUint8, InitValueBoolean,\r
                VardefValueBoolean, UnInitValueUint64, UnInitValueUint32, UnInitValueUint16, UnInitValueUint8, UnInitValueBoolean]\r
-    DbItemTotal = [DbSkuidValue, DbSkuIndexValue, DbInitValueUint64, DbVardefValueUint64, DbInitValueUint32, DbVardefValueUint32, DbVpdHeadValue, DbExMapTable,\r
-               DbLocalTokenNumberTable, DbGuidTable, DbStringHeadValue,  DbPcdNameOffsetTable,DbVariableTable,DbSkuTable, DbStringTableLen, DbPcdTokenTable, DbPcdCNameTable, \r
+    DbItemTotal = [DbSkuidValue,  DbInitValueUint64, DbVardefValueUint64, DbInitValueUint32, DbVardefValueUint32, DbVpdHeadValue, DbExMapTable,\r
+               DbLocalTokenNumberTable, DbGuidTable, DbStringHeadValue,  DbPcdNameOffsetTable,DbVariableTable, DbStringTableLen, DbPcdTokenTable, DbPcdCNameTable,\r
                DbSizeTableValue, DbInitValueUint16, DbVardefValueUint16, DbInitValueUint8, DbVardefValueUint8, DbInitValueBoolean,\r
                DbVardefValueBoolean, DbUnInitValueUint64, DbUnInitValueUint32, DbUnInitValueUint16, DbUnInitValueUint8, DbUnInitValueBoolean]\r
     \r
     # VardefValueBoolean is the last table in the init table items\r
     InitTableNum = DbNameTotle.index("VardefValueBoolean") + 1\r
     # The FixedHeader length of the PCD_DATABASE_INIT, from Signature to Pad\r
-    FixedHeaderLen = 72\r
+    FixedHeaderLen = 76\r
 \r
     # Get offset of SkuId table in the database \r
     SkuIdTableOffset = FixedHeaderLen\r
@@ -782,26 +778,8 @@ def BuildExDataBase(Dict):
     \r
     \r
     # Get offset of SkuValue table in the database    \r
-    SkuTableOffset = FixedHeaderLen\r
-    for DbIndex in xrange(len(DbTotal)):\r
-        if DbTotal[DbIndex] is SkuTable:\r
-            break\r
-        elif DbItemTotal[DbIndex] is DbSkuIndexValue:\r
-            if DbItemTotal[DbIndex].RawDataList:\r
-                Count = 0\r
-                for item in DbItemTotal[DbIndex].RawDataList:\r
-                    Count += len(item)\r
-                SkuTableOffset += DbItemTotal[DbIndex].ItemSize * Count\r
-                continue\r
-        SkuTableOffset += DbItemTotal[DbIndex].GetListSize()\r
 \r
     # Fix up the LocalTokenNumberTable, SkuHeader table\r
-    SkuHeaderIndex = 0\r
-    if len(Dict['SKU_INDEX_VALUE']) > 0:\r
-        SkuIndexIndexTable = [(0) for i in xrange(len(Dict['SKU_INDEX_VALUE']))]\r
-        SkuIndexIndexTable[0] = 0  #Dict['SKU_INDEX_VALUE'][0][0]\r
-        for i in range(1,len(Dict['SKU_INDEX_VALUE'])):\r
-            SkuIndexIndexTable[i] = SkuIndexIndexTable[i-1]+Dict['SKU_INDEX_VALUE'][i-1][0] + 1\r
     for (LocalTokenNumberTableIndex, (Offset, Table)) in enumerate(LocalTokenNumberTable):\r
         DbIndex = 0\r
         DbOffset = FixedHeaderLen\r
@@ -809,13 +787,6 @@ def BuildExDataBase(Dict):
             if DbTotal[DbIndex] is Table:\r
                 DbOffset += DbItemTotal[DbIndex].GetInterOffset(Offset)\r
                 break\r
-            elif DbItemTotal[DbIndex] is DbSkuIndexValue:\r
-                if DbItemTotal[DbIndex].RawDataList:\r
-                    Count = 0\r
-                    for item in DbItemTotal[DbIndex].RawDataList:\r
-                        Count += len(item)\r
-                    DbOffset += DbItemTotal[DbIndex].ItemSize * Count\r
-                    continue\r
             DbOffset += DbItemTotal[DbIndex].GetListSize()\r
             if DbIndex + 1 == InitTableNum:\r
                 if DbOffset % 8:\r
@@ -828,16 +799,8 @@ def BuildExDataBase(Dict):
         LocalTokenNumberTable[LocalTokenNumberTableIndex] = DbOffset|int(TokenTypeValue)\r
         # if PCD_TYPE_SKU_ENABLED, then we need to fix up the SkuTable\r
         \r
-        SkuIndexTabalOffset = SkuIdTableOffset + len(Dict['SKUID_VALUE']) * 8\r
-        if (TokenTypeValue & (0x2 << 28)):\r
-            SkuTable[SkuHeaderIndex] = (DbOffset|int(TokenTypeValue & ~(0x2<<28)), SkuIndexTabalOffset + SkuIndexIndexTable[PcdTokenNumberMap[LocalTokenNumberTableIndex]] * 8)\r
-            LocalTokenNumberTable[LocalTokenNumberTableIndex] = (SkuTableOffset + SkuHeaderIndex * 8) | int(TokenTypeValue)\r
-            SkuHeaderIndex += 1\r
         \r
     \r
-    if SkuHeaderIndex == 0:\r
-        SkuHeaderIndex = 1\r
-    assert(SkuHeaderIndex == NumberOfSkuEnabledPcd)\r
 \r
     # resolve variable table offset \r
     for VariableEntries in VariableTable:\r
@@ -850,13 +813,6 @@ def BuildExDataBase(Dict):
                 if DbTotal[DbIndex] is VariableRefTable:\r
                     DbOffset += DbItemTotal[DbIndex].GetInterOffset(VariableOffset)\r
                     break\r
-                elif DbItemTotal[DbIndex] is DbSkuIndexValue:\r
-                    if DbItemTotal[DbIndex].RawDataList:\r
-                        Count = 0\r
-                        for item in DbItemTotal[DbIndex].RawDataList:\r
-                            Count += len(item)\r
-                        DbOffset += DbItemTotal[DbIndex].ItemSize * Count\r
-                        continue\r
                 DbOffset += DbItemTotal[DbIndex].GetListSize()\r
                 if DbIndex + 1 == InitTableNum:\r
                     if DbOffset % 8:\r
@@ -888,13 +844,7 @@ def BuildExDataBase(Dict):
             SkuIdTableOffset = DbTotalLength\r
         elif DbItemTotal[DbIndex] is DbPcdNameOffsetTable:\r
             DbPcdNameOffset = DbTotalLength\r
-        elif DbItemTotal[DbIndex] is DbSkuIndexValue:\r
-            if DbItemTotal[DbIndex].RawDataList:\r
-                Count = 0\r
-                for item in DbItemTotal[DbIndex].RawDataList:\r
-                    Count += len(item)\r
-                DbTotalLength += DbItemTotal[DbIndex].ItemSize * Count\r
-                continue\r
+\r
 \r
         DbTotalLength += DbItemTotal[DbIndex].GetListSize()\r
     if not Dict['PCD_INFO_FLAG']:\r
@@ -936,6 +886,9 @@ def BuildExDataBase(Dict):
     Buffer += b\r
     b = pack('=Q', SystemSkuId)\r
 \r
+    Buffer += b\r
+    b = pack('=L', 0)\r
+\r
     Buffer += b\r
     b = pack('=L', UninitDataBaseSize)\r
 \r
@@ -1003,7 +956,7 @@ def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH):
         EdkLogger.error("build", AUTOGEN_ERROR, "Not supported PcdIsDriver type:%s" % Info.PcdIsDriver,\r
                         ExtraData="[%s]" % str(Info))\r
 \r
-    AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer = CreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, 'PEI')\r
+    AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer = NewCreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, 'PEI')\r
     AutoGenH.Append(AdditionalAutoGenH.String)\r
 \r
     Phase = gPcdPhaseMap[Info.PcdIsDriver]\r
@@ -1011,7 +964,7 @@ def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH):
         AutoGenC.Append(AdditionalAutoGenC.String)\r
 \r
     if Phase == 'DXE':\r
-        AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer = CreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, Phase)\r
+        AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer = NewCreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, Phase)\r
         AutoGenH.Append(AdditionalAutoGenH.String)\r
         AutoGenC.Append(AdditionalAutoGenC.String)\r
 \r
@@ -1022,14 +975,83 @@ def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH):
     DbFile = StringIO()\r
     DbFile.write(PcdDbBuffer)\r
     Changed = SaveFileOnChange(DbFileName, DbFile.getvalue(), True)\r
+def CreatePcdDataBase(PcdDBData):\r
+    delta = {}\r
+    basedata = {}\r
+    if not PcdDBData:\r
+        return ""\r
+    for skuname,skuid in PcdDBData:\r
+        if len(PcdDBData[(skuname,skuid)][1]) != len(PcdDBData[("DEFAULT","0")][1]):\r
+            EdkLogger.ERROR("The size of each sku in one pcd are not same")\r
+    for skuname,skuid in PcdDBData:\r
+        if skuname == "DEFAULT":\r
+            continue\r
+        delta[(skuname,skuid)] = [(index,data,hex(data)) for index,data in enumerate(PcdDBData[(skuname,skuid)][1]) if PcdDBData[(skuname,skuid)][1][index] != PcdDBData[("DEFAULT","0")][1][index]]\r
+        basedata[(skuname,skuid)] = [(index,PcdDBData[("DEFAULT","0")][1][index],hex(PcdDBData[("DEFAULT","0")][1][index])) for index,data in enumerate(PcdDBData[(skuname,skuid)][1]) if PcdDBData[(skuname,skuid)][1][index] != PcdDBData[("DEFAULT","0")][1][index]]\r
+    databasebuff = PcdDBData[("DEFAULT","0")][0]\r
+\r
+    for skuname,skuid in delta:\r
+        databasebuff += pack('=H', int(skuid))\r
+        databasebuff += pack('=H', 0)\r
+        databasebuff += pack('=L', 8+4*len(delta[(skuname,skuid)]))\r
+        for item in delta[(skuname,skuid)]:\r
+            databasebuff += pack("=L",item[0])\r
+            databasebuff = databasebuff[:-1] + pack("=B",item[1])\r
+    totallen = len(databasebuff)\r
+    totallenbuff = pack("=L",totallen)\r
+    newbuffer = databasebuff[:32]\r
+    for i in range(4):\r
+        newbuffer += totallenbuff[i]\r
+    for i in range(36,totallen):\r
+        newbuffer += databasebuff[i]\r
+\r
+    return newbuffer\r
+def CreateVarCheckBin(VarCheckTab):\r
+    return VarCheckTab[('DEFAULT',"0")]\r
+def CreateAutoGen(PcdDriverAutoGenData):\r
+    autogenC = TemplateString()\r
+    for skuname,skuid in PcdDriverAutoGenData:\r
+        autogenC.Append("//SKUID: %s" % skuname)\r
+        autogenC.Append(PcdDriverAutoGenData[(skuname,skuid)][1].String)\r
+    return (PcdDriverAutoGenData[(skuname,skuid)][0],autogenC)\r
+def NewCreatePcdDatabasePhaseSpecificAutoGen(Platform,Phase):\r
+    def prune_sku(pcd,skuname):\r
+        new_pcd = copy.deepcopy(pcd)\r
+        new_pcd.SkuInfoList = {skuname:pcd.SkuInfoList[skuname]}\r
+        return new_pcd\r
+    DynamicPcds = Platform.DynamicPcdList\r
+    DynamicPcdSet_Sku = {(SkuName,skuobj.SkuId):[] for pcd in DynamicPcds for (SkuName,skuobj) in pcd.SkuInfoList.items() }\r
+    for skuname,skuid in DynamicPcdSet_Sku:\r
+        DynamicPcdSet_Sku[(skuname,skuid)] = [prune_sku(pcd,skuname) for pcd in DynamicPcds]\r
+    PcdDBData = {}\r
+    PcdDriverAutoGenData = {}\r
+    VarCheckTableData = {}\r
+    if DynamicPcdSet_Sku:\r
+        for skuname,skuid in DynamicPcdSet_Sku:\r
+            AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer,VarCheckTab = CreatePcdDatabasePhaseSpecificAutoGen (Platform,DynamicPcdSet_Sku[(skuname,skuid)], Phase)\r
+            final_data = ()\r
+            for item in PcdDbBuffer:\r
+                final_data += unpack("B",item)\r
+            PcdDBData[(skuname,skuid)] = (PcdDbBuffer, final_data)\r
+            PcdDriverAutoGenData[(skuname,skuid)] = (AdditionalAutoGenH, AdditionalAutoGenC)\r
+            VarCheckTableData[(skuname,skuid)] = VarCheckTab\r
+        if Platform.Platform.VarCheckFlag:\r
+            dest = os.path.join(Platform.BuildDir, 'FV')\r
+            VarCheckTable = CreateVarCheckBin(VarCheckTableData)\r
+            VarCheckTable.dump(dest, Phase)\r
+        AdditionalAutoGenH, AdditionalAutoGenC =  CreateAutoGen(PcdDriverAutoGenData)\r
+    else:\r
+        AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer,VarCheckTab = CreatePcdDatabasePhaseSpecificAutoGen (Platform,{}, Phase)\r
 \r
+    PcdDbBuffer = CreatePcdDataBase(PcdDBData)\r
+    return AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer\r
 ## Create PCD database in DXE or PEI phase\r
 #\r
 #   @param      Platform    The platform object\r
 #   @retval     tuple       Two TemplateString objects for C code and header file,\r
 #                           respectively\r
 #\r
-def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):\r
+def CreatePcdDatabasePhaseSpecificAutoGen (Platform, DynamicPcdList, Phase):\r
     AutoGenC = TemplateString()\r
     AutoGenH = TemplateString()\r
 \r
@@ -1106,8 +1128,6 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
 \r
     Dict['LOCAL_TOKEN_NUMBER_DB_VALUE'] = []\r
     Dict['VARIABLE_DB_VALUE'] = []\r
-    Dict['SKUHEAD_TABLE_VALUE'] = []\r
-    Dict['SKU_INDEX_VALUE'] = []\r
     \r
     Dict['PCD_TOKENSPACE'] = []\r
     Dict['PCD_CNAME'] = [] \r
@@ -1132,7 +1152,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
     GuidList = []\r
     VarCheckTab = VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER()\r
     i = 0\r
-    ReorderedDynPcdList = GetOrderedDynamicPcdList(Platform.DynamicPcdList, Platform.PcdTokenNumber)\r
+    ReorderedDynPcdList = GetOrderedDynamicPcdList(DynamicPcdList, Platform.PcdTokenNumber)\r
     for item in ReorderedDynPcdList:\r
         if item.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
             item.DatumType = "VOID*"\r
@@ -1193,11 +1213,9 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
             Pcd.TokenTypeList = ['PCD_DATUM_TYPE_' + Pcd.DatumType]\r
 \r
         if len(Pcd.SkuInfoList) > 1:\r
-            Pcd.TokenTypeList += ['PCD_TYPE_SKU_ENABLED']\r
+            Pcd.TokenTypeList += ['PCD_TYPE_SKU_ENABLED']\r
             NumberOfSkuEnabledPcd += 1\r
         \r
-        SkuIndexTableTmp = []\r
-        SkuIndexTableTmp.append(0)  \r
         SkuIdIndex = 1  \r
         VariableHeadList = []\r
         for SkuName in Pcd.SkuInfoList:\r
@@ -1206,10 +1224,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
             if SkuId == None or SkuId == '':\r
                 continue\r
 \r
-            if (SkuId + 'U') not in Dict['SKUID_VALUE']:\r
-                Dict['SKUID_VALUE'].append(SkuId + 'U')\r
                 \r
-            SkuIndexTableTmp.append(SkuId+'U')\r
             SkuIdIndex += 1\r
     \r
             if len(Sku.VariableName) > 0:\r
@@ -1240,32 +1255,28 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
                 Pcd.InitString = 'INIT'\r
                 # Store all variable names of one HII PCD under different SKU to stringTable\r
                 # and calculate the VariableHeadStringIndex\r
-                if SkuIdIndex - 2 == 0:\r
-                    for SkuName2 in Pcd.SkuInfoList:\r
-                        SkuInfo = Pcd.SkuInfoList[SkuName2]\r
-                        if SkuInfo.SkuId == None or SkuInfo.SkuId == '':\r
-                            continue\r
-                        VariableNameStructure = StringToArray(SkuInfo.VariableName)\r
-                        if VariableNameStructure not in Dict['STRING_TABLE_VALUE']:\r
-                            Dict['STRING_TABLE_CNAME'].append(CName)\r
-                            Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid)\r
-                            if StringTableIndex == 0:\r
-                                Dict['STRING_TABLE_INDEX'].append('')\r
-                            else:\r
-                                Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex)\r
-                            VarNameSize = len(VariableNameStructure.replace(',',' ').split())\r
-                            Dict['STRING_TABLE_LENGTH'].append(VarNameSize )\r
-                            Dict['STRING_TABLE_VALUE'].append(VariableNameStructure)\r
-                            StringHeadOffsetList.append(str(StringTableSize) + 'U')\r
-                            VarStringDbOffsetList = []\r
-                            VarStringDbOffsetList.append(StringTableSize)\r
-                            Dict['STRING_DB_VALUE'].append(VarStringDbOffsetList)      \r
-                            StringTableIndex += 1\r
-                            StringTableSize += len(VariableNameStructure.replace(',',' ').split())\r
-                        VariableHeadStringIndex = 0\r
-                        for Index in range(Dict['STRING_TABLE_VALUE'].index(VariableNameStructure)):\r
-                            VariableHeadStringIndex += Dict['STRING_TABLE_LENGTH'][Index]\r
-                        VariableHeadList.append(VariableHeadStringIndex)\r
+\r
+                VariableNameStructure = StringToArray(Sku.VariableName)\r
+                if VariableNameStructure not in Dict['STRING_TABLE_VALUE']:\r
+                    Dict['STRING_TABLE_CNAME'].append(CName)\r
+                    Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid)\r
+                    if StringTableIndex == 0:\r
+                        Dict['STRING_TABLE_INDEX'].append('')\r
+                    else:\r
+                        Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex)\r
+                    VarNameSize = len(VariableNameStructure.replace(',',' ').split())\r
+                    Dict['STRING_TABLE_LENGTH'].append(VarNameSize )\r
+                    Dict['STRING_TABLE_VALUE'].append(VariableNameStructure)\r
+                    StringHeadOffsetList.append(str(StringTableSize) + 'U')\r
+                    VarStringDbOffsetList = []\r
+                    VarStringDbOffsetList.append(StringTableSize)\r
+                    Dict['STRING_DB_VALUE'].append(VarStringDbOffsetList)\r
+                    StringTableIndex += 1\r
+                    StringTableSize += len(VariableNameStructure.replace(',',' ').split())\r
+                VariableHeadStringIndex = 0\r
+                for Index in range(Dict['STRING_TABLE_VALUE'].index(VariableNameStructure)):\r
+                    VariableHeadStringIndex += Dict['STRING_TABLE_LENGTH'][Index]\r
+                VariableHeadList.append(VariableHeadStringIndex)\r
                         \r
                 VariableHeadStringIndex = VariableHeadList[SkuIdIndex - 2]\r
                 # store VariableGuid to GuidTable and get the VariableHeadGuidIndex\r
@@ -1411,9 +1422,6 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
             Dict['SIZE_TABLE_CURRENT_LENGTH'].append(VoidStarTypeCurrSize)\r
         \r
         \r
-        SkuIndexTableTmp[0] = len(SkuIndexTableTmp) - 1\r
-        if len(Pcd.SkuInfoList) > 1:\r
-            Dict['SKU_INDEX_VALUE'].append(SkuIndexTableTmp)            \r
 \r
         if 'PCD_TYPE_HII' in Pcd.TokenTypeList:\r
             Dict['VARIABLE_HEAD_CNAME_DECL'].append(CName)\r
@@ -1666,11 +1674,10 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
                 \r
         AutoGenC.Append(gPcdDatabaseAutoGenC.Replace(Dict))\r
     \r
-    if Platform.Platform.VarCheckFlag:\r
-        dest = os.path.join(Platform.BuildDir, 'FV')\r
-        VarCheckTab.dump(dest, Phase)\r
+\r
+#     print Phase\r
     Buffer = BuildExDataBase(Dict)\r
-    return AutoGenH, AutoGenC, Buffer\r
+    return AutoGenH, AutoGenC, Buffer,VarCheckTab\r
 \r
 def GetOrderedDynamicPcdList(DynamicPcdList, PcdTokenNumberList):\r
     ReorderedDyPcdList = [None for i in range(len(DynamicPcdList))]\r
index 98e1a4c..7ee3979 100644 (file)
@@ -115,6 +115,9 @@ class VariableMgr(object):
 \r
         var_data = self.process_variable_data()\r
 \r
+        if not var_data:\r
+            return []\r
+\r
         pcds_default_data = var_data.get(("DEFAULT","STANDARD"))\r
         NvStoreDataBuffer = ""\r
         var_data_offset = collections.OrderedDict()\r
@@ -129,6 +132,11 @@ class VariableMgr(object):
             else:\r
                 var_attr_value = 0x07\r
 \r
+#             print "default var_name_buffer"\r
+#             print self.format_data(var_name_buffer)\r
+#             print "default var_buffer"\r
+#             print self.format_data(default_data)\r
+\r
             DataBuffer = self.AlignData(var_name_buffer + default_data)\r
 \r
             data_size = len(DataBuffer)\r
@@ -143,6 +151,8 @@ class VariableMgr(object):
 \r
         nv_default_part = self.AlignData(self.PACK_DEFAULT_DATA(0, 0, self.unpack_data(variable_storage_header_buffer+NvStoreDataBuffer)))\r
 \r
+#         print "default whole data \n",self.format_data(nv_default_part)\r
+\r
         data_delta_structure_buffer = ""\r
         for skuname,defaultstore in var_data:\r
             if (skuname,defaultstore) == ("DEFAULT","STANDARD"):\r
@@ -156,6 +166,9 @@ class VariableMgr(object):
                 delta_data_set.extend(delta_data)\r
 \r
             data_delta_structure_buffer += self.AlignData(self.PACK_DELTA_DATA(skuname,defaultstore,delta_data_set))\r
+#             print "delta data"\r
+#             print delta_data_set\r
+#             print self.format_data(self.AlignData(self.PACK_DELTA_DATA(skuname,defaultstore,delta_data_set)))\r
 \r
         return self.format_data(nv_default_part + data_delta_structure_buffer)\r
 \r
@@ -171,6 +184,8 @@ class VariableMgr(object):
         return final_data\r
 \r
     def calculate_delta(self, default, theother):\r
+#         print "default data \n", default\r
+#         print "other data \n",theother\r
         if len(default) - len(theother) != 0:\r
             EdkLogger.error("build", FORMAT_INVALID, 'The variable data length is not the same for the same PCD.')\r
         data_delta = []\r
@@ -182,11 +197,13 @@ class VariableMgr(object):
     def dump(self):\r
 \r
         default_var_bin = self.new_process_varinfo()\r
-        value_str = "{"\r
-        default_var_bin_strip = [ data.strip("""'""") for data in default_var_bin]\r
-        value_str += ",".join(default_var_bin_strip)\r
-        value_str += "}"\r
-        return value_str\r
+        if default_var_bin:\r
+            value_str = "{"\r
+            default_var_bin_strip = [ data.strip("""'""") for data in default_var_bin]\r
+            value_str += ",".join(default_var_bin_strip)\r
+            value_str += "}"\r
+            return value_str\r
+        return ""\r
 \r
     def PACK_VARIABLE_STORE_HEADER(self,size):\r
         #Signature: gEfiVariableGuid\r
index d3e5f9f..27779c5 100644 (file)
@@ -85,6 +85,7 @@ WARNING_AS_ERROR = 0xF006
 MIGRATION_ERROR = 0xF010\r
 PCD_VALIDATION_INFO_ERROR = 0xF011\r
 PCD_VARIABLE_ATTRIBUTES_ERROR = 0xF012\r
+PCD_VARIABLE_INFO_ERROR = 0xF016\r
 PCD_VARIABLE_ATTRIBUTES_CONFLICT_ERROR = 0xF013\r
 PCD_STRUCTURE_PCD_INVALID_FIELD_ERROR = 0xF014\r
 PCD_STRUCTURE_PCD_ERROR = 0xF015\r
index 8b9eed8..2ff8516 100644 (file)
@@ -2111,7 +2111,10 @@ class DefaultStore():
     def GetMin(self,DefaultSIdList):\r
         if not DefaultSIdList:\r
             return "STANDARD"\r
-        minid = min({storeid for storeid, storename in self.DefaultStores.values() if storename in DefaultSIdList}  )\r
+        storeidset = {storeid for storeid, storename in self.DefaultStores.values() if storename in DefaultSIdList}\r
+        if not storeidset:\r
+            return ""\r
+        minid = min(storeidset )\r
         for sid,name in self.DefaultStores.values():\r
             if sid == minid:\r
                 return name\r
index d45fb4c..56161ef 100644 (file)
@@ -102,8 +102,9 @@ class VpdInfoFile:
             if Vpd.MaxDatumSize == None or Vpd.MaxDatumSize == "":\r
                 Vpd.MaxDatumSize = VpdInfoFile._MAX_SIZE_TYPE[Vpd.DatumType]\r
         else:\r
-            EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,  \r
-                            "Invalid DatumType %s for VPD PCD %s.%s" % (Vpd.DatumType, Vpd.TokenSpaceGuidCName, Vpd.TokenCName))\r
+            if Vpd.MaxDatumSize <= 0:\r
+                EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,\r
+                                "Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))\r
             \r
         if Vpd not in self._VpdArray.keys():\r
             #\r
index 5b5dbb6..d2114fe 100644 (file)
@@ -598,7 +598,7 @@ class DscBuildData(PlatformBuildClassObject):
                 if not IsValidWord(Record[1]):\r
                     EdkLogger.error('build', FORMAT_INVALID, "The format of the Sku ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'",\r
                                     File=self.MetaFile, Line=Record[-1])\r
-                self._SkuIds[Record[1]] = (Record[0],Record[1],Record[2])\r
+                self._SkuIds[Record[1].upper()] = (Record[0], Record[1].upper(), Record[2].upper())\r
             if 'DEFAULT' not in self._SkuIds:\r
                 self._SkuIds['DEFAULT'] = ("0","DEFAULT","DEFAULT")\r
             if 'COMMON' not in self._SkuIds:\r
@@ -617,7 +617,7 @@ class DscBuildData(PlatformBuildClassObject):
                 if Record[1] in [None, '']:\r
                     EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID name',\r
                                     File=self.MetaFile, Line=Record[-1])\r
-                self.DefaultStores[Record[1]] = (self.ToInt(Record[0]),Record[1])\r
+                self.DefaultStores[Record[1].upper()] = (self.ToInt(Record[0]),Record[1].upper())\r
             if TAB_DEFAULT_STORES_DEFAULT not in self.DefaultStores:\r
                 self.DefaultStores[TAB_DEFAULT_STORES_DEFAULT] = (0,TAB_DEFAULT_STORES_DEFAULT)\r
         return self.DefaultStores\r
@@ -794,7 +794,7 @@ class DscBuildData(PlatformBuildClassObject):
 \r
     def _ValidatePcd(self, PcdCName, TokenSpaceGuid, Setting, PcdType, LineNo):\r
         if self._DecPcds == None:\r
-            self._DecPcds = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain)\r
+\r
             FdfInfList = []\r
             if GlobalData.gFdfParser:\r
                 FdfInfList = GlobalData.gFdfParser.Profile.InfList\r
@@ -806,13 +806,11 @@ class DscBuildData(PlatformBuildClassObject):
                     continue\r
                 ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]\r
                 PkgSet.update(ModuleData.Packages)\r
-            DecPcds = {}\r
-            for Pkg in PkgSet:\r
-                for Pcd in Pkg.Pcds:\r
-                    DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
-            self._DecPcds.update(DecPcds)\r
 \r
-        if (PcdCName, TokenSpaceGuid) not in self._DecPcds and "." in TokenSpaceGuid and (TokenSpaceGuid.split(".")[1], TokenSpaceGuid.split(".")[0]) not in self._DecPcds:\r
+            self._DecPcds = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain,PkgSet)\r
+\r
+\r
+        if (PcdCName, TokenSpaceGuid) not in self._DecPcds:\r
             EdkLogger.error('build', PARSER_ERROR,\r
                             "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TokenSpaceGuid, PcdCName, self._Arch),\r
                             File=self.MetaFile, Line=LineNo)\r
@@ -861,6 +859,18 @@ class DscBuildData(PlatformBuildClassObject):
                 pcd = Pcds[pcdname]\r
                 Pcds[pcdname].SkuInfoList = {skuid:pcd.SkuInfoList[skuid] for skuid in pcd.SkuInfoList if skuid in available_sku}\r
         return Pcds\r
+    def CompleteHiiPcdsDefaultStores(self,Pcds):\r
+        HiiPcd = [Pcds[pcd] for pcd in Pcds if Pcds[pcd].Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]]\r
+        DefaultStoreMgr = DefaultStore(self.DefaultStores)\r
+        for pcd in HiiPcd:\r
+            for skuid in pcd.SkuInfoList:\r
+                skuobj = pcd.SkuInfoList.get(skuid)\r
+                if "STANDARD" not in skuobj.DefaultStoreDict:\r
+                    PcdDefaultStoreSet = set([defaultstorename  for defaultstorename in skuobj.DefaultStoreDict])\r
+                    mindefaultstorename = DefaultStoreMgr.GetMin(PcdDefaultStoreSet)\r
+                    skuobj.DefaultStoreDict['STANDARD'] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename])\r
+        return Pcds\r
+\r
     ## Retrieve all PCD settings in platform\r
     def _GetPcds(self):\r
         if self._Pcds == None:\r
@@ -877,6 +887,7 @@ class DscBuildData(PlatformBuildClassObject):
 \r
             self._Pcds = self.CompletePcdValues(self._Pcds)\r
             self._Pcds = self.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST, self._Pcds)\r
+            self._Pcds = self.CompleteHiiPcdsDefaultStores(self._Pcds)\r
             self._Pcds = self._FilterPcdBySkuUsage(self._Pcds)\r
         return self._Pcds\r
 \r
@@ -938,28 +949,6 @@ class DscBuildData(PlatformBuildClassObject):
 \r
         return structure_pcd_data\r
 \r
-    def CompleteStructurePcdValue(self,pcdset):\r
-        skuset = set([item[3] for item in pcdset])\r
-        pcddatamap = {(item[0],item[1],item[2],item[3]):item for item in pcdset}\r
-        FieldSet = {}\r
-        for item in pcdset:\r
-            if (item[0],item[1]) not in FieldSet:\r
-                FieldSet[(item[0],item[1])] = set()\r
-            FieldSet[(item[0],item[1])].add(item[2])\r
-        completeset = []\r
-        for tockenspacename,pcdname, in FieldSet:\r
-            for field in FieldSet[(tockenspacename,pcdname)]:\r
-                for skuid in skuset:\r
-                    nextskuid = skuid\r
-                    while (tockenspacename,pcdname,field,nextskuid) not in pcddatamap:\r
-                        nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
-                        if nextskuid == "DEFAULT":\r
-                            break\r
-                    if (tockenspacename,pcdname,field,nextskuid) not in pcddatamap:\r
-                        continue\r
-                    item = pcddatamap[tockenspacename,pcdname,field,nextskuid]\r
-                    completeset.append((tockenspacename,pcdname,field,skuid, item[4],item[5], item[6]))\r
-        return completeset\r
     def UpdateStructuredPcds(self, TypeList, AllPcds):\r
         Pcds = AllPcds\r
         DefaultStoreMgr = DefaultStore(self.DefaultStores)\r
@@ -969,16 +958,19 @@ class DscBuildData(PlatformBuildClassObject):
         S_PcdSet = []\r
         # Find out all possible PCD candidates for self._Arch\r
         RecordList = []\r
+\r
         for Type in TypeList:\r
             RecordList.extend(self._RawData[Type, self._Arch])\r
 \r
         for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, default_store, Dummy4,Dummy5 in RecordList:\r
+            SkuName = SkuName.upper()\r
+            default_store = default_store.upper()\r
+            SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName\r
             if SkuName not in SkuIds:\r
                 continue\r
-            SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName\r
+\r
             if SkuName in SkuIds and "." in TokenSpaceGuid:\r
                 S_PcdSet.append(( TokenSpaceGuid.split(".")[0],TokenSpaceGuid.split(".")[1], PcdCName,SkuName, default_store,Dummy5, AnalyzePcdExpression(Setting)[0]))\r
-        S_PcdSet = self.CompleteStructurePcdValue(S_PcdSet)\r
 \r
         # handle pcd value override\r
         StrPcdSet = self.GetStructurePcdInfo(S_PcdSet)\r
@@ -997,6 +989,10 @@ class DscBuildData(PlatformBuildClassObject):
                     if str_pcd_data[3] in SkuIds:\r
                         str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else str_pcd_data[3],'STANDARD' if str_pcd_data[4] == 'COMMON' else str_pcd_data[4], self.MetaFile.File,LineNo=str_pcd_data[5])\r
                 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str\r
+            else:\r
+                EdkLogger.error('build', PARSER_ERROR,\r
+                            "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),\r
+                            File=self.MetaFile,Line = StrPcdSet[str_pcd][0][5])\r
         # Add the Structure PCD that only defined in DEC, don't have override in DSC file\r
         for Pcd in self._DecPcds:\r
             if type (self._DecPcds[Pcd]) is StructurePcd:\r
@@ -1022,22 +1018,33 @@ class DscBuildData(PlatformBuildClassObject):
             if stru_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
                 for skuid in SkuIds:\r
                     nextskuid = skuid\r
+                    NoDefault = False\r
                     if skuid not in stru_pcd.SkuOverrideValues:\r
                         while nextskuid not in stru_pcd.SkuOverrideValues:\r
+                            if nextskuid == "DEFAULT":\r
+                                NoDefault = True\r
+                                break\r
                             nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
                         stru_pcd.SkuOverrideValues[skuid] = {}\r
-                    PcdDefaultStoreSet = set([defaultstorename  for defaultstorename in stru_pcd.SkuOverrideValues[skuid]])\r
+                    if NoDefault:\r
+                        continue\r
+                    PcdDefaultStoreSet = set([defaultstorename  for defaultstorename in stru_pcd.SkuOverrideValues[nextskuid]])\r
                     mindefaultstorename = DefaultStoreMgr.GetMin(PcdDefaultStoreSet)\r
+\r
                     for defaultstoreid in DefaultStores:\r
                         if defaultstoreid not in stru_pcd.SkuOverrideValues[skuid]:\r
-                            stru_pcd.SkuOverrideValues[skuid][defaultstoreid] = stru_pcd.SkuOverrideValues[nextskuid][mindefaultstorename]\r
+                            stru_pcd.SkuOverrideValues[skuid][defaultstoreid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid][mindefaultstorename])\r
             for skuid in SkuIds:\r
                 if skuid in stru_pcd.SkuOverrideValues:\r
                     continue\r
                 nextskuid = self.SkuIdMgr.GetNextSkuId(skuid)\r
+                NoDefault = False\r
                 while nextskuid not in stru_pcd.SkuOverrideValues:\r
+                    if nextskuid == "DEFAULT":\r
+                        NoDefault = True\r
+                        break\r
                     nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
-                stru_pcd.SkuOverrideValues[skuid] = stru_pcd.SkuOverrideValues[nextskuid]\r
+                stru_pcd.SkuOverrideValues[skuid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid]) if not NoDefault else copy.deepcopy({defaultstorename: stru_pcd.DefaultValues for defaultstorename in DefaultStores})\r
         Str_Pcd_Values = self.GenerateByteArrayValue(S_pcd_set)\r
         if Str_Pcd_Values:\r
             for (skuname,StoreName,PcdGuid,PcdName,PcdValue) in Str_Pcd_Values:\r
@@ -1070,8 +1077,7 @@ class DscBuildData(PlatformBuildClassObject):
                 str_pcd_obj.SkuInfoList[self.SkuIdMgr.SystemSkuId].HiiDefaultValue = str_pcd_obj.SkuInfoList[self.SkuIdMgr.SystemSkuId].DefaultStoreDict[mindefaultstorename]\r
 \r
             for str_pcd_obj in S_pcd_set.values():\r
-                if not str_pcd_obj.OverrideValues:\r
-                    continue\r
+\r
                 str_pcd_obj.MaxDatumSize = self.GetStructurePcdMaxSize(str_pcd_obj)\r
                 Pcds[str_pcd_obj.TokenCName, str_pcd_obj.TokenSpaceGuidCName] = str_pcd_obj\r
 \r
@@ -1089,7 +1095,7 @@ class DscBuildData(PlatformBuildClassObject):
         # tdict is a special dict kind of type, used for selecting correct\r
         # PCD settings for certain ARCH\r
         #\r
-\r
+        AvailableSkuIdSet = copy.copy(self.SkuIds)\r
 \r
         PcdDict = tdict(True, 3)\r
         PcdSet = set()\r
@@ -1097,6 +1103,11 @@ class DscBuildData(PlatformBuildClassObject):
         RecordList = self._RawData[Type, self._Arch]\r
         PcdValueDict = sdict()\r
         for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4,Dummy5 in RecordList:\r
+            SkuName = SkuName.upper()\r
+            SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName\r
+            if SkuName not in AvailableSkuIdSet:\r
+                EdkLogger.error('build ', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
+                                            File=self.MetaFile, Line=Dummy5)\r
             if SkuName in (self.SkuIdMgr.SystemSkuId, 'DEFAULT', 'COMMON'):\r
                 if "." not in TokenSpaceGuid:\r
                     PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy4))\r
@@ -1516,8 +1527,11 @@ class DscBuildData(PlatformBuildClassObject):
 \r
 \r
         for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4,Dummy5 in RecordList:\r
+            SkuName = SkuName.upper()\r
+            SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName\r
             if SkuName not in AvailableSkuIdSet:\r
-                continue\r
+                EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
+                                            File=self.MetaFile, Line=Dummy5)\r
             if "." not in TokenSpaceGuid:\r
                 PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4))\r
             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
@@ -1590,7 +1604,7 @@ class DscBuildData(PlatformBuildClassObject):
     def CompletePcdValues(self,PcdSet):\r
         Pcds = {}\r
         DefaultStoreObj = DefaultStore(self._GetDefaultStores())\r
-        SkuIds = set([skuid for pcdobj in PcdSet.values() for skuid in pcdobj.SkuInfoList.keys()])\r
+        SkuIds = set([(skuid,skuobj.SkuId) for pcdobj in PcdSet.values() for skuid,skuobj in pcdobj.SkuInfoList.items()])\r
         DefaultStores = set([storename for pcdobj in PcdSet.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict.keys()])\r
         for PcdCName, TokenSpaceGuid in PcdSet:\r
             PcdObj = PcdSet[(PcdCName, TokenSpaceGuid)]\r
@@ -1609,14 +1623,16 @@ class DscBuildData(PlatformBuildClassObject):
                     mindefaultstorename = DefaultStoreObj.GetMin(set([defaultstorename  for defaultstorename in skuobj.DefaultStoreDict]))\r
                     for defaultstorename in DefaultStores:\r
                         if defaultstorename not in skuobj.DefaultStoreDict:\r
-                            skuobj.DefaultStoreDict[defaultstorename] = skuobj.DefaultStoreDict[mindefaultstorename]\r
+                            skuobj.DefaultStoreDict[defaultstorename] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename])\r
                     skuobj.HiiDefaultValue = skuobj.DefaultStoreDict[mindefaultstorename]\r
-            for skuid in SkuIds:\r
-                if skuid not in PcdObj.SkuInfoList:\r
-                    nextskuid = self.SkuIdMgr.GetNextSkuId(skuid)\r
+            for skuname,skuid in SkuIds:\r
+                if skuname not in PcdObj.SkuInfoList:\r
+                    nextskuid = self.SkuIdMgr.GetNextSkuId(skuname)\r
                     while nextskuid not in PcdObj.SkuInfoList:\r
                         nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
-                    PcdObj.SkuInfoList[skuid] = PcdObj.SkuInfoList[nextskuid]\r
+                    PcdObj.SkuInfoList[skuname] = copy.deepcopy(PcdObj.SkuInfoList[nextskuid])\r
+                    PcdObj.SkuInfoList[skuname].SkuId = skuid\r
+                    PcdObj.SkuInfoList[skuname].SkuIdName = skuname\r
             if PcdType in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
                 PcdObj.DefaultValue = PcdObj.SkuInfoList.values()[0].HiiDefaultValue if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE else PcdObj.SkuInfoList["DEFAULT"].HiiDefaultValue\r
             Pcds[PcdCName, TokenSpaceGuid]= PcdObj\r
@@ -1641,12 +1657,20 @@ class DscBuildData(PlatformBuildClassObject):
         RecordList = self._RawData[Type, self._Arch]\r
         # Find out all possible PCD candidates for self._Arch\r
         AvailableSkuIdSet = copy.copy(self.SkuIds)\r
+        DefaultStoresDefine = self._GetDefaultStores()\r
 \r
         for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, DefaultStore, Dummy4,Dummy5 in RecordList:\r
+            SkuName = SkuName.upper()\r
+            SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName\r
+            DefaultStore = DefaultStore.upper()\r
             if DefaultStore == "COMMON":\r
                 DefaultStore = "STANDARD"\r
             if SkuName not in AvailableSkuIdSet:\r
-                continue\r
+                EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
+                                            File=self.MetaFile, Line=Dummy5)\r
+            if DefaultStore not in DefaultStoresDefine:\r
+                EdkLogger.error('build', PARAMETER_INVALID, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore,\r
+                                            File=self.MetaFile, Line=Dummy5)\r
             if "." not in TokenSpaceGuid:\r
                 PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy4))\r
             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid,DefaultStore] = Setting\r
@@ -1729,7 +1753,7 @@ class DscBuildData(PlatformBuildClassObject):
                     sku.HiiDefaultValue = pcdDecObject.DefaultValue\r
             if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():\r
                 valuefromDec = pcdDecObject.DefaultValue\r
-                SkuInfo = SkuInfoClass('DEFAULT', '0', SkuInfoObj.VariableName, SkuInfoObj.VariableGuid, SkuInfoObj.VariableOffset, valuefromDec)\r
+                SkuInfo = SkuInfoClass('DEFAULT', '0', SkuInfoObj.VariableName, SkuInfoObj.VariableGuid, SkuInfoObj.VariableOffset, valuefromDec,VariableAttribute=SkuInfoObj.VariableAttribute,DefaultStore={DefaultStore:valuefromDec})\r
                 pcd.SkuInfoList['DEFAULT'] = SkuInfo\r
             elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
                 pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']\r
@@ -1747,7 +1771,7 @@ class DscBuildData(PlatformBuildClassObject):
             else:\r
                 MaxSize = 0\r
             if pcdDecObject.DatumType == 'VOID*':\r
-                for (skuname, skuobj) in pcd.SkuInfoList.items():\r
+                for (_, skuobj) in pcd.SkuInfoList.items():\r
                     datalen = 0\r
                     if skuobj.HiiDefaultValue.startswith("L"):\r
                         datalen = (len(skuobj.HiiDefaultValue) - 3 + 1) * 2\r
@@ -1758,9 +1782,23 @@ class DscBuildData(PlatformBuildClassObject):
                     if datalen > MaxSize:\r
                         MaxSize = datalen\r
                 pcd.MaxDatumSize = str(MaxSize)\r
+        rt, invalidhii = self.CheckVariableNameAssignment(Pcds)\r
+        if not rt:\r
+            invalidpcd = ",".join(invalidhii)\r
+            EdkLogger.error('build', PCD_VARIABLE_INFO_ERROR, Message='The same HII PCD must map to the same EFI variable for all SKUs', File=self.MetaFile, ExtraData=invalidpcd)\r
         return Pcds\r
 \r
-\r
+    def CheckVariableNameAssignment(self,Pcds):\r
+        invalidhii = []\r
+        for pcdname in Pcds:\r
+            pcd = Pcds[pcdname]\r
+            varnameset = set([sku.VariableName for (skuid,sku) in pcd.SkuInfoList.items()])\r
+            if len(varnameset) > 1:\r
+                invalidhii.append(".".join((pcdname[1],pcdname[0])))\r
+        if len(invalidhii):\r
+            return False,invalidhii\r
+        else:\r
+            return True, []\r
     ## Retrieve dynamic VPD PCD settings\r
     #\r
     #   @param  Type    PCD type\r
@@ -1783,8 +1821,11 @@ class DscBuildData(PlatformBuildClassObject):
         AvailableSkuIdSet = copy.copy(self.SkuIds)\r
 \r
         for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4,Dummy5 in RecordList:\r
+            SkuName = SkuName.upper()\r
+            SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName\r
             if SkuName not in AvailableSkuIdSet:\r
-                continue\r
+                EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,\r
+                                            File=self.MetaFile, Line=Dummy5)\r
             if "." not in TokenSpaceGuid:\r
                 PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4))\r
             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
index 67aa530..c289b9d 100644 (file)
@@ -44,8 +44,10 @@ def GetPackageList(Platform, BuildDatabase, Arch, Target, Toolchain):
 #  @param Toolchain: Current toolchain\r
 #  @retval: A dictionary contains instances of PcdClassObject with key (PcdCName, TokenSpaceGuid)\r
 #\r
-def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain):\r
+def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain,additionalPkgs):\r
     PkgList = GetPackageList(Platform, BuildDatabase, Arch, Target, Toolchain)\r
+    PkgList = set(PkgList)\r
+    PkgList |= additionalPkgs\r
     DecPcds = {}\r
     for Pkg in PkgList:\r
         for Pcd in Pkg.Pcds:\r