X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FVpdInfoFile.py;h=b1baf06b9ccd40a4f86b14965b271df980afd7b3;hb=7da06eeede10fc8b908327b375bcdf36707ff7b5;hp=1a68e9bee1725c658ae9b533ef882e248ca9b5cd;hpb=1be2ed90a20618d71ddf34b8a07d038da0b36854;p=mirror_edk2.git
diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Source/Python/Common/VpdInfoFile.py
index 1a68e9bee1..b1baf06b9c 100644
--- a/BaseTools/Source/Python/Common/VpdInfoFile.py
+++ b/BaseTools/Source/Python/Common/VpdInfoFile.py
@@ -6,7 +6,7 @@
# is pointed by *_*_*_VPD_TOOL_GUID in conf/tools_def.txt
#
#
-# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -20,7 +20,9 @@ import re
import Common.EdkLogger as EdkLogger
import Common.BuildToolError as BuildToolError
import subprocess
+import Common.GlobalData as GlobalData
from Common.LongFilePathSupport import OpenLongFilePath as open
+from Common.Misc import SaveFileOnChange
FILE_COMMENT_TEMPLATE = \
"""
@@ -77,6 +79,7 @@ class VpdInfoFile:
# @see BuildClassObject.PcdClassObject
# Value : offset in different SKU such as [sku1_offset, sku2_offset]
self._VpdArray = {}
+ self._VpdInfo = {}
## Add a VPD PCD collected from platform's autogen when building.
#
@@ -85,8 +88,8 @@ class VpdInfoFile:
#
# @param offset integer value for VPD's offset in specific SKU.
#
- def Add(self, Vpd, Offset):
- if (Vpd == None):
+ def Add(self, Vpd, skuname,Offset):
+ if (Vpd is None):
EdkLogger.error("VpdInfoFile", BuildToolError.ATTRIBUTE_UNKNOWN_ERROR, "Invalid VPD PCD entry.")
if not (Offset >= 0 or Offset == "*"):
@@ -97,22 +100,20 @@ class VpdInfoFile:
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,
"Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))
elif Vpd.DatumType in ["BOOLEAN", "UINT8", "UINT16", "UINT32", "UINT64"]:
- if Vpd.MaxDatumSize == None or Vpd.MaxDatumSize == "":
+ if Vpd.MaxDatumSize is None or Vpd.MaxDatumSize == "":
Vpd.MaxDatumSize = VpdInfoFile._MAX_SIZE_TYPE[Vpd.DatumType]
else:
- EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,
- "Invalid DatumType %s for VPD PCD %s.%s" % (Vpd.DatumType, Vpd.TokenSpaceGuidCName, Vpd.TokenCName))
+ if Vpd.MaxDatumSize <= 0:
+ EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,
+ "Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))
if Vpd not in self._VpdArray.keys():
#
# 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
@@ -121,37 +122,28 @@ class VpdInfoFile:
# If
# @param FilePath The given file path which would hold VPD information
def Write(self, FilePath):
- if not (FilePath != None or len(FilePath) != 0):
+ if not (FilePath is not None or len(FilePath) != 0):
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,
"Invalid parameter FilePath: %s." % FilePath)
- try:
- fd = open(FilePath, "w")
- except:
- EdkLogger.error("VpdInfoFile",
- BuildToolError.FILE_OPEN_FAILURE,
- "Fail to open file %s for written." % FilePath)
-
- try:
- # write file header
- fd.write(FILE_COMMENT_TEMPLATE)
- # write each of PCD in VPD type
- Pcds = self._VpdArray.keys()
- Pcds.sort()
- for Pcd in Pcds:
- i = 0
- for Offset in self._VpdArray[Pcd]:
- PcdValue = str(Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[i]].DefaultValue).strip()
- if PcdValue == "" :
- PcdValue = Pcd.DefaultValue
-
- fd.write("%s.%s|%s|%s|%s|%s \n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, str(Pcd.SkuInfoList.keys()[i]),str(Offset).strip(), str(Pcd.MaxDatumSize).strip(),PcdValue))
- i += 1
- except:
- EdkLogger.error("VpdInfoFile",
- BuildToolError.FILE_WRITE_FAILURE,
- "Fail to write file %s" % FilePath)
- fd.close()
+ Content = FILE_COMMENT_TEMPLATE
+ Pcds = self._VpdArray.keys()
+ Pcds.sort()
+ for Pcd in Pcds:
+ i = 0
+ PcdTokenCName = Pcd.TokenCName
+ for PcdItem in GlobalData.MixedPcd:
+ if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
+ PcdTokenCName = PcdItem[0]
+ 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, skuname,str(self._VpdArray[Pcd][skuname]).strip(), str(Pcd.MaxDatumSize).strip(),PcdValue)
+ i += 1
+
+ return SaveFileOnChange(FilePath, Content, False)
## Read an existing VPD PCD info file.
#
@@ -185,13 +177,20 @@ class VpdInfoFile:
Found = False
+ if (TokenSpaceName, PcdTokenName) not in self._VpdInfo:
+ self._VpdInfo[(TokenSpaceName, PcdTokenName)] = []
+ self._VpdInfo[(TokenSpaceName, PcdTokenName)].append((SkuId,Offset, Value))
for VpdObject in self._VpdArray.keys():
- for sku in VpdObject.SkuInfoList.keys():
- if VpdObject.TokenSpaceGuidCName == TokenSpaceName and VpdObject.TokenCName == PcdTokenName.strip() and sku == SkuId:
- if self._VpdArray[VpdObject][VpdObject.SkuInfoList.keys().index(sku)] == "*":
+ VpdObjectTokenCName = VpdObject.TokenCName
+ for PcdItem in GlobalData.MixedPcd:
+ if (VpdObject.TokenCName, VpdObject.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
+ VpdObjectTokenCName = PcdItem[0]
+ for sku in VpdObject.SkuInfoList.keys():
+ if VpdObject.TokenSpaceGuidCName == TokenSpaceName and VpdObjectTokenCName == PcdTokenName.strip() and sku == SkuId:
+ 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.")
@@ -219,6 +218,8 @@ class VpdInfoFile:
return None
return self._VpdArray[vpd]
+ def GetVpdInfo(self,(PcdTokenName,TokenSpaceName)):
+ return self._VpdInfo.get((TokenSpaceName, PcdTokenName))
## Call external BPDG tool to process VPD file
#
@@ -226,8 +227,8 @@ class VpdInfoFile:
# @param VpdFileName The string path name for VPD information guid.txt
#
def CallExtenalBPDGTool(ToolPath, VpdFileName):
- assert ToolPath != None, "Invalid parameter ToolPath"
- assert VpdFileName != None and os.path.exists(VpdFileName), "Invalid parameter VpdFileName"
+ assert ToolPath is not None, "Invalid parameter ToolPath"
+ assert VpdFileName is not None and os.path.exists(VpdFileName), "Invalid parameter VpdFileName"
OutputDir = os.path.dirname(VpdFileName)
FileName = os.path.basename(VpdFileName)
@@ -236,19 +237,20 @@ def CallExtenalBPDGTool(ToolPath, VpdFileName):
OutputBinFileName = os.path.join(OutputDir, "%s.bin" % BaseName)
try:
- PopenObject = subprocess.Popen([ToolPath,
+ PopenObject = subprocess.Popen(' '.join([ToolPath,
'-o', OutputBinFileName,
'-m', OutputMapFileName,
'-q',
'-f',
- VpdFileName],
+ VpdFileName]),
stdout=subprocess.PIPE,
- stderr= subprocess.PIPE)
+ stderr= subprocess.PIPE,
+ shell=True)
except Exception, X:
EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, ExtraData="%s" % (str(X)))
(out, error) = PopenObject.communicate()
print out
- while PopenObject.returncode == None :
+ while PopenObject.returncode is None :
PopenObject.wait()
if PopenObject.returncode != 0: