From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web09.3338.1610596480760950147 for ; Wed, 13 Jan 2021 19:54:41 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=yYBbBXA+; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: bob.c.feng@intel.com) IronPort-SDR: cH3e42oWBRPA+wbVDsxmQvBwIVijAVVMNP8rfOLnDboYPvJPGuca4/feNd4MB3MWMYE1xxFkWh QYQDjGZziH5g== X-IronPort-AV: E=McAfee;i="6000,8403,9863"; a="165392577" X-IronPort-AV: E=Sophos;i="5.79,346,1602572400"; d="scan'208";a="165392577" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2021 19:54:38 -0800 IronPort-SDR: PDstuPkubCt7Pp8IeIj4oS81NYhsAUPavJl2MwPuXZVJhXVu15cxNOjNCdZpSKBkVMqipY/3DN 37qXP/FFDRVg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,346,1602572400"; d="scan'208";a="400770121" Received: from fmsmsx606.amr.corp.intel.com ([10.18.126.86]) by fmsmga002.fm.intel.com with ESMTP; 13 Jan 2021 19:54:38 -0800 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx606.amr.corp.intel.com (10.18.126.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 13 Jan 2021 19:54:38 -0800 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 13 Jan 2021 19:54:37 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 13 Jan 2021 19:54:37 -0800 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.168) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Wed, 13 Jan 2021 19:54:37 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NosXP1pW4S2PhgnTmx04z6lfzBO4PZSrCtfz62zFU9wV53fPhjBlBBnk6JlANeHhSRbl8ZloPjX1KTzhGWQ5Oc3KZbCkj/of+t2ZXmYT4enchLNAO2I4vlTuJYVK2eJbLl76/VXCsg1Ar0BTudxHJnvuYNX0Dr+M/+QyVwj72ZPSBC+bl/3DIPHzf9p7d+fMf3L7ilFWjR9MH6wVPrpVytkLvInXqV+8QUL2ncxDqcmjbvboOF/lPoYcqJkilMaO4zPzyrVNkuhKEoE0An4MCyldnyMtBQbm4VKt+iEywJE4fZBPa/rHo5CSf+Zg7o+LoyEZ+c50d1TV4YdAWfHvnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=In/81IwLNdrDXjmXJeiX9vpsA+sNIUezVY03G7JJfvk=; b=SmIwyH3nQMPGJppvjNiyyIH3QHRS3u/qBQeu5d0hPKzAlh/j1adVmQzSOazFdMg9wmIIGwYSYvKS1wNL2p02dJtIHMWnA4kkNGqUMl54OnQXstDOQ2J53ZIKNeZecRkY6pI/7Ztggcz5sUUChA9w2B/oij4yfkpbyURKzb7dPZCUBfR+W5ElcxhcrMdQf4TJdpTclN64H2ql5ECKEUGNqzIyfNw2ZLxCIwEtMEgykwrqHFjkRnaCJAD+WcR+LNfOF8MeLnbMF3mnJ1d1KRK+YtAmVfjXQY9bl/Cc3V5rHHjJxaAcbY7dpDQu9Hq/cD0UQ4Xc7sgLFsuAixpmDxC4qQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=In/81IwLNdrDXjmXJeiX9vpsA+sNIUezVY03G7JJfvk=; b=yYBbBXA+h9sIKztxKerI6yOqQVXSomHet7sJyHHV7UkNpJlh4liz4Og4LWhlVRY6utxqB02X7nVA26gLEZK4Qn3ByofL8orW/kUFPq/GWo59A+/Ou/zB+EkgQBFCCSLMOukhWjTD+Hmwo91wN6QYim3JElJ8UFxQLXCTZ8pTzmc= Received: from DM6PR11MB4073.namprd11.prod.outlook.com (2603:10b6:5:19f::22) by DM6PR11MB4156.namprd11.prod.outlook.com (2603:10b6:5:192::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10; Thu, 14 Jan 2021 03:54:36 +0000 Received: from DM6PR11MB4073.namprd11.prod.outlook.com ([fe80::845:55b:f6b3:aa0a]) by DM6PR11MB4073.namprd11.prod.outlook.com ([fe80::845:55b:f6b3:aa0a%6]) with mapi id 15.20.3742.012; Thu, 14 Jan 2021 03:54:36 +0000 From: "Bob Feng" To: "Chen, Christine" , "devel@edk2.groups.io" CC: Yunhua Feng , Liming Gao Subject: Re: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT algorithm of LibFindFvInFd Thread-Topic: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT algorithm of LibFindFvInFd Thread-Index: AQHWtjvqVleaJsx99EyekJ0aXgMTTaom0MbwgAAUo4A= Date: Thu, 14 Jan 2021 03:54:36 +0000 Message-ID: References: <20201109015725.1733-1-bob.c.feng@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.102.204.37] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c9c47327-a62f-4bbc-43c8-08d8b8401c46 x-ms-traffictypediagnostic: DM6PR11MB4156: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3276; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: TJTQerEAkNjAqnZuv+yifYqTyfpufttZkfYOb/iiqECZ930xGyH8I5vrbO83KkLSNej8HtN/hwNT5gz/QNbrg4aRyaZF6tCbIB0h5boecIUGrwJQbvYDKEvAbAxABwOv6QAjBhPYTvuyfe3r0U1vxpRt9GfY/Rs+v8HWA3t6zucc1Ti0wZmwnbON556Ifmx9wNBzR9qUoaNbkvx4yJ0CEDIqSpGTRSu6tLAfAP1qqngYc7z8d4tggNq0MSl4nRQgx+enBPSgpcvsDsnNYOYxQ88yi9qgir0juqUG6LRgHI5/sRV2iDjHQWAXFUwrvwSpg2weejLwwk2DqyJ1fjScWvh1hFSXfK380TgGPcb0xk8Y3LNE0sQl/r2af7kVAVfQjBRRHKR/eE4GMz2kzyX3p4u1XyBVT4kYdSd328VA9x6lF0RGPRYdC8g+Y/jUF6gDEHDuYVRSjVrSW5QBnLNq3Q== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4073.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(6029001)(4636009)(376002)(366004)(346002)(136003)(396003)(39860400002)(86362001)(66476007)(4326008)(26005)(186003)(7696005)(5660300002)(53546011)(8676002)(71200400001)(6506007)(8936002)(9686003)(33656002)(55016002)(2906002)(83380400001)(110136005)(966005)(66946007)(52536014)(478600001)(316002)(64756008)(66446008)(54906003)(76116006)(66556008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?K947joXJv5kBf/QwTvP0fYE0lWQRe0tVPw86ap5YDBQJCxB36lbgcX+W619o?= =?us-ascii?Q?CzkHcQAe0e4RB4LU2V5ZfHuC6CJVF+3X42W8E4b/j9hMdEF2ROanLy4D/xie?= =?us-ascii?Q?t4J8evQz+8DzMpfCV8YrNljVLUVwFJUOX4WXwDYYltS2+1nhewPEOxzJGiYD?= =?us-ascii?Q?diJxFzzqfyrxEMlZS9W4vZN6Riki0K3PGRmaXkX4g4csodeeDbSWpCfWSXbE?= =?us-ascii?Q?1qKmMgFq7woZLdeAtWvJxmeJ6h7VNe4wC/qvg8V5Thve32P+/VrKyQ5e/D3B?= =?us-ascii?Q?YP8NSS1tEd9XARPKj5BGsMbR/r5Lzi/2lgjH3gwo2zJgHb8QP1okYijuJENT?= =?us-ascii?Q?OwDqNyi3iDZQdZ9OGpbFHKy6yAKvsoSZXg/lFtgkXOW2FDHXOMpIcRl/xFhy?= =?us-ascii?Q?ltfORSx3tF6mNt2w5R7CvxUHGKsk2cCLHhHMI5jXC22oGKDzRbbj/dg9P+EV?= =?us-ascii?Q?yWEnZmBUxwgqN8eT19itjLtXscJ3j0+1rDcFr3mGrTFs6xxZVzhN1BDuAXJ3?= =?us-ascii?Q?UUWHOGWOI1t+R+cVBJj07gONG4IH5xbXz3fhR7t3kIPBg7WqScJjHsJCKSYe?= =?us-ascii?Q?GnGogq9kwNyUsjZmM3pWqoH1Fj3vCqEn3oafaxlvbo0EyM8ExinBZkwXRm1w?= =?us-ascii?Q?7u3hWGDEQc6/ftlFm876jL/xcsECkPkJ0zj7vnc6ql1sxuDPgVoiN5vEwPjh?= =?us-ascii?Q?blpmchBtKiHaBjVLJVLlBWlzZ0QaECDKsEMTFnxBzBm5b4jXlDsxwHVNGSqZ?= =?us-ascii?Q?Q/RukA0gDBkFClGkGm68gVp5oNY+AeLPgEu7UO6YvGn4RhnbuVuHeodS3e+S?= =?us-ascii?Q?nYILT+Y6eJoT8NSLmUS7r8KwFkB0mf0PPbstaO7Bqtqd6fvi+GfJSy4XhETd?= =?us-ascii?Q?gfi2vFY8Grw9BpMl6QF10xFDEZggNZfilLWHpIf+59ssf53/ef0fH+M10uME?= =?us-ascii?Q?XBudA+M5tn5LpHeZ7IvoZ4F1c+yDYz2fGFU0cE1AM5c=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4073.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9c47327-a62f-4bbc-43c8-08d8b8401c46 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2021 03:54:36.3210 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: JT2u4cUmmzNxXptynaF61mL25BFnR5udqsZPVsOQLFQ1XEj1W8rtboITO7DhoiRzx1P424tWzakl0JwiMnkRYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4156 Return-Path: bob.c.feng@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Pushed at d911c5720f3fde5ffe72bbc4230a77025adf2e62 -----Original Message----- From: Chen, Christine =20 Sent: Thursday, January 14, 2021 10:41 AM To: devel@edk2.groups.io; Feng, Bob C Cc: Yunhua Feng ; Liming Gao Subject: RE: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FM= MT algorithm of LibFindFvInFd Reviewed-by: Yuwei Chen > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Bob=20 > Feng > Sent: Monday, November 9, 2020 9:57 AM > To: devel@edk2.groups.io > Cc: Yunhua Feng ; Liming Gao=20 > > Subject: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the=20 > FMMT algorithm of LibFindFvInFd >=20 > The LibFindFvInFd algorithm of FMMT and BFM are different. > The LibFindFvInFd in FMMT is the correct one. > By applying FMMT LibFindFvInFd, BFM can handle the case that there are=20 > two same bios images in one Firmware binary. >=20 > Signed-off-by: Bob Feng > Cc: Yunhua Feng > Cc: Liming Gao > --- > BaseTools/Source/C/BfmLib/BfmLib.c | 63=20 > ++++++++++++++++-------------- > 1 file changed, 34 insertions(+), 29 deletions(-) >=20 > diff --git a/BaseTools/Source/C/BfmLib/BfmLib.c > b/BaseTools/Source/C/BfmLib/BfmLib.c > index 73854fdc73..c247cc8e1d 100644 > --- a/BaseTools/Source/C/BfmLib/BfmLib.c > +++ b/BaseTools/Source/C/BfmLib/BfmLib.c > @@ -164,34 +164,34 @@ LibFindFvInFd ( > ) { FIRMWARE_DEVICE *LocalFdData; UINT16 = Index; > CHAR8 Ffs2Guid[16];- CHAR8 S= ignatureCheck[4];+ > CHAR8 SignatureCheck[5] =3D ""; CHAR8 = Signature[5] > =3D "_FVH"; FV_INFORMATION *CurrentFv; FV_INFORMATION > *NewFoundFv; BOOLEAN FirstMatch; UINT32 = FdSize; > UINT16 FvCount;- VOID *FdBuf= fer;- VOID > *FdBufferOri;- UINT32 Count;-+ UINT8 = *FdBuffer;+ > UINT8 *FdBufferEnd;+ UINT8 *= FdBufferOri;+ > EFI_FIRMWARE_VOLUME_HEADER *FvHeader; CurrentFv =3D NULL; > NewFoundFv =3D NULL; FdBuffer =3D NULL; FdBufferOri =3D = NULL; > FirstMatch =3D TRUE; Index =3D 0; FdSize =3D 0; = FvCount =3D 0;- > Count =3D 0; LocalFdData =3D NULL; if (InputFile =3D=3D = NULL) {+ Error > ("BFM", 0, 0001, "Error opening the input file", ""); return EFI_ABOR= TED; } > // // Find each FVs in the FD@@ -204,56 +204,66 @@ LibFindFvInFd ( > fseek(InputFile,0,SEEK_SET); // // Create an FD structure to stor= e useful > information. //- LocalFdData =3D (FIRMWARE_DEVICE *) calloc (sizeo= f > (FIRMWARE_DEVICE), sizeof(UINT8));+ LocalFdData =3D (FIRMWARE_DEVICE > *) malloc (sizeof (FIRMWARE_DEVICE)); if (LocalFdData =3D=3D NULL) {+ = Error > ("BFM", 0, 0002, "Error searching FVs in the input fd", "Allocate memory > error"); return EFI_OUT_OF_RESOURCES; }- LocalFdData->Fv =3D > (FV_INFORMATION *) calloc (sizeof (FV_INFORMATION), sizeof(UINT8));+ > LocalFdData->Fv =3D (FV_INFORMATION *) malloc (sizeof=20 > LocalFdData->(FV_INFORMATION)); > if (LocalFdData->Fv =3D=3D NULL) {+ Error ("BFM", 0, 0002, "Error sear= ching FVs > in the input fd", "Allocate memory error"); free (LocalFdData); r= eturn > EFI_OUT_OF_RESOURCES; }+ LibInitializeFvStruct (LocalFdData->Fv); = // > // Readout the FD file data to buffer. // FdBuffer =3D malloc (FdSize= ); if > (FdBuffer =3D=3D NULL) {+ Error ("BFM", 0, 0002, "Error searching FVs = in the > input fd", "Allocate memory error"); free (LocalFdData->Fv); free > (LocalFdData); return EFI_OUT_OF_RESOURCES; } if (fread (FdBuffe= r, 1, > FdSize, InputFile) !=3D FdSize) {+ Error ("BFM", 0, 0002, "Error searc= hing FVs in > the input fd", "Read FD file error!"); free (LocalFdData->Fv); fr= ee > (LocalFdData); free (FdBuffer); return EFI_ABORTED; } FdBuff= erOri =3D > FdBuffer;+ FdBufferEnd =3D FdBuffer + FdSize; - for (Count=3D0; Count <= =20 > FdSize - 4; Count++) {+ if (FdSize <=20 > sizeof(EFI_FIRMWARE_VOLUME_HEADER)) {+ Error ("BFM", 0, 0002, "Error Chec= k the input FD, Please make sure the FD is > valid", "Check FD size error!");+ return EFI_ABORTED;+ }++ while (Fd= Buffer > <=3D FdBufferEnd - sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {+ FvHeader = =3D > (EFI_FIRMWARE_VOLUME_HEADER *) FdBuffer; // // Copy 4 bytes of fd > data to check the _FVH signature //- memcpy (SignatureCheck, FdBuf= fer, > 4);- FdBuffer =3D(UINT8 *)FdBuffer + 4;+ memcpy (SignatureCheck, > &FvHeader->Signature, 4); if (strncmp(SignatureCheck, Signature, 4) = =3D=3D > 0){ // // Still need to determine the FileSystemGuid in > EFI_FIRMWARE_VOLUME_HEADER equal to- // > EFI_FIRMWARE_FILE_SYSTEM2_GUID.+ // > EFI_FIRMWARE_FILE_SYSTEM2_GUID or > EFI_FIRMWARE_FILE_SYSTEM3_GUID. // Turn back 28 bytes to find the > GUID. //- FdBuffer =3D (UINT8 *)FdBuffer - 28;- memcpy (F= fs2Guid, > FdBuffer, 16);+ memcpy (Ffs2Guid, &FvHeader->FileSystemGuid, 16); > // // Compare GUID. // for (Index =3D 0; Index < 16; In= dex ++) {@@ - > 267,32 +277,28 @@ LibFindFvInFd ( > break; } } } - //- // Point = to the original address- > //- FdBuffer =3D (UINT8 *)FdBuffer + 28;- // // Here we = found an FV. > //- if (Index =3D=3D 16) {+ if ((Index =3D=3D 16) && ((FdBuffer= + FvHeader- > >FvLength) <=3D FdBufferEnd)) { if (FirstMatch) {- Local= FdData->Fv- > >ImageAddress =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) -=20 > >0x2c;+ > LocalFdData->Fv->ImageAddress =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 > *)FdBufferOri); CurrentFv =3D LocalFdData->= Fv; > CurrentFv->FvNext =3D NULL; // // Store t= he FV name by > found sequence // sprintf(CurrentFv->FvName, "FV%d", = FvCount); > FirstMatch =3D FALSE; } else { NewFoundFv =3D (FV_I= NFORMATION *) > malloc (sizeof (FV_INFORMATION));- if (NULL =3D=3D NewFoundFv)= {+ > if (NewFoundFv =3D=3D NULL) {+ Error ("BFM", 0, 0002, "Error= searching > FVs in the input fd", "Allocate memory error"); free (Local= FdData->Fv); > free (LocalFdData); free (FdBuffer); return > EFI_OUT_OF_RESOURCES; }@@ -300,11 +306,11 @@ LibFindFvInFd ( > LibInitializeFvStruct (NewFoundFv); // = // Need to turn > back 0x2c bytes //- NewFoundFv->ImageAddress =3D > (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) - 0x2c;+ > NewFoundFv->ImageAddress =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 > *)FdBufferOri); // // Store the FV name by found= sequence > // sprintf(NewFoundFv->FvName, "FV%d", FvCount);@@ -320,19 > +326,18 @@ LibFindFvInFd ( > // CurrentFv =3D CurrentFv->FvNex= t; } FvCount > ++;- Index =3D 0;+ FdBuffer =3D FdBuffer + FvHeader->FvLeng= th;+ } else > {+ FdBuffer ++; } + } else {+ FdBuffer ++; }-- = //- // We need to > turn back 3 bytes.- //- FdBuffer =3D (UINT8 *)FdBuffer - 3; } = LocalFdData- > >Size =3D FdSize; *FdData =3D LocalFdData;-- > 2.29.1.windows.1 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#67131):=20 > https://edk2.groups.io/g/devel/message/67131 > Mute This Topic: https://groups.io/mt/78127410/4546272 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub=20 > [yuwei.chen@intel.com] -=3D-=3D-=3D-=3D-=3D-=3D >=20