X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FVpdInfoFile.py;h=435b23f203a05b1a130e6f1df695fd5a7588432e;hp=0111744cc045cc6c1a344f24ac28d82494315348;hb=890d8ede6867dd43d96b5b04454f0b571938e3a3;hpb=e56468c072e0d53834787f4ad0e292b33cc6be08 diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Source/Python/Common/VpdInfoFile.py index 0111744cc0..435b23f203 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,41 +218,40 @@ class VpdInfoFile: return None return self._VpdArray[vpd] + def GetVpdInfo(self, arg): + (PcdTokenName, TokenSpaceName) = arg + return self._VpdInfo.get((TokenSpaceName, PcdTokenName)) ## Call external BPDG tool to process VPD file # # @param ToolPath The string path name for BPDG tool # @param VpdFileName The string path name for VPD information guid.txt # -def CallExtenalBPDGTool(ToolPath, VpdFilePath, VpdFileName): - assert ToolPath != None, "Invalid parameter ToolPath" - assert VpdFilePath != None and os.path.exists(VpdFilePath), "Invalid parameter VpdFileName" +def CallExtenalBPDGTool(ToolPath, 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(VpdFilePath) - if (VpdFileName == None or VpdFileName == "") : - FileName = os.path.basename(VpdFilePath) - BaseName, ext = os.path.splitext(FileName) - OutputMapFileName = os.path.join(OutputDir, "%s.map" % BaseName) - OutputBinFileName = os.path.join(OutputDir, "%s.bin" % BaseName) - else : - OutputMapFileName = os.path.join(OutputDir, "%s.map" % VpdFileName) - OutputBinFileName = os.path.join(OutputDir, "%s.bin" % VpdFileName) + OutputDir = os.path.dirname(VpdFileName) + FileName = os.path.basename(VpdFileName) + BaseName, ext = os.path.splitext(FileName) + OutputMapFileName = os.path.join(OutputDir, "%s.map" % BaseName) + OutputBinFileName = os.path.join(OutputDir, "%s.bin" % BaseName) try: - PopenObject = subprocess.Popen([ToolPath, + PopenObject = subprocess.Popen(' '.join([ToolPath, '-o', OutputBinFileName, '-m', OutputMapFileName, - '-s', + '-q', '-f', - '-v', - VpdFilePath], + 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: