From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web09.2635.1610592041448732566 for ; Wed, 13 Jan 2021 18:40:41 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=dC9ulxoG; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: yuwei.chen@intel.com) IronPort-SDR: oqTzQqfRrbV3nvY+3NuXvDqkktgM8KcoDcD9EQtFiMfsq55k6dxu0KOH69eK8jhxxLAqQpMJz4 HnVXok14Zk4w== X-IronPort-AV: E=McAfee;i="6000,8403,9863"; a="157480525" X-IronPort-AV: E=Sophos;i="5.79,346,1602572400"; d="scan'208";a="157480525" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2021 18:40:40 -0800 IronPort-SDR: WxFP6nRNM1bYHSWP+xM05p4DXpSCJH6VmDIw7hevbyUpPNaw5UdHyO/EKtKtHjojelvYPNZuCU NzLcgK/crVsw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,346,1602572400"; d="scan'208";a="349020962" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by orsmga003.jf.intel.com with ESMTP; 13 Jan 2021 18:40:40 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX606.amr.corp.intel.com (10.22.229.19) 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 18:40:40 -0800 Received: from orsmsx605.amr.corp.intel.com (10.22.229.18) by ORSMSX611.amr.corp.intel.com (10.22.229.24) 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 18:40:39 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx605.amr.corp.intel.com (10.22.229.18) 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 18:40:39 -0800 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.100) by edgegateway.intel.com (134.134.137.103) 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 18:40:39 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nw8UkvGoJJ6tMvGXRMAbbpRH7l3ZCaPWR/pP2y598OCPd9q0RSehsQeGtJWiUhoZ8zaFersW4GfyhyGdP9lzMDftcoiLAKK7WW8PDWtEmc5I0H6UeHCv0PE4H2GPIHjVBLFPUsgGdHwXpyeTAU1A2mLyZQ1hNcJIevWJ/qFw8jQT0fObI4vy7h2A5L1eO4c/7QgSED5dgXBd6X9Nv88Edb5coa5VZn/wkARfsJQmRrbevTnRwqTcjckrGUHfFp12AVB4o0Q1l/bhwwry6Vw01Cf+5B8XG3afJXsH802jn0dYd8wbCyjIkbgMxa1IGoH2UNyYqWdwZcvjQE3wZtQo0g== 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=+utStcqKIee9A+Iva5igiTbEYSXtIrRwq/OUFdkyiXQ=; b=QHSCh2QBhhg48TD2GsCPMkXAM52Q+9F6bMIDZ+pZpVcw1fwcf3vay8vk1vW+TMNxtJqxQbSIEropXNIK60iBWTFgfik3X28+nfEryn5HDi4Y+7uHVBf1FdPTvWMdJW7nS5Xg92N1mXvzI5KHIxONuS/VTo0EhV0DGVgRr4yNQGbRwuQgPo6N3t9LRsa5ERY10YBttMCxkg5rO6hpf2EkaJyFVYKY65fSn4Mf2JWd2BV5KsW8JHEB54KI3ZKX1UC0S55v4+jmt0me5HJ2pngpWP9Iutq91RUMoML9aaIq1rZKed/LFko1Y8jJfkYUaqrbDhL0fpALJd7YWPUYO6feGA== 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=+utStcqKIee9A+Iva5igiTbEYSXtIrRwq/OUFdkyiXQ=; b=dC9ulxoGETU66Q0FGbfLYQl9qcYmoOJjxfDl5qur2e2CBWhhe7u1DtxqinUgFHjD+EyZYpxomIAuF3g1MeURz2+FL6ZvXB1W8uU1ShZYTu+SJYKZVbBZOOelKRJtNKMwFDj1E/uzLqPislUsBiq1ViUf6QEWkAiWjnqAJUR+Be8= Received: from DM5PR11MB1594.namprd11.prod.outlook.com (2603:10b6:4:5::16) by DM6PR11MB3833.namprd11.prod.outlook.com (2603:10b6:5:144::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Thu, 14 Jan 2021 02:40:38 +0000 Received: from DM5PR11MB1594.namprd11.prod.outlook.com ([fe80::59f7:5329:fc62:a3be]) by DM5PR11MB1594.namprd11.prod.outlook.com ([fe80::59f7:5329:fc62:a3be%9]) with mapi id 15.20.3763.010; Thu, 14 Jan 2021 02:40:37 +0000 From: "Yuwei Chen" To: "devel@edk2.groups.io" , "Feng, Bob C" 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: AQHWtjvqVleaJsx99EyekJ0aXgMTTaom0Mbw Date: Thu, 14 Jan 2021 02:40:37 +0000 Message-ID: References: <20201109015725.1733-1-bob.c.feng@intel.com> In-Reply-To: <20201109015725.1733-1-bob.c.feng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-reaction: no-action dlp-product: dlpe-windows authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.102.204.36] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4fc65156-1de7-4345-9442-08d8b835c6bb x-ms-traffictypediagnostic: DM6PR11MB3833: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2657; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: eHwNdXjsSC7V5RF4H/XPlYhy+Xzp9zgPGxB2cmtfkLfSdySVnO68MYDyaFfBhwFn7KWY4MPevCCQ8FrIxwbLIIOYY5bVYS6IjFOqo+Huq3Dsi55yCj7ls9j5UMP/N5F7c2HO1Fx67IitvgOV3chW4rKRXFXx/leHfgNCSWzMS0xDsfWe7V8WKwLPRamm2z6oK1Xxjn6hoND5FJP4ybIbdcTuarG/dKK3TUKMeQV3tOryDG9CZ59w1MdxsDc0weL5VA/bMepylzUaXF5GlX/0JRHbjmaqzi+EJnNc8utkW3FrloLQ+oWcM9Qha4qPmQ+g022irUm/DJ5sOXuXHf5WTmZ3Eu5tY3peXCGmtJETeyNQdy5iPJ5rgU9+9EDb5wrtVMbNbRYB9gY1x0HJQ2IvD9abuMVChZrRW2oGUjxVA4JwA2sGgH4LWiiyfmICjvHnJna4dWZPWsydfZ9Y67yFug== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR11MB1594.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(6029001)(4636009)(396003)(376002)(136003)(39860400002)(346002)(366004)(76116006)(53546011)(6506007)(52536014)(8676002)(9686003)(966005)(316002)(33656002)(66446008)(55016002)(71200400001)(4326008)(186003)(66476007)(26005)(7696005)(66946007)(83380400001)(86362001)(8936002)(6636002)(54906003)(64756008)(2906002)(66556008)(110136005)(5660300002)(478600001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?GyVRRl/eAuKHkHevV5aUVbneNWgYFm4KB1d8PhwtjuiUxPYacQi6KPIrLUc1?= =?us-ascii?Q?8BjuGg5smSWQEWj96MfSjsg/YflRtlGgaLWXPDEPBHPlx5JcaQbiDO/6yqKt?= =?us-ascii?Q?hz+yElxP28Gnf8OORECcuiT005QorbjAUhBgDg25PqEAEUhCUzF4bgEUz8II?= =?us-ascii?Q?72b2/kpFwhJzqdksLcE+elBeYme30fWswXtaDRnlEtbtzO8l1IU7oWeBY3ws?= =?us-ascii?Q?AwwdfbCCq4YtQxeLqrZ5xk4TWt81Xm+nfW+V20tDL5p6YcdKGT5FAv2gEkos?= =?us-ascii?Q?HlPzWUU6snJPtelOkK7jt3DpJUQUON65jNKTW3Wyho6oNTWObXmg/0YJv/FA?= =?us-ascii?Q?PSfnKtg+OEBZc/z7gLHZrclYHo+mUkaaAaWK0bdP8mcfaUhK+PcElRKJ1oZ5?= =?us-ascii?Q?ReJgMg7ZLqItEsHS8GEvWclbzfQ2nU6JWSxnrL2eEGbfDur6/gdFBj76CD37?= =?us-ascii?Q?f4j2PaJ6p4DRxlY+iIKW4krwt/O0BuRmzDOSElWFo0uKhBN4YYWCMRmQ4tED?= =?us-ascii?Q?OPcjfQXS6FTYhBkQd1shgY+FeCKRidLY7B15027X2V8VF8fUPvvvK6uOomlU?= =?us-ascii?Q?tPspU/rw8Z66N70zOB3l+Tz3E7PMpXsK803iGL6CpYdVWC6dach9I689GMzY?= =?us-ascii?Q?nELb+ewJeyA4RxeQ6d885rPUz5DLYNjEj+Xa8iye3Z1ZMRrNv8nPU3k1DUq1?= =?us-ascii?Q?H3V5JJWLR1Qspys2xUIkuJLzcj3JOlT2v/IraRL+tLiFc9uHxMYB2aPsE8Z3?= =?us-ascii?Q?ivo1zkEnxzRl+gaigLp35kXDy+8/CCzx/90qYvFievOA68sN64+HVLEyzLEB?= =?us-ascii?Q?hUQPOkqUMO6bKEM7kulpngp6eciMkniH5FfUfGbyijS8yyY8GbE4mwpHqxqe?= =?us-ascii?Q?1oL58r3Wq3K30SMb9PlP424RnDtRi+LHzntmFQ8Dk6Ed4pTiELSFbL/nf6uL?= =?us-ascii?Q?ksBIAR0XdK1XoduCB9akXdwdxJhMikWtN4PcPxgSUCA=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM5PR11MB1594.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4fc65156-1de7-4345-9442-08d8b835c6bb X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2021 02:40:37.8825 (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: hdjEE6zHn0ma2Q0E/anTC3ClXRdNAn39CGTFedXcDRPSoupLnd3NRw5erZFOaygD5SgmcOJ+jzVy8PXvqlA5lg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB3833 Return-Path: yuwei.chen@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yuwei Chen > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Bob > Feng > Sent: Monday, November 9, 2020 9:57 AM > To: devel@edk2.groups.io > Cc: Yunhua Feng ; Liming Gao > > Subject: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the 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 > 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 ++++++++++++++++-------------- > 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 (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 <= FdSize - > 4; Count++) {+ if (FdSize < sizeof(EFI_FIRMWARE_VOLUME_HEADER)) {+ > Error ("BFM", 0, 0002, "Error Check 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) - 0x2= c;+ > 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): 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 [yuwei.chen@intel.com] > -=3D-=3D-=3D-=3D-=3D-=3D >=20