From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 69389223E0B80 for ; Thu, 22 Mar 2018 22:51:20 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Mar 2018 22:57:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,348,1517904000"; d="scan'208";a="39896373" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.129]) by fmsmga004.fm.intel.com with ESMTP; 22 Mar 2018 22:57:52 -0700 From: Yonghong Zhu To: edk2-devel@lists.01.org Date: Fri, 23 Mar 2018 13:57:49 +0800 Message-Id: <1521784669-11164-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [Patch] BaseTools: Fix size override issue for Void* Patchable pcd X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Mar 2018 05:51:20 -0000 when multiple driver link same library, and the drivers override the pcd to different value in the DSC component section, it cause the pcd size incorrect. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yonghong Zhu --- BaseTools/Source/Python/AutoGen/GenC.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py index 0509a9f..a895067 100644 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -912,10 +912,11 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd): TokenCName = PcdItem[0] break PcdTokenName = '_PCD_TOKEN_' + TokenCName PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE' PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName + PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName if Pcd.PcdValueFromComm: Pcd.DefaultValue = Pcd.PcdValueFromComm @@ -1159,10 +1160,11 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd): if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize)) AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName)) AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName) AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize)) + AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (PatchPcdMaxSizeVariable,Pcd.MaxDatumSize)) elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value)) AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName)) AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array)) AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName)) @@ -1210,10 +1212,11 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd): break PcdTokenName = '_PCD_TOKEN_' + TokenCName FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE' PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName + PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName if Pcd.PcdValueFromComm: Pcd.DefaultValue = Pcd.PcdValueFromComm # @@ -1316,26 +1319,27 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd): AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName)) else: AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName)) AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName)) if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE: + GetModeMaxSizeName = '_PCD_GET_MODE_MAXSIZE' + '_' + TokenCName PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName if DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']: - ArraySize = int(Pcd.MaxDatumSize, 0) - if Pcd.DefaultValue[0] == 'L': - ArraySize = ArraySize / 2 - Array = '[%d]' % ArraySize - DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L'] + if DatumType == 'VOID*' and Array == '[]': + DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L'] + else: + DatumType = 'UINT8' AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array)) else: AutoGenH.Append('extern volatile %s %s%s;\n' % (DatumType, PcdVariableName, Array)) AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName)) PcdDataSize = GetPcdSize(Pcd) if Pcd.DatumType not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']: - AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, TokenCName, TokenCName)) - AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, TokenCName, TokenCName)) - AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize)) + AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable)) + AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable)) + AutoGenH.Append('#define %s %s\n' % (GetModeMaxSizeName,PatchPcdMaxSizeVariable)) + AutoGenH.Append('extern const UINTN %s; \n' % PatchPcdMaxSizeVariable) else: AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName)) AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName)) AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize)) -- 2.6.1.windows.1