From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.14503.1621224262921841274 for ; Sun, 16 May 2021 21:04:23 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: tung.lun.loo@intel.com) IronPort-SDR: yV0CFknoaRSzpJPZWx++GmFp4vPt0yfCPRR+NkLeafCQ9+9H8mJ2RLhKayDd5EdiR8cUbHHSUo RhTfv3oj8mIg== X-IronPort-AV: E=McAfee;i="6200,9189,9986"; a="261614039" X-IronPort-AV: E=Sophos;i="5.82,306,1613462400"; d="scan'208";a="261614039" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2021 21:04:21 -0700 IronPort-SDR: HT/uVKfCYHRzB2C///FJaKCqH68WxiMnO+iWNq5859alYfMBRS6v1zf3gs3gXmHd65UfTDRBYn pobPizODwx9A== X-IronPort-AV: E=Sophos;i="5.82,306,1613462400"; d="scan'208";a="626285762" Received: from tunglunl-mobl1.gar.corp.intel.com ([10.215.163.77]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2021 21:04:19 -0700 From: "Tung Lun" To: devel@edk2.groups.io Cc: Loo Tung Lun , Maurice Ma , Nate DeSimone , Star Zeng , Chasel Chiu Subject: [PATCH v3] IntelFsp2Pkg: YAML script bug fix Date: Mon, 17 May 2021 12:04:13 +0800 Message-Id: <20210517040413.1025-1-tung.lun.loo@intel.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3395 This patch fixes the issue observed during BSF file to YAML file conversion. It also addresses the issue during multibyte array data conversion check, for example the data representation of 0xFFFF instead of 0xFF, 0xFF would be thrown exception "Array size is not proper" without this patch. Cc: Maurice Ma Cc: Nate DeSimone Cc: Star Zeng Cc: Chasel Chiu Signed-off-by: Loo Tung Lun --- IntelFsp2Pkg/Tools/FspDscBsf2Yaml.py | 11 +++++++++-- IntelFsp2Pkg/Tools/GenCfgOpt.py | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/IntelFsp2Pkg/Tools/FspDscBsf2Yaml.py b/IntelFsp2Pkg/Tools/FspD= scBsf2Yaml.py index cad9b60e73..d2ca7145ae 100644 --- a/IntelFsp2Pkg/Tools/FspDscBsf2Yaml.py +++ b/IntelFsp2Pkg/Tools/FspDscBsf2Yaml.py @@ -46,6 +46,13 @@ def Bytes2Val(Bytes): return reduce(lambda x, y: (x << 8) | y, Bytes[::-1])=0D =0D =0D +def Str2Bytes(Value, Blen):=0D + Result =3D bytearray(Value[1:-1], 'utf-8') # Excluding quotes=0D + if len(Result) < Blen:=0D + Result.extend(b'\x00' * (Blen - len(Result)))=0D + return Result=0D +=0D +=0D class CFspBsf2Dsc:=0D =0D def __init__(self, bsf_file):=0D @@ -108,7 +115,8 @@ class CFspBsf2Dsc: cfg_item['find'] =3D prefix=0D cfg_item['cname'] =3D 'Signature'=0D cfg_item['length'] =3D len(finds[0][1])=0D - cfg_item['value'] =3D '0x%X' % Bytes2Val(finds[0][1].encod= e('UTF-8'))=0D + str2byte =3D Str2Bytes("'" + finds[0][1] + "'", len(finds[= 0][1]))=0D + cfg_item['value'] =3D '0x%X' % Bytes2Val(str2byte)=0D cfg_list.append(dict(cfg_item))=0D cfg_item =3D dict(cfg_temp)=0D find_list.pop(0)=0D @@ -291,7 +299,6 @@ class CFspDsc2Yaml(): raise Exception('DSC variable creation error !')=0D else:=0D raise Exception('Unsupported file "%s" !' % file_name)=0D - gen_cfg_data.UpdateDefaultValue()=0D self.gen_cfg_data =3D gen_cfg_data=0D =0D def print_dsc_line(self):=0D diff --git a/IntelFsp2Pkg/Tools/GenCfgOpt.py b/IntelFsp2Pkg/Tools/GenCfgOpt= .py index 660824b740..714b2d8b1a 100644 --- a/IntelFsp2Pkg/Tools/GenCfgOpt.py +++ b/IntelFsp2Pkg/Tools/GenCfgOpt.py @@ -708,7 +708,8 @@ EndList for Page in PageList:=0D Page =3D Page.strip()=0D Match =3D re.match("(\w+):\"(.+)\"", Page)= =0D - self._CfgPageDict[Match.group(1)] =3D Matc= h.group(2)=0D + if Match !=3D None:=0D + self._CfgPageDict[Match.group(1)] =3D = Match.group(2)=0D =0D Match =3D re.match("(?:^|.+\s+)BLOCK:{NAME:\"(.+)\= "\s*,\s*VER:\"(.+)\"\s*}", Remaining)=0D if Match:=0D --=20 2.28.0.windows.1