From nobody Fri Apr 26 05:19:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69553+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69553+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1609757325; cv=none; d=zohomail.com; s=zohoarc; b=U6CdUXceV2aRjr4guPw2+tdNigKGwAYsIXYw6TsyR0thO//fJoguGG54qUpd9uXI46PQd26CtQLdxi5s9JMZswKlz4NysDErRY2rsJ8v6u7FXxc17dQnogtUq2FPhy9PAzeaJ3PiZ8EOGUuqP9uldOG0vMHEFWTwuqLyDK1cReQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609757325; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=C1rEgmJIYYTUQljJ+r0iwED/zAswBLyZIOuH6YzdTRs=; b=fpnbKQiCLXma2+E11Zdy4/MDeO9GwquTLhXqbB86TAMHMC5uo/d74mnJ0IFqN8t7WkmY21oEZVtHWuYzB2n76dhehCRVRAqwefbipgclu/qOS0pM5rxzJ1015QUpNIFvlUUSgMIav/uSs94j+7pec9nYAgwHCiA80B14AM9GwiE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69553+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609757325277310.21019336390316; Mon, 4 Jan 2021 02:48:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id xCx3YY1788612xHNZ8nNrFz8; Mon, 04 Jan 2021 02:48:44 -0800 X-Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by mx.groups.io with SMTP id smtpd.web12.12125.1609757318551558043 for ; Mon, 04 Jan 2021 02:48:39 -0800 X-Received: from LAPTOP2AECFQIA ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Mon, 04 Jan 2021 18:48:35 +0800 X-WM-Sender: fengyunhua@byosoft.com.cn X-WM-AuthFlag: YES X-WM-AuthUser: fengyunhua@byosoft.com.cn From: "fengyunhua" To: "'Bob Feng'" , Cc: "'Liming Gao'" References: <20201109015725.1733-1-bob.c.feng@intel.com> In-Reply-To: <20201109015725.1733-1-bob.c.feng@intel.com> Subject: =?UTF-8?B?W2VkazItZGV2ZWxdIOWbnuWkjTogW1BhdGNoXSBbZWRrMi1zdGFnaW5nXUJhc2VUb29scy9CZm06IEFwcGx5IHRoZSBGTU1UIGFsZ29yaXRobSBvZiBMaWJGaW5kRnZJbkZk?= Date: Mon, 4 Jan 2021 18:48:36 +0800 Message-ID: <000101d6e287$27905100$76b0f300$@byosoft.com.cn> MIME-Version: 1.0 Thread-Index: AQKgQv+/qKnkojHlVYe0R4C0hKGR7aiEh3GQ Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,fengyunhua@byosoft.com.cn X-Gm-Message-State: z2rTTzQvB1sTxurTChXnL5ugx1787277AA= Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609757324; bh=q1FT88CfUWumjsZ5fLH5NN9zpTBcuont+Pn3Kz8FA28=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=chyAD8LHuP+b6NeD3y1AQu2lwdmlKlGqsxPnQ4abKShQyv7CVNBwXgbwEoKPB4YOXeE z0ebO38s06UfyYlNVsl+90Xyea2a657Yzr8yDfpz3Xu0VfJw15kgqC1qzhXKi8dWpwfn6 PasLFRAWYkj5cLBjrR83sSsriM9Y8wsizyo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Reviewed-by: Yunhua Feng Thanks, Yunhua -----=E9=82=AE=E4=BB=B6=E5=8E=9F=E4=BB=B6----- =E5=8F=91=E4=BB=B6=E4=BA=BA: Bob Feng =20 =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2020=E5=B9=B411=E6=9C=889=E6=97=A5 9:= 57 =E6=94=B6=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io =E6=8A=84=E9=80=81: Yunhua Feng ; Liming Gao =E4=B8=BB=E9=A2=98: [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT alg= orithm 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_INFORMATION *CurrentFv; FV_INFORMATION *NewFoundFv; BOOLEAN FirstMatch; UINT32 FdSize; UINT16 FvCount; - VOID *FdBuffer; - VOID *FdBufferOri; - UINT32 Count; - + UINT8 *FdBuffer; + UINT8 *FdBufferEnd; + UINT8 *FdBufferOri; + EFI_FIRMWARE_VOLUME_HEADER *FvHeader; =20 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; =20 if (InputFile =3D=3D NULL) { + Error ("BFM", 0, 0001, "Error opening the input file", ""); return EFI_ABORTED; } =20 // // Find each FVs in the FD @@ -204,56 +204,66 @@ LibFindFvInFd ( =20 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_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 searching FVs in the input fd", "Allocate memory error"); free (LocalFdData); return EFI_OUT_OF_RESOURCES; } + LibInitializeFvStruct (LocalFdData->Fv); =20 // // Readout the FD file data to buffer. // FdBuffer =3D malloc (FdSize); =20 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; } =20 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; } =20 FdBufferOri =3D FdBuffer; + FdBufferEnd =3D FdBuffer + FdSize; =20 - 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 (FdBuffer <=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, FdBuffer, 4); - FdBuffer =3D(UINT8 *)FdBuffer + 4; + memcpy (SignatureCheck, &FvHeader->Signature, 4); =20 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 (Ffs2Guid, FdBuffer, 16); + memcpy (Ffs2Guid, &FvHeader->FileSystemGuid, 16); =20 // // Compare GUID. // for (Index =3D 0; Index < 16; Index ++) { @@ -267,32 +277,28 @@ LibFindFvInFd ( break; } } } =20 - // - // 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) { - LocalFdData->Fv->ImageAddress =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) - 0x2c; + LocalFdData->Fv->ImageAddress =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri); CurrentFv =3D LocalFdData->Fv; CurrentFv->FvNext =3D NULL; // // Store the FV name by found sequence // sprintf(CurrentFv->FvName, "FV%d", FvCount); =20 FirstMatch =3D FALSE; } else { NewFoundFv =3D (FV_INFORMATION *) 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 (LocalFdData->Fv); free (LocalFdData); free (FdBuffer); return EFI_OUT_OF_RESOURCES; } @@ -300,11 +306,11 @@ LibFindFvInFd ( LibInitializeFvStruct (NewFoundFv); =20 // // Need to turn back 0x2c bytes // - NewFoundFv->ImageAddress =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) - 0x2c; + NewFoundFv->ImageAddress =3D (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri); =20 // // Store the FV name by found sequence // sprintf(NewFoundFv->FvName, "FV%d", FvCount); @@ -320,19 +326,18 @@ LibFindFvInFd ( // CurrentFv =3D CurrentFv->FvNext; } =20 FvCount ++; - Index =3D 0; + FdBuffer =3D FdBuffer + FvHeader->FvLength; + } else { + FdBuffer ++; } =20 + } else { + FdBuffer ++; } - - // - // We need to turn back 3 bytes. - // - FdBuffer =3D (UINT8 *)FdBuffer - 3; } =20 LocalFdData->Size =3D FdSize; =20 *FdData =3D LocalFdData; --=20 2.29.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69553): https://edk2.groups.io/g/devel/message/69553 Mute This Topic: https://groups.io/mt/79421502/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-