BaseTools: Generate correct VPD PCD value to store the default setting
authorLiming Gao <liming.gao@intel.com>
Fri, 22 Dec 2017 12:23:21 +0000 (20:23 +0800)
committerLiming Gao <liming.gao@intel.com>
Mon, 25 Dec 2017 03:05:51 +0000 (11:05 +0800)
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/BPDG/GenVpd.py

index 28e575d..67de173 100644 (file)
@@ -1393,29 +1393,29 @@ class PlatformAutoGen(AutoGen):
         return VariableInfo\r
 \r
     def UpdateNVStoreMaxSize(self,OrgVpdFile):\r
-        VpdMapFilePath = os.path.join(self.BuildDir, "FV", "%s.map" % self.Platform.VpdToolGuid)\r
-#         VpdFile = VpdInfoFile.VpdInfoFile()\r
-        PcdNvStoreDfBuffer = [item for item in self._DynamicPcdList if item.TokenCName == "PcdNvStoreDefaultValueBuffer" and item.TokenSpaceGuidCName == "gEfiMdeModulePkgTokenSpaceGuid"]\r
-\r
-        if PcdNvStoreDfBuffer:\r
-            if os.path.exists(VpdMapFilePath):\r
-                OrgVpdFile.Read(VpdMapFilePath)\r
-                PcdItems = OrgVpdFile.GetOffset(PcdNvStoreDfBuffer[0])\r
-                NvStoreOffset = PcdItems[0].strip() if PcdItems else 0\r
-            else:\r
-                EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
+        if self.VariableInfo:\r
+            VpdMapFilePath = os.path.join(self.BuildDir, "FV", "%s.map" % self.Platform.VpdToolGuid)\r
+            PcdNvStoreDfBuffer = [item for item in self._DynamicPcdList if item.TokenCName == "PcdNvStoreDefaultValueBuffer" and item.TokenSpaceGuidCName == "gEfiMdeModulePkgTokenSpaceGuid"]\r
+\r
+            if PcdNvStoreDfBuffer:\r
+                if os.path.exists(VpdMapFilePath):\r
+                    OrgVpdFile.Read(VpdMapFilePath)\r
+                    PcdItems = OrgVpdFile.GetOffset(PcdNvStoreDfBuffer[0])\r
+                    NvStoreOffset = PcdItems[0].strip() if PcdItems else '0'\r
+                else:\r
+                    EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
 \r
-            NvStoreOffset = int(NvStoreOffset,16) if NvStoreOffset.upper().startswith("0X") else int(NvStoreOffset)\r
-            maxsize = self.VariableInfo.VpdRegionSize  - NvStoreOffset\r
-            var_data = self.VariableInfo.PatchNVStoreDefaultMaxSize(maxsize)\r
-            default_skuobj = PcdNvStoreDfBuffer[0].SkuInfoList.get("DEFAULT")\r
+                NvStoreOffset = int(NvStoreOffset,16) if NvStoreOffset.upper().startswith("0X") else int(NvStoreOffset)\r
+                default_skuobj = PcdNvStoreDfBuffer[0].SkuInfoList.get("DEFAULT")\r
+                maxsize = self.VariableInfo.VpdRegionSize  - NvStoreOffset if self.VariableInfo.VpdRegionSize else len(default_skuobj.DefaultValue.split(","))\r
+                var_data = self.VariableInfo.PatchNVStoreDefaultMaxSize(maxsize)\r
 \r
-            if var_data and default_skuobj:\r
-                default_skuobj.DefaultValue = var_data\r
-                PcdNvStoreDfBuffer[0].DefaultValue = var_data\r
-                PcdNvStoreDfBuffer[0].SkuInfoList.clear()\r
-                PcdNvStoreDfBuffer[0].SkuInfoList['DEFAULT'] = default_skuobj\r
-                PcdNvStoreDfBuffer[0].MaxDatumSize = str(len(default_skuobj.DefaultValue.split(",")))\r
+                if var_data and default_skuobj:\r
+                    default_skuobj.DefaultValue = var_data\r
+                    PcdNvStoreDfBuffer[0].DefaultValue = var_data\r
+                    PcdNvStoreDfBuffer[0].SkuInfoList.clear()\r
+                    PcdNvStoreDfBuffer[0].SkuInfoList['DEFAULT'] = default_skuobj\r
+                    PcdNvStoreDfBuffer[0].MaxDatumSize = str(len(default_skuobj.DefaultValue.split(",")))\r
 \r
         return OrgVpdFile\r
 \r
