From: "GregX Yeh" <gregx.yeh@intel.com>
To: devel@edk2.groups.io
Cc: Bob Feng <bob.c.feng@intel.com>, Liming Gao <gaoliming@byosoft.com.cn>
Subject: [PATCH] [edk2-staging] BaseTools/FMMT: Replace file failure when FV level over 2
Date: Fri, 27 Nov 2020 10:16:58 +0800 [thread overview]
Message-ID: <20201127021658.11480-1-gregx.yeh@intel.com> (raw)
Fixed replace file failure when FFS in multi level FV and FV level over 2.
Signed-off-by: GregX Yeh <gregx.yeh@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
---
BaseTools/Source/C/FMMT/FirmwareModuleManagement.h | 4 +-
BaseTools/Source/C/FMMT/FmmtLib.c | 654 ++++++++++-----------
2 files changed, 326 insertions(+), 332 deletions(-)
diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h
index 9d09c9160a..ccc8ba00be 100644
--- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h
+++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.h
@@ -195,7 +195,7 @@ typedef struct {
// UI Name for this FFS file, if has.
//
CHAR16 UiName[_MAX_PATH];
- UINT32 UiNameSize;
+ UINT32 UiNameSize;
//
// Total section number in this FFS.
//
@@ -208,7 +208,7 @@ typedef struct {
//
//Describe the belong to FV
//
- UINT8 FvId;
+ UINT8 FvId;
//
// If this FFS has no encapsulate section, this flag will set to True.
//
diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c b/BaseTools/Source/C/FMMT/FmmtLib.c
index b945e9b63d..d6d43030fa 100644
--- a/BaseTools/Source/C/FMMT/FmmtLib.c
+++ b/BaseTools/Source/C/FMMT/FmmtLib.c
@@ -709,10 +709,10 @@ LibGenFfsFile (
free(FfsFileName);
FfsFileName = NULL;
- CurrentFv->FfsNumbers = *FfsCount;
-
*FfsCount += 1;
+ CurrentFv->FfsNumbers = *FfsCount;
+
if (ErasePolarity) {
CurrentFile->State = (UINT8)~(CurrentFile->State);
}
@@ -833,7 +833,6 @@ LibParseSection (
CHAR8 *ToolInputFileName;
CHAR8 *ToolOutputFileName;
BOOLEAN HasUiSection;
- BOOLEAN FirstInFlag;
DataOffset = 0;
GuidAttr = 0;
@@ -869,7 +868,6 @@ LibParseSection (
EncapDataNeedUpdata = TRUE;
LargeHeaderOffset = 0;
HasUiSection = FALSE;
- FirstInFlag = TRUE;
while (ParsedLength < BufferLength) {
@@ -997,9 +995,7 @@ LibParseSection (
break;
case EFI_SECTION_COMPRESSION:
- if (FirstInFlag) {
- Level ++;
- }
+ Level ++;
NumberOfSections ++;
EncapDataNeedUpdata = TRUE;
@@ -1181,9 +1177,7 @@ LibParseSection (
// looks up the appropriate tool to use for extracting
// a GUID defined FV section.
//
- if (FirstInFlag) {
- Level ++;
- }
+ Level ++;
NumberOfSections++;
EncapDataNeedUpdata = TRUE;
HasUiSection = TRUE;
@@ -1682,7 +1676,6 @@ LibParseSection (
}
ParsedLength += SectionLength;
- FirstInFlag = FALSE;
//
// We make then next section begin on a 4-byte boundary
//
@@ -2016,7 +2009,7 @@ LibGetFileInfo (
LocalEncapData->Level = Level;
LocalEncapData->Type = FMMT_ENCAP_TREE_FFS;
- LocalEncapData->FvExtHeader = NULL;
+ LocalEncapData->FvExtHeader = NULL;
LocalEncapData->Depex = NULL;
LocalEncapData->DepexLen = 0;
LocalEncapData->UiNameSize = 0;
@@ -4198,6 +4191,7 @@ LibEncapNewFvFile(
UINT32 header;
UINT8 AlignN;
UINT8 AlignV[1] = {0xFF};
+
AlignN = 0;
Id = 0;
InputFileSize = 0;
@@ -4225,7 +4219,6 @@ LibEncapNewFvFile(
OutputFileSize = 0;
LargeFileSize = 0x1000000;
-
OutputFileNameList = (FFS_INFORMATION *)malloc(sizeof(FFS_INFORMATION));
if (OutputFileNameList == NULL) {
Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n", "");
@@ -4258,12 +4251,12 @@ LibEncapNewFvFile(
//
// Encapsulate from the lowest FFS file level.
//
- LocalEncapData = CurrentEncapData;
- if (LocalEncapData == NULL) {
- LocalEncapData = FvInFd->EncapData;
- }
- Level = LocalEncapData->Level;
- Type = LocalEncapData->Type;
+ LocalEncapData = CurrentEncapData;
+ if (LocalEncapData == NULL) {
+ LocalEncapData = FvInFd->EncapData;
+ }
+ Level = LocalEncapData->Level;
+ Type = LocalEncapData->Type;
if (CurrentEncapData == NULL) {
LocalEncapData = FvInFd->EncapData;
@@ -4271,22 +4264,21 @@ LibEncapNewFvFile(
if (LocalEncapData->Type == FMMT_ENCAP_TREE_FFS) {
LocalEncapDataTemp = LocalEncapData->RightNode;
while (LocalEncapDataTemp != NULL) {
- LocalEncapDataNext = LocalEncapDataTemp->NextNode;
- if (LocalEncapDataNext != NULL && LocalEncapDataNext->NextNode != NULL) {
-
- LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, 1, &ChildFileNameList);
- ChildFileNameList->ParentLevel = LocalEncapDataTemp->Level -1;
- if (FvInFd->ChildFvFFS == NULL) {
- FvInFd->ChildFvFFS = ChildFileNameList;
- } else {
- NewFileNameList = FvInFd->ChildFvFFS;
- while (NewFileNameList->Next != NULL) {
- NewFileNameList = NewFileNameList->Next;
- }
- NewFileNameList->Next = ChildFileNameList;
+ LocalEncapDataNext = LocalEncapDataTemp->NextNode;
+ if(LocalEncapDataNext != NULL && LocalEncapDataNext->NextNode != NULL) {
+ LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEncapDataTemp->Level-1, &ChildFileNameList);
+ //ChildFileNameList->ParentLevel = LocalEncapDataTemp->Level -1;
+ if (FvInFd->ChildFvFFS == NULL) {
+ FvInFd->ChildFvFFS = ChildFileNameList;
+ } else {
+ NewFileNameList = FvInFd->ChildFvFFS;
+ while (NewFileNameList->Next != NULL) {
+ NewFileNameList = NewFileNameList->Next;
}
+ NewFileNameList->Next = ChildFileNameList;
}
- LocalEncapDataTemp = LocalEncapDataTemp->RightNode;
+ }
+ LocalEncapDataTemp = LocalEncapDataTemp->RightNode;
}
}
@@ -4329,24 +4321,24 @@ LibEncapNewFvFile(
} else {
LocalEncapData = CurrentEncapData;
while (LocalEncapData != NULL) {
- if (Level_Break > 1 && LocalEncapData->Type == FMMT_ENCAP_TREE_FFS) {
+ if (LocalEncapData->Type == FMMT_ENCAP_TREE_FFS) {
LocalEncapDataTemp = LocalEncapData->RightNode;
while (LocalEncapDataTemp != NULL) {
- LocalEncapDataNext = LocalEncapDataTemp->NextNode;
- if (LocalEncapDataNext != NULL && LocalEncapDataNext->NextNode != NULL) {
- LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEncapDataTemp->Level-1, &ChildFileNameList);
- //ChildFileNameList->ParentLevel = LocalEncapDataTemp->Level -1;
- if (FvInFd->ChildFvFFS == NULL) {
- FvInFd->ChildFvFFS = ChildFileNameList;
- } else {
- NewFileNameList = FvInFd->ChildFvFFS;
- while (NewFileNameList->Next != NULL) {
- NewFileNameList = NewFileNameList->Next;
- }
- NewFileNameList->Next = ChildFileNameList;
+ LocalEncapDataNext = LocalEncapDataTemp->NextNode;
+ if (LocalEncapDataNext != NULL && LocalEncapDataNext->NextNode != NULL) {
+ LibEncapNewFvFile(FvInFd, TemDir, LocalEncapDataTemp, LocalEncapDataTemp->Level-1, &ChildFileNameList);
+ //ChildFileNameList->ParentLevel = LocalEncapDataTemp->Level -1;
+ if (FvInFd->ChildFvFFS == NULL) {
+ FvInFd->ChildFvFFS = ChildFileNameList;
+ } else {
+ NewFileNameList = FvInFd->ChildFvFFS;
+ while (NewFileNameList->Next != NULL) {
+ NewFileNameList = NewFileNameList->Next;
}
+ NewFileNameList->Next = ChildFileNameList;
}
- LocalEncapDataTemp = LocalEncapDataTemp->RightNode;
+ }
+ LocalEncapDataTemp = LocalEncapDataTemp->RightNode;
}
}
if (LocalEncapData->Level > Level) {
@@ -4366,12 +4358,12 @@ LibEncapNewFvFile(
case FMMT_ENCAP_TREE_FV:
OutputFileNameListFlag = TRUE;
EncapFvStart = 0;
- for(OuterIndex=0;OutputFileNameListFlag;OuterIndex++){
+ for(OuterIndex=0;OutputFileNameListFlag;OuterIndex++){
//
// Generate FV.inf attributes.
//
InfFileName = LibFilenameStrExtended (strrchr(GenTempFile (),OS_SEP), TemDir, "inf");
- FirstInFlag = TRUE;
+ FirstInFlag = TRUE;
InfFile = fopen (InfFileName, "wt+");
@@ -4383,9 +4375,9 @@ LibEncapNewFvFile(
}
if (CurrentEncapData == NULL) {
- LocalEncapData = FvInFd->EncapData;
+ LocalEncapData = FvInFd->EncapData;
} else {
- LocalEncapData = CurrentEncapData;
+ LocalEncapData = CurrentEncapData;
}
while (LocalEncapData->NextNode != NULL) {
@@ -4456,6 +4448,7 @@ LibEncapNewFvFile(
free (ChildFileNameList);
return Status;
}
+
if (LocalEncapData->FvExtHeader != NULL) {
Status = LibGenExtFile(LocalEncapData->FvExtHeader, InfFile);
if (EFI_ERROR(Status)) {
@@ -4473,93 +4466,93 @@ LibEncapNewFvFile(
while (LocalEncapData->Level != ParentLevel) {
LocalEncapData = LocalEncapData->NextNode;
}
- for (Index = 0; Index <= FvInFd->FfsNumbers; Index++) {
- if ((memcmp(&FvInFd->FfsAttuibutes[Index].GuidName, &(LocalEncapData->FvExtHeader->FvName), sizeof(EFI_GUID)) == 0)) {
- SubFvId = Index;
- break;
- }
+ for (Index = 0; Index <= FvInFd->FfsNumbers; Index++) {
+ if ((memcmp(&FvInFd->FfsAttuibutes[Index].GuidName, &(LocalEncapData->FvExtHeader->FvName), sizeof(EFI_GUID)) == 0)) {
+ SubFvId = Index;
+ break;
}
+ }
}
//
// Found FFSs from Fv structure.
//
FfsFoundFlag = FALSE;
IsRootFv = FALSE;
- for (Index=0; Index <= FvInFd->FfsNumbers; Index++) {
- if (OutputFileNameList != NULL && OutputFileNameList->FFSName != NULL && OutputFileNameList->IsFFS == FALSE){
- break;
- }
- if (OutputFileNameList != NULL && OutputFileNameList->FFSName != NULL && OutputFileNameList->IsFFS == TRUE){
- if (Index == EncapFvIndex) {
- if (FirstInFlag) {
- Status = LibAddFfsFileToFvInf (OutputFileNameList->FFSName, InfFile, TRUE);
- FirstInFlag = FALSE;
- } else {
- Status = LibAddFfsFileToFvInf (OutputFileNameList->FFSName, InfFile, FALSE);
- }
- if (EFI_ERROR (Status)) {
- Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FV inf file [files] section failed!");
- fclose (InfFile);
- free (OutputFileNameList);
- free (ChildFileNameList);
- return Status;
- }
- }
+ for (Index = 0; Index < FvInFd->FfsNumbers; Index++) {
+ if (OutputFileNameList != NULL && OutputFileNameList->FFSName != NULL && OutputFileNameList->IsFFS == FALSE){
+ break;
+ }
+ if (OutputFileNameList != NULL && OutputFileNameList->FFSName != NULL && OutputFileNameList->IsFFS == TRUE){
+ if (Index == EncapFvIndex) {
+ if (FirstInFlag) {
+ Status = LibAddFfsFileToFvInf (OutputFileNameList->FFSName, InfFile, TRUE);
+ FirstInFlag = FALSE;
+ } else {
+ Status = LibAddFfsFileToFvInf (OutputFileNameList->FFSName, InfFile, FALSE);
+ }
+ if (EFI_ERROR (Status)) {
+ Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FV inf file [files] section failed!");
+ fclose (InfFile);
+ free (OutputFileNameList);
+ free (ChildFileNameList);
+ return Status;
+ }
}
+ }
- NewFileNameList = FvInFd->ChildFvFFS;
- while (NewFileNameList != NULL && NewFileNameList -> FFSName != NULL) {
- if (NewFileNameList -> ParentLevel == ParentLevel && Index == NewFileNameList->InFvId && NewFileNameList->FfsFoundFlag==TRUE) {
- if (FirstInFlag) {
- Status = LibAddFfsFileToFvInf (NewFileNameList->FFSName, InfFile, TRUE);
- FirstInFlag = FALSE;
- } else {
- Status = LibAddFfsFileToFvInf (NewFileNameList->FFSName, InfFile, FALSE);
- }
- if (EFI_ERROR (Status)) {
- Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FV inf file [files] section failed!");
- fclose (InfFile);
- free (OutputFileNameList);
- free (ChildFileNameList);
- return Status;
- }
- NewFileNameList->FfsFoundFlag = FALSE;
- }
- NewFileNameList = NewFileNameList->Next;
+ NewFileNameList = FvInFd->ChildFvFFS;
+ while (NewFileNameList != NULL && NewFileNameList -> FFSName != NULL) {
+ if (NewFileNameList -> ParentLevel == ParentLevel && Index == NewFileNameList->InFvId && NewFileNameList->FfsFoundFlag==TRUE) {
+ if (FirstInFlag) {
+ Status = LibAddFfsFileToFvInf (NewFileNameList->FFSName, InfFile, TRUE);
+ FirstInFlag = FALSE;
+ } else {
+ Status = LibAddFfsFileToFvInf (NewFileNameList->FFSName, InfFile, FALSE);
+ }
+ if (EFI_ERROR (Status)) {
+ Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FV inf file [files] section failed!");
+ fclose (InfFile);
+ free (OutputFileNameList);
+ free (ChildFileNameList);
+ return Status;
+ }
+ NewFileNameList->FfsFoundFlag = FALSE;
}
+ NewFileNameList = NewFileNameList->Next;
+ }
- if (FvInFd->FfsAttuibutes[Index].IsHandle==TRUE) {
- continue;
- }
- if (SubFvId > 0 && Index < SubFvId) {
- continue;
- }
+ if (FvInFd->FfsAttuibutes[Index].IsHandle==TRUE) {
+ continue;
+ }
+ if (SubFvId > 0 && Index < SubFvId) {
+ continue;
+ }
//
// For the last level FFS, the level below FFSs we should not care the IsLeaf Flag.
//
if (IsLastLevelFfs) {
IsLeafFlagIgnore = TRUE;
- } else {
- IsLeafFlagIgnore = FvInFd->FfsAttuibutes[Index].IsLeaf;
- }
+ } else {
+ IsLeafFlagIgnore = FvInFd->FfsAttuibutes[Index].IsLeaf;
+ }
if (FvInFd->FfsAttuibutes[Index].FvId == LocalEncapData->FvId && FvInFd->FfsAttuibutes[Index].Level >= ParentLevel + 1 && IsLeafFlagIgnore) {
if (FirstInFlag) {
- if (FvInFd->FfsAttuibutes[Index].Level < 0xFF) {
- FfsFoundFlag = TRUE;
- Status = LibAddFfsFileToFvInf (FvInFd->FfsAttuibutes[Index].FfsName, InfFile, TRUE);
- FirstInFlag = FALSE;
- FvInFd->FfsAttuibutes[Index].IsHandle=TRUE;
- EncapFvStart = Index;
- }
+ if (FvInFd->FfsAttuibutes[Index].Level < 0xFF) {
+ FfsFoundFlag = TRUE;
+ Status = LibAddFfsFileToFvInf (FvInFd->FfsAttuibutes[Index].FfsName, InfFile, TRUE);
+ FirstInFlag = FALSE;
+ FvInFd->FfsAttuibutes[Index].IsHandle=TRUE;
+ EncapFvStart = Index;
+ }
if (EFI_ERROR (Status)) {
- Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FV inf file [files] section failed!");
- fclose (InfFile);
- free (OutputFileNameList);
- free (ChildFileNameList);
- return Status;
+ Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FV inf file [files] section failed!");
+ fclose (InfFile);
+ free (OutputFileNameList);
+ free (ChildFileNameList);
+ return Status;
}
if (Index == 0) {
// Root FV need to include all FFS files.
@@ -4586,33 +4579,32 @@ LibEncapNewFvFile(
}
- //avoid a FV contain too many ffs files
- if ((!IsRootFv) && (FvInFd->FfsAttuibutes[Index].FvLevel <= FvInFd->MulFvLevel) && (FvInFd->FfsAttuibutes[Index+1].FvLevel <= FvInFd->MulFvLevel) &&
- (FvInFd->FfsAttuibutes[Index].FvLevel != FvInFd->FfsAttuibutes[Index+1].FvLevel) && (ParentLevel != 1) && (FvInFd->FfsAttuibutes[Index].Level != FvInFd->FfsAttuibutes[Index+1].Level) &&
- FvInFd->FfsAttuibutes[Index].Level != 0xFF && FvInFd->FfsAttuibutes[Index+1].Level != 0xFF && FvInFd->FfsAttuibutes[Index+1].Level != 0x0){
- FvInFd->FfsAttuibutes[Index].Level = 0;
- break;
- }else{
- if (FvInFd->FfsAttuibutes[Index].Level != 0xFF){
- FvInFd->FfsAttuibutes[Index].Level = 0;
- }
- }
-
+ //avoid a FV contain too many ffs files
+ if ((!IsRootFv) && (FvInFd->FfsAttuibutes[Index].FvLevel <= FvInFd->MulFvLevel) && (FvInFd->FfsAttuibutes[Index+1].FvLevel <= FvInFd->MulFvLevel) &&
+ (FvInFd->FfsAttuibutes[Index].FvLevel != FvInFd->FfsAttuibutes[Index+1].FvLevel) && (ParentLevel != 1) && (FvInFd->FfsAttuibutes[Index].Level != FvInFd->FfsAttuibutes[Index+1].Level) &&
+ FvInFd->FfsAttuibutes[Index].Level != 0xFF && FvInFd->FfsAttuibutes[Index+1].Level != 0xFF && FvInFd->FfsAttuibutes[Index+1].Level != 0x0){
+ FvInFd->FfsAttuibutes[Index].Level = 0;
+ break;
+ } else {
+ if (FvInFd->FfsAttuibutes[Index].Level != 0xFF){
+ FvInFd->FfsAttuibutes[Index].Level = 0;
+ }
}
}
- // The Fv may has multiple level (> 2), when it is in the FvLevel == 2, we set the IsLastLevelFfs Flag
- if (Index <=FvInFd->FfsNumbers && FvInFd->FfsAttuibutes[Index].FvLevel <= FvInFd->MulFvLevel) {
- if (FvInFd->FfsAttuibutes[Index].FvLevel == 2) {
- IsLastLevelFfs = FALSE;
- }
- }
- if (!FfsFoundFlag){
- OutputFileNameListFlag = FALSE;
- if (OuterIndex > 0){
- fclose (InfFile);
- break;
- }
- }
+ }
+ // The Fv may has multiple level (> 2), when it is in the FvLevel == 2, we set the IsLastLevelFfs Flag
+ if (Index <=FvInFd->FfsNumbers && FvInFd->FfsAttuibutes[Index].FvLevel <= FvInFd->MulFvLevel) {
+ if (FvInFd->FfsAttuibutes[Index].FvLevel == 2) {
+ IsLastLevelFfs = FALSE;
+ }
+ }
+ if (!FfsFoundFlag){
+ OutputFileNameListFlag = FALSE;
+ if (OuterIndex > 0){
+ fclose (InfFile);
+ break;
+ }
+ }
//
// Create FV
//
@@ -4631,15 +4623,15 @@ LibEncapNewFvFile(
return Status;
}
- OutputFileNameList->FFSName = (char *)malloc(strlen(OutputFileName)+1);
- if (OutputFileNameList->FFSName == NULL) {
- Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n", "");
- return EFI_OUT_OF_RESOURCES;
- }
- memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, strlen(OutputFileName)+1);
- if (CurrentEncapData != NULL) {
- OutputFileNameList->InFvId = EncapFvIndex;
- if (EncapFvIndex > 0) {
+ OutputFileNameList->FFSName = (char *)malloc(strlen(OutputFileName)+1);
+ if (OutputFileNameList->FFSName == NULL) {
+ Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n", "");
+ return EFI_OUT_OF_RESOURCES;
+ }
+ memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, strlen(OutputFileName)+1);
+ if (CurrentEncapData != NULL) {
+ OutputFileNameList->InFvId = EncapFvIndex;
+ if (EncapFvIndex > 0) {
memcpy(OutputFileNameList->UiName,FvInFd->FfsAttuibutes[EncapFvIndex - 1].UiName, FvInFd->FfsAttuibutes[EncapFvIndex - 1].UiNameSize);
OutputFileNameList->UiNameSize = FvInFd->FfsAttuibutes[EncapFvIndex - 1].UiNameSize;
OutputFileNameList->Depex = FvInFd->FfsAttuibutes[EncapFvIndex - 1].Depex;
@@ -4647,9 +4639,9 @@ LibEncapNewFvFile(
OutputFileNameList->FfsFoundFlag = FfsFoundFlag;
OutputFileNameList->FvId = FvInFd->FfsAttuibutes[EncapFvIndex - 1].FvId;
OutputFileNameList->ParentLevel = ParentLevel - 1;
+ }
+ }
}
- }
- }
break;
case FMMT_ENCAP_TREE_FFS:
@@ -4662,13 +4654,13 @@ LibEncapNewFvFile(
}
while (LocalEncapData->NextNode != NULL) {
if (LocalEncapData->Level == ParentLevel) {
- for(;LocalEncapData->NextNode != NULL;) {
- if(LocalEncapData->FvExtHeader != NULL) {
- break;
- }
- LocalEncapData = LocalEncapData->NextNode;
- }
- break;
+ for(;LocalEncapData->NextNode != NULL;) {
+ if(LocalEncapData->FvExtHeader != NULL) {
+ break;
+ }
+ LocalEncapData = LocalEncapData->NextNode;
+ }
+ break;
}
LocalEncapData = LocalEncapData->NextNode;
}
@@ -4728,101 +4720,106 @@ LibEncapNewFvFile(
InputFileName = TmpFileName;
}
if (OutputFileNameList->DepexLen > 0) {
- TmpFileName = LibFilenameStrExtended(strrchr(GenTempFile (), OS_SEP), TemDir, "tmp");
- TmpFile = fopen(TmpFileName, "wb+");
- if (TmpFile == NULL) {
- Error("FMMT", 0, 0004, "Could not open tmp file %s to store Depex section information! \n", "");
- free (OutputFileNameList);
- free (ChildFileNameList);
- return EFI_ABORTED;
- }
- InputFile = fopen(InputFileName, "rb+");
- if (InputFile == NULL) {
- Error("FMMT", 0, 0004, "Could not open input file %s! \n", "");
+ TmpFileName = LibFilenameStrExtended(strrchr(GenTempFile (), OS_SEP), TemDir, "tmp");
+ TmpFile = fopen(TmpFileName, "wb+");
+ if (TmpFile == NULL) {
+ Error("FMMT", 0, 0004, "Could not open tmp file %s to store Depex section information! \n", "");
+ free (OutputFileNameList);
+ free (ChildFileNameList);
+ return EFI_ABORTED;
+ }
+ InputFile = fopen(InputFileName, "rb+");
+ if (InputFile == NULL) {
+ Error("FMMT", 0, 0004, "Could not open input file %s! \n", "");
+ fclose(TmpFile);
+ free (OutputFileNameList);
+ free (ChildFileNameList);
+ return EFI_ABORTED;
+ }
+ fseek(InputFile, 0, SEEK_SET);
+ fseek(InputFile, 0, SEEK_END);
+ InputFileSize = ftell(InputFile);
+ fseek(InputFile, 0, SEEK_SET);
+ // make sure the section is 4 byte align
+ if (OutputFileNameList->DepexLen % 4 != 0) {
+ AlignN = 4 - OutputFileNameList->DepexLen % 4;
+ }
+ Buffer = malloc(InputFileSize + OutputFileNameList->DepexLen + AlignN);
+ memcpy(Buffer, OutputFileNameList->Depex, OutputFileNameList->DepexLen);
+ if (AlignN != 0) {
+ for (Index = 0; Index < AlignN; Index ++) {
+ memcpy(Buffer + OutputFileNameList->DepexLen + Index, AlignV, 1);
+ }
+ }
+ if (fread(Buffer + OutputFileNameList->DepexLen + AlignN, 1, InputFileSize, InputFile) != InputFileSize) {
+ Error("FMMT", 0, 0004, "Could not open sec file %s to add Depex section information! \n", "");
fclose(TmpFile);
+ fclose(InputFile);
+ free(Buffer);
free (OutputFileNameList);
free (ChildFileNameList);
return EFI_ABORTED;
+ }
+ fwrite(Buffer, 1, InputFileSize + OutputFileNameList->DepexLen + AlignN, TmpFile);
+ free(Buffer);
+ fclose(TmpFile);
+ fclose(InputFile);
+ InputFileName = TmpFileName;
+ }
+ //
+ // Delete origin FFS
+ //
+ for (Id = FvInFd->FfsNumbers; Id <= FvInFd->FfsNumbers; Id--) {
+ if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(LocalEncapData->FvExtHeader->FvName), sizeof(EFI_GUID)) == 0)){
+ if (access(FvInFd->FfsAttuibutes[Id].FfsName, 0) != -1) {
+ Status = LibFmmtDeleteFile(FvInFd->FfsAttuibutes[Id].FfsName);
+ if (EFI_ERROR(Status)) {
+ Error("FMMT", 0, 0004, "error while encapsulate FD Image", "Delete the specified file failed!");
+ free (OutputFileNameList);
+ free (ChildFileNameList);
+ return Status;
+ }
+ memset(FvInFd->FfsAttuibutes[Id].FfsName, '\0', _MAX_PATH);
+ FvInFd->FfsAttuibutes[Id].Level = 0xFF;
+ break;
}
- fseek(InputFile, 0, SEEK_SET);
- fseek(InputFile, 0, SEEK_END);
- InputFileSize = ftell(InputFile);
- fseek(InputFile, 0, SEEK_SET);
- // make sure the section is 4 byte align
- if (OutputFileNameList->DepexLen % 4 != 0) {
- AlignN = 4 - OutputFileNameList->DepexLen % 4;
- }
- Buffer = malloc(InputFileSize + OutputFileNameList->DepexLen + AlignN);
- memcpy(Buffer, OutputFileNameList->Depex, OutputFileNameList->DepexLen);
- if (AlignN != 0) {
- for (Index = 0; Index < AlignN; Index ++) {
- memcpy(Buffer + OutputFileNameList->DepexLen + Index, AlignV, 1);
- }
- }
- if (fread(Buffer + OutputFileNameList->DepexLen + AlignN, 1, InputFileSize, InputFile) != InputFileSize) {
- Error("FMMT", 0, 0004, "Could not open sec file %s to add Depex section information! \n", "");
- fclose(TmpFile);
- fclose(InputFile);
- free(Buffer);
- free (OutputFileNameList);
- free (ChildFileNameList);
- return EFI_ABORTED;
- }
- fwrite(Buffer, 1, InputFileSize + OutputFileNameList->DepexLen + AlignN, TmpFile);
- free(Buffer);
- fclose(TmpFile);
- fclose(InputFile);
- InputFileName = TmpFileName;
- }
- for (Id = FvInFd->FfsNumbers; Id <= FvInFd->FfsNumbers; Id--) {
- if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(LocalEncapData->FvExtHeader->FvName), sizeof(EFI_GUID)) == 0)){
- if (access(FvInFd->FfsAttuibutes[Id].FfsName, 0) != -1) {
- Status = LibFmmtDeleteFile(FvInFd->FfsAttuibutes[Id].FfsName);
- if (EFI_ERROR(Status)) {
- Error("FMMT", 0, 0004, "error while encapsulate FD Image", "Delete the specified file failed!");
- free (OutputFileNameList);
- free (ChildFileNameList);
- return Status;
- }
- memset(FvInFd->FfsAttuibutes[Id].FfsName, '\0', _MAX_PATH);
- FvInFd->FfsAttuibutes[Id].Level = 0xFF;
- break;
- }
- }
- }
- if (LocalEncapData->NextNode != NULL) {
- LocalEncapDataTemp = LocalEncapData->NextNode;
- if ((LocalEncapDataTemp->Type == FMMT_ENCAP_TREE_GUIDED_SECTION) || (LocalEncapDataTemp->Type == FMMT_ENCAP_TREE_COMPRESS_SECTION)) {
- Status = LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->FvName, FALSE, "1");
- }
- else{
- Status = LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->FvName, FALSE, FvInFd->AlignmentStr);
- }
- }
- else{
- Status = LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->FvName, FALSE, FvInFd->AlignmentStr);
- }
- if (EFI_ERROR (Status)) {
- Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FFS file failed!");
- free (OutputFileNameList);
- free (ChildFileNameList);
- return Status;
- }
- free(LocalEncapData->FvExtHeader);
- LocalEncapData->FvExtHeader = NULL;
- OutputFileNameList->FFSName = (char *)malloc(strlen(OutputFileName)+1);
- if (OutputFileNameList->FFSName == NULL) {
- Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n", "");
- return EFI_OUT_OF_RESOURCES;
- }
- memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, strlen(OutputFileName)+1);
- OutputFileNameList->IsFFS = TRUE;
- OutputFileNameList->ParentLevel = ParentLevel - 1;
- if (OutputFileNameList->Next == NULL){
- break;
- }
- OutputFileNameList = OutputFileNameList->Next;
- }
+ }
+ }
+ if (LocalEncapData->NextNode != NULL) {
+ LocalEncapDataTemp = LocalEncapData->NextNode;
+ if ((LocalEncapDataTemp->Type == FMMT_ENCAP_TREE_GUIDED_SECTION) || (LocalEncapDataTemp->Type == FMMT_ENCAP_TREE_COMPRESS_SECTION)) {
+ Status = LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->FvName, FALSE, "1");
+ } else{
+ Status = LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->FvName, FALSE, FvInFd->AlignmentStr);
+ }
+ } else{
+ Status = LibEncapSectionFileToFFS(EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, InputFileName, OutputFileName, LocalEncapData->FvExtHeader->FvName, FALSE, FvInFd->AlignmentStr);
+ }
+
+ if (EFI_ERROR (Status)) {
+ Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FFS file failed!");
+ free (OutputFileNameList);
+ free (ChildFileNameList);
+ return Status;
+ }
+
+ free(LocalEncapData->FvExtHeader);
+ LocalEncapData->FvExtHeader = NULL;
+
+ OutputFileNameList->FFSName = (char *)malloc(strlen(OutputFileName)+1);
+ if (OutputFileNameList->FFSName == NULL) {
+ Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n", "");
+ return EFI_OUT_OF_RESOURCES;
+ }
+ memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, strlen(OutputFileName)+1);
+ OutputFileNameList->IsFFS = TRUE;
+ OutputFileNameList->ParentLevel = ParentLevel - 1;
+ OutputFileNameList->InFvId = Id;
+ if (OutputFileNameList->Next == NULL){
+ break;
+ }
+ OutputFileNameList = OutputFileNameList->Next;
+ }
break;
case FMMT_ENCAP_TREE_GUIDED_SECTION:
while(OutputFileNameList!= NULL && OutputFileNameList->FFSName != NULL){
@@ -4941,25 +4938,25 @@ LibEncapNewFvFile(
if (OutputFileSize > LargeFileSize) {
IsLargeFile = TRUE;
}
- OutputFileNameList->FFSName = (char *)malloc(strlen(OutputFileName)+1);
- if (OutputFileNameList->FFSName == NULL) {
- Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n", "");
- return EFI_OUT_OF_RESOURCES;
- }
- memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, strlen(OutputFileName)+1);
-
- if (EFI_ERROR (Status)) {
- Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate guided section failed!");
- free (OutputFileNameList);
- free (ChildFileNameList);
- return Status;
+ OutputFileNameList->FFSName = (char *)malloc(strlen(OutputFileName)+1);
+ if (OutputFileNameList->FFSName == NULL) {
+ Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n", "");
+ return EFI_OUT_OF_RESOURCES;
+ }
+ memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, strlen(OutputFileName)+1);
+
+ if (EFI_ERROR (Status)) {
+ Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate guided section failed!");
+ free (OutputFileNameList);
+ free (ChildFileNameList);
+ return Status;
+ }
+ OutputFileNameList->ParentLevel = ParentLevel - 1;
+ if (OutputFileNameList->Next == NULL) {
+ break;
+ }
+ OutputFileNameList = OutputFileNameList->Next;
}
- OutputFileNameList->ParentLevel = ParentLevel - 1;
- if (OutputFileNameList->Next == NULL){
- break;
- }
- OutputFileNameList = OutputFileNameList->Next;
- }
break;
case FMMT_ENCAP_TREE_COMPRESS_SECTION:
while(OutputFileNameList!= NULL && OutputFileNameList->FFSName != NULL){
@@ -5000,89 +4997,86 @@ LibEncapNewFvFile(
break;
case FMMT_ENCAP_TREE_FV_SECTION:
while(OutputFileNameList!= NULL && OutputFileNameList->FFSName != NULL){
- InputFileName = OutputFileNameList->FFSName;
- OutputFileName= LibFilenameStrExtended (strrchr(GenTempFile (), OS_SEP), TemDir, "sec");
-
- Status = LibCreateFfsSection(NULL, InputFileName, NULL, EFI_SECTION_FIRMWARE_VOLUME_IMAGE, OutputFileName, NULL, NULL, NULL, 0, 0, NULL);
+ InputFileName = OutputFileNameList->FFSName;
+ OutputFileName= LibFilenameStrExtended (strrchr(GenTempFile (), OS_SEP), TemDir, "sec");
- if (EFI_ERROR (Status)) {
- Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FV section failed!");
- free (OutputFileNameList);
- free (ChildFileNameList);
- return Status;
- }
+ Status = LibCreateFfsSection(NULL, InputFileName, NULL, EFI_SECTION_FIRMWARE_VOLUME_IMAGE, OutputFileName, NULL, NULL, NULL, 0, 0, NULL);
- InputFileName = OutputFileName;
- OutputFileName= LibFilenameStrExtended (strrchr(GenTempFile (), OS_SEP), TemDir, "sec");
+ if (EFI_ERROR (Status)) {
+ Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FV section failed!");
+ free (OutputFileNameList);
+ free (ChildFileNameList);
+ return Status;
+ }
- //
- // Make it alignment.
- //
- Status = LibCreateFfsSection(FvInFd, InputFileName, NULL, 0, OutputFileName, NULL, NULL, NULL, 0, 0, NULL);
- OutFile = fopen(OutputFileName, "rb+");
- if (OutFile == NULL) {
+ InputFileName = OutputFileName;
+ OutputFileName= LibFilenameStrExtended (strrchr(GenTempFile (), OS_SEP), TemDir, "sec");
+
+ //
+ // Make it alignment.
+ //
+ Status = LibCreateFfsSection(FvInFd, InputFileName, NULL, 0, OutputFileName, NULL, NULL, NULL, 0, 0, NULL);
+ OutFile = fopen(OutputFileName, "rb+");
+ if (OutFile == NULL) {
Error("FMMT", 0, 0004, "Could not open the file %s! \n", "");
free (OutputFileNameList);
free (ChildFileNameList);
return EFI_ABORTED;
- }
- fseek(OutFile, 0, SEEK_SET);
- fseek(OutFile, 0, SEEK_END);
- OutputFileSize = ftell(OutFile);
- fclose(OutFile);
- if (OutputFileSize > LargeFileSize) {
+ }
+ fseek(OutFile, 0, SEEK_SET);
+ fseek(OutFile, 0, SEEK_END);
+ OutputFileSize = ftell(OutFile);
+ fclose(OutFile);
+ if (OutputFileSize > LargeFileSize) {
IsLargeFile = TRUE;
+ }
+
+ OutputFileNameList->FFSName = (char *)malloc(strlen(OutputFileName)+1);
+ if (OutputFileNameList->FFSName == NULL) {
+ Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n", "");
+ return EFI_OUT_OF_RESOURCES;
+ }
+ memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, strlen(OutputFileName)+1);
+
+ if (EFI_ERROR (Status)) {
+ Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FV section failed!");
+ free (OutputFileNameList);
+ free (ChildFileNameList);
+ return Status;
+ }
+ OutputFileNameList->ParentLevel = ParentLevel - 1;
+ if (OutputFileNameList->Next == NULL){
+ break;
+ }
+ OutputFileNameList = OutputFileNameList->Next;
}
-
- OutputFileNameList->FFSName = (char *)malloc(strlen(OutputFileName)+1);
- if (OutputFileNameList->FFSName == NULL) {
- Error ("FMMT", 0, 0004, "Out of resource, memory allocation failed! \n", "");
- return EFI_OUT_OF_RESOURCES;
- }
- memcpy((char *)OutputFileNameList->FFSName, (char *)OutputFileName, strlen(OutputFileName)+1);
-
- if (EFI_ERROR (Status)) {
- Error ("FMMT", 0, 0004, "error while encapsulate FD Image", "Generate FV section failed!");
- free (OutputFileNameList);
- free (ChildFileNameList);
- return Status;
- }
- OutputFileNameList->ParentLevel = ParentLevel - 1;
- if (OutputFileNameList->Next == NULL){
- break;
- }
- OutputFileNameList = OutputFileNameList->Next;
- }
break;
default:
for (Id = FvInFd->FfsNumbers; Id <= FvInFd->FfsNumbers; Id--) {
- if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(CurrentEncapData->FvExtHeader->FvName), sizeof(EFI_GUID)) == 0)){
- FvInFd->FfsAttuibutes[Id].IsHandle = TRUE;
- memcpy(OutputFileNameList->UiName, FvInFd->FfsAttuibutes[Id].UiName, FvInFd->FfsAttuibutes[Id].UiNameSize);
- OutputFileNameList->UiNameSize = FvInFd->FfsAttuibutes[Id].UiNameSize;
- OutputFileNameList->FFSName = FvInFd->FfsAttuibutes[Id].FfsName;
- OutputFileNameList->Depex = FvInFd->FfsAttuibutes[Id].Depex;
- OutputFileNameList->DepexLen = FvInFd->FfsAttuibutes[Id].DepexLen;
- OutputFileNameList->FfsFoundFlag = TRUE;
- OutputFileNameList->IsFFS = TRUE;
- OutputFileNameList->InFvId = Id;
- OutputFileNameList->FvId = FvInFd->FfsAttuibutes[Id].FvId;
- OutputFileNameList->ParentLevel = ParentLevel - 1;
- *OutputFile = OutputFileNameList;
- return EFI_SUCCESS;
- }
+ if ((memcmp(&FvInFd->FfsAttuibutes[Id].GuidName, &(CurrentEncapData->FvExtHeader->FvName), sizeof(EFI_GUID)) == 0)){
+ FvInFd->FfsAttuibutes[Id].IsHandle = TRUE;
+ memcpy(OutputFileNameList->UiName, FvInFd->FfsAttuibutes[Id].UiName, FvInFd->FfsAttuibutes[Id].UiNameSize);
+ OutputFileNameList->UiNameSize = FvInFd->FfsAttuibutes[Id].UiNameSize;
+ OutputFileNameList->FFSName = FvInFd->FfsAttuibutes[Id].FfsName;
+ OutputFileNameList->Depex = FvInFd->FfsAttuibutes[Id].Depex;
+ OutputFileNameList->DepexLen = FvInFd->FfsAttuibutes[Id].DepexLen;
+ OutputFileNameList->FfsFoundFlag = TRUE;
+ OutputFileNameList->IsFFS = TRUE;
+ OutputFileNameList->InFvId = Id;
+ OutputFileNameList->FvId = FvInFd->FfsAttuibutes[Id].FvId;
+ OutputFileNameList->ParentLevel = ParentLevel - 1;
+ *OutputFile = OutputFileNameList;
+ return EFI_SUCCESS;
+ }
}
}
if (CurrentEncapData == NULL) {
LocalEncapData = FvInFd->EncapData;
} else {
- if (OutputFileNameList != NULL && OutputFileNameList->FFSName != NULL && OutputFileNameList->IsFFS == TRUE) {
- *OutputFile = OutputFileNameList;
- return EFI_SUCCESS;
- }
LocalEncapData = CurrentEncapData;
}
+
ParentLevel -= 1;
while (LocalEncapData->NextNode != NULL) {
--
2.16.2.windows.1
next reply other threads:[~2020-11-27 2:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-27 2:16 GregX Yeh [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-03-10 2:05 [PATCH] [edk2-staging] BaseTools/FMMT: Replace file failure when FV level over 2 GregX Yeh
2021-03-15 4:34 ` Bob Feng
2021-03-16 1:54 ` GregX Yeh
2021-03-17 6:57 ` Bob Feng
2021-01-04 3:11 GregX Yeh
2020-12-08 7:32 GregX Yeh
2020-12-08 8:30 ` Bob Feng
2020-12-08 8:33 ` GregX Yeh
2020-12-18 9:33 ` Bob Feng
2020-12-23 8:00 ` GregX Yeh
2021-01-04 2:54 ` Bob Feng
2020-12-04 9:04 GregX Yeh
2020-12-01 7:43 GregX Yeh
2020-11-27 1:38 GregX Yeh
2020-11-27 2:08 ` Bob Feng
2020-11-26 7:07 GregX Yeh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201127021658.11480-1-gregx.yeh@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox