BaseTools: Generate correct VPD PCD value to store the default setting

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>
This commit is contained in:
Liming Gao
2017-12-22 20:23:21 +08:00
parent b23957242c
commit 0b6c5954e1
2 changed files with 41 additions and 33 deletions

View File

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

View File

@ -503,6 +503,14 @@ class GenVPD :
# #
self.PcdUnknownOffsetList.sort(lambda x, y: cmp(x.PcdBinSize, y.PcdBinSize)) self.PcdUnknownOffsetList.sort(lambda x, y: cmp(x.PcdBinSize, y.PcdBinSize))
index =0
for pcd in self.PcdUnknownOffsetList:
index += 1
if pcd.PcdCName == ".".join(("gEfiMdeModulePkgTokenSpaceGuid","PcdNvStoreDefaultValueBuffer")):
if index != len(self.PcdUnknownOffsetList):
for i in range(len(self.PcdUnknownOffsetList) - index):
self.PcdUnknownOffsetList[index+i -1 ] , self.PcdUnknownOffsetList[index+i] = self.PcdUnknownOffsetList[index+i] , self.PcdUnknownOffsetList[index+i -1]
# #
# Process all Offset value are "*" # Process all Offset value are "*"
# #