From nobody Tue Feb 10 11:15:35 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 1524868495472286.8309395503561; Fri, 27 Apr 2018 15:34:55 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9D935207DF452; Fri, 27 Apr 2018 15:33:09 -0700 (PDT) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 D5B582034C8D3 for ; Fri, 27 Apr 2018 15:33:02 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Apr 2018 15:33:02 -0700 Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga002.jf.intel.com with ESMTP; 27 Apr 2018 15:33:01 -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.115; helo=mga14.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="54252874" From: Jaben Carsey To: edk2-devel@lists.01.org Date: Fri, 27 Apr 2018 15:32:48 -0700 Message-Id: X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [edk2] [PATCH v1 34/42] BaseTools: standardize GUID and pack size 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" currently GUID packing and pack size determination is spread throughout the code. This introduces a shared function and dict and routes all code paths through them. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/AutoGen/GenPcdDb.py | 45 ++--------= ------- BaseTools/Source/Python/AutoGen/GenVar.py | 25 +--------- BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py | 28 ++--------- BaseTools/Source/Python/Common/DataType.py | 11 +++++ BaseTools/Source/Python/Common/Misc.py | 51 ++++++++++= ++++------ BaseTools/Source/Python/GenFds/Fv.py | 22 ++------- BaseTools/Source/Python/build/BuildReport.py | 2 +- 7 files changed, 61 insertions(+), 123 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenPcdDb.py b/BaseTools/Source= /Python/AutoGen/GenPcdDb.py index ef6647a15302..94f430897b98 100644 --- a/BaseTools/Source/Python/AutoGen/GenPcdDb.py +++ b/BaseTools/Source/Python/AutoGen/GenPcdDb.py @@ -21,7 +21,6 @@ from Common.VariableAttributes import VariableAttributes import copy from struct import unpack from Common.DataType import * -from GenVar import PackGUID =20 DATABASE_VERSION =3D 7 =20 @@ -290,22 +289,7 @@ class DbItemList: GuidString =3D GuidStructureStringToGuidString(GuidStructureVa= lue) return PackGUID(GuidString.split('-')) =20 - if self.ItemSize =3D=3D 8: - PackStr =3D "=3DQ" - elif self.ItemSize =3D=3D 4: - PackStr =3D "=3DL" - elif self.ItemSize =3D=3D 2: - PackStr =3D "=3DH" - elif self.ItemSize =3D=3D 1: - PackStr =3D "=3DB" - elif self.ItemSize =3D=3D 0: - PackStr =3D "=3DB" - elif self.ItemSize =3D=3D 16: - # pack Guid - PackStr =3D '' - else: - # should not reach here - assert(False) + PackStr =3D PACK_CODE_BY_SIZE[self.ItemSize] =20 Buffer =3D '' for Datas in self.RawDataList: @@ -379,18 +363,7 @@ class DbComItemList (DbItemList): return self.ListSize =20 def PackData(self): - if self.ItemSize =3D=3D 8: - PackStr =3D "=3DQ" - elif self.ItemSize =3D=3D 4: - PackStr =3D "=3DL" - elif self.ItemSize =3D=3D 2: - PackStr =3D "=3DH" - elif self.ItemSize =3D=3D 1: - PackStr =3D "=3DB" - elif self.ItemSize =3D=3D 0: - PackStr =3D "=3DB" - else: - assert(False) + PackStr =3D PACK_CODE_BY_SIZE[self.ItemSize] =20 Buffer =3D '' for DataList in self.RawDataList: @@ -818,19 +791,7 @@ def BuildExDataBase(Dict): # Construct the database buffer Guid =3D "{0x3c7d193c, 0x682c, 0x4c14, 0xa6, 0x8f, 0x55, 0x2d, 0xea, 0= x4f, 0x43, 0x7e}" Guid =3D StringArrayToList(Guid) - Buffer =3D pack('=3DLHHBBBBBBBB', - Guid[0], - Guid[1], - Guid[2], - Guid[3], - Guid[4], - Guid[5], - Guid[6], - Guid[7], - Guid[8], - Guid[9], - Guid[10], - ) + Buffer =3D PackByteFormatGUID(Guid) =20 b =3D pack("=3DL", DATABASE_VERSION) Buffer +=3D b diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py b/BaseTools/Source/P= ython/AutoGen/GenVar.py index e3595bb62315..bc750bd72f37 100644 --- a/BaseTools/Source/Python/AutoGen/GenVar.py +++ b/BaseTools/Source/Python/AutoGen/GenVar.py @@ -26,22 +26,6 @@ var_info =3D collections.namedtuple("uefi_var", "pcdinde= x,pcdname,defaultstoragena NvStorageHeaderSize =3D 28 VariableHeaderSize =3D 32 =20 -def PackGUID(Guid): - GuidBuffer =3D pack('=3DLHHBBBBBBBB', - int(Guid[0], 16), - int(Guid[1], 16), - int(Guid[2], 16), - int(Guid[3][-4:-2], 16), - int(Guid[3][-2:], 16), - int(Guid[4][-12:-10], 16), - int(Guid[4][-10:-8], 16), - int(Guid[4][-8:-6], 16), - int(Guid[4][-6:-4], 16), - int(Guid[4][-4:-2], 16), - int(Guid[4][-2:], 16) - ) - return GuidBuffer - class VariableMgr(object): def __init__(self, DefaultStoreMap,SkuIdMap): self.VarInfo =3D [] @@ -87,14 +71,7 @@ class VariableMgr(object): data_type =3D item.data_type value_list =3D item.default_value.strip("{").strip("}").sp= lit(",") if data_type in DataType.TAB_PCD_NUMERIC_TYPES: - if data_type =3D=3D ["BOOLEAN", DataType.TAB_UINT8]: - data_flag =3D "=3DB" - elif data_type =3D=3D DataType.TAB_UINT16: - data_flag =3D "=3DH" - elif data_type =3D=3D DataType.TAB_UINT32: - data_flag =3D "=3DL" - elif data_type =3D=3D DataType.TAB_UINT64: - data_flag =3D "=3DQ" + data_flag =3D PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_typ= e]] data =3D value_list[0] value_list =3D [] for data_byte in pack(data_flag,int(data,16) if data.u= pper().startswith('0X') else int(data)): diff --git a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py b/B= aseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py index f5b1574e4440..3ca113c25669 100644 --- a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py +++ b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py @@ -34,13 +34,6 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object): self.var_check_info.append(var_check_tab) =20 def dump(self, dest, Phase): - - FormatMap =3D {} - FormatMap[1] =3D "=3DB" - FormatMap[2] =3D "=3DH" - FormatMap[4] =3D "=3DL" - FormatMap[8] =3D "=3DQ" - if not os.path.isabs(dest): return if not os.path.exists(dest): @@ -106,19 +99,8 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object): realLength +=3D 4 =20 Guid =3D var_check_tab.Guid - b =3D pack('=3DLHHBBBBBBBB', - Guid[0], - Guid[1], - Guid[2], - Guid[3], - Guid[4], - Guid[5], - Guid[6], - Guid[7], - Guid[8], - Guid[9], - Guid[10], - ) + b =3D PackByteFormatGUID(Guid) + =20 Buffer +=3D b realLength +=3D 16 =20 @@ -156,14 +138,14 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object): realLength +=3D 1 for v_data in item.data: if type(v_data) in (int, long): - b =3D pack(FormatMap[item.StorageWidth], v_data) + b =3D pack(PACK_CODE_BY_SIZE[item.StorageWidth], v= _data) Buffer +=3D b realLength +=3D item.StorageWidth else: - b =3D pack(FormatMap[item.StorageWidth], v_data[0]) + b =3D pack(PACK_CODE_BY_SIZE[item.StorageWidth], v= _data[0]) Buffer +=3D b realLength +=3D item.StorageWidth - b =3D pack(FormatMap[item.StorageWidth], v_data[1]) + b =3D pack(PACK_CODE_BY_SIZE[item.StorageWidth], v= _data[1]) Buffer +=3D b realLength +=3D item.StorageWidth =20 diff --git a/BaseTools/Source/Python/Common/DataType.py b/BaseTools/Source/= Python/Common/DataType.py index 48700ba82012..c3058d751470 100644 --- a/BaseTools/Source/Python/Common/DataType.py +++ b/BaseTools/Source/Python/Common/DataType.py @@ -530,3 +530,14 @@ SECTIONS_HAVE_ITEM_AFTER_ARCH =3D [TAB_LIBRARY_CLASSES= .upper(), TAB_DEPEX.upper(), PCDS_DYNAMICEX_HII.upper(), TAB_BUILD_OPTIONS.upper(), TAB_INCLUDES.upper()] + +# +# pack codes as used in PcdDb and elsewhere +# +PACK_PATTERN_GUID =3D '=3DLHHBBBBBBBB' +PACK_CODE_BY_SIZE =3D {8:'=3DQ', + 4:'=3DL', + 2:'=3DH', + 1:'=3DB', + 0:'=3DB', + 16:""} diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/Common/Misc.py index f6ebaa60e23f..86c69808422c 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -2087,20 +2087,7 @@ class SkuClass(): # Pack a registry format GUID # def PackRegistryFormatGuid(Guid): - Guid =3D Guid.split('-') - return pack('=3DLHHBBBBBBBB', - int(Guid[0], 16), - int(Guid[1], 16), - int(Guid[2], 16), - int(Guid[3][-4:-2], 16), - int(Guid[3][-2:], 16), - int(Guid[4][-12:-10], 16), - int(Guid[4][-10:-8], 16), - int(Guid[4][-8:-6], 16), - int(Guid[4][-6:-4], 16), - int(Guid[4][-4:-2], 16), - int(Guid[4][-2:], 16) - ) + return PackGUID(Guid.split('-')) =20 ## Get the integer value from string like "14U" or integer like 2 # @@ -2126,6 +2113,42 @@ def GetIntegerValue(Input): else: return int(String) =20 +# +# Pack a GUID (registry format) list into a buffer and return it +# +def PackGUID(Guid): + return pack(PACK_PATTERN_GUID, + int(Guid[0], 16), + int(Guid[1], 16), + int(Guid[2], 16), + int(Guid[3][-4:-2], 16), + int(Guid[3][-2:], 16), + int(Guid[4][-12:-10], 16), + int(Guid[4][-10:-8], 16), + int(Guid[4][-8:-6], 16), + int(Guid[4][-6:-4], 16), + int(Guid[4][-4:-2], 16), + int(Guid[4][-2:], 16) + ) + +# +# Pack a GUID (byte) list into a buffer and return it +# +def PackByteFormatGUID(Guid): + return pack(PACK_PATTERN_GUID, + Guid[0], + Guid[1], + Guid[2], + Guid[3], + Guid[4], + Guid[5], + Guid[6], + Guid[7], + Guid[8], + Guid[9], + Guid[10], + ) + ## # # This acts like the main() function for the script, unless it is 'import'= ed into another diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python= /GenFds/Fv.py index 2e57c5e92365..40e8bcd5aa72 100644 --- a/BaseTools/Source/Python/GenFds/Fv.py +++ b/BaseTools/Source/Python/GenFds/Fv.py @@ -26,7 +26,7 @@ import FfsFileStatement from GenFdsGlobalVariable import GenFdsGlobalVariable from GenFds import GenFds from CommonDataClass.FdfClass import FvClassObject -from Common.Misc import SaveFileOnChange +from Common.Misc import SaveFileOnChange, PackGUID from Common.LongFilePathSupport import CopyLongFilePath from Common.LongFilePathSupport import OpenLongFilePath as open =20 @@ -366,10 +366,7 @@ class FV (FvClassObject): # FV UI name # Buffer +=3D (pack('HH', (FvUiLen + 16 + 4), 0x0002) - + pack('=3DLHHBBBBBBBB', int(Guid[0], 16), int(= Guid[1], 16), int(Guid[2], 16), - int(Guid[3][-4:-2], 16), int(Guid[3][-2:= ], 16), int(Guid[4][-12:-10], 16), - int(Guid[4][-10:-8], 16), int(Guid[4][-8= :-6], 16), int(Guid[4][-6:-4], 16), - int(Guid[4][-4:-2], 16), int(Guid[4][-2:= ], 16)) + + PackGUID(Guid) + self.UiFvName) =20 for Index in range (0, len(self.FvExtEntryType)): @@ -403,20 +400,7 @@ class FV (FvClassObject): Buffer +=3D pack('B', int(ByteList[Index1], 16)) =20 Guid =3D self.FvNameGuid.split('-') - Buffer =3D pack('=3DLHHBBBBBBBBL', - int(Guid[0], 16), - int(Guid[1], 16), - int(Guid[2], 16), - int(Guid[3][-4:-2], 16), - int(Guid[3][-2:], 16), - int(Guid[4][-12:-10], 16), - int(Guid[4][-10:-8], 16), - int(Guid[4][-8:-6], 16), - int(Guid[4][-6:-4], 16), - int(Guid[4][-4:-2], 16), - int(Guid[4][-2:], 16), - TotalSize - ) + Buffer + Buffer =3D PackGUID(Guid) + pack('=3DL', TotalSize) + Buffer =20 # # Generate FV extension header file if the total size is not z= ero diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Sourc= e/Python/build/BuildReport.py index bcbe6f89b48b..505bbcd29e0a 100644 --- a/BaseTools/Source/Python/build/BuildReport.py +++ b/BaseTools/Source/Python/build/BuildReport.py @@ -313,7 +313,7 @@ class DepexParser(object): Statement =3D gOpCodeList[struct.unpack("B", OpCode)[0]] if Statement in ["BEFORE", "AFTER", "PUSH"]: GuidValue =3D "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02= X%02X" % \ - struct.unpack("=3DLHHBBBBBBBB", DepexFile.read= (16)) + struct.unpack(PACK_PATTERN_GUID, DepexFile.rea= d(16)) GuidString =3D self._GuidDb.get(GuidValue, GuidValue) Statement =3D "%s %s" % (Statement, GuidString) DepexStatement.append(Statement) --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel