5 Commits

Author SHA1 Message Date
Yuwei Chen
d8a171b895 BaseTools: Enhance FMMT rebase feature with FFS type check
1.Add FFS file type check: Only allow rebase operation for
EFI_FV_FILETYPE_SECURITY_CORE, EFI_FV_FILETYPE_PEI_CORE,
EFI_FV_FILETYPE_DXE_CORE, EFI_FV_FILETYPE_PEIM, EFI_FV_FILETYPE_DRIVER,
EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER,EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
types, improving safety and compliance.
2.Automatically detect and complete the PE/COFF or TE image
relocation table (reloc section) to ensure integrity and compatibility
of the rebase operation.
3.After rebase, automatically update FFS checksum and FV header
information to ensure correct data structure.
4.Support recursive processing for nested FVs, ensuring all related FFS
files' PE/TE images are properly rebased and reloc tables are completed.
5.Use table-driven architecture for relocation types, making it easier to
extend to more platforms.
6.Improve error handling and logging for better robustness and
maintainability.

Please attention, only IA32 and X64 PE/COFF image are supported now.
For other Arch, will support it after testing.

Signed-off-by: Yuwei Chen <yuwei.chen@intel.com>
2025-11-23 23:30:49 +00:00
Yuwei Chen
7977926811 BaseTools: Enable FMMT Rebase function
This patch adds and improves the rebase functionality
for firmware images (PE/COFF/TE) in the FMMT tool.
Key features include:

1.Automatically rebases PE/COFF/TE images within FFS files
when the firmware volume (FV) layout is adjusted or FFS files
are moved, ensuring correct loading and execution at new addresses.
2.Implements recursive rebase logic for nested sections,
guaranteeing all relevant images are properly relocated.
3.Adds support for rebasing subsequent FFS files within the same FV,
enhancing compatibility and stability during firmware layout changes.
4.Core code changes are mainly in FvHandler.py, BiosTreeNode.py,
and BinaryFactoryProduct.py, covering rebase flag detection, address calculation,
and actual relocation operations.
5.This feature improves the flexibility of firmware space management
and enhances the automation and reliability of the FMMT tool.

Co-Auther: Ashraf Ali S <ashraf.ali.s@intel.com>
Signed-off-by: Yuwei Chen <yuwei.chen@intel.com>
2025-11-23 23:30:49 +00:00
Pierre Gondois
ff0162bf07 BaseTools: FMTT: Remove unnecessary code
Running the vulture tool on the FMTT folder gave the following
report. Remove the unnecessary code.

- FMMT/core/BinaryFactoryProduct.py:132:
  unused attribute 'ROffset' (60% confidence)
- FMMT/core/BinaryFactoryProduct.py:176:
  unused attribute 'ROffset' (60% confidence)
- FMMT/core/BinaryFactoryProduct.py:229:
  unused attribute 'ROffset' (60% confidence)
- FMMT/core/BinaryFactoryProduct.py:365:
  unused class 'ElfSectionProduct' (60% confidence)
- FMMT/core/BinaryFactoryProduct.py:369:
  unused method 'ParserSectionData' (60% confidence)
- FMMT/core/BinaryFactoryProduct.py:371:
  unused method 'ParserProgramData' (60% confidence)
- FMMT/core/BiosTree.py:76:
  unused method 'insertRel' (60% confidence)
- FMMT/core/BiosTree.py:84:
  unused method 'deleteNode' (60% confidence)
- FMMT/core/BiosTreeNode.py:63:
  unused attribute 'ROffset' (60% confidence)
- FMMT/core/BiosTreeNode.py:125:
  unused attribute 'ROffset' (60% confidence)
- FMMT/core/BiosTreeNode.py:182:
  unused attribute 'ROffset' (60% confidence)
- FMMT/core/BiosTreeNode.py:185:
  unused attribute 'SectionMaxAlignment' (60% confidence)
- FMMT/core/BiosTreeNode.py:220:
  unused attribute 'ROffset' (60% confidence)
- FMMT/core/BiosTreeNode.py:223:
  unused attribute 'OriHeader' (60% confidence)
- FMMT/core/BiosTreeNode.py:226:
  unused attribute 'SectionMaxAlignment' (60% confidence)
- FMMT/core/BiosTreeNode.py:247:
  unused attribute 'ROffset' (60% confidence)
- FMMT/FMMT.py:52:
  unused attribute 'firmware_packet' (60% confidence)

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-07-01 09:51:38 +08:00
Yuwei Chen
59f0d350a9 BaseTools: FMMT support ELF UPLD parser
FMMT add new function to support the .elf file parsing.
Using '-v' option, the UPLD info will be printed out.

'''
- UNIVERSAL_PAYLOAD_INFO
  - 4 bytes align (BOOLEAN)
    - Identifier
    - SpecRevision
    - Attribute
    - Revision
    - Capability
    - ProducerId
    - ImageId
UPLD Buffer
'''

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
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>
2023-12-11 10:12:52 +00:00
Chen, Christine
a64b944942 BaseTools: Add FMMT Python Tool
The FMMT python tool is used for firmware files operation, which has
the Fv/FFs-based 'View'&'Add'&'Delete'&'Replace' operation function:

1.Parse a FD(Firmware Device) / FV(Firmware Volume) / FFS(Firmware Files)
2.Add a new FFS into a FV file (both included in a FD file or not)
3.Replace an FFS in a FV file with a new FFS file
4.Delete an FFS in a FV file (both included in a FD file or not)
5.Extract the FFS from a FV file (both included in a FD file or not)

This version of FMMT Python tool does not support PEIM rebase feature,
this feature will be added in future update.

Currently the FMMT C tool is saved in edk2-staging repo, but its
quality and coding style can't meet the Edk2 quality, which is hard to
maintain (Hard/Duplicate Code; Regression bugs; Restrict usage).

The new Python version keeps same functions with origin C version. It
has higher quality and better coding style, and it is much easier to
extend new functions and to maintain.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1847
RFC Link: https://edk2.groups.io/g/devel/message/82877
Staging Link: https://github.com/tianocore/edk2-staging/tree/PyFMMT

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Yuwei Chen <yuwei.chen@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
Acked-by: Liming Gao <gaoliming@byosoft.com.cn>
2022-05-06 04:22:21 +00:00