Skip to content

Commit

Permalink
BaseTools: fixing FMMT ShrinkFv issue
Browse files Browse the repository at this point in the history
1. FvLength not change issue;
2. FileSystemGuid align with File Size;

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Bob Feng <bob.c.feng@intel.com>
Signed-off-by: Yuwei Chen <yuwei.chen@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
  • Loading branch information
YuweiChen1110 authored and mergify[bot] committed Dec 11, 2023
1 parent 59f0d35 commit 5b54815
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion BaseTools/Source/Python/FMMT/core/FMMTOperation.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def ExtractFfs(inputfile: str, Ffs_name: str, outputfile: str, Fv_name: str=None
FmmtParser.WholeFvTree.Findlist.remove(FmmtParser.WholeFvTree.Findlist[index])
if FmmtParser.WholeFvTree.Findlist != []:
TargetNode = FmmtParser.WholeFvTree.Findlist[0]
if TargetNode.type == FV_TREE or SEC_FV_TREE or DATA_FV_TREE:
if TargetNode.type == FV_TREE or TargetNode.type == SEC_FV_TREE or TargetNode.type == DATA_FV_TREE:
FinalData = struct2stream(TargetNode.Data.Header) + TargetNode.Data.Data
with open(outputfile, "wb") as f:
f.write(FinalData)
Expand Down
10 changes: 7 additions & 3 deletions BaseTools/Source/Python/FMMT/core/FvHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def ModifyTest(self, ParTree, Needed_Space: int) -> None:
ParTree.Child.remove(ParTree.Child[-1])
ParTree.Data.Free_Space = 0
ParTree.Data.Size += Needed_Space
ParTree.Data.Header.Fvlength = ParTree.Data.Size
ParTree.Data.Header.FvLength = ParTree.Data.Size
ModifyFvSystemGuid(ParTree)
for item in ParTree.Child:
if item.type == FFS_FREE_SPACE:
Expand Down Expand Up @@ -663,8 +663,12 @@ def ShrinkFv(self) -> bool:
Removed_Space = TargetFv.Data.Free_Space - New_Free_Space
TargetFv.Child[-1].Data.Data = b'\xff' * New_Free_Space
TargetFv.Data.Size -= Removed_Space
TargetFv.Data.Header.Fvlength = TargetFv.Data.Size
ModifyFvSystemGuid(TargetFv)
TargetFv.Data.Header.FvLength = TargetFv.Data.Size
if struct2stream(TargetFv.Data.Header.FileSystemGuid) == EFI_FIRMWARE_FILE_SYSTEM3_GUID_BYTE:
if TargetFv.Data.Size <= 0xFFFFFF:
TargetFv.Data.Header.FileSystemGuid = ModifyGuidFormat(
"8c8ce578-8a3d-4f1c-9935-896185c32dd3")

for item in TargetFv.Child:
if item.type == FFS_FREE_SPACE:
TargetFv.Data.Data += item.Data.Data + item.Data.PadData
Expand Down

0 comments on commit 5b54815

Please sign in to comment.