* Re: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT algorithm of LibFindFvInFd
[not found] <1645B458920B2EFC.8542@groups.io>
@ 2021-01-04 3:01 ` Bob Feng
2021-01-04 8:42 ` 回复: " gaoliming
0 siblings, 1 reply; 4+ messages in thread
From: Bob Feng @ 2021-01-04 3:01 UTC (permalink / raw)
To: devel@edk2.groups.io, Feng, Bob C, Yunhua Feng, Liming Gao
Hi Liming and Yunhua,
Could you review this patch?
Thanks,
Bob
-----Original Message-----
From: devel@edk2.groups.io <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 <fengyunhua@byosoft.com.cn>; Liming Gao <gaoliming@byosoft.com.cn>
Subject: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT algorithm 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 <bob.c.feng@intel.com>
Cc: Yunhua Feng <fengyunhua@byosoft.com.cn>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
---
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] = ""; CHAR8 Signature[5] = "_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; CurrentFv = NULL; NewFoundFv = NULL; FdBuffer = NULL; FdBufferOri = NULL; FirstMatch = TRUE; Index = 0; FdSize = 0; FvCount = 0;- Count = 0; LocalFdData = NULL; if (InputFile == NULL) {+ Error ("BFM", 0, 0001, "Error opening the input file", ""); return EFI_ABORTED; } // // Find each FVs in the FD@@ -204,56 +204,66 @@ LibFindFvInFd (
fseek(InputFile,0,SEEK_SET); // // Create an FD structure to store useful information. //- LocalFdData = (FIRMWARE_DEVICE *) calloc (sizeof (FIRMWARE_DEVICE), sizeof(UINT8));+ LocalFdData = (FIRMWARE_DEVICE *) malloc (sizeof (FIRMWARE_DEVICE)); if (LocalFdData == NULL) {+ Error ("BFM", 0, 0002, "Error searching FVs in the input fd", "Allocate memory error"); return EFI_OUT_OF_RESOURCES; }- LocalFdData->Fv = (FV_INFORMATION *) calloc (sizeof (FV_INFORMATION), sizeof(UINT8));+ LocalFdData->Fv = (FV_INFORMATION *) malloc (sizeof (FV_INFORMATION)); if (LocalFdData->Fv == 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); // // Readout the FD file data to buffer. // FdBuffer = malloc (FdSize); if (FdBuffer == 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) != 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 = FdBuffer;+ FdBufferEnd = FdBuffer + FdSize; - for (Count=0; 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 <= FdBufferEnd - sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {+ FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) FdBuffer; // // Copy 4 bytes of fd data to check the _FVH signature //- memcpy (SignatureCheck, FdBuffer, 4);- FdBuffer =(UINT8 *)FdBuffer + 4;+ memcpy (SignatureCheck, &FvHeader->Signature, 4); if (strncmp(SignatureCheck, Signature, 4) == 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 = (UINT8 *)FdBuffer - 28;- memcpy (Ffs2Guid, FdBuffer, 16);+ memcpy (Ffs2Guid, &FvHeader->FileSystemGuid, 16); // // Compare GUID. // for (Index = 0; Index < 16; Index ++) {@@ -267,32 +277,28 @@ LibFindFvInFd (
break; } } } - //- // Point to the original address- //- FdBuffer = (UINT8 *)FdBuffer + 28;- // // Here we found an FV. //- if (Index == 16) {+ if ((Index == 16) && ((FdBuffer + FvHeader->FvLength) <= FdBufferEnd)) { if (FirstMatch) {- LocalFdData->Fv->ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) - 0x2c;+ LocalFdData->Fv->ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri); CurrentFv = LocalFdData->Fv; CurrentFv->FvNext = NULL; // // Store the FV name by found sequence // sprintf(CurrentFv->FvName, "FV%d", FvCount); FirstMatch = FALSE; } else { NewFoundFv = (FV_INFORMATION *) malloc (sizeof (FV_INFORMATION));- if (NULL == NewFoundFv) {+ if (NewFoundFv == 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->ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) - 0x2c;+ NewFoundFv->ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri); // // Store the FV name by found sequence // sprintf(NewFoundFv->FvName, "FV%d", FvCount);@@ -320,19 +326,18 @@ LibFindFvInFd (
// CurrentFv = CurrentFv->FvNext; } FvCount ++;- Index = 0;+ FdBuffer = FdBuffer + FvHeader->FvLength;+ } else {+ FdBuffer ++; } + } else {+ FdBuffer ++; }-- //- // We need to turn back 3 bytes.- //- FdBuffer = (UINT8 *)FdBuffer - 3; } LocalFdData->Size = FdSize; *FdData = LocalFdData;--
2.29.1.windows.1
-=-=-=-=-=-=
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] -=-=-=-=-=-=
^ permalink raw reply related [flat|nested] 4+ messages in thread
* 回复: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT algorithm of LibFindFvInFd
2021-01-04 3:01 ` [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT algorithm of LibFindFvInFd Bob Feng
@ 2021-01-04 8:42 ` gaoliming
0 siblings, 0 replies; 4+ messages in thread
From: gaoliming @ 2021-01-04 8:42 UTC (permalink / raw)
To: devel, bob.c.feng, 'Yunhua Feng'
Sure. I will check it this week.
Thanks
Liming
> -----邮件原件-----
> 发件人: bounce+27952+69529+4905953+8761045@groups.io
> <bounce+27952+69529+4905953+8761045@groups.io> 代表 Bob Feng
> 发送时间: 2021年1月4日 11:01
> 收件人: devel@edk2.groups.io; Feng, Bob C <bob.c.feng@intel.com>; Yunhua
> Feng <fengyunhua@byosoft.com.cn>; Liming Gao
> <gaoliming@byosoft.com.cn>
> 主题: Re: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the
> FMMT algorithm of LibFindFvInFd
>
> Hi Liming and Yunhua,
>
> Could you review this patch?
>
> Thanks,
> Bob
>
> -----Original Message-----
> From: devel@edk2.groups.io <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 <fengyunhua@byosoft.com.cn>; Liming Gao
> <gaoliming@byosoft.com.cn>
> Subject: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT
> algorithm 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 <bob.c.feng@intel.com>
> Cc: Yunhua Feng <fengyunhua@byosoft.com.cn>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> ---
> 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]
> = ""; CHAR8 Signature[5] = "_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;
> CurrentFv = NULL; NewFoundFv = NULL; FdBuffer
> = NULL; FdBufferOri = NULL; FirstMatch = TRUE; Index
> = 0; FdSize = 0; FvCount = 0;- Count =
> 0; LocalFdData = NULL; if (InputFile == NULL) {+ Error ("BFM",
> 0, 0001, "Error opening the input file", ""); return EFI_ABORTED; }
> // // Find each FVs in the FD@@ -204,56 +204,66 @@ LibFindFvInFd (
> fseek(InputFile,0,SEEK_SET); // // Create an FD structure to store
> useful information. //- LocalFdData = (FIRMWARE_DEVICE *) calloc
> (sizeof (FIRMWARE_DEVICE), sizeof(UINT8));+ LocalFdData =
> (FIRMWARE_DEVICE *) malloc (sizeof (FIRMWARE_DEVICE)); if
> (LocalFdData == NULL) {+ Error ("BFM", 0, 0002, "Error searching FVs in
> the input fd", "Allocate memory error"); return
> EFI_OUT_OF_RESOURCES; }- LocalFdData->Fv = (FV_INFORMATION *)
> calloc (sizeof (FV_INFORMATION), sizeof(UINT8));+ LocalFdData->Fv =
> (FV_INFORMATION *) malloc (sizeof (FV_INFORMATION)); if
> (LocalFdData->Fv == 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); // // Readout the FD file data to buffer. //
> FdBuffer = malloc (FdSize); if (FdBuffer == 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) !=
> 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 = FdBuffer;+
> FdBufferEnd = FdBuffer + FdSize; - for (Count=0; 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
> <= FdBufferEnd - sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {+
> FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) FdBuffer; // //
> Copy 4 bytes of fd data to check the _FVH signature //- memcpy
> (SignatureCheck, FdBuffer, 4);- FdBuffer =(UINT8 *)FdBuffer + 4;+
> memcpy (SignatureCheck, &FvHeader->Signature, 4); if
> (strncmp(SignatureCheck, Signature, 4) == 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 = (UINT8 *)FdBuffer - 28;-
> memcpy (Ffs2Guid, FdBuffer, 16);+ memcpy (Ffs2Guid,
> &FvHeader->FileSystemGuid, 16); // // Compare GUID.
> // for (Index = 0; Index < 16; Index ++) {@@ -267,32 +277,28 @@
> LibFindFvInFd (
> break; } } } - //- //
> Point to the original address- //- FdBuffer = (UINT8 *)FdBuffer
+
> 28;- // // Here we found an FV. //- if (Index ==
> 16) {+ if ((Index == 16) && ((FdBuffer + FvHeader->FvLength) <=
> FdBufferEnd)) { if (FirstMatch) {-
> LocalFdData->Fv->ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8
> *)FdBufferOri) - 0x2c;+ LocalFdData->Fv->ImageAddress =
> (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri); CurrentFv
> = LocalFdData->Fv; CurrentFv->FvNext = NULL;
> // // Store the FV name by found sequence //
> sprintf(CurrentFv->FvName, "FV%d", FvCount); FirstMatch =
> FALSE; } else { NewFoundFv =
> (FV_INFORMATION *) malloc (sizeof (FV_INFORMATION));- if
> (NULL == NewFoundFv) {+ if (NewFoundFv == 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->ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8
> *)FdBufferOri) - 0x2c;+ NewFoundFv->ImageAddress =
> (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri); //
> // Store the FV name by found sequence //
> sprintf(NewFoundFv->FvName, "FV%d", FvCount);@@ -320,19 +326,18 @@
> LibFindFvInFd (
> // CurrentFv =
> CurrentFv->FvNext; } FvCount ++;- Index =
> 0;+ FdBuffer = FdBuffer + FvHeader->FvLength;+ } else {+
> FdBuffer ++; } + } else {+ FdBuffer ++; }-- //-
> // We need to turn back 3 bytes.- //- FdBuffer = (UINT8 *)FdBuffer -
> 3; } LocalFdData->Size = FdSize; *FdData = LocalFdData;--
> 2.29.1.windows.1
>
>
>
> -=-=-=-=-=-=
> 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]
> -=-=-=-=-=-=
>
>
>
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT algorithm of LibFindFvInFd
2020-11-09 1:57 Bob Feng
@ 2021-01-14 2:40 ` Yuwei Chen
2021-01-14 3:54 ` Bob Feng
0 siblings, 1 reply; 4+ messages in thread
From: Yuwei Chen @ 2021-01-14 2:40 UTC (permalink / raw)
To: devel@edk2.groups.io, Feng, Bob C; +Cc: Yunhua Feng, Liming Gao
Reviewed-by: Yuwei Chen<yuwei.chen@intel.com>
> -----Original Message-----
> From: devel@edk2.groups.io <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 <fengyunhua@byosoft.com.cn>; Liming Gao
> <gaoliming@byosoft.com.cn>
> Subject: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT
> algorithm 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 <bob.c.feng@intel.com>
> Cc: Yunhua Feng <fengyunhua@byosoft.com.cn>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> ---
> 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] = ""; CHAR8 Signature[5]
> = "_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; CurrentFv = NULL;
> NewFoundFv = NULL; FdBuffer = NULL; FdBufferOri = NULL;
> FirstMatch = TRUE; Index = 0; FdSize = 0; FvCount = 0;-
> Count = 0; LocalFdData = NULL; if (InputFile == NULL) {+ Error
> ("BFM", 0, 0001, "Error opening the input file", ""); return EFI_ABORTED; }
> // // Find each FVs in the FD@@ -204,56 +204,66 @@ LibFindFvInFd (
> fseek(InputFile,0,SEEK_SET); // // Create an FD structure to store useful
> information. //- LocalFdData = (FIRMWARE_DEVICE *) calloc (sizeof
> (FIRMWARE_DEVICE), sizeof(UINT8));+ LocalFdData = (FIRMWARE_DEVICE
> *) malloc (sizeof (FIRMWARE_DEVICE)); if (LocalFdData == NULL) {+ Error
> ("BFM", 0, 0002, "Error searching FVs in the input fd", "Allocate memory
> error"); return EFI_OUT_OF_RESOURCES; }- LocalFdData->Fv =
> (FV_INFORMATION *) calloc (sizeof (FV_INFORMATION), sizeof(UINT8));+
> LocalFdData->Fv = (FV_INFORMATION *) malloc (sizeof (FV_INFORMATION));
> if (LocalFdData->Fv == 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); //
> // Readout the FD file data to buffer. // FdBuffer = malloc (FdSize); if
> (FdBuffer == 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) != 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 =
> FdBuffer;+ FdBufferEnd = FdBuffer + FdSize; - for (Count=0; 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
> <= FdBufferEnd - sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {+ FvHeader =
> (EFI_FIRMWARE_VOLUME_HEADER *) FdBuffer; // // Copy 4 bytes of fd
> data to check the _FVH signature //- memcpy (SignatureCheck, FdBuffer,
> 4);- FdBuffer =(UINT8 *)FdBuffer + 4;+ memcpy (SignatureCheck,
> &FvHeader->Signature, 4); if (strncmp(SignatureCheck, Signature, 4) ==
> 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 = (UINT8 *)FdBuffer - 28;- memcpy (Ffs2Guid,
> FdBuffer, 16);+ memcpy (Ffs2Guid, &FvHeader->FileSystemGuid, 16);
> // // Compare GUID. // for (Index = 0; Index < 16; Index ++) {@@ -
> 267,32 +277,28 @@ LibFindFvInFd (
> break; } } } - //- // Point to the original address-
> //- FdBuffer = (UINT8 *)FdBuffer + 28;- // // Here we found an FV.
> //- if (Index == 16) {+ if ((Index == 16) && ((FdBuffer + FvHeader-
> >FvLength) <= FdBufferEnd)) { if (FirstMatch) {- LocalFdData->Fv-
> >ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) - 0x2c;+
> LocalFdData->Fv->ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8
> *)FdBufferOri); CurrentFv = LocalFdData->Fv;
> CurrentFv->FvNext = NULL; // // Store the FV name by
> found sequence // sprintf(CurrentFv->FvName, "FV%d", FvCount);
> FirstMatch = FALSE; } else { NewFoundFv = (FV_INFORMATION *)
> malloc (sizeof (FV_INFORMATION));- if (NULL == NewFoundFv) {+
> if (NewFoundFv == 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->ImageAddress =
> (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) - 0x2c;+
> NewFoundFv->ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8
> *)FdBufferOri); // // Store the FV name by found sequence
> // sprintf(NewFoundFv->FvName, "FV%d", FvCount);@@ -320,19
> +326,18 @@ LibFindFvInFd (
> // CurrentFv = CurrentFv->FvNext; } FvCount
> ++;- Index = 0;+ FdBuffer = FdBuffer + FvHeader->FvLength;+ } else
> {+ FdBuffer ++; } + } else {+ FdBuffer ++; }-- //- // We need to
> turn back 3 bytes.- //- FdBuffer = (UINT8 *)FdBuffer - 3; } LocalFdData-
> >Size = FdSize; *FdData = LocalFdData;--
> 2.29.1.windows.1
>
>
>
> -=-=-=-=-=-=
> 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]
> -=-=-=-=-=-=
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT algorithm of LibFindFvInFd
2021-01-14 2:40 ` [edk2-devel] " Yuwei Chen
@ 2021-01-14 3:54 ` Bob Feng
0 siblings, 0 replies; 4+ messages in thread
From: Bob Feng @ 2021-01-14 3:54 UTC (permalink / raw)
To: Chen, Christine, devel@edk2.groups.io; +Cc: Yunhua Feng, Liming Gao
Pushed at d911c5720f3fde5ffe72bbc4230a77025adf2e62
-----Original Message-----
From: Chen, Christine <yuwei.chen@intel.com>
Sent: Thursday, January 14, 2021 10:41 AM
To: devel@edk2.groups.io; Feng, Bob C <bob.c.feng@intel.com>
Cc: Yunhua Feng <fengyunhua@byosoft.com.cn>; Liming Gao <gaoliming@byosoft.com.cn>
Subject: RE: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT algorithm of LibFindFvInFd
Reviewed-by: Yuwei Chen<yuwei.chen@intel.com>
> -----Original Message-----
> From: devel@edk2.groups.io <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 <fengyunhua@byosoft.com.cn>; Liming Gao
> <gaoliming@byosoft.com.cn>
> Subject: [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the
> FMMT algorithm 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 <bob.c.feng@intel.com>
> Cc: Yunhua Feng <fengyunhua@byosoft.com.cn>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> ---
> 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] = ""; CHAR8 Signature[5]
> = "_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; CurrentFv = NULL;
> NewFoundFv = NULL; FdBuffer = NULL; FdBufferOri = NULL;
> FirstMatch = TRUE; Index = 0; FdSize = 0; FvCount = 0;-
> Count = 0; LocalFdData = NULL; if (InputFile == NULL) {+ Error
> ("BFM", 0, 0001, "Error opening the input file", ""); return EFI_ABORTED; }
> // // Find each FVs in the FD@@ -204,56 +204,66 @@ LibFindFvInFd (
> fseek(InputFile,0,SEEK_SET); // // Create an FD structure to store useful
> information. //- LocalFdData = (FIRMWARE_DEVICE *) calloc (sizeof
> (FIRMWARE_DEVICE), sizeof(UINT8));+ LocalFdData = (FIRMWARE_DEVICE
> *) malloc (sizeof (FIRMWARE_DEVICE)); if (LocalFdData == NULL) {+ Error
> ("BFM", 0, 0002, "Error searching FVs in the input fd", "Allocate memory
> error"); return EFI_OUT_OF_RESOURCES; }- LocalFdData->Fv =
> (FV_INFORMATION *) calloc (sizeof (FV_INFORMATION), sizeof(UINT8));+
> LocalFdData->Fv = (FV_INFORMATION *) malloc (sizeof
> LocalFdData->(FV_INFORMATION));
> if (LocalFdData->Fv == 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); //
> // Readout the FD file data to buffer. // FdBuffer = malloc (FdSize); if
> (FdBuffer == 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) != 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 =
> FdBuffer;+ FdBufferEnd = FdBuffer + FdSize; - for (Count=0; 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
> <= FdBufferEnd - sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {+ FvHeader =
> (EFI_FIRMWARE_VOLUME_HEADER *) FdBuffer; // // Copy 4 bytes of fd
> data to check the _FVH signature //- memcpy (SignatureCheck, FdBuffer,
> 4);- FdBuffer =(UINT8 *)FdBuffer + 4;+ memcpy (SignatureCheck,
> &FvHeader->Signature, 4); if (strncmp(SignatureCheck, Signature, 4) ==
> 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 = (UINT8 *)FdBuffer - 28;- memcpy (Ffs2Guid,
> FdBuffer, 16);+ memcpy (Ffs2Guid, &FvHeader->FileSystemGuid, 16);
> // // Compare GUID. // for (Index = 0; Index < 16; Index ++) {@@ -
> 267,32 +277,28 @@ LibFindFvInFd (
> break; } } } - //- // Point to the original address-
> //- FdBuffer = (UINT8 *)FdBuffer + 28;- // // Here we found an FV.
> //- if (Index == 16) {+ if ((Index == 16) && ((FdBuffer + FvHeader-
> >FvLength) <= FdBufferEnd)) { if (FirstMatch) {- LocalFdData->Fv-
> >ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) -
> >0x2c;+
> LocalFdData->Fv->ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8
> *)FdBufferOri); CurrentFv = LocalFdData->Fv;
> CurrentFv->FvNext = NULL; // // Store the FV name by
> found sequence // sprintf(CurrentFv->FvName, "FV%d", FvCount);
> FirstMatch = FALSE; } else { NewFoundFv = (FV_INFORMATION *)
> malloc (sizeof (FV_INFORMATION));- if (NULL == NewFoundFv) {+
> if (NewFoundFv == 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->ImageAddress =
> (UINTN)((UINT8 *)FdBuffer - (UINT8 *)FdBufferOri) - 0x2c;+
> NewFoundFv->ImageAddress = (UINTN)((UINT8 *)FdBuffer - (UINT8
> *)FdBufferOri); // // Store the FV name by found sequence
> // sprintf(NewFoundFv->FvName, "FV%d", FvCount);@@ -320,19
> +326,18 @@ LibFindFvInFd (
> // CurrentFv = CurrentFv->FvNext; } FvCount
> ++;- Index = 0;+ FdBuffer = FdBuffer + FvHeader->FvLength;+ } else
> {+ FdBuffer ++; } + } else {+ FdBuffer ++; }-- //- // We need to
> turn back 3 bytes.- //- FdBuffer = (UINT8 *)FdBuffer - 3; } LocalFdData-
> >Size = FdSize; *FdData = LocalFdData;--
> 2.29.1.windows.1
>
>
>
> -=-=-=-=-=-=
> 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] -=-=-=-=-=-=
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-01-14 3:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1645B458920B2EFC.8542@groups.io>
2021-01-04 3:01 ` [edk2-devel] [Patch] [edk2-staging]BaseTools/Bfm: Apply the FMMT algorithm of LibFindFvInFd Bob Feng
2021-01-04 8:42 ` 回复: " gaoliming
2020-11-09 1:57 Bob Feng
2021-01-14 2:40 ` [edk2-devel] " Yuwei Chen
2021-01-14 3:54 ` Bob Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox