From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.8698.1609729271147097423 for ; Sun, 03 Jan 2021 19:01:11 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=aF9ghyqg; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: bob.c.feng@intel.com) IronPort-SDR: yzzROQAxc+5u40DDU5TedDxSauCxSTNkuV9ub9ZONBvqbYFe4VNwOLTZD5oWK2YrOugeDqIikI AIkoFDz9FEGA== X-IronPort-AV: E=McAfee;i="6000,8403,9853"; a="156691594" X-IronPort-AV: E=Sophos;i="5.78,472,1599548400"; d="scan'208";a="156691594" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2021 19:01:09 -0800 IronPort-SDR: 8ASfejvKefYgel4O0Swmqbd3OxDTJVGp9/MZG8Hr4jfoB1/CLSxm/eWz+KzeZP0pX0K6/d6HCG ycZbVyxpXN8A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,472,1599548400"; d="scan'208";a="421197225" Received: from fmsmsx606.amr.corp.intel.com ([10.18.126.86]) by orsmga001.jf.intel.com with ESMTP; 03 Jan 2021 19:01:09 -0800 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) 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; Sun, 3 Jan 2021 19:01:08 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Sun, 3 Jan 2021 19:01:08 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.105) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Sun, 3 Jan 2021 19:01:06 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TjW3zpj5NHTw8s146NmBaus8keJQNBbxyZhTNZsUDQJLEPtI69tSnIZ1iHOCyOw2NCGTUf8Pz5F5Sj3Lp/R7EQS+yI+jSZdDAA26j0nkn4s21EXsPzYZGKvwCcd8tkFvZFhhs5SxGx2CWJFoAVLPXeyOw+wp3Pg9rsLiKn56NiP+hTVb2vd5f/m7BcjprNjEm2IfylXhhzL4Vmj1x+/OK26nQH+jvwe8HTizL6QGjCQf77gc0G5bF8yhQqiAGRb8caDMaRr6faI3i5U3kTt1nnyydem/1ahx7hCjUjx/sr4R9RzYx8RB82G6fJJlF43LQOB4x0Zh7ghv6vGs8j4ihw== 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=k5E2XeH8ZnUG/BBqqH2is9tYIR0dm0+jB0gABKdLWLY=; b=BOMci+bAAWsydo/zs2hnpkji0wVsLFoLY5uvZfLgfn3hAUCPlJa9HqwmN8UMhgh/CvcN/4cFamm9L6QTcxbqNdEPF8JsyyMagn/ownpj0U1ihyhqltset/arI4wKpj1yZ+83lEiNBVqfsFPWG5pZvyttmZEwHnnlLvVWSIT4CDTqF6vJmjq8Jo7FK3zvuArjqbs0MITgEiogCU2Q64aM6/SLdVWppwl2EBWHJRdIEKfwq1/zKAWiL00meqxEw0o/iaN/dQe1BhuYW/LqjBs4beD0LV+nCHPB94Fh9juZnMvQcCxIcj/Fj3GioNE4NFAXhSxpxIy8wsOIpu9sYFVbLw== 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=k5E2XeH8ZnUG/BBqqH2is9tYIR0dm0+jB0gABKdLWLY=; b=aF9ghyqgztadlZzIrijem3wJQZoPZ+JWhMnOTYoXWou21c9g4I0QJp4DJR2Zp5/fTF5YfsOloN5PpBKKQ4P823yEJXhZB5B/EuU2QARP1hJujW1etxeIsRDXbrr9z1hwBLXIOyYIePXyjkgt3ZwshJHUJWd40AJDy82ZJ8ph24o= Received: from DM6PR11MB4073.namprd11.prod.outlook.com (2603:10b6:5:19f::22) by DM5PR1101MB2268.namprd11.prod.outlook.com (2603:10b6:4:53::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.19; Mon, 4 Jan 2021 03:01:05 +0000 Received: from DM6PR11MB4073.namprd11.prod.outlook.com ([fe80::5c3c:da40:5046:5413]) by DM6PR11MB4073.namprd11.prod.outlook.com ([fe80::5c3c:da40:5046:5413%7]) with mapi id 15.20.3721.024; Mon, 4 Jan 2021 03:01:05 +0000 From: "Bob Feng" To: "devel@edk2.groups.io" , "Feng, Bob C" , 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: AQHWtjvrkUEnTo9Wx0mIm1M9WEQK0KoXHvyA Date: Mon, 4 Jan 2021 03:01:05 +0000 Message-ID: References: <1645B458920B2EFC.8542@groups.io> In-Reply-To: <1645B458920B2EFC.8542@groups.io> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: 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: 2bc457a9-bd9e-4acc-fc60-08d8b05cfa0c x-ms-traffictypediagnostic: DM5PR1101MB2268: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: +zY01kdE6lzZWc4SLALjqDL6xKs3k4zZIpIhLtoLV6PHpn/75IdFAjswYhkqJlxBK+yUNV94IWKFA9XyAX5cWzBojWebNvIblGzaefU39Vj9Xfle91+6i0sFOiaUeB1S3eMH9rcq7vF7GF5sGnP+jZN2arbqqcH8+nkVyT0lwF98kVb53OQf2m1FzY/Me3NSYLzV2baGBzq4jz7wqpy9ty7aRnFBWnDlSrjNcSvvG//YhmerEzGemfgAHSMdu4jVWC+XGs7nKAZL1nlp/XtMTGOWJvMEz8vM/ETyUgQnAu9x9ol72X3mqdTUcTkqIuJ3EeI91KWcPISNyK2ShMVZIN4Znba98Zu698XAlw5ZCq11CVY4mqRIGcePDwJn38NpO/LHDO3nDLasQoWdQmbUpeDq9PFzb6jXWYe9lo1ODEKOl/payeiHr5OVtrwq4y9LFJSEz0F9PiBdNTyWZzyXqg== 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)(136003)(39860400002)(366004)(396003)(376002)(346002)(83380400001)(7696005)(52536014)(316002)(2906002)(110136005)(71200400001)(8676002)(76116006)(33656002)(66946007)(9686003)(26005)(66556008)(64756008)(66476007)(86362001)(8936002)(53546011)(6506007)(55016002)(66446008)(966005)(5660300002)(478600001)(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sJBIw+R5?= =?us-ascii?Q?VkRtN+Iwnaok/BPlUtyasFoOsHvrQtFGfDmVkwwn7VpmgbkCxlth5IOBg/0v?= =?us-ascii?Q?7hAmqrfK+fVZDTFm40KwO1EXyzdQXtqCZv/jH5Prm9cxOm3ONdYXWtkOEZjt?= =?us-ascii?Q?Du4IIZcpfwQ6Vu6VHd8+EfwCaQNGDbwFKlRrCwtZV3g=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: 2bc457a9-bd9e-4acc-fc60-08d8b05cfa0c X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Jan 2021 03:01:05.0430 (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: S6EuOAAuwbyCrl15R9gHA4RjZWbCP6VZBYu2sa6zvgxh212B1woC2lGk0xw/mOnwvLCCV3SYt+YdhImPeHGiZg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1101MB2268 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 Hi Liming and Yunhua, Could you review this patch? Thanks, Bob -----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 a= lgorithm of LibFindFvInFd 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. 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(-) 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 = SignatureCheck[4];+ CHAR8 SignatureCheck[5= ] =3D ""; CHAR8 Signature[5] =3D "_FVH"; FV_INFOR= MATION *CurrentFv; FV_INFORMATION *NewFoundFv; = BOOLEAN FirstMatch; UINT32 FdS= ize; UINT16 FvCount;- VOID *= FdBuffer;- VOID *FdBufferOri;- UINT32 = Count;-+ UINT8 *FdBuffer;+ UINT8 = *FdBufferEnd;+ UINT8 *FdBufferOri;+ EF= I_FIRMWARE_VOLUME_HEADER *FvHeader; CurrentFv =3D NULL; NewFound= Fv =3D NULL; FdBuffer =3D NULL; FdBufferOri =3D NULL; Fi= rstMatch =3D TRUE; Index =3D 0; FdSize =3D 0; Fv= Count =3D 0;- Count =3D 0; LocalFdData =3D NULL; i= f (InputFile =3D=3D NULL) {+ Error ("BFM", 0, 0001, "Error opening the i= nput file", ""); return EFI_ABORTED; } // // Find each FVs in th= e FD@@ -204,56 +204,66 @@ LibFindFvInFd ( fseek(InputFile,0,SEEK_SET); // // Create an FD structure to store = useful information. //- LocalFdData =3D (FIRMWARE_DEVICE *) calloc (= sizeof (FIRMWARE_DEVICE), sizeof(UINT8));+ LocalFdData =3D (FIRMWARE_D= EVICE *) malloc (sizeof (FIRMWARE_DEVICE)); if (LocalFdData =3D=3D NULL) = {+ Error ("BFM", 0, 0002, "Error searching FVs in the input fd", "Alloca= te 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 searc= hing FVs in the input fd", "Allocate memory error"); free (LocalFdData)= ; return EFI_OUT_OF_RESOURCES; }+ LibInitializeFvStruct (LocalFdDat= a->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 (FdBuffer, 1, FdSize, InputFile) !=3D FdSize) {+ Error = ("BFM", 0, 0002, "Error searching FVs in the input fd", "Read FD file error= !"); free (LocalFdData->Fv); free (LocalFdData); free (FdBuffer= ); return EFI_ABORTED; } FdBufferOri =3D FdBuffer;+ FdBufferEnd = =3D FdBuffer + FdSize; - for (Count=3D0; Count < FdSize - 4; Count++) {+ = if (FdSize < sizeof(EFI_FIRMWARE_VOLUME_HEADER)) {+ Error ("BFM", 0, 000= 2, "Error Check the input FD, Please make sure the FD is valid", "Check FD = size error!");+ return EFI_ABORTED;+ }++ while (FdBuffer <=3D FdBuffer= End - 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, FdBuffer, 4);- FdB= uffer =3D(UINT8 *)FdBuffer + 4;+ memcpy (SignatureCheck, &FvHeader->Sign= ature, 4); if (strncmp(SignatureCheck, Signature, 4) =3D=3D 0){ = // // Still need to determine the FileSystemGuid in EFI_FIRMWARE_VOLU= ME_HEADER equal to- // EFI_FIRMWARE_FILE_SYSTEM2_GUID.+ // EFI_FI= RMWARE_FILE_SYSTEM2_GUID or EFI_FIRMWARE_FILE_SYSTEM3_GUID. // Turn b= ack 28 bytes to find the GUID. //- FdBuffer =3D (UINT8 *)FdBuffe= r - 28;- memcpy (Ffs2Guid, FdBuffer, 16);+ memcpy (Ffs2Guid, &FvH= eader->FileSystemGuid, 16); // // Compare GUID. // = for (Index =3D 0; Index < 16; Index ++) {@@ -267,32 +277,28 @@ LibFindFvIn= Fd ( 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 FdBu= fferEnd)) { if (FirstMatch) {- LocalFdData->Fv->ImageAddre= ss =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) - 0x2c;+ = LocalFdData->Fv->ImageAddress =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBu= fferOri); CurrentFv =3D LocalFdData->Fv; = CurrentFv->FvNext =3D NULL; // // Sto= re the FV name by found sequence // sprintf(CurrentFv->= FvName, "FV%d", FvCount); FirstMatch =3D FALSE; } else= { NewFoundFv =3D (FV_INFORMATION *) malloc (sizeof (FV_INFORMA= TION));- if (NULL =3D=3D NewFoundFv) {+ if (NewFoundF= v =3D=3D NULL) {+ Error ("BFM", 0, 0002, "Error searching FVs = in the input fd", "Allocate memory error"); free (LocalFdData= ->Fv); free (LocalFdData); free (FdBuffer); = return EFI_OUT_OF_RESOURCES; }@@ -300,11 +306,11 @@ = LibFindFvInFd ( LibInitializeFvStruct (NewFoundFv); // = // Need to turn back 0x2c bytes //- NewFoundFv->Im= ageAddress =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) - 0x2c;+ = NewFoundFv->ImageAddress =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 *= )FdBufferOri); // // Store the FV name by found se= quence // sprintf(NewFoundFv->FvName, "FV%d", FvCou= nt);@@ -320,19 +326,18 @@ LibFindFvInFd ( // CurrentFv =3D CurrentFv->FvNext;= } FvCount ++;- Index =3D 0;+ FdBuffer =3D= FdBuffer + FvHeader->FvLength;+ } else {+ FdBuffer ++; }= + } else {+ FdBuffer ++; }-- //- // We need to turn back= 3 bytes.- //- FdBuffer =3D (UINT8 *)FdBuffer - 3; } LocalFdData= ->Size =3D FdSize; *FdData =3D LocalFdData;--=20 2.29.1.windows.1 -=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/1768742 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [bob.c.feng@intel.com] -= =3D-=3D-=3D-=3D-=3D-=3D