BaseTools: Fix VPD data optimization issue

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-19 16:26:16 +08:00
parent a09395932d
commit 8ac167890f
3 changed files with 29 additions and 16 deletions

View File

@ -1401,7 +1401,7 @@ class PlatformAutoGen(AutoGen):
if os.path.exists(VpdMapFilePath):
OrgVpdFile.Read(VpdMapFilePath)
PcdItems = OrgVpdFile.GetOffset(PcdNvStoreDfBuffer[0])
NvStoreOffset = PcdItems[0].strip() if PcdItems else '0'
NvStoreOffset = PcdItems.values()[0].strip() if PcdItems else '0'
else:
EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)
@ -1665,6 +1665,14 @@ class PlatformAutoGen(AutoGen):
PcdKey in VpdPcdDict:
Pcd = VpdPcdDict[PcdKey]
SkuValueMap = {}
DefaultSku = Pcd.SkuInfoList.get('DEFAULT')
if DefaultSku:
PcdValue = DefaultSku.DefaultValue
if PcdValue not in SkuValueMap:
SkuValueMap[PcdValue] = []
VpdFile.Add(Pcd, 'DEFAULT',DefaultSku.VpdOffset)
SkuValueMap[PcdValue].append(DefaultSku)
for (SkuName,Sku) in Pcd.SkuInfoList.items():
Sku.VpdOffset = Sku.VpdOffset.strip()
PcdValue = Sku.DefaultValue
@ -1691,7 +1699,7 @@ class PlatformAutoGen(AutoGen):
EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Alignment))
if PcdValue not in SkuValueMap:
SkuValueMap[PcdValue] = []
VpdFile.Add(Pcd, Sku.VpdOffset)
VpdFile.Add(Pcd, SkuName,Sku.VpdOffset)
SkuValueMap[PcdValue].append(Sku)
# if the offset of a VPD is *, then it need to be fixed up by third party tool.
if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":
@ -1720,6 +1728,13 @@ class PlatformAutoGen(AutoGen):
if not FoundFlag :
# just pick the a value to determine whether is unicode string type
SkuValueMap = {}
DefaultSku = DscPcdEntry.SkuInfoList.get('DEFAULT')
if DefaultSku:
PcdValue = DefaultSku.DefaultValue
if PcdValue not in SkuValueMap:
SkuValueMap[PcdValue] = []
VpdFile.Add(DscPcdEntry, 'DEFAULT',Sku.VpdOffset)
SkuValueMap[PcdValue].append(Sku)
for (SkuName,Sku) in DscPcdEntry.SkuInfoList.items():
Sku.VpdOffset = Sku.VpdOffset.strip()
@ -1770,7 +1785,7 @@ class PlatformAutoGen(AutoGen):
EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, Alignment))
if PcdValue not in SkuValueMap:
SkuValueMap[PcdValue] = []
VpdFile.Add(DscPcdEntry, Sku.VpdOffset)
VpdFile.Add(DscPcdEntry, SkuName,Sku.VpdOffset)
SkuValueMap[PcdValue].append(Sku)
if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":
NeedProcessVpdMapFile = True

View File

@ -88,7 +88,7 @@ class VpdInfoFile:
#
# @param offset integer value for VPD's offset in specific SKU.
#
def Add(self, Vpd, Offset):
def Add(self, Vpd, skuname,Offset):
if (Vpd == None):
EdkLogger.error("VpdInfoFile", BuildToolError.ATTRIBUTE_UNKNOWN_ERROR, "Invalid VPD PCD entry.")
@ -111,12 +111,9 @@ class VpdInfoFile:
#
# If there is no Vpd instance in dict, that imply this offset for a given SKU is a new one
#
self._VpdArray[Vpd] = [Offset]
else:
#
# If there is an offset for a specific SKU in dict, then append this offset for other sku to array.
#
self._VpdArray[Vpd].append(Offset)
self._VpdArray[Vpd] = {}
self._VpdArray[Vpd].update({skuname:Offset})
## Generate VPD PCD information into a text file
@ -138,12 +135,12 @@ class VpdInfoFile:
for PcdItem in GlobalData.MixedPcd:
if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
PcdTokenCName = PcdItem[0]
for Offset in self._VpdArray[Pcd]:
PcdValue = str(Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[i]].DefaultValue).strip()
for skuname in self._VpdArray[Pcd]:
PcdValue = str(Pcd.SkuInfoList[skuname].DefaultValue).strip()
if PcdValue == "" :
PcdValue = Pcd.DefaultValue
Content += "%s.%s|%s|%s|%s|%s \n" % (Pcd.TokenSpaceGuidCName, PcdTokenCName, str(Pcd.SkuInfoList.keys()[i]),str(Offset).strip(), str(Pcd.MaxDatumSize).strip(),PcdValue)
Content += "%s.%s|%s|%s|%s|%s \n" % (Pcd.TokenSpaceGuidCName, PcdTokenCName, skuname,str(self._VpdArray[Pcd][skuname]).strip(), str(Pcd.MaxDatumSize).strip(),PcdValue)
i += 1
return SaveFileOnChange(FilePath, Content, False)
@ -190,10 +187,10 @@ class VpdInfoFile:
VpdObjectTokenCName = PcdItem[0]
for sku in VpdObject.SkuInfoList.keys():
if VpdObject.TokenSpaceGuidCName == TokenSpaceName and VpdObjectTokenCName == PcdTokenName.strip() and sku == SkuId:
if self._VpdArray[VpdObject][VpdObject.SkuInfoList.keys().index(sku)] == "*":
if self._VpdArray[VpdObject][sku] == "*":
if Offset == "*":
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "The offset of %s has not been fixed up by third-party BPDG tool." % PcdName)
self._VpdArray[VpdObject][VpdObject.SkuInfoList.keys().index(sku)] = Offset
self._VpdArray[VpdObject][sku] = Offset
Found = True
if not Found:
EdkLogger.error("BPDG", BuildToolError.PARSER_ERROR, "Can not find PCD defined in VPD guid file.")

View File

@ -1653,6 +1653,7 @@ class DscBuildData(PlatformBuildClassObject):
Pcds = {}
DefaultStoreObj = DefaultStore(self._GetDefaultStores())
SkuIds = set([(skuid,skuobj.SkuId) for pcdobj in PcdSet.values() for skuid,skuobj in pcdobj.SkuInfoList.items()])
SkuIds = self.SkuIdMgr.AvailableSkuIdSet
DefaultStores = set([storename for pcdobj in PcdSet.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict.keys()])
for PcdCName, TokenSpaceGuid in PcdSet:
PcdObj = PcdSet[(PcdCName, TokenSpaceGuid)]
@ -1673,7 +1674,7 @@ class DscBuildData(PlatformBuildClassObject):
if defaultstorename not in skuobj.DefaultStoreDict:
skuobj.DefaultStoreDict[defaultstorename] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename])
skuobj.HiiDefaultValue = skuobj.DefaultStoreDict[mindefaultstorename]
for skuname,skuid in SkuIds:
for skuname,skuid in SkuIds.items():
if skuname not in PcdObj.SkuInfoList:
nextskuid = self.SkuIdMgr.GetNextSkuId(skuname)
while nextskuid not in PcdObj.SkuInfoList: