From nobody Tue Feb 10 13:21:50 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1524868446942676.6499485596006; Fri, 27 Apr 2018 15:34:06 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id BF337203B9274; Fri, 27 Apr 2018 15:33:07 -0700 (PDT) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2E85C2034C8D4 for ; Fri, 27 Apr 2018 15:33:02 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Apr 2018 15:33:01 -0700 Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga002.jf.intel.com with ESMTP; 27 Apr 2018 15:32:59 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,336,1520924400"; d="scan'208";a="54252823" From: Jaben Carsey To: edk2-devel@lists.01.org Date: Fri, 27 Apr 2018 15:32:32 -0700 Message-Id: <83ae42f0dd824c7d13678fe465f628b03257b2bd.1524868034.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [edk2] [PATCH v1 18/42] BaseTools: move PCD size calculation functions to PcdClassObject X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" move both GetPcdMaxSize and GetPcdSize to the PcdClassObject. fix MAX_SIZE_TYPE to have int values Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/AutoGen/GenC.py | 37 ++++------= ---------- BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py | 2 +- BaseTools/Source/Python/Common/DataType.py | 2 +- BaseTools/Source/Python/Common/VpdInfoFile.py | 2 +- BaseTools/Source/Python/Workspace/BuildClassObject.py | 30 ++++++++++= ++++++ BaseTools/Source/Python/Workspace/DscBuildData.py | 19 +--------- 6 files changed, 40 insertions(+), 52 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Pyt= hon/AutoGen/GenC.py index 73d7699ad01b..4e7e3d90be64 100644 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -868,31 +868,6 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH): % (RealTokenCName, RealTokenCName, Rea= lTokenCName, RealTokenCName)) TokenCNameList.add(TokenCName) =20 -def GetPcdSize(Pcd): - if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES: - Value =3D Pcd.DefaultValue - if Value in [None, '']: - return 1 - elif Value[0] =3D=3D 'L': - return (len(Value) - 2) * 2 - elif Value[0] =3D=3D '{': - return len(Value.split(',')) - else: - return len(Value) - 1 - if Pcd.DatumType =3D=3D TAB_UINT64: - return 8 - if Pcd.DatumType =3D=3D TAB_UINT32: - return 4 - if Pcd.DatumType =3D=3D TAB_UINT16: - return 2 - if Pcd.DatumType =3D=3D TAB_UINT8: - return 1 - if Pcd.DatumType =3D=3D 'BOOLEAN': - return 1 - else: - return Pcd.MaxDatumSize - - ## Create code for module PCDs # # @param Info The ModuleAutoGen object @@ -1115,7 +1090,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd= ): "The maximum size of VOID* type PCD '%= s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, T= okenCName), ExtraData=3D"[%s]" % str(Info)) else: - ArraySize =3D GetPcdSize(Pcd) + ArraySize =3D Pcd.GetPcdSize() if Unicode: ArraySize =3D ArraySize / 2 Value =3D NewValue + '0 }' @@ -1155,7 +1130,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd= ): AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVari= ableName, Array)) AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdV= ariableName)) =20 - PcdDataSize =3D GetPcdSize(Pcd) + PcdDataSize =3D Pcd.GetPcdSize() if Pcd.Type =3D=3D TAB_PCDS_FIXED_AT_BUILD: AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, = PcdDataSize)) AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,Fix= PcdSizeTokenName)) @@ -1172,14 +1147,14 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, P= cd): AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pc= d.DatumType, PcdVariableName, Array)) AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, Pcd= VariableName)) =20 - PcdDataSize =3D GetPcdSize(Pcd) + PcdDataSize =3D Pcd.GetPcdSize() AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pc= dDataSize)) =20 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPc= dSizeVariableName)) AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableNa= me) AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s =3D %s= ;\n' % (PatchPcdSizeVariableName,PcdDataSize)) else: - PcdDataSize =3D GetPcdSize(Pcd) + PcdDataSize =3D Pcd.GetPcdSize() AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdD= ataSize)) AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdS= izeTokenName)) =20 @@ -1338,7 +1313,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pc= d): else: AutoGenH.Append('extern volatile %s %s%s;\n' % (DatumType, P= cdVariableName, Array)) AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeNa= me, Type, TokenCName)) - PcdDataSize =3D GetPcdSize(Pcd) + PcdDataSize =3D Pcd.GetPcdSize() if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES: AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcd= SetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffe= r))\n' % (SetModeName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSiz= eVariable)) AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcd= SetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buff= er))\n' % (SetModeStatusName, TokenCName, PatchPcdSizeVariableName, PatchPc= dMaxSizeVariable)) @@ -1372,7 +1347,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pc= d): AutoGenH.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCNam= e, Type, PcdVariableName)) else: AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName,= Pcd.DefaultValue)) - PcdDataSize =3D GetPcdSize(Pcd) + PcdDataSize =3D Pcd.GetPcdSize() if PcdItemType =3D=3D TAB_PCDS_FIXED_AT_BUILD: if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES: if ConstFixedPcd: diff --git a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py b/B= aseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py index dd78dc520075..2f8f4fac23f8 100644 --- a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py +++ b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py @@ -253,7 +253,7 @@ class VAR_CHECK_PCD_VALID_OBJ(object): =20 def updateStorageWidth(self): try: - self.StorageWidth =3D int(MAX_SIZE_TYPE[self.PcdDataType]) + self.StorageWidth =3D MAX_SIZE_TYPE[self.PcdDataType] except: self.StorageWidth =3D 0 self.ValidData =3D False diff --git a/BaseTools/Source/Python/Common/DataType.py b/BaseTools/Source/= Python/Common/DataType.py index 20f31ce4b72f..8af94354620c 100644 --- a/BaseTools/Source/Python/Common/DataType.py +++ b/BaseTools/Source/Python/Common/DataType.py @@ -278,7 +278,7 @@ TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_LIST =3D [TAB_PCDS_= PATCHABLE_LOAD_FIX_ADDRESS_ ## The mapping dictionary from datum type to its maximum number. MAX_VAL_TYPE =3D {"BOOLEAN":0x01, TAB_UINT8:0xFF, TAB_UINT16:0xFFFF, TAB_U= INT32:0xFFFFFFFF, TAB_UINT64:0xFFFFFFFFFFFFFFFF} ## The mapping dictionary from datum type to size string. -MAX_SIZE_TYPE =3D {"BOOLEAN":"1", TAB_UINT8:"1", TAB_UINT16:"2", TAB_UINT3= 2:"4", TAB_UINT64:"8"} +MAX_SIZE_TYPE =3D {"BOOLEAN":1, TAB_UINT8:1, TAB_UINT16:2, TAB_UINT32:4, T= AB_UINT64:8} =20 TAB_DEPEX =3D 'Depex' TAB_DEPEX_COMMON =3D TAB_DEPEX + TAB_SPLIT + TAB_ARCH_COMMON diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Sour= ce/Python/Common/VpdInfoFile.py index 155693740f12..32895deb5d0c 100644 --- a/BaseTools/Source/Python/Common/VpdInfoFile.py +++ b/BaseTools/Source/Python/Common/VpdInfoFile.py @@ -99,7 +99,7 @@ class VpdInfoFile: EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_IN= VALID,=20 "Invalid max datum size for VPD PCD %s.%s"= % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName)) elif Vpd.DatumType in TAB_PCD_NUMERIC_TYPES:=20 - if Vpd.MaxDatumSize is None or Vpd.MaxDatumSize =3D=3D "": + if not Vpd.MaxDatumSize: Vpd.MaxDatumSize =3D MAX_SIZE_TYPE[Vpd.DatumType] else: if Vpd.MaxDatumSize <=3D 0: diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTo= ols/Source/Python/Workspace/BuildClassObject.py index 258905e80f25..52725e968226 100644 --- a/BaseTools/Source/Python/Workspace/BuildClassObject.py +++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py @@ -72,6 +72,36 @@ class PcdClassObject(object): self.PcdValueFromComm =3D "" self.DefinitionPosition =3D ("","") =20 + ## Get the maximum number of bytes + def GetPcdMaxSize(self): + if self.DatumType in TAB_PCD_NUMERIC_TYPES: + return MAX_SIZE_TYPE[self.DatumType] + + MaxSize =3D int(self.MaxDatumSize,10) if self.MaxDatumSize else 0 + if self.PcdValueFromComm: + if self.PcdValueFromComm.startswith("{") and self.PcdValueFrom= Comm.endswith("}"): + return max([len(self.PcdValueFromComm.split(",")),MaxSize]) + elif self.PcdValueFromComm.startswith("\"") or self.PcdValueFr= omComm.startswith("\'"): + return max([len(self.PcdValueFromComm)-2+1,MaxSize]) + elif self.PcdValueFromComm.startswith("L\""): + return max([2*(len(self.PcdValueFromComm)-3+1),MaxSize]) + else: + return max([len(self.PcdValueFromComm),MaxSize]) + return MaxSize + + ## Get the number of bytes + def GetPcdSize(self): + if self.DatumType in TAB_PCD_NUMERIC_TYPES: + return MAX_SIZE_TYPE[self.DatumType] + if not self.DefaultValue: + return 1 + elif self.DefaultValue[0] =3D=3D 'L': + return (len(self.DefaultValue) - 2) * 2 + elif self.DefaultValue[0] =3D=3D '{': + return len(self.DefaultValue.split(',')) + else: + return len(self.DefaultValue) - 1 + ## Convert the class to a string # # Convert each member of the class to string diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index 8ebac8957a1b..13a1ed886cc4 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -1535,23 +1535,6 @@ class DscBuildData(PlatformBuildClassObject): Result =3D Result + '"' return Result =20 - @staticmethod - def GetPcdMaxSize(Pcd): - if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES: - return MAX_SIZE_TYPE[Pcd.DatumType] - - MaxSize =3D int(Pcd.MaxDatumSize,10) if Pcd.MaxDatumSize else 0 - if Pcd.PcdValueFromComm: - if Pcd.PcdValueFromComm.startswith("{") and Pcd.PcdValueFromCo= mm.endswith("}"): - return max([len(Pcd.PcdValueFromComm.split(",")),MaxSize]) - elif Pcd.PcdValueFromComm.startswith("\"") or Pcd.PcdValueFrom= Comm.startswith("\'"): - return max([len(Pcd.PcdValueFromComm)-2+1,MaxSize]) - elif Pcd.PcdValueFromComm.startswith("L\""): - return max([2*(len(Pcd.PcdValueFromComm)-3+1),MaxSize]) - else: - return max([len(Pcd.PcdValueFromComm),MaxSize]) - return MaxSize - def GenerateSizeFunction(self,Pcd): CApp =3D "// Default Value in Dec \n" CApp =3D CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.Toke= nSpaceGuidCName, Pcd.TokenCName) @@ -1634,7 +1617,7 @@ class DscBuildData(PlatformBuildClassObject): while '[' in FieldName: FieldName =3D FieldName.rsplit('[', 1)[0] CApp =3D CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d);= // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), Ar= rayIndex + 1, Pcd.PcdFieldValueFromComm[FieldName_ori][1], Pcd.PcdFieldValu= eFromComm[FieldName_ori][2], Pcd.PcdFieldValueFromComm[FieldName_ori][0]) - CApp =3D CApp + " *Size =3D (%d > *Size ? %d : *Size); // The Pcd= maxsize is %d \n" % (DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMa= xSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd)) + CApp =3D CApp + " *Size =3D (%d > *Size ? %d : *Size); // The Pcd= maxsize is %d \n" % (Pcd.GetPcdMaxSize(),Pcd.GetPcdMaxSize(),Pcd.GetPcdMax= Size()) CApp =3D CApp + "}\n" return CApp =20 --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel