X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=inline;f=BaseTools%2FSource%2FPython%2FCommon%2FVpdInfoFile.py;h=09b8196faf0743b5f604caab691b077ea1ad5ccb;hb=72443dd25014a8b6209895640af36dec33da51e0;hp=5f92fa5cdda6f6b970b183f0605a75c0d898691a;hpb=08dd311f5dc735c595d39faf2e6f7e2810bb79a9;p=mirror_edk2.git
diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Source/Python/Common/VpdInfoFile.py
index 5f92fa5cdd..09b8196faf 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, Intel Corporation. All rights reserved.
+# Copyright (c) 2010 - 2018, 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
@@ -15,11 +15,16 @@
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
-import os
+from __future__ import print_function
+import Common.LongFilePathOs as os
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
+from Common.DataType import *
FILE_COMMENT_TEMPLATE = \
"""
@@ -64,9 +69,7 @@ FILE_COMMENT_TEMPLATE = \
# ::= ["," ]*
#
class VpdInfoFile:
-
- ## The mapping dictionary from datum type to size string.
- _MAX_SIZE_TYPE = {"BOOLEAN":"1", "UINT8":"1", "UINT16":"2", "UINT32":"4", "UINT64":"8"}
+
_rVpdPcdLine = None
## Constructor
def __init__(self):
@@ -76,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.
#
@@ -84,34 +88,32 @@ 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 == "*"):
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID, "Invalid offset parameter: %s." % Offset)
- if Vpd.DatumType == "VOID*":
+ if Vpd.DatumType == TAB_VOID:
if Vpd.MaxDatumSize <= 0:
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 == "":
- Vpd.MaxDatumSize = VpdInfoFile._MAX_SIZE_TYPE[Vpd.DatumType]
+ elif Vpd.DatumType in TAB_PCD_NUMERIC_TYPES:
+ if not Vpd.MaxDatumSize:
+ Vpd.MaxDatumSize = 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 Vpd not in self._VpdArray:
#
# 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
@@ -120,33 +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
- for Pcd in self._VpdArray.keys():
- for Offset in self._VpdArray[Pcd]:
- PcdValue = str(Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]].DefaultValue).strip()
- if PcdValue == "" :
- PcdValue = Pcd.DefaultValue
-
- fd.write("%s.%s|%s|%s|%s \n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, str(Offset).strip(), str(Pcd.MaxDatumSize).strip(),PcdValue))
- 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.
#
@@ -172,21 +169,29 @@ class VpdInfoFile:
# the line must follow output format defined in BPDG spec.
#
try:
- PcdName, Offset, Size, Value = Line.split("#")[0].split("|")
+ PcdName, SkuId,Offset, Size, Value = Line.split("#")[0].split("|")
+ PcdName, SkuId,Offset, Size, Value = PcdName.strip(), SkuId.strip(),Offset.strip(), Size.strip(), Value.strip()
TokenSpaceName, PcdTokenName = PcdName.split(".")
except:
EdkLogger.error("BPDG", BuildToolError.PARSER_ERROR, "Fail to parse VPD information file %s" % FilePath)
Found = False
- for VpdObject in self._VpdArray.keys():
- if VpdObject.TokenSpaceGuidCName == TokenSpaceName and VpdObject.TokenCName == PcdTokenName.strip():
- if self._VpdArray[VpdObject][0] == "*":
- 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][0] = Offset
- Found = True
- break
+
+ if (TokenSpaceName, PcdTokenName) not in self._VpdInfo:
+ self._VpdInfo[(TokenSpaceName, PcdTokenName)] = []
+ self._VpdInfo[(TokenSpaceName, PcdTokenName)].append((SkuId,Offset, Value))
+ for VpdObject in self._VpdArray:
+ 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:
+ 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][sku] = Offset
+ Found = True
if not Found:
EdkLogger.error("BPDG", BuildToolError.PARSER_ERROR, "Can not find PCD defined in VPD guid file.")
@@ -213,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
#
@@ -220,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)
@@ -230,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)
- except Exception, X:
- EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, ExtraData="%s" % (str(X)))
+ stderr= subprocess.PIPE,
+ shell=True)
+ except Exception as X:
+ EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, ExtraData=str(X))
(out, error) = PopenObject.communicate()
- print out
- while PopenObject.returncode == None :
+ print(out)
+ while PopenObject.returncode is None :
PopenObject.wait()
if PopenObject.returncode != 0: