X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FVpdInfoFile.py;h=130d5c7e0cdec42cec504e98b62e834af1b881e1;hp=1a68e9bee1725c658ae9b533ef882e248ca9b5cd;hb=626bece451db2e2a19fa7696889ad4d4c441b16e;hpb=1be2ed90a20618d71ddf34b8a07d038da0b36854 diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Source/Python/Common/VpdInfoFile.py index 1a68e9bee1..130d5c7e0c 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. # @@ -100,8 +103,9 @@ class VpdInfoFile: if Vpd.MaxDatumSize == 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(): # @@ -124,34 +128,25 @@ class VpdInfoFile: if not (FilePath != 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 Offset in self._VpdArray[Pcd]: + PcdValue = str(Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[i]].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) + i += 1 + + return SaveFileOnChange(FilePath, Content, False) ## Read an existing VPD PCD info file. # @@ -185,9 +180,16 @@ 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: + 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][VpdObject.SkuInfoList.keys().index(sku)] == "*": if Offset == "*": EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "The offset of %s has not been fixed up by third-party BPDG tool." % PcdName) @@ -219,6 +221,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 # @@ -236,14 +240,15 @@ 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()