@@ -1613,9 +1613,9 @@ class PlatformAutoGen(AutoGen):
         #\r
         # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.\r
         #\r
-        UnicodePcdArray = []\r
-        HiiPcdArray     = []\r
-        OtherPcdArray   = []\r
+        UnicodePcdArray = set()\r
+        HiiPcdArray     = set()\r
+        OtherPcdArray   = set()\r
         VpdPcdDict      = {}\r
         VpdFile               = VpdInfoFile.VpdInfoFile()\r
         NeedProcessVpdMapFile = False\r
@@ -1775,12 +1775,12 @@ class PlatformAutoGen(AutoGen):
                                 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
                                     NeedProcessVpdMapFile = True \r
                             if DscPcdEntry.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
-                                UnicodePcdArray.append(DscPcdEntry)\r
+                                UnicodePcdArray.add(DscPcdEntry)\r
                             elif len(Sku.VariableName) > 0:\r
-                                HiiPcdArray.append(DscPcdEntry)\r
+                                HiiPcdArray.add(DscPcdEntry)\r
                             else:\r
-                                OtherPcdArray.append(DscPcdEntry)\r
-                                \r
+                                OtherPcdArray.add(DscPcdEntry)\r
+\r
                                 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
                             VpdSkuMap[DscPcd] = SkuValueMap\r
             if (self.Platform.FlashDefinition == None or self.Platform.FlashDefinition == '') and \\r
@@ -1826,16 +1826,16 @@ class PlatformAutoGen(AutoGen):
                 PcdValue = Sku.DefaultValue\r
                 if Pcd.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
                     # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
-                    UnicodePcdArray.append(Pcd)\r
+                    UnicodePcdArray.add(Pcd)\r
                 elif len(Sku.VariableName) > 0:\r
                     # if found HII type PCD then insert to right of UnicodeIndex\r
-                    HiiPcdArray.append(Pcd)\r
+                    HiiPcdArray.add(Pcd)\r
                 else:\r
-                    OtherPcdArray.append(Pcd)\r
+                    OtherPcdArray.add(Pcd)\r
             del self._DynamicPcdList[:]\r
-        self._DynamicPcdList.extend(UnicodePcdArray)\r
-        self._DynamicPcdList.extend(HiiPcdArray)\r
-        self._DynamicPcdList.extend(OtherPcdArray)\r
+        self._DynamicPcdList.extend(list(UnicodePcdArray))\r
+        self._DynamicPcdList.extend(list(HiiPcdArray))\r
+        self._DynamicPcdList.extend(list(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
index 4ff4647..9861e7d 100644 (file)
@@ -503,6 +503,14 @@ class GenVPD :
         #\r
         self.PcdUnknownOffsetList.sort(lambda x, y: cmp(x.PcdBinSize, y.PcdBinSize))\r
 \r
+        index =0\r
+        for pcd in self.PcdUnknownOffsetList:\r
+            index += 1\r
+            if pcd.PcdCName == ".".join(("gEfiMdeModulePkgTokenSpaceGuid","PcdNvStoreDefaultValueBuffer")):\r
+                if index != len(self.PcdUnknownOffsetList):\r
+                    for i in range(len(self.PcdUnknownOffsetList) - index):\r
+                        self.PcdUnknownOffsetList[index+i -1 ] , self.PcdUnknownOffsetList[index+i] = self.PcdUnknownOffsetList[index+i] , self.PcdUnknownOffsetList[index+i -1]\r
+\r
         #\r
         # Process all Offset value are "*"\r
         #\